cvs: php4 /pear/XML Parser.php RPC.php

From: Date: Tue, 26 Sep 2000 07:33:19 +0000
Subject: cvs: php4 /pear/XML Parser.php RPC.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1826@lists.php.net to get a copy of this message
sbergmann Tue Sep 26 00:33:19 2000 EDT Modified files: /php4/pear/XML Parser.php RPC.php Log: don't know if XML_RPC_Parser works now, but it definitely couldn't have worked before Index: php4/pear/XML/Parser.php diff -u php4/pear/XML/Parser.php:1.2 php4/pear/XML/Parser.php:1.3 --- php4/pear/XML/Parser.php:1.2 Sun Aug 27 12:46:01 2000 +++ php4/pear/XML/Parser.php Tue Sep 26 00:33:19 2000 @@ -5,6 +5,7 @@ /* Tests that need to be made: +- error class - mixing character encodings - a test using all expat handlers - options (folding, output charset) @@ -12,113 +13,104 @@ */ class XML_Parser extends PEAR { - var $parser; - var $fp; - var $options = array( - 'case_folding' => true, - 'input_encoding' => 'UTF-8', - 'output_encoding' => 'UTF-8' - ); - - function XML_Parser($options = array()) { - $this->PEAR(); - while (list($option, $value) = each($options)) { - $this->options[$option] = $value; - } - $xp = @xml_parser_create($this->options['input_charset']); - if (is_resource($xp)) { - $this->parser = $xp; - xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, - $this->options['case_folding']); - xml_parser_set_option($xp, XML_OPTION_TARGET_ENCODING, - $this->options['output_encoding']); - xml_set_object($xp, &$this); - if (method_exists($this, "startHandler") || - method_exists($this, "endHandler")) { - xml_set_element_handler($xp, "startHandler", "endHandler"); - } - if (method_exists($this, "cdataHandler")) { - xml_set_character_data_handler($xp, "cdataHandler"); - } - if (method_exists($this, "defaultHandler")) { - xml_set_default_handler($xp, "defaultHandler"); - } - if (method_exists($this, "piHandler")) { - xml_set_processing_instruction_handler($xp, "piHandler"); - } - if (method_exists($this, "unparsedHandler")) { - xml_set_unparsed_entity_decl_handler($xp, "unparsedHandler"); - } - if (method_exists($this, "notationHandler")) { - xml_set_notation_decl_handler($xp, "notationHandler"); - } - if (method_exists($this, "entityrefHandler")) { - xml_set_external_entity_ref_handler($xp, "entityrefHandler"); - } - } - } - - function setInputFile($file) { - $fp = @fopen($file, "r"); - if (is_resource($fp)) { - $this->fp = $fp; - return $fp; - } - return new XML_Parser_Error($php_errormsg); - } - - function setInput($fp) { - if (is_resource($fp)) { - $this->fp = $fp; - return true; - } - return new XML_Parser_Error("not a file resource"); - } - - function parse() { - if (!is_resource($this->fp)) { - return new XML_Parser_Error("no input"); - } - if (!is_resource($this->parser)) { - return new XML_Parser_Error("no parser"); - } - while ($data = fread($this->fp, 2048)) { - $err = $this->parseString(&$data, feof($this->fp)); - if (PEAR::isError($err)) { - return $err; - } - } - return true; - } - - function parseString($data, $eof = false) { - if (!is_resource($this->parser)) { - return new XML_Parser_Error("no parser"); - } - if (!xml_parse($this->parser, $data, $eof)) { - $err = new XML_Parser_Error($this->parser); - xml_parser_free($this->parser); - return $err; - } - return true; + var $parser; + var $fp; + var $folding = true; + + function XML_Parser($charset = 'UTF-8') { + $this->PEAR(); + $xp = @xml_parser_create($charset); + if (is_resource($xp)) { + $this->parser = $xp; + xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, + $this->folding); + xml_set_object($xp, $this); + if (method_exists($this, "startHandler") || + method_exists($this, "endHandler")) { + xml_set_element_handler($xp, "startHandler", "endHandler"); + } + if (method_exists($this, "cdataHandler")) { + xml_set_character_data_handler($xp, "cdataHandler"); + } + if (method_exists($this, "defaultHandler")) { + xml_set_default_handler($xp, "defaultHandler"); + } + if (method_exists($this, "piHandler")) { + xml_set_processing_instruction_handler($xp, "piHandler"); + } + if (method_exists($this, "unparsedHandler")) { + xml_set_unparsed_entity_decl_handler($xp, "unparsedHandler"); + } + if (method_exists($this, "notationHandler")) { + xml_set_notation_decl_handler($xp, "notationHandler"); + } + if (method_exists($this, "entityrefHandler")) { + xml_set_external_entity_ref_handler($xp, "entityrefHandler"); + } + } + } + + function setInputFile($file) { + $fp = @fopen($file, "r"); + if (is_resource($fp)) { + $this->fp = $fp; + return $fp; + } + return new XML_Parser_Error($php_errormsg); + } + + function setInput($fp) { + if (is_resource($fp)) { + $this->fp = $fp; + return true; + } + return new XML_Parser_Error("not a file resource"); + } + + function parse() { + if (!is_resource($this->fp)) { + return new XML_Parser_Error("no input"); + } + if (!is_resource($this->parser)) { + return new XML_Parser_Error("no parser"); + } + while ($data = fread($this->fp, 2048)) { + $err = $this->parseString($data, feof($this->fp)); + if (PEAR::isError($err)) { + return $err; + } + } + return true; + } + + function parseString($data, $eof = false) { + if (!is_resource($this->parser)) { + return new XML_Parser_Error("no parser"); + } + if (!xml_parse($this->parser, $data, $eof)) { + $err = new XML_Parser_Error($this->parser); + xml_parser_free($this->parser); + return $err; } + return true; + } } class XML_Parser_Error extends PEAR_Error { - var $error_message_prefix = 'XML_Parser: '; - function XML_Parser_Error($msgorparser = 'unknown error', - $code = 0, - $mode = PEAR_ERROR_RETURN, - $level = E_USER_NOTICE) { - if (is_resource($msgorparser)) { - $msgorparser = - sprintf("%s at XML input line %d", - xml_error_string(xml_get_error_code($msgorparser)), - xml_get_current_line_number($msgorparser)); - } - $this->PEAR_Error($msgorparser, $code, $mode, $level); + var $error_message_prefix = 'XML_Parser: '; + function XML_Parser_Error($msgorparser = 'unknown error', + $code = 0, + $mode = PEAR_ERROR_RETURN, + $level = E_USER_NOTICE) { + if (is_resource($msgorparser)) { + $msgorparser = + sprintf("%s at XML input line %d", + xml_error_string(xml_get_error_code($msgorparser)), + xml_get_current_line_number($msgorparser)); } + $this->PEAR_Error($msgorparser, $code, $mode, $level); + } } ?> Index: php4/pear/XML/RPC.php diff -u php4/pear/XML/RPC.php:1.1 php4/pear/XML/RPC.php:1.2 --- php4/pear/XML/RPC.php:1.1 Sun Jul 30 10:41:31 2000 +++ php4/pear/XML/RPC.php Tue Sep 26 00:33:19 2000 @@ -1,11 +1,13 @@ <?php + require_once "XML/Parser.php"; + // // This file contains PEAR-ifications of XML-RPC code written by Edd // Dumbill. // // by Edd Dumbill (C) 1999-2000 // <edd@usefulinc.com> -// $Id: RPC.php,v 1.1 2000/07/30 17:41:31 ssb Exp $ +// $Id: RPC.php,v 1.2 2000/09/26 07:33:19 sbergmann Exp $ // License is granted to use or modify this software ("XML-RPC for PHP") // for commercial or non-commercial use provided the copyright of the author @@ -106,7 +108,7 @@ var $params; /* used to store parameters in method calls */ var $method; /* used to store method name */ - class XML_RPC_Parser { + function XML_RPC_Parser() { $this->XML_Parser(); } @@ -314,10 +316,10 @@ $username="", $password="") { if($timeout>0) $fp=fsockopen($server, $port, - &$this->errno, &$this->errstr, $timeout); + $this->errno, $this->errstr, $timeout); else $fp=fsockopen($server, $port, - &$this->errno, &$this->errstr); + $this->errno, $this->errstr); if (!$fp) { return 0; }

« previous php.cvs (#1826) next »