function ProcessRequest()
 {
     global $HTTP_SERVER_VARS, $APPLICATION;
     if ($HTTP_SERVER_VARS["REQUEST_METHOD"] != "POST" or !class_exists("CDataXML")) {
         $this->ShowSOAPFault("Error: this web page does only understand POST methods. BitrixXMLParser. ");
     }
     for ($i = 0; $i < count($this->OnRequestEvent); $i++) {
         $this->OnRequestEvent[$i]->OnBeforeRequest($this);
     }
     //AddMessage2Log($this->RawPostData);
     $xmlData = $this->stripHTTPHeader($this->RawPostData);
     $xmlData = $APPLICATION->ConvertCharset($xmlData, "UTF-8", SITE_CHARSET);
     $xml = new CDataXML();
     //AddMessage2Log($xmlData);
     if (!$xml->LoadString($xmlData)) {
         $this->ShowSOAPFault("Error: Can't parse request xml data. ");
     }
     $dom = $xml->GetTree();
     // Check for non-parsing XML, to avoid call to non-object error.
     if (!is_object($dom)) {
         $this->ShowSOAPFault("Bad XML");
     }
     // add namespace fetching on body
     // get the SOAP body
     $body = $dom->elementsByName("Body");
     $children = $body[0]->children();
     if (count($children) == 1) {
         $requestNode = $children[0];
         $requestParsed = false;
         // get target namespace for request
         // it often function request message. in wsdl gen. = function+"request"
         $functionName = $requestNode->name();
         $namespaceURI = $requestNode->namespaceURI();
         for ($i = 0; $i < count($this->OnRequestEvent); $i++) {
             if ($this->OnRequestEvent[$i]->ProcessRequestBody($this, $requestNode)) {
                 $requestParsed = true;
                 break;
             }
         }
         for ($i = 0; $i < count($this->OnRequestEvent); $i++) {
             $this->OnRequestEvent[$i]->OnAfterResponse($this);
         }
         if (!$requestParsed) {
             $this->ShowSOAPFault('Unknown operation requested.');
         }
         return $requestParsed;
     } else {
         $this->ShowSOAPFault('"Body" element in the request has wrong number of children');
     }
     return false;
 }
Beispiel #2
0
 function decodeStream($request, $stream)
 {
     global $APPLICATION;
     $stream_cutted = $this->stripHTTPHeader($stream);
     if (!$stream_cutted or !class_exists("CDataXML")) {
         $APPLICATION->ThrowException("Error: BitrixXMLParser. " . "Downloaded page: <br>" . htmlspecialcharsEx($stream));
         return;
     }
     $stream = $stream_cutted;
     $xml = new CDataXML();
     $stream = $APPLICATION->ConvertCharset($stream, "UTF-8", SITE_CHARSET);
     if (!$xml->LoadString($stream)) {
         $APPLICATION->ThrowException("Error: Can't parse request xml data. ");
         return;
     }
     $dom = $xml->GetTree();
     $this->DOMDocument = $dom;
     if (get_class($dom) == "CDataXMLDocument" || get_class($dom) == "cdataxmldocument") {
         // check for fault
         $response = $dom->elementsByName('Fault');
         if (count($response) == 1) {
             $this->IsFault = 1;
             $faultStringArray = $dom->elementsByName("faultstring");
             $this->FaultString = $faultStringArray[0]->textContent();
             $faultCodeArray = $dom->elementsByName("faultcode");
             $this->FaultCode = $faultCodeArray[0]->textContent();
             return;
         }
         // get the response
         $body = $dom->elementsByName("Body");
         $body = $body[0];
         $response = $body->children();
         $response = $response[0];
         if (get_class($response) == "CDataXMLNode" || get_class($response) == "cdataxmlnode") {
             /*Cut from the SOAP spec:
             				The method response is viewed as a single struct containing an accessor
             				for the return value and each [out] or [in/out] parameter.
             				The first accessor is the return value followed by the parameters
             				in the same order as in the method signature.
             
             				Each parameter accessor has a name corresponding to the name
             				of the parameter and type corresponding to the type of the parameter.
             				The name of the return value accessor is not significant.
             				Likewise, the name of the struct is not significant.
             				However, a convention is to name it after the method name
             				with the string "Response" appended.
             				*/
             $responseAccessors = $response->children();
             //echo '<pre>'; print_r($responseAccessors); echo '</pre>';
             if (count($responseAccessors) > 0) {
                 $this->Value = array();
                 foreach ($responseAccessors as $arChild) {
                     $value = $arChild->decodeDataTypes();
                     $this->Value = array_merge($this->Value, $value);
                 }
             }
         } else {
             $APPLICATION->ThrowException("Could not understand type of class decoded");
         }
     } else {
         $APPLICATION->ThrowException("Could not process XML in response");
     }
 }
