Joined: 15 Jul 2011 |
Posts: 1 |
|
|
|
Posted: Fri Jul 15, 2011 10:21 am |
|
|
|
|
|
Hi there,
I just registered today on this forum to propose some patches for NuSOAP.
All of them are to be applied against the last version in CVS.
The first one is to prevent an infinite loop which occurs for some huge arrays.
--- D:/nusoap/nusoap.php Thu Jun 09 16:30:30 2011
+++ D:/nusoap/new/nusoap_fixed.php Thu Jun 09 17:09:25 2011
@@ -1833,6 +1833,8 @@
}
}
return $this->simpleTypes[$type];
+ } elseif(!$is_element){
+ // to fix an infinite loop
} elseif(isset($this->elements[$type])){
$this->xdebug("in getTypeDef, found element $type");
if (!isset($this->elements[$type]['phpType'])) {
|
The second one is to fix a warning "Warning: Attempt to modify property of non-object in /home/user/www/nusoap/nusoap.php on line 4845"
You just forgot to browse all items of $this->schemas[$ns] array.
--- D:/nusoap/nusoap.php Thu Jun 09 16:30:30 2011
+++ D:/nusoap/new/nusoap_fixed.php Thu Jun 09 17:15:11 2011
@@ -4837,7 +4837,9 @@
foreach ($xs->imports as $ns2 => $list2) {
for ($ii = 0; $ii < count($list2); $ii++) {
if (! $list2[$ii]['loaded']) {
- $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
+ for ($jj = 0; $jj < count($this->schemas[$ns]); $jj++) {
+ $this->schemas[$ns][$jj]->imports[$ns2][$ii]['loaded'] = true;
+ }
$url = $list2[$ii]['location'];
if ($url != '') {
$urlparts = parse_url($url);
|
The third one is to add support for mime type application/soap+xml which is used by gSOAP.
--- D:/nusoap/nusoap.php Thu Jun 09 16:30:30 2011
+++ D:/nusoap/new/nusoap_fixed.php Thu Jun 09 17:15:37 2011
@@ -7864,8 +7864,8 @@
$this->setError('Response not of type text/xml (no content-type header)');
return false;
}
- if (!strstr($headers['content-type'], 'text/xml')) {
- $this->setError('Response not of type text/xml: ' . $headers['content-type']);
+ if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml')) {
+ $this->setError('Response not of type text/xml or application/soap+xml: ' . $headers['content-type']);
return false;
}
if (strpos($headers['content-type'], '=')) {
|
The last one is to support basic MTOM attachments (the class bundled with NuSOAP doesn't work).
--- D:/nusoap/nusoap.php Fri Jun 10 14:27:31 2011
+++ D:/nusoap/nusoap_fixed.php Fri Jun 10 14:34:29 2011
@@ -38,7 +38,7 @@
*/
/*
- * Some of the standards implmented in whole or part by NuSOAP:
+ * Some of the standards implemented in whole or part by NuSOAP:
*
* SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
* WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
@@ -2187,6 +2187,7 @@
var $request_method = 'POST';
var $protocol_version = '1.0';
var $encoding = '';
+ var $attachments = array();
var $outgoing_headers = array();
var $incoming_headers = array();
var $incoming_cookies = array();
@@ -3346,6 +3347,54 @@
return false;
}
+ if (isset($this->incoming_headers['content-type'])) {
+ $content_type = $this->incoming_headers['content-type'];
+ // check if Content-Type is multipart/related
+ if (preg_match("#multipart/related#", $content_type)) {
+ // check and get used boundary for multipart
+ if (preg_match("#boundary=\"([^\"]+)\";#", $content_type, $regs)) {
+ $boundary = $regs[1];
+ // split each part
+ $parts = explode("--$boundary", $data);
+ // process each part
+ if (count($parts)) foreach($parts as $part) if ($part) {
+ $part = trim($part);
+ // search for real data position
+ $pos = strpos($part,"$lb$lb");
+ $header_data = trim(substr($part,0,$pos));
+ $header_array = explode($lb,$header_data);
+ $part = ltrim(substr($part,$pos));
+ $content_id = '';
+ $content_type = '';
+ // check headers
+ foreach ($header_array as $header_line) {
+ $arr = explode(':',$header_line,2);
+ if(count($arr) > 1){
+ $header_name = strtolower(trim($arr[0]));
+ $header_value = trim($arr[1]);
+ if ($header_name == 'content-type') {
+ $content_type = $header_value;
+ } elseif ($header_name == 'content-id') {
+ $content_id = 'id:'.substr($header_value, 1, strlen($header_value)-2);
+ }
+ }
+ }
+ // real data uses SOAP-ENV:Envelope
+ if ($content_id == 'id:SOAP-ENV:Envelope')
+ {
+ // overwrite Content-Type
+ $this->incoming_headers['content-type'] = $content_type;
+ $data = $part;
+ }
+ else
+ {
+ $this->attachments[] = array('content-id' => $content_id, 'content-type' => $content_type, 'data' => $part);
+ }
+ }
+ }
+ }
+ }
+
return $data;
}
@@ -6785,13 +6834,22 @@
* @param string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
* @access public
*/
- function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
+ function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true,$attachments=''){
parent::nusoap_base();
$this->xml = $xml;
$this->xml_encoding = $encoding;
$this->method = $method;
$this->decode_utf8 = $decode_utf8;
+ // virtual position to be sure we are not overwriting real positions
+ $attachment_position = 1000;
+ // add attachements in $this->ids and $this->message
+ if ($attachments) foreach($attachments as $attachment) {
+ $this->ids[$attachment['content-id']] = $attachment_position;
+ $this->message[$attachment_position] = array('cdata' => $attachment['data'], 'name' => $attachment['content-id'], 'type' => $attachment['content-type'], 'children' => '');
+ ++$attachment_id;
+ }
+
// Check whether content has been read.
if(!empty($xml)){
// Check XML encoding
@@ -7847,7 +7905,7 @@
return false;
} else {
$this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']);
- return $this->parseResponse($http->incoming_headers, $this->responseData);
+ return $this->parseResponse($http->incoming_headers, $this->responseData, $http->attachments);
}
break;
default:
@@ -7865,7 +7923,7 @@
* @return mixed value of the message, decoded into a PHP type
* @access private
*/
- function parseResponse($headers, $data) {
+ function parseResponse($headers, $data, $attachments='') {
$this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
$this->appendDebug($this->varDump($headers));
if (!isset($headers['content-type'])) {
@@ -7881,8 +7939,9 @@
if (strpos($headers['content-type'], '=')) {
$enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
$this->debug('Got response encoding: ' . $enc);
- if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
- $this->xml_encoding = strtoupper($enc);
+ // line could have extra characters after encoding
+ if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)/i',$enc,$regs)){
+ $this->xml_encoding = strtoupper($regs[1]);
} else {
$this->xml_encoding = 'US-ASCII';
}
@@ -7891,7 +7950,7 @@
$this->xml_encoding = 'ISO-8859-1';
}
$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
- $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
+ $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8,$attachments);
// add parser debug data to our debug
$this->appendDebug($parser->getDebug());
// if parse errors
|
Please could you review and apply these patches on CVS ?
Thanks in advance.
|