Permalink
Browse files

Replaced the REXML XML generator with LibXML for large speed improvem…

…ents, also to render the XML according to RFC for some strange registries using mod_epp
  • Loading branch information...
1 parent 5857eb6 commit 66ac9aa2b6199b1222996e3f2abd0bf0bceace00 Joshua Delsman committed Jul 15, 2010
Showing with 31 additions and 30 deletions.
  1. +1 −1 lib/epp.rb
  2. +27 −27 lib/epp/server.rb
  3. +1 −1 test/test_epp.rb
  4. +2 −1 test/xml/new_request.xml
View
@@ -1,7 +1,7 @@
# Gem and other dependencies
require 'rubygems'
require 'openssl'
-require 'rexml/document'
+require 'libxml'
require 'hpricot'
require 'uuidtools'
View
@@ -1,6 +1,6 @@
module Epp #:nodoc:
class Server
- include REXML
+ include LibXML::XML
include RequiresParameters
attr_accessor :tag, :password, :server, :port, :lang, :services, :extensions, :version
@@ -34,14 +34,12 @@ def initialize(attributes = {})
end
def new_epp_request
- xml = Document.new
- xml << XMLDecl.new("1.0", "UTF-8", "no")
+ xml = Document.new
+ xml.root = Node.new("epp")
- xml.add_element("epp", {
- "xmlns" => "urn:ietf:params:xml:ns:epp-1.0",
- "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
- "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"
- })
+ xml.root["xmlns"] = "urn:ietf:params:xml:ns:epp-1.0"
+ xml.root["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
+ xml.root["xsi:schemaLocation"] = "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"
return xml
end
@@ -140,30 +138,32 @@ def login
xml = new_epp_request
- command = xml.root.add_element("command")
- login = command.add_element("login")
+ xml.root << command = Node.new("command")
+ command << login = Node.new("login")
- login.add_element("clID").text = tag
- login.add_element("pw").text = password
+ login << Node.new("clID", tag)
+ login << Node.new("pw", password)
- options = login.add_element("options")
- options.add_element("version").text = version
- options.add_element("lang").text = lang
+ login << options = Node.new("options")
- services = login.add_element("svcs")
- services.add_element("objURI").text = "urn:ietf:params:xml:ns:domain-1.0"
- services.add_element("objURI").text = "urn:ietf:params:xml:ns:contact-1.0"
- services.add_element("objURI").text = "urn:ietf:params:xml:ns:host-1.0"
+ options << Node.new("version", version)
+ options << Node.new("lang", lang)
- extensions_container = services.add_element("svcExtension") unless extensions.empty?
+ login << services = Node.new("svcs")
+
+ services << Node.new("objURI", "urn:ietf:params:xml:ns:domain-1.0")
+ services << Node.new("objURI", "urn:ietf:params:xml:ns:contact-1.0")
+ services << Node.new("objURI", "urn:ietf:params:xml:ns:host-1.0")
+
+ services << extensions_container = Node.new("svcExtension") unless extensions.empty?
for uri in extensions
- extensions_container.add_element("extURI").text = uri
+ extensions_container << Node.new("extURI", uri)
end
- command.add_element("clTRID").text = UUIDTools::UUID.timestamp_create.to_s
+ command << Node.new("clTRID", UUIDTools::UUID.timestamp_create.to_s)
- response = Hpricot.XML(send_request(xml.to_s))
+ response = Hpricot::XML(send_request(xml.to_s))
handle_response(response)
end
@@ -174,12 +174,12 @@ def logout
xml = new_epp_request
- command = xml.root.add_element("command")
+ xml.root << command = Node.new("command")
- command.add_element("logout")
- command.add_element("clTRID").text = UUIDTools::UUID.timestamp_create.to_s
+ command << login = Node.new("logout")
+ command << Node.new("clTRID", UUIDTools::UUID.timestamp_create.to_s)
- response = Hpricot.XML(send_request(xml.to_s))
+ response = Hpricot::XML(send_request(xml.to_s))
handle_response(response, 1500)
end
View
@@ -61,7 +61,7 @@ class EppTest < Test::Unit::TestCase
should "build a new XML request" do
xml = xml_file("new_request.xml")
- assert @epp.new_epp_request.is_a?(REXML::Document)
+ assert @epp.new_epp_request.is_a?(LibXML::XML::Document)
assert_equal xml, @epp.new_epp_request.to_s
end
View
@@ -1 +1,2 @@
-<?xml version='1.0' encoding='UTF-8' standalone='no'?><epp xsi:schemaLocation='urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='urn:ietf:params:xml:ns:epp-1.0'/>
+<?xml version="1.0" encoding="UTF-8"?>
+<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"/>

0 comments on commit 66ac9aa

Please sign in to comment.