Class: OverSIP::SIP::Message

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/oversip/sip/message.rb,
ext/sip_parser/sip_parser_ruby.c

Direct Known Subclasses

Request, Response

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

Instance Method Summary collapse

Methods included from Logger

close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



46
47
48
# File 'lib/oversip/sip/message.rb', line 46

def body
  @body
end

#call_idObject (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

#connectionObject

Returns the value of attribute connection.



17
18
19
# File 'lib/oversip/sip/message.rb', line 17

def connection
  @connection
end

#contactObject (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_paramsObject (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_lengthObject (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

#cseqObject (readonly)

Returns the value of attribute cseq.



38
39
40
# File 'lib/oversip/sip/message.rb', line 38

def cseq
  @cseq
end

#fromObject

NameAddr instance.



48
49
50
# File 'lib/oversip/sip/message.rb', line 48

def from
  @from
end

#from_tagObject (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_fromObject (readonly)

String



56
57
58
# File 'lib/oversip/sip/message.rb', line 56

def hdr_from
  @hdr_from
end

#hdr_routeObject (readonly)

Array



58
59
60
# File 'lib/oversip/sip/message.rb', line 58

def hdr_route
  @hdr_route
end

#hdr_toObject (readonly)

String



57
58
59
# File 'lib/oversip/sip/message.rb', line 57

def hdr_to
  @hdr_to
end

#hdr_viaObject (readonly)

Array



55
56
57
# File 'lib/oversip/sip/message.rb', line 55

def hdr_via
  @hdr_via
end

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/oversip/sip/message.rb', line 22

def headers
  @headers
end

#max_forwardsObject (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_viasObject (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_requireObject (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

#requireObject (readonly)

Returns the value of attribute require.



42
43
44
# File 'lib/oversip/sip/message.rb', line 42

def require
  @require
end

#routesObject (readonly)

Returns the value of attribute routes.



41
42
43
# File 'lib/oversip/sip/message.rb', line 41

def routes
  @routes
end

#sip_methodObject (readonly)

SIP message attributes.



20
21
22
# File 'lib/oversip/sip/message.rb', line 20

def sip_method
  @sip_method
end

#sip_versionObject (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_ipObject

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_typeObject

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_portObject

Returns the value of attribute source_port.



16
17
18
# File 'lib/oversip/sip/message.rb', line 16

def source_port
  @source_port
end

#supportedObject (readonly)

Returns the value of attribute supported.



43
44
45
# File 'lib/oversip/sip/message.rb', line 43

def supported
  @supported
end

#toObject

NameAddr instance.



50
51
52
# File 'lib/oversip/sip/message.rb', line 50

def to
  @to
end

#to_tagObject (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

#transportObject

SIP related attributes.



13
14
15
# File 'lib/oversip/sip/message.rb', line 13

def transport
  @transport
end

#tvarsObject

Other attributes.



61
62
63
# File 'lib/oversip/sip/message.rb', line 61

def tvars
  @tvars
end

#via_branchObject (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_idObject

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_rfc3261Object (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_valueObject (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_aliasObject (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_rportObject (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_paramsObject (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_receivedObject (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_rportObject

Value not parsed.



31
32
33
# File 'lib/oversip/sip/message.rb', line 31

def via_rport
  @via_rport
end

#via_sent_by_hostObject (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_portObject (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_connectionObject

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

Returns:

  • (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

Returns:

  • (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.

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


64
# File 'lib/oversip/sip/message.rb', line 64

def tcp?               ; @transport == :tcp          end

#tls?Boolean

Returns:

  • (Boolean)


65
# File 'lib/oversip/sip/message.rb', line 65

def tls?               ; @transport == :tls          end

#udp?Boolean

Returns:

  • (Boolean)


63
# File 'lib/oversip/sip/message.rb', line 63

def udp?               ; @transport == :udp          end

#unknown_method?Boolean

Returns:

  • (Boolean)


71
# File 'lib/oversip/sip/message.rb', line 71

def unknown_method?    ; @is_unknown_method          end

#via_alias?Boolean

Returns:

  • (Boolean)


75
# File 'lib/oversip/sip/message.rb', line 75

def via_alias?         ; @via_has_alias              end

#via_rport?Boolean

Returns:

  • (Boolean)


73
# File 'lib/oversip/sip/message.rb', line 73

def via_rport?         ; @via_has_rport              end

#websocket?Boolean

Returns:

  • (Boolean)


69
# File 'lib/oversip/sip/message.rb', line 69

def websocket?         ; @transport == :ws || @transport == :wss  end

#ws?Boolean

Returns:

  • (Boolean)


66
# File 'lib/oversip/sip/message.rb', line 66

def ws?                ; @transport == :ws           end

#wss?Boolean

Returns:

  • (Boolean)


67
# File 'lib/oversip/sip/message.rb', line 67

def wss?               ; @transport == :wss          end