Class: OverSIP::SIP::Message
- Inherits:
-
Object
- Object
- OverSIP::SIP::Message
- Includes:
- Logger
- Defined in:
- lib/oversip/sip/message.rb,
ext/sip_parser/sip_parser_ruby.c
Constant Summary collapse
- DIALOG_FORMING_METHODS =
{ :INVITE=>true, :SUBSCRIBE=>true, :REFER=>true }
- RECORD_ROUTING_AWARE_METHODS =
{ :INVITE=>true, :REGISTER=>true, :SUBSCRIBE=>true, :REFER=>true }
- OUTBOUND_AWARE_METHODS =
{ :INVITE=>true, :REGISTER=>true, :SUBSCRIBE=>true, :REFER=>true }
- EMPTY_ARRAY =
[].freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#call_id ⇒ Object
readonly
Returns the value of attribute call_id.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#contact ⇒ Object
readonly
NameAddr instance (when it has a single value).
-
#contact_params ⇒ Object
readonly
Returns the value of attribute contact_params.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#cseq ⇒ Object
readonly
Returns the value of attribute cseq.
-
#from ⇒ Object
NameAddr instance.
-
#from_tag ⇒ Object
readonly
Returns the value of attribute from_tag.
-
#hdr_from ⇒ Object
readonly
String.
-
#hdr_route ⇒ Object
readonly
Array.
-
#hdr_to ⇒ Object
readonly
String.
-
#hdr_via ⇒ Object
readonly
Array.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#max_forwards ⇒ Object
readonly
Returns the value of attribute max_forwards.
-
#num_vias ⇒ Object
readonly
Returns the value of attribute num_vias.
-
#proxy_require ⇒ Object
readonly
Returns the value of attribute proxy_require.
-
#require ⇒ Object
readonly
Returns the value of attribute require.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#sip_method ⇒ Object
readonly
SIP message attributes.
-
#sip_version ⇒ Object
readonly
Returns the value of attribute sip_version.
-
#source_ip ⇒ Object
Returns the value of attribute source_ip.
-
#source_ip_type ⇒ Object
Returns the value of attribute source_ip_type.
-
#source_port ⇒ Object
Returns the value of attribute source_port.
-
#supported ⇒ Object
readonly
Returns the value of attribute supported.
-
#to ⇒ Object
NameAddr instance.
-
#to_tag ⇒ Object
readonly
Returns the value of attribute to_tag.
-
#transport ⇒ Object
SIP related attributes.
-
#tvars ⇒ Object
Other attributes.
-
#via_branch ⇒ Object
readonly
Returns the value of attribute via_branch.
-
#via_branch_id ⇒ Object
It’s the branch value without “z9hG4bK”.
-
#via_branch_rfc3261 ⇒ Object
readonly
Returns the value of attribute via_branch_rfc3261.
-
#via_core_value ⇒ Object
readonly
Returns the value of attribute via_core_value.
-
#via_has_alias ⇒ Object
readonly
Returns the value of attribute via_has_alias.
-
#via_has_rport ⇒ Object
readonly
Returns the value of attribute via_has_rport.
-
#via_params ⇒ Object
readonly
Returns the value of attribute via_params.
-
#via_received ⇒ Object
readonly
Returns the value of attribute via_received.
-
#via_rport ⇒ Object
Value not parsed.
-
#via_sent_by_host ⇒ Object
readonly
Returns the value of attribute via_sent_by_host.
-
#via_sent_by_port ⇒ Object
readonly
Returns the value of attribute via_sent_by_port.
Instance Method Summary collapse
-
#append_header(name, value) ⇒ Object
Append the given value in the last position of header name.
-
#close_connection ⇒ Object
Close the connection from which the SIP request/response has been received.
- #contact_reg_id? ⇒ Boolean
-
#delete_header(name) ⇒ Object
Completely deletes the header with given name.
-
#delete_header_top(name) ⇒ Object
Removes the first value of a given header name.
- #dialog_forming? ⇒ Boolean
-
#has_header?(name) ⇒ Boolean
Returns true if a header with the given header name exists, false otherwise.
-
#header_all(name) ⇒ Object
Returns an array with all the values of the given header name, an empty array if it doesn’t exist.
-
#header_top(name) ⇒ Object
(also: #header)
Returns the first value of the given header name, nil if it doesn’t exist.
-
#insert_header(name, value) ⇒ Object
Inserts the given value in the first position of header name.
- #outbound_aware? ⇒ Boolean
- #record_routing_aware? ⇒ Boolean
-
#replace_header_top(name, value) ⇒ Object
Replaces the top value of the given header name with the string given as argument value.
-
#set_header(name, value) ⇒ Object
Replaces the header of given name with a the given value.
- #tcp? ⇒ Boolean
- #tls? ⇒ Boolean
- #udp? ⇒ Boolean
- #unknown_method? ⇒ Boolean
- #via_alias? ⇒ Boolean
- #via_rport? ⇒ Boolean
- #websocket? ⇒ Boolean
- #ws? ⇒ Boolean
- #wss? ⇒ Boolean
Methods included from Logger
close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
46 47 48 |
# File 'lib/oversip/sip/message.rb', line 46 def body @body end |
#call_id ⇒ Object (readonly)
Returns the value of attribute call_id.
37 38 39 |
# File 'lib/oversip/sip/message.rb', line 37 def call_id @call_id end |
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/oversip/sip/message.rb', line 17 def connection @connection end |
#contact ⇒ Object (readonly)
NameAddr instance (when it has a single value).
52 53 54 |
# File 'lib/oversip/sip/message.rb', line 52 def contact @contact end |
#contact_params ⇒ Object (readonly)
Returns the value of attribute contact_params.
53 54 55 |
# File 'lib/oversip/sip/message.rb', line 53 def contact_params @contact_params end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
40 41 42 |
# File 'lib/oversip/sip/message.rb', line 40 def content_length @content_length end |
#cseq ⇒ Object (readonly)
Returns the value of attribute cseq.
38 39 40 |
# File 'lib/oversip/sip/message.rb', line 38 def cseq @cseq end |
#from ⇒ Object
NameAddr instance.
48 49 50 |
# File 'lib/oversip/sip/message.rb', line 48 def from @from end |
#from_tag ⇒ Object (readonly)
Returns the value of attribute from_tag.
49 50 51 |
# File 'lib/oversip/sip/message.rb', line 49 def from_tag @from_tag end |
#hdr_from ⇒ Object (readonly)
String
56 57 58 |
# File 'lib/oversip/sip/message.rb', line 56 def hdr_from @hdr_from end |
#hdr_route ⇒ Object (readonly)
Array
58 59 60 |
# File 'lib/oversip/sip/message.rb', line 58 def hdr_route @hdr_route end |
#hdr_to ⇒ Object (readonly)
String
57 58 59 |
# File 'lib/oversip/sip/message.rb', line 57 def hdr_to @hdr_to end |
#hdr_via ⇒ Object (readonly)
Array
55 56 57 |
# File 'lib/oversip/sip/message.rb', line 55 def hdr_via @hdr_via end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
22 23 24 |
# File 'lib/oversip/sip/message.rb', line 22 def headers @headers end |
#max_forwards ⇒ Object (readonly)
Returns the value of attribute max_forwards.
39 40 41 |
# File 'lib/oversip/sip/message.rb', line 39 def max_forwards @max_forwards end |
#num_vias ⇒ Object (readonly)
Returns the value of attribute num_vias.
35 36 37 |
# File 'lib/oversip/sip/message.rb', line 35 def num_vias @num_vias end |
#proxy_require ⇒ Object (readonly)
Returns the value of attribute proxy_require.
44 45 46 |
# File 'lib/oversip/sip/message.rb', line 44 def proxy_require @proxy_require end |
#require ⇒ Object (readonly)
Returns the value of attribute require.
42 43 44 |
# File 'lib/oversip/sip/message.rb', line 42 def require @require end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
41 42 43 |
# File 'lib/oversip/sip/message.rb', line 41 def routes @routes end |
#sip_method ⇒ Object (readonly)
SIP message attributes.
20 21 22 |
# File 'lib/oversip/sip/message.rb', line 20 def sip_method @sip_method end |
#sip_version ⇒ Object (readonly)
Returns the value of attribute sip_version.
21 22 23 |
# File 'lib/oversip/sip/message.rb', line 21 def sip_version @sip_version end |
#source_ip ⇒ Object
Returns the value of attribute source_ip.
14 15 16 |
# File 'lib/oversip/sip/message.rb', line 14 def source_ip @source_ip end |
#source_ip_type ⇒ Object
Returns the value of attribute source_ip_type.
15 16 17 |
# File 'lib/oversip/sip/message.rb', line 15 def source_ip_type @source_ip_type end |
#source_port ⇒ Object
Returns the value of attribute source_port.
16 17 18 |
# File 'lib/oversip/sip/message.rb', line 16 def source_port @source_port end |
#supported ⇒ Object (readonly)
Returns the value of attribute supported.
43 44 45 |
# File 'lib/oversip/sip/message.rb', line 43 def supported @supported end |
#to ⇒ Object
NameAddr instance.
50 51 52 |
# File 'lib/oversip/sip/message.rb', line 50 def to @to end |
#to_tag ⇒ Object (readonly)
Returns the value of attribute to_tag.
51 52 53 |
# File 'lib/oversip/sip/message.rb', line 51 def to_tag @to_tag end |
#transport ⇒ Object
SIP related attributes.
13 14 15 |
# File 'lib/oversip/sip/message.rb', line 13 def transport @transport end |
#tvars ⇒ Object
Other attributes.
61 62 63 |
# File 'lib/oversip/sip/message.rb', line 61 def tvars @tvars end |
#via_branch ⇒ Object (readonly)
Returns the value of attribute via_branch.
26 27 28 |
# File 'lib/oversip/sip/message.rb', line 26 def via_branch @via_branch end |
#via_branch_id ⇒ Object
It’s the branch value without “z9hG4bK”.
27 28 29 |
# File 'lib/oversip/sip/message.rb', line 27 def via_branch_id @via_branch_id end |
#via_branch_rfc3261 ⇒ Object (readonly)
Returns the value of attribute via_branch_rfc3261.
28 29 30 |
# File 'lib/oversip/sip/message.rb', line 28 def via_branch_rfc3261 @via_branch_rfc3261 end |
#via_core_value ⇒ Object (readonly)
Returns the value of attribute via_core_value.
33 34 35 |
# File 'lib/oversip/sip/message.rb', line 33 def via_core_value @via_core_value end |
#via_has_alias ⇒ Object (readonly)
Returns the value of attribute via_has_alias.
32 33 34 |
# File 'lib/oversip/sip/message.rb', line 32 def via_has_alias @via_has_alias end |
#via_has_rport ⇒ Object (readonly)
Returns the value of attribute via_has_rport.
30 31 32 |
# File 'lib/oversip/sip/message.rb', line 30 def via_has_rport @via_has_rport end |
#via_params ⇒ Object (readonly)
Returns the value of attribute via_params.
34 35 36 |
# File 'lib/oversip/sip/message.rb', line 34 def via_params @via_params end |
#via_received ⇒ Object (readonly)
Returns the value of attribute via_received.
29 30 31 |
# File 'lib/oversip/sip/message.rb', line 29 def via_received @via_received end |
#via_rport ⇒ Object
Value not parsed.
31 32 33 |
# File 'lib/oversip/sip/message.rb', line 31 def via_rport @via_rport end |
#via_sent_by_host ⇒ Object (readonly)
Returns the value of attribute via_sent_by_host.
24 25 26 |
# File 'lib/oversip/sip/message.rb', line 24 def via_sent_by_host @via_sent_by_host end |
#via_sent_by_port ⇒ Object (readonly)
Returns the value of attribute via_sent_by_port.
25 26 27 |
# File 'lib/oversip/sip/message.rb', line 25 def via_sent_by_port @via_sent_by_port end |
Instance Method Details
#append_header(name, value) ⇒ Object
Append the given value in the last position of header name. value must be a string.
149 150 151 152 153 154 155 |
# File 'lib/oversip/sip/message.rb', line 149 def append_header name, value if hdr = @headers[k=MessageParser.headerize(name)] hdr.push value.to_s else @headers[k] = [ value.to_s ] end end |
#close_connection ⇒ Object
Close the connection from which the SIP request/response has been received.
169 170 171 172 173 |
# File 'lib/oversip/sip/message.rb', line 169 def close_connection return false if @transport == :udp @connection.close true end |
#contact_reg_id? ⇒ Boolean
77 |
# File 'lib/oversip/sip/message.rb', line 77 def contact_reg_id? ; @contact_has_reg_id end |
#delete_header(name) ⇒ Object
Completely deletes the header with given name. Returns an array containing all the header values, nil otherwise.
122 123 124 |
# File 'lib/oversip/sip/message.rb', line 122 def delete_header name @headers.delete MessageParser.headerize(name) end |
#delete_header_top(name) ⇒ Object
Removes the first value of a given header name. Returns the extracted value, nil otherwise.
128 129 130 131 132 |
# File 'lib/oversip/sip/message.rb', line 128 def delete_header_top name if hdr = @headers[k=MessageParser.headerize(name)] hdr.size > 1 ? hdr.shift : @headers.delete(k)[0] end end |
#dialog_forming? ⇒ Boolean
79 80 81 |
# File 'lib/oversip/sip/message.rb', line 79 def dialog_forming? DIALOG_FORMING_METHODS[@sip_method] end |
#has_header?(name) ⇒ Boolean
Returns true if a header with the given header name exists, false otherwise.
92 93 94 |
# File 'lib/oversip/sip/message.rb', line 92 def has_header? name @headers[MessageParser.headerize(name)] && true end |
#header_all(name) ⇒ Object
Returns an array with all the values of the given header name, an empty array if it doesn’t exist.
104 105 106 |
# File 'lib/oversip/sip/message.rb', line 104 def header_all name ( hdr = @headers[MessageParser.headerize(name)] ) ? hdr : EMPTY_ARRAY end |
#header_top(name) ⇒ Object Also known as: header
Returns the first value of the given header name, nil if it doesn’t exist.
97 98 99 |
# File 'lib/oversip/sip/message.rb', line 97 def header_top name ( hdr = @headers[MessageParser.headerize(name)] ) ? hdr[0] : nil end |
#insert_header(name, value) ⇒ Object
Inserts the given value in the first position of header name. value must be a string.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/oversip/sip/message.rb', line 136 def insert_header name, value if hdr = @headers[k=MessageParser.headerize(name)] hdr.unshift value.to_s else #@headers[k] = [ value.to_s ] # NOTE: If the header name doesn't already exist in the mesage, insert # the new header in the first position of the Hash. @headers = { k => [ value.to_s ] }.merge! @headers end end |
#outbound_aware? ⇒ Boolean
87 88 89 |
# File 'lib/oversip/sip/message.rb', line 87 def outbound_aware? OUTBOUND_AWARE_METHODS[@sip_method] end |
#record_routing_aware? ⇒ Boolean
83 84 85 |
# File 'lib/oversip/sip/message.rb', line 83 def record_routing_aware? RECORD_ROUTING_AWARE_METHODS[@sip_method] end |
#replace_header_top(name, value) ⇒ Object
Replaces the top value of the given header name with the string given as argument value.
159 160 161 162 163 164 165 |
# File 'lib/oversip/sip/message.rb', line 159 def replace_header_top name, value if hdr = @headers[k=MessageParser.headerize(name)] hdr[0] = value.to_s else @headers[k] = [ value.to_s ] end end |
#set_header(name, value) ⇒ Object
Replaces the header of given name with a the given value. value can be a single value or an array.
110 111 112 113 114 115 116 117 118 |
# File 'lib/oversip/sip/message.rb', line 110 def set_header name, value @headers[MessageParser.headerize(name)] = case value when ::Array value else [ value.to_s ] end end |
#tcp? ⇒ Boolean
64 |
# File 'lib/oversip/sip/message.rb', line 64 def tcp? ; @transport == :tcp end |
#tls? ⇒ Boolean
65 |
# File 'lib/oversip/sip/message.rb', line 65 def tls? ; @transport == :tls end |
#udp? ⇒ Boolean
63 |
# File 'lib/oversip/sip/message.rb', line 63 def udp? ; @transport == :udp end |
#unknown_method? ⇒ Boolean
71 |
# File 'lib/oversip/sip/message.rb', line 71 def unknown_method? ; @is_unknown_method end |
#via_alias? ⇒ Boolean
75 |
# File 'lib/oversip/sip/message.rb', line 75 def via_alias? ; @via_has_alias end |
#via_rport? ⇒ Boolean
73 |
# File 'lib/oversip/sip/message.rb', line 73 def via_rport? ; @via_has_rport end |
#websocket? ⇒ Boolean
69 |
# File 'lib/oversip/sip/message.rb', line 69 def websocket? ; @transport == :ws || @transport == :wss end |
#ws? ⇒ Boolean
66 |
# File 'lib/oversip/sip/message.rb', line 66 def ws? ; @transport == :ws end |
#wss? ⇒ Boolean
67 |
# File 'lib/oversip/sip/message.rb', line 67 def wss? ; @transport == :wss end |