Class: Rex::Proto::SIP::Response

Inherits:
Message
  • Object
show all
Defined in:
lib/rex/proto/sip/response.rb

Overview

Represents a SIP response message

Instance Attribute Summary collapse

Attributes inherited from Message

#headers

Class Method Summary collapse

Methods inherited from Message

extract_headers, #header, #initialize

Constructor Details

This class inherits a constructor from Rex::Proto::SIP::Message

Instance Attribute Details

#codeObject

Returns the value of attribute code


42
43
44
# File 'lib/rex/proto/sip/response.rb', line 42

def code
  @code
end

#messageObject

Returns the value of attribute message


42
43
44
# File 'lib/rex/proto/sip/response.rb', line 42

def message
  @message
end

#status_lineObject

Returns the value of attribute status_line


42
43
44
# File 'lib/rex/proto/sip/response.rb', line 42

def status_line
  @status_line
end

#versionObject

Returns the value of attribute version


42
43
44
# File 'lib/rex/proto/sip/response.rb', line 42

def version
  @version
end

Class Method Details

.parse(data) ⇒ Object

Parses data, constructs and returns a Response


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rex/proto/sip/response.rb', line 45

def self.parse(data)
  response = Response.new
  # do some basic sanity checking on this response to ensure that it is SIP
  response.status_line = data.split(/\r\n/)[0]
  unless response.status_line && response.status_line =~ SIP_STATUS_REGEX
    fail(ArgumentError, "Invalid SIP status line: #{response.status_line}")
  end
  response.version = Regexp.last_match(1)
  response.code = Regexp.last_match(2)
  response.message = Regexp.last_match(3)
  response.headers = extract_headers(data)
  response
end