IXR_Message

IXR_MESSAGE.

Defined (1)

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

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