Class: Riddl::Protocols::XMPP::Parser
- Inherits:
-
Object
- Object
- Riddl::Protocols::XMPP::Parser
- Defined in:
- lib/ruby/riddl/protocols/xmpp/parser.rb
Constant Summary collapse
- FORM_CONTENT_TYPES =
[ #{{{ 'application/x-www-form-urlencoded' #}}} ].freeze
- STD_ATTRIBUTES =
[ #{{{ 'content-type', 'content-disposition', 'content-id', 'content-transfer-type', 'RIDDL-TYPE', #}}} ].freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(query_string, input) ⇒ Parser
constructor
A new instance of Parser.
- #parse_part(input, head, ctype, content_disposition, content_id, riddl_type) ⇒ Object
Constructor Details
#initialize(query_string, input) ⇒ Parser
Returns a new instance of Parser.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ruby/riddl/protocols/xmpp/parser.rb', line 87 def initialize(query_string,input) #{{{ @params = Riddl::Parameter::Array.new parse_nested_query(query_string,:query) input.find('/message/xr:part').each do |p| content_type = p.attributes['content-type'] || nil media_type = content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase if FORM_CONTENT_TYPES.include?(media_type) # sub is a fix for Safari Ajax postings that always append \0 parse_nested_query(p.text.sub(/\0\z/, ''),:body) else parse_part(p.children,p.attributes,content_type,p.attributes['content-disposition']||'',p.attributes['content-id']||'',p.attributes['RIDDL-TYPE']||'') end end #}}} end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
106 107 108 |
# File 'lib/ruby/riddl/protocols/xmpp/parser.rb', line 106 def params @params end |
Instance Method Details
#parse_part(input, head, ctype, content_disposition, content_id, riddl_type) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby/riddl/protocols/xmpp/parser.rb', line 25 def parse_part(input,head,ctype,content_disposition,content_id,riddl_type) #{{{ head = Hash[ head.map do |h| STD_ATTRIBUTES.include?(h.qname.name) ? nil : [h.qname.name, h.value] end.compact ] ctype = nil if riddl_type == 'simple' filename = content_disposition[/ filename="?([^\";]*)"?/ni, 1] name = content_disposition[/ name="?([^\";]*)"?/ni, 1] || content_id if ctype || filename body = Parameter::Tempfile.new("RiddlMultipart") body.binmode if body.respond_to?(:binmode) else body = '' end input.each { |i| body << i.dump } body.rewind if body.respond_to?(:binmode) add_to_params(name,body,filename,ctype,head) #}}} end |