sip-lab 1.12.39 → 1.13.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.
Files changed (40) hide show
  1. package/DEV.md +19 -3
  2. package/README.md +3 -2
  3. package/binding.gyp +97 -86
  4. package/build_deps.sh +2 -1
  5. package/index.js +14 -7
  6. package/package.json +7 -2
  7. package/prebuilds/linux-x64/node.abi102.node +0 -0
  8. package/prebuilds/linux-x64/node.abi108.node +0 -0
  9. package/prebuilds/linux-x64/node.abi88.node +0 -0
  10. package/prebuilds/linux-x64/node.abi93.node +0 -0
  11. package/samples/16_audio_streams.js +179 -0
  12. package/samples/delayed_media.js +117 -81
  13. package/samples/g729.js +50 -28
  14. package/samples/mrcp_and_audio.js +445 -0
  15. package/samples/mrcp_and_audio.simplified_media.js +273 -0
  16. package/samples/mrcp_and_audio.switching_order.js +273 -0
  17. package/samples/options.js +82 -0
  18. package/samples/refer.js +247 -0
  19. package/samples/refuse_telephone_event.js +166 -0
  20. package/samples/register_no_expires.js +82 -0
  21. package/samples/register_subscribe.js +36 -4
  22. package/samples/reinvite_and_dtmf.js +236 -161
  23. package/samples/reinvite_audio_audio.js +320 -0
  24. package/samples/reinvite_with_hold_unhold.js +412 -0
  25. package/samples/send_and_receive_fax.js +4 -8
  26. package/samples/simple.js +5 -9
  27. package/samples/sip_cancel.js +4 -6
  28. package/samples/tcp_and_extra_headers.js +98 -45
  29. package/samples/two_audio_media.js +497 -0
  30. package/src/addon.cpp +488 -268
  31. package/src/event_templates.cpp +84 -35
  32. package/src/event_templates.hpp +22 -12
  33. package/src/idmanager.cpp +58 -57
  34. package/src/idmanager.hpp +10 -10
  35. package/src/log.cpp +9 -11
  36. package/src/log.hpp +4 -4
  37. package/src/sip.cpp +6838 -5041
  38. package/src/sip.hpp +26 -34
  39. package/src/packetdumper.cpp +0 -234
  40. package/src/packetdumper.hpp +0 -67
package/src/sip.hpp CHANGED
@@ -1,80 +1,72 @@
1
1
  #ifndef __SIP_HPP__
2
2
  #define __SIP_HPP__
3
3
 
4
- #include <pjsip.h>
5
- #include <pjmedia.h>
6
- #include <pjmedia-codec.h>
7
- #include <pjsip_ua.h>
8
- #include <pjsip_simple.h>
9
4
  #include <pjlib-util.h>
10
5
  #include <pjlib.h>
6
+ #include <pjmedia-codec.h>
7
+ #include <pjmedia.h>
8
+ #include <pjsip.h>
9
+ #include <pjsip_simple.h>
10
+ #include <pjsip_ua.h>
11
11
 
12
12
  #define FLAG_NO_AUTO_100_TRYING 1
13
13
 
14
14
  #define CALL_FLAG_DELAYED_MEDIA 1
15
15
 
16
-
17
16
  int __pjw_init();
18
17
  int __pjw_poll(char *out_evt);
19
18
 
20
- //int pjw_transport_create(const char *sip_ipaddr, int port, pjsip_transport_type_e type, int *out_t_id, int *out_port);
21
- int pjw_transport_create(const char *json, int *out_t_id, char *out_t_address, int *out_port);
19
+ int pjw_transport_create(const char *json, int *out_t_id, char *out_t_address,
20
+ int *out_port);
22
21
 
23
22
  int pjw_transport_get_info(int t_id, char **out_sip_ipaddr, int *out_port);
24
23
 
25
- //int pjw_account_create(int t_id, const char *domain, const char *server, const char *username, const char *password, const char *additional_headers, const char *c_to_url, int expires, int *out_acc_id);
26
24
  int pjw_account_create(int t_id, const char *json, int *out_acc_id);
27
25
 
28
- //int pjw_account_register(long acc_id, pj_bool_t autoreg);
29
26
  int pjw_account_register(long acc_id, const char *json);
30
27
 
31
28
  int pjw_account_unregister(long acc_id);
