[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 include_once 'Horde/SyncML/State.php'; 4 include_once 'Horde/SyncML/Command.php'; 5 6 /** 7 * The Horde_SyncML_Alert class provides a SyncML implementation of 8 * the Alert command as defined in SyncML Representation Protocol, 9 * version 1.1 5.5.2. 10 * 11 * $Horde: framework/SyncML/SyncML/Command/Alert.php,v 1.18 2004/07/03 15:21:14 chuck Exp $ 12 * 13 * Copyright 2003-2004 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 Anthony Mills <amills@pyramid6.com> 19 * @version $Revision: 21249 $ 20 * @since Horde 3.0 21 * @package Horde_SyncML 22 */ 23 class Horde_SyncML_Command_Alert extends Horde_SyncML_Command { 24 25 /** 26 * @var integer $_alert 27 */ 28 var $_alert; 29 30 /** 31 * @var string $_sourceURI 32 */ 33 var $_sourceLocURI; 34 35 /** 36 * @var string $_targetURI 37 */ 38 var $_targetLocURI; 39 40 /** 41 * @var string $_metaAnchorNext 42 */ 43 var $_metaAnchorNext; 44 45 /** 46 * @var integer $_metaAnchorLast 47 */ 48 var $_metaAnchorLast; 49 50 /** 51 * Use in xml tag. 52 */ 53 var $_isInSource; 54 55 /** 56 * Creates a new instance of Alert. 57 */ 58 function Horde_SyncML_Command_Alert($alert = null) 59 { 60 if ($alert != null) { 61 $this->_alert = $alert; 62 } 63 } 64 65 function output($currentCmdID, &$output) 66 { 67 $attrs = array(); 68 69 $state = &$_SESSION['SyncML.state']; 70 71 // Handle unauthorized first. 72 if (!$state->isAuthorized()) { 73 $status = &new Horde_SyncML_Command_Status(RESPONSE_INVALID_CREDENTIALS, 'Alert'); 74 $status->setCmdRef($this->_cmdID); 75 $currentCmdID = $status->output($currentCmdID, $output); 76 return $currentCmdID; 77 } 78 79 80 81 if($this->_alert < ALERT_RESULT_ALERT) 82 { 83 84 $type = $this->_targetLocURI; 85 86 // Store client's Next Anchor in State. After successful sync 87 // this is then written to persistence for negotiation of 88 // further syncs. 89 $state->setClientAnchorNext($type, $this->_metaAnchorNext); 90 91 $info = $state->getSyncSummary($this->_targetLocURI); 92 #Horde::logMessage("SyncML: Anchor match, TwoWaySync sinceee " . $clientlast, __FILE__, __LINE__, PEAR_LOG_DEBUG); 93 if (is_a($info, 'DataTreeObject')) { 94 $x = $info->get('ClientAnchor'); 95 $clientlast = $x[$type]; 96 $x = $info->get('ServerAnchor'); 97 $state->setServerAnchorLast($type, $x[$type]); 98 } elseif (is_array($info)) { 99 $clientlast = $info['ClientAnchor']; 100 $state->setServerAnchorLast($type, $info['ServerAnchor']); 101 } else { 102 $clientlast = 0; 103 $state->setServerAnchorLast($type, 0); 104 } 105 106 // Set Server Anchor for this sync to current time. 107 $state->setServerAnchorNext($type,time()); 108 if ($clientlast && $clientlast == $this->_metaAnchorLast) { 109 // Last Sync Anchor matches, TwoWaySync will do. 110 $code = RESPONSE_OK; 111 Horde::logMessage("SyncML: Anchor match, TwoWaySync since " . $clientlast, __FILE__, __LINE__, PEAR_LOG_DEBUG); 112 } else { 113 Horde::logMessage("SyncML: Anchor mismatch, enforcing SlowSync clientlast $clientlast serverlast ".$this->_metaAnchorLast, __FILE__, __LINE__, PEAR_LOG_DEBUG); 114 // Mismatch, enforce slow sync. 115 $this->_alert = 201; 116 $code = 508; 117 // create new synctype 118 $sync = &Horde_SyncML_Sync::factory($this->_alert); 119 $sync->_targetLocURI = $this->_targetLocURI; 120 $sync->_sourceLocURI = $this->_sourceLocURI; 121 if(isset($this->_targetLocURIParameters)) 122 $sync->_targetLocURIParameters = $this->_targetLocURIParameters; 123 $state->setSync($this->_targetLocURI, $sync); 124 } 125 126 $status = &new Horde_SyncML_Command_Status($code, 'Alert'); 127 $status->setCmdRef($this->_cmdID); 128 if ($this->_sourceLocURI != null) { 129 $status->setSourceRef($this->_sourceLocURI); 130 } 131 if ($this->_targetLocURI != null) { 132 $status->setTargetRef((isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI)); 133 } 134 135 // Mirror Next Anchor from client back to client. 136 if (isset($this->_metaAnchorNext)) { 137 $status->setItemDataAnchorNext($this->_metaAnchorNext); 138 } 139 140 // Mirror Last Anchor from client back to client. 141 if (isset($this->_metaAnchorLast)) { 142 $status->setItemDataAnchorLast($this->_metaAnchorLast); 143 } 144 145 $currentCmdID = $status->output($currentCmdID, $output); 146 147 if ($state->isAuthorized()) { 148 $output->startElement($state->getURI(), 'Alert', $attrs); 149 150 $output->startElement($state->getURI(), 'CmdID', $attrs); 151 $chars = $currentCmdID; 152 $output->characters($chars); 153 $output->endElement($state->getURI(), 'CmdID'); 154 155 $output->startElement($state->getURI(), 'Data', $attrs); 156 $chars = $this->_alert; 157 $output->characters($chars); 158 $output->endElement($state->getURI(), 'Data'); 159 160 $output->startElement($state->getURI(), 'Item', $attrs); 161 162 if ($this->_sourceLocURI != null) { 163 $output->startElement($state->getURI(), 'Target', $attrs); 164 $output->startElement($state->getURI(), 'LocURI', $attrs); 165 $chars = $this->_sourceLocURI; 166 $output->characters($chars); 167 $output->endElement($state->getURI(), 'LocURI'); 168 $output->endElement($state->getURI(), 'Target'); 169 } 170 171 if ($this->_targetLocURI != null) { 172 $output->startElement($state->getURI(), 'Source', $attrs); 173 $output->startElement($state->getURI(), 'LocURI', $attrs); 174 $chars = (isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI); 175 $output->characters($chars); 176 $output->endElement($state->getURI(), 'LocURI'); 177 $output->endElement($state->getURI(), 'Source'); 178 } 179 180 $output->startElement($state->getURI(), 'Meta', $attrs); 181 182 $output->startElement($state->getURIMeta(), 'Anchor', $attrs); 183 184 $output->startElement($state->getURIMeta(), 'Last', $attrs); 185 $chars = $state->getServerAnchorLast($type); 186 $output->characters($chars); 187 $output->endElement($state->getURIMeta(), 'Last'); 188 189 $output->startElement($state->getURIMeta(), 'Next', $attrs); 190 $chars = $state->getServerAnchorNext($type); 191 $output->characters($chars); 192 $output->endElement($state->getURIMeta(), 'Next'); 193 194 $output->endElement($state->getURIMeta(), 'Anchor'); 195 $output->endElement($state->getURI(), 'Meta'); 196 $output->endElement($state->getURI(), 'Item'); 197 $output->endElement($state->getURI(), 'Alert'); 198 199 $state->_sendFinal = true; 200 201 $currentCmdID++; 202 } 203 } elseif ($this->_alert == ALERT_NEXT_MESSAGE) { 204 $status = &new Horde_SyncML_Command_Status(RESPONSE_OK, 'Alert'); 205 $status->setCmdRef($this->_cmdID); 206 if ($this->_targetLocURI != null) { 207 $status->setTargetRef((isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI)); 208 } 209 if ($this->_sourceLocURI != null) { 210 $status->setSourceRef($this->_sourceLocURI); 211 } 212 $status->setItemSourceLocURI($this->_sourceLocURI); 213 $status->setItemTargetLocURI(isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI); 214 $currentCmdID = $status->output($currentCmdID, $output); 215 216 $state->setAlert222Received(true); 217 218 #if($state->getSyncStatus() > CLIENT_SYNC_STARTED && $state->getSyncStatus() < CLIENT_SYNC_ACKNOWLEDGED) { 219 # $state->setSyncStatus(CLIENT_SYNC_ACKNOWLEDGED); 220 #} 221 } else { 222 $status = &new Horde_SyncML_Command_Status(RESPONSE_OK, 'Alert'); 223 $status->setCmdRef($this->_cmdID); 224 if ($this->_sourceLocURI != null) { 225 $status->setSourceRef($this->_sourceLocURI); 226 } 227 if ($this->_targetLocURI != null) { 228 $status->setTargetRef((isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI)); 229 } 230 231 $currentCmdID = $status->output($currentCmdID, $output); 232 } 233 /* else 234 { 235 if ($state->isAuthorized()) { 236 $output->startElement($state->getURI(), 'Alert', $attrs); 237 238 $output->startElement($state->getURI(), 'CmdID', $attrs); 239 $chars = $currentCmdID; 240 $output->characters($chars); 241 $output->endElement($state->getURI(), 'CmdID'); 242 243 $output->startElement($state->getURI(), 'Data', $attrs); 244 $chars = $this->_alert; 245 $output->characters($chars); 246 $output->endElement($state->getURI(), 'Data'); 247 248 $output->startElement($state->getURI(), 'Item', $attrs); 249 250 if ($this->_sourceLocURI != null) { 251 $output->startElement($state->getURI(), 'Target', $attrs); 252 $output->startElement($state->getURI(), 'LocURI', $attrs); 253 $chars = $this->_sourceLocURI; 254 $output->characters($chars); 255 $output->endElement($state->getURI(), 'LocURI'); 256 $output->endElement($state->getURI(), 'Target'); 257 } 258 259 if ($this->_targetLocURI != null) { 260 $output->startElement($state->getURI(), 'Source', $attrs); 261 $output->startElement($state->getURI(), 'LocURI', $attrs); 262 $chars = (isset($this->_targetLocURIParameters) ? $this->_targetLocURI.'?/'.$this->_targetLocURIParameters : $this->_targetLocURI); 263 $output->characters($chars); 264 $output->endElement($state->getURI(), 'LocURI'); 265 $output->endElement($state->getURI(), 'Source'); 266 } 267 $output->endElement($state->getURI(), 'Item'); 268 $output->endElement($state->getURI(), 'Alert'); 269 270 $currentCmdID++; 271 } 272 }*/ 273 274 return $currentCmdID; 275 } 276 277 /** 278 * Setter for property sourceURI. 279 * 280 * @param string $sourceURI New value of property sourceURI. 281 */ 282 function setSourceLocURI($sourceURI) 283 { 284 $this->_sourceLocURI = $sourceURI; 285 } 286 287 function getTargetLocURI() 288 { 289 return $this->_targetURI; 290 } 291 292 /** 293 * Setter for property targetURI. 294 * 295 * @param string $targetURI New value of property targetURI. 296 */ 297 // is this function still used??? 298 function setTargetURI($targetURI) 299 { 300 $this->_targetLocURI = $targetURI; 301 } 302 303 /** 304 * Setter for property targetURI. 305 * 306 * @param string $targetURI New value of property targetURI. 307 */ 308 function setTargetLocURI($targetURI) 309 { 310 $this->_targetLocURI = $targetURI; 311 } 312 313 function startElement($uri, $element, $attrs) 314 { 315 parent::startElement($uri, $element, $attrs); 316 317 switch ($this->_xmlStack) { 318 case 3: 319 if ($element == 'Target') { 320 $this->_isInSource = false; 321 } else { 322 $this->_isInSource = true; 323 } 324 break; 325 } 326 } 327 328 function endElement($uri, $element) 329 { 330 switch ($this->_xmlStack) { 331 case 1: 332 $state = & $_SESSION['SyncML.state']; 333 $sync = $state->getSync($this->_targetLocURI); 334 335 if (!$sync && $this->_alert < ALERT_RESULT_ALERT) { 336 Horde::logMessage('SyncML: create new sync for ' . $this->_targetLocURI . ' ' . $this->_alert, __FILE__, __LINE__, PEAR_LOG_DEBUG); 337 $sync = &Horde_SyncML_Sync::factory($this->_alert); 338 339 $sync->_targetLocURI = $this->_targetLocURI; 340 $sync->_sourceLocURI = $this->_sourceLocURI; 341 if(isset($this->_targetLocURIParameters)) 342 $sync->_targetLocURIParameters = $this->_targetLocURIParameters; 343 344 $state->setSync($this->_targetLocURI, $sync); 345 } 346 break; 347 348 case 2: 349 if ($element == 'Data') { 350 $this->_alert = intval(trim($this->_chars)); 351 } 352 break; 353 354 case 4: 355 if ($element == 'LocURI') { 356 if ($this->_isInSource) { 357 $this->_sourceLocURI = trim($this->_chars); 358 } else { 359 $targetLocURIData = explode('?/',trim($this->_chars)); 360 361 $this->_targetLocURI = $targetLocURIData[0]; 362 363 if(isset($targetLocURIData[1])) 364 { 365 $this->_targetLocURIParameters = $targetLocURIData[1]; 366 } 367 } 368 } 369 break; 370 371 case 5: 372 if ($element == 'Next') { 373 $this->_metaAnchorNext = trim($this->_chars); 374 } else if ($element == 'Last') { 375 $this->_metaAnchorLast = trim($this->_chars); 376 } 377 break; 378 } 379 380 parent::endElement($uri, $element); 381 } 382 383 function getAlert() 384 { 385 return $this->_alert; 386 } 387 388 function setAlert($alert) 389 { 390 $this->_alert = $alert; 391 } 392 393 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |