-
Notifications
You must be signed in to change notification settings - Fork 2
/
B2BCall.hxx
308 lines (255 loc) · 9.58 KB
/
B2BCall.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#ifndef __B2BCall_h
#define __B2BCall_h
/* B2BCall models a bridged call between a caller and a callee
*/
#include "rutil/Data.hxx"
#include "resip/dum/DialogUsageManager.hxx"
namespace b2bua
{
class B2BCall;
class MyDialogSetHandler;
}
#include "AuthorizationManager.hxx"
#include "CallHandle.hxx"
#include "CDRHandler.hxx"
#include "MediaManager.hxx"
#include "MyAppDialog.hxx"
namespace b2bua
{
class B2BCall {
protected:
typedef enum B2BCallState {
NewCall = 0, // just started
CallerCancel, // CANCEL received from A leg
AuthorizationPending,
AuthorizationSuccess,
AuthorizationFail,
// RoutesPending, // routes requested
// RoutesSuccess,
// RoutesFail,
// MediaProxyPending, // Media Proxy requested
MediaProxySuccess,
MediaProxyFail,
ReadyToDial, // Route ready
DialInProgress, // INVITE sent
DialFailed, // Network error, e.g. ICMP
DialRejected, // SIP error received
// error code in data member
// failureStatusCode
SelectAlternateRoute, // Need to select another
// route
DialAborted, // No other carriers
// available, or a failure
// that doesn't require us
// to try another carrier
// e.g. Busy
// DialReceived100, // 100 response received
DialReceived180, // 180 response received
// DialReceived183, // 183 response received
DialReceivedEarlyAnswer, // early answer (SDP) received
// DialEarlyMediaProxyRequested, // Media proxy requested for
// early media
DialEarlyMediaProxySuccess, // Media Proxy ready
DialEarlyMediaProxyFail, // Media Proxy failed
CallAccepted, // 200 received
// CallAcceptedMediaProxyRequested, // Media proxy requested for
// media
CallAcceptedMediaProxySuccess, // Media Proxy ready
CallAcceptedMediaProxyFail, // Media proxy failed
CallActive, // Call in progress
CallerHangup, // Caller has hungup
CalleeHangup, // Callee has hungup
LocalHangup, // B2BUA initiated hangup
CallStop, // Call is stopped
// CallStopMediaProxyNotified, // Media proxy informed
CallStopMediaProxySuccess, // Media proxy acknowledged
CallStopMediaProxyFail, // Media proxy failed to ack
CallStopFinal // Call can be purged from
// the system
};
static resip::Data callStateNames[];
typedef enum BasicClearingReason {
NoAnswer = 0, // caller gave up/timeout
Busy, // callee indicated busy
Congestion, // callee indicated congestion
Error, // callee indicated error
Answered // call was answered
};
static const char *basicClearingReasonName[];
typedef enum FullClearingReason {
Unset,
// No attempted
InvalidDestination,
AuthError,
// not answered
NoAnswerCancel,
NoAnswerTimeout,
NoAnswerError, // media negotiation failed
// Rejected
RejectBusy,
RejectOther, // rejectOtherCode = SIP error code
// Answered
AnsweredALegHangup, // A leg hangup first
AnsweredBLegHangup, // B leg hangup first
AnsweredLimit, // reached limit
AnsweredShutdown, // Answered, B2BUA shutdown
AnsweredError, // An error occured, e.g. during a re-INVITE
AnsweredNoMedia, // Media stopped
AnsweredUnknown // Answered, hangup for unknown reason
};
CDRHandler& cdrHandler;
resip::DialogUsageManager& dum;
//CallController *callController;
AuthorizationManager& authorizationManager;
//static std::list<B2BCall *> calls;
// Attributes of the call, from the original INVITE
resip::NameAddr sourceAddr;
resip::Uri destinationAddr;
resip::Data authRealm;
resip::Data authUser;
resip::Data authPassword;
resip::Data srcIp;
resip::Data contextId;
resip::Data accountId;
resip::Data baseIp;
resip::Data controlId;
//int callState;
B2BCallState callState;
BasicClearingReason basicClearingReason;
FullClearingReason fullClearingReason;
int rejectOtherCode;
// Call time information
time_t startTime;
time_t connectTime;
time_t finishTime;
// CallHandle from CallController
CallHandle *callHandle;
std::list<CallRoute *>::iterator callRoute;
resip::Data appRef1;
resip::Data appRef2;
// If we are waiting for something, this is the timeout
time_t timeout;
MyAppDialog *aLegAppDialog;
MyAppDialog *bLegAppDialog;
MyAppDialogSet *bLegAppDialogSet;
//resip::SdpContents *aLegSdp; // most recent offer from A leg
//resip::SdpContents *bLegSdp; // most recent offer from B leg
bool earlyAnswerSent;
MediaManager *mediaManager;
// resip::SharedPtr<resip::UserProfile> outboundUserProfile;
int failureStatusCode;
resip::Data *failureReason;
// Returns true if successful, false if new state is not
// permitted
bool setCallState(B2BCallState newCallState);
bool isCallStatePermitted(B2BCallState newCallState);
const resip::Data& getCallStateName(B2BCallState s);
void setALegSdp(const resip::SdpContents& sdp, const in_addr_t& msgSourceAddress);
void setBLegSdp(const resip::SdpContents& sdp, const in_addr_t& msgSourceAddress);
void doNewCall();
void doCallerCancel();
void doAuthorizationPending();
void doAuthorizationSuccess();
void doAuthorizationFail();
void doMediaProxySuccess();
void doMediaProxyFail();
void doReadyToDial();
void doDialFailed();
void doDialRejected();
void doSelectAlternateRoute();
void doDialAborted();
//void doDialReceived100();
void doDialReceived180();
//void doCallDial183();
void doDialReceivedEarlyAnswer();
void doDialEarlyMediaProxySuccess();
void doDialEarlyMediaProxyFail();
void doCallAccepted();
void doCallAcceptedMediaProxySuccess();
void doCallAcceptedMediaProxyFail();
void doCallActive();
void doHangup();
void doCallStop();
void doCallStopMediaProxySuccess();
void doCallStopMediaProxyFail();
void doCallStopFinal();
// sets the clearing reason codes if necessary
void setClearingReason(FullClearingReason reason, int code);
void setClearingReasonMediaFail();
void writeCDR();
public:
// More basic then B2BCallState, used for reporting
typedef enum CallStatus {
PreDial, // the call hasn't started dialing
Dialing, // the call is dialing
Connected, // the call has connected
Finishing, // the call has been hung up
Unknown // unknown
};
void checkProgress(time_t now, bool stopping);
bool isComplete();
CallStatus getStatus();
//static void setDum(resip::DialogUsageManager *dum);
//static void setCallController(CallController *callController);
// B2BCall(MyAppDialog *aLegDialog);
B2BCall(CDRHandler& cdrHandler, resip::DialogUsageManager& dum, AuthorizationManager& authorizationManager, MyAppDialog *aLegDialog, const resip::NameAddr& sourceAddr, const resip::Uri& destinationAddr, const resip::Data& authRealm, const resip::Data& authUser, const resip::Data& authPassword, const resip::Data& srcIp, const resip::Data& contextId, const resip::Data& accountId, const resip::Data& baseIp, const resip::Data& controlId);
virtual ~B2BCall();
void setBLegAppDialog(MyAppDialog *myAppDialog);
// called every time we go through the main program loop
//static void checkCalls();
// For InviteSessionHandler
//void onTrying();
void onRinging();
//void onSessionProgress();
void onEarlyMedia(const resip::SdpContents& sdp, const in_addr_t& msgSourceAddress);
void onCancel();
void onFailure(MyAppDialog *myAppDialog);
void onRejected(int statusCode, const resip::Data& reason);
void onOffer(MyAppDialog *myAppDialog, const resip::SdpContents& sdp, const in_addr_t& msgSourceAddress);
void onAnswer(MyAppDialog *myAppDialog, const resip::SdpContents& sdp, const in_addr_t& msgSourceAddress);
void onMediaTimeout();
void onHangup(MyAppDialog *myAppDialog);
// For B2BCallManager
void onStopping();
void releaseAppDialog(MyAppDialog *myAppDialog);
void releaseAppDialogSet(MyAppDialogSet *myAppDialogSet);
friend class MyDialogSetHandler;
};
}
#endif
/* ====================================================================
*
* Copyright 2012 Daniel Pocock. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. Neither the name of the author(s) nor the names of any contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
*
*
*/