oversip 1.0.7.beta1 → 1.1.0.beta1

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.
@@ -1,47 +1,87 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- #
4
- # OverSIP - Logic.
5
1
  #
2
+ # OverSIP - Server Logic.
6
3
  #
7
4
 
8
5
 
9
- class OverSIP::SIP::Logic
10
6
 
11
- ### Custom configuration options:
12
- #
7
+
8
+ ### Custom Application Code:
9
+
10
+
11
+ # Define here your custom code for the application running on top of OverSIP.
12
+ # Here you can load thirdy-party libraries and so on.
13
+ #
14
+ # require "some-gem"
15
+ #
16
+ module MyExampleApp
17
+ extend ::OverSIP::Logger
18
+
19
+ # Custom configuration options:
20
+
13
21
  # Set this to _true_ if the SIP registrar behind OverSIP does not support Path.
14
- USE_MODULE_REGISTRAR_WITHOUT_PATH = true
15
- #
22
+ SIP_USE_MODULE_REGISTRAR_WITHOUT_PATH = true
23
+
16
24
  # Set this to _true_ if the SIP proxy/server behind OverSIP performing the authentication
17
25
  # is ready to accept a P-Asserted-Identity header from OverSIP indicating the already
18
26
  # asserted SIP user of the client's connection (this avoids authenticating all the requests
19
27
  # but the first one).
20
- USE_MODULE_USER_ASSERTION = true
28
+ SIP_USE_MODULE_USER_ASSERTION = true
29
+ end
30
+
31
+
32
+
33
+
34
+ ### OverSIP Events:
35
+
36
+
37
+ module OverSIP
38
+
39
+ ### System Events:
40
+
41
+
42
+ # This method is called once the OverSIP reactor has been started.
43
+ #
44
+ # def SystemEvents.on_started
45
+ # [...]
46
+ # end
47
+
48
+
49
+ # This method is called when a USR1 signal is received by OverSIP main
50
+ # process and allows the user to set custom code to be executed
51
+ # or reloaded.
52
+ #
53
+ # def SystemEvents.on_user_reload
54
+ # [...]
55
+ # end
21
56
 
22
57
 
23
- def run
24
58
 
25
- log_info "#{@request.sip_method} from #{@request.from.uri} (UA: #{@request.header("User-Agent")}) to #{@request.ruri} via #{@request.transport.upcase} #{@request.source_ip} : #{@request.source_port}"
59
+
60
+ ### SIP Events:
61
+
62
+
63
+ # This method is called when a SIP request is received.
64
+ #
65
+ def SipEvents.on_request request
66
+
67
+ log_info "#{request.sip_method} from #{request.from.uri} (UA: #{request.header("User-Agent")}) to #{request.ruri} via #{request.transport.upcase} #{request.source_ip} : #{request.source_port}"
26
68
 
27
69
  # Check Max-Forwards value (max 10).
28
- return unless @request.check_max_forwards 10
70
+ return unless request.check_max_forwards 10
29
71
 
30
72
  # Assume all the traffic is from clients and help them with NAT issues
31
73
  # by forcing rport usage and Outbound mechanism.
32
- @request.fix_nat
33
-
74
+ request.fix_nat
34
75
 
35
- ### In-dialog requests.
36
-
37
- if @request.in_dialog?
38
- if @request.loose_route
39
- log_debug "proxying in-dialog #{@request.sip_method}"
40
- @request.proxy(:proxy_in_dialog).route
76
+ # In-dialog requests.
77
+ if request.in_dialog?
78
+ if request.loose_route
79
+ log_debug "proxying in-dialog #{request.sip_method}"
80
+ request.proxy(:proxy_in_dialog).route
41
81
  else
42
- unless @request.sip_method == :ACK
82
+ unless request.sip_method == :ACK
43
83
  log_notice "forbidden in-dialog request without top Route pointing to us => 403"
44
- @request.reply 403, "forbidden in-dialog request without top Route pointing to us"
84
+ request.reply 403, "forbidden in-dialog request without top Route pointing to us"
45
85
  else
46
86
  log_notice "ignoring not loose routing ACK"
47
87
  end
@@ -49,32 +89,29 @@ class OverSIP::SIP::Logic
49
89
  return
