Class: OverSIP::SIP::Uri

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

Direct Known Subclasses

NameAddr

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme = :sip, user = nil, host = nil, port = nil) ⇒ Uri

Returns a new instance of Uri.



14
15
16
17
18
19
20
21
22
# File 'lib/oversip/sip/uri.rb', line 14

def initialize scheme=:sip, user=nil, host=nil, port=nil
  @scheme = scheme.to_sym
  @user = user
  @host = host
  @host_type = ::OverSIP::Utils.ip_type(host) || :domain  if host
  @port = port

  @uri_modified = true
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def headers
  @headers
end

#hostObject Also known as: domain

Returns the value of attribute host.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def host
  @host
end

#host_typeObject

Returns the value of attribute host_type.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def host_type
  @host_type
end

#ovid_paramObject (readonly)

Returns the value of attribute ovid_param.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def ovid_param
  @ovid_param
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def params
  @params
end

#phone_context_paramObject

Returns the value of attribute phone_context_param.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def phone_context_param
  @phone_context_param
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def scheme
  @scheme
end

#transport_paramObject

Returns the value of attribute transport_param.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def transport_param
  @transport_param
end

#userObject Also known as: number

Returns the value of attribute user.



4
5
6
# File 'lib/oversip/sip/uri.rb', line 4

def user
  @user
end

Class Method Details

.parse(value) ⇒ Object



7
8
9
10
11
# File 'lib/oversip/sip/uri.rb', line 7

def self.parse value
  uri = ::OverSIP::SIP::MessageParser.parse_uri value, false
  raise ::OverSIP::ParsingError, "invalid URI #{value.inspect}"  unless uri.is_a? (::OverSIP::SIP::Uri)
  uri
end

Instance Method Details

#aorObject

Returns a String with the AoR of the URI:

  • SIP URI: sip:user@domain.

  • TEL URI: tel:number

  • Others: nil



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/oversip/sip/uri.rb', line 186

def aor
  case @scheme
    when :sip, :sips
      aor = "sip:"
      ( aor << ::EscapeUtils.escape_uri(@user) << "@" )  if @user
      aor << @host

    when :tel
      aor = "tel:"
      aor << @user

    end

  aor
end

#clear_paramsObject



101
102
103
104
105
106
107
108
109
# File 'lib/oversip/sip/uri.rb', line 101

def clear_params
  return nil  if unknown_scheme?
  return false  unless @params
  @params.clear
  @transport_param = nil
  @phone_context_param = nil
  @uri_modified = true
  true
end

#del_param(k) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/oversip/sip/uri.rb', line 91

def del_param k
  return nil  if unknown_scheme?
  return false  unless @params
  if @params.include?(k=k.downcase)
    @uri_modified = true
    return @params.delete(k)
  end
  false
end

#get_param(k) ⇒ Object



79
80
81
82
# File 'lib/oversip/sip/uri.rb', line 79

def get_param k
  return nil  if unknown_scheme?
  params[k.to_s.downcase]
end

#has_param?(k) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/oversip/sip/uri.rb', line 74

def has_param? k
  return nil  if unknown_scheme?
  params.include? k.to_s.downcase
end

#lr_param?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/oversip/sip/uri.rb', line 133

def lr_param?
  @lr_param ? true : false
end

#modified?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/oversip/sip/uri.rb', line 202

def modified?
  @uri_modified
end

#ob_param?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/oversip/sip/uri.rb', line 137

def ob_param?
  @ob_param ? true : false
end

#set_param(k, v) ⇒ Object



84
85
86
87
88
89
# File 'lib/oversip/sip/uri.rb', line 84

def set_param k, v
  return nil  if unknown_scheme?
  @params ||= {}
  @params[k.downcase] = v
  @uri_modified = true
end

#sip?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/oversip/sip/uri.rb', line 24

def sip?
  @scheme == :sip or @scheme == :sips
end

#tel?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/oversip/sip/uri.rb', line 28

def tel?
  @scheme == :tel
end

#unknown_scheme?Boolean

Returns:

  • (Boolean)


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

def unknown_scheme?
  not @scheme.is_a? Symbol
end

#uriObject Also known as: to_s, inspect



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/oversip/sip/uri.rb', line 147

def uri
  return @uri  unless @uri_modified

  case @scheme
    when :sip, :sips
      @uri = @scheme.to_s << ":"
      ( @uri << ::EscapeUtils.escape_uri(@user) << "@" )  if @user
      @uri << @host
      ( @uri << ":" << @port.to_s )  if @port

      @params.each do |k,v|
        @uri << ";" << k
        ( @uri << "=" << v.to_s )  if v
      end  if @params

      @uri << @headers  if @headers

    when :tel
      @uri = "tel:"
      @uri << @user

      @params.each do |k,v|
        @uri << ";" << k
        ( @uri << "=" << v.to_s )  if v
      end  if @params

    end

  @uri_modified = false
  @uri
end