[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/XML/ -> WBXML.php (source)

   1  <?php
   2  
   3  /**
   4   * Constants are from Binary XML Content Format Specification Version
   5   * 1.3, 25 July 2001 found at http://www.wapforum.org
   6   */
   7  
   8  /**
   9   * From 7.1 Global Tokens.
  10   */
  11  
  12  define('XML_WBXML_GLOBAL_TOKEN_SWITCH_PAGE', 0);  // 0x00
  13  define('XML_WBXML_GLOBAL_TOKEN_END', 1);          // 0x01
  14  define('XML_WBXML_GLOBAL_TOKEN_ENTITY', 2);       // 0x02
  15  define('XML_WBXML_GLOBAL_TOKEN_STR_I', 3);        // 0x03
  16  define('XML_WBXML_GLOBAL_TOKEN_LITERAL', 4);      // 0x04
  17  
  18  define('XML_WBXML_GLOBAL_TOKEN_EXT_I_0', 64);     // 0x40
  19  define('XML_WBXML_GLOBAL_TOKEN_EXT_I_1', 65);     // 0x41
  20  define('XML_WBXML_GLOBAL_TOKEN_EXT_I_2', 66);     // 0x42
  21  define('XML_WBXML_GLOBAL_TOKEN_PI', 67);          // 0x43
  22  define('XML_WBXML_GLOBAL_TOKEN_LITERAL_C', 68);   // 0x44
  23  
  24  define('XML_WBXML_GLOBAL_TOKEN_EXT_T_0', 128);    // 0x80
  25  define('XML_WBXML_GLOBAL_TOKEN_EXT_T_1', 129);    // 0x81
  26  define('XML_WBXML_GLOBAL_TOKEN_EXT_T_2', 130);    // 0x82
  27  define('XML_WBXML_GLOBAL_TOKEN_STR_T', 131);      // 0x83
  28  define('XML_WBXML_GLOBAL_TOKEN_LITERAL_A', 132);  // 0x84
  29  
  30  define('XML_WBXML_GLOBAL_TOKEN_EXT_0', 192);      // 0xC0
  31  define('XML_WBXML_GLOBAL_TOKEN_EXT_1', 193);      // 0xC1
  32  define('XML_WBXML_GLOBAL_TOKEN_EXT_2', 194);      // 0xC2
  33  define('XML_WBXML_GLOBAL_TOKEN_OPAQUE', 195);     // 0xC3
  34  define('XML_WBXML_GLOBAL_TOKEN_LITERAL_AC', 196); // 0xC4
  35  
  36  /**
  37   * Not sure where defined.
  38   * ADD CHAPTER
  39   */
  40  define('DPI_DTD_WML_1_0', '-//WAPFORUM//DTD WML 1.0//EN');
  41  define('DPI_DTD_WTA_1_0', '-//WAPFORUM//DTD WTA 1.0//EN');
  42  define('DPI_DTD_WML_1_1', '-//WAPFORUM//DTD WML 1.1//EN');
  43  define('DPI_DTD_SI_1_1', '-//WAPFORUM//DTD SI 1.1//EN');
  44  define('DPI_DTD_SL_1_0', '-//WAPFORUM//DTD SL 1.0//EN');
  45  define('DPI_DTD_CO_1_0', '-//WAPFORUM//DTD CO 1.0//EN');
  46  define('DPI_DTD_CHANNEL_1_1', '-//WAPFORUM//DTD CHANNEL 1.1//EN');
  47  define('DPI_DTD_WML_1_2', '-//WAPFORUM//DTD WML 1.2//EN');
  48  define('DPI_DTD_WML_1_3', '-//WAPFORUM//DTD WML 1.3//EN');
  49  define('DPI_DTD_PROV_1_0', '-//WAPFORUM//DTD PROV 1.0//EN');
  50  define('DPI_DTD_WTA_WML_1_2', '-//WAPFORUM//DTD WTA-WML 1.2//EN');
  51  define('DPI_DTD_CHANNEL_1_2', '-//WAPFORUM//DTD CHANNEL 1.2//EN');
  52  define('DPI_DTD_SYNCML_1_0', '-//SYNCML//DTD SyncML 1.0//EN');
  53  define('DPI_DTD_DEVINF_1_0', '-//SYNCML//DTD DevInf 1.0//EN');
  54  define('DPI_DTD_SYNCML_1_1', '-//SYNCML//DTD SyncML 1.1//EN');
  55  define('DPI_DTD_DEVINF_1_1', '-//SYNCML//DTD DevInf 1.1//EN');
  56  
  57  /**
  58   * Only default character encodings from J2SE are currently supported.
  59   */
  60  define('CHARSET_US_ASCII', 'US-ASCII');
  61  define('CHARSET_ISO_8859_1', 'ISO-8859-1');
  62  define('CHARSET_UTF_8', 'UTF-8');
  63  define('CHARSET_UTF_16BE', 'UTF-16BE');
  64  define('CHARSET_UTF_16LE', 'UTF-16LE');
  65  define('CHARSET_UTF_16', 'UTF-16');
  66  
  67  /**
  68   * Copyright 2003-2006 Anthony Mills <amills@pyramid6.com>
  69   *
  70   * See the enclosed file COPYING for license information (LGPL).  If you
  71   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  72   *
  73   * $Horde: framework/XML_WBXML/WBXML.php,v 1.13.12.8 2006/03/13 09:16:25 jan Exp $
  74   *
  75   * @package XML_WBXML
  76   */
  77  class XML_WBXML {
  78  
  79      /**
  80       * Decoding Multi-byte Integers from Section 5.1
  81       *
  82       * Use long because it is unsigned.
  83       */
  84      function MBUInt32ToInt($in, &$pos)
  85      {
  86          $val = 0;
  87  
  88          do {
  89              $b = ord($in[$pos++]);
  90              $val <<= 7; // Bitshift left 7 bits.
  91              $val += ($b & 127);
  92          } while (($b & 128) != 0);
  93  
  94          return $val;
  95      }
  96  
  97      /**
  98       * Encoding Multi-byte Integers from Section 5.1
  99       */
 100      function intToMBUInt32(&$out, $i)
 101      {
 102          if ($i > 268435455) {
 103              $bytes0 = 0 | XML_WBXML::getBits(0, $i);
 104              $bytes1 = 128 | XML_WBXML::getBits(1, $i);
 105              $bytes2 = 128 | XML_WBXML::getBits(2, $i);
 106              $bytes3 = 128 | XML_WBXML::getBits(3, $i);
 107              $bytes4 = 128 | XML_WBXML::getBits(4, $i);
 108  
 109              $out .= chr($bytes4) . chr($bytes3) . chr($bytes2) . chr($bytes1) . chr($bytes0);
 110          } elseif ($i > 2097151) {
 111              $bytes0 = 0 | XML_WBXML::getBits(0, $i);
 112              $bytes1 = 128 | XML_WBXML::getBits(1, $i);
 113              $bytes2 = 128 | XML_WBXML::getBits(2, $i);
 114              $bytes3 = 128 | XML_WBXML::getBits(3, $i);
 115  
 116              $out .= chr($bytes3) . chr($bytes2) . chr($bytes1) . chr($bytes0);
 117          } elseif ($i > 16383) {
 118              $bytes0 = 0 | XML_WBXML::getBits(0, $i);
 119              $bytes1 = 128 | XML_WBXML::getBits(1, $i);
 120              $bytes2 = 128 | XML_WBXML::getBits(2, $i);
 121  
 122              $out .= chr($bytes2) . chr($bytes1) . chr($bytes0);
 123          } elseif ($i > 127) {
 124              $bytes0 = 0 | XML_WBXML::getBits(0, $i);
 125              $bytes1 = 128 | XML_WBXML::getBits(1, $i);
 126  
 127              $out .= chr($bytes1) . chr($bytes0);
 128          } else {
 129              $bytes0 = 0 | XML_WBXML::getBits(0, $i);
 130  
 131              $out .= chr($bytes0);
 132          }
 133      }
 134  
 135      function getBits($num, $l)
 136      {
 137          switch ($num) {
 138          case 0:
 139              return $l & 127; // 0x7F
 140  
 141          case 1:
 142              return ($l >> 7) & 127; // 0x7F
 143  
 144          case 2:
 145              return ($l >> 14) & 127; // 0x7F
 146  
 147          case 3:
 148              return ($l >> 21) & 127; // 0x7F
 149  
 150          case 4:
 151              return ($l >> 28) & 127; // 0x7F
 152          }
 153  
 154          return 0;
 155      }
 156  
 157      function getDPIString($i)
 158      {
 159          /**
 160           * ADD CHAPTER
 161           */
 162          $DPIString = array(2 => DPI_DTD_WML_1_0,
 163                             3 => DPI_DTD_WTA_1_0,
 164                             4 => DPI_DTD_WML_1_1,
 165                             5 => DPI_DTD_SI_1_1,
 166                             6 => DPI_DTD_SL_1_0,
 167                             7 => DPI_DTD_CO_1_0,
 168                             8 => DPI_DTD_CHANNEL_1_1,
 169                             9 => DPI_DTD_WML_1_2,
 170                             10 => DPI_DTD_WML_1_3,
 171                             11 => DPI_DTD_PROV_1_0,
 172                             12 => DPI_DTD_WTA_WML_1_2,
 173                             13 => DPI_DTD_CHANNEL_1_2,
 174  
 175                             // Not all SyncML clients know this, so we
 176                             // should use the string table.
 177                             // 0xFD1 => DPI_DTD_SYNCML_1_1,
 178                             4049 => DPI_DTD_SYNCML_1_0,
 179                             4050 => DPI_DTD_DEVINF_1_0,
 180                             4051 => DPI_DTD_SYNCML_1_1,
 181                             4052 => DPI_DTD_DEVINF_1_1,
 182                             );
 183          return isset($DPIString[$i]) ? $DPIString[$i] : null;
 184      }
 185  
 186      function getDPIInt($dpi)
 187      {
 188          /**
 189           * ADD CHAPTER
 190           */
 191          $DPIInt = array(DPI_DTD_WML_1_0 => 2,
 192                          DPI_DTD_WTA_1_0 => 3,
 193                          DPI_DTD_WML_1_1 => 4,
 194                          DPI_DTD_SI_1_1 => 5,
 195                          DPI_DTD_SL_1_0 => 6,
 196                          DPI_DTD_CO_1_0 => 7,
 197                          DPI_DTD_CHANNEL_1_1 => 8,
 198                          DPI_DTD_WML_1_2 => 9,
 199                          DPI_DTD_WML_1_3 => 10,
 200                          DPI_DTD_PROV_1_0 => 11,
 201                          DPI_DTD_WTA_WML_1_2 => 12,
 202                          DPI_DTD_CHANNEL_1_2 => 13,
 203  
 204                          // Not all SyncML clients know this, so maybe we
 205                          // should use the string table.
 206                          DPI_DTD_SYNCML_1_0 => 4049,
 207                          DPI_DTD_DEVINF_1_0 => 4050,
 208                          DPI_DTD_SYNCML_1_1 => 4051,
 209                          DPI_DTD_DEVINF_1_1 => 4052
 210                          // DPI_DTD_SYNCML_1_1 => 0xFD1,
 211                          // DPI_DTD_DEVINF_1_1 => 0xFD2,
 212                          );
 213  
 214          return isset($DPIInt[$dpi]) ? $DPIInt[$dpi] : 0;
 215      }
 216  
 217      /**
 218       * Returns the character encoding.
 219       * only default character encodings from J2SE are supported
 220       * from http://www.iana.org/assignments/character-sets
 221       * and http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html
 222       */
 223      function getCharsetString($cs)
 224      {
 225          /**
 226           * From http://www.iana.org/assignments/character-sets
 227           */
 228          $charsetString = array(3 => 'US-ASCII',
 229                                 4 => 'ISO-8859-1',
 230                                 106 => 'UTF-8',
 231                                 1013 => 'UTF-16BE',
 232                                 1014 => 'UTF-16LE',
 233                                 1015 => 'UTF-16');
 234  
 235          return isset($charsetString[$cs]) ? $charsetString[$cs] : null;
 236      }
 237  
 238      /**
 239       * Returns the character encoding.
 240       *
 241       * Only default character encodings from J2SE are supported.
 242       *
 243       * From http://www.iana.org/assignments/character-sets and
 244       * http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html
 245       */
 246      function getCharsetInt($cs)
 247      {
 248          /**
 249           * From http://www.iana.org/assignments/character-sets
 250           */
 251          $charsetInt = array('US-ASCII' => 3,
 252                              'ISO-8859-1' => 4,
 253                              'UTF-8' => 106,
 254                              'UTF-16BE' => 1013,
 255                              'UTF-16LE' => 1014,
 256                              'UTF-16' => 1015);
 257  
 258          return isset($charsetInt[$cs]) ? $charsetInt[$cs] : null;
 259      }
 260  
 261  }
 262  
 263  /**
 264   * @package XML_WBXML
 265   */
 266  class XML_WBXML_HashTable {
 267  
 268      var $_h;
 269  
 270      function set($k, $v)
 271      {
 272          $this->_h[$k] = $v;
 273      }
 274  
 275      function get($k)
 276      {
 277          return isset($this->_h[$k]) ? $this->_h[$k] : null;
 278      }
 279  
 280  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7