50
90
  end
51
91
 
52
-
53
- ### Initial requests.
92
+ # Initial requests.
54
93
 
55
94
  # Check that the request does not contain a top Route pointing to another server.
56
- if @request.loose_route
57
- unless @request.sip_method == :ACK
95
+ if request.loose_route
96
+ unless request.sip_method == :ACK
58
97
  log_notice "pre-loaded Route not allowed here => 403"
59
- @request.reply 403, "Pre-loaded Route not allowed"
98
+ request.reply 403, "Pre-loaded Route not allowed"
60
99
  else
61
100
  log_notice "ignoring ACK initial request"
62
101
  end
63
102
  return
64
103
  end
65
104
 
66
-
67
- if USE_MODULE_REGISTRAR_WITHOUT_PATH
105
+ if MyExampleApp::SIP_USE_MODULE_REGISTRAR_WITHOUT_PATH
68
106
  # Extract the Outbound flow token from the RURI.
69
- OverSIP::SIP::Modules::RegistrarWithoutPath.extract_outbound_from_ruri @request
107
+ OverSIP::SIP::Modules::RegistrarWithoutPath.extract_outbound_from_ruri request
70
108
  end
71
109
 
72
-
73
110
  # The request goes to a client using Outbound through OverSIP.
74
- if @request.incoming_outbound_requested?
111
+ if request.incoming_outbound_requested?
75
112
  log_info "routing initial request to an Outbound client"
76
113
 
77
- proxy = @request.proxy(:proxy_to_users)
114
+ proxy = request.proxy(:proxy_to_users)
78
115
 
79
116
  proxy.on_success_response do |response|
80
117
  log_info "incoming Outbound on_success_response: #{response.status_code} '#{response.reason_phrase}'"
@@ -95,25 +132,23 @@ class OverSIP::SIP::Logic
95
132
  return
96
133
  end
97
134
 
98
-
99
135
  # An initial request with us (OverSIP) as final destination, ok, received, bye...
100
- if @request.destination_myself?
136
+ if request.destination_myself?
101
137
  log_info "request for myself => 404"
102
- @request.reply 404, "Ok, I'm here"
138
+ request.reply 404, "Ok, I'm here"
103
139
  return
104
140
  end
105
141
 
106
-
107
142
  # An outgoing initial request.
108
- case @request.sip_method
143
+ case request.sip_method
109
144
 
110
145
  when :INVITE, :MESSAGE, :OPTIONS, :SUBSCRIBE, :PUBLISH
111
146
 
112
- if USE_MODULE_USER_ASSERTION
113
- ::OverSIP::SIP::Modules::UserAssertion.add_pai @request
147
+ if MyExampleApp::SIP_USE_MODULE_USER_ASSERTION
148
+ ::OverSIP::SIP::Modules::UserAssertion.add_pai request
114
149
  end
115
150
 
116
- proxy = @request.proxy(:proxy_out)
151
+ proxy = request.proxy(:proxy_out)
117
152
 
118
153
  proxy.on_provisional_response do |response|
119
154
  log_info "on_provisional_response: #{response.status_code} '#{response.reason_phrase}'"
@@ -136,21 +171,21 @@ class OverSIP::SIP::Logic
136
171
 
137
172
  when :REGISTER
138
173
 
139
- if USE_MODULE_REGISTRAR_WITHOUT_PATH
174
+ if MyExampleApp::SIP_USE_MODULE_REGISTRAR_WITHOUT_PATH
140
175
  # Contact mangling for the case in which the registrar does not support Path.
141
- ::OverSIP::SIP::Modules::RegistrarWithoutPath.add_outbound_to_contact @request
176
+ ::OverSIP::SIP::Modules::RegistrarWithoutPath.add_outbound_to_contact request
142
177
  end
143
178
 
144
- proxy = @request.proxy(:proxy_out)
179
+ proxy = request.proxy(:proxy_out)
145
180
 
146
181
  proxy.on_success_response do |response|
147
- if USE_MODULE_REGISTRAR_WITHOUT_PATH
182
+ if MyExampleApp::SIP_USE_MODULE_REGISTRAR_WITHOUT_PATH
148
183
  # Undo changes done to the Contact header provided by the client, so it receives
