sip-lab 1.7.3 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/devjournal +7 -0
- package/package.json +1 -1
- package/samples/g729.js +0 -2
- package/samples/late_negotiation.js +0 -4
- package/samples/reinvite_and_dtmf.js +291 -0
- package/samples/simple.js +0 -171
- package/samples/sip_cancel.js +0 -2
- package/src/sip.cpp +98 -10
package/devjournal
CHANGED
|
@@ -431,5 +431,12 @@ The problem is that on_rx_reinvite is getting an offer without media (due RE-INV
|
|
|
431
431
|
Instead, I think we should go back to use original on_rx_offer because it seems this is called only when we get media offer and so we would avoid this problem.
|
|
432
432
|
|
|
433
433
|
|
|
434
|
+
------------------------------------------------------------
|
|
435
|
+
2022/08/12 takeshi:
|
|
436
|
+
|
|
437
|
+
When rebuilding the addon, this should be enough (it should be fast):
|
|
438
|
+
```
|
|
439
|
+
npm install --unsafe-perm
|
|
440
|
+
```
|
|
434
441
|
|
|
435
442
|
|
package/package.json
CHANGED
package/samples/g729.js
CHANGED
|
@@ -208,8 +208,6 @@ async function test() {
|
|
|
208
208
|
},
|
|
209
209
|
], 500)
|
|
210
210
|
|
|
211
|
-
await z.sleep(100)
|
|
212
|
-
|
|
213
211
|
sip.call.reinvite(oc.id, false, flags)
|
|
214
212
|
|
|
215
213
|
await z.wait([
|
|
@@ -275,8 +273,6 @@ async function test() {
|
|
|
275
273
|
},
|
|
276
274
|
], 1000)
|
|
277
275
|
|
|
278
|
-
await z.sleep(1000)
|
|
279
|
-
|
|
280
276
|
console.log("Success")
|
|
281
277
|
|
|
282
278
|
sip.stop()
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
var sip = require ('../index.js')
|
|
2
|
+
var Zester = require('zester')
|
|
3
|
+
var z = new Zester()
|
|
4
|
+
var m = require('data-matching')
|
|
5
|
+
var sip_msg = require('sip-matching')
|
|
6
|
+
|
|
7
|
+
async function test() {
|
|
8
|
+
//sip.set_log_level(6)
|
|
9
|
+
sip.dtmf_aggregation_on(500)
|
|
10
|
+
|
|
11
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
12
|
+
var e = evt.args[0]
|
|
13
|
+
return e
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
17
|
+
|
|
18
|
+
t1 = sip.transport.create("127.0.0.1", 5090, 1)
|
|
19
|
+
t2 = sip.transport.create("127.0.0.1", 5092, 1)
|
|
20
|
+
|
|
21
|
+
console.log("t1", t1)
|
|
22
|
+
console.log("t2", t2)
|
|
23
|
+
|
|
24
|
+
flags = 0
|
|
25
|
+
|
|
26
|
+
oc = sip.call.create(t1.id, flags, 'sip:a@t', 'sip:b@127.0.0.1:5092')
|
|
27
|
+
|
|
28
|
+
await z.wait([
|
|
29
|
+
{
|
|
30
|
+
event: "incoming_call",
|
|
31
|
+
call_id: m.collect("call_id"),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
event: 'response',
|
|
35
|
+
call_id: oc.id,
|
|
36
|
+
method: 'INVITE',
|
|
37
|
+
msg: sip_msg({
|
|
38
|
+
$rs: '100',
|
|
39
|
+
$rr: 'Trying',
|
|
40
|
+
'$(hdrcnt(via))': 1,
|
|
41
|
+
'$hdr(call-id)': m.collect('sip_call_id'),
|
|
42
|
+
$fU: 'a',
|
|
43
|
+
$fd: 't',
|
|
44
|
+
$tU: 'b',
|
|
45
|
+
'$hdr(l)': '0',
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
], 1000)
|
|
49
|
+
|
|
50
|
+
ic = {
|
|
51
|
+
id: z.store.call_id,
|
|
52
|
+
sip_call_id: z.store.sip_call_id,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
sip.call.respond(ic.id, 200, 'OK')
|
|
56
|
+
|
|
57
|
+
await z.wait([
|
|
58
|
+
{
|
|
59
|
+
event: 'media_status',
|
|
60
|
+
call_id: oc.id,
|
|
61
|
+
status: 'setup_ok',
|
|
62
|
+
local_mode: 'sendrecv',
|
|
63
|
+
remote_mode: 'sendrecv',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
event: 'media_status',
|
|
67
|
+
call_id: ic.id,
|
|
68
|
+
status: 'setup_ok',
|
|
69
|
+
local_mode: 'sendrecv',
|
|
70
|
+
remote_mode: 'sendrecv',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
event: 'response',
|
|
74
|
+
call_id: oc.id,
|
|
75
|
+
method: 'INVITE',
|
|
76
|
+
msg: sip_msg({
|
|
77
|
+
$rs: '200',
|
|
78
|
+
$rr: 'OK',
|
|
79
|
+
'$(hdrcnt(VIA))': 1,
|
|
80
|
+
$fU: 'a',
|
|
81
|
+
$fd: 't',
|
|
82
|
+
$tU: 'b',
|
|
83
|
+
'$hdr(content-type)': 'application/sdp',
|
|
84
|
+
$rb: '!{_}a=sendrecv',
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
], 1000)
|
|
88
|
+
|
|
89
|
+
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
90
|
+
sip.call.send_dtmf(ic.id, '4321', 1)
|
|
91
|
+
|
|
92
|
+
await z.wait([
|
|
93
|
+
{
|
|
94
|
+
event: 'dtmf',
|
|
95
|
+
call_id: ic.id,
|
|
96
|
+
digits: '1234',
|
|
97
|
+
mode: 0,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
event: 'dtmf',
|
|
101
|
+
call_id: oc.id,
|
|
102
|
+
digits: '4321',
|
|
103
|
+
mode: 1,
|
|
104
|
+
},
|
|
105
|
+
], 2000)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
sip.call.reinvite(oc.id, true, 0)
|
|
109
|
+
|
|
110
|
+
await z.wait([
|
|
111
|
+
{
|
|
112
|
+
event: 'response',
|
|
113
|
+
call_id: oc.id,
|
|
114
|
+
method: 'INVITE',
|
|
115
|
+
msg: sip_msg({
|
|
116
|
+
$rs: '200',
|
|
117
|
+
$rr: 'OK',
|
|
118
|
+
$rb: '!{_}a=recvonly',
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
event: 'media_status',
|
|
123
|
+
call_id: oc.id,
|
|
124
|
+
status: 'setup_ok',
|
|
125
|
+
local_mode: 'sendonly',
|
|
126
|
+
remote_mode: 'recvonly',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
event: 'media_status',
|
|
130
|
+
call_id: ic.id,
|
|
131
|
+
status: 'setup_ok',
|
|
132
|
+
local_mode: 'recvonly',
|
|
133
|
+
remote_mode: 'sendonly',
|
|
134
|
+
},
|
|
135
|
+
], 500)
|
|
136
|
+
|
|
137
|
+
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
138
|
+
sip.call.send_dtmf(ic.id, '4321', 1) // this will not generate event 'dtmf' as the call is on hold
|
|
139
|
+
|
|
140
|
+
await z.wait([
|
|
141
|
+
{
|
|
142
|
+
event: 'dtmf',
|
|
143
|
+
call_id: ic.id,
|
|
144
|
+
digits: '1234',
|
|
145
|
+
mode: 0,
|
|
146
|
+
},
|
|
147
|
+
], 2000)
|
|
148
|
+
|
|
149
|
+
sip.call.reinvite(ic.id, false, 0)
|
|
150
|
+
|
|
151
|
+
await z.wait([
|
|
152
|
+
{
|
|
153
|
+
event: 'response',
|
|
154
|
+
call_id: ic.id,
|
|
155
|
+
method: 'INVITE',
|
|
156
|
+
msg: sip_msg({
|
|
157
|
+
$rs: '200',
|
|
158
|
+
$rr: 'OK',
|
|
159
|
+
$rb: '!{_}a=sendonly',
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
event: 'media_status',
|
|
164
|
+
call_id: oc.id,
|
|
165
|
+
status: 'setup_ok',
|
|
166
|
+
local_mode: 'sendonly',
|
|
167
|
+
remote_mode: 'recvonly',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
event: 'media_status',
|
|
171
|
+
call_id: ic.id,
|
|
172
|
+
status: 'setup_ok',
|
|
173
|
+
local_mode: 'recvonly',
|
|
174
|
+
remote_mode: 'sendonly',
|
|
175
|
+
},
|
|
176
|
+
], 500)
|
|
177
|
+
|
|
178
|
+
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
179
|
+
sip.call.send_dtmf(ic.id, '4321', 1) // this will not generate event 'dtmf' as the call is on hold
|
|
180
|
+
|
|
181
|
+
await z.wait([
|
|
182
|
+
{
|
|
183
|
+
event: 'dtmf',
|
|
184
|
+
call_id: ic.id,
|
|
185
|
+
digits: '1234',
|
|
186
|
+
mode: 0,
|
|
187
|
+
},
|
|
188
|
+
], 2000)
|
|
189
|
+
|
|
190
|
+
sip.call.send_request(oc.id, 'INFO')
|
|
191
|
+
|
|
192
|
+
await z.wait([
|
|
193
|
+
{
|
|
194
|
+
event: 'request',
|
|
195
|
+
call_id: ic.id,
|
|
196
|
+
msg: sip_msg({
|
|
197
|
+
$rm: 'INFO',
|
|
198
|
+
}),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
event: 'response',
|
|
202
|
+
call_id: oc.id,
|
|
203
|
+
method: 'INFO',
|
|
204
|
+
msg: sip_msg({
|
|
205
|
+
$rs: '200',
|
|
206
|
+
$rr: 'OK',
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
209
|
+
], 500)
|
|
210
|
+
|
|
211
|
+
sip.call.reinvite(oc.id, false, 0)
|
|
212
|
+
|
|
213
|
+
await z.wait([
|
|
214
|
+
{
|
|
215
|
+
event: 'response',
|
|
216
|
+
call_id: oc.id,
|
|
217
|
+
method: 'INVITE',
|
|
218
|
+
msg: sip_msg({
|
|
219
|
+
$rs: '200',
|
|
220
|
+
$rr: 'OK',
|
|
221
|
+
$rb: '!{_}a=sendrecv',
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
event: 'media_status',
|
|
226
|
+
call_id: oc.id,
|
|
227
|
+
status: 'setup_ok',
|
|
228
|
+
local_mode: 'sendrecv',
|
|
229
|
+
remote_mode: 'sendrecv',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
event: 'media_status',
|
|
233
|
+
call_id: ic.id,
|
|
234
|
+
status: 'setup_ok',
|
|
235
|
+
local_mode: 'sendrecv',
|
|
236
|
+
remote_mode: 'sendrecv',
|
|
237
|
+
},
|
|
238
|
+
], 500)
|
|
239
|
+
|
|
240
|
+
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
241
|
+
sip.call.send_dtmf(ic.id, '4321', 1)
|
|
242
|
+
|
|
243
|
+
await z.wait([
|
|
244
|
+
{
|
|
245
|
+
event: 'dtmf',
|
|
246
|
+
call_id: ic.id,
|
|
247
|
+
digits: '1234',
|
|
248
|
+
mode: 0,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
event: 'dtmf',
|
|
252
|
+
call_id: oc.id,
|
|
253
|
+
digits: '4321',
|
|
254
|
+
mode: 1,
|
|
255
|
+
},
|
|
256
|
+
], 2000)
|
|
257
|
+
|
|
258
|
+
sip.call.terminate(oc.id)
|
|
259
|
+
|
|
260
|
+
await z.wait([
|
|
261
|
+
{
|
|
262
|
+
event: 'call_ended',
|
|
263
|
+
call_id: oc.id,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
event: 'call_ended',
|
|
267
|
+
call_id: ic.id,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
event: 'response',
|
|
271
|
+
call_id: oc.id,
|
|
272
|
+
method: 'BYE',
|
|
273
|
+
msg: sip_msg({
|
|
274
|
+
$rs: '200',
|
|
275
|
+
$rr: 'OK',
|
|
276
|
+
}),
|
|
277
|
+
},
|
|
278
|
+
], 1000)
|
|
279
|
+
|
|
280
|
+
console.log("Success")
|
|
281
|
+
|
|
282
|
+
sip.stop()
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
test()
|
|
287
|
+
.catch(e => {
|
|
288
|
+
console.error(e)
|
|
289
|
+
process.exit(1)
|
|
290
|
+
})
|
|
291
|
+
|
package/samples/simple.js
CHANGED
|
@@ -86,175 +86,6 @@ async function test() {
|
|
|
86
86
|
},
|
|
87
87
|
], 1000)
|
|
88
88
|
|
|
89
|
-
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
90
|
-
sip.call.send_dtmf(ic.id, '4321', 1)
|
|
91
|
-
|
|
92
|
-
await z.wait([
|
|
93
|
-
{
|
|
94
|
-
event: 'dtmf',
|
|
95
|
-
call_id: ic.id,
|
|
96
|
-
digits: '1234',
|
|
97
|
-
mode: 0,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
event: 'dtmf',
|
|
101
|
-
call_id: oc.id,
|
|
102
|
-
digits: '4321',
|
|
103
|
-
mode: 1,
|
|
104
|
-
},
|
|
105
|
-
], 2000)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
sip.call.reinvite(oc.id, true, 0)
|
|
109
|
-
|
|
110
|
-
await z.wait([
|
|
111
|
-
{
|
|
112
|
-
event: 'response',
|
|
113
|
-
call_id: oc.id,
|
|
114
|
-
method: 'INVITE',
|
|
115
|
-
msg: sip_msg({
|
|
116
|
-
$rs: '200',
|
|
117
|
-
$rr: 'OK',
|
|
118
|
-
$rb: '!{_}a=recvonly',
|
|
119
|
-
}),
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
event: 'media_status',
|
|
123
|
-
call_id: oc.id,
|
|
124
|
-
status: 'setup_ok',
|
|
125
|
-
local_mode: 'sendonly',
|
|
126
|
-
remote_mode: 'recvonly',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
event: 'media_status',
|
|
130
|
-
call_id: ic.id,
|
|
131
|
-
status: 'setup_ok',
|
|
132
|
-
local_mode: 'recvonly',
|
|
133
|
-
remote_mode: 'sendonly',
|
|
134
|
-
},
|
|
135
|
-
], 500)
|
|
136
|
-
|
|
137
|
-
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
138
|
-
sip.call.send_dtmf(ic.id, '4321', 1) // this will not generate event 'dtmf' as the call is on hold
|
|
139
|
-
|
|
140
|
-
await z.wait([
|
|
141
|
-
{
|
|
142
|
-
event: 'dtmf',
|
|
143
|
-
call_id: ic.id,
|
|
144
|
-
digits: '1234',
|
|
145
|
-
mode: 0,
|
|
146
|
-
},
|
|
147
|
-
], 2000)
|
|
148
|
-
|
|
149
|
-
sip.call.reinvite(ic.id, false, 0)
|
|
150
|
-
|
|
151
|
-
await z.wait([
|
|
152
|
-
{
|
|
153
|
-
event: 'response',
|
|
154
|
-
call_id: ic.id,
|
|
155
|
-
method: 'INVITE',
|
|
156
|
-
msg: sip_msg({
|
|
157
|
-
$rs: '200',
|
|
158
|
-
$rr: 'OK',
|
|
159
|
-
$rb: '!{_}a=sendonly',
|
|
160
|
-
}),
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
event: 'media_status',
|
|
164
|
-
call_id: oc.id,
|
|
165
|
-
status: 'setup_ok',
|
|
166
|
-
local_mode: 'sendonly',
|
|
167
|
-
remote_mode: 'recvonly',
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
event: 'media_status',
|
|
171
|
-
call_id: ic.id,
|
|
172
|
-
status: 'setup_ok',
|
|
173
|
-
local_mode: 'recvonly',
|
|
174
|
-
remote_mode: 'sendonly',
|
|
175
|
-
},
|
|
176
|
-
], 500)
|
|
177
|
-
|
|
178
|
-
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
179
|
-
sip.call.send_dtmf(ic.id, '4321', 1) // this will not generate event 'dtmf' as the call is on hold
|
|
180
|
-
|
|
181
|
-
await z.wait([
|
|
182
|
-
{
|
|
183
|
-
event: 'dtmf',
|
|
184
|
-
call_id: ic.id,
|
|
185
|
-
digits: '1234',
|
|
186
|
-
mode: 0,
|
|
187
|
-
},
|
|
188
|
-
], 2000)
|
|
189
|
-
|
|
190
|
-
sip.call.send_request(oc.id, 'INFO')
|
|
191
|
-
|
|
192
|
-
await z.wait([
|
|
193
|
-
{
|
|
194
|
-
event: 'request',
|
|
195
|
-
call_id: ic.id,
|
|
196
|
-
msg: sip_msg({
|
|
197
|
-
$rm: 'INFO',
|
|
198
|
-
}),
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
event: 'response',
|
|
202
|
-
call_id: oc.id,
|
|
203
|
-
method: 'INFO',
|
|
204
|
-
msg: sip_msg({
|
|
205
|
-
$rs: '200',
|
|
206
|
-
$rr: 'OK',
|
|
207
|
-
}),
|
|
208
|
-
},
|
|
209
|
-
], 500)
|
|
210
|
-
|
|
211
|
-
sip.call.reinvite(oc.id, false, 0)
|
|
212
|
-
|
|
213
|
-
await z.wait([
|
|
214
|
-
{
|
|
215
|
-
event: 'response',
|
|
216
|
-
call_id: oc.id,
|
|
217
|
-
method: 'INVITE',
|
|
218
|
-
msg: sip_msg({
|
|
219
|
-
$rs: '200',
|
|
220
|
-
$rr: 'OK',
|
|
221
|
-
$rb: '!{_}a=sendrecv',
|
|
222
|
-
}),
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
event: 'media_status',
|
|
226
|
-
call_id: oc.id,
|
|
227
|
-
status: 'setup_ok',
|
|
228
|
-
local_mode: 'sendrecv',
|
|
229
|
-
remote_mode: 'sendrecv',
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
event: 'media_status',
|
|
233
|
-
call_id: ic.id,
|
|
234
|
-
status: 'setup_ok',
|
|
235
|
-
local_mode: 'sendrecv',
|
|
236
|
-
remote_mode: 'sendrecv',
|
|
237
|
-
},
|
|
238
|
-
], 500)
|
|
239
|
-
|
|
240
|
-
sip.call.send_dtmf(oc.id, '1234', 0)
|
|
241
|
-
sip.call.send_dtmf(ic.id, '4321', 1)
|
|
242
|
-
|
|
243
|
-
await z.wait([
|
|
244
|
-
{
|
|
245
|
-
event: 'dtmf',
|
|
246
|
-
call_id: ic.id,
|
|
247
|
-
digits: '1234',
|
|
248
|
-
mode: 0,
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
event: 'dtmf',
|
|
252
|
-
call_id: oc.id,
|
|
253
|
-
digits: '4321',
|
|
254
|
-
mode: 1,
|
|
255
|
-
},
|
|
256
|
-
], 2000)
|
|
257
|
-
|
|
258
89
|
sip.call.terminate(oc.id)
|
|
259
90
|
|
|
260
91
|
await z.wait([
|
|
@@ -277,8 +108,6 @@ async function test() {
|
|
|
277
108
|
},
|
|
278
109
|
], 1000)
|
|
279
110
|
|
|
280
|
-
await z.sleep(1000)
|
|
281
|
-
|
|
282
111
|
console.log("Success")
|
|
283
112
|
|
|
284
113
|
sip.stop()
|
package/samples/sip_cancel.js
CHANGED
package/src/sip.cpp
CHANGED
|
@@ -196,6 +196,7 @@ Pair_Call_CallId_Buf g_LastCalls(1000);
|
|
|
196
196
|
typedef map<pjsip_transport*, int> SipTransportMap;
|
|
197
197
|
SipTransportMap g_SipTransportMap;
|
|
198
198
|
int g_TlsTransportId = -100;
|
|
199
|
+
int g_TcpTransportId = -100;
|
|
199
200
|
|
|
200
201
|
typedef set< pair<string,string> > PackageSet;
|
|
201
202
|
PackageSet g_PackageSet;
|
|
@@ -322,10 +323,13 @@ pjsip_transport *allocate_udp_transport(pjsip_endpoint* sip_endpt, pj_str_t *ipa
|
|
|
322
323
|
pjsip_tpfactory *create_tls_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int *allocated_port);
|
|
323
324
|
pjsip_tpfactory *allocate_tls_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int port);
|
|
324
325
|
|
|
326
|
+
pjsip_tpfactory *create_tcp_factory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int *allocated_port);
|
|
327
|
+
pjsip_tpfactory *allocate_tcp_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int port);
|
|
328
|
+
|
|
325
329
|
bool set_proxy(pjsip_dialog *dlg, const char *proxy_uri);
|
|
326
330
|
|
|
327
331
|
void build_local_contact(char *dest, pjsip_transport *transport, const char *contact_username);
|
|
328
|
-
void build_local_contact_from_tpfactory(char *dest, pjsip_tpfactory *tpfactory, const char *contact_username);
|
|
332
|
+
void build_local_contact_from_tpfactory(char *dest, pjsip_tpfactory *tpfactory, const char *contact_username, pjsip_transport_type_e type);
|
|
329
333
|
|
|
330
334
|
pj_bool_t add_additional_headers(pj_pool_t *pool, pjsip_tx_data *tdata, const char *additional_headers);
|
|
331
335
|
|
|
@@ -812,6 +816,52 @@ pjsip_transport *create_udp_transport(pjsip_endpoint* sip_endpt, pj_str_t *ipadd
|
|
|
812
816
|
return NULL;
|
|
813
817
|
}
|
|
814
818
|
|
|
819
|
+
pjsip_tpfactory *allocate_tcp_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int port) {
|
|
820
|
+
printf("allocate_tcp_tpfactory ipaddr=%.*s port=%i\n", ipaddr->slen, ipaddr->ptr, port);
|
|
821
|
+
pj_status_t status;
|
|
822
|
+
pjsip_tpfactory *tpfactory;
|
|
823
|
+
pj_sockaddr local_addr;
|
|
824
|
+
pjsip_host_port a_name;
|
|
825
|
+
|
|
826
|
+
int af;
|
|
827
|
+
af = pj_AF_INET();
|
|
828
|
+
pj_sockaddr_init(af, &local_addr, NULL, 0);
|
|
829
|
+
|
|
830
|
+
pj_sockaddr_set_port(&local_addr, (pj_uint16_t)port);
|
|
831
|
+
|
|
832
|
+
status = pj_sockaddr_set_str_addr(af, &local_addr, ipaddr);
|
|
833
|
+
if (status != PJ_SUCCESS) {
|
|
834
|
+
return NULL;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
status = pjsip_tcp_transport_start2(sip_endpt, &local_addr.ipv4, NULL, 1, &tpfactory);
|
|
838
|
+
if (status != PJ_SUCCESS) {
|
|
839
|
+
printf("status=%i\n", status);
|
|
840
|
+
return NULL;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return tpfactory;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
pjsip_tpfactory *create_tcp_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int *allocated_port)
|
|
847
|
+
{
|
|
848
|
+
pj_status_t status;
|
|
849
|
+
pjsip_tpfactory *tpfactory;
|
|
850
|
+
|
|
851
|
+
int port = 6060;
|
|
852
|
+
for(int i=0 ; i<1000 ; ++i)
|
|
853
|
+
{
|
|
854
|
+
port += i;
|
|
855
|
+
tpfactory = allocate_tcp_tpfactory(sip_endpt, ipaddr, port);
|
|
856
|
+
if (tpfactory) {
|
|
857
|
+
*allocated_port = port;
|
|
858
|
+
return tpfactory;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
return NULL;
|
|
863
|
+
}
|
|
864
|
+
|
|
815
865
|
pjsip_tpfactory *allocate_tls_tpfactory(pjsip_endpoint* sip_endpt, pj_str_t *ipaddr, int port) {
|
|
816
866
|
addon_log(LOG_LEVEL_DEBUG, "allocate_tls_tpfactory ipaddr=%.*s port=%i\n", ipaddr->slen, ipaddr->ptr, port);
|
|
817
867
|
pj_status_t status;
|
|
@@ -904,7 +954,37 @@ int pjw_transport_create(const char *sip_ipaddr, int port, pjsip_transport_type_
|
|
|
904
954
|
if(type == PJSIP_TRANSPORT_UDP) {
|
|
905
955
|
g_SipTransportMap.insert(make_pair(sip_transport, t_id));
|
|
906
956
|
}
|
|
957
|
+
} else if(type == PJSIP_TRANSPORT_TCP) {
|
|
958
|
+
pjsip_tpfactory *tpfactory;
|
|
959
|
+
int af;
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
if(port != 0) {
|
|
963
|
+
tpfactory = allocate_tcp_tpfactory(g_sip_endpt, &ipaddr, port);
|
|
964
|
+
} else {
|
|
965
|
+
tpfactory = create_tcp_tpfactory(g_sip_endpt, &ipaddr, &port);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
if(!tpfactory)
|
|
969
|
+
{
|
|
970
|
+
PJW_UNLOCK();
|
|
971
|
+
set_error("Unable to start TCP transport");
|
|
972
|
+
return -1;
|
|
973
|
+
}
|
|
907
974
|
|
|
975
|
+
t = new Transport;
|
|
976
|
+
t->type = PJSIP_TRANSPORT_TCP;
|
|
977
|
+
t->tpfactory = tpfactory;
|
|
978
|
+
|
|
979
|
+
if(!g_transport_ids.add((long)t, t_id)){
|
|
980
|
+
status = (tpfactory->destroy)(tpfactory);
|
|
981
|
+
|
|
982
|
+
PJW_UNLOCK();
|
|
983
|
+
set_error("Failed to allocate id");
|
|
984
|
+
return -1;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
g_TcpTransportId = t_id;
|
|
908
988
|
} else {
|
|
909
989
|
pjsip_tpfactory *tpfactory;
|
|
910
990
|
int af;
|
|
@@ -1392,7 +1472,7 @@ int pjw_call_create(long t_id, unsigned flags, const char *from_uri, const char
|
|
|
1392
1472
|
if(t->type == PJSIP_TRANSPORT_UDP) {
|
|
1393
1473
|
build_local_contact(local_contact, t->sip_transport, contact_username);
|
|
1394
1474
|
} else {
|
|
1395
|
-
build_local_contact_from_tpfactory(local_contact, t->tpfactory, contact_username);
|
|
1475
|
+
build_local_contact_from_tpfactory(local_contact, t->tpfactory, contact_username, t->type);
|
|
1396
1476
|
}
|
|
1397
1477
|
|
|
1398
1478
|
if(!dlg_create(&dlg, t, from_uri, to_uri, request_uri, realm, username, password, local_contact)) {
|
|
@@ -1469,12 +1549,14 @@ void build_local_contact(char *dest, pjsip_transport *t, const char *contact_use
|
|
|
1469
1549
|
}
|
|
1470
1550
|
if(t->key.type == PJSIP_TRANSPORT_UDP) {
|
|
1471
1551
|
p += sprintf(p,">");
|
|
1552
|
+
} else if(t->key.type == PJSIP_TRANSPORT_TCP) {
|
|
1553
|
+
p += sprintf(p,";transport=tcp>");
|
|
1472
1554
|
} else {
|
|
1473
1555
|
p += sprintf(p,";transport=tls>");
|
|
1474
1556
|
}
|
|
1475
1557
|
}
|
|
1476
1558
|
|
|
1477
|
-
void build_local_contact_from_tpfactory(char *dest, pjsip_tpfactory *tpfactory, const char *contact_username) {
|
|
1559
|
+
void build_local_contact_from_tpfactory(char *dest, pjsip_tpfactory *tpfactory, const char *contact_username, pjsip_transport_type_e type) {
|
|
1478
1560
|
char *p = dest;
|
|
1479
1561
|
int len;
|
|
1480
1562
|
p += sprintf(p, "<sip:%s@", contact_username);
|
|
@@ -1484,7 +1566,11 @@ void build_local_contact_from_tpfactory(char *dest, pjsip_tpfactory *tpfactory,
|
|
|
1484
1566
|
if(tpfactory->addr_name.port) {
|
|
1485
1567
|
p += sprintf(p, ":%d",tpfactory->addr_name.port);
|
|
1486
1568
|
}
|
|
1487
|
-
|
|
1569
|
+
if(type == PJSIP_TRANSPORT_TCP) {
|
|
1570
|
+
p += sprintf(p,";transport=tcp>");
|
|
1571
|
+
} else {
|
|
1572
|
+
p += sprintf(p,";transport=tls>");
|
|
1573
|
+
}
|
|
1488
1574
|
}
|
|
1489
1575
|
|
|
1490
1576
|
|
|
@@ -2839,7 +2925,9 @@ static pj_bool_t on_rx_request( pjsip_rx_data *rdata ){
|
|
|
2839
2925
|
if( iter != g_SipTransportMap.end() ){
|
|
2840
2926
|
transport_id = iter->second;
|
|
2841
2927
|
} else {
|
|
2842
|
-
if(t->key.type ==
|
|
2928
|
+
if(t->key.type == PJSIP_TRANSPORT_TCP) {
|
|
2929
|
+
transport_id = g_TcpTransportId;
|
|
2930
|
+
} else if(t->key.type == PJSIP_TRANSPORT_TLS) {
|
|
2843
2931
|
transport_id = g_TlsTransportId;
|
|
2844
2932
|
} else {
|
|
2845
2933
|
transport_id = -1;
|
|
@@ -3262,6 +3350,9 @@ int __pjw_shutdown()
|
|
|
3262
3350
|
|
|
3263
3351
|
g_shutting_down = true;
|
|
3264
3352
|
|
|
3353
|
+
//disable auto cleanup
|
|
3354
|
+
|
|
3355
|
+
/*
|
|
3265
3356
|
map<long, long>::iterator iter;
|
|
3266
3357
|
iter = g_call_ids.id_map.begin();
|
|
3267
3358
|
while(iter != g_call_ids.id_map.end()){
|
|
@@ -3339,11 +3430,6 @@ int __pjw_shutdown()
|
|
|
3339
3430
|
//uint32_t wait = 100000 * (g_call_ids.id_map.size() + g_account_ids.id_map.size()));
|
|
3340
3431
|
//wait += 1000000; //Wait one whole second to permit packet capture to get any final packets
|
|
3341
3432
|
|
|
3342
|
-
/*
|
|
3343
|
-
time_t end,start;
|
|
3344
|
-
time(&start);
|
|
3345
|
-
end = start;
|
|
3346
|
-
*/
|
|
3347
3433
|
timeval tv_start;
|
|
3348
3434
|
timeval tv_end;
|
|
3349
3435
|
gettimeofday(&tv_start, NULL);
|
|
@@ -3363,6 +3449,8 @@ int __pjw_shutdown()
|
|
|
3363
3449
|
//time(&end);
|
|
3364
3450
|
}
|
|
3365
3451
|
|
|
3452
|
+
*/
|
|
3453
|
+
|
|
3366
3454
|
return 0;
|
|
3367
3455
|
}
|
|
3368
3456
|
|