Class: Gelfd::ChunkedParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gelfd/chunked_parser.rb

Constant Summary collapse

@@chunk_map =
Hash.new {|hash,key| hash[key] = {:total_chunks => 0, :chunks => {} } }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#chunksObject

Returns the value of attribute chunks.



5
6
7
# File 'lib/gelfd/chunked_parser.rb', line 5

def chunks
  @chunks
end

#decoded_dataObject

Returns the value of attribute decoded_data.



5
6
7
# File 'lib/gelfd/chunked_parser.rb', line 5

def decoded_data
  @decoded_data
end

#max_chunksObject

Returns the value of attribute max_chunks.



5
6
7
# File 'lib/gelfd/chunked_parser.rb', line 5

def max_chunks
  @max_chunks
end

#message_idObject

Returns the value of attribute message_id.



5
6
7
# File 'lib/gelfd/chunked_parser.rb', line 5

def message_id
  @message_id
end

#seenObject

Returns the value of attribute seen.



5
6
7
# File 'lib/gelfd/chunked_parser.rb', line 5

def seen
  @seen
end

Class Method Details

.assemble_chunks(msg_id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gelfd/chunked_parser.rb', line 14

def self.assemble_chunks(msg_id)
  buff = ''
  chunks = @@chunk_map[msg_id][:chunks]
  chunks.keys.sort.each do |k|
    buff += chunks[k]
  end
  begin
    # TODO
    # This has a chance for an DoS
    # you can send a chunked message as a chunked message
    t = Parser.parse(buff.clone)
    @@chunk_map.delete(msg_id)
    t
  rescue Exception => e
    "Exception: #{e.message}"
  end
end

.parse(data) ⇒ Object



7
8
9
10
11
12
# File 'lib/gelfd/chunked_parser.rb', line 7

def self.parse(data)
  msg_id = self.parse_chunk(data)
  if @@chunk_map[msg_id][:chunks].size == @@chunk_map[msg_id][:total_chunks]
    assemble_chunks(msg_id)
  end
end