32
29
 
33
- //int pjw_call_create(long t_id, unsigned flags, const char *from_uri, const char *to_uri, const char *request_uri, const char *proxy_uri, const char *additional_headers, const char *realm, const char *username, const char *password, long *out_call_id, char *out_sip_call_id);
34
- int pjw_call_create(long t_id, const char *json, long *out_call_id, char *out_sip_call_id);
30
+ int pjw_request_create(long t_id, const char *json, long *out_request_id,
31
+ char *out_sip_call_id);
32
+
33
+ int pjw_request_respond(long request_id, const char *json);
34
+
35
+ int pjw_call_create(long t_id, const char *json, long *out_call_id,
36
+ char *out_sip_call_id);
35
37
 
36
- //int pjw_call_respond(long call_id, int code, const char *reason, const char *additional_headers);
37
38
  int pjw_call_respond(long call_id, const char *json);
38
39
 
39
- //int pjw_call_terminate(long call_id, int code, const char *reason, const char *additional_headers);
40
40
  int pjw_call_terminate(long call_id, const char *json);
41
41
 
42
- //int pjw_call_send_dtmf(long call_id, const char *digits, int mode);
43
42
  int pjw_call_send_dtmf(long call_id, const char *json);
44
43
 
45
- //int pjw_call_reinvite(long call_id, int hold, unsigned flags);
46
44
  int pjw_call_reinvite(long call_id, const char *json);
47
45
 
48
- //int pjw_call_send_request(long call_id, const char *method_name, const char *additional_headers, const char *body, const char *ct_type, const char *ct_subtype);
49
46
  int pjw_call_send_request(long call_id, const char *json);
50
47
 
51
- //int pjw_call_start_record_wav(long call_id, const char *file);
52
48
  int pjw_call_start_record_wav(long call_id, const char *file);
53
49
 
54
- //int pjw_call_start_play_wav(long call_id, const char *file);
55
50
  int pjw_call_start_play_wav(long call_id, const char *file);
56
51
 
57
- int pjw_call_stop_play_wav(long call_id);
52
+ int pjw_call_stop_play_wav(long call_id, const char *json);
58
53
 
59
- int pjw_call_stop_record_wav(long call_id);
54
+ int pjw_call_stop_record_wav(long call_id, const char *json);
60
55
 
61
- //int pjw_call_start_fax(long call_id, bool is_sender, const char *file);
62
56
  int pjw_call_start_fax(long call_id, const char *json);
63
57
 
64
- int pjw_call_stop_fax(long call_id);
58
+ int pjw_call_stop_fax(long call_id, const char *json);
65
59
 
66
- int pjw_call_get_stream_stat(long call_id, char *out_stats);
60
+ int pjw_call_get_stream_stat(long call_id, const char *json, char *out_stats);
67
61
 
68
- //int pjw_call_refer(long call_id, const char *dest_uri, const char *additional_headers, long *out_subscription_id);
69
- int pjw_call_refer(long call_id, const char *json, long *out_subscription_id);
62
+ // int pjw_call_refer(long call_id, const char *json, long
63
+ // *out_subscription_id);
70
64
 
71
65
  int pjw_call_get_info(long call_id, const char *required_info, char *out_info);
72
66
 
73
67
  int pjw_call_gen_string_replaces(long call_id, char *out_replaces);
74
68
 
75
- int pjw_packetdump_start(const char *dev, const char *file);
76
-
77
- int pjw_packetdump_stop();
69
+ int pjw_call_send_tcp_msg(long call_id, const char *json);
78
70
 
79
71
  int pjw_get_codecs(char *out_codecs);
80
72
 
@@ -82,18 +74,15 @@ int pjw_set_codecs(const char *in_codec_info);
82
74
 
83
75
  int __pjw_shutdown();
84
76
 
85
- //int pjw_notify(long subscriber_id, const char *content_type, const char *body, int subscription_state, const char *reason, const char *additional_headers);
86
77
  int pjw_notify(long subscriber_id, const char *json);
87
78
 
88
- //int pjw_notify_xfer(long subscriber_id, int subscription_state, int xfer_status_code, const char *xfer_status_text);
89
79
  int pjw_notify_xfer(long subscriber_id, const char *json);
90
80
 
91
81
  int pjw_register_pkg(const char *event, const char *accept);
92
82
 
