[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 define('ALERT_DISPLAY', 100); 4 5 // Not implemented. 6 define('ALERT_TWO_WAY', 200); 7 define('ALERT_SLOW_SYNC', 201); 8 define('ALERT_ONE_WAY_FROM_CLIENT', 202); 9 define('ALERT_REFRESH_FROM_CLIENT', 203); 10 define('ALERT_ONE_WAY_FROM_SERVER', 204); 11 define('ALERT_REFRESH_FROM_SERVER', 205); 12 13 // Not implemented. 14 define('ALERT_TWO_WAY_BY_SERVER', 206); 15 define('ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER', 207); 16 define('ALERT_REFRESH_FROM_CLIENT_BY_SERVER', 208); 17 define('ALERT_ONE_WAY_FROM_SERVER_BY_SERVER', 209); 18 define('ALERT_REFRESH_FROM_SERVER_BY_SERVER', 210); 19 20 define('ALERT_RESULT_ALERT', 221); 21 define('ALERT_NEXT_MESSAGE', 222); 22 define('ALERT_NO_END_OF_DATA', 223); 23 24 define('MIME_SYNCML_XML', 'application/vnd.syncml+xml'); 25 define('MIME_SYNCML_WBXML', 'application/vnd.syncml+wbxml'); 26 27 define('MIME_SYNCML_DEVICE_INFO_XML', 'application/vnd.syncml-devinf+xml'); 28 define('MIME_SYNCML_DEVICE_INFO_WBXML', 'application/vnd.syncml-devinf+wbxml'); 29 30 define('MIME_TEXT_PLAIN', 'text/plain'); 31 define('MIME_VCARD_V21', 'text/x-vcard'); 32 define('MIME_VCARD_V30', 'text/vcard'); 33 34 define('MIME_VCALENDAR', 'text/x-vcalendar'); 35 define('MIME_ICALENDAR', 'text/calendar'); 36 define('MIME_XML_ICALENDAR', 'application/vnd.syncml-xcal'); 37 38 define('MIME_MESSAGE', 'text/message'); 39 40 define('MIME_SYNCML_XML_EMAIL', 'application/vnd.syncml-xmsg'); 41 define('MIME_SYNCML_XML_BOOKMARK', 'application/vnd.syncml-xbookmark'); 42 define('MIME_SYNCML_RELATIONAL_OBJECT', 'application/vnd.syncml-xrelational'); 43 44 define('RESPONSE_IN_PROGRESS', 101); 45 46 define('RESPONSE_OK', 200); 47 define('RESPONSE_ITEM_ADDED', 201); 48 define('RESPONSE_ACCEPTED_FOR_PROCESSING', 202); 49 define('RESPONSE_NONAUTHORIATATIVE_RESPONSE', 203); 50 define('RESPONSE_NO_CONTENT', 204); 51 define('RESPONSE_RESET_CONTENT', 205); 52 define('RESPONSE_PARTIAL_CONTENT', 206); 53 define('RESPONSE_CONFLICT_RESOLVED_WITH_MERGE', 207); 54 define('RESPONSE_CONFLICT_RESOLVED_WITH_CLIENT_WINNING', 208); 55 define('RESPONSE_CONFILCT_RESOLVED_WITH_DUPLICATE', 209); 56 define('RESPONSE_DELETE_WITHOUT_ARCHIVE', 210); 57 define('RESPONSE_ITEM_NO_DELETED', 211); 58 define('RESPONSE_AUTHENTICATION_ACCEPTED', 212); 59 define('RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED', 213); 60 define('RESPONSE_OPERATION_CANCELLED', 214); 61 define('RESPONSE_NO_EXECUTED', 215); 62 define('RESPONSE_ATOMIC_ROLL_BACK_OK', 216); 63 64 define('RESPONSE_MULTIPLE_CHOICES', 300); 65 // Need to change names. 66 // define('RESPONSE_MULTIPLE_CHOICES', 301); 67 // define('RESPONSE_MULTIPLE_CHOICES', 302); 68 // define('RESPONSE_MULTIPLE_CHOICES', 303); 69 // define('RESPONSE_MULTIPLE_CHOICES', 304); 70 define('RESPONSE_USE_PROXY', 305); 71 72 define('RESPONSE_BAD_REQUEST', 400); 73 define('RESPONSE_INVALID_CREDENTIALS', 401); 74 // Need to change names. 75 // define('RESPONSE_INVALID_CREDENTIALS', 402); 76 // define('RESPONSE_INVALID_CREDENTIALS', 403); 77 define('RESPONSE_NOT_FOUND', 404); 78 // Need to change names. 79 // define('RESPONSE_INVALID_CREDENTIALS', 405); 80 // define('RESPONSE_INVALID_CREDENTIALS', 406); 81 define('RESPONSE_MISSING_CREDENTIALS', 407); 82 // define('RESPONSE_INVALID_CREDENTIALS', 408); 83 // define('RESPONSE_INVALID_CREDENTIALS', 409); 84 // define('RESPONSE_INVALID_CREDENTIALS', 410); 85 // define('RESPONSE_INVALID_CREDENTIALS', 411); 86 // define('RESPONSE_INVALID_CREDENTIALS', 412); 87 // define('RESPONSE_INVALID_CREDENTIALS', 413); 88 // define('RESPONSE_INVALID_CREDENTIALS', 414); 89 // define('RESPONSE_INVALID_CREDENTIALS', 415); 90 define('RESPONSE_REQUEST_SIZE_TOO_BIG', 416); 91 // Need to change names. 92 // define('RESPONSE_INVALID_CREDENTIALS', 417); 93 // define('RESPONSE_INVALID_CREDENTIALS', 418); 94 // define('RESPONSE_INVALID_CREDENTIALS', 419); 95 // define('RESPONSE_INVALID_CREDENTIALS', 420); 96 // define('RESPONSE_INVALID_CREDENTIALS', 421); 97 // define('RESPONSE_INVALID_CREDENTIALS', 422); 98 // define('RESPONSE_INVALID_CREDENTIALS', 423); 99 define('RESPONSE_SIZE_MISMATCH', 424); 100 101 define('RESPONSE_COMMAND_FAILED', 500); 102 // Need to change names. 103 // define('RESPONSE_COMMAND_FAILED', 501); 104 // define('RESPONSE_COMMAND_FAILED', 502); 105 // define('RESPONSE_COMMAND_FAILED', 503); 106 // define('RESPONSE_COMMAND_FAILED', 504); 107 // define('RESPONSE_COMMAND_FAILED', 505); 108 // define('RESPONSE_COMMAND_FAILED', 506); 109 // define('RESPONSE_COMMAND_FAILED', 507); 110 // define('RESPONSE_COMMAND_FAILED', 508); 111 // define('RESPONSE_COMMAND_FAILED', 509); 112 // define('RESPONSE_COMMAND_FAILED', 510); 113 // define('RESPONSE_COMMAND_FAILED', 511); 114 // define('RESPONSE_COMMAND_FAILED', 512); 115 // define('RESPONSE_COMMAND_FAILED', 513); 116 // define('RESPONSE_COMMAND_FAILED', 514); 117 // define('RESPONSE_COMMAND_FAILED', 515); 118 define('RESPONSE_ATOMIC_ROLL_BACK_FAILED', 516); 119 120 define('NAME_SPACE_URI_SYNCML', 'syncml:syncml1.0'); 121 define('NAME_SPACE_URI_SYNCML_1_1', 'syncml:syncml1.1'); 122 define('NAME_SPACE_URI_METINF', 'syncml:metinf'); 123 define('NAME_SPACE_URI_METINF_1_1', 'syncml:metinf1.1'); 124 define('NAME_SPACE_URI_DEVINF', 'syncml:devinf'); 125 define('NAME_SPACE_URI_DEVINF_1_1', 'syncml:devinf1.1'); 126 127 define('CLIENT_SYNC_STARTED', 1); 128 define('CLIENT_SYNC_FINNISHED', 2); 129 define('CLIENT_SYNC_ACKNOWLEDGED', 3); 130 define('SERVER_SYNC_DATA_PENDING', 4); 131 define('SERVER_SYNC_FINNISHED', 5); 132 define('SERVER_SYNC_ACKNOWLEDGED', 6); 133 134 define('MAX_DATA', 19); 135 define('MAX_ENTRIES', 10); 136 137 /** 138 * The Horde_SyncML_State class provides a SyncML state object. 139 * 140 * $Horde: framework/SyncML/SyncML/State.php,v 1.15 2004/07/26 09:24:38 jan Exp $ 141 * 142 * Copyright 2003-2004 Anthony Mills <amills@pyramid6.com> 143 * 144 * See the enclosed file COPYING for license information (LGPL). If you 145 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 146 * 147 * @author Anthony Mills <amills@pyramid6.com> 148 * @version $Revision: 22261 $ 149 * @since Horde 3.0 150 * @package Horde_SyncML 151 */ 152 class Horde_SyncML_State { 153 154 var $_sessionID; 155 156 var $_verProto; 157 158 var $_msgID; 159 160 var $_targetURI; 161 162 var $_sourceURI; 163 164 var $_version; 165 166 var $_locName; 167 168 var $_password; 169 170 var $_isAuthorized; 171 172 var $_uri; 173 174 var $_uriMeta; 175 176 var $_syncs = array(); 177 178 var $_clientAnchorNext = array(); // written to db after successful sync 179 180 var $_serverAnchorLast = array(); 181 182 var $_serverAnchorNext = array(); // written to db after successful sync 183 184 var $_clientDeviceInfo = array(); 185 186 // array list of changed items, which need to be synced to the client 187 var $_changedItems; 188 189 // array list of deleted items, which need to be synced to the client 190 var $_deletedItems; 191 192 // array list of added items, which need to be synced to the client 193 var $_addedItems; 194 195 // bool flag that we need to more data 196 var $_syncStatus; 197 198 var $_log = array(); 199 200 // stores if we received Alert 222 already 201 var $_receivedAlert222 = false; 202 203 /** 204 * Creates a new instance of Horde_SyncML_State. 205 */ 206 function Horde_SyncML_State($sourceURI, $locName, $sessionID, $password = false) 207 { 208 $this->setSourceURI($sourceURI); 209 $this->setLocName($locName); 210 $this->setSessionID($sessionID); 211 if ($password) { 212 $this->setPassword($password); 213 } 214 215 $this->isAuthorized = false; 216 } 217 218 /** 219 * Returns the DataTree used as persistence layer for SyncML. The 220 * datatree var should not be a class member of State as State is 221 * stored as a session var. Resource handles (=db connections) 222 * cannot be stored in sessions. 223 * 224 * @return object DataTree The DataTree object. 225 */ 226 function &getDataTree() 227 { 228 $driver = $GLOBALS['conf']['datatree']['driver']; 229 $params = Horde::getDriverConfig('datatree', $driver); 230 $params = array_merge($params, array( 'group' => 'syncml' )); 231 232 return DataTree::singleton($driver, $params); 233 } 234 235 function getLocName() 236 { 237 if(isset($this->_locName)) 238 return $this->_locName; 239 else 240 return False; 241 } 242 243 function getSourceURI() 244 { 245 return $this->_sourceURI; 246 } 247 248 function getTargetURI() 249 { 250 return $this->_targetURI; 251 } 252 253 function getVersion() 254 { 255 return $this->_version; 256 } 257 258 function &getAddedItems($_type) 259 { 260 if(isset($this->_addedItems[$_type])) 261 { 262 return $this->_addedItems[$_type]; 263 } 264 265 return false; 266 } 267 268 function &getChangedItems($_type) 269 { 270 if(isset($this->_changedItems[$_type])) 271 { 272 return $this->_changedItems[$_type]; 273 } 274 275 return false; 276 } 277 278 function &getDeletedItems($_type) 279 { 280 if(isset($this->_deletedItems[$_type])) 281 { 282 return $this->_deletedItems[$_type]; 283 } 284 285 return false; 286 } 287 288 function getMoreDataPending() 289 { 290 return $this->_moreDataPending; 291 } 292 293 function getMsgID() 294 { 295 return $this->_msgID; 296 } 297 298 function setWBXML($wbxml) 299 { 300 $this->_wbxml = $wbxml; 301 } 302 303 function isWBXML() 304 { 305 return !empty($this->_wbxml); 306 } 307 308 function &getSyncStatus() 309 { 310 return $this->_syncStatus; 311 } 312 313 function setAddedItems($_type, $_addedItems) 314 { 315 $this->_addedItems[$_type] = $_addedItems; 316 } 317 318 function setChangedItems($_type, $_changedItems) 319 { 320 $this->_changedItems[$_type] = $_changedItems; 321 } 322 323 function setClientDeviceInfo($clientDeviceInfo) 324 { 325 $this->_clientDeviceInfo = $clientDeviceInfo; 326 } 327 328 function setDeletedItems($_type, $_deletedItems) 329 { 330 $this->_deletedItems[$_type] = $_deletedItems; 331 } 332 333 function setMoreDataPending($_state) 334 { 335 $this->_moreDataPending = $_state; 336 } 337 338 /** 339 * Setter for property msgID. 340 * @param msgID New value of property msgID. 341 */ 342 function setMsgID($msgID) 343 { 344 $this->_msgID = $msgID; 345 } 346 347 /** 348 * Setter for property locName. 349 * @param locName New value of property locName. 350 */ 351 function setLocName($locName) 352 { 353 $this->_locName = $locName; 354 } 355 356 /** 357 * Setter for property locName. 358 * @param locName New value of property locName. 359 */ 360 function setPassword($password) 361 { 362 $this->_password = $password; 363 } 364 365 function setSourceURI($sourceURI) 366 { 367 $this->_sourceURI = $sourceURI; 368 } 369 370 function setSyncStatus($_syncStatus) 371 { 372 #Horde::logMessage('SyncML: syncState set to ==> ' . $_syncStatus, __FILE__, __LINE__, PEAR_LOG_DEBUG); 373 $this->_syncStatus = $_syncStatus; 374 } 375 376 function setTargetURI($targetURI) 377 { 378 $this->_targetURI = $targetURI; 379 } 380 381 function setVersion($version) 382 { 383 $this->_version = $version; 384 385 if ($version == 0) { 386 $this->_uri = NAME_SPACE_URI_SYNCML; 387 $this->_uriMeta = NAME_SPACE_URI_METINF; 388 $this->_uriDevInf = NAME_SPACE_URI_DEVINF; 389 } else { 390 $this->_uri = NAME_SPACE_URI_SYNCML_1_1; 391 $this->_uriMeta = NAME_SPACE_URI_METINF_1_1; 392 $this->_uriDevInf = NAME_SPACE_URI_DEVINF_1_1; 393 } 394 } 395 396 function setSessionID($sessionID) 397 { 398 $this->_sessionID = $sessionID; 399 } 400 401 function isAuthorized() 402 { 403 if (!$this->_isAuthorized) { 404 405 if(strstr($this->_locName,'@') === False) 406 { 407 $this->_locName .= '@'.$GLOBALS['phpgw_info']['server']['default_domain']; 408 } 409 410 #Horde::logMessage('SyncML: Authenticate ' . $this->_locName . ' - ' . $this->_password, __FILE__, __LINE__, PEAR_LOG_DEBUG); 411 412 if($GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create($this->_locName,$this->_password,'text','u')) 413 { 414 $this->_isAuthorized = true; 415 #Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 416 } 417 else 418 { 419 $this->_isAuthorized = false; 420 Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 421 } 422 } 423 else 424 { 425 // store sessionID in a variable, because ->verify maybe resets that value 426 $sessionID = session_id(); 427 if(!$GLOBALS['phpgw']->session->verify($sessionID, 'staticsyncmlkp3')) 428 Horde::logMessage('SyncML_EGW: egw session('.$sessionID. ') not verified ' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 429 } 430 431 return $this->_isAuthorized; 432 } 433 434 function clearSync($target) 435 { 436 unset($this->_syncs[$target]); 437 } 438 439 function setSync($target, $sync) 440 { 441 $this->_syncs[$target] = $sync; 442 } 443 444 function getSync($target) 445 { 446 if (isset($this->_syncs[$target])) { 447 return $this->_syncs[$target]; 448 } else { 449 return false; 450 } 451 } 452 453 function getTargets() 454 { 455 if(count($this->_syncs) < 1) 456 return FALSE; 457 458 foreach($this->_syncs as $target => $sync) 459 { 460 $targets[] = $target; 461 } 462 463 return $targets; 464 } 465 466 function getURI() 467 { 468 /* 469 * The non WBXML devices (notably P900 and Sync4j seem to get confused 470 * by a <SyncML xmlns="syncml:SYNCML1.1"> element. They require 471 * just <SyncML>. So don't use an ns for non wbxml devices. 472 */ 473 if ($this->isWBXML()) { 474 return $this->_uri; 475 } else { 476 return ''; 477 } 478 } 479 function getURIMeta() 480 { 481 return $this->_uriMeta; 482 } 483 484 function getURIDevInf() 485 { 486 return $this->_uriDevInf; 487 } 488 489 490 /** 491 * Converts a Horde GUID (like 492 * kronolith:0d1b415fc124d3427722e95f0e926b75) to a client ID as 493 * used by the sync client (like 12) returns false if no such id 494 * is stored yet. 495 * 496 * Remember that the datatree is really a tree disguised as a 497 * table. So to look up the guid above, getId first looks for an 498 * entry 'kronolith' and then for an entry 499 * 0d1b415fc124d3427722e95f0e926b75 with kronolith as parent. 500 */ 501 function getLocID($type, $guid) 502 { 503 $dt = &$this->getDataTree(); 504 $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $guid); 505 if (is_a($id, 'PEAR_Error')) { 506 return false; 507 } 508 509 $gid = $dt->getObjectById($id); 510 if (is_a($gid, 'PEAR_Error')) { 511 return false; 512 } 513 514 return $gid->get('locid'); 515 } 516 517 /** 518 * Puts a given client $locid and Horde server $guid pair into the 519 * map table to allow mapping between the client's and server's 520 * IDs. Actually there are two maps: from the localid to the guid 521 * and vice versa. The localid is converted to a key as follows: 522 * this->_locName . $this->_sourceURI . $type . $locid so you can 523 * have different syncs with different devices. If an entry 524 * already exists, it is overwritten. 525 */ 526 function setUID($type, $locid, $guid, $ts=0) 527 { 528 $dt = &$this->getDataTree(); 529 530 // Set $locid. 531 $gid = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . $guid); 532 $gid->set('type', $type); 533 $gid->set('locid', $locid); 534 $gid->set('ts', $ts); 535 536 $r = $dt->add($gid); 537 if (is_a($r, 'PEAR_Error')) { 538 // Object already exists: update instead. 539 $r = $dt->updateData($gid); 540 } 541 $this->dieOnError($r, __FILE__, __LINE__); 542 543 // Set $globaluid 544 $lid = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . $locid); 545 $lid->set('globaluid', $guid); 546 $r = $dt->add($lid); 547 if (is_a($r, 'PEAR_Error')) { 548 // object already exists: update instead. 549 $r = $dt->updateData($lid); 550 } 551 $this->dieOnError($r, __FILE__, __LINE__); 552 } 553 554 /** 555 * Retrieves the Horde server guid (like 556 * kronolith:0d1b415fc124d3427722e95f0e926b75) for a given client 557 * locid. Returns false if no such id is stored yet. 558 * 559 * Opposite of getLocId which returns the locid for a given guid. 560 */ 561 function getGlobalUID($type, $locid) 562 { 563 $this->dieOnError($type, __FILE__, __LINE__); 564 $this->dieOnError($locid, __FILE__, __LINE__); 565 $this->dieOnError($locid, __FILE__, __LINE__); 566 $this->dieOnError($this->_locName, __FILE__, __LINE__); 567 $this->dieOnError($this->_sourceURI, __FILE__, __LINE__); 568 569 $dt = &$this->getDataTree(); 570 571 $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $locid); 572 if (is_a($id, 'PEAR_Error')) { 573 return false; 574 } 575 $lid = $dt->getObjectById($id); 576 if (is_a($lid, 'PEAR_Error')) { 577 return false; 578 } 579 580 return $lid->get('globaluid'); 581 } 582 583 /** 584 * Returns the timestamp (if set) of the last change to the 585 * obj:guid, that was caused by the client. This is stored to 586 * avoid mirroring these changes back to the client. 587 */ 588 function getChangeTS($type, $guid) 589 { 590 $dt = &$this->getDataTree(); 591 592 $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $guid); 593 if (is_a($id, 'PEAR_Error')) { 594 return false; 595 } 596 597 $gid = $dt->getObjectById($id); 598 if (is_a($gid, 'PEAR_Error')) { 599 return false; 600 } 601 602 return $gid->get('ts'); 603 } 604 605 /** 606 * Removes the locid<->guid mapping for the given locid. Returns 607 * the guid that was removed or false if no mapping entry was 608 * found. 609 */ 610 function removeUID($type, $locid) 611 { 612 $dt = &$this->getDataTree(); 613 614 $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $locid); 615 if (is_a($id, 'PEAR_Error')) { 616 Horde::logMessage("SyncML: state->removeUID(type=$type,locid=$locid) : nothing to remove", __FILE__, __LINE__, PEAR_LOG_DEBUG); 617 return false; 618 } 619 $lid = $dt->getObjectById($id); 620 $guid = $lid->get('globaluid'); 621 Horde::logMessage("SyncML: state->removeUID(type=$type,locid=$locid) : removing guid:$guid and lid:$lid", __FILE__, __LINE__, PEAR_LOG_DEBUG); 622 $dt->remove($guid); 623 $dt->remove($lid); 624 625 return $guid; 626 } 627 628 /** 629 * This function should use DevINF information. 630 */ 631 function getPreferedContentType($type) 632 { 633 # if ($type == 'contacts') { 634 # return 'text/x-vcard'; 635 # } elseif ($type == 'notes') { 636 # return 'text/x-vnote'; 637 # } elseif ($type == 'tasks') { 638 # return 'text/x-vcalendar'; 639 # } elseif ($type == 'calendar') { 640 # return 'text/x-vcalendar'; 641 # } 642 switch($type) { 643 case 'contacts': 644 return 'text/x-vcard'; 645 break; 646 647 case 'sifcalendar': 648 case './sifcalendar': 649 return 'text/x-s4j-sife'; 650 break; 651 652 case 'sifcontacts': 653 case './sifcontacts': 654 return 'text/x-s4j-sifc'; 655 break; 656 657 case 'siftasks': 658 case './siftasks': 659 return 'text/x-s4j-sift'; 660 break; 661 662 case 'notes': 663 return 'text/x-vnote'; 664 break; 665 666 case 'tasks': 667 return 'text/x-vcalendar'; 668 break; 669 670 case 'calendar': 671 return 'text/x-vcalendar'; 672 break; 673 } 674 } 675 676 /** 677 * Returns the preferred contenttype of the client for the given 678 * sync data type (database). 679 * 680 * This is passed as an option to the Horde API export functions. 681 */ 682 function getPreferedContentTypeClient($_sourceLocURI) 683 { 684 $deviceInfo = $this->getClientDeviceInfo(); 685 686 if(isset($deviceInfo['dataStore'][$_sourceLocURI]['rxPreference']['contentType'])) 687 { 688 return array('ContentType' => $deviceInfo['dataStore'][$_sourceLocURI]['rxPreference']['contentType']); 689 } 690 691 Horde::logMessage('SyncML: sourceLocURI ' . $_sourceLocURI .' not found', __FILE__, __LINE__, PEAR_LOG_DEBUG); 692 return PEAR::raiseError(_('sourceLocURI not found')); 693 # elseif ($type == 'contacts') { 694 # return 'text/x-vcard'; 695 # } elseif ($type == 'notes') { 696 # return array('ContentType' => 'text/x-vnote', 697 # 'ENCODING' => 'QUOTED-PRINTABLE', 698 # 'CHARSET' => 'UTF-8'); 699 # } elseif ($type == 'tasks') { 700 # return 'text/x-vcalendar'; 701 # } elseif ($type == 'calendar') { 702 # return array('ContentType' => 'text/x-vcalendar', 703 # 'ENCODING' => 'QUOTED-PRINTABLE', 704 # 'CHARSET' => 'UTF-8'); 705 # } 706 } 707 708 function setClientAnchorNext($type, $a) 709 { 710 $this->_clientAnchorNext[$type] = $a; 711 } 712 713 function setServerAnchorLast($type, $a) 714 { 715 $this->_serverAnchorLast[$type] = $a; 716 } 717 718 function setServerAnchorNext($type, $a) 719 { 720 $this->_serverAnchorNext[$type] = $a; 721 } 722 723 function getClientAnchorNext($type) 724 { 725 return $this->_clientAnchorNext[$type]; 726 } 727 728 function getServerAnchorNext($type) 729 { 730 return $this->_serverAnchorNext[$type]; 731 } 732 733 function getServerAnchorLast($type) 734 { 735 return $this->_serverAnchorLast[$type]; 736 } 737 738 /** 739 * Retrieves information about the previous sync if any. Returns 740 * false if no info found or a DateTreeObject with at least the 741 * following attributes: 742 * 743 * ClientAnchor: the clients Next Anchor of the previous sync. 744 * ServerAnchor: the Server Next Anchor of the previous sync. 745 */ 746 function &getSyncSummary($type) 747 { 748 $dt = &$this->getDataTree(); 749 750 $id = $dt->getId($this->_locName . $this->_sourceURI . $type . 'syncSummary'); 751 if (is_a($id, 'PEAR_Error')) { 752 return false; 753 } 754 755 return $dt->getObjectById($id); 756 } 757 758 /** 759 * Retrieves information about the clients device info if any. Returns 760 * false if no info found or a DateTreeObject with at least the 761 * following attributes: 762 * 763 * a array containing all available infos about the device 764 */ 765 function getClientDeviceInfo() 766 { 767 $dt = &$this->getDataTree(); 768 769 $id = $dt->getId($this->_locName . $this->_sourceURI . 'deviceInfo'); 770 if (is_a($id, 'PEAR_Error')) { 771 return false; 772 } 773 774 $info = $dt->getObjectById($id); 775 776 return $info->get('ClientDeviceInfo'); 777 } 778 779 /** 780 * write clients device info to database 781 */ 782 function writeClientDeviceInfo() 783 { 784 if (!isset($this->_clientDeviceInfo) || !is_array($this->_clientDeviceInfo)) { 785 return; 786 } 787 788 $dt = &$this->getDataTree(); 789 790 $s = $this->_locName . $this->_sourceURI . 'deviceInfo'; 791 792 // Set $locid. 793 $info = &new DataTreeObject($s); 794 $info->set('ClientDeviceInfo', $this->_clientDeviceInfo); 795 $r = $dt->add($info); 796 if (is_a($r, 'PEAR_Error')) { 797 // Object already exists: update instead. 798 $dt->updateData($info); 799 } 800 } 801 802 /** 803 * After a successful sync, the client and server's Next Anchors 804 * are written to the database so they can be used to negotiate 805 * upcoming syncs. 806 */ 807 function writeSyncSummary() 808 { 809 if (!isset($this->_serverAnchorNext) || !is_array($this->_serverAnchorNext)) { 810 return; 811 } 812 813 $dt = &$this->getDataTree(); 814 815 foreach (array_keys($this->_serverAnchorNext) as $type) { 816 $s = $this->_locName . $this->_sourceURI . $type . 'syncSummary'; 817 818 // Set $locid. 819 $info = &new DataTreeObject($s); 820 $info->set('ClientAnchor', $this->_clientAnchorNext); 821 $info->set('ServerAnchor', $this->_serverAnchorNext); 822 $r = $dt->add($info); 823 if (is_a($r, 'PEAR_Error')) { 824 // Object already exists: update instead. 825 $dt->updateData($info); 826 } 827 } 828 } 829 830 /** 831 * The log simply counts the entries for each topic. 832 */ 833 function log($topic) 834 { 835 if (isset($this->_log[$topic])) { 836 $this->_log[$topic] += 1; 837 } else { 838 $this->_log[$topic] = 1; 839 } 840 } 841 842 /** 843 * The Log is an array where the key is the event name and the 844 * value says how often this event occured. 845 */ 846 function getLog() 847 { 848 return $this->_log; 849 } 850 851 /** 852 * Convert the content. 853 * 854 * Currently strips uid (primary key) information as client and 855 * server might use different ones. 856 * 857 * Charset conversions might be added here too. 858 */ 859 function convertClient2Server($content, $contentType) 860 { 861 switch ($contentType) { 862 case 'text/calendar': 863 case 'text/x-icalendar': 864 case 'text/x-vcalendar': 865 case 'text/x-vevent': 866 case 'text/x-vtodo': 867 $content = preg_replace('/^UID:.*\n/m', '', $content, 1); 868 break; 869 } 870 871 return $content; 872 } 873 874 /** 875 * Convert the content. 876 * 877 * Currently strips uid (primary key) information as client and 878 * server might use different ones. 879 * 880 * Charset conversions might be added here too. 881 */ 882 function convertServer2Client($content, $contentType) 883 { 884 switch ($contentType) { 885 case 'text/calendar': 886 case 'text/x-icalendar': 887 case 'text/x-vcalendar': 888 case 'text/x-vevent': 889 case 'text/x-vtodo': 890 $content = preg_replace('/^UID:.*\n/m', '', $content, 1); 891 break; 892 } 893 894 // FIXME: utf8 really should be fine. But the P900 seems to 895 // expect ISO 8559 even when <?xml version="1.0" 896 // encoding="utf-8"> is specified. 897 // 898 // So at least make this dependant on the device information. 899 return utf8_decode($content); 900 } 901 902 /** 903 * When True, Task Item changes (NAG) are sent to the server 904 * during "calendar" Syncs. That's the way the P800/900 handles 905 * things. Should be retrieved from devinf? 906 */ 907 function handleTasksInCalendar() 908 { 909 return false; 910 } 911 912 /** 913 * This is a small helper function that can be included to check 914 * whether a given $obj is a PEAR_Error or not. If so, it logs 915 * to debug, var_dumps the $obj and exits. 916 */ 917 function dieOnError($obj, $file = __FILE__, $line = __LINE__) 918 { 919 if (!is_a($obj, 'PEAR_Error')) { 920 return; 921 } 922 923 Horde::logMessage('SyncML: PEAR Error: ' . $obj->getMessage(), $file, $line, PEAR_LOG_ERR); 924 print "PEAR ERROR\n\n"; 925 var_dump($obj); 926 exit; 927 } 928 929 function getAlert222Received() { 930 return $this->_receivedAlert222; 931 } 932 933 function setAlert222Received($_status) { 934 $this->_receivedAlert222 = (bool)$_status; 935 } 936 937 }
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 |