Esempio n. 1
0
 /**
  * return request params
  *
  * @return array
  */
 protected function _getRequestParameters(CakeRequest $request)
 {
     //if (strpos($request->getRequestUri(), '&') === false) {
     //$this->_logger->debug('Requested url: ' . print_r($request->query, true));
     //$this->_logger->debug('Empty query: ' . print_r(empty($request->query), true));
     //$this->_logger->debug('Count query: ' . print_r(count($request->query), true));
     //if (strpos($request->url, '&') === false) {
     if (count($request->query) <= 1) {
         $this->_logger->debug('Non query request');
         $commands = array(0 => 'Sync', 1 => 'SendMail', 2 => 'SmartForward', 3 => 'SmartReply', 4 => 'GetAttachment', 9 => 'FolderSync', 10 => 'FolderCreate', 11 => 'FolderDelete', 12 => 'FolderUpdate', 13 => 'MoveItems', 14 => 'GetItemEstimate', 15 => 'MeetingResponse', 16 => 'Search', 17 => 'Settings', 18 => 'Ping', 19 => 'ItemOperations', 20 => 'Provision', 21 => 'ResolveRecipients', 22 => 'ValidateCert');
         //$requestParameters = substr($request->getRequestUri(), strpos($request->getRequestUri(), '?'));
         $requestParameters = substr($request->url, strpos($request->url, '?'));
         $stream = fopen("php://temp", 'r+');
         fwrite($stream, base64_decode($requestParameters));
         rewind($stream);
         // unpack the first 4 bytes
         $unpacked = unpack('CprotocolVersion/Ccommand/vlocale', fread($stream, 4));
         // 140 => 14.0
         $protocolVersion = substr($unpacked['protocolVersion'], 0, -1) . '.' . substr($unpacked['protocolVersion'], -1);
         $command = $commands[$unpacked['command']];
         $locale = $unpacked['locale'];
         // unpack deviceId
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $toUnpack = fread($stream, $length);
             $unpacked = unpack("H" . $length * 2 . "string", $toUnpack);
             $deviceId = $unpacked['string'];
         }
         // unpack policyKey
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $unpacked = unpack('Vstring', fread($stream, $length));
             $policyKey = $unpacked['string'];
         }
         // unpack device type
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
             $deviceType = $unpacked['string'];
         }
         while (!feof($stream)) {
             $tag = ord(fread($stream, 1));
             $length = ord(fread($stream, 1));
             switch ($tag) {
                 case self::PARAMETER_ATTACHMENTNAME:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $attachmentName = $unpacked['string'];
                     break;
                 case self::PARAMETER_COLLECTIONID:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $collectionId = $unpacked['string'];
                     break;
                 case self::PARAMETER_ITEMID:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $itemId = $unpacked['string'];
                     break;
                 case self::PARAMETER_OPTIONS:
                     $options = ord(fread($stream, 1));
                     $saveInSent = !!($options & 0x1);
                     $acceptMultiPart = !!($options & 0x2);
                     break;
                 default:
                     if ($this->_logger instanceof Syncroton_Log) {
                         $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " found unhandled command parameters");
                     }
             }
         }
         $result = array('protocolVersion' => $protocolVersion, 'command' => $command, 'deviceId' => $deviceId, 'deviceType' => isset($deviceType) ? $deviceType : null, 'policyKey' => isset($policyKey) ? $policyKey : null, 'saveInSent' => isset($saveInSent) ? $saveInSent : false, 'collectionId' => isset($collectionId) ? $collectionId : null, 'itemId' => isset($itemId) ? $itemId : null, 'attachmentName' => isset($attachmentName) ? $attachmentName : null, 'acceptMultipart' => isset($acceptMultiPart) ? $acceptMultiPart : false);
     } else {
         $result = array('protocolVersion' => $request->header('MS_ASPROTOCOLVERSION'), 'command' => $request->query('Cmd'), 'deviceId' => $request->query('DeviceId'), 'deviceType' => $request->query('DeviceType'), 'policyKey' => $request->header('X_MS_POLICYKEY'), 'saveInSent' => $request->query('SaveInSent') == 'T', 'collectionId' => $request->query('CollectionId'), 'itemId' => $request->query('ItemId'), 'attachmentName' => $request->query('AttachmentName'), 'acceptMultipart' => $request->header('MS_ASACCEPTMULTIPART') == 'T');
     }
     $result['userAgent'] = env('HTTP_USER_AGENT', $result['deviceType']);
     $result['contentType'] = env('CONTENT_TYPE');
     //$this->_logger->debug('Query result: ' . print_r($result, true));
     return $result;
 }