149
184
  # the same value in the 200 response from the registrar.
150
185
  ::OverSIP::SIP::Modules::RegistrarWithoutPath.remove_outbound_from_contact response
151
186
  end
152
187
 
153
- if USE_MODULE_USER_ASSERTION
188
+ if MyExampleApp::SIP_USE_MODULE_USER_ASSERTION
154
189
  # The registrar replies 200 after a REGISTER with credentials so let's assert
155
190
  # the current SIP user to this connection.
156
191
  ::OverSIP::SIP::Modules::UserAssertion.assert_connection response
@@ -158,7 +193,7 @@ class OverSIP::SIP::Logic
158
193
  end
159
194
 
160
195
  proxy.on_failure_response do |response|
161
- if USE_MODULE_USER_ASSERTION
196
+ if MyExampleApp::SIP_USE_MODULE_USER_ASSERTION
162
197
  # We don't add PAI for re-REGISTER, so 401 will be replied, and after it let's
163
198
  # revoke the current user assertion (will be re-added upon REGISTER with credentials).
164
199
  ::OverSIP::SIP::Modules::UserAssertion.revoke_assertion response
@@ -170,12 +205,39 @@ class OverSIP::SIP::Logic
170
205
 
171
206
  else
172
207
 
173
- log_info "method #{@request.sip_method} not implemented => 501"
174
- @request.reply 501, "Not Implemented"
208
+ log_info "method #{request.sip_method} not implemented => 501"
209
+ request.reply 501, "Not Implemented"
175
210
  return
176
211
 
177
212
  end
213
+ end
214
+
215
+
216
+
217
+
218
+ ### WebSocket Events:
219
+
220
+
221
+ # This method is called when a new WebSocket connection is being requested.
222
+ # Here you can inspect the connection and the HTTP GET request. If you
223
+ # decide not to accept this connection then call to:
224
+ #
225
+ # connection.http_reject(status_code, reason_phrase=nil, extra_headers=nil)
226
+ #
227
+ # You can also set variables for this connection via the connection.cvars
228
+ # Hash. Later you can access to this Hash in SIP request from this connection
229
+ # by accessing to request.cvars attribute.
230
+ #
231
+ # def WebSocketEvents.on_connection connection, http_request
232
+ # [...]
233
+ # end
234
+
235
+
236
+ # This method is called when a WebSocket connection is closed.
237
+ #
238
+ # def WebSocketEvents.on_connection_closed connection
239
+ # [...]
240
+ # end
178
241
 
179
- end # def run
180
242
 
181
- end # class OverSIP::SIP::Logic
243
+ end # module OverSIP
@@ -13,11 +13,7 @@ module OverSIP
13
13
  DEFAULT_TLS_CA_DIR = "tls/ca/"
14
14
  DEFAULT_CONFIG_FILE = "oversip.conf"
15
15
  PROXIES_FILE = "proxies.conf"
16
- LOGIC_FILE = "logic.rb"
17
- WEBSOCKET_POLICY_FILE = "websocket_policy.rb"
18
- SYSTEM_EVENTS_FILE = "system_events.rb"
19
- EVENTS_FILE = "events.rb"
20
- CUSTOM_LIB_FILE = "custom_lib.rb"
16
+ SERVER_FILE = "server.rb"
21
17
 
22
18
  def self.log_id
23
19
  @log_id ||= "Config"
@@ -122,14 +118,10 @@ module OverSIP
122
118
 
123
119
 
124
120
  def self.load config_dir=nil, config_file=nil
125
- @config_dir = (config_dir || DEFAULT_CONFIG_DIR)
121
+ @config_dir = (::File.expand_path(config_dir) || DEFAULT_CONFIG_DIR)
126
122
  @config_file = ::File.join(@config_dir, config_file || DEFAULT_CONFIG_FILE)
127
123
  @proxies_file = ::File.join(@config_dir, PROXIES_FILE)
