11 var $_cookies = array();
12 var $content_type = 'text/xml';
16 * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
17 * @param integer $fcode set it to anything but 0 to create an error response
18 * @param string $fstr the error string, in case of an error response
19 * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
21 * @todo add check that $val / $fcode / $fstr is of correct type???
22 * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
23 * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
25 function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')
30 $this->errno = $fcode;
31 $this->errstr = $fstr;
32 //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
36 // successful response
40 // user did not declare type of response value: try to guess it
41 if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
43 $this->valtyp = 'xmlrpcvals';
45 else if (is_string($this->val))
47 $this->valtyp = 'xml';
52 $this->valtyp = 'phpvals';
57 // user declares type of resp value: believe him
58 $this->valtyp = $valtyp;
64 * Returns the error code of the response.
65 * @return integer the error code of this response (0 for not-error responses)
74 * Returns the error code of the response.
75 * @return string the error string of this response ('' for not-error responses)
78 function faultString()
84 * Returns the value received by the server.
85 * @return mixed the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
94 * Returns an array with the cookies received from the server.
95 * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
96 * with attributes being e.g. 'expires', 'path', domain'.
97 * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
98 * are still present in the array. It is up to the user-defined code to decide
99 * how to use the received cookies, and whether they have to be sent back with the next
100 * request to the server (using xmlrpc_client::setCookie) or not
101 * @return array array of cookies received from the server
106 return $this->_cookies;
110 * Returns xml representation of the response. XML prologue not included
111 * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
112 * @return string the xml representation of the response
115 function serialize($charset_encoding='')
117 $xmlrpc = Phpxmlrpc::instance();
119 if ($charset_encoding != '')
120 $this->content_type = 'text/xml; charset=' . $charset_encoding;
122 $this->content_type = 'text/xml';
123 if ($xmlrpc->xmlrpc_null_apache_encoding)
125 $result = "<methodResponse xmlns:ex=\"".$xmlrpc->xmlrpc_null_apache_encoding_ns."\">\n";
129 $result = "<methodResponse>\n";
133 // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
134 // by xml-encoding non ascii chars
135 $result .= "<fault>\n" .
136 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
137 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
138 xmlrpc_encode_entitites($this->errstr, $xmlrpc->xmlrpc_internalencoding, $charset_encoding) . "</string></value>\n</member>\n" .
139 "</struct>\n</value>\n</fault>";
143 if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
145 if (is_string($this->val) && $this->valtyp == 'xml')
147 $result .= "<params>\n<param>\n" .
149 "</param>\n</params>";
153 /// @todo try to build something serializable?
154 die('cannot serialize xmlrpcresp objects whose content is native php values');
159 $result .= "<params>\n<param>\n" .
160 $this->val->serialize($charset_encoding) .
161 "</param>\n</params>";
164 $result .= "\n</methodResponse>";
165 $this->payload = $result;