function processRequest()
 {
     global $HTTP_SERVER_VARS;
     if ($_SERVER["REQUEST_METHOD"] != "POST") {
         print "Error: this web page does only understand POST methods";
         exit;
     }
     $xmlData = $this->stripHTTPHeader($this->RawPostData);
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->preserveWhiteSpace = false;
     $success = $dom->loadXML($xmlData);
     // Check for non-parsing XML, to avoid call to non-object error.
     if (!$success) {
         $this->showResponse('unknown_function_name', 'unknown_namespace_uri', new eZSOAPFault('Server Error', 'Bad XML'));
         return;
     }
     // add namespace fetching on body
     // get the SOAP body
     $body = $dom->getElementsByTagName("Body");
     $children = $body->item(0)->childNodes;
     if ($children->length == 1) {
         $requestNode = $children->item(0);
         // get target namespace for request
         $functionName = $requestNode->localName;
         $namespaceURI = $requestNode->namespaceURI;
         $params = array();
         // check parameters
         foreach ($requestNode->childNodes as $parameterNode) {
             $params[] = eZSOAPResponse::decodeDataTypes($parameterNode);
         }
         list($objectName, $objectFunctionName) = preg_split('/::/', $functionName, 2, PREG_SPLIT_NO_EMPTY);
         if (!$objectFunctionName and in_array($functionName, $this->FunctionList) && function_exists($functionName)) {
             $this->showResponse($functionName, $namespaceURI, call_user_func_array($functionName, $params));
         } else {
             if ($objectName and $objectFunctionName) {
                 if (!class_exists($objectName)) {
                     $this->showResponse($functionName, $namespaceURI, new eZSOAPFault('Server Error', 'Object not found'));
                 } else {
                     $object = new $objectName();
                     if (!method_exists($object, $objectFunctionName)) {
                         $this->showResponse($functionName, $namespaceURI, new eZSOAPFault('Server Error', 'Objectmethod not found'));
                     } else {
                         $this->showResponse($functionName, $namespaceURI, call_user_func_array(array($object, $objectFunctionName), $params));
                     }
                 }
             } else {
                 $this->showResponse($functionName, $namespaceURI, new eZSOAPFault('Server Error', 'Method not found'));
             }
         }
     } else {
         // error
         $this->showResponse($functionName, $namespaceURI, new eZSOAPFault('Server Error', '"Body" element in the request ' . 'has wrong number of children'));
     }
 }
 function send($request)
 {
     if (!$this->UseSSL || !in_array("curl", get_loaded_extensions())) {
         if ($this->Timeout != 0) {
             $fp = fsockopen($this->Server, $this->Port, $this->errorNumber, $this->errorString, $this->Timeout);
         } else {
             $fp = fsockopen($this->Server, $this->Port, $this->errorNumber, $this->errorString);
         }
         if ($fp == 0) {
             $this->ErrorString = '<b>Error:</b> eZSOAPClient::send() : Unable to open connection to ' . $this->Server . '.';
             return 0;
         }
         $payload = $request->payload();
         $authentification = "";
         if ($this->login() != "") {
             $authentification = "Authorization: Basic " . base64_encode($this->login() . ":" . $this->password()) . "\r\n";
         }
         $HTTPRequest = "POST " . $this->Path . " HTTP/1.0\r\n" . "User-Agent: eZ soap client\r\n" . "Host: " . $this->Server . ":" . $this->Port . "\r\n" . $authentification . "Content-Type: text/xml\r\n" . "SOAPAction: \"" . $request->ns() . '/' . $request->name() . "\"\r\n" . "Content-Length: " . strlen($payload) . "\r\n\r\n" . $payload;
         if (!fputs($fp, $HTTPRequest, strlen($HTTPRequest))) {
             $this->ErrorString = "<b>Error:</b> could not send the SOAP request. Could not write to the socket.";
             $response = 0;
             return $response;
         }
         $rawResponse = "";
         // fetch the SOAP response
         while ($data = fread($fp, 32768)) {
             $rawResponse .= $data;
         }
         // close the socket
         fclose($fp);
     } else {
         if ($request instanceof eZSOAPRequest) {
             $URL = "https://" . $this->Server . ":" . $this->Port . $this->Path;
             $ch = curl_init($URL);
             if ($this->Timeout != 0) {
                 curl_setopt($ch, CURLOPT_TIMEOUT, $this->Timeout);
             }
             $payload = $request->payload();
             if ($ch != 0) {
                 $HTTPCall = "POST " . $this->Path . " HTTP/1.0\r\n" . "User-Agent: eZ soap client\r\n" . "Host: " . $this->Server . ":" . $this->Port . "\r\n" . "Content-Type: text/xml\r\n" . "SOAPAction: \"" . $request->ns() . '/' . $request->name() . "\"\r\n" . "Content-Length: " . strlen($payload) . "\r\n";
                 if ($this->login() != '') {
                     $HTTPCall .= "Authorization: Basic " . base64_encode($this->login() . ":" . $this->Password()) . "\r\n";
                 }
                 $HTTPCall .= "\r\n" . $payload;
                 curl_setopt($ch, CURLOPT_URL, $URL);
                 curl_setopt($ch, CURLOPT_HEADER, 1);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $HTTPCall);
                 // Don't use CURLOPT_CUSTOMREQUEST without making sure your server supports the custom request method first.
                 unset($rawResponse);
                 if ($ch != 0) {
                     $rawResponse = curl_exec($ch);
                 }
                 if (!$rawResponse) {
                     $this->ErrorString = "<b>Error:</b> could not send the XML-SOAP with SSL call. Could not write to the socket.";
                     $response = 0;
                     return $response;
                 }
             }
             curl_close($ch);
         }
     }
     $response = new eZSOAPResponse();
     $response->decodeStream($request, $rawResponse);
     return $response;
 }