128
- @logic_file = ::File.join(@config_dir, LOGIC_FILE)
129
- @websocket_policy_file = ::File.join(@config_dir, WEBSOCKET_POLICY_FILE)
130
- @system_events_file = ::File.join(@config_dir, SYSTEM_EVENTS_FILE)
131
- @events_file = ::File.join(@config_dir, EVENTS_FILE)
132
- @custom_lib_file = ::File.join(@config_dir, CUSTOM_LIB_FILE)
124
+ @server_file = ::File.join(@config_dir, SERVER_FILE)
133
125
 
134
126
  begin
135
127
  conf_yaml = ::YAML.load_file @config_file
@@ -138,27 +130,6 @@ module OverSIP
138
130
  fatal e
139
131
  end
140
132
 
141
- begin
142
- ::Kernel.load @custom_lib_file
143
- rescue ::Exception => e
144
- log_system_crit "error loading Custom Library file '#{@custom_lib_file}':"
145
- fatal e
146
- end
147
-
148
- begin
149
- ::Kernel.load @system_events_file
150
- rescue ::Exception => e
151
- log_system_crit "error loading System Events file '#{@system_events_file}':"
152
- fatal e
153
- end
154
-
155
- begin
156
- ::Kernel.load @events_file
157
- rescue ::Exception => e
158
- log_system_crit "error loading Events file '#{@events_file}':"
159
- fatal e
160
- end
161
-
162
133
  begin
163
134
  proxies_yaml = ::YAML.load_file @proxies_file
164
135
  rescue ::Exception => e
@@ -167,16 +138,9 @@ module OverSIP
167
138
  end
168
139
 
169
140
  begin
170
- ::Kernel.load @logic_file
141
+ ::Kernel.load @server_file
171
142
  rescue ::Exception => e
172
- log_system_crit "error loading Logic file '#{@logic_file}':"
173
- fatal e
174
- end
175
-
176
- begin
177
- ::Kernel.load @websocket_policy_file
178
- rescue ::Exception => e
179
- log_system_crit "error loading WebSocket Policy file '#{@websocket_policy_file}':"
143
+ log_system_crit "error loading Server file '#{@server_file}':"
180
144
  fatal e
181
145
  end
182
146
 
@@ -575,30 +539,6 @@ module OverSIP
575
539
  def self.system_reload
576
540
  log_system_notice "reloading OverSIP..."
577
541
 
578
- begin
579
- ::Kernel.load @custom_lib_file
580
- log_system_notice "Custom Library file '#{@custom_lib_file}' reloaded"
581
- rescue ::Exception => e
582
- log_system_crit "error reloading Custom Library file '#{@custom_lib_file}':"
583
- log_system_crit e
584
- end
585
-
586
- begin
587
- ::Kernel.load @system_events_file
588
- log_system_notice "System Events file '#{@system_events_file}' reloaded"
589
- rescue ::Exception => e
590
- log_system_crit "error reloading System Events file '#{@system_events_file}':"
591
- log_system_crit e
592
- end
593
-
594
- begin
595
- ::Kernel.load @events_file
596
- log_system_notice "Events file '#{@events_file}' reloaded"
597
- rescue ::Exception => e
598
- log_system_crit "error reloading Events file '#{@events_file}':"
599
- log_system_crit e
600
- end
601
-
602
542
  begin
603
543
  proxies_yaml = ::YAML.load_file @proxies_file
604
544
  ::OverSIP::ProxiesConfig.load proxies_yaml, reload=true
@@ -611,14 +551,14 @@ module OverSIP
611
551
  end
612
552
 
613
553
  begin
614
- ::Kernel.load @logic_file
615
- log_system_notice "Logic file '#{@logic_file}' reloaded"
554
+ ::Kernel.load @server_file
555
+ log_system_notice "Server file '#{@server_file}' reloaded"
616
556
  rescue ::Exception => e
617
- log_system_crit "error reloading Logic file '#{@logic_file}':"
557
+ log_system_crit "error reloading Server file '#{@server_file}':"
618
558
  log_system_crit e
619
559
  end
620
560
  end
621
561
 
622
562
  end
623
563
 