93
- //int pjw_subscription_create(long transport_id, const char *event, const char *accept, const char *from_uri, const char *to_uri, const char *request_uri, const char *proxy_uri, const char *realm, const char *username, const char *password, long *out_subscription_id);
94
- int pjw_subscription_create(long transport_id, const char *json, long *out_subscription_id);
83
+ int pjw_subscription_create(long transport_id, const char *json,
84
+ long *out_subscription_id);
95
85
 
96
- //int pjw_subscription_subscribe(long subscription_id, int expires, const char *additional_headers);
97
86
  int pjw_subscription_subscribe(long subscription_id, const char *json);
98
87
 
99
88
  int pjw_log_level(long log_level);
@@ -103,5 +92,8 @@ int pjw_set_flags(unsigned flags);
103
92
  int pjw_dtmf_aggregation_on(int inter_digit_timer);
104
93
  int pjw_dtmf_aggregation_off();
105
94
 
95
+ int pjw_enable_telephone_event();
96
+ int pjw_disable_telephone_event();
97
+
106
98
  char *pjw_get_error();
107
99
  #endif
@@ -1,234 +0,0 @@
1
- #include <stdio.h>
2
- #include <pcap.h>
3
- #include <sys/socket.h>
4
- #include <arpa/inet.h>
5
- #include <netinet/if_ether.h>
6
- #include <netinet/udp.h>
7
-
8
- #include <pthread.h>
9
-
10
- #include "packetdumper.hpp"
11
-
12
- #include "boost/mem_fn.hpp"
13
-
14
-
15
- #define LOCK() pthread_mutex_lock(&_mutex);
16
- #define UNLOCK() pthread_mutex_unlock(&_mutex);
17
-
18
- PacketDumper::PacketDumper()
19
- : _handler(0), _dumper(0), _end_flag(false)
20
- {
21
- }
22
-
23
- PacketDumper::~PacketDumper()
24
- {
25
- _end_flag = true;
26
- pthread_join(_thread, NULL);
27
- //printf("PacketDumper destroyed\n");
28
- }
29
-
30
- bool PacketDumper::init(string dev, string file) {
31
- if(_handler){ return false; } // already initialized
32
-
33
- char errbuf[PCAP_ERRBUF_SIZE];
34
-
35
- _dev = dev;
36
-
37
- _handler = pcap_open_live(_dev.c_str(), 2000, 0, 0, errbuf);
38
- if(!_handler){
39
- printf("pcap_open_live(): %s\n", errbuf);
40
- return false;
41
- }
42
-
43
- this->datalink = pcap_datalink(_handler);
44
- //printf("pcap_datalink: %d\n",this->datalink);
45
- if(this->datalink != DLT_EN10MB && this->datalink != DLT_LINUX_SLL) {
46
- printf("pcap_datalink: unsupported datalink %d\n",this->datalink);
47
- return false;
48
- }
49
-
50
- if( pcap_setnonblock(_handler, 1, errbuf) == -1){
51
- printf("pcap_setnonblock(): %s\n", errbuf);
52
- return false;
53
- }
54
-
55
- _dumper = pcap_dump_open(_handler, file.c_str());
56
- if(!_dumper){
57
- printf("pcap_dump_open(): %s\n", pcap_geterr(_handler));
58
- return false;
59
- }
60
-
61
- bpf_u_int32 mask;
62
- bpf_u_int32 net;
63
-
64
- //if(pcap_lookupnet(_dev.c_str(), &net, &mask, errbuf) == -1){
65
- if(pcap_lookupnet(_dev.c_str(), &net, &mask, errbuf) < 0){
66
- printf("Couldn't get netmask for device %s: %s\n",
67
- _dev.c_str(), errbuf);
68
- return false;
69
- }
70
-
71
- if( pcap_compile(_handler, &_filter_program, "udp", 0, net) == -1 ) {
72
- printf("Failed to compile filter: %s\n", pcap_geterr(_handler));
73
- return false;
74
- }
75
-
76
- if(pcap_setfilter(_handler, &_filter_program) == -1) {
77
- printf("Couldn't install filter: %s\n", pcap_geterr(_handler));
78
- pcap_freecode(&_filter_program);
79
- return false;
80
- }
81
-
82
- pthread_mutex_init(&_mutex, NULL);
83
-
84
- if( pthread_create(&_thread, NULL, &thread_func, (void*)this) ){
85
- printf("pthread_create() failed\n");
86
- return false;
87
- }
88
-
89
- //printf("phread_create ok\n");
90
- return true;
91
- }
92
-
93
- bool PacketDumper::add_endpoint(uint32_t ipaddr, uint16_t port){
94
- LOCK();
95
- ipaddr_map::iterator iter = _awaited_endpoints.find(ipaddr);
96
- if( _awaited_endpoints.end() == iter ) {
97
- //printf("PacketDumper: adding IP MAP %X\n", ipaddr);
98
- port_set ps;
99
- ps.insert(port);
100
- _awaited_endpoints.insert( make_pair(ipaddr, ps) );
101
- } else {
102
- iter->second.insert(port);
103
- }
104
- //printf("PacketDumper: adding port %X:%d\n", ipaddr, port);
105
- UNLOCK();
106
- return true;
107
- }
108
-
109
- bool PacketDumper::remove_endpoint(uint32_t ipaddr, uint16_t port){
110
- bool res = false;
111
- LOCK();
112
- ipaddr_map::iterator im_iter = _awaited_endpoints.find(ipaddr);
113
- if( _awaited_endpoints.end() != im_iter ) {
114
- port_set::iterator ps_iter = im_iter->second.find(port);
115
- if( im_iter->second.end() != ps_iter ) {
116
- im_iter->second.erase(ps_iter);
117
- //printf("PacketDumper: Removing port %X:%d\n", ipaddr, port);
118
- res = true;
119
- }
120
- if(0 == im_iter->second.size()) {
121
- _awaited_endpoints.erase(im_iter);
122
- //printf("PacketDumper: Removing IP MAP %X\n", ipaddr);
123
- }
124
- }
125
- UNLOCK();
126
- return res;
127
- }
128
-
129
- void PacketDumper::process(){
130
- const u_char *packet;
131
- pcap_pkthdr hdr;
132
- ip_header* ip_h;
133
- udphdr *udp_h;
134
-
135
- packet = pcap_next(_handler, &hdr);
136
- if(packet)
137
- {
138
- bool dumpit;
139
- if(DLT_EN10MB == this->datalink) {
140
- ip_h = (ip_header*)(packet + sizeof(ether_header));
141
- u_int size_ip = IP_HL(ip_h)*4;
142
- udp_h = (udphdr*)(packet + sizeof(ether_header) + size_ip);
143
- } else {
144
- //Linux SLL cooked
145
- ip_h = (ip_header*)(packet + sizeof(dlt_linux_sll));
146
- u_int size_ip = IP_HL(ip_h)*4;
147
- udp_h = (udphdr*)(packet + sizeof(dlt_linux_sll) + size_ip);
148
- }
149
-
150
-
151
- //if(ip_h->ip_src == 0xb905adca || ip_h->ip_dst == 0xb905adca) {
152
- // printf("PacketDumper: packet received src=%X:%d dst=%X:%d\n", ip_h->ip_src, udp_h->source, ip_h->ip_dst, udp_h->dest);
153
- //}
154
-
155
- ipaddr_map::iterator im_iter;
156
-
157
- //Check packet source
158
- im_iter = _awaited_endpoints.find( ip_h->ip_src );
159
- if( im_iter != _awaited_endpoints.end() ) {
160
- port_set::iterator ps_iter = im_iter->second.find( udp_h->source);
161
- if( ps_iter != im_iter->second.end() ) {
162
- pcap_dump((u_char*)_dumper, &hdr, packet);
163
- if( pcap_dump_flush(_dumper) == -1){
164
- printf("pcap_dump_flush() error\n");
165
- }
166
- return;
167
- }
168
- }
169
-
170
-
171
- //Check packet dest
172
- im_iter = _awaited_endpoints.find( ip_h->ip_dst );
173
- if( im_iter != _awaited_endpoints.end() ) {
174
- port_set::iterator ps_iter = im_iter->second.find( udp_h->dest);
175
- if( ps_iter != im_iter->second.end() ) {
176
- pcap_dump((u_char*)_dumper, &hdr, packet);
177
- if( pcap_dump_flush(_dumper) == -1){
178
- printf("pcap_dump_flush() error\n");
179
- }
180
- return;
181
- }
182
- }
183
-
184
-
185
- }
186
- }
187
-
188
- static void *thread_func(void *vptr_args){
189
- //printf("entering thread_func\n");
190
- PacketDumper *t = (PacketDumper*)vptr_args;
191
- while(!t->_end_flag){
192
- usleep(10);
193
- pthread_mutex_lock(&t->_mutex);
194
- t->process();
195
- pthread_mutex_unlock(&t->_mutex);
196
- }
197
-
198
- if(t->_handler){
199
- pcap_close(t->_handler);
200
- }
201
- if(t->_dumper){
202
- pcap_dump_close(t->_dumper);
203
- }
204
-
205
- //printf("exiting thread_func\n");
206
- }
207
-
208
- int test() {
209
- PacketDumper pd;
210
- pd.init("bond1", "x.cap");
211
-
212
- uint32_t ip_host = 0xc0a8581c;
213
- uint32_t ip_net = htonl(ip_host);
214
- printf("net:%X\n",ip_net);
215
-
216
- uint16_t port_host = 5060;
217
- uint16_t port_net = htons(port_host);
218
- printf("net:%X\n",port_net);
219
-
220
- pd.add_endpoint( inet_addr("192.168.88.2"), htons(5060) );
221
- pd.add_endpoint( inet_addr("192.168.88.8"), htons(5060) );
222
- pd.add_endpoint( inet_addr("192.168.88.3"), htons(5060) );
223
- pd.add_endpoint( inet_addr("192.168.88.28"), htons(5060) );
224
- pd.add_endpoint( inet_addr("192.168.88.4"), htons(5060) );
225
- pd.add_endpoint( inet_addr("192.168.88.66"), htons(5060) );
226
- pd.add_endpoint( inet_addr("192.168.88.64"), htons(5060) );
227
- pd.add_endpoint( inet_addr("192.168.88.62"), htons(5060) );
228
-
229
- pd.remove_endpoint( inet_addr("192.168.88.4"), htons(5060) );
230
- pd.remove_endpoint( inet_addr("192.168.88.66"), htons(5060) );
231
- for(;;) {
232
- ;
233
- }
234
- }
@@ -1,67 +0,0 @@
1
- #ifndef __TCPDUMPER_H__
2
- #define __TCPDUMPER_H__
3
-
4
- #include <pcap.h>
5
-
6
- #include <string>
7
- #include <pthread.h>
8
- #include "boost/bind.hpp"
9
-
10
- #include <set>
11
- #include <map>
12
-
13
- using namespace std;
14
-
15
- class PacketDumper
16
- {
17
- public:
18
- PacketDumper();
19
- ~PacketDumper();
20
- bool init(string dev, string file);
21
- bool add_endpoint(uint32_t ipaddr, uint16_t port);
22
- bool remove_endpoint(uint32_t ipaddr, uint16_t port);
23
- void process();
24
- pthread_mutex_t _mutex;
25
- bool _end_flag;
26
- string _dev;
27
- pcap_t *_handler;
28
- pcap_dumper_t *_dumper;
29
- private:
30
- string _filter;
31
- bpf_program _filter_program;
32
- pthread_t _thread;
33
- int datalink;
34
- typedef set<uint16_t> port_set;
35
- typedef map <uint32_t, port_set> ipaddr_map;
36
- ipaddr_map _awaited_endpoints;
37
- };
38
-
39
- static void *thread_func(void *vptr_args);
40
-
41
- struct dlt_linux_sll {
42
- u_short packet_type;
43
- u_short ARPHRD;
44
- u_short slink_length;
45
- u_char bytes[8];
46
- u_short ether_type;
47
- };
48
-
49
- struct ip_header {
50
- u_char ip_version_headerlength; // version << 4 | header length >> 2
51
- #define IP_HL(ip) (((ip)->ip_version_headerlength) & 0x0f)
52
- #define IP_V(ip) (((ip)->ip_version_headerlength) >> 4)
53
- u_char ip_tos; //Type of service
54
- u_short ip_len; // total length
55
- u_short ip_id; // identification
56
- u_short ip_off; //fragment offset field
57
-
58
- u_char ip_ttl;
59
- u_char ip_p;
60
- u_short ip_sum;
61
- u_int ip_src;
62
- u_int ip_dst;
63
- };
64
-
65
-
66
-
67
- #endif