示例#3
0
 static function decodeDataTypes($node, $type = "")
 {
     $returnValue = false;
     $attributeValue = '';
     $attribute = $node->getAttributeNodeNS(eZSOAPEnvelope::SCHEMA_INSTANCE, 'type');
     if (!$attribute) {
         $attribute = $node->getAttributeNodeNS('http://www.w3.org/1999/XMLSchema-instance', 'type');
     }
     $attributeValue = $attribute->value;
     $dataType = $type;
     $attrParts = explode(":", $attributeValue);
     if ($attrParts[1]) {
         $dataType = $attrParts[1];
     }
     /*
             $typeNamespacePrefix = $this->DOMDocument->namespaceByAlias( $attrParts[0] );
     
             check that this is a namespace type definition
                     if ( ( $typeNamespacePrefix == eZSOAPEnvelope::SCHEMA_DATA ) ||
                          ( $typeNamespacePrefix == eZSOAPEnvelope::ENC )
                          )
     TODO: add encoding checks with schema validation.
     */
     switch ($dataType) {
         case "string":
         case "int":
         case "float":
         case 'double':
             $returnValue = $node->textContent;
             break;
         case "boolean":
             if ($node->textContent == "true") {
                 $returnValue = true;
             } else {
                 $returnValue = false;
             }
             break;
         case "base64":
             $returnValue = base64_decode($node->textContent);
             break;
         case "Array":
             // Get array type
             $arrayType = $node->getAttributeNodeNS(eZSOAPEnvelope::ENC, 'arrayType')->value;
             $arrayTypeParts = explode(":", $arrayType);
             preg_match("#(.*)\\[(.*)\\]#", $arrayTypeParts[1], $matches);
             $type = $matches[1];
             $count = $matches[2];
             $returnValue = array();
             foreach ($node->childNodes as $child) {
                 if ($child instanceof DOMElement) {
                     $returnValue[] = eZSOAPResponse::decodeDataTypes($child, $type);
                 }
             }
             break;
         case "SOAPStruct":
             $returnValue = array();
             foreach ($node->childNodes as $child) {
                 if ($child instanceof DOMElement) {
                     $returnValue[$child->tagName] = eZSOAPResponse::decodeDataTypes($child);
                 }
             }
             break;
         default:
             foreach ($node->childNodes as $childNode) {
                 if ($childNode instanceof DOMElement) {
                     // check data type for child
                     $attr = $childNode->getAttributeNodeNS(eZSOAPEnvelope::SCHEMA_INSTANCE, 'type')->value;
                     $dataType = false;
                     $attrParts = explode(":", $attr);
                     $dataType = $attrParts[1];
                     $returnValue[$childNode->tagName] = eZSOAPResponse::decodeDataTypes($childNode);
                 }
             }
             break;
     }
     return $returnValue;
 }