624
- end
564
+ end
@@ -0,0 +1,41 @@
1
+ module OverSIP
2
+
3
+ module SystemEvents
4
+
5
+ extend ::OverSIP::Logger
6
+
7
+ def self.on_started
8
+ log_system_notice "on_started() event is not defined"
9
+ end
10
+
11
+ def self.on_user_reload
12
+ log_system_notice "on_user_reload() event is not defined"
13
+ end
14
+
15
+ end
16
+
17
+ module SipEvents
18
+
19
+ extend ::OverSIP::Logger
20
+
21
+ def self.on_request request
22
+ log_system_notice "on_request() event is not defined"
23
+ end
24
+
25
+ end
26
+
27
+ module WebSocketEvents
28
+
29
+ extend ::OverSIP::Logger
30
+
31
+ def self.on_connection connection, http_request
32
+ log_system_notice "on_connection() event is not defined"
33
+ end
34
+
35
+ def self.on_connection_closed connection
36
+ log_system_notice "on_connection_closed() event is not defined"
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -300,11 +300,11 @@ module OverSIP::Launcher
300
300
  log_system_info "reactor running"
301
301
 
302
302
  # Run the user provided on_started callback.
303
- log_system_info "calling user provided OverSIP::SystemEvents.on_started() callback..."
303
+ log_system_info "calling OverSIP::SystemEvents.on_started()..."
304
304
  begin
305
305
  ::OverSIP::SystemEvents.on_started
306
306
  rescue ::Exception => e
307
- log_system_crit "error calling user provided OverSIP::SystemEvents.on_started() callback:"
307
+ log_system_crit "error calling OverSIP::SystemEvents.on_started():"
308
308
  fatal e
309
309
  end
310
310
 
@@ -441,12 +441,12 @@ module OverSIP::Launcher
441
441
 
442
442
  # Signal USR1 reloads custom code provided by the user.
443
443
  trap :USR1 do
444
- log_system_notice "USR1 signal received, calling user provided OverSIP::SystemEvents.on_user_reload() callback..."
444
+ log_system_notice "USR1 signal received, calling OverSIP::SystemEvents.on_user_reload()..."
445
445
  # Run the user provided on_started callback.
446
446
  begin
447
447
  ::OverSIP::SystemEvents.on_user_reload
448
448
  rescue ::Exception => e
449
- log_system_crit "error calling user provided OverSIP::SystemEvents.on_user_reload() callback:"
449
+ log_system_crit "error calling OverSIP::SystemEvents.on_user_reload():"
450
450
  log_system_crit e
451
451
  end
452
452
  end
@@ -160,7 +160,7 @@ module OverSIP
160
160
  # Default logging identifier is the class name. If log_id() method is redefined by the
161
161
  # class including this module, or it sets @log_id, then such a value takes preference.
162
162
  def log_id
163
- @log_id ||= self.class.name
163
+ @log_id ||= (self.is_a?(::Module) ? self.name.split("::").last : self.class.name)
164
164
  end
165
165
 
166
166
  end # module Logger
@@ -24,8 +24,6 @@ require "posix-spawn"
24
24
 
25
25
  # OverSIP files.
26
26
 
27
- require "oversip/ruby_ext/eventmachine.rb"
28
-
29
27
  require "oversip/sip/sip.rb"
30
28
  require "oversip/sip/sip_parser.so"
31
29
  require "oversip/sip/constants.rb"
@@ -43,7 +41,6 @@ require "oversip/sip/transport_manager.rb"
43
41
  require "oversip/sip/timers.rb"
44
42
  require "oversip/sip/tags.rb"
45
43
  require "oversip/sip/rfc3263.rb"
46
- require "oversip/sip/logic.rb"
47
44
  require "oversip/sip/proxy.rb"
48
45
 
49
46
  require "oversip/websocket/ws_http_parser.so"
@@ -56,10 +53,13 @@ require "oversip/websocket/ws_framing.rb"
56
53
  require "oversip/websocket/ws_app.rb"
57
54
  require "oversip/websocket/ws_apps.rb"
58
55
 
56
+ require "oversip/sip/modules/core.rb"
57
+ require "oversip/sip/modules/user_assertion.rb"
58
+ require "oversip/sip/modules/registrar_without_path.rb"
59
+
60
+ require "oversip/default_server.rb"
59
61
  require "oversip/fiber_pool.rb"
60
62
  require "oversip/tls.rb"
61
63
  require "oversip/stun.so"
