[sync] WBXML kludge
Anthony Mills
amills at gascard.net
Mon Feb 9 22:08:11 PST 2004
I modified Encoder and Decoder to use libwbxml. It is an ugly hack, but
it seems to work. I can go back to working on SyncML now. I'm only
sending patches, someone else can commit it if they think it is useful.
Anthon
Index: Encoder.php
===================================================================
RCS file: /repository/framework/XML_WBXML/WBXML/Encoder.php,v
retrieving revision 1.20
diff -r1.20 Encoder.php
84a85,93
> $tmp_id = mt_rand();
> $tmp_file = '/tmp' . DIRECTORY_SEPARATOR . 'wbxml_encoder_' .
$tmp_id;
>
> $fp = fopen($tmp_file . '.xml', 'wb');
> fwrite($fp, $xml);
> fclose($fp);
>
> exec('/usr/bin/xml2wbxml -o ' . $tmp_file . '.wbxml ' .
$tmp_file . '.xml');
>
86,103c95,114
< $this->_parser = xml_parser_create_ns($this->_charset);
< xml_set_object($this->_parser, $this);
< xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING,
false);
< xml_set_element_handler($this->_parser, '_startElement',
'_endElement');
< xml_set_character_data_handler($this->_parser, '_characters');
< xml_set_default_handler($this->_parser, 'defaultHandler');
< xml_set_processing_instruction_handler($this->_parser, '');
< xml_set_external_entity_ref_handler($this->_parser, '');
<
< if (!xml_parse($this->_parser, $xml)) {
< return $this->raiseError(sprintf('XML error: %s at line %d',
<
xml_error_string(xml_get_error_code($this->_parser)),
<
xml_get_current_line_number($this->_parser)));
< }
<
< xml_parser_free($this->_parser);
<
< return $this->_output;
---
> //$this->_parser = xml_parser_create_ns($this->_charset);
> // xml_set_object($this->_parser, $this);
> // xml_parser_set_option($this->_parser,
XML_OPTION_CASE_FOLDING, false);
> // xml_set_element_handler($this->_parser, '_startElement',
'_endElement');
> // xml_set_character_data_handler($this->_parser, '_characters');
> // xml_set_default_handler($this->_parser, 'defaultHandler');
> // xml_set_processing_instruction_handler($this->_parser, '');
> // xml_set_external_entity_ref_handler($this->_parser, '');
> //
> // if (!xml_parse($this->_parser, $xml)) {
> // return $this->raiseError(sprintf('XML error: %s at
line %d',
> //
xml_error_string(xml_get_error_code($this->_parser)),
> //
xml_get_current_line_number($this->_parser)));
> // }
> //
> // xml_parser_free($this->_parser);
>
>
> return file_get_contents($tmp_file . '.wbxml');
> //return $this->_output;
Index: Decoder.php
===================================================================
RCS file: /repository/framework/XML_WBXML/WBXML/Decoder.php,v
retrieving revision 1.16
diff -r1.16 Decoder.php
88,135c88,146
< $this->_strpos = 0;
< // Get Version Number from Section 5.4
< // version = u_int8
< // currently 1, 2 or 3
< $this->_wbxmlVersion = $this->getVersionNumber($input);
<
< // Get Document Public Idetifier from Section 5.5
< // publicid = mb_u_int32 | (zero index)
< // zero = u_int8
< // Containing the value zero (0)
< // The actual DPI is determined after the String Table is read.
< $dpiStruct = $this->getDocumentPublicIdentifier($input);
<
< // Get Charset from 5.6
< // charset = mb_u_int32
< $this->_charset = $this->getCharset($input);
<
< // Get String Table from 5.7
< // strb1 = length *byte
< $this->_stringTable = $this->getStringTable($input,
$this->_charset);
<
< // Get Document Public Idetifier from Section 5.5.
< $this->_dpi =
$this->getDocumentPublicIdentifierImpl($dpiStruct['dpiType'],
<
$dpiStruct['dpiNumber'],
<
$this->_stringTable);
<
< // Now the real fun begins.
< // from Sections 5.2 and 5.8
<
< // Default content handler.
< $this->_ch = &new XML_WBXML_ContentHandler();
<
< // Default content handler.
< $this->_dtdManager = &new XML_WBXML_DTDManager();
<
< // Get the starting DTD.
< $this->_tagDTD = $this->_dtdManager->getInstance($this->_dpi);
< if (!$this->_tagDTD) {
< return $this->raiseError('No DTD found for ' . $this->_dpi);
< }
<
< $this->_attributeDTD = $this->_tagDTD;
<
< while ($this->_strpos < strlen($input)) {
< $this->_decode($input);
< }
<
< return $this->_ch->getOutput();
------
> $tmp_id = mt_rand();
> $tmp_file = '/tmp' . DIRECTORY_SEPARATOR . 'wbxml_decoder_' .
$tmp_id;
>
> $fp = fopen($tmp_file . '.wbxml', 'wb');
> fwrite($fp, $input);
> fclose($fp);
>
> exec('/usr/bin/wbxml2xml -o ' . $tmp_file . '.xml ' .
$tmp_file . '.wbxml');
>
> // $this->_strpos = 0;
> // // Get Version Number from Section 5.4
> // // version = u_int8
> // // currently 1, 2 or 3
> // $this->_wbxmlVersion = $this->getVersionNumber($input);
> //
> // // Get Document Public Idetifier from Section 5.5
> // // publicid = mb_u_int32 | (zero index)
> // // zero = u_int8
> // // Containing the value zero (0)
> // // The actual DPI is determined after the String Table is
read.
> // $dpiStruct = $this->getDocumentPublicIdentifier($input);
> //
> // // Get Charset from 5.6
> // // charset = mb_u_int32
> // $this->_charset = $this->getCharset($input);
> //
> // // Get String Table from 5.7
> // // strb1 = length *byte
> // $this->_stringTable = $this->getStringTable($input,
$this->_charset);
> //
> // // Get Document Public Idetifier from Section 5.5.
> // $this->_dpi =
$this->getDocumentPublicIdentifierImpl($dpiStruct['dpiType'],
> //
$dpiStruct['dpiNumber'],
> //
$this->_stringTable);
> //
> // // Now the real fun begins.
> // // from Sections 5.2 and 5.8
> //
> // // Default content handler.
> // $this->_ch = &new XML_WBXML_ContentHandler();
> //
> // // Default content handler.
> // $this->_dtdManager = &new XML_WBXML_DTDManager();
> //
> // // Get the starting DTD.
> // $this->_tagDTD = $this->_dtdManager->getInstance($this->_dpi);
> // if (!$this->_tagDTD) {
> // return $this->raiseError('No DTD found for ' .
$this->_dpi);
> // }
> //
> // $this->_attributeDTD = $this->_tagDTD;
> //
> // while ($this->_strpos < strlen($input)) {
> // $this->_decode($input);
> // }
> //
> // return $this->_ch->getOutput();
>
> return file_get_contents($tmp_file . '.xml');
More information about the sync
mailing list