1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 if ( ! function_exists('xml_parser_create'))
\r
18 show_error('Your PHP installation does not support XML');
\r
22 // ------------------------------------------------------------------------
\r
25 * XML-RPC request handler class
\r
27 * @package CodeIgniter
\r
28 * @subpackage Libraries
\r
30 * @author ExpressionEngine Dev Team
\r
31 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
\r
35 var $debug = FALSE; // Debugging on or off
\r
36 var $xmlrpcI4 = 'i4';
\r
37 var $xmlrpcInt = 'int';
\r
38 var $xmlrpcBoolean = 'boolean';
\r
39 var $xmlrpcDouble = 'double';
\r
40 var $xmlrpcString = 'string';
\r
41 var $xmlrpcDateTime = 'datetime.iso8601';
\r
42 var $xmlrpcBase64 = 'base64';
\r
43 var $xmlrpcArray = 'array';
\r
44 var $xmlrpcStruct = 'struct';
\r
46 var $xmlrpcTypes = array();
\r
47 var $valid_parents = array();
\r
48 var $xmlrpcerr = array(); // Response numbers
\r
49 var $xmlrpcstr = array(); // Response strings
\r
51 var $xmlrpc_defencoding = 'UTF-8';
\r
52 var $xmlrpcName = 'XML-RPC for CodeIgniter';
\r
53 var $xmlrpcVersion = '1.1';
\r
54 var $xmlrpcerruser = 800; // Start of user errors
\r
55 var $xmlrpcerrxml = 100; // Start of XML Parse errors
\r
56 var $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp
\r
62 var $error = ''; // Error string for request
\r
64 var $response = array(); // Response from remote server
\r
67 //-------------------------------------
\r
68 // VALUES THAT MULTIPLE CLASSES NEED
\r
69 //-------------------------------------
\r
71 function CI_Xmlrpc ($config = array())
\r
73 $this->xmlrpcName = $this->xmlrpcName;
\r
74 $this->xmlrpc_backslash = chr(92).chr(92);
\r
76 // Types for info sent back and forth
\r
77 $this->xmlrpcTypes = array(
\r
78 $this->xmlrpcI4 => '1',
\r
79 $this->xmlrpcInt => '1',
\r
80 $this->xmlrpcBoolean => '1',
\r
81 $this->xmlrpcString => '1',
\r
82 $this->xmlrpcDouble => '1',
\r
83 $this->xmlrpcDateTime => '1',
\r
84 $this->xmlrpcBase64 => '1',
\r
85 $this->xmlrpcArray => '2',
\r
86 $this->xmlrpcStruct => '3'
\r
89 // Array of Valid Parents for Various XML-RPC elements
\r
90 $this->valid_parents = array('BOOLEAN' => array('VALUE'),
\r
91 'I4' => array('VALUE'),
\r
92 'INT' => array('VALUE'),
\r
93 'STRING' => array('VALUE'),
\r
94 'DOUBLE' => array('VALUE'),
\r
95 'DATETIME.ISO8601' => array('VALUE'),
\r
96 'BASE64' => array('VALUE'),
\r
97 'ARRAY' => array('VALUE'),
\r
98 'STRUCT' => array('VALUE'),
\r
99 'PARAM' => array('PARAMS'),
\r
100 'METHODNAME' => array('METHODCALL'),
\r
101 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
\r
102 'MEMBER' => array('STRUCT'),
\r
103 'NAME' => array('MEMBER'),
\r
104 'DATA' => array('ARRAY'),
\r
105 'FAULT' => array('METHODRESPONSE'),
\r
106 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT')
\r
110 // XML-RPC Responses
\r
111 $this->xmlrpcerr['unknown_method'] = '1';
\r
112 $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server';
\r
113 $this->xmlrpcerr['invalid_return'] = '2';
\r
114 $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.';
\r
115 $this->xmlrpcerr['incorrect_params'] = '3';
\r
116 $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method';
\r
117 $this->xmlrpcerr['introspect_unknown'] = '4';
\r
118 $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown";
\r
119 $this->xmlrpcerr['http_error'] = '5';
\r
120 $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server.";
\r
121 $this->xmlrpcerr['no_data'] = '6';
\r
122 $this->xmlrpcstr['no_data'] ='No data received from server.';
\r
124 $this->initialize($config);
\r
126 log_message('debug', "XML-RPC Class Initialized");
\r
130 //-------------------------------------
\r
131 // Initialize Prefs
\r
132 //-------------------------------------
\r
134 function initialize($config = array())
\r
136 if (sizeof($config) > 0)
\r
138 foreach ($config as $key => $val)
\r
140 if (isset($this->$key))
\r
142 $this->$key = $val;
\r
149 //-------------------------------------
\r
150 // Take URL and parse it
\r
151 //-------------------------------------
\r
153 function server($url, $port=80)
\r
155 if (substr($url, 0, 4) != "http")
\r
157 $url = "http://".$url;
\r
160 $parts = parse_url($url);
\r
162 $path = ( ! isset($parts['path'])) ? '/' : $parts['path'];
\r
164 if (isset($parts['query']) && $parts['query'] != '')
\r
166 $path .= '?'.$parts['query'];
\r
169 $this->client = new XML_RPC_Client($path, $parts['host'], $port);
\r
173 //-------------------------------------
\r
175 //-------------------------------------
\r
177 function timeout($seconds=5)
\r
179 if ( ! is_null($this->client) && is_int($seconds))
\r
181 $this->client->timeout = $seconds;
\r
186 //-------------------------------------
\r
188 //-------------------------------------
\r
190 function method($function)
\r
192 $this->method = $function;
\r
196 //-------------------------------------
\r
197 // Take Array of Data and Create Objects
\r
198 //-------------------------------------
\r
200 function request($incoming)
\r
202 if ( ! is_array($incoming))
\r
207 $this->data = array();
\r
209 foreach($incoming as $key => $value)
\r
211 $this->data[$key] = $this->values_parsing($value);
\r
217 //-------------------------------------
\r
219 //-------------------------------------
\r
221 function set_debug($flag = TRUE)
\r
223 $this->debug = ($flag == TRUE) ? TRUE : FALSE;
\r
226 //-------------------------------------
\r
228 //-------------------------------------
\r
230 function values_parsing($value, $return = FALSE)
\r
232 if (is_array($value) && isset($value['0']))
\r
234 if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])]))
\r
236 if (is_array($value[0]))
\r
238 $temp = new XML_RPC_Values($value['0'], 'array');
\r
242 $temp = new XML_RPC_Values($value['0'], 'string');
\r
245 elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array'))
\r
247 while (list($k) = each($value['0']))
\r
249 $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE);
\r
252 $temp = new XML_RPC_Values($value['0'], $value['1']);
\r
256 $temp = new XML_RPC_Values($value['0'], $value['1']);
\r
261 $temp = new XML_RPC_Values($value, 'string');
\r
269 //-------------------------------------
\r
270 // Sends XML-RPC Request
\r
271 //-------------------------------------
\r
273 function send_request()
\r
275 $this->message = new XML_RPC_Message($this->method,$this->data);
\r
276 $this->message->debug = $this->debug;
\r
278 if ( ! $this->result = $this->client->send($this->message))
\r
280 $this->error = $this->result->errstr;
\r
283 elseif( ! is_object($this->result->val))
\r
285 $this->error = $this->result->errstr;
\r
289 $this->response = $this->result->decode();
\r
295 //-------------------------------------
\r
297 //-------------------------------------
\r
299 function display_error()
\r
301 return $this->error;
\r
305 //-------------------------------------
\r
306 // Returns Remote Server Response
\r
307 //-------------------------------------
\r
309 function display_response()
\r
311 return $this->response;
\r
315 //-------------------------------------
\r
316 // Sends an Error Message for Server Request
\r
317 //-------------------------------------
\r
319 function send_error_message($number, $message)
\r
321 return new XML_RPC_Response('0',$number, $message);
\r
326 //-------------------------------------
\r
327 // Send Response for Server Request
\r
328 //-------------------------------------
\r
330 function send_response($response)
\r
332 // $response should be array of values, which will be parsed
\r
333 // based on their data and type into a valid group of XML-RPC values
\r
335 $response = $this->values_parsing($response);
\r
337 return new XML_RPC_Response($response);
\r
341 } // END XML_RPC Class
\r
346 * XML-RPC Client class
\r
348 * @category XML-RPC
\r
349 * @author ExpressionEngine Dev Team
\r
350 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
\r
352 class XML_RPC_Client extends CI_Xmlrpc
\r
358 var $errstring = '';
\r
360 var $no_multicall = false;
\r
362 function XML_RPC_Client($path, $server, $port=80)
\r
364 parent::CI_Xmlrpc();
\r
366 $this->port = $port;
\r
367 $this->server = $server;
\r
368 $this->path = $path;
\r
371 function send($msg)
\r
373 if (is_array($msg))
\r
375 // Multi-call disabled
\r
376 $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']);
\r
380 return $this->sendPayload($msg);
\r
383 function sendPayload($msg)
\r
385 $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout);
\r
387 if ( ! is_resource($fp))
\r
389 error_log($this->xmlrpcstr['http_error']);
\r
390 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']);
\r
394 if(empty($msg->payload))
\r
396 // $msg = XML_RPC_Messages
\r
397 $msg->createPayload();
\r
401 $op = "POST {$this->path} HTTP/1.0$r";
\r
402 $op .= "Host: {$this->server}$r";
\r
403 $op .= "Content-Type: text/xml$r";
\r
404 $op .= "User-Agent: {$this->xmlrpcName}$r";
\r
405 $op .= "Content-Length: ".strlen($msg->payload). "$r$r";
\r
406 $op .= $msg->payload;
\r
409 if ( ! fputs($fp, $op, strlen($op)))
\r
411 error_log($this->xmlrpcstr['http_error']);
\r
412 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']);
\r
415 $resp = $msg->parseResponse($fp);
\r
420 } // end class XML_RPC_Client
\r
424 * XML-RPC Response class
\r
426 * @category XML-RPC
\r
427 * @author ExpressionEngine Dev Team
\r
428 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
\r
430 class XML_RPC_Response
\r
435 var $headers = array();
\r
437 function XML_RPC_Response($val, $code = 0, $fstr = '')
\r
442 $this->errno = $code;
\r
443 $this->errstr = htmlentities($fstr);
\r
445 else if ( ! is_object($val))
\r
447 // programmer error, not an object
\r
448 error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value.");
\r
449 $this->val = new XML_RPC_Values();
\r
457 function faultCode()
\r
459 return $this->errno;
\r
462 function faultString()
\r
464 return $this->errstr;
\r
472 function prepare_response()
\r
474 $result = "<methodResponse>\n";
\r
477 $result .= '<fault>
\r
481 <name>faultCode</name>
\r
482 <value><int>' . $this->errno . '</int></value>
\r
485 <name>faultString</name>
\r
486 <value><string>' . $this->errstr . '</string></value>
\r
494 $result .= "<params>\n<param>\n" .
\r
495 $this->val->serialize_class() .
\r
496 "</param>\n</params>";
\r
498 $result .= "\n</methodResponse>";
\r
502 function decode($array=FALSE)
\r
504 $CI =& get_instance();
\r
506 if ($array !== FALSE && is_array($array))
\r
508 while (list($key) = each($array))
\r
510 if (is_array($array[$key]))
\r
512 $array[$key] = $this->decode($array[$key]);
\r
516 $array[$key] = $CI->input->xss_clean($array[$key]);
\r
524 $result = $this->xmlrpc_decoder($this->val);
\r
526 if (is_array($result))
\r
528 $result = $this->decode($result);
\r
532 $result = $CI->input->xss_clean($result);
\r
541 //-------------------------------------
\r
542 // XML-RPC Object to PHP Types
\r
543 //-------------------------------------
\r
545 function xmlrpc_decoder($xmlrpc_val)
\r
547 $kind = $xmlrpc_val->kindOf();
\r
549 if($kind == 'scalar')
\r
551 return $xmlrpc_val->scalarval();
\r
553 elseif($kind == 'array')
\r
555 reset($xmlrpc_val->me);
\r
556 list($a,$b) = each($xmlrpc_val->me);
\r
557 $size = sizeof($b);
\r
561 for($i = 0; $i < $size; $i++)
\r
563 $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]);
\r
567 elseif($kind == 'struct')
\r
569 reset($xmlrpc_val->me['struct']);
\r
572 while(list($key,$value) = each($xmlrpc_val->me['struct']))
\r
574 $arr[$key] = $this->xmlrpc_decoder($value);
\r
581 //-------------------------------------
\r
582 // ISO-8601 time to server or UTC time
\r
583 //-------------------------------------
\r
585 function iso8601_decode($time, $utc=0)
\r
587 // return a timet in the localtime, or UTC
\r
589 if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs))
\r
592 $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
\r
594 $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
\r
599 } // End Response Class
\r
604 * XML-RPC Message class
\r
606 * @category XML-RPC
\r
607 * @author ExpressionEngine Dev Team
\r
608 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
\r
610 class XML_RPC_Message extends CI_Xmlrpc
\r
614 var $params = array();
\r
617 function XML_RPC_Message($method, $pars=0)
\r
619 parent::CI_Xmlrpc();
\r
621 $this->method_name = $method;
\r
622 if (is_array($pars) && sizeof($pars) > 0)
\r
624 for($i=0; $i<sizeof($pars); $i++)
\r
626 // $pars[$i] = XML_RPC_Values
\r
627 $this->params[] = $pars[$i];
\r
632 //-------------------------------------
\r
633 // Create Payload to Send
\r
634 //-------------------------------------
\r
636 function createPayload()
\r
638 $this->payload = "<?xml version=\"1.0\"?".">\r\n<methodCall>\r\n";
\r
639 $this->payload .= '<methodName>' . $this->method_name . "</methodName>\r\n";
\r
640 $this->payload .= "<params>\r\n";
\r
642 for($i=0; $i<sizeof($this->params); $i++)
\r
644 // $p = XML_RPC_Values
\r
645 $p = $this->params[$i];
\r
646 $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n";
\r
649 $this->payload .= "</params>\r\n</methodCall>\r\n";
\r
652 //-------------------------------------
\r
653 // Parse External XML-RPC Server's Response
\r
654 //-------------------------------------
\r
656 function parseResponse($fp)
\r
660 while($datum = fread($fp, 4096))
\r
665 //-------------------------------------
\r
666 // DISPLAY HTTP CONTENT for DEBUGGING
\r
667 //-------------------------------------
\r
669 if ($this->debug === TRUE)
\r
672 echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
\r
676 //-------------------------------------
\r
678 //-------------------------------------
\r
682 error_log($this->xmlrpcstr['no_data']);
\r
683 $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']);
\r
688 //-------------------------------------
\r
689 // Check for HTTP 200 Response
\r
690 //-------------------------------------
\r
692 if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data))
\r
694 $errstr= substr($data, 0, strpos($data, "\n")-1);
\r
695 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')');
\r
699 //-------------------------------------
\r
700 // Create and Set Up XML Parser
\r
701 //-------------------------------------
\r
703 $parser = xml_parser_create($this->xmlrpc_defencoding);
\r
705 $this->xh[$parser] = array();
\r
706 $this->xh[$parser]['isf'] = 0;
\r
707 $this->xh[$parser]['ac'] = '';
\r
708 $this->xh[$parser]['headers'] = array();
\r
709 $this->xh[$parser]['stack'] = array();
\r
710 $this->xh[$parser]['valuestack'] = array();
\r
711 $this->xh[$parser]['isf_reason'] = 0;
\r
713 xml_set_object($parser, $this);
\r
714 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
\r
715 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
\r
716 xml_set_character_data_handler($parser, 'character_data');
\r
717 //xml_set_default_handler($parser, 'default_handler');
\r
720 //-------------------------------------
\r
722 //-------------------------------------
\r
724 $lines = explode("\r\n", $data);
\r
725 while (($line = array_shift($lines)))
\r
727 if (strlen($line) < 1)
\r
731 $this->xh[$parser]['headers'][] = $line;
\r
733 $data = implode("\r\n", $lines);
\r
736 //-------------------------------------
\r
738 //-------------------------------------
\r
740 if ( ! xml_parse($parser, $data, sizeof($data)))
\r
742 $errstr = sprintf('XML error: %s at line %d',
\r
743 xml_error_string(xml_get_error_code($parser)),
\r
744 xml_get_current_line_number($parser));
\r
745 //error_log($errstr);
\r
746 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
\r
747 xml_parser_free($parser);
\r
750 xml_parser_free($parser);
\r
752 // ---------------------------------------
\r
753 // Got Ourselves Some Badness, It Seems
\r
754 // ---------------------------------------
\r
756 if ($this->xh[$parser]['isf'] > 1)
\r
758 if ($this->debug === TRUE)
\r
760 echo "---Invalid Return---\n";
\r
761 echo $this->xh[$parser]['isf_reason'];
\r
762 echo "---Invalid Return---\n\n";
\r
765 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
\r
768 elseif ( ! is_object($this->xh[$parser]['value']))
\r
770 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
\r
774 //-------------------------------------
\r
775 // DISPLAY XML CONTENT for DEBUGGING
\r
776 //-------------------------------------
\r
778 if ($this->debug === TRUE)
\r
782 if (count($this->xh[$parser]['headers'] > 0))
\r
784 echo "---HEADERS---\n";
\r
785 foreach ($this->xh[$parser]['headers'] as $header)
\r
789 echo "---END HEADERS---\n\n";
\r
792 echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
\r
794 echo "---PARSED---\n" ;
\r
795 var_dump($this->xh[$parser]['value']);
\r
796 echo "\n---END PARSED---</pre>";
\r
799 //-------------------------------------
\r
801 //-------------------------------------
\r
803 $v = $this->xh[$parser]['value'];
\r
805 if ($this->xh[$parser]['isf'])
\r
807 $errno_v = $v->me['struct']['faultCode'];
\r
808 $errstr_v = $v->me['struct']['faultString'];
\r
809 $errno = $errno_v->scalarval();
\r
813 // FAULT returned, errno needs to reflect that
\r
817 $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval());
\r
821 $r = new XML_RPC_Response($v);
\r
824 $r->headers = $this->xh[$parser]['headers'];
\r
828 // ------------------------------------
\r
829 // Begin Return Message Parsing section
\r
830 // ------------------------------------
\r
832 // quick explanation of components:
\r
833 // ac - used to accumulate values
\r
834 // isf - used to indicate a fault
\r
835 // lv - used to indicate "looking for a value": implements
\r
836 // the logic to allow values with no types to be strings
\r
837 // params - used to store parameters in method calls
\r
838 // method - used to store method name
\r
839 // stack - array with parent tree of the xml element,
\r
840 // used to validate the nesting of elements
\r
842 //-------------------------------------
\r
843 // Start Element Handler
\r
844 //-------------------------------------
\r
846 function open_tag($the_parser, $name, $attrs)
\r
848 // If invalid nesting, then return
\r
849 if ($this->xh[$the_parser]['isf'] > 1) return;
\r
851 // Evaluate and check for correct nesting of XML elements
\r
853 if (count($this->xh[$the_parser]['stack']) == 0)
\r
855 if ($name != 'METHODRESPONSE' && $name != 'METHODCALL')
\r
857 $this->xh[$the_parser]['isf'] = 2;
\r
858 $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
\r
864 // not top level element: see if parent is OK
\r
865 if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
\r
867 $this->xh[$the_parser]['isf'] = 2;
\r
868 $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0];
\r
877 // Creates array for child elements
\r
879 $cur_val = array('value' => array(),
\r
882 array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
\r
886 $this->xh[$the_parser]['ac'] = '';
\r
889 $this->xh[$the_parser]['isf'] = 1;
\r
892 $this->xh[$the_parser]['value'] = null;
\r
895 $this->xh[$the_parser]['vt'] = 'value';
\r
896 $this->xh[$the_parser]['ac'] = '';
\r
897 $this->xh[$the_parser]['lv'] = 1;
\r
904 case 'DATETIME.ISO8601':
\r
906 if ($this->xh[$the_parser]['vt'] != 'value')
\r
908 //two data elements inside a value: an error occurred!
\r
909 $this->xh[$the_parser]['isf'] = 2;
\r
910 $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value";
\r
914 $this->xh[$the_parser]['ac'] = '';
\r
917 // Set name of <member> to nothing to prevent errors later if no <name> is found
\r
918 $this->xh[$the_parser]['valuestack'][0]['name'] = '';
\r
920 // Set NULL value to check to see if value passed for this param/member
\r
921 $this->xh[$the_parser]['value'] = null;
\r
925 case 'METHODRESPONSE':
\r
927 // valid elements that add little to processing
\r
930 /// An Invalid Element is Found, so we have trouble
\r
931 $this->xh[$the_parser]['isf'] = 2;
\r
932 $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name";
\r
936 // Add current element name to stack, to allow validation of nesting
\r
937 array_unshift($this->xh[$the_parser]['stack'], $name);
\r
939 if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0;
\r
944 //-------------------------------------
\r
945 // End Element Handler
\r
946 //-------------------------------------
\r
948 function closing_tag($the_parser, $name)
\r
950 if ($this->xh[$the_parser]['isf'] > 1) return;
\r
952 // Remove current element from stack and set variable
\r
953 // NOTE: If the XML validates, then we do not have to worry about
\r
954 // the opening and closing of elements. Nesting is checked on the opening
\r
955 // tag so we be safe there as well.
\r
957 $curr_elem = array_shift($this->xh[$the_parser]['stack']);
\r
963 $cur_val = array_shift($this->xh[$the_parser]['valuestack']);
\r
964 $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values'];
\r
965 $this->xh[$the_parser]['vt'] = strtolower($name);
\r
968 $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac'];
\r
975 case 'DATETIME.ISO8601':
\r
977 $this->xh[$the_parser]['vt'] = strtolower($name);
\r
979 if ($name == 'STRING')
\r
981 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
\r
983 elseif ($name=='DATETIME.ISO8601')
\r
985 $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime;
\r
986 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
\r
988 elseif ($name=='BASE64')
\r
990 $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']);
\r
992 elseif ($name=='BOOLEAN')
\r
994 // Translated BOOLEAN values to TRUE AND FALSE
\r
995 if ($this->xh[$the_parser]['ac'] == '1')
\r
997 $this->xh[$the_parser]['value'] = TRUE;
\r
1001 $this->xh[$the_parser]['value'] = FALSE;
\r
1004 elseif ($name=='DOUBLE')
\r
1006 // we have a DOUBLE
\r
1007 // we must check that only 0123456789-.<space> are characters here
\r
1008 if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']))
\r
1010 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
\r
1014 $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac'];
\r
1019 // we have an I4/INT
\r
1020 // we must check that only 0123456789-<space> are characters here
\r
1021 if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']))
\r
1023 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
\r
1027 $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac'];
\r
1030 $this->xh[$the_parser]['ac'] = '';
\r
1031 $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value
\r
1034 // This if() detects if no scalar was inside <VALUE></VALUE>
\r
1035 if ($this->xh[$the_parser]['vt']=='value')
\r
1037 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
\r
1038 $this->xh[$the_parser]['vt'] = $this->xmlrpcString;
\r
1041 // build the XML-RPC value out of the data received, and substitute it
\r
1042 $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']);
\r
1044 if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY')
\r
1047 $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp;
\r
1052 $this->xh[$the_parser]['value'] = $temp;
\r
1056 $this->xh[$the_parser]['ac']='';
\r
1058 // If value add to array in the stack for the last element built
\r
1059 if ($this->xh[$the_parser]['value'])
\r
1061 $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value'];
\r
1065 $this->xh[$the_parser]['ac']='';
\r
1068 if ($this->xh[$the_parser]['value'])
\r
1070 $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value'];
\r
1073 case 'METHODNAME':
\r
1074 $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']);
\r
1078 case 'METHODCALL':
\r
1079 case 'METHORESPONSE':
\r
1080 // We're all good kids with nuthin' to do
\r
1083 // End of an Invalid Element. Taken care of during the opening tag though
\r
1088 //-------------------------------------
\r
1089 // Parses Character Data
\r
1090 //-------------------------------------
\r
1092 function character_data($the_parser, $data)
\r
1094 if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already
\r
1096 // If a value has not been found
\r
1097 if ($this->xh[$the_parser]['lv'] != 3)
\r
1099 if ($this->xh[$the_parser]['lv'] == 1)
\r
1101 $this->xh[$the_parser]['lv'] = 2; // Found a value
\r
1104 if( ! @isset($this->xh[$the_parser]['ac']))
\r
1106 $this->xh[$the_parser]['ac'] = '';
\r
1109 $this->xh[$the_parser]['ac'] .= $data;
\r
1114 function addParam($par) { $this->params[]=$par; }
\r
1116 function output_parameters($array=FALSE)
\r
1118 $CI =& get_instance();
\r
1120 if ($array !== FALSE && is_array($array))
\r
1122 while (list($key) = each($array))
\r
1124 if (is_array($array[$key]))
\r
1126 $array[$key] = $this->output_parameters($array[$key]);
\r
1130 $array[$key] = $CI->input->xss_clean($array[$key]);
\r
1134 $parameters = $array;
\r
1138 $parameters = array();
\r
1140 for ($i = 0; $i < sizeof($this->params); $i++)
\r
1142 $a_param = $this->decode_message($this->params[$i]);
\r
1144 if (is_array($a_param))
\r
1146 $parameters[] = $this->output_parameters($a_param);
\r
1150 $parameters[] = $CI->input->xss_clean($a_param);
\r
1155 return $parameters;
\r
1159 function decode_message($param)
\r
1161 $kind = $param->kindOf();
\r
1163 if($kind == 'scalar')
\r
1165 return $param->scalarval();
\r
1167 elseif($kind == 'array')
\r
1169 reset($param->me);
\r
1170 list($a,$b) = each($param->me);
\r
1174 for($i = 0; $i < sizeof($b); $i++)
\r
1176 $arr[] = $this->decode_message($param->me['array'][$i]);
\r
1181 elseif($kind == 'struct')
\r
1183 reset($param->me['struct']);
\r
1187 while(list($key,$value) = each($param->me['struct']))
\r
1189 $arr[$key] = $this->decode_message($value);
\r
1196 } // End XML_RPC_Messages class
\r
1201 * XML-RPC Values class
\r
1203 * @category XML-RPC
\r
1204 * @author ExpressionEngine Dev Team
\r
1205 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
\r
1207 class XML_RPC_Values extends CI_Xmlrpc
\r
1209 var $me = array();
\r
1212 function XML_RPC_Values($val=-1, $type='')
\r
1214 parent::CI_Xmlrpc();
\r
1216 if ($val != -1 OR $type != '')
\r
1218 $type = $type == '' ? 'string' : $type;
\r
1220 if ($this->xmlrpcTypes[$type] == 1)
\r
1222 $this->addScalar($val,$type);
\r
1224 elseif ($this->xmlrpcTypes[$type] == 2)
\r
1226 $this->addArray($val);
\r
1228 elseif ($this->xmlrpcTypes[$type] == 3)
\r
1230 $this->addStruct($val);
\r
1235 function addScalar($val, $type='string')
\r
1237 $typeof = $this->xmlrpcTypes[$type];
\r
1239 if ($this->mytype==1)
\r
1241 echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />';
\r
1247 echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />';
\r
1251 if ($type == $this->xmlrpcBoolean)
\r
1253 if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false')))
\r
1263 if ($this->mytype == 2)
\r
1265 // adding to an array here
\r
1266 $ar = $this->me['array'];
\r
1267 $ar[] = new XML_RPC_Values($val, $type);
\r
1268 $this->me['array'] = $ar;
\r
1272 // a scalar, so set the value and remember we're scalar
\r
1273 $this->me[$type] = $val;
\r
1274 $this->mytype = $typeof;
\r
1279 function addArray($vals)
\r
1281 if ($this->mytype != 0)
\r
1283 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
\r
1287 $this->mytype = $this->xmlrpcTypes['array'];
\r
1288 $this->me['array'] = $vals;
\r
1292 function addStruct($vals)
\r
1294 if ($this->mytype != 0)
\r
1296 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
\r
1299 $this->mytype = $this->xmlrpcTypes['struct'];
\r
1300 $this->me['struct'] = $vals;
\r
1306 switch($this->mytype)
\r
1322 function serializedata($typ, $val)
\r
1326 switch($this->xmlrpcTypes[$typ])
\r
1330 $rs .= "<struct>\n";
\r
1332 while(list($key2, $val2) = each($val))
\r
1334 $rs .= "<member>\n<name>{$key2}</name>\n";
\r
1335 $rs .= $this->serializeval($val2);
\r
1336 $rs .= "</member>\n";
\r
1338 $rs .= '</struct>';
\r
1342 $rs .= "<array>\n<data>\n";
\r
1343 for($i=0; $i < sizeof($val); $i++)
\r
1345 $rs .= $this->serializeval($val[$i]);
\r
1347 $rs.="</data>\n</array>\n";
\r
1353 case $this->xmlrpcBase64:
\r
1354 $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>\n";
\r
1356 case $this->xmlrpcBoolean:
\r
1357 $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>\n";
\r
1359 case $this->xmlrpcString:
\r
1360 $rs .= "<{$typ}>" . htmlspecialchars($val). "</{$typ}>\n";
\r
1363 $rs .= "<{$typ}>{$val}</{$typ}>\n";
\r
1372 function serialize_class()
\r
1374 return $this->serializeval($this);
\r
1377 function serializeval($o)
\r
1382 list($typ, $val) = each($ar);
\r
1383 $rs = "<value>\n".$this->serializedata($typ, $val)."</value>\n";
\r
1387 function scalarval()
\r
1390 list($a,$b) = each($this->me);
\r
1395 //-------------------------------------
\r
1396 // Encode time in ISO-8601 form.
\r
1397 //-------------------------------------
\r
1399 // Useful for sending time in XML-RPC
\r
1401 function iso8601_encode($time, $utc=0)
\r
1405 $t = strftime("%Y%m%dT%H:%M:%S", $time);
\r
1409 if (function_exists('gmstrftime'))
\r
1410 $t = gmstrftime("%Y%m%dT%H:%M:%S", $time);
\r
1412 $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z'));
\r
1418 // END XML_RPC_Values Class
\r
1420 /* End of file Xmlrpc.php */
\r
1421 /* Location: ./system/libraries/Xmlrpc.php */