oversip 1.1.0.beta5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/etc/oversip.conf +16 -4
  2. data/etc/proxies.conf +8 -9
  3. data/etc/server.rb +59 -0
  4. data/ext/sip_parser/sip_parser.c +12066 -11975
  5. data/ext/sip_parser/sip_parser.h +1 -0
  6. data/ext/sip_parser/sip_parser_ruby.c +15 -4
  7. data/ext/utils/haproxy_protocol.c +4 -1
  8. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +2 -2
  9. data/lib/oversip/config.rb +50 -38
  10. data/lib/oversip/default_server.rb +12 -0
  11. data/lib/oversip/launcher.rb +10 -35
  12. data/lib/oversip/master_process.rb +2 -2
  13. data/lib/oversip/proxies_config.rb +2 -2
  14. data/lib/oversip/sip/client_transaction.rb +1 -7
  15. data/lib/oversip/sip/grammar/uri.rb +23 -1
  16. data/lib/oversip/sip/listeners/{reactor.rb → connection.rb} +16 -2
  17. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +1 -1
  18. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +1 -1
  19. data/lib/oversip/sip/listeners/tcp_client.rb +2 -3
  20. data/lib/oversip/sip/listeners/{tcp_reactor.rb → tcp_connection.rb} +14 -2
  21. data/lib/oversip/sip/listeners/tcp_server.rb +2 -5
  22. data/lib/oversip/sip/listeners/tls_client.rb +15 -12
  23. data/lib/oversip/sip/listeners/tls_server.rb +11 -11
  24. data/lib/oversip/sip/listeners/{tls_tunnel_reactor.rb → tls_tunnel_connection.rb} +20 -20
  25. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +2 -5
  26. data/lib/oversip/sip/listeners/{udp_reactor.rb → udp_connection.rb} +4 -4
  27. data/lib/oversip/sip/listeners.rb +6 -10
  28. data/lib/oversip/sip/message.rb +4 -3
  29. data/lib/oversip/sip/message_processor.rb +17 -17
  30. data/lib/oversip/sip/modules/core.rb +18 -13
  31. data/lib/oversip/sip/modules/user_assertion.rb +7 -53
  32. data/lib/oversip/sip/proxy.rb +3 -3
  33. data/lib/oversip/sip/request.rb +2 -0
  34. data/lib/oversip/sip/rfc3263.rb +3 -3
  35. data/lib/oversip/sip/sip.rb +6 -0
  36. data/lib/oversip/sip/transport_manager.rb +8 -8
  37. data/lib/oversip/tls.rb +18 -22
  38. data/lib/oversip/version.rb +1 -1
  39. data/lib/oversip/websocket/constants.rb +0 -1
  40. data/lib/oversip/websocket/http_request.rb +4 -8
  41. data/lib/oversip/websocket/launcher.rb +83 -139
  42. data/lib/oversip/websocket/listeners/connection.rb +47 -0
  43. data/lib/oversip/websocket/{ws_apps/ipv4_ws_sip_app.rb → listeners/ipv4_ws_server.rb} +3 -3
  44. data/lib/oversip/websocket/{ws_apps/ipv4_wss_sip_app.rb → listeners/ipv4_wss_server.rb} +2 -2
  45. data/lib/oversip/websocket/listeners/ipv4_wss_tunnel_server.rb +21 -0
  46. data/lib/oversip/websocket/{ws_apps/ipv6_ws_sip_app.rb → listeners/ipv6_ws_server.rb} +3 -3
  47. data/lib/oversip/websocket/{ws_apps/ipv6_wss_sip_app.rb → listeners/ipv6_wss_server.rb} +2 -3
  48. data/lib/oversip/websocket/listeners/ipv6_wss_tunnel_server.rb +21 -0
  49. data/lib/oversip/websocket/listeners/{tcp_server.rb → ws_server.rb} +63 -43
  50. data/lib/oversip/websocket/listeners/{tls_server.rb → wss_server.rb} +14 -13
  51. data/lib/oversip/websocket/listeners/{tls_tunnel_server.rb → wss_tunnel_server.rb} +36 -10
  52. data/lib/oversip/websocket/listeners.rb +10 -9
  53. data/lib/oversip/websocket/websocket.rb +13 -0
  54. data/lib/oversip/websocket/ws_framing.rb +35 -97
  55. data/lib/oversip/websocket/ws_sip_app.rb +120 -0
  56. data/lib/oversip.rb +1 -1
  57. data/test/oversip_test_helper.rb +2 -2
  58. data/test/test_http_parser.rb +2 -2
  59. data/test/test_sip_parser.rb +18 -3
  60. data/test/test_uri.rb +44 -0
  61. metadata +39 -42
  62. data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +0 -15
  63. data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +0 -15
  64. data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +0 -15
  65. data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +0 -15
  66. data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +0 -15
  67. data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +0 -15
  68. data/lib/oversip/websocket/ws_app.rb +0 -77
  69. data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +0 -23
  70. data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +0 -156
  71. data/lib/oversip/websocket/ws_apps.rb +0 -9
