Class: Rex::Proto::SIP::Message

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

Overview

Represents a generic SIP message

Direct Known Subclasses

Response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

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

#headersObject

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(message)
  pairs = message.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