Commit f0039677 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-797 WBXMLDecoder is handling ActiveSync WBXML, which is only a subset of WBXML.

Released under the Affero GNU General Public License (AGPL) version 3.

let's cleanup and remove some (non working) code
for exemple we do not handle attributes
see also:
http://msdn.microsoft.com/en-us/library/hh475626%28v=exchg.80%29.aspx
http://www.w3.org/1999/06/NOTE-wbxml-19990624/
https://android.googlesource.com/platform/packages/apps/Exchange/+/master/src/com/android/exchange/adapter/Parser.java
parent 650d633d
This diff is collapsed.
...@@ -61,24 +61,27 @@ class WBXMLDefs { ...@@ -61,24 +61,27 @@ class WBXMLDefs {
const WBXML_SWITCH_PAGE = 0x00; const WBXML_SWITCH_PAGE = 0x00;
const WBXML_END = 0x01; const WBXML_END = 0x01;
const WBXML_ENTITY = 0x02; const WBXML_ENTITY = 0x02; //not used in ActiveSync
const WBXML_STR_I = 0x03; const WBXML_STR_I = 0x03;
const WBXML_LITERAL = 0x04; const WBXML_LITERAL = 0x04; //not used in ActiveSync
const WBXML_EXT_I_0 = 0x40; const WBXML_EXT_I_0 = 0x40; //not used in ActiveSync
const WBXML_EXT_I_1 = 0x41; const WBXML_EXT_I_1 = 0x41; //not used in ActiveSync
const WBXML_EXT_I_2 = 0x42; const WBXML_EXT_I_2 = 0x42; //not used in ActiveSync
const WBXML_PI = 0x43; const WBXML_PI = 0x43; //not used in ActiveSync
const WBXML_LITERAL_C = 0x44; const WBXML_LITERAL_C = 0x44; //not used in ActiveSync
const WBXML_EXT_T_0 = 0x80; const WBXML_EXT_T_0 = 0x80; //not used in ActiveSync
const WBXML_EXT_T_1 = 0x81; const WBXML_EXT_T_1 = 0x81; //not used in ActiveSync
const WBXML_EXT_T_2 = 0x82; const WBXML_EXT_T_2 = 0x82; //not used in ActiveSync
const WBXML_STR_T = 0x83; const WBXML_STR_T = 0x83; //not used in ActiveSync
const WBXML_LITERAL_A = 0x84; const WBXML_LITERAL_A = 0x84; //not used in ActiveSync
const WBXML_EXT_0 = 0xC0; const WBXML_EXT_0 = 0xC0; //not used in ActiveSync
const WBXML_EXT_1 = 0xC1; const WBXML_EXT_1 = 0xC1; //not used in ActiveSync
const WBXML_EXT_2 = 0xC2; const WBXML_EXT_2 = 0xC2; //not used in ActiveSync
const WBXML_OPAQUE = 0xC3; const WBXML_OPAQUE = 0xC3;
const WBXML_LITERAL_AC = 0xC4; const WBXML_LITERAL_AC = 0xC4; //not used in ActiveSync
const WBXML_WITH_ATTRIBUTES = 0x80; //not used in ActiveSync
const WBXML_WITH_CONTENT = 0x40;
/** /**
* The WBXML DTDs * The WBXML DTDs
......
...@@ -46,9 +46,9 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -46,9 +46,9 @@ class WBXMLEncoder extends WBXMLDefs {
private $_dtd; private $_dtd;
private $_out; private $_out;
private $_tagcp; private $_tagcp = 0;
private $_attrcp;
private $log = false;
private $logStack = array(); private $logStack = array();
// We use a delayed output mechanism in which we only output a tag when it actually has something // We use a delayed output mechanism in which we only output a tag when it actually has something
...@@ -63,14 +63,10 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -63,14 +63,10 @@ class WBXMLEncoder extends WBXMLDefs {
private $bodyparts; private $bodyparts;
public function WBXMLEncoder($output, $multipart = false) { public function WBXMLEncoder($output, $multipart = false) {
// make sure WBXML_DEBUG is defined. It should be at this point $this->log = @constant('WBXML_DEBUG') === true;
if (!defined('WBXML_DEBUG')) define('WBXML_DEBUG', false);
$this->_out = $output; $this->_out = $output;
$this->_tagcp = 0;
$this->_attrcp = 0;
// reverse-map the DTD // reverse-map the DTD
foreach($this->dtd["namespaces"] as $nsid => $nsname) { foreach($this->dtd["namespaces"] as $nsid => $nsname) {
$this->_dtd["namespaces"][$nsname] = $nsid; $this->_dtd["namespaces"][$nsname] = $nsid;
...@@ -124,7 +120,6 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -124,7 +120,6 @@ class WBXMLEncoder extends WBXMLDefs {
if(!$nocontent) { if(!$nocontent) {
$stackelem['tag'] = $tag; $stackelem['tag'] = $tag;
$stackelem['attributes'] = $attributes;
$stackelem['nocontent'] = $nocontent; $stackelem['nocontent'] = $nocontent;
$stackelem['sent'] = false; $stackelem['sent'] = false;
...@@ -134,7 +129,7 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -134,7 +129,7 @@ class WBXMLEncoder extends WBXMLDefs {
// output of an empty tag, and we therefore output the stack here // output of an empty tag, and we therefore output the stack here
} else { } else {
$this->_outputStack(); $this->_outputStack();
$this->_startTag($tag, $attributes, $nocontent); $this->_startTag($tag, $nocontent);
} }
} }
...@@ -252,7 +247,7 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -252,7 +247,7 @@ class WBXMLEncoder extends WBXMLDefs {
private function _outputStack() { private function _outputStack() {
for($i=0;$i<count($this->_stack);$i++) { for($i=0;$i<count($this->_stack);$i++) {
if(!$this->_stack[$i]['sent']) { if(!$this->_stack[$i]['sent']) {
$this->_startTag($this->_stack[$i]['tag'], $this->_stack[$i]['attributes'], $this->_stack[$i]['nocontent']); $this->_startTag($this->_stack[$i]['tag'], $this->_stack[$i]['nocontent']);
$this->_stack[$i]['sent'] = true; $this->_stack[$i]['sent'] = true;
} }
} }
...@@ -264,8 +259,9 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -264,8 +259,9 @@ class WBXMLEncoder extends WBXMLDefs {
* @access private * @access private
* @return * @return
*/ */
private function _startTag($tag, $attributes = false, $nocontent = false) { private function _startTag($tag, $nocontent = false) {
$this->logStartTag($tag, $attributes, $nocontent); if ($this->log)
$this->logStartTag($tag, $nocontent);
$mapping = $this->getMapping($tag); $mapping = $this->getMapping($tag);
...@@ -278,17 +274,11 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -278,17 +274,11 @@ class WBXMLEncoder extends WBXMLDefs {
} }
$code = $mapping["code"]; $code = $mapping["code"];
if(isset($attributes) && is_array($attributes) && count($attributes) > 0) {
$code |= 0x80;
}
if(!isset($nocontent) || !$nocontent) if(!isset($nocontent) || !$nocontent)
$code |= 0x40; $code |= 0x40;
$this->outByte($code); $this->outByte($code);
if($code & 0x80)
$this->outAttributes($attributes);
} }
/** /**
...@@ -299,7 +289,8 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -299,7 +289,8 @@ class WBXMLEncoder extends WBXMLDefs {
* @return * @return
*/ */
private function _content($content) { private function _content($content) {
$this->logContent($content); if ($this->log)
$this->logContent($content);
$this->outByte(self::WBXML_STR_I); $this->outByte(self::WBXML_STR_I);
$this->outTermStr($content); $this->outTermStr($content);
} }
...@@ -325,10 +316,11 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -325,10 +316,11 @@ class WBXMLEncoder extends WBXMLDefs {
} }
fwrite($this->_out, chr(0)); fwrite($this->_out, chr(0));
// data is out, do some logging if ($this->log) {
$stat = fstat($stream); // data is out, do some logging
$logContent = sprintf("<<< written %d of %d bytes of %s data >>>", $written, $stat['size'], $asBase64 ? "base64 encoded":"plain"); $stat = fstat($stream);
$this->logContent($logContent); $this->logContent(sprintf("<<< written %d of %d bytes of %s data >>>", $written, $stat['size'], $asBase64 ? "base64 encoded":"plain"));
}
} }
/** /**
...@@ -338,7 +330,8 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -338,7 +330,8 @@ class WBXMLEncoder extends WBXMLDefs {
* @return * @return
*/ */
private function _endTag() { private function _endTag() {
$this->logEndTag(); if ($this->log)
$this->logEndTag();
$this->outByte(self::WBXML_END); $this->outByte(self::WBXML_END);
} }
...@@ -388,20 +381,6 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -388,20 +381,6 @@ class WBXMLEncoder extends WBXMLDefs {
fwrite($this->_out, chr(0)); fwrite($this->_out, chr(0));
} }
/**
* Output attributes
* We don't actually support this, because to do so, we would have
* to build a string table before sending the data (but we can't
* because we're streaming), so we'll just send an END, which just
* terminates the attribute list with 0 attributes.
*
* @access private
* @return
*/
private function outAttributes() {
$this->outByte(self::WBXML_END);
}
/** /**
* Switches the codepage * Switches the codepage
* *
...@@ -475,16 +454,12 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -475,16 +454,12 @@ class WBXMLEncoder extends WBXMLDefs {
* Logs a StartTag to ZLog * Logs a StartTag to ZLog
* *
* @param $tag * @param $tag
* @param $attr
* @param $nocontent * @param $nocontent
* *
* @access private * @access private
* @return * @return
*/ */
private function logStartTag($tag, $attr, $nocontent) { private function logStartTag($tag, $nocontent) {
if(!WBXML_DEBUG)
return;
$spaces = str_repeat(" ", count($this->logStack)); $spaces = str_repeat(" ", count($this->logStack));
if($nocontent) if($nocontent)
ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag/>"); ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag/>");
...@@ -501,9 +476,6 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -501,9 +476,6 @@ class WBXMLEncoder extends WBXMLDefs {
* @return * @return
*/ */
private function logEndTag() { private function logEndTag() {
if(!WBXML_DEBUG)
return;
$spaces = str_repeat(" ", count($this->logStack)); $spaces = str_repeat(" ", count($this->logStack));
$tag = array_pop($this->logStack); $tag = array_pop($this->logStack);
ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . "</$tag>"); ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . "</$tag>");
...@@ -518,9 +490,6 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -518,9 +490,6 @@ class WBXMLEncoder extends WBXMLDefs {
* @return * @return
*/ */
private function logContent($content) { private function logContent($content) {
if(!WBXML_DEBUG)
return;
$spaces = str_repeat(" ", count($this->logStack)); $spaces = str_repeat(" ", count($this->logStack));
ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . $content); ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . $content);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment