NXS_XMLRPC_Message

NXS_XMLRPC_MESSAGE.

Defined (1)

The class is defined in the following location(s).

/inc-cl/apis/xmlrpc-client.php  
  1. class NXS_XMLRPC_Message 
  2. var $message; 
  3. var $messageType; // methodCall / methodResponse / fault 
  4. var $faultCode; 
  5. var $faultString; 
  6. var $methodName; 
  7. var $params; 
  8.  
  9. // Current variable stacks 
  10. var $_arraystructs = array(); // The stack used to keep track of the current array/struct 
  11. var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array 
  12. var $_currentStructName = array(); // A stack as well 
  13. var $_param; 
  14. var $_value; 
  15. var $_currentTag; 
  16. var $_currentTagContents; 
  17. // The XML parser 
  18. var $_parser; 
  19.  
  20. function NXS_XMLRPC_Message($message) 
  21. $this->message =& $message; 
  22.  
  23. function parse() 
  24. // first remove the XML declaration 
  25. // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages 
  26. $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1); 
  27. $this->message = substr_replace($this->message, $header, 0, 100); 
  28. if (trim($this->message) == '') { 
  29. return false; 
  30. $this->_parser = xml_parser_create(); 
  31. // Set XML parser to take the case of tags in to account 
  32. xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); 
  33. // Set XML parser callback functions 
  34. xml_set_object($this->_parser, $this); 
  35. xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); 
  36. xml_set_character_data_handler($this->_parser, 'cdata'); 
  37. $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages 
  38. do { 
  39. if (strlen($this->message) <= $chunk_size) { 
  40. $final = true; 
  41. $part = substr($this->message, 0, $chunk_size); 
  42. $this->message = substr($this->message, $chunk_size); 
  43. if (!xml_parse($this->_parser, $part, $final)) { 
  44. return false; 
  45. if ($final) { 
  46. break; 
  47. } while (true); 
  48. xml_parser_free($this->_parser); 
  49.  
  50. // Grab the error messages, if any 
  51. if ($this->messageType == 'fault') { 
  52. $this->faultCode = $this->params[0]['faultCode']; 
  53. $this->faultString = $this->params[0]['faultString']; 
  54. return true; 
  55.  
  56. function tag_open($parser, $tag, $attr) 
  57. $this->_currentTagContents = ''; 
  58. $this->currentTag = $tag; 
  59. switch($tag) { 
  60. case 'methodCall': 
  61. case 'methodResponse': 
  62. case 'fault': 
  63. $this->messageType = $tag; 
  64. break; 
  65. /** Deal with stacks of arrays and structs */ 
  66. case 'data': // data is to all intents and puposes more interesting than array 
  67. $this->_arraystructstypes[] = 'array'; 
  68. $this->_arraystructs[] = array(); 
  69. break; 
  70. case 'struct': 
  71. $this->_arraystructstypes[] = 'struct'; 
  72. $this->_arraystructs[] = array(); 
  73. break; 
  74.  
  75. function cdata($parser, $cdata) 
  76. $this->_currentTagContents .= $cdata; 
  77.  
  78. function tag_close($parser, $tag) 
  79. $valueFlag = false; 
  80. switch($tag) { 
  81. case 'int': 
  82. case 'i4': 
  83. $value = (int)trim($this->_currentTagContents); 
  84. $valueFlag = true; 
  85. break; 
  86. case 'double': 
  87. $value = (double)trim($this->_currentTagContents); 
  88. $valueFlag = true; 
  89. break; 
  90. case 'string': 
  91. $value = (string)trim($this->_currentTagContents); 
  92. $valueFlag = true; 
  93. break; 
  94. case 'dateTime.iso8601': 
  95. $value = new NXS_XMLRPC_Date(trim($this->_currentTagContents)); 
  96. $valueFlag = true; 
  97. break; 
  98. case 'value': 
  99. // "If no type is indicated, the type is string." 
  100. if (trim($this->_currentTagContents) != '') { 
  101. $value = (string)$this->_currentTagContents; 
  102. $valueFlag = true; 
  103. break; 
  104. case 'boolean': 
  105. $value = (boolean)trim($this->_currentTagContents); 
  106. $valueFlag = true; 
  107. break; 
  108. case 'base64': 
  109. $value = base64_decode($this->_currentTagContents); 
  110. $valueFlag = true; 
  111. break; 
  112. /** Deal with stacks of arrays and structs */ 
  113. case 'data': 
  114. case 'struct': 
  115. $value = array_pop($this->_arraystructs); 
  116. array_pop($this->_arraystructstypes); 
  117. $valueFlag = true; 
  118. break; 
  119. case 'member': 
  120. array_pop($this->_currentStructName); 
  121. break; 
  122. case 'name': 
  123. $this->_currentStructName[] = trim($this->_currentTagContents); 
  124. break; 
  125. case 'methodName': 
  126. $this->methodName = trim($this->_currentTagContents); 
  127. break; 
  128.  
  129. if ($valueFlag) { 
  130. if (count($this->_arraystructs) > 0) { 
  131. // Add value to struct or array 
  132. if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { 
  133. // Add to struct 
  134. $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; 
  135. } else { 
  136. // Add to array 
  137. $this->_arraystructs[count($this->_arraystructs)-1][] = $value; 
  138. } else { 
  139. // Just add as a paramater 
  140. $this->params[] = $value; 
  141. $this->_currentTagContents = '';