Пример #1
0
require_once 'inc/class.xml_offset_mapper.inc.php';
require_once 'inc/class.syncml_wbxml_parser.inc.php';
require_once 'inc/class.syncml_wbxml_response.inc.php';
require_once 'inc/class.syncml_response.inc.php';
require_once 'inc/class.syncml_message.inc.php';
$file_date = gettimeofday(true);
// this is a ugly, ugly hack
//$GLOBALS['phpgw']->db->query('TRUNCATE phpgw_access_log');
if (!isset($_SERVER['CONTENT_TYPE']) || $_SERVER['REQUEST_METHOD'] != 'POST') {
    exit('I\'m a SyncML server (1)');
}
$post_input = implode("\r\n", file('php://input'));
file_put_contents('/tmp/' . $file_date . '-a.xml', $post_input);
switch ($_SERVER['CONTENT_TYPE']) {
    case 'application/vnd.syncml+wbxml':
        $post_input = wbxml_decode($post_input);
    case 'application/vnd.syncml+xml':
        $parser = new xml_parser();
        $response = new syncml_response();
        break;
    default:
        exit('I\'m a SyncML server (2)');
}
$message = new syncml_message();
// the header
$header = $parser->parse($post_input, new xml_offset_mapper(array('SYNCML', 'SYNCHDR')));
$message->process_header($header);
unset($header);
// the body
$body = $parser->parse($post_input, new xml_offset_mapper(array('SYNCML', 'SYNCBODY')));
$message->process_body($body);
 /**
  * Decode from type to XML array.
  *
  * @param $data        Data to decode.
  * @param $type        Type of input data.
  * @param $dtd_version 
  * @return string Decoded data in XML array format.
  */
 function _decode($data, $type)
 {
     switch ($type) {
         case 'application/vnd.syncml-devinf+wbxml':
             $parser = new wbxml_parser();
             return $parser->parse(wbxml_decode($data), new xml_mapper());
         case 'application/vnd.syncml-devinf+xml':
             return $data;
         default:
             return NULL;
     }
 }