62
64
 
63
- require "oversip/sip/modules/core.rb"
64
- require "oversip/sip/modules/user_assertion.rb"
65
- require "oversip/sip/modules/registrar_without_path.rb"
65
+ require "oversip/ruby_ext/eventmachine.rb"
@@ -90,11 +90,12 @@ module OverSIP::SIP
90
90
  @msg.tvars = {}
91
91
  @msg.cvars = @cvars
92
92
 
93
- # Create the Logic instance and run it!
94
- ::OverSIP::SIP::Logic.new(@msg).run
95
- rescue => e
93
+ # Run the user provided OverSIP::SipEvents.on_request() callback.
94
+ ::OverSIP::SipEvents.on_request @msg
95
+ rescue ::Exception => e
96
+ log_system_error "error calling OverSIP::WebSocketEvents.on_request() => 500:"
96
97
  log_system_error e
97
- @msg.reply 503, "Internal Error", ["Content-Type: text/plain"], "#{e.class }: #{e.message}"
98
+ @msg.reply 500, "Internal Error", ["Content-Type: text/plain"], "#{e.class}: #{e.message}"
98
99
  end
99
100
  end
100
101
  end
@@ -4,8 +4,8 @@ module OverSIP
4
4
 
5
5
  module Version
6
6
  MAJOR = 1
7
- MINOR = 0
8
- TINY = 7
7
+ MINOR = 1
8
+ TINY = 0
9
9
  DEVEL = "beta1" # Set to nil for stable releases.
10
10
  end
11
11
 
@@ -72,9 +72,9 @@ module OverSIP::WebSocket
72
72
 
73
73
  if @ws_handshake_done
74
74
  begin
75
- ::OverSIP::Events.on_websocket_connection_closed self
75
+ ::OverSIP::WebSocketEvents.on_connection_closed self
76
76
  rescue ::Exception => e
77
- log_system_error "error calling user provided OverSIP::Events.on_websocket_connection_closed():"
77
+ log_system_error "error calling OverSIP::WebSocketEvents.on_connection_closed():"
78
78
  log_system_error e
79
79
  end
80
80
  end
@@ -99,8 +99,8 @@ module OverSIP::WebSocket
99
99
  when :check_http_request
100
100
  check_http_request
101
101
 
102
- when :new_websocket_connection_callback
103
- check_new_websocket_connection_callback
102
+ when :ws_connection_callback
103
+ check_ws_connection_callback
104
104
 
105
105
  when :accept_ws_handshake
106
106
  accept_ws_handshake
@@ -206,36 +206,16 @@ module OverSIP::WebSocket
206
206
  end
207
207
  end
208
208
 
209
- # Check WebSocket policy.
210
-
211
- unless ::OverSIP::WebSocket::Policy.check_hostport(@http_request.host, @http_request.port)
212
- log_system_notice "host/port policy not satisfied (host=#{@http_request.host.inspect}, port=#{@http_request.port.inspect}) => 403"
213
- http_reject 403, "request host/port not satisfied"
214
- return false
215
- end
216
-
217
- unless ::OverSIP::WebSocket::Policy.check_origin(@http_request.hdr_origin)
218
- log_system_notice "'Origin' policy not satisfied (origin=#{@http_request.hdr_origin.inspect}) => 403"
219
- http_reject 403, "request 'Origin' not satisfied"
220
- return false
221
- end
222
-
223
- unless ::OverSIP::WebSocket::Policy.check_request_uri(@http_request.uri_path, @http_request.uri_query)
224
- log_system_notice "request URI path/query not satisfied (path=#{@http_request.uri_path.inspect}, query=#{@http_request.uri_query.inspect}) => 403"
225
- http_reject 403, "request URI path/query not satisfied"
226
- return false
227
- end
228
-
229
- @state = :new_websocket_connection_callback
209
+ @state = :ws_connection_callback
230
210
  true
231
211
  end
232
212
 
233
213
 
234
- def check_new_websocket_connection_callback
214
+ def check_ws_connection_callback
235
215
  begin
236
- ::OverSIP::Events.on_new_websocket_connection self, @http_request
216
+ ::OverSIP::WebSocketEvents.on_connection self, @http_request
237
217
  rescue ::Exception => e
