[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once 'SyncML/Command.php'; 4 5 /** 6 * The SyncML_Command_Get class. 7 * 8 * This class responds to a client get request and returns the DevInf 9 * information for the SyncML server. 10 * 11 * $Horde: framework/SyncML/SyncML/Command/Get.php,v 1.14.10.10 2006/05/29 16:40:37 jan Exp $ 12 * 13 * Copyright 2003-2006 Anthony Mills <amills@pyramid6.com> 14 * 15 * See the enclosed file COPYING for license information (LGPL). If you 16 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 17 * 18 * @author Karsten Fourmont <fourmont@gmx.de> 19 * @author Anthony Mills <amills@pyramid6.com> 20 * @since Horde 3.0 21 * @package SyncML 22 */ 23 class SyncML_Command_Get extends SyncML_Command { 24 25 function output($currentCmdID, &$output) 26 { 27 $state = &$_SESSION['SyncML.state']; 28 29 $ref = ($state->getVersion() == 0) ? './devinf10' : './devinf11'; 30 31 $status = &new SyncML_Command_Status(($state->isAuthorized() ? RESPONSE_OK : RESPONSE_INVALID_CREDENTIALS), 'Get'); 32 $status->setCmdRef($this->_cmdID); 33 $status->setTargetRef($ref); 34 $currentCmdID = $status->output($currentCmdID, $output); 35 36 if ($state->isAuthorized()) { 37 $attrs = array(); 38 $output->startElement($state->getURI(), 'Results', $attrs); 39 40 $output->startElement($state->getURI(), 'CmdID', $attrs); 41 $chars = $currentCmdID; 42 $output->characters($chars); 43 $output->endElement($state->getURI(), 'CmdID'); 44 45 $output->startElement($state->getURI(), 'MsgRef', $attrs); 46 $chars = $state->getMsgID(); 47 $output->characters($chars); 48 $output->endElement($state->getURI(), 'MsgRef'); 49 50 $output->startElement($state->getURI(), 'CmdRef', $attrs); 51 $chars = $this->_cmdID; 52 $output->characters($chars); 53 $output->endElement($state->getURI(), 'CmdRef'); 54 55 $output->startElement($state->getURI(), 'Meta', $attrs); 56 $output->startElement($state->getURIMeta(), 'Type', $attrs); 57 if (is_a($output, 'XML_WBXML_Encoder')) { 58 $output->characters(MIME_SYNCML_DEVICE_INFO_WBXML); 59 } else { 60 $output->characters(MIME_SYNCML_DEVICE_INFO_XML); 61 } 62 63 $output->endElement($state->getURIMeta(), 'Type'); 64 $output->endElement($state->getURI(), 'Meta'); 65 66 $output->startElement($state->getURI(), 'Item', $attrs); 67 $output->startElement($state->getURI(), 'Source', $attrs); 68 $output->startElement($state->getURI(), 'LocURI', $attrs); 69 $output->characters($ref); 70 $output->endElement($state->getURI(), 'LocURI'); 71 $output->endElement($state->getURI(), 'Source'); 72 73 $output->startElement($state->getURI(), 'Data', $attrs); 74 75 /* DevInf data is stored in wbxml not as a seperate codepage but 76 * rather as a complete wbxml stream as opaque data. So we need a 77 * new Handler. */ 78 $devinfoutput = $output->createSubHandler(); 79 80 $devinfoutput->startElement($state->getURIDevInf() , 'DevInf', $attrs); 81 $devinfoutput->startElement($state->getURIDevInf() , 'VerDTD', $attrs); 82 $devinfoutput->characters(($state->getVersion() == 0) ? '1.0' : '1.1'); 83 $devinfoutput->endElement($state->getURIDevInf() , 'VerDTD', $attrs); 84 $devinfoutput->startElement($state->getURIDevInf() , 'Man', $attrs); 85 $devinfoutput->characters('The Horde Project (http://www.horde.org)'); 86 $devinfoutput->endElement($state->getURIDevInf() , 'Man', $attrs); 87 $devinfoutput->startElement($state->getURIDevInf() , 'DevID', $attrs); 88 $devinfoutput->characters($_SERVER['HTTP_HOST']); 89 $devinfoutput->endElement($state->getURIDevInf() , 'DevID', $attrs); 90 $devinfoutput->startElement($state->getURIDevInf() , 'DevTyp', $attrs); 91 $devinfoutput->characters('server'); 92 $devinfoutput->endElement($state->getURIDevInf() , 'DevTyp', $attrs); 93 $this->_writeDataStore('notes', 'text/x-vnote', '1.1', $devinfoutput, 94 array('text/plain' => '1.0')); 95 $this->_writeDataStore('contacts', 'text/x-vcard', '3.0', $devinfoutput, 96 array('text/x-vcard' => '2.1')); 97 $this->_writeDataStore('tasks', 'text/calendar', '2.0', $devinfoutput, 98 array('text/x-vcalendar' => '1.0')); 99 $this->_writeDataStore('calendar', 'text/calendar', '2.0', $devinfoutput, 100 array('text/x-vcalendar' => '1.0')); 101 $devinfoutput->endElement($state->getURIDevInf() , 'DevInf', $attrs); 102 103 $output->opaque($devinfoutput->getOutput()); 104 $output->endElement($state->getURI(), 'Data'); 105 $output->endElement($state->getURI(), 'Item'); 106 $output->endElement($state->getURI(), 'Results'); 107 108 $currentCmdID++; 109 } 110 111 return $currentCmdID; 112 } 113 114 /** 115 * Writes DevInf data for one DataStore. 116 * 117 * @param string $sourceref: data for SourceRef element. 118 * @param string $mimetype: data for <(R|T)x-Pref><CTType> 119 * @param string $version: data for <(R|T)x-Pref><VerCT> 120 * @param string &$output contenthandler that will received the output. 121 * @param array $additionaltypes: array of additional types for Tx and Rx; 122 * format array('text/vcard' => '2.0') 123 */ 124 function _writeDataStore($sourceref, $mimetype, $version, &$output, 125 $additionaltypes = false) 126 { 127 $attrs = array(); 128 129 $state = &$_SESSION['SyncML.state']; 130 131 $output->startElement($state->getURIDevInf() , 'DataStore', $attrs); 132 $output->startElement($state->getURIDevInf() , 'SourceRef', $attrs); 133 $output->characters($sourceref); 134 $output->endElement($state->getURIDevInf() , 'SourceRef', $attrs); 135 136 $output->startElement($state->getURIDevInf() , 'Rx-Pref', $attrs); 137 $output->startElement($state->getURIDevInf() , 'CTType', $attrs); 138 $output->characters($mimetype); 139 $output->endElement($state->getURIDevInf() , 'CTType', $attrs); 140 $output->startElement($state->getURIDevInf() , 'VerCT', $attrs); 141 $output->characters($version); 142 $output->endElement($state->getURIDevInf() , 'VerCT', $attrs); 143 $output->endElement($state->getURIDevInf() , 'Rx-Pref', $attrs); 144 145 if (is_array($additionaltypes)) { 146 foreach ($additionaltypes as $ct => $ctver){ 147 $output->startElement($state->getURIDevInf() , 'Rx', $attrs); 148 $output->startElement($state->getURIDevInf() , 'CTType', $attrs); 149 $output->characters($ct); 150 $output->endElement($state->getURIDevInf() , 'CTType', $attrs); 151 $output->startElement($state->getURIDevInf() , 'VerCT', $attrs); 152 $output->characters($ctver); 153 $output->endElement($state->getURIDevInf() , 'VerCT', $attrs); 154 $output->endElement($state->getURIDevInf() , 'Rx', $attrs); 155 } 156 } 157 158 $output->startElement($state->getURIDevInf() , 'Tx-Pref', $attrs); 159 $output->startElement($state->getURIDevInf() , 'CTType', $attrs); 160 $output->characters($mimetype); 161 $output->endElement($state->getURIDevInf() , 'CTType', $attrs); 162 $output->startElement($state->getURIDevInf() , 'VerCT', $attrs); 163 $output->characters($version); 164 $output->endElement($state->getURIDevInf() , 'VerCT', $attrs); 165 $output->endElement($state->getURIDevInf() , 'Tx-Pref', $attrs); 166 167 if (is_array($additionaltypes)) { 168 foreach ($additionaltypes as $ct => $ctver){ 169 $output->startElement($state->getURIDevInf() , 'Tx', $attrs); 170 $output->startElement($state->getURIDevInf() , 'CTType', $attrs); 171 $output->characters($ct); 172 $output->endElement($state->getURIDevInf() , 'CTType', $attrs); 173 $output->startElement($state->getURIDevInf() , 'VerCT', $attrs); 174 $output->characters($ctver); 175 $output->endElement($state->getURIDevInf() , 'VerCT', $attrs); 176 $output->endElement($state->getURIDevInf() , 'Tx', $attrs); 177 } 178 } 179 180 $output->startElement($state->getURIDevInf() , 'SyncCap', $attrs); 181 $output->startElement($state->getURIDevInf() , 'SyncType', $attrs); 182 $output->characters('1'); 183 $output->endElement($state->getURIDevInf() , 'SyncType', $attrs); 184 $output->startElement($state->getURIDevInf() , 'SyncType', $attrs); 185 $output->characters('2'); 186 $output->endElement($state->getURIDevInf() , 'SyncType', $attrs); 187 $output->endElement($state->getURIDevInf() , 'SyncCap', $attrs); 188 $output->endElement($state->getURIDevInf() , 'DataStore', $attrs); 189 } 190 191 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |