Class: OverSIP::SIP::Request
- Includes:
- Modules::Core
- Defined in:
- lib/oversip/sip/request.rb,
lib/oversip/sip/modules/core.rb,
lib/oversip/sip/modules/user_assertion.rb,
ext/sip_parser/sip_parser_ruby.c
Constant Summary collapse
- SECURE_TRANSPORTS =
{ :tls=>true, :wss=>true }
Constants inherited from Message
Message::DIALOG_FORMING_METHODS, Message::EMPTY_ARRAY, Message::LOOSE_RECORD_AWARE_METHODS, Message::OUTBOUND_AWARE_METHODS
Constants included from Logger
Logger::SYSLOG_POSIXMQ_MAPPING
Instance Attribute Summary collapse
-
#antiloop_id ⇒ Object
Returns the value of attribute antiloop_id.
-
#in_rr ⇒ Object
Used for internal purposes when doing proxy and adding the first Record-Route or Path.
-
#incoming_outbound_requested ⇒ Object
writeonly
Sets the attribute incoming_outbound_requested.
-
#new_max_forwards ⇒ Object
readonly
Returns the value of attribute new_max_forwards.
-
#outgoing_outbound_requested ⇒ Object
writeonly
Sets the attribute outgoing_outbound_requested.
-
#proxied ⇒ Object
If true it means that this request has been already proxied.
-
#route_outbound_flow_token ⇒ Object
Returns the value of attribute route_outbound_flow_token.
-
#ruri ⇒ Object
readonly
Returns the value of attribute ruri.
-
#server_transaction ⇒ Object
Returns the value of attribute server_transaction.
Attributes inherited from Message
#body, #call_id, #connection, #contact, #contact_params, #content_length, #cseq, #from, #from_tag, #hdr_from, #hdr_route, #hdr_to, #hdr_via, #headers, #max_forwards, #num_vias, #proxy_require, #require, #routes, #sip_method, #sip_version, #source_ip, #source_ip_type, #source_port, #supported, #to, #to_tag, #transport, #tvars, #via_branch, #via_branch_id, #via_branch_rfc3261, #via_core_value, #via_has_alias, #via_has_rport, #via_params, #via_received, #via_rport, #via_sent_by_host, #via_sent_by_port
Instance Method Summary collapse
- #asserted_user ⇒ Object
- #asserted_user? ⇒ Boolean
- #in_dialog? ⇒ Boolean
- #initial? ⇒ Boolean
- #log_id ⇒ Object
- #reply(status_code, reason_phrase = nil, extra_headers = [], body = nil) ⇒ Object
- #reply_full(response) ⇒ Object
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #secure? ⇒ Boolean
- #send_response(response) ⇒ Object
- #to_s ⇒ Object
Methods included from Modules::Core
#check_max_forwards, #connection_outbound_flow_token, #create_transaction, #destination_myself?, #fix_nat, #incoming_outbound_requested?, #loose_route, #outgoing_outbound_requested?, #proxy
Methods inherited from Message
#append_header, #delete_header, #delete_header_top, #dialog_forming?, #has_header?, #header_all, #header_top, #insert_header, #loose_record_aware?, #outbound_aware?, #replace_header_top, #set_header, #tcp?, #tls?, #udp?, #unknown_method?, #via_alias?, #via_rport?, #websocket?, #ws?
Methods included from Logger
close, #fatal, fg_system_msg2str, init_logger_mq, load_methods, syslog_system_msg2str, syslog_user_msg2str
Instance Attribute Details
#antiloop_id ⇒ Object
Returns the value of attribute antiloop_id.
10 11 12 |
# File 'lib/oversip/sip/request.rb', line 10 def antiloop_id @antiloop_id end |
#in_rr ⇒ Object
Used for internal purposes when doing proxy and adding the first Record-Route or Path.
18 19 20 |
# File 'lib/oversip/sip/request.rb', line 18 def in_rr @in_rr end |
#incoming_outbound_requested=(value) ⇒ Object (writeonly)
Sets the attribute incoming_outbound_requested
13 14 15 |
# File 'lib/oversip/sip/request.rb', line 13 def incoming_outbound_requested=(value) @incoming_outbound_requested = value end |
#new_max_forwards ⇒ Object (readonly)
Returns the value of attribute new_max_forwards.
9 10 11 |
# File 'lib/oversip/sip/request.rb', line 9 def new_max_forwards @new_max_forwards end |
#outgoing_outbound_requested=(value) ⇒ Object (writeonly)
Sets the attribute outgoing_outbound_requested
13 14 15 |
# File 'lib/oversip/sip/request.rb', line 13 def outgoing_outbound_requested=(value) @outgoing_outbound_requested = value end |
#proxied ⇒ Object
If true it means that this request has been already proxied.
14 15 16 |
# File 'lib/oversip/sip/request.rb', line 14 def proxied @proxied end |
#route_outbound_flow_token ⇒ Object
Returns the value of attribute route_outbound_flow_token.
11 12 13 |
# File 'lib/oversip/sip/request.rb', line 11 def route_outbound_flow_token @route_outbound_flow_token end |
#ruri ⇒ Object (readonly)
Returns the value of attribute ruri.
8 9 10 |
# File 'lib/oversip/sip/request.rb', line 8 def ruri @ruri end |
#server_transaction ⇒ Object
Returns the value of attribute server_transaction.
7 8 9 |
# File 'lib/oversip/sip/request.rb', line 7 def server_transaction @server_transaction end |
Instance Method Details
#asserted_user ⇒ Object
85 86 87 |
# File 'lib/oversip/sip/modules/user_assertion.rb', line 85 def asserted_user self.connection.asserted_user end |
#asserted_user? ⇒ Boolean
81 82 83 |
# File 'lib/oversip/sip/modules/user_assertion.rb', line 81 def asserted_user? true if self.connection.asserted_user end |
#in_dialog? ⇒ Boolean
29 |
# File 'lib/oversip/sip/request.rb', line 29 def in_dialog? ; @to_tag end |
#initial? ⇒ Boolean
28 |
# File 'lib/oversip/sip/request.rb', line 28 def initial? ; ! @to_tag end |
#log_id ⇒ Object
21 22 23 |
# File 'lib/oversip/sip/request.rb', line 21 def log_id @log_id ||= "SIP Request #{@via_branch_id}" end |
#reply(status_code, reason_phrase = nil, extra_headers = [], body = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/oversip/sip/request.rb', line 36 def reply status_code, reason_phrase=nil, extra_headers=[], body=nil return false unless @server_transaction.receive_response(status_code) if @server_transaction reason_phrase ||= REASON_PHARSE[status_code] || REASON_PHARSE_NOT_SET if status_code > 100 @internal_to_tag ||= @to_tag || ( @server_transaction ? SecureRandom.hex(6) : OverSIP::SIP::Tags.totag_for_sl_reply ) end response = "SIP/2.0 #{status_code} #{reason_phrase}\r\n" @hdr_via.each do |hdr| response << "Via: " << hdr << "\r\n" end response << "From: " << @hdr_from << "\r\n" response << "To: " << @hdr_to response << ";tag=#{@internal_to_tag}" if @internal_to_tag response << "\r\n" response << "Call-ID: " << @call_id << "\r\n" response << "CSeq: " << @cseq.to_s << " " << @sip_method.to_s << "\r\n" response << "Content-Length: #{body ? body.bytesize : "0"}\r\n" extra_headers.each do |header| response << header.to_s << "\r\n" end if extra_headers response << HDR_SERVER << "\r\n" response << "\r\n" response << body if body @server_transaction.last_response = response if @server_transaction log_system_debug "replying #{status_code} \"#{reason_phrase}\"" if $oversip_debug send_response(response) true end |
#reply_full(response) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/oversip/sip/request.rb', line 79 def reply_full response return false unless @server_transaction.receive_response(response.status_code) if @server_transaction # Ensure the response has Content-Length. Add it otherwise. if response.body response.headers["Content-Length"] = [ response.body.bytesize.to_s ] else response.headers["Content-Length"] = HDR_ARRAY_CONTENT_LENGTH_0 end response_leg_a = response.to_s @server_transaction.last_response = response_leg_a if @server_transaction log_system_debug "forwarding response #{response.status_code} \"#{response.reason_phrase}\"" if $oversip_debug send_response(response_leg_a) true end |
#request? ⇒ Boolean
25 |
# File 'lib/oversip/sip/request.rb', line 25 def request? ; true end |
#response? ⇒ Boolean
26 |
# File 'lib/oversip/sip/request.rb', line 26 def response? ; false end |
#secure? ⇒ Boolean
31 32 33 |
# File 'lib/oversip/sip/request.rb', line 31 def secure? SECURE_TRANSPORTS[@transport] || false end |
#send_response(response) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/oversip/sip/request.rb', line 99 def send_response(response) unless (case @transport when :udp @connection.send_sip_msg response, @source_ip, @via_rport || @via_sent_by_port || 5060 else @connection.send_sip_msg response end ) log_system_notice "error sending the SIP response" end end |
#to_s ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/oversip/sip/request.rb', line 112 def to_s msg = "#{@sip_method.to_s} #{self.ruri.uri} SIP/2.0\r\n" @headers.each do |key, values| values.each do |value| msg << key << ": #{value}\r\n" end end msg << CRLF msg << @body if @body msg end |