Skip to content
Browse files

Remove .gitignore and update xmlrpc from MRI 1.9.3. Fixes #1721.

  • Loading branch information...
1 parent 56494d0 commit 53fc71291899daa2f2602bdd0956f5f93fbb3ef2 @ileitch ileitch committed May 18, 2012
View
1 lib/19/xmlrpc/.gitignore
@@ -1 +0,0 @@
-config.rb
View
46 lib/19/xmlrpc/README.rdoc
@@ -59,7 +59,7 @@ use the client and implement a server.
* REXML (REXMLStreamParser)
* xml-scan (XMLScanStreamParser)
* Fastest parser is Expat's XMLStreamParser!
-
+
* General
* possible to choose between XMLParser module (Expat wrapper) and REXML/NQXML (pure Ruby) parsers
* Marshalling Ruby objects to Hashs and reconstruct them later from a Hash
@@ -70,7 +70,7 @@ use the client and implement a server.
=== Client
require "xmlrpc/client"
-
+
# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
@@ -86,7 +86,7 @@ use the client and implement a server.
There are two possible ways, of handling a fault-structure:
-==== by catching a XMLRPC::FaultException exception
+==== by catching a XMLRPC::FaultException exception
require "xmlrpc/client"
@@ -107,7 +107,7 @@ There are two possible ways, of handling a fault-structure:
puts e.faultCode
puts e.faultString
end
-
+
==== by calling "call2" which returns a boolean
require "xmlrpc/client"
@@ -128,7 +128,7 @@ There are two possible ways, of handling a fault-structure:
puts result.faultCode
puts result.faultString
end
-
+
=== Client using Proxy
You can create a +Proxy+ object onto which you can call methods. This way it
@@ -137,7 +137,7 @@ looks nicer. Both forms, _call_ and _call2_ are supported through _proxy_ and
given to each XML-RPC call using that Proxy.
require "xmlrpc/client"
-
+
# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
@@ -167,7 +167,7 @@ can be mixed:
s.add_handler("sample.sumAndDifference") do |a,b|
{ "sum" => a + b, "difference" => a - b }
end
-
+
s.serve
==== Java-like (handler classes)
@@ -181,8 +181,8 @@ can be mixed:
{ "sum" => a + b, "difference" => a - b }
end
end
-
- # NOTE: Security Hole (read below)!!!
+
+ # NOTE: Security Hole (read below)!!!
s.add_handler("sample", MyHandler.new)
s.serve
@@ -195,17 +195,17 @@ To return a fault-structure you have to raise an FaultException e.g.:
From Brian Candler:
- Above code sample has an extremely nasty security hole, in that you can now call
- any method of 'MyHandler' remotely, including methods inherited from Object
- and Kernel! For example, in the client code, you can use
-
- puts server.call("sample.send","`","ls")
-
- (backtick being the method name for running system processes). Needless to
- say, 'ls' can be replaced with something else.
-
- The version which binds proc objects (or the version presented below in the next section)
- doesn't have this problem, but people may be tempted to use the second version because it's
+ Above code sample has an extremely nasty security hole, in that you can now call
+ any method of 'MyHandler' remotely, including methods inherited from Object
+ and Kernel! For example, in the client code, you can use
+
+ puts server.call("sample.send","`","ls")
+
+ (backtick being the method name for running system processes). Needless to
+ say, 'ls' can be replaced with something else.
+
+ The version which binds proc objects (or the version presented below in the next section)
+ doesn't have this problem, but people may be tempted to use the second version because it's
so nice and 'Rubyesque'. I think it needs a big red disclaimer.
@@ -225,7 +225,7 @@ A solution is to undef insecure methods or to use (({XMLRPC::iPIMethods})) as sh
# ...
-This adds only public instance methods explicitly declared in class MyHandler
+This adds only public instance methods explicitly declared in class MyHandler
(and not those inherited from any other class).
==== With interface declarations
@@ -271,7 +271,7 @@ XML parser, then you have to call the <i>set_parser</i> method of
<tt>XMLRPC::BasicServer</tt> or by editing xmlrpc/config.rb.
Client Example:
-
+
# ...
server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
server.set_parser(XMLRPC::XMLParser::XMLParser.new)
@@ -283,7 +283,7 @@ Server Example:
s = XMLRPC::CGIServer.new
s.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
# ...
-
+
or:
# ...
View
2 lib/19/xmlrpc/base64.rb
@@ -77,5 +77,5 @@ def Base64.encode(str)
=begin
= History
- $Id: base64.rb 25189 2009-10-02 12:04:37Z akr $
+ $Id$
=end
View
59 lib/19/xmlrpc/client.rb
@@ -268,7 +268,7 @@
= History
- $Id: client.rb 25189 2009-10-02 12:04:37Z akr $
+ $Id$
=end
@@ -279,6 +279,7 @@
require "xmlrpc/config"
require "xmlrpc/utils" # ParserWriterChooseMixin
require "net/http"
+require "uri"
module XMLRPC
@@ -324,8 +325,7 @@ def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
@proxy_port = @proxy_port.to_i if @proxy_port != nil
# HTTP object for synchronous calls
- Net::HTTP.version_1_2
- @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port)
+ @http = net_http(@host, @port, @proxy_host, @proxy_port)
@http.use_ssl = @use_ssl if @use_ssl
@http.read_timeout = @timeout
@http.open_timeout = @timeout
@@ -338,21 +338,25 @@ def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
class << self
def new2(uri, proxy=nil, timeout=nil)
- if match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(uri)
- proto = match[1]
- user, passwd = (match[3] || "").split(":")
- host, port = match[4].split(":")
- path = match[5]
-
- if proto != "http" and proto != "https"
- raise "Wrong protocol specified. Only http or https allowed!"
- end
+ begin
+ url = URI(uri)
+ rescue URI::InvalidURIError => e
+ raise ArgumentError, e.message, e.backtrace
+ end
- else
- raise "Wrong URI as parameter!"
+ unless URI::HTTP === url
+ raise ArgumentError, "Wrong protocol specified. Only http or https allowed!"
end
+ proto = url.scheme
+ user = url.user
+ passwd = url.password
+ host = url.host
+ port = url.port
+ path = url.path.empty? ? nil : url.request_uri
+
proxy_host, proxy_port = (proxy || "").split(":")
+ proxy_port = proxy_port.to_i if proxy_port
self.new(host, path, port, proxy_host, proxy_port, user, passwd, (proto == "https"), timeout)
end
@@ -487,21 +491,25 @@ def proxy2_async(prefix=nil, *args)
private # ----------------------------------------------------------
+ def net_http(host, port, proxy_host, proxy_port)
+ Net::HTTP.new host, port, proxy_host, proxy_port
+ end
+
def set_auth
if @user.nil?
@auth = nil
else
a = "#@user"
a << ":#@password" if @password != nil
- @auth = ("Basic " + [a].pack("m")).chomp
+ @auth = "Basic " + [a].pack("m0")
end
end
def do_rpc(request, async=false)
header = {
"User-Agent" => USER_AGENT,
"Content-Type" => "text/xml; charset=utf-8",
- "Content-Length" => request.size.to_s,
+ "Content-Length" => request.bytesize.to_s,
"Connection" => (async ? "close" : "keep-alive")
}
@@ -518,15 +526,14 @@ def do_rpc(request, async=false)
if async
# use a new HTTP object for each call
- Net::HTTP.version_1_2
- http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port)
+ http = net_http(@host, @port, @proxy_host, @proxy_port)
http.use_ssl = @use_ssl if @use_ssl
http.read_timeout = @timeout
http.open_timeout = @timeout
# post request
http.start {
- resp = http.post2(@path, request, header)
+ resp = http.request_post(@path, request, header)
}
else
# reuse the HTTP object for each call => connection alive is possible
@@ -535,7 +542,7 @@ def do_rpc(request, async=false)
@http.start if not @http.started?
# post request
- resp = @http.post2(@path, request, header)
+ resp = @http.request_post(@path, request, header)
end
@http_last_response = resp
@@ -549,7 +556,9 @@ def do_rpc(request, async=false)
raise "HTTP-Error: #{resp.code} #{resp.message}"
end
- ct = parse_content_type(resp["Content-Type"]).first
+ # assume text/xml on instances where Content-Type header is not set
+ ct_expected = resp["Content-Type"] || 'text/xml'
+ ct = parse_content_type(ct_expected).first
if ct != "text/xml"
if ct == "text/html"
raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}"
@@ -559,10 +568,10 @@ def do_rpc(request, async=false)
end
expected = resp["Content-Length"] || "<unknown>"
- if data.nil? or data.size == 0
- raise "Wrong size. Was #{data.size}, should be #{expected}"
- elsif expected != "<unknown>" and expected.to_i != data.size and resp["Transfer-Encoding"].nil?
- raise "Wrong size. Was #{data.size}, should be #{expected}"
+ if data.nil? or data.bytesize == 0
+ raise "Wrong size. Was #{data.bytesize}, should be #{expected}"
+ elsif expected != "<unknown>" and expected.to_i != data.bytesize and resp["Transfer-Encoding"].nil?
+ raise "Wrong size. Was #{data.bytesize}, should be #{expected}"
end
set_cookies = resp.get_fields("Set-Cookie")
View
40 lib/19/xmlrpc/config.rb
@@ -0,0 +1,40 @@
+#
+# $Id$
+# Configuration file for XML-RPC for Ruby
+#
+
+module XMLRPC
+
+ module Config
+
+ DEFAULT_WRITER = XMLWriter::Simple # or XMLWriter::XMLParser
+
+ # available parser:
+ # * XMLParser::NQXMLTreeParser
+ # * XMLParser::NQXMLStreamParser
+ # * XMLParser::XMLTreeParser
+ # * XMLParser::XMLStreamParser (fastest)
+ # * XMLParser::REXMLStreamParser
+ # * XMLParser::XMLScanStreamParser
+ DEFAULT_PARSER = XMLParser::REXMLStreamParser
+
+ # enable <nil/> tag
+ ENABLE_NIL_CREATE = false
+ ENABLE_NIL_PARSER = false
+
+ # allows integers greater than 32-bit if true
+ ENABLE_BIGINT = false
+
+ # enable marshalling ruby objects which include XMLRPC::Marshallable
+ ENABLE_MARSHALLING = true
+
+ # enable multiCall extension by default
+ ENABLE_MULTICALL = false
+
+ # enable Introspection extension by default
+ ENABLE_INTROSPECTION = false
+
+ end
+
+end
+
View
3 lib/19/xmlrpc/create.rb
@@ -3,7 +3,7 @@
#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
-# $Id: create.rb 31813 2011-05-30 04:44:04Z yugui $
+# $Id$
#
require "date"
@@ -206,6 +206,7 @@ def conv2value(param)
end
when Float
+ raise "Wrong value #{param}. Not allowed!" unless param.finite?
@writer.tag("double", param.to_s)
when Struct
View
2 lib/19/xmlrpc/datetime.rb
@@ -138,5 +138,5 @@ def ==(o)
=begin
= History
- $Id: datetime.rb 25189 2009-10-02 12:04:37Z akr $
+ $Id$
=end
View
4 lib/19/xmlrpc/httpserver.rb
@@ -4,7 +4,7 @@
#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
-# $Id: httpserver.rb 25189 2009-10-02 12:04:37Z akr $
+# $Id$
#
@@ -170,7 +170,7 @@ def serve(io)
io << http_resp(response.status, response.status_message,
response.header, response.body)
- rescue Exception => e
+ rescue Exception
io << http_resp(500, "Internal Server Error")
end
View
2 lib/19/xmlrpc/marshal.rb
@@ -3,7 +3,7 @@
#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
-# $Id: marshal.rb 25189 2009-10-02 12:04:37Z akr $
+# $Id$
#
require "xmlrpc/parser"
View
19 lib/19/xmlrpc/parser.rb
@@ -3,7 +3,7 @@
#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
-# $Id: parser.rb 27235 2010-04-06 03:01:52Z naruse $
+# $Id$
#
@@ -54,11 +54,10 @@ module XMLRPC
class FaultException < StandardError
attr_reader :faultCode, :faultString
- alias message faultString
-
def initialize(faultCode, faultString)
@faultCode = faultCode
@faultString = faultString
+ super(@faultString)
end
# returns a hash
@@ -170,7 +169,7 @@ def parseMethodCall(str)
private
#
- # remove all whitespaces but in the tags i4, int, boolean....
+ # remove all whitespaces but in the tags i4, i8, int, boolean....
# and all comments
#
def removeWhitespacesAndComments(node)
@@ -180,7 +179,7 @@ def removeWhitespacesAndComments(node)
case _nodeType(nd)
when :TEXT
# TODO: add nil?
- unless %w(i4 int boolean string double dateTime.iso8601 base64).include? node.nodeName
+ unless %w(i4 i8 int boolean string double dateTime.iso8601 base64).include? node.nodeName
if node.nodeName == "value"
if not node.childNodes.to_a.detect {|n| _nodeType(n) == :ELEMENT}.nil?
@@ -254,7 +253,7 @@ def text_zero_one(node)
def integer(node)
#TODO: check string for float because to_i returnsa
# 0 when wrong string
- nodeMustBe(node, %w(i4 int))
+ nodeMustBe(node, %w(i4 i8 int))
hasOnlyOneChild(node)
Convert.int(text(node.firstChild))
@@ -416,7 +415,7 @@ def value(node)
text_zero_one(node)
when :ELEMENT
case child.nodeName
- when "i4", "int" then integer(child)
+ when "i4", "i8", "int" then integer(child)
when "boolean" then boolean(child)
when "string" then string(child)
when "double" then double(child)
@@ -526,7 +525,7 @@ def endElement(name)
case name
when "string"
@value = @data
- when "i4", "int"
+ when "i4", "i8", "int"
@value = Convert.int(@data)
when "boolean"
@value = Convert.boolean(@data)
@@ -714,7 +713,7 @@ def method_missing(*a)
end
def parse(str)
- parser = REXML::Document.parse_stream(str, self)
+ REXML::Document.parse_stream(str, self)
end
end
@@ -743,7 +742,7 @@ def parse(str)
end
alias :on_stag :startElement
- alias :on_etag :endElement
+ alias :on_etag :endElement
def on_stag_end(name); end
View
16 lib/19/xmlrpc/server.rb
@@ -456,7 +456,7 @@ def serve
$stdin.binmode if $stdin.respond_to? :binmode
data = $stdin.read(length)
- http_error(400, "Bad Request") if data.nil? or data.size != length
+ http_error(400, "Bad Request") if data.nil? or data.bytesize != length
http_write(process(data), "Content-type" => "text/xml; charset=utf-8")
}
@@ -487,7 +487,7 @@ def http_write(body, header)
h = {}
header.each {|key, value| h[key.to_s.capitalize] = value}
h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.size.to_s
+ h['Content-length'] ||= body.bytesize.to_s
str = ""
h.each {|key, value| str << "#{key}: #{value}\r\n"}
@@ -531,7 +531,7 @@ def serve
@ap.binmode
data = @ap.read(length)
- http_error(400, "Bad Request") if data.nil? or data.size != length
+ http_error(400, "Bad Request") if data.nil? or data.bytesize != length
http_write(process(data), 200, "Content-type" => "text/xml; charset=utf-8")
}
@@ -562,7 +562,7 @@ def http_write(body, status, header)
h = {}
header.each {|key, value| h[key.to_s.capitalize] = value}
h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.size.to_s
+ h['Content-length'] ||= body.bytesize.to_s
h.each {|key, value| @ap.headers_out[key] = value }
@ap.content_type = h["Content-type"]
@@ -751,17 +751,17 @@ def service(request, response)
data = request.body
- if data.nil? or data.size != length
+ if data.nil? or data.bytesize != length
raise WEBrick::HTTPStatus::BadRequest
end
resp = process(data)
- if resp.nil? or resp.size <= 0
+ if resp.nil? or resp.bytesize <= 0
raise WEBrick::HTTPStatus::InternalServerError
end
response.status = 200
- response['Content-Length'] = resp.size
+ response['Content-Length'] = resp.bytesize
response['Content-Type'] = "text/xml; charset=utf-8"
response.body = resp
end
@@ -773,6 +773,6 @@ def service(request, response)
=begin
= History
- $Id: server.rb 26986 2010-03-20 03:30:59Z nobu $
+ $Id$
=end
View
2 lib/19/xmlrpc/utils.rb
@@ -6,7 +6,7 @@
#
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
#
-# $Id: utils.rb 27537 2010-04-28 18:51:35Z jeg2 $
+# $Id$
#
module XMLRPC

0 comments on commit 53fc712

Please sign in to comment.
Something went wrong with that request. Please try again.