Author: Michael J Rubinsky (mrubinsk@horde.org)
Inheritance: extends Horde_ActiveSync_Wbxml
Example #1
0
 /**
  * Send WBXML to indicate provisioning is required.
  *
  * @param string $requestType  The type of request we are handling.
  * @param integer $status      The reason we need to provision.
  */
 protected function _requireProvisionWbxml($requestType, $status)
 {
     $this->_encoder->startWBXML();
     $this->_encoder->startTag($requestType);
     $this->_encoder->startTag(Horde_ActiveSync::SYNC_STATUS);
     $this->_encoder->content($status);
     $this->_encoder->endTag();
     $this->_encoder->endTag();
 }
Example #2
0
 /**
  * Stream a message deletion to the client.
  *
  * @param string $id  The uid of the message we are deleting.
  * @param boolean $soft  If true, send a SOFTDELETE, otherwise a REMOVE.
  */
 public function messageDeletion($id, $soft = false)
 {
     if ($soft) {
         $this->_encoder->startTag(Horde_ActiveSync::SYNC_SOFTDELETE);
     } else {
         $this->_encoder->startTag(Horde_ActiveSync::SYNC_REMOVE);
     }
     $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID);
     $this->_encoder->content($id);
     $this->_encoder->endTag();
     $this->_encoder->endTag();
 }
Example #3
0
 protected function _setLogger(array $options)
 {
     if (!empty($this->_loggerFactory)) {
         self::$_logger = $this->_loggerFactory->create($options);
         $this->_encoder->setLogger(self::$_logger);
         $this->_decoder->setLogger(self::$_logger);
         $this->_driver->setLogger(self::$_logger);
         $this->_state->setLogger(self::$_logger);
     }
 }
Example #4
0
 /**
  * Output a single policy value
  *
  * @param string $policy      The policy name
  * @param mixed $value        The policy value
  * @param boolean $nodefault  Don't send the policy if the value is default.
  */
 protected function _sendPolicy($policy, $value, $nodefault = false)
 {
     if ($nodefault && $value == $this->_defaults[$policy]) {
         return;
     }
     if ($value === false) {
         $value = 0;
     } elseif ($value === true) {
         $value = 1;
     }
     $this->_encoder->startTag('Provision:' . $policy);
     $this->_encoder->content($value);
     $this->_encoder->endTag();
 }
Example #5
0
 /**
  * Encodes this object (and any sub-objects) as wbxml to the output stream.
  * Output is ordered according to $_mapping
  *
  * @param Horde_ActiveSync_Wbxml_Encoder $encoder  The wbxml stream encoder
  */
 public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder)
 {
     foreach ($this->_mapping as $tag => $map) {
         if (isset($this->{$map}[self::KEY_ATTRIBUTE])) {
             // Variable is available
             if (is_object($this->{$map}[self::KEY_ATTRIBUTE]) && !$this->{$map}[self::KEY_ATTRIBUTE] instanceof Horde_Date) {
                 // Subobjects can do their own encoding
                 $encoder->startTag($tag);
                 $this->{$map}[self::KEY_ATTRIBUTE]->encodeStream($encoder);
                 $encoder->endTag();
             } elseif (isset($map[self::KEY_VALUES]) && is_array($this->{$map}[self::KEY_ATTRIBUTE])) {
                 // Array of objects. Note that some array values must be
                 // send as an empty tag if they contain no elements.
                 if (count($this->{$map}[self::KEY_ATTRIBUTE])) {
                     $encoder->startTag($tag);
                     foreach ($this->{$map}[self::KEY_ATTRIBUTE] as $element) {
                         if (is_object($element)) {
                             // Outputs object container (eg Attachment)
                             $encoder->startTag($map[self::KEY_VALUES]);
                             $element->encodeStream($encoder);
                             $encoder->endTag();
                         } else {
                             // Do not ever output empty items here
                             if (strlen($element) > 0) {
                                 $encoder->startTag($map[self::KEY_VALUES]);
                                 $encoder->content($element);
                                 $encoder->endTag();
                             }
                         }
                     }
                     $encoder->endTag();
                 } elseif ($this->_checkSendEmpty($tag)) {
                     $encoder->startTag($tag, null, true);
                 }
             } else {
                 // Simple type
                 if (!is_resource($this->{$map}[self::KEY_ATTRIBUTE]) && strlen($this->{$map}[self::KEY_ATTRIBUTE]) == 0) {
                     // Do not output empty items except for the following:
                     if ($this->_checkSendEmpty($tag)) {
                         $encoder->startTag($tag, $this->{$map}[self::KEY_ATTRIBUTE], true);
                     }
                     continue;
                 } elseif ($encoder->multipart && in_array($tag, array(Horde_ActiveSync::SYNC_DATA, Horde_ActiveSync::AIRSYNCBASE_DATA, Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA))) {
                     $this->_logger->info('HANDLING MULTIPART OUTPUT');
                     $encoder->addPart($this->{$map}[self::KEY_ATTRIBUTE]);
                     $encoder->startTag(Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_PART);
                     $encoder->content((string) (count($encoder->getParts()) - 1));
                     $encoder->endTag();
                     continue;
                 }
                 $encoder->startTag($tag);
                 if (isset($map[self::KEY_TYPE]) && ($map[self::KEY_TYPE] == self::TYPE_DATE || $map[self::KEY_TYPE] == self::TYPE_DATE_DASHES)) {
                     if (!empty($this->{$map}[self::KEY_ATTRIBUTE])) {
                         // don't output 1-1-1970
                         $encoder->content($this->_formatDate($this->{$map}[self::KEY_ATTRIBUTE], $map[self::KEY_TYPE]));
                     }
                 } elseif (isset($map[self::KEY_TYPE]) && $map[self::KEY_TYPE] == self::TYPE_HEX) {
                     $encoder->content(Horde_String::upper(bin2hex($this->{$map}[self::KEY_ATTRIBUTE])));
                 } elseif (isset($map[self::KEY_TYPE]) && $map[self::KEY_TYPE] == self::TYPE_MAPI_STREAM) {
                     $encoder->content($this->{$map}[self::KEY_ATTRIBUTE]);
                 } else {
                     $encoder->content($this->_checkEncoding($this->{$map}[self::KEY_ATTRIBUTE], $tag));
                 }
                 $encoder->endTag();
             }
         }
     }
 }
