Class: OverSIP::SIP::UacRequest
- Inherits:
-
Object
- Object
- OverSIP::SIP::UacRequest
- Defined in:
- lib/oversip/sip/uac_request.rb
Constant Summary collapse
- DEFAULT_MAX_FORWARDS =
"20"
- DEFAULT_FROM =
"\"OverSIP #{::OverSIP::VERSION}\" <sip:[email protected]>"
Instance Attribute Summary collapse
-
#antiloop_id ⇒ Object
readonly
Returns the value of attribute antiloop_id.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#call_id ⇒ Object
readonly
Returns the value of attribute call_id.
-
#cseq ⇒ Object
readonly
Returns the value of attribute cseq.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#from_tag ⇒ Object
readonly
Returns the value of attribute from_tag.
-
#routes ⇒ Object
readonly
Always nil (needed for OverSIP::SIP::Tags.create_antiloop_id()..
-
#ruri ⇒ Object
readonly
Returns the value of attribute ruri.
-
#sip_method ⇒ Object
readonly
Returns the value of attribute sip_method.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#tvars ⇒ Object
Transaction variables (a hash).
Instance Method Summary collapse
- #delete_header_top(name) ⇒ Object
-
#initialize(data, extra_headers = [], body = nil) ⇒ UacRequest
constructor
A new instance of UacRequest.
- #insert_header(name, value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data, extra_headers = [], body = nil) ⇒ UacRequest
Returns a new instance of UacRequest.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/oversip/sip/uac_request.rb', line 14 def initialize data, extra_headers=[], body=nil unless (@sip_method = data[:sip_method]) raise ::OverSIP::RuntimeError, "no data[:sip_method] given" end unless (@ruri = data[:ruri]) raise ::OverSIP::RuntimeError, "no data[:ruri] given" end @from = data[:from] || DEFAULT_FROM @from_tag = data[:from_tag] || ::SecureRandom.hex(4) @to = data[:to] || @ruri @call_id = data[:call_id] || ::SecureRandom.hex(8) @cseq = data[:cseq] || rand(1000) @max_forwards = data[:max_forwards] || DEFAULT_MAX_FORWARDS @headers = {} @extra_headers = extra_headers @body = body @antiloop_id = ::OverSIP::SIP::Tags.create_antiloop_id(self) end |
Instance Attribute Details
#antiloop_id ⇒ Object (readonly)
Returns the value of attribute antiloop_id.
9 10 11 |
# File 'lib/oversip/sip/uac_request.rb', line 9 def antiloop_id @antiloop_id end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def body @body end |
#call_id ⇒ Object (readonly)
Returns the value of attribute call_id.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def call_id @call_id end |
#cseq ⇒ Object (readonly)
Returns the value of attribute cseq.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def cseq @cseq end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def from @from end |
#from_tag ⇒ Object (readonly)
Returns the value of attribute from_tag.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def from_tag @from_tag end |
#routes ⇒ Object (readonly)
Always nil (needed for OverSIP::SIP::Tags.create_antiloop_id().
10 11 12 |
# File 'lib/oversip/sip/uac_request.rb', line 10 def routes @routes end |
#ruri ⇒ Object (readonly)
Returns the value of attribute ruri.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def ruri @ruri end |
#sip_method ⇒ Object (readonly)
Returns the value of attribute sip_method.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def sip_method @sip_method end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
8 9 10 |
# File 'lib/oversip/sip/uac_request.rb', line 8 def to @to end |
#tvars ⇒ Object
Transaction variables (a hash).
11 12 13 |
# File 'lib/oversip/sip/uac_request.rb', line 11 def tvars @tvars end |
Instance Method Details
#delete_header_top(name) ⇒ Object
43 44 45 |
# File 'lib/oversip/sip/uac_request.rb', line 43 def delete_header_top name @headers.delete name end |
#insert_header(name, value) ⇒ Object
38 39 40 |
# File 'lib/oversip/sip/uac_request.rb', line 38 def insert_header name, value @headers[name] = value.to_s end |
#to_s ⇒ Object
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 77 78 |
# File 'lib/oversip/sip/uac_request.rb', line 48 def to_s # Let @ruri to be an String, an OverSIP::SIP::Uri or an OverSIP::SIP::NameAddr instance. ruri = case @ruri when ::String @ruri when ::OverSIP::SIP::Uri, ::OverSIP::SIP::NameAddr @ruri.uri end msg = "#{@sip_method.to_s} #{ruri} SIP/2.0\r\n" @headers.each do |name, value| msg << name << ": #{value}\r\n" end msg << "From: #{@from.to_s};tag=#{@from_tag}\r\n" msg << "To: #{@to.to_s}\r\n" msg << "Call-ID: #{@call_id}\r\n" msg << "CSeq: #{@cseq.to_s} #{@sip_method.to_s}\r\n" msg << "Content-Length: #{@body ? @body.bytesize : "0"}\r\n" msg << "Max-Forwards: #{@max_forwards.to_s}\r\n" msg << HDR_USER_AGENT << CRLF @extra_headers.each do |header| msg << header << CRLF end msg << CRLF msg << @body if @body msg end |