Module: Handsoap

Defined in:
lib/handsoap/service.rb,
lib/handsoap/parser.rb,
lib/handsoap/service.rb,
lib/handsoap/compiler.rb,
lib/handsoap/xml_mason.rb,
lib/handsoap/xml_query_front.rb

Overview

Legacy/BC code here. This shouldn’t be used in new applications.

Defined Under Namespace

Modules: Parser, XmlMason, XmlQueryFront Classes: CodeWriter, Compiler, Fault, Service

Class Method Summary collapse

Class Method Details

.http_driverObject



8
9
10
# File 'lib/handsoap/service.rb', line 8

def self.http_driver
  @http_driver || (self.http_driver = :curb)
end

.http_driver=(driver) ⇒ Object



12
13
14
15
16
17
# File 'lib/handsoap/service.rb', line 12

def self.http_driver=(driver)
  @http_driver = driver
  require 'httpclient' if driver == :httpclient
  require 'curb' if driver == :curb
  return driver
end

.parse_multipart(boundary, content_io, content_length = nil) ⇒ Object

Parses a multipart http-response body into parts. boundary is a string of the boundary token. content_io is either a string or an IO. If it’s an IO, then content_length must be specified. content_length (optional) is an integer, specifying the length of content_io

This code is lifted from cgi.rb

Raises:

  • (EOFError)


334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/handsoap/service.rb', line 334

def self.parse_multipart(boundary, content_io, content_length = nil)
  if content_io.kind_of? String
    content_length = content_io.length
    content_io = StringIO.new(content_io, 'r')
  elsif !(content_io.kind_of? IO) || content_length.nil?
    raise "Second argument must be String or IO with content_length"
  end

  boundary = "--" + boundary
  quoted_boundary = Regexp.quote(boundary, "n")
  buf = ""
  bufsize = 10 * 1024
  boundary_end = ""

  # start multipart/form-data
  content_io.binmode if defined? content_io.binmode
  boundary_size = boundary.size + "\r\n".size
  content_length -= boundary_size
  status = content_io.read(boundary_size)
  if nil == status
    raise EOFError, "no content body"
  elsif boundary + "\r\n" != status
    raise EOFError, "bad content body"
  end

  parts = []

  loop do
    head = nil
    if 10240 < content_length
      require "tempfile"
      body = Tempfile.new("CGI")
    else
      begin
        require "stringio"
        body = StringIO.new
      rescue LoadError
        require "tempfile"
        body = Tempfile.new("CGI")
      end
    end
    body.binmode if defined? body.binmode

    until head and /#{quoted_boundary}(?:\r\n|--)/n.match(buf)

      if (not head) and /\r\n\r\n/n.match(buf)
        buf = buf.sub(/\A((?:.|\n)*?\r\n)\r\n/n) do
          head = $1.dup
          ""
        end
        next
      end

      if head and ( ("\r\n" + boundary + "\r\n").size < buf.size )
        body.print buf[0 ... (buf.size - ("\r\n" + boundary + "\r\n").size)]
        buf[0 ... (buf.size - ("\r\n" + boundary + "\r\n").size)] = ""
      end

      c = if bufsize < content_length
            content_io.read(bufsize)
          else
            content_io.read(content_length)
          end
      if c.nil? || c.empty?
        raise EOFError, "bad content body"
      end
      buf.concat(c)
      content_length -= c.size
    end

    buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do
      body.print $1
      if "--" == $2
        content_length = -1
      end
      boundary_end = $2.dup
      ""
    end

    body.rewind
    parts << {:head => head, :body => body.read(body.size)}

    # if body.kind_of? ::StringIO
    #   parts << {:head => head, :body => body.string}
    # elsif body.kind_of? ::Tempfile
    #   body.rewind
    #   parts << {:head => head, :body => body.read(body.size)}
    # else
    #   raise "body must be StringIO or Tempfile"
    # end

    break if buf.size == 0
    break if content_length == -1
  end
  raise EOFError, "bad boundary end of body part" unless boundary_end =~ /--/
  parts
end

.pretty_format_envelope(xml_string) ⇒ Object



314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/handsoap/service.rb', line 314

def self.pretty_format_envelope(xml_string)
  if /^<.*:Envelope/.match(xml_string)
    begin
      doc = Handsoap::XmlQueryFront.parse_string(xml_string, Handsoap.xml_query_driver)
    rescue Exception => ex
      return xml_string
    end
    return doc.to_xml
    # return "\n\e[1;33m" + doc.to_s + "\e[0m"
  end
  return xml_string
end

.xml_query_driverObject



19
20
21
# File 'lib/handsoap/service.rb', line 19

def self.xml_query_driver
  @xml_query_driver || (self.xml_query_driver = :nokogiri)
end

.xml_query_driver=(driver) ⇒ Object



23
24
25
# File 'lib/handsoap/service.rb', line 23

def self.xml_query_driver=(driver)
  @xml_query_driver = Handsoap::XmlQueryFront.load_driver!(driver)
end