238
- log_system_error "error calling user provided OverSIP::Events.on_new_websocket_connection() callback => 500:"
218
+ log_system_error "error calling OverSIP::WebSocketEvents.on_connection() => 500:"
239
219
  log_system_error e
240
220
  http_reject 500
241
221
  return false
@@ -243,7 +223,7 @@ module OverSIP::WebSocket
243
223
 
244
224
  # The user provided callback could have reject the WS connection, so
245
225
  # check it not to reply a 101 after the reply sent by the user.
246
- if @state == :new_websocket_connection_callback
226
+ if @state == :ws_connection_callback
247
227
  @state = :accept_ws_handshake
248
228
  true
249
229
  else
@@ -71,6 +71,6 @@ module OverSIP::WebSocket
71
71
  end
72
72
 
73
73
 
74
- end # WsApplication
74
+ end # WsApp
75
75
 
76
76
  end
@@ -151,6 +151,6 @@ module OverSIP::WebSocket
151
151
  end
152
152
 
153
153
 
154
- end # WsSipApplication
154
+ end # WsSipApp
155
155
 
156
156
  end
data/lib/oversip.rb CHANGED
@@ -26,6 +26,7 @@ require "oversip/launcher.rb"
26
26
  require "oversip/utils.so"
27
27
  require "oversip/utils.rb"
28
28
  require "oversip/posix_mq.rb"
29
+ require "oversip/default_server.rb"
29
30
 
30
31
 
31
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oversip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7.beta1
4
+ version: 1.1.0.beta1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine-le
16
- requirement: &19620160 !ruby/object:Gem::Requirement
16
+ requirement: &15245840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19620160
24
+ version_requirements: *15245840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: iobuffer
27
- requirement: &19619700 !ruby/object:Gem::Requirement
27
+ requirement: &15245380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19619700
35
+ version_requirements: *15245380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-posixmq
38
- requirement: &19619240 !ruby/object:Gem::Requirement
38
+ requirement: &15244920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.2.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *19619240
46
+ version_requirements: *15244920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: em-udns
49
- requirement: &19618780 !ruby/object:Gem::Requirement
49
+ requirement: &15244460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.3.6
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *19618780
57
+ version_requirements: *15244460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: escape_utils
60
- requirement: &19618320 !ruby/object:Gem::Requirement
60
+ requirement: &15244000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.2.4
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *19618320
68
+ version_requirements: *15244000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: term-ansicolor
71
- requirement: &19617940 !ruby/object:Gem::Requirement
71
+ requirement: &15243620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *19617940
79
+ version_requirements: *15243620
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: posix-spawn
82
- requirement: &19617400 !ruby/object:Gem::Requirement
82
+ requirement: &15243080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.3.6
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *19617400
90
+ version_requirements: *15243080
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &19616900 !ruby/object:Gem::Requirement
93
+ requirement: &15242580 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 0.9.2
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *19616900
101
+ version_requirements: *15242580
102
102
  description: ! "OverSIP is an async SIP server. Built on top of Ruby EventMachine\n
103
103
  \ library it follows the Reactor Pattern, allowing thousands of concurrent connections
104
104
  and requests\n handled by a single processor in a never-blocking fashion. It
@@ -122,6 +122,7 @@ files:
122
122
  - lib/oversip/utils.rb
123
123
  - lib/oversip/errors.rb
124
124
  - lib/oversip/master_process.rb
125
+ - lib/oversip/default_server.rb
125
126
  - lib/oversip/tls.rb
126
127
  - lib/oversip/config_validators.rb
127
128
  - lib/oversip/version.rb
@@ -136,7 +137,6 @@ files:
136
137
  - lib/oversip/sip/listeners.rb
137
138
  - lib/oversip/sip/proxy.rb
138
139
  - lib/oversip/sip/server_transaction.rb
139
- - lib/oversip/sip/logic.rb
140
140
  - lib/oversip/sip/tags.rb
141
141
  - lib/oversip/sip/request.rb
142
142
  - lib/oversip/sip/timers.rb
@@ -228,12 +228,8 @@ files:
228
228
  - ext/stud/extconf.rb