@@ -128,6 +128,7 @@ typedef struct struct_message {
128
128
  msg_element_cb from_tag;
129
129
  msg_element_cb to_tag;
130
130
  msg_element_cb contact_params;
131
+ msg_has_param_cb contact_has_reg_id;
131
132
  /* Header value without header params. */
132
133
  header_core_value_cb header_core_value;
133
134
  header_param_cb header_param;
@@ -50,6 +50,7 @@ static ID id_to_tag;
50
50
  static ID id_routes;
51
51
  static ID id_contact;
52
52
  static ID id_contact_params;
53
+ static ID id_contact_has_reg_id;
53
54
  static ID id_require;
54
55
  static ID id_proxy_require;
55
56
  static ID id_supported;
@@ -362,7 +363,7 @@ static void msg_via_has_rport(VALUE parsed)
362
363
  static void msg_via_has_alias(VALUE parsed)
363
364
  {
364
365
  TRACE();
365
-
366
+
366
367
  rb_ivar_set(parsed, id_via_has_alias, Qtrue);
367
368
  }
368
369
 
@@ -588,7 +589,7 @@ static void uri_has_param(VALUE parsed, enum uri_owner owner, enum uri_param_nam
588
589
  TRACE();
589
590
 
590
591
  VALUE p;
591
-
592
+
592
593
  switch(param_name) {
593
594
  case uri_param_lr: p = id_uri_lr_param; break;
594
595
  case uri_param_ob: p = id_uri_ob_param; break;
@@ -683,6 +684,14 @@ static void msg_contact_params(VALUE parsed, const char *at, size_t length)
683
684
  }
684
685
 
685
686
 
687
+ static void msg_contact_has_reg_id(VALUE parsed)
688
+ {
689
+ TRACE();
690
+
691
+ rb_ivar_set(parsed, id_contact_has_reg_id, Qtrue);
692
+ }
693
+
694
+
686
695
  static void option_tag(VALUE parsed, enum header_field header_field, const char *at, size_t length)
687
696
  {
688
697
  TRACE();
@@ -786,6 +795,7 @@ VALUE SipMessageParser_alloc(VALUE klass)
786
795
  parser->message.from_tag = msg_from_tag;
787
796
  parser->message.to_tag = msg_to_tag;
788
797
  parser->message.contact_params = msg_contact_params;
798
+ parser->message.contact_has_reg_id = msg_contact_has_reg_id;
789
799
  parser->message.header_core_value = header_core_value;
790
800
  parser->message.header_param = header_param;
791
801
  parser->message.option_tag = option_tag;
@@ -1178,9 +1188,9 @@ void Init_sip_parser()
1178
1188
  rb_define_method(cSIPMessageParser, "duplicated_core_header?", SipMessageParser_has_duplicated_core_header,0);
1179
1189
  rb_define_method(cSIPMessageParser, "missing_core_header?", SipMessageParser_has_missing_core_header,0);
1180
1190
  rb_define_method(cSIPMessageParser, "post_parsing", SipMessageParser_post_parsing,0);
1181
-
1191
+
1182
1192
  rb_define_module_function(cSIPMessageParser, "headerize", SipMessageParser_Class_headerize,1);
1183
-
1193
+
1184
1194
  init_common_headers();
1185
1195
  init_short_headers();
1186
1196
 
@@ -1213,6 +1223,7 @@ void Init_sip_parser()
1213
1223
  id_routes = rb_intern("@routes");
1214
1224
  id_contact = rb_intern("@contact");
1215
1225
  id_contact_params = rb_intern("@contact_params");
1226
+ id_contact_has_reg_id = rb_intern("@contact_has_reg_id");
1216
1227
  id_require = rb_intern("@require");
1217
1228
  id_proxy_require = rb_intern("@proxy_require");
1218
1229
  id_supported = rb_intern("@supported");
@@ -6152,12 +6152,15 @@ case 374:
6152
6152
 
6153
6153
  #line 77 "haproxy_protocol.rl"
6154
6154
 
6155
- if(finished && len == p-str)
6155
+ /* if(finished && len == p-str) */
6156
+ if(finished)
6156
6157
  haproxy_protocol.valid = 1;
6157
6158
 
6158
6159
  /* Write the number of read bytes so the HAProxy Protocol line can be removed. */
6159
6160
  haproxy_protocol.total_len = (int)(p - str);
6160
6161
 
6162
+ printf("**** haproxy_protocol.total_len = %i\n", haproxy_protocol.total_len);
6163
+
6161
6164
  return haproxy_protocol;
6162
6165
  }
6163
6166
 
@@ -14,7 +14,7 @@ static VALUE cUtf8Validator;
14
14
  * Ruby functions.
15
15
  */
16
16
 
17
- VALUE WsFrammingUtils_unmask(VALUE self, VALUE payload, VALUE mask)
17
+ VALUE WsFramingUtils_unmask(VALUE self, VALUE payload, VALUE mask)
18
18
  {
19
19
  char *payload_str, *mask_str;
20
20
  long payload_len; /* mask length is always 4 bytes. */
@@ -127,7 +127,7 @@ void Init_ws_framing_utils()
127
127
  mFramingUtils = rb_define_module_under(mWebSocket, "FramingUtils");
128
128
  cUtf8Validator = rb_define_class_under(mFramingUtils, "Utf8Validator", rb_cObject);
129
129
 
130
- rb_define_module_function(mFramingUtils, "unmask", WsFrammingUtils_unmask,2);
130
+ rb_define_module_function(mFramingUtils, "unmask", WsFramingUtils_unmask,2);
131
131
 
132
132
  rb_define_alloc_func(cUtf8Validator, Utf8Validator_alloc);
133
133
  rb_define_method(cUtf8Validator, "reset", Utf8Validator_reset,0);
@@ -38,6 +38,7 @@ module OverSIP
38
38
  :listen_port_tls => 5061,
39
39
  :use_tls_tunnel => false,
40
40
  :listen_port_tls_tunnel => 5062,
41
+ :callback_on_client_tls_handshake => true,
41
42
  :local_domains => nil,
42
43
  :tcp_keepalive_interval => nil,
43
44
  :record_route_hostname_tls_ipv4 => nil,
@@ -54,6 +55,7 @@ module OverSIP
54
55
  :listen_port_tls => 10443,
55
56
  :use_tls_tunnel => false,
56
57
  :listen_port_tls_tunnel => 10444,
58
+ :callback_on_client_tls_handshake => true,
57
59
  :max_ws_message_size => 65536,
58
60
  :max_ws_frame_size => 65536,
59
61
  :ws_keepalive_interval => nil
@@ -67,52 +69,54 @@ module OverSIP
67
69
 
68
70
  CONFIG_VALIDATIONS = {
69
71
  :core => {
70
- :nameservers => [ :ipv4, :multi_value ],
71
- :syslog_facility => [
72
+ :nameservers => [ :ipv4, :multi_value ],
73
+ :syslog_facility => [
72
74
  [ :choices,
73
75
  %w{ kern user daemon local0 local1 local2 local3 local4 local5 local6 local7 } ]
74
76
  ],
75
- :syslog_level => [
77
+ :syslog_level => [
76
78
  [ :choices,
77
79
  %w{ debug info notice warn error crit } ]
78
80
  ],
79
81
  },
80
82
  :sip => {
81
- :sip_udp => :boolean,
82
- :sip_tcp => :boolean,
83
- :sip_tls => :boolean,
84
- :enable_ipv4 => :boolean,
85
- :listen_ipv4 => :ipv4,
86
- :enable_ipv6 => :boolean,
87
- :listen_ipv6 => :ipv6,
88
- :listen_port => :port,
89
- :listen_port_tls => :port,
90
- :use_tls_tunnel => :boolean,
91
- :listen_port_tls_tunnel => :port,
92
- :local_domains => [ :domain, :multi_value ],
93
- :tcp_keepalive_interval => [ :fixnum, [ :greater_equal_than, 180 ] ],
94
- :record_route_hostname_tls_ipv4 => :domain,
95
- :record_route_hostname_tls_ipv6 => :domain,
83
+ :sip_udp => :boolean,
84
+ :sip_tcp => :boolean,
85
+ :sip_tls => :boolean,
86
+ :enable_ipv4 => :boolean,
87
+ :listen_ipv4 => :ipv4,
88
+ :enable_ipv6 => :boolean,
89
+ :listen_ipv6 => :ipv6,
90
+ :listen_port => :port,
91
+ :listen_port_tls => :port,
92
+ :use_tls_tunnel => :boolean,
93
+ :listen_port_tls_tunnel => :port,
94
+ :callback_on_client_tls_handshake => :boolean,
95
+ :local_domains => [ :domain, :multi_value ],
96
+ :tcp_keepalive_interval => [ :fixnum, [ :greater_equal_than, 180 ] ],
97
+ :record_route_hostname_tls_ipv4 => :domain,
98
+ :record_route_hostname_tls_ipv6 => :domain,
96
99
  },
97
100
  :websocket => {
98
- :sip_ws => :boolean,
99
- :sip_wss => :boolean,
100
- :enable_ipv4 => :boolean,
101
- :listen_ipv4 => :ipv4,
102
- :enable_ipv6 => :boolean,
103
- :listen_ipv6 => :ipv6,
104
- :listen_port => :port,
105
- :listen_port_tls => :port,
106
- :use_tls_tunnel => :boolean,
107
- :listen_port_tls_tunnel => :port,
108
- :max_ws_message_size => [ :fixnum, [ :minor_than, 1048576 ] ],
109
- :max_ws_frame_size => [ :fixnum, [ :minor_than, 1048576 ] ],
110
- :ws_keepalive_interval => [ :fixnum, [ :greater_equal_than, 180 ] ]
101
+ :sip_ws => :boolean,
102
+ :sip_wss => :boolean,
103
+ :enable_ipv4 => :boolean,
104
+ :listen_ipv4 => :ipv4,
105
+ :enable_ipv6 => :boolean,
106
+ :listen_ipv6 => :ipv6,
107
+ :listen_port => :port,
108
+ :listen_port_tls => :port,
109
+ :use_tls_tunnel => :boolean,
110
+ :listen_port_tls_tunnel => :port,
111
+ :callback_on_client_tls_handshake => :boolean,
112
+ :max_ws_message_size => [ :fixnum, [ :minor_than, 1048576 ] ],
113
+ :max_ws_frame_size => [ :fixnum, [ :minor_than, 1048576 ] ],
114
+ :ws_keepalive_interval => [ :fixnum, [ :greater_equal_than, 180 ] ]
111
115
  },
112
116
  :tls => {
113
- :public_cert => [ :readable_file, :tls_pem_chain ],
114
- :private_cert => [ :readable_file, :tls_pem_private ],
115
- :ca_dir => :readable_dir
117
+ :public_cert => [ :readable_file, :tls_pem_chain ],
118
+ :private_cert => [ :readable_file, :tls_pem_private ],
119
+ :ca_dir => :readable_dir
116
120
  }
117
121
  }
118
122
 
@@ -306,7 +310,7 @@ module OverSIP
306
310
 
307
311
  if ( @use_sip_udp_or_tcp or @use_sip_tls ) and @configuration[:sip][:listen_ipv4] == nil and @configuration[:sip][:enable_ipv4]
308
312
  unless (@configuration[:sip][:listen_ipv4] = discover_local_ip(:ipv4))
309
- log_system_warn "dissabling IPv4 for SIP"
313
+ log_system_warn "disabling IPv4 for SIP"
310
314
  @configuration[:sip][:listen_ipv4] = nil
311
315
  @configuration[:sip][:enable_ipv4] = false
312
316
  end
@@ -314,7 +318,7 @@ module OverSIP
314
318
 
315
319
  if ( @use_sip_udp_or_tcp or @use_sip_tls ) and @configuration[:sip][:listen_ipv6] == nil and @configuration[:sip][:enable_ipv6]
316
320
  unless (@configuration[:sip][:listen_ipv6] = discover_local_ip(:ipv6))
317
- log_system_warn "dissabling IPv6 for SIP"
321
+ log_system_warn "disabling IPv6 for SIP"
318
322
  @configuration[:sip][:listen_ipv6] = nil
319
323
  @configuration[:sip][:enable_ipv6] = false
320
324
  end
@@ -322,7 +326,7 @@ module OverSIP
322
326
 
323
327
  if ( @use_sip_ws or @use_sip_wss ) and @configuration[:websocket][:listen_ipv4] == nil and @configuration[:websocket][:enable_ipv4]
324
328
  unless (@configuration[:websocket][:listen_ipv4] = discover_local_ip(:ipv4))
325
- log_system_warn "dissabling IPv4 for WebSocket"
329
+ log_system_warn "disabling IPv4 for WebSocket"
326
330
  @configuration[:websocket][:listen_ipv4] = nil
327
331
  @configuration[:websocket][:enable_ipv4] = false
328
332
  end
@@ -330,7 +334,7 @@ module OverSIP
330
334
 
331
335
  if ( @use_sip_ws or @use_sip_wss ) and @configuration[:websocket][:listen_ipv6] == nil and @configuration[:websocket][:enable_ipv6]
332
336
  unless (@configuration[:websocket][:listen_ipv6] = discover_local_ip(:ipv6))
333
- log_system_warn "dissabling IPv6 for WebSocket"
337
+ log_system_warn "disabling IPv6 for WebSocket"
334
338
  @configuration[:websocket][:listen_ipv6] = nil
335
339
  @configuration[:websocket][:enable_ipv6] = false
336
340
  end
@@ -420,6 +424,14 @@ module OverSIP
420
424
  end
421
425
  end
422
426
 
427
+ unless @configuration[:sip][:use_tls_tunnel]
428
+ @configuration[:sip][:listen_port_tls_tunnel] = nil
429
+ end
430
+
431
+ unless @configuration[:websocket][:use_tls_tunnel]
432
+ @configuration[:websocket][:listen_port_tls_tunnel] = nil
433
+ end
434
+
423
435
  [:udp, :tcp].each do |transport|
424
436
  transport_str = transport.to_s.upcase
425
437
  binds[transport].each do |ip, port|
@@ -27,6 +27,14 @@ module OverSIP
27
27
  log_system_notice "on_request() callback is not defined"
28
28
  end
29
29
 
30
+ def self.on_client_tls_handshake connection, pems
31
+ log_system_notice "on_client_tls_handshake() callback is not defined"
32
+ end
33
+
34
+ def self.on_server_tls_handshake connection, pems
35
+ log_system_notice "on_server_tls_handshake() callback is not defined"
36
+ end
37
+
30
38
  end
31
39
 
32
40
  module WebSocketEvents
@@ -41,6 +49,10 @@ module OverSIP
41
49
  log_system_notice "on_disconnection() callback is not defined"
42
50
  end
43
51
 
52
+ def self.on_client_tls_handshake connection, pems
53
+ log_system_notice "on_client_tls_handshake() callback is not defined"
54
+ end
55
+
44
56
  end
45
57
 
46
58
  end
@@ -106,8 +106,9 @@ module OverSIP::Launcher
106
106
  ::OverSIP::TLS.module_init
107
107
  ::OverSIP::SIP.module_init
108
108
  ::OverSIP::SIP::RFC3263.module_init
109
+ ::OverSIP::WebSocket.module_init
109
110
  ::OverSIP::WebSocket::WsFraming.class_init
110
- ::OverSIP::WebSocket::WsApp.class_init
111
+ ::OverSIP::WebSocket::WsSipApp.class_init
111
112
 
112
113
  # I'm the syslogger process.
113
114
  else
@@ -211,15 +212,13 @@ module OverSIP::Launcher
211
212
  # WebSocket IPv4 TCP SIP server.
212
213
  if configuration[:websocket][:enable_ipv4]
213
214
  ::OverSIP::WebSocket::Launcher.run true, :ipv4, configuration[:websocket][:listen_ipv4],
214
- configuration[:websocket][:listen_port], :tcp,
215
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
215
+ configuration[:websocket][:listen_port], :ws
216
216
  end
217
217
 
218
218
  # WebSocket IPv6 TCP SIP server.
219
219
  if configuration[:websocket][:enable_ipv6]
220
220
  ::OverSIP::WebSocket::Launcher.run true, :ipv6, configuration[:websocket][:listen_ipv6],
221
- configuration[:websocket][:listen_port], :tcp,
222
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
221
+ configuration[:websocket][:listen_port], :ws
223
222
  end
224
223
  end
225
224
 
@@ -228,27 +227,23 @@ module OverSIP::Launcher
228
227
  # WebSocket IPv4 TLS SIP server (native).
229
228
  if configuration[:websocket][:enable_ipv4]
230
229
  ::OverSIP::WebSocket::Launcher.run true, :ipv4, configuration[:websocket][:listen_ipv4],
231
- configuration[:websocket][:listen_port_tls], :tls,
232
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
230
+ configuration[:websocket][:listen_port_tls], :wss
233
231
  end
234
232
 
235
233
  # WebSocket IPv6 TLS SIP server (native).
236
234
  if configuration[:websocket][:enable_ipv6]
237
235
  ::OverSIP::WebSocket::Launcher.run true, :ipv6, configuration[:websocket][:listen_ipv6],
238
- configuration[:websocket][:listen_port_tls], :tls,
239
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
236
+ configuration[:websocket][:listen_port_tls], :wss
240
237
  end
241
238
  else
242
239
  # WebSocket IPv4 TLS SIP server (Stud).
243
240
  if configuration[:websocket][:enable_ipv4]
244
241
  ::OverSIP::WebSocket::Launcher.run true, :ipv4, "127.0.0.1",
245
- configuration[:websocket][:listen_port_tls_tunnel], :tls_tunnel,
246
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL,
242
+ configuration[:websocket][:listen_port_tls_tunnel], :wss_tunnel,
247
243
  configuration[:websocket][:listen_ipv4],
248
244
  configuration[:websocket][:listen_port_tls]
249
245
  ::OverSIP::WebSocket::Launcher.run false, :ipv4, configuration[:websocket][:listen_ipv4],
250
- configuration[:websocket][:listen_port_tls], :tls,
251
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
246
+ configuration[:websocket][:listen_port_tls], :wss
252
247
 
253
248
  # Spawn a Stud process.
254
249
  spawn_stud_process options,
@@ -260,13 +255,11 @@ module OverSIP::Launcher
260
255
  # WebSocket IPv6 TLS SIP server (Stud).
261
256
  if configuration[:sip][:enable_ipv6]
262
257
  ::OverSIP::WebSocket::Launcher.run true, :ipv6, "::1",
263
- configuration[:websocket][:listen_port_tls_tunnel], :tls_tunnel,
264
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL,
258
+ configuration[:websocket][:listen_port_tls_tunnel], :wss_tunnel,
265
259
  configuration[:websocket][:listen_ipv6],
266
260
  configuration[:websocket][:listen_port_tls]
267
261
  ::OverSIP::WebSocket::Launcher.run false, :ipv6, configuration[:websocket][:listen_ipv6],
268
- configuration[:websocket][:listen_port_tls], :tls,
269
- ::OverSIP::WebSocket::WS_SIP_PROTOCOL
262
+ configuration[:websocket][:listen_port_tls], :wss
270
263
 
271
264
  # Spawn a Stud process.
272
265
  spawn_stud_process options,
@@ -278,24 +271,6 @@ module OverSIP::Launcher
278
271
  end
279
272
 
280
273
 
281
- # TEST: WebSocket Autobahn server.
282
- #if configuration[:websocket][:sip_ws]
283
- # if configuration[:websocket][:enable_ipv4]
284
- # ::OverSIP::WebSocket::Launcher.run true, :ipv4, configuration[:websocket][:listen_ipv4],
285
- # 9001, :tcp,
286
- # ::OverSIP::WebSocket::WS_AUTOBAHN_PROTOCOL
287
- # end
288
- #end
289
- #
290
- #if configuration[:websocket][:sip_wss]
291
- # if configuration[:websocket][:enable_ipv4]
292
- # ::OverSIP::WebSocket::Launcher.run true, :ipv4, configuration[:websocket][:listen_ipv4],
293
- # 9002, :tls,
294
- # ::OverSIP::WebSocket::WS_AUTOBAHN_PROTOCOL
295
- # end
296
- #end
297
-
298
-
299
274
  # Change process permissions if requested.
300
275
  set_user_group(options[:user], options[:group])
301
276
 
@@ -43,6 +43,7 @@ require "oversip/sip/tags.rb"
43
43
  require "oversip/sip/rfc3263.rb"
44
44
  require "oversip/sip/proxy.rb"
45
45
 
46
+ require "oversip/websocket/websocket.rb"
46
47
  require "oversip/websocket/ws_http_parser.so"
47
48
  require "oversip/websocket/constants.rb"
48
49
  require "oversip/websocket/http_request.rb"
@@ -50,8 +51,7 @@ require "oversip/websocket/listeners.rb"
50
51
  require "oversip/websocket/launcher.rb"
51
52
  require "oversip/websocket/ws_framing_utils.so"
52
53
  require "oversip/websocket/ws_framing.rb"
53
- require "oversip/websocket/ws_app.rb"
54
- require "oversip/websocket/ws_apps.rb"
54
+ require "oversip/websocket/ws_sip_app.rb"
55
55
 
56
56
  require "oversip/sip/modules/core.rb"
57
57
  require "oversip/sip/modules/user_assertion.rb"
@@ -23,7 +23,7 @@ module OverSIP
23
23
  :timer_B => 32,
24
24
  :timer_C => 120,
25
25
  :timer_F => 32,
26
- :tls_validation => false
26
+ :callback_on_server_tls_handshake => true
27
27
  }
28
28
 
29
29
  PROXY_CONFIG_VALIDATIONS = {
@@ -40,7 +40,7 @@ module OverSIP
40
40
  :timer_B => [ :fixnum, [ :greater_equal_than, 2 ], [ :minor_equal_than, 64 ] ],
41
41
  :timer_C => [ :fixnum, [ :greater_equal_than, 8 ], [ :minor_equal_than, 180 ] ],
42
42
  :timer_F => [ :fixnum, [ :greater_equal_than, 2 ], [ :minor_equal_than, 64 ] ],
43
- :tls_validation => :boolean
43
+ :callback_on_server_tls_handshake => :boolean
44
44
  }
45
45
 
46
46
  def self.load proxies_yaml, reload=false
@@ -55,7 +55,7 @@ module OverSIP::SIP
55
55
  end
56
56
  end
57
57
 
58
- @connection = ::OverSIP::SIP::TransportManager.get_connection @server_klass, @ip, @port, self, transaction_conf[:tls_validation]
58
+ @connection = ::OverSIP::SIP::TransportManager.get_connection @server_klass, @ip, @port, self, transaction_conf[:callback_on_server_tls_handshake]
59
59
  end
60
60
 
61
61
  # Ensure the request has Content-Length. Add it otherwise.
@@ -187,9 +187,6 @@ module OverSIP::SIP
187
187
  # Set server transaction variables to the response.
188
188
  response.tvars = @request.tvars
189
189
 
190
- # Set original request's connection variables to the response.
191
- response.cvars = @request.cvars
192
-
193
190
  # Provisional response
194
191
  if response.status_code < 200
195
192
  case @state
@@ -506,9 +503,6 @@ module OverSIP::SIP
506
503
  # Set server transaction variables to the response.
507
504
  response.tvars = @request.tvars
508
505
 
509
- # Set original request's connection variables to the response.
510
- response.cvars = @request.cvars
511
-
512
506
  # Provisional response
513
507
  if response.status_code < 200
514
508
  case @state
@@ -1,7 +1,7 @@
1
1
  module OverSIP::SIP
2
2
 
3
3
  class Uri
4
- attr_reader :scheme, :user, :host, :host_type, :port, :params, :transport_param, :ovid_param, :phone_context_param, :headers
4
+ attr_reader :scheme, :user, :host, :host_type, :port, :params, :transport_param, :phone_context_param, :ovid_param, :headers
5
5
  attr_accessor :uri_modified
6
6
 
7
7
  def scheme= value
@@ -63,6 +63,28 @@ module OverSIP::SIP
63
63
  false
64
64
  end
65
65
 
66
+ def transport_param= value
67
+ return nil unless @scheme == :sip or @scheme == :sips
68
+ if value
69
+ @transport_param = value.to_sym
70
+ set_param "transport", value.to_s
71
+ else
72
+ @transport_param = nil
73
+ del_param "transport"
74
+ end
75
+ end
76
+
77
+ def phone_context_param= value
78
+ return nil unless @scheme == :tel
79
+ if value
80
+ @phone_context_param = value.to_sym
81
+ set_param "phone-context", value.to_s
82
+ else
83
+ @phone_context_param = nil
84
+ del_param "phone-context"
85
+ end
86
+ end
87
+
66
88
  def lr_param?
67
89
  @lr_param ? true : false
68
90
  end
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class Reactor < ::EM::Connection
3
+ class Connection < ::EM::Connection
4
4
 
5
5
  include ::OverSIP::Logger
6
6
  include ::OverSIP::SIP::MessageProcessor
@@ -19,10 +19,14 @@ module OverSIP::SIP
19
19
  end
20
20
  end
21
21
 
22
+
23
+ attr_reader :cvars
24
+
22
25
  def initialize
23
26
  @parser = ::OverSIP::SIP::MessageParser.new
24
27
  @buffer = ::IO::Buffer.new
25
28
  @state = :init
29
+ @cvars = {}
26
30
 
27
31
  # Set the socket sending error handling to report the error:
28
32
  # :ERRORHANDLING_KILL, :ERRORHANDLING_IGNORE, :ERRORHANDLING_REPORT
@@ -33,7 +37,17 @@ module OverSIP::SIP
33
37
  log_system_error "Socket sending error: #{error.inspect}, #{data.inspect}"
34
38
  end
35
39
 
36
- end # class Reactor
40
+ def transport
41
+ self.class.transport
42
+ end
43
+
44
+ def open?
45
+ ! error?
46
+ end
47
+
48
+ # close() method causes @local_closed = true.
49
+ alias close close_connection_after_writing
50
+ end
37
51
 
38
52
  end
39
53
 
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class IPv4UdpServer < UdpReactor
3
+ class IPv4UdpServer < UdpConnection
4
4
 
5
5
  @ip_type = :ipv4
6
6
  @transport = :udp
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class IPv6UdpServer < UdpReactor
3
+ class IPv6UdpServer < UdpConnection
4
4
 
5
5
  @ip_type = :ipv6
6
6
  @transport = :udp
@@ -1,12 +1,12 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class TcpClient < TcpReactor
3
+ class TcpClient < TcpConnection
4
4
 
5
5
  attr_reader :connected
6
6
  attr_reader :pending_client_transactions
7
7
 
8
8
  def initialize ip, port
9
- # NOTE: The parent class implementing "initialize" method is Reactor, and allows no arguments.
9
+ # NOTE: The parent class implementing "initialize" method is Connection, and allows no arguments.
10
10
  # If we call just "super" from here it will fail since "ip" and "port" will be passed as
11
11
  # arguments. So we must use "super()" and we are done (no arguments are passed to parent).
12
12
  super()
@@ -19,7 +19,6 @@ module OverSIP::SIP
19
19
 
20
20
  ### TODO: make it configurable.
21
21
  set_pending_connect_timeout 2.0
22
-
23
22
  end
24
23
 
25
24
 
@@ -1,11 +1,23 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class TcpReactor < Reactor
3
+ class TcpConnection < Connection
4
4
 
5
5
  # Max size (bytes) of the buffered data when receiving message headers
6
6
  # (avoid DoS attacks).
7
7
  HEADERS_MAX_SIZE = 16384
8
8
 
9
+ def remote_ip_type
10
+ @remote_ip_type || self.class.ip_type
11
+ end
12
+
13
+ def remote_ip
14
+ @remote_ip
15
+ end
16
+
17
+ def remote_port
18
+ @remote_port
19
+ end
20
+
9
21
  def receive_data data
10
22
  @state == :ignore and return
11
23
  @buffer << data
@@ -104,7 +116,7 @@ module OverSIP::SIP
104
116
  @msg.source_port = @remote_port
105
117
  @msg.source_ip_type = @remote_ip_type || self.class.ip_type
106
118
 
107
- unless valid_message?
119
+ unless valid_message? @parser
108
120
  close_connection_after_writing
109
121
  @state = :ignore
110
122
  return false
@@ -1,6 +1,6 @@
1
1
  module OverSIP::SIP
2
2
 
3
- class TcpServer < TcpReactor
3
+ class TcpServer < TcpConnection
4
4
 
5
5
  attr_reader :outbound_flow_token
6
6
 
@@ -14,8 +14,6 @@ module OverSIP::SIP
14
14
  return
15
15
  end
16
16
 
17
- log_system_info "connection opened from " << remote_desc
18
-
19
17
  @connection_id = ::OverSIP::SIP::TransportManager.add_connection self, self.class, self.class.ip_type, @remote_ip, @remote_port
20
18
 
21
19
  # Create an Outbound (RFC 5626) flow token for this connection.
@@ -30,8 +28,7 @@ module OverSIP::SIP
30
28
  set_sock_opt Socket::SOL_TCP, Socket::TCP_KEEPINTVL, ::OverSIP::SIP.tcp_keepalive_interval # Interval between TCP pings.
31
29
  end
32
30
 
33
- # Initialize @cvars.
34
- @cvars = {}
31
+ log_system_info "connection opened from " << remote_desc
35
32
  end
36
33
 
37
34
  def remote_desc force=nil