Пример #1
0
 /**
  * @param unknown_type $_class
  * @param Syncroton_Model_IDevice $_device
  * @param DateTime $_timeStamp
  * @throws InvalidArgumentException
  * @return Syncroton_Data_IData
  */
 public static function factory($_classFactory, Syncroton_Model_IDevice $_device, DateTime $_timeStamp)
 {
     switch ($_classFactory) {
         case self::CLASS_CALENDAR:
             $className = Syncroton_Registry::get(Syncroton_Registry::CALENDAR_DATA_CLASS);
             break;
         case self::CLASS_CONTACTS:
             $className = Syncroton_Registry::get(Syncroton_Registry::CONTACTS_DATA_CLASS);
             break;
         case self::STORE_EMAIL:
         case self::CLASS_EMAIL:
             $className = Syncroton_Registry::get(Syncroton_Registry::EMAIL_DATA_CLASS);
             break;
         case self::CLASS_NOTES:
             $className = Syncroton_Registry::get(Syncroton_Registry::NOTES_DATA_CLASS);
             break;
         case self::CLASS_TASKS:
             $className = Syncroton_Registry::get(Syncroton_Registry::TASKS_DATA_CLASS);
             break;
         case self::STORE_GAL:
             $className = Syncroton_Registry::get(Syncroton_Registry::GAL_DATA_CLASS);
             break;
         default:
             throw new Syncroton_Exception_UnexpectedValue('invalid class type provided');
             breeak;
     }
     $class = new $className($_device, $_timeStamp);
     if (!$class instanceof Syncroton_Data_IData) {
         throw new RuntimeException('class must be instanceof Syncroton_Data_IData');
     }
     return $class;
 }
Пример #2
0
 /**
  * get existing device of owner or create new device for owner
  *
  * @param unknown_type $ownerId
  * @param unknown_type $deviceId
  * @param unknown_type $deviceType
  * @param unknown_type $userAgent
  * @param unknown_type $protocolVersion
  * @return Syncroton_Model_Device
  */
 protected function _getUserDevice($ownerId, $requestParameters)
 {
     try {
         $device = $this->_deviceBackend->getUserDevice($ownerId, $requestParameters['deviceId']);
         $device->useragent = $requestParameters['userAgent'];
         $device->acsversion = $requestParameters['protocolVersion'];
         if ($device->isDirty()) {
             $device = $this->_deviceBackend->update($device);
         }
     } catch (Syncroton_Exception_NotFound $senf) {
         $device = $this->_deviceBackend->create(new Syncroton_Model_Device(array('owner_id' => $ownerId, 'deviceid' => $requestParameters['deviceId'], 'devicetype' => $requestParameters['deviceType'], 'useragent' => $requestParameters['userAgent'], 'acsversion' => $requestParameters['protocolVersion'], 'policyId' => Syncroton_Registry::isRegistered(Syncroton_Registry::DEFAULT_POLICY) ? Syncroton_Registry::get(Syncroton_Registry::DEFAULT_POLICY) : null)));
     }
     return $device;
 }
 /**
  * constructor
  */
 private function __construct()
 {
     if (Syncroton_Registry::isRegistered('loggerBackend')) {
         $this->_logger = Syncroton_Registry::get('loggerBackend');
     }
 }
 /**
  * Get Expressomail message id from source structure
  *
  * @param array|string $source
  * @return string
  */
 public function getMessageIdFromSource($source)
 {
     $serverId = is_array($source) ? $source['itemId'] : $source;
     $folderId = is_array($source) ? $source['collectionId'] : NULL;
     // is $serverId a LongId?
     if (strpos($serverId, ActiveSync_Frontend_Abstract::LONGID_DELIMITER) !== false) {
         list($folderId, $serverId) = explode(ActiveSync_Frontend_Abstract::LONGID_DELIMITER, $serverId, 2);
     }
     $folderBackend = Syncroton_Registry::get(Syncroton_Registry::FOLDERBACKEND);
     $folder = $folderBackend->getFolder($this->_device, $folderId);
     return $this->getBigContentId($folder->id, $serverId);
 }
Пример #5
0
 /**
  * the constructor
  *
  * @param  mixed				   $requestBody
  * @param  Syncroton_Model_Device  $device
  * @param  array				   $requestParameters
  */
 public function __construct($requestBody, Syncroton_Model_IDevice $device, $requestParameters)
 {
     $this->_requestBody = $requestBody;
     $this->_device = $device;
     $this->_requestParameters = $requestParameters;
     $this->_policyKey = $requestParameters['policyKey'];
     $this->_deviceBackend = Syncroton_Registry::getDeviceBackend();
     $this->_folderBackend = Syncroton_Registry::getFolderBackend();
     $this->_syncStateBackend = Syncroton_Registry::getSyncStateBackend();
     $this->_contentStateBackend = Syncroton_Registry::getContentStateBackend();
     $this->_policyBackend = Syncroton_Registry::getPolicyBackend();
     if (Syncroton_Registry::isRegistered('loggerBackend')) {
         $this->_logger = Syncroton_Registry::get('loggerBackend');
     }
     $this->_syncTimeStamp = new DateTime(null, new DateTimeZone('UTC'));
     // set default content type
     $this->_headers['Content-Type'] = 'application/vnd.ms-sync.wbxml';
     if ($this->_logger instanceof Syncroton_Log) {
         $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " sync timestamp: " . $this->_syncTimeStamp->format('Y-m-d H:i:s'));
     }
     if (isset($this->_defaultNameSpace) && isset($this->_documentElement)) {
         // Creates an instance of the DOMImplementation class
         $imp = new DOMImplementation();
         // Creates a DOMDocumentType instance
         $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
         // Creates a DOMDocument instance
         $this->_outputDom = $imp->createDocument($this->_defaultNameSpace, $this->_documentElement, $dtd);
         $this->_outputDom->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Syncroton', 'uri:Syncroton');
         $this->_outputDom->formatOutput = false;
         $this->_outputDom->encoding = 'utf-8';
     }
     if ($this->_skipValidatePolicyKey != true) {
         if (!empty($this->_device->policyId)) {
             $policy = $this->_policyBackend->get($this->_device->policyId);
             if ((int) $policy->policyKey != (int) $this->_policyKey) {
                 $this->_outputDom->documentElement->appendChild($this->_outputDom->createElementNS($this->_defaultNameSpace, 'Status', 142));
                 $sepn = new Syncroton_Exception_ProvisioningNeeded();
                 $sepn->domDocument = $this->_outputDom;
                 throw $sepn;
             }
             // should we wipe the mobile phone?
             if ($this->_device->remotewipe >= Syncroton_Command_Provision::REMOTEWIPE_REQUESTED) {
                 $this->_outputDom->documentElement->appendChild($this->_outputDom->createElementNS($this->_defaultNameSpace, 'Status', 140));
                 $sepn = new Syncroton_Exception_ProvisioningNeeded();
                 $sepn->domDocument = $this->_outputDom;
                 throw $sepn;
             }
         }
     }
 }