1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
<?php
require_once 'SyncML/Command.php';
/**
* The SyncML_Command_Put class provides a SyncML implementation of the Put
* command as defined in SyncML Representation Protocol, version 1.1, section
* 5.5.10.
*
* The Put command is used to transfer data items to a recipient network
* device or database. The SyncML_Command_Put class handles DevInf device
* information sent by the client.
*
* The data is stored in a SyncML_DeviceInfo object which is defined in
* Device.php and then stored in SyncML_Device as an attribute.
*
* $Horde: framework/SyncML/SyncML/Command/Put.php,v 1.12.10.15 2009/10/01 09:21:07 jan Exp $
*
* Copyright 2005-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Karsten Fourmont <karsten@horde.org>
* @author Jan Schneider <jan@horde.org>
* @since Horde 3.0
* @package SyncML
*/
class SyncML_Command_Put extends SyncML_Command {
/**
* Name of the command.
*
* @var string
*/
var $_cmdName = 'Put';
/**
* The SyncML_DeviceInfo object where all parsed <DevInf> content is
* saved.
*
* <DevInf> specifies the type of the source synchronization device.
*
* @var SyncML_DeviceInfo
*/
var $_devinf;
/**
* A SyncML_DataStore object where the information from the currently
* parsed <DataStore> section is saved.
*
* <DataStore> specifies the properties of a given local datastore.
*
* @var SyncML_DataStore
*/
var $_currentDS;
/**
* The MIME content type as specified by the last <CTType> element like
* text/calendar or text/x-vcard.
*
* <CTType> specifies the type of a supported content type.
*
* @var string
*/
var $_currentCTType;
/**
* The version of the MIME content type in $_currentCTType as specified by
* the last <VerCT> element like 1.0 for text/x-vcalendar or 2.1 for
* text/x-vcard.
*
* <VerCT> specifies the version of a supported content type.
*
* @var string
*/
var $_VerCT;
/**
* A property name of the currently parsed content type (CTType), like
* 'DTSTART' for text/calendar or 'BDAY' for text/x-vcard.
*
* <PropName> specifies a supported property of a given content type.
*
* @var string
*/
var $_currentPropName;
/**
* A property name of the currently parsed property name (PropName), like
* 'ROLE' for 'ATTENDEE' or 'HOME' for 'ADR'.
*
* <ParamName> specifies supported parameters of a given content type
* property.
*
* @var string
*/
var $_currentParamName;
/**
* The name of the currently parsed DevInf extension (<Ext>) as specified
* by the XNam element.
*
* <XNam> specifies the name of one of the DevInf extension element types.
*
* @var string
*/
var $_currentXNam;
/**
* Start element handler for the XML parser, delegated from
* SyncML_ContentHandler::startElement().
*
* @param string $uri The namespace URI of the element.
* @param string $element The element tag name.
* @param array $attrs A hash with the element's attributes.
*/
function startElement($uri, $element, $attrs)
{
parent::startElement($uri, $element, $attrs);
switch (count($this->_stack)) {
case 1:
$this->_devinf = new SyncML_DeviceInfo();
break;
case 5:
if ($element == 'DataStore') {
$this->_currentDS = new SyncML_DataStore();
}
break;
}
}
/**
* End element handler for the XML parser, delegated from
* SyncML_ContentHandler::endElement().
*
* @param string $uri The namespace URI of the element.
* @param string $element The element tag name.
*/
function endElement($uri, $element)
{
switch ($element) {
case 'VerDTD':
case 'Man':
case 'Mod':
case 'OEM':
case 'FwV':
case 'SwV':
case 'HwV':
case 'DevID':
case 'DevTyp':
$this->_devinf->$element = trim($this->_chars);
break;
case 'UTC':
case 'SupportLargeObjs':
case 'SupportNumberOfChanges':
$this->_devinf->$element = true;
break;
case 'DataStore':
$this->_devinf->DataStores[] = $this->_currentDS;
break;
case 'CTCap':
case 'Ext':
// Automatically handled by subelements.
break;
case 'SourceRef':
case 'DisplayName':
case 'MaxGUIDSize':
$this->_currentDS->$element = trim($this->_chars);
break;
case 'Rx-Pref':
case 'Rx':
case 'Tx-Pref':
case 'Tx':
$property = str_replace('-', '_', $element);
$this->_currentDS->{$property}[$this->_currentCTType] = $this->_VerCT;
break;
case 'DSMem':
// Currently ignored, to be done.
break;
case 'SyncCap':
// Automatically handled by SyncType subelement.
break;
case 'CTType':
$this->_currentCTType = trim($this->_chars);
break;
case 'PropName':
$this->_currentPropName = trim($this->_chars);
// Reset param state.
unset($this->_currentParamName);
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName] = new SyncML_Property();
break;
case 'ParamName':
$this->_currentParamName = trim($this->_chars);
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName]->Params[$this->_currentParamName] = new SyncML_PropertyParameter();
break;
case 'ValEnum':
if (!empty($this->_currentParamName)) {
// We're in parameter mode.
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName]->Params[$this->_currentParamName]->ValEnum[trim($this->_chars)] = true;
} else {
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName]->ValEnum[trim($this->_chars)] = true;
}
break;
case 'DataType':
case 'Size':
case 'DisplayName':
if (!empty($this->_currentParamName)) {
// We're in parameter mode.
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName]->Params[$this->_currentParamName]->{'_' . $element} = trim($this->_chars);
} else {
$this->_devinf->CTCaps[$this->_currentCTType][$this->_currentPropName]->{'_' . $element} = trim($this->_chars);
}
break;
case 'XNam':
$this->_currentXNam = trim($this->_chars);
break;
case 'XVal':
$this->_devinf->Exts[$this->_currentXNam][] = trim($this->_chars);
break;
case 'VerCT':
$this->_VerCT = trim($this->_chars);
break;
case 'SyncType':
$this->_currentDS->SyncCap[trim($this->_chars)] = true;
break;
}
parent::endElement($uri, $element);
}
/**
* Implements the actual business logic of the Alert command.
*/
function handleCommand($debug = false)
{
$state = &$_SESSION['SyncML.state'];
// Store received data.
$state->deviceInfo = $this->_devinf;
// Log DevInf object.
$GLOBALS['backend']->logFile(SYNCML_LOGFILE_DEVINF,
var_export($this->_devinf, true));
// Create status response.
$this->_outputHandler->outputStatus($this->_cmdID, $this->_cmdName,
RESPONSE_OK, '',
$state->getDevInfURI());
}
}
|