Example #6
0
 public function testEncodingSimpleExceptions()
 {
     $this->markTestSkipped('Needs updated fixture.');
     $l = new Horde_Test_Log();
     $logger = $l->getLogger();
     //$logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream(fopen('/tmp/test.log', 'a')));
     // Every other week recurrence, on thursday, no end.
     $r = new Horde_Date_Recurrence('2011-12-01T15:00:00');
     $r->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY);
     $r->setRecurInterval(2);
     $r->setRecurOnDay(Horde_Date::MASK_THURSDAY);
     $r->addException(2011, 12, 29);
     $e = new Horde_ActiveSync_Message_Exception();
     $d = new Horde_Date('2011-12-29T15:00:00');
     $e->setExceptionStartTime($d);
     $e->deleted = true;
     $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger));
     $appt->setSubject('Event Title');
     $appt->setBody('Event Description');
     $appt->setLocation('Philadelphia, PA');
     $start = new Horde_Date('2011-12-01T15:00:00');
     $appt->setDatetime(array('start' => $start, 'end' => new Horde_Date('2011-12-01T16:00:00'), 'allday' => false));
     $appt->setTimezone($start);
     $appt->setSensitivity(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL);
     $appt->setBusyStatus(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY);
     $appt->setDTStamp($start->timestamp());
     $appt->setRecurrence($r);
     $appt->addException($e);
     $stream = fopen('php://memory', 'w+');
     $encoder = new Horde_ActiveSync_Wbxml_Encoder($stream);
     $encoder->setLogger($logger);
     $encoder->startTag(Horde_ActiveSync::SYNC_DATA);
     $appt->encodeStream($encoder);
     $encoder->endTag();
     $fixture = file_get_contents(__DIR__ . '/fixtures/simpleexception.wbxml');
     rewind($stream);
     $results = stream_get_contents($stream);
     fclose($stream);
     $this->assertEquals($fixture, $results);
 }
