Esempio n. 1
0
 /**
  * @todo Update the error class or better make a implementation of it
  * @return IO
  */
 public function InputResponse($strResponse, $objCodifyEngine)
 {
     $objDebug = Debug::getInstance();
     // Check for start and end tag
     if (strpos($strResponse, "<|@|") === false || strpos($strResponse, "|@|>") === false) {
         $objDebug->addDebug("Error CtoComIOImpl_Default", substr($strResponse, 0, 4096));
         throw new \RuntimeException("Could not find start or endtag from response.");
     }
     // Find position of start/end - tag
     $intStart = intval(strpos($strResponse, "<|@|") + 4);
     $intLength = intval(strpos($strResponse, "|@|>") - $intStart);
     $strResponse = substr($strResponse, $intStart, $intLength);
     $strResponse = base64_decode($strResponse);
     $strResponse = @gzuncompress($strResponse);
     // Check if uncompress works
     if ($strResponse === false) {
         throw new \RuntimeException("Error on uncompressing the response. Maybe wrong API-Key or ctoCom version.");
     }
     // Decrypt
     $strResponse = $objCodifyEngine->Decrypt($strResponse);
     // Deserialize response
     $arrResponse = unserialize($strResponse);
     // Check if we have a array
     if (is_array($arrResponse) == false) {
         $objDebug->addDebug("Error CtoComIOImpl_Default", substr($arrResponse, 0, 4096));
         throw new \RuntimeException("Response is not an array. Maybe wrong API-Key or cryptionengine.");
     }
     // Clean array
     $arrResponse = $this->cleanUp($arrResponse);
     $objContainer = new IO();
     $objContainer->setSuccess($arrResponse["success"]);
     $objContainer->setResponse($arrResponse["response"]);
     $objContainer->setSplitcontent($arrResponse["splitcontent"]);
     $objContainer->setSplitcount($arrResponse["splitcount"]);
     $objContainer->setSplitname($arrResponse["splitname"]);
     // Set error
     if ($arrResponse["error"] != "") {
         $objError = new Error();
         $objError->setID($arrResponse["error"]["id"]);
         $objError->setObject($arrResponse["error"]["object"]);
         $objError->setMessage($arrResponse["error"]["msg"]);
         $objError->setRPC($arrResponse["error"]["rpc"]);
         $objError->setClass($arrResponse["error"]["class"]);
         $objError->setFunction($arrResponse["error"]["function"]);
         $objError->setException($arrResponse["error"]["exception"]);
         $objContainer->setError($objError);
     }
     return $objContainer;
 }
Esempio n. 2
0
 /**
  * Build the answer and serialize it
  *
  * @return string
  */
 protected function generateOutput()
 {
     $objOutputContainer = new IO();
     if ($this->objError == false) {
         $objOutputContainer->setSuccess(true);
         $objOutputContainer->setResponse($this->mixOutput);
         $objOutputContainer->setSplitcontent(false);
         $objOutputContainer->setSplitcount(0);
         $objOutputContainer->setSplitname("");
     } else {
         $objOutputContainer->setSuccess(false);
         $objOutputContainer->setError($this->objError);
         $objOutputContainer->setResponse(null);
         $objOutputContainer->setSplitcontent(false);
         $objOutputContainer->setSplitcount(0);
         $objOutputContainer->setSplitname("");
     }
     $mixOutput = $this->objIOEngine->OutputResponse($objOutputContainer, $this->objCodifyengine);
     // Check if we have a big output and split it
     if ($this->config->getResponseLength() != -1 && strlen($mixOutput) > $this->config->getResponseLength()) {
         $mixOutput = str_split($mixOutput, (int) ($this->config->getResponseLength() * 0.8));
         $strFileName = md5(time()) . md5(rand(0, 65000)) . ".ctoComPart";
         $intCountPart = count($mixOutput);
         foreach ($mixOutput as $keyOutput => $valueOutput) {
             $objFile = new \File("system/tmp/" . $keyOutput . "_" . $strFileName);
             $objFile->write($valueOutput);
             $objFile->close();
         }
         $objOutputContainer = new IO();
         $objOutputContainer->setSuccess(true);
         $objOutputContainer->setResponse(null);
         $objOutputContainer->setSplitcontent(true);
         $objOutputContainer->setSplitcount($intCountPart);
         $objOutputContainer->setSplitname($strFileName);
         $mixOutput = $this->objIOEngine->OutputResponse($objOutputContainer, $this->objCodifyengine);
     }
     // Set some header fields
     header("Content-Type: " . $GLOBALS["CTOCOM_IO"][$this->strIOEngine]["contentType"]);
     // Clean output buffer
     while (@ob_end_clean()) {
     }
     // Echo response
     echo $mixOutput;
 }