229
229
  - thirdparty/stud/stud.tar.gz
230
230
  - etc/oversip.conf
231
- - etc/system_events.rb
232
- - etc/events.rb
233
- - etc/custom_lib.rb
234
- - etc/logic.rb
235
231
  - etc/proxies.conf
236
- - etc/websocket_policy.rb
232
+ - etc/server.rb
237
233
  - etc/tls/demo-tls.oversip.net.crt
238
234
  - etc/tls/demo-tls.oversip.net.key
239
235
  - etc/tls/upgrade-cacert.sh
data/etc/custom_lib.rb DELETED
@@ -1,15 +0,0 @@
1
- #
2
- # OverSIP - Custom Library.
3
- #
4
- #
5
- # Add your custom code for your application running on top of OverSIP.
6
- # Here you can load thirdy-party libraries and so on.
7
-
8
-
9
- module MyOverSIP
10
-
11
- extend ::OverSIP::Logger
12
-
13
- # Add here your code.
14
-
15
- end
data/etc/events.rb DELETED
@@ -1,34 +0,0 @@
1
- #
2
- # OverSIP - Events.
3
- #
4
- #
5
- # OverSIP common callbacks. Fill them according to your needs.
6
-
7
-
8
- module OverSIP::Events
9
-
10
- extend ::OverSIP::Logger
11
- @log_id = "Events"
12
-
13
- # This method is called once a WebSocket connection has been accepted
14
- # but before the HTTP 101 has been replied to the client.
15
- # Here you can inspect the HTTP request (WebSocket handshake) and,
16
- # based on your service, reject the connection by calling:
17
- #
18
- # connection.http_reject(status_code, reason_phrase=nil, extra_headers=nil)
19
- #
20
- # You can also set variables for this connection via the connection.cvars
21
- # hash. You can later inspect such a hash within the logic.rb file by
22
- # accessing to @request.cvars.
23
- #
24
- def self.on_new_websocket_connection connection, http_request
25
- # Do something.
26
- end
27
-
28
- # This method is called once a WebSocket connection has been closed.
29
- #
30
- def self.on_websocket_connection_closed connection
31
- # Do something.
32
- end
33
-
34
- end
data/etc/system_events.rb DELETED
@@ -1,25 +0,0 @@
1
- #
2
- # OverSIP - System Events.
3
- #
4
- #
5
- # OverSIP system callbacks. Fill them according to your needs.
6
-
7
-
8
- module OverSIP::SystemEvents
9
-
10
- extend ::OverSIP::Logger
11
- @log_id = "SystemEvents"
12
-
13
- # This method is called once the OverSIP reactor has been started.
14
- def self.on_started
15
- # Do something.
16
- end
17
-
18
- # This method is called when a USR1 signal is received by the main
19
- # process and allows the user to set custom code to be executed
20
- # or reloaded.
21
- def self.on_user_reload
22
- # Do something.
23
- end
24
-
25
- end
@@ -1,30 +0,0 @@
1
- #
2
- # OverSIP - WebSocket Access Policy.
3
- #
4
- #
5
- # Fill these functions with your own access policy for allowing or
6
- # disallowing WebSocket connections from clients.
7
- #
8
- # If any of the following methods return _false_ then the WebSocket
9
- # connection is rejected.
10
-
11
-
12
- module OverSIP::WebSocket::Policy
13
-
14
- # Check the value of the Host header, by splitting it into
15
- # host (a String) and port (Fixnum). Both could be _nil_.
16
- def self.check_hostport host=nil, port=nil
17
- return true
18
- end
19
-
20
- # Check the value of the Origin header (a String with original value).
21
- def self.check_origin origin=nil
22
- return true
23
- end
24
-
25
- # Check the request URI path (String) and query (String). Both can be _nil_.
26
- def self.check_request_uri path=nil, query=nil
27
- return true
28
- end
29
-
30
- end
@@ -1,14 +0,0 @@
1
- module OverSIP::SIP
2
-
3
- class Logic
4
-
5
- include ::OverSIP::Logger
6
-
7
- def initialize request
8
- @log_id = "Logic " << request.via_branch_id
9
- @request = request
10
- end
11
-
12
- end # class Logic
13
-
14
- end