Example #7
0
File: Base.php Project: horde/horde
 /**
  * Encodes this object (and any sub-objects) as wbxml to the output stream.
  * Output is ordered according to $_mapping
  *
  * @param Horde_ActiveSync_Wbxml_Encoder $encoder  The wbxml stream encoder
  * @throws  Horde_ActiveSync_Exception
  */
 public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder)
 {
     if (!$this->_preEncodeValidation()) {
         $this->_logger->err(sprintf('Pre-encoding validation failed for %s item', get_class($this)));
         throw new Horde_ActiveSync_Exception(sprintf('Pre-encoding validation failded for %s item', get_class($this)));
     }
     foreach ($this->_mapping as $tag => $map) {
         if (isset($this->{$map[self::KEY_ATTRIBUTE]})) {
             // Variable is available
             if (is_object($this->{$map[self::KEY_ATTRIBUTE]}) && !$this->{$map[self::KEY_ATTRIBUTE]} instanceof Horde_Date) {
                 // Objects can do their own encoding
                 $encoder->startTag($tag);
                 $this->{$map[self::KEY_ATTRIBUTE]}->encodeStream($encoder);
                 $encoder->endTag();
             } elseif (isset($map[self::KEY_VALUES]) && is_array($this->{$map[self::KEY_ATTRIBUTE]})) {
                 // Array of objects. Note that some array values must be
                 // send as an empty tag if they contain no elements.
                 if (count($this->{$map[self::KEY_ATTRIBUTE]})) {
                     if (!isset($map[self::KEY_PROPERTY]) || $map[self::KEY_PROPERTY] != self::PROPERTY_NO_CONTAINER) {
                         $encoder->startTag($tag);
                     }
                     foreach ($this->{$map[self::KEY_ATTRIBUTE]} as $element) {
                         if (is_object($element)) {
                             // Hanlde multi-typed array containers.
                             if (is_array($map[self::KEY_VALUES])) {
                                 $idx = array_search(get_class($element), $map[self::KEY_TYPE]);
                                 $tag = $map[self::KEY_VALUES][$idx];
                             } else {
                                 $tag = $map[self::KEY_VALUES];
                             }
                             // Outputs object container (eg Attachment)
                             $encoder->startTag($tag);
                             $element->encodeStream($encoder);
                             $encoder->endTag();
                         } else {
                             // Do not ever output empty items here
                             if (strlen($element) > 0) {
                                 $encoder->startTag($map[self::KEY_VALUES]);
                                 $encoder->content($element);
                                 $encoder->endTag();
                             }
                         }
                     }
                     if (!isset($map[self::KEY_PROPERTY]) || $map[self::KEY_PROPERTY] != self::PROPERTY_NO_CONTAINER) {
                         $encoder->endTag();
                     }
                 } elseif ($this->_checkSendEmpty($tag)) {
                     $encoder->startTag($tag, null, true);
                 }
             } else {
                 // Simple type
                 if (!is_resource($this->{$map[self::KEY_ATTRIBUTE]}) && strlen($this->{$map[self::KEY_ATTRIBUTE]}) == 0) {
                     // Do not output empty items except for the following:
                     if ($this->_checkSendEmpty($tag)) {
                         $encoder->startTag($tag, $this->{$map[self::KEY_ATTRIBUTE]}, true);
                     }
                     continue;
                 } elseif ($encoder->multipart && in_array($tag, array(Horde_ActiveSync::SYNC_DATA, Horde_ActiveSync::AIRSYNCBASE_DATA, Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA))) {
                     $this->_logger->info('HANDLING MULTIPART OUTPUT');
                     $encoder->addPart($this->{$map[self::KEY_ATTRIBUTE]});
                     $encoder->startTag(Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_PART);
                     $encoder->content((string) (count($encoder->getParts()) - 1));
                     $encoder->endTag();
                     continue;
                 }
                 $encoder->startTag($tag);
                 if (isset($map[self::KEY_TYPE]) && in_array($map[self::KEY_TYPE], array(self::TYPE_DATE, self::TYPE_DATE_DASHES, self::TYPE_DATE_LOCAL))) {
                     if (!empty($this->{$map[self::KEY_ATTRIBUTE]})) {
                         // don't output 1-1-1970
                         $encoder->content($this->_formatDate($this->{$map[self::KEY_ATTRIBUTE]}, $map[self::KEY_TYPE]));
                     }
                 } elseif (isset($map[self::KEY_TYPE]) && $map[self::KEY_TYPE] == self::TYPE_HEX) {
                     $encoder->content(Horde_String::upper(bin2hex($this->{$map[self::KEY_ATTRIBUTE]})));
                 } elseif (isset($map[self::KEY_TYPE]) && $map[self::KEY_TYPE] == self::TYPE_MAPI_STREAM) {
                     $encoder->content($this->{$map[self::KEY_ATTRIBUTE]});
                 } else {
                     $encoder->content($this->_checkEncoding($this->{$map[self::KEY_ATTRIBUTE]}, $tag));
                 }
                 $encoder->endTag();
             }
         }
     }
 }