Beispiel #3
0
 function encodeValue($name, $value, $complexDataTypeName = "")
 {
     global $xsd_simple_type;
     if (!is_array($this->outputVars) or !count($this->outputVars)) {
         CSOAPServer::ShowSOAPFault("encodeValue() has no Output Data Type Declaration for validation.");
         exit;
     }
     $dataType = "";
     $typeDeclaration = "";
     if (isset($this->outputVars[$name])) {
         $typeDeclaration = $this->outputVars[$name];
     } else {
         if (isset($this->typensVars[$name])) {
             $typeDeclaration = $this->typensVars[$name];
         } else {
             if (isset($this->typensVars[$complexDataTypeName][$name])) {
                 $typeDeclaration = $this->typensVars[$complexDataTypeName][$name];
             }
         }
     }
     if (isset($typeDeclaration["varType"])) {
         // if not, name = complex data type
         $dataType = $typeDeclaration["varType"];
     } else {
         $dataType = $name;
     }
     if (isset($xsd_simple_type[$dataType])) {
         $dataType = $xsd_simple_type[$dataType];
     }
     // Type validation
     $this->_validateType($dataType, $value);
     switch ($dataType) {
         case "string":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":string" );
             $node->setData($value);
             return $node;
             break;
         case "boolean":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":boolean" );
             if ($value === true) {
                 $node->setData("true");
             } else {
                 $node->setData("false");
             }
             return $node;
             break;
         case "integer":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":int" );
             $node->setData(intval($value));
             return $node;
             break;
         case "float":
         case "double":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":float" );
             $node->setData($value);
             return $node;
             break;
             // added by Sigurd
         // added by Sigurd
         case "base64":
         case "base64Binary":
             $node = new CXMLCreator($name);
             //$node->setAttribute("type", BX_SOAP_XSD_PREFIX . ":base64Binary" );
             $node->setData(base64_encode($value));
             return $node;
             break;
         case 'any':
             $node = new CXMLCreator($name);
             if (is_object($value)) {
                 // $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/ws.log', 'a');
                 // fwrite($fp, $value->GetTree()."\n");
                 // fwrite($fp, '===================================='."\r\n");
                 // fclose($fp);
                 if (get_class($value) == 'CDataXML') {
                     $node->addChild(CXMLCreator::CreateFromDOM($value->GetTree()));
                 } elseif (get_class($value) == 'CDataXMLDocument') {
                     $node->addChild(CXMLCreator::CreateFromDOM($value));
                 } elseif (get_class($value) == 'CXMLCreator') {
                     $node->addChild($value);
                 }
             } else {
                 $data = new CDataXML();
                 if ($data->LoadString($value)) {
                     $node->addChild(CXMLCreator::CreateFromDOM($data->GetTree()));
                 } else {
                     $node->setData($value);
                 }
             }
             return $node;
             break;
         default:
             $node = new CXMLCreator($name);
             if (isset($typeDeclaration["arrType"])) {
                 if (!isset($typeDeclaration["varType"])) {
                     $this->_errorTypeValidation("varType [undef]", $value);
                 }
                 $varType = $typeDeclaration["varType"];
                 // Decode array
                 $maxOccurs = 0;
                 $arrayType = $typeDeclaration["arrType"];
                 if (isset($typeDeclaration["maxOccursA"])) {
                     $maxOccurs = $typeDeclaration["maxOccursA"];
                 }
                 if (isset($xsd_simple_type[$arrayType])) {
                     $i = 0;
                     $arrayType = $xsd_simple_type[$arrayType];
                     $arrayTypeEl = $varType . "El";
                     // TODO: non fixed. get El name from wsdl. or decl.
                     if (!is_array($value)) {
                         CSOAPCodec::_errorTypeValidation("Array", $value);
                     }
                     foreach ($value as $valnode) {
                         $i++;
                         $this->_validateType($arrayType, $valnode);
                         $cndata = new CXMLCreator($arrayTypeEl);
                         $cndata->setData($valnode);
                         $node->addChild($cndata);
                         if (intval($maxOccurs) > 0 and $i > $maxOccurs) {
                             break;
                         }
                     }
                 } else {
                     // Complex data type arrays // $arrayType as is.
                     // TODO: non fixed. get $arrayTypeEl name from wsdl. or decl.
                     $i = 0;
                     $arrayTypeEl = $varType . "El";
                     if (!is_array($value)) {
                         CSOAPCodec::_errorTypeValidation("Array", $value);
                     }
                     foreach ($value as $valnode) {
                         $decoded = null;
                         $i++;
                         $this->_validateType($arrayType, $valnode);
                         $decoded = $this->encodeValue($arrayType, $valnode);
                         $cndata = new CXMLCreator($arrayTypeEl);
                         if ($decoded) {
                             $this->_validateClassType("CXMLCreator", $decoded);
                             $decoded->setName($arrayTypeEl);
                             $node->addChild($decoded);
                         }
                         if (intval($maxOccurs) > 0 and $i > $maxOccurs) {
                             break;
                         }
                     }
                 }
             } else {
                 // Here we goes with struct, or with class
                 // First, try to find declaration
                 $objectDecl = 0;
                 $returnValue = array();
                 $params = array();
                 if (!isset($this->typensVars[$dataType])) {
                     break;
                 }
                 $objectDecl = $this->typensVars[$dataType];
                 if (!$objectDecl) {
                     CSOAPServer::ShowSOAPFault("encodeValue() cant find complex type declaration for {$dataType}.");
                     exit;
                 }
                 // Type of serialization: class/assoc array
                 $objectClass = null;
                 $serialize = "assoc";
                 if (isset($objectDecl["serialize"])) {
                     $serialize = $objectDecl["serialize"];
                     unset($objectDecl["serialize"]);
                 }
                 // Validate hard complex data types
                 if ($serialize == "assoc") {
                     $this->_validateType("array", $value);
                 }
                 if ($serialize != "assoc") {
                     $this->_validateClassType($dataType, $value);
                 }
                 foreach ($objectDecl as $pname => $param) {
                     $decoded = null;
                     $strict = true;
                     if (isset($param["strict"])) {
                         $strict = $param["strict"] == "strict" ? true : false;
                     }
                     if ($serialize == "assoc") {
                         //var_dump($pname); var_dump($value[$pname]); die();
                         if (isset($value[$pname])) {
                             $decoded = $this->encodeValue($pname, $value[$pname], $dataType);
                         }
                     } else {
                         if ($serialize != "assoc") {
                             if (isset($value->{$pname})) {
                                 $decoded = $this->encodeValue($pname, $value->{$pname}, $dataType);
                             }
                         }
                     }
                     if ($decoded) {
                         $this->_validateClassType("CXMLCreator", $decoded);
                     }
                     if (!$decoded and !$strict) {
                         CSOAPServer::ShowSOAPFault("Request has no enought params of strict type to be decoded. ");
                         exit;
                     }
                     $node->addChild($decoded);
                 }
             }
             return $node;
             break;
     }
     return false;
 }
	$bIncorrectFormat = false;
	$handle = fopen($abs_path, "r");
	$size = filesize($abs_path);

	if ($size > 20)
	{
		$contents = fread($handle, 20);
		if (strtolower(substr($contents, 0, 5)) != "<?xml")
			$bIncorrectFormat = true;
	}

	if (!$bIncorrectFormat)
	{
		$objXML = new CDataXML();
		$objXML->Load($abs_path);
		$arTree = $objXML->GetTree();
		$arTracks = Array();
		$bIncorrectFormat = true;

		$ch = $arTree->children;
		if (count($ch) > 0 && strtolower($ch[0]->name) == 'playlist')
		{
			$pl = $ch[0];
			$tls = $pl->children;
			for ($i_ = 0, $l_ = count($tls); $i_ < $l_; $i_++)
			{
				if (strtolower($tls[$i_]->name) != 'tracklist')
					continue;
				$tracks = $tls[$i_]->children;
				for ($i = 0, $l = count($tracks); $i < $l; $i++)
				{
Beispiel #5
0
 /**
  * @param string $rawMetadata
  * @return array|false
  */
 protected function parseXmlMetadata($rawMetadata)
 {
     $xml = new \CDataXML();
     if ($xml->LoadString($rawMetadata)) {
         //detect xml encoding
         if (preg_match('/<\\?xml[^>]+?encoding=[\'"](.+?)[\'"]\\?>/', $rawMetadata, $matches)) {
             $this->metadataEncoding = $matches[1];
         } else {
             $this->metadataEncoding = 'UTF-8';
         }
         $result = array();
         $dom = $xml->GetTree();
         $mainNode = $dom->elementsByName('oembed');
         foreach ($mainNode[0]->children as $node) {
             $result[$node->name] = $node->content;
         }
         return $result;
     }
     return false;
 }