Class: Rex::Proto::SIP::Message
- Inherits:
-
Object
- Object
- Rex::Proto::SIP::Message
- Defined in:
- lib/rex/proto/sip/response.rb
Overview
Represents a generic SIP message
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
Class Method Summary collapse
-
.extract_headers(message) ⇒ Object
Returns a hash of header name to values mapping from the provided message, or nil if no headers are found.
Instance Method Summary collapse
-
#header(name) ⇒ Object
Returns a list of all values from all
name
headers, regardless of case, or nil if no matching header is found. -
#initialize ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
13 14 15 |
# File 'lib/rex/proto/sip/response.rb', line 13 def initialize @headers = {} end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
11 12 13 |
# File 'lib/rex/proto/sip/response.rb', line 11 def headers @headers end |
Class Method Details
.extract_headers(message) ⇒ Object
Returns a hash of header name to values mapping from the provided message, or nil if no headers are found
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rex/proto/sip/response.rb', line 28 def self.extract_headers() pairs = .scan(/^([^\s:]+):\s*(.*)$/) return nil if pairs.empty? headers = {} pairs.each do |pair| headers[pair.first] ||= [] headers[pair.first] << pair.last.strip end headers end |
Instance Method Details
#header(name) ⇒ Object
Returns a list of all values from all name
headers, regardless of case, or nil if no matching header is found
19 20 21 22 23 |
# File 'lib/rex/proto/sip/response.rb', line 19 def header(name) matches = @headers.select { |k, _| k.downcase == name.downcase } return nil if matches.empty? matches.values.flatten end |