@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function stream_open($path, $mode, $options, &$opened_path) { |
| 35 | 35 | $contextOptions = stream_context_get_options($this->context); |
| 36 | - if (!isset($contextOptions[self::PROTOCOL]['stream'])) |
|
| 37 | - return false; |
|
| 36 | + if (!isset($contextOptions[self::PROTOCOL]['stream'])) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | $this->position = 0; |
| 40 | 41 | $this->toTruncate = false; |
@@ -47,8 +48,7 @@ discard block |
||
| 47 | 48 | if ($this->mapistream) { |
| 48 | 49 | $stat = mapi_stream_stat($this->mapistream); |
| 49 | 50 | $this->streamlength = $stat["cb"]; |
| 50 | - } |
|
| 51 | - else { |
|
| 51 | + } else { |
|
| 52 | 52 | $this->streamlength = 0; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -74,8 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | if ($this->mapistream) { |
| 76 | 76 | $data = mapi_stream_read($this->mapistream, $len); |
| 77 | - } |
|
| 78 | - else { |
|
| 77 | + } else { |
|
| 79 | 78 | $data = ""; |
| 80 | 79 | } |
| 81 | 80 | $this->position += strlen($data); |
@@ -63,20 +63,19 @@ discard block |
||
| 63 | 63 | if ($folderidForBackendId != $this->folderidHex) { |
| 64 | 64 | $this->prefix = $folderidForBackendId . ':'; |
| 65 | 65 | } |
| 66 | - } |
|
| 67 | - else { |
|
| 66 | + } else { |
|
| 68 | 67 | $storeprops = mapi_getprops($store, array(PR_IPM_SUBTREE_ENTRYID, PR_IPM_PUBLIC_FOLDERS_ENTRYID)); |
| 69 | 68 | if (ZPush::GetBackend()->GetImpersonatedUser() == 'system') { |
| 70 | 69 | $entryid = $storeprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID]; |
| 71 | - } |
|
| 72 | - else { |
|
| 70 | + } else { |
|
| 73 | 71 | $entryid = $storeprops[PR_IPM_SUBTREE_ENTRYID]; |
| 74 | 72 | } |
| 75 | 73 | } |
| 76 | 74 | |
| 77 | 75 | $folder = false; |
| 78 | - if ($entryid) |
|
| 79 | - $folder = mapi_msgstore_openentry($store, $entryid); |
|
| 76 | + if ($entryid) { |
|
| 77 | + $folder = mapi_msgstore_openentry($store, $entryid); |
|
| 78 | + } |
|
| 80 | 79 | |
| 81 | 80 | if(!$folder) { |
| 82 | 81 | $this->importer = false; |
@@ -90,8 +89,7 @@ discard block |
||
| 90 | 89 | |
| 91 | 90 | if ($folderid) { |
| 92 | 91 | $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportContentsChanges, 0 , 0); |
| 93 | - } |
|
| 94 | - else { |
|
| 92 | + } else { |
|
| 95 | 93 | $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportHierarchyChanges, 0 , 0); |
| 96 | 94 | } |
| 97 | 95 | } |
@@ -110,13 +108,15 @@ discard block |
||
| 110 | 108 | $this->flags = $flags; |
| 111 | 109 | |
| 112 | 110 | // this should never happen |
| 113 | - if ($this->importer === false) |
|
| 114 | - throw new StatusException("ImportChangesICS->Config(): Error, importer not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 111 | + if ($this->importer === false) { |
|
| 112 | + throw new StatusException("ImportChangesICS->Config(): Error, importer not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 113 | + } |
|
| 115 | 114 | |
| 116 | 115 | // Put the state information in a stream that can be used by ICS |
| 117 | 116 | $stream = mapi_stream_create(); |
| 118 | - if(strlen($state) == 0) |
|
| 119 | - $state = hex2bin("0000000000000000"); |
|
| 117 | + if(strlen($state) == 0) { |
|
| 118 | + $state = hex2bin("0000000000000000"); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->Config(): initializing importer with state: 0x%s", bin2hex($state))); |
| 122 | 122 | |
@@ -127,12 +127,13 @@ discard block |
||
| 127 | 127 | // possible conflicting messages will be cached here |
| 128 | 128 | $this->memChanges = new ChangesMemoryWrapper(); |
| 129 | 129 | $stat = mapi_importcontentschanges_config($this->importer, $stream, $flags); |
| 130 | + } else { |
|
| 131 | + $stat = mapi_importhierarchychanges_config($this->importer, $stream, $flags); |
|
| 130 | 132 | } |
| 131 | - else |
|
| 132 | - $stat = mapi_importhierarchychanges_config($this->importer, $stream, $flags); |
|
| 133 | 133 | |
| 134 | - if (!$stat) |
|
| 135 | - throw new StatusException(sprintf("ImportChangesICS->Config(): Error, mapi_import_*_changes_config() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 134 | + if (!$stat) { |
|
| 135 | + throw new StatusException(sprintf("ImportChangesICS->Config(): Error, mapi_import_*_changes_config() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 136 | + } |
|
| 136 | 137 | return $stat; |
| 137 | 138 | } |
| 138 | 139 | |
@@ -172,25 +173,29 @@ discard block |
||
| 172 | 173 | */ |
| 173 | 174 | public function GetState() { |
| 174 | 175 | $error = false; |
| 175 | - if(!isset($this->statestream) || $this->importer === false) |
|
| 176 | - $error = true; |
|
| 176 | + if(!isset($this->statestream) || $this->importer === false) { |
|
| 177 | + $error = true; |
|
| 178 | + } |
|
| 177 | 179 | |
| 178 | - if ($error === false && $this->folderid !== false && function_exists("mapi_importcontentschanges_updatestate")) |
|
| 179 | - if(mapi_importcontentschanges_updatestate($this->importer, $this->statestream) != true) |
|
| 180 | + if ($error === false && $this->folderid !== false && function_exists("mapi_importcontentschanges_updatestate")) { |
|
| 181 | + if(mapi_importcontentschanges_updatestate($this->importer, $this->statestream) != true) |
|
| 180 | 182 | $error = true; |
| 183 | + } |
|
| 181 | 184 | |
| 182 | - if ($error == true) |
|
| 183 | - throw new StatusException(sprintf("ImportChangesICS->GetState(): Error, state not available or unable to update: 0x%X", mapi_last_hresult()), (($this->folderid)?SYNC_STATUS_FOLDERHIERARCHYCHANGED:SYNC_FSSTATUS_CODEUNKNOWN), null, LOGLEVEL_WARN); |
|
| 185 | + if ($error == true) { |
|
| 186 | + throw new StatusException(sprintf("ImportChangesICS->GetState(): Error, state not available or unable to update: 0x%X", mapi_last_hresult()), (($this->folderid)?SYNC_STATUS_FOLDERHIERARCHYCHANGED:SYNC_FSSTATUS_CODEUNKNOWN), null, LOGLEVEL_WARN); |
|
| 187 | + } |
|
| 184 | 188 | |
| 185 | 189 | mapi_stream_seek($this->statestream, 0, STREAM_SEEK_SET); |
| 186 | 190 | |
| 187 | 191 | $state = ""; |
| 188 | 192 | while(true) { |
| 189 | 193 | $data = mapi_stream_read($this->statestream, 4096); |
| 190 | - if(strlen($data)) |
|
| 191 | - $state .= $data; |
|
| 192 | - else |
|
| 193 | - break; |
|
| 194 | + if(strlen($data)) { |
|
| 195 | + $state .= $data; |
|
| 196 | + } else { |
|
| 197 | + break; |
|
| 198 | + } |
|
| 194 | 199 | } |
| 195 | 200 | |
| 196 | 201 | return $state; |
@@ -265,8 +270,9 @@ discard block |
||
| 265 | 270 | * @throws StatusException |
| 266 | 271 | */ |
| 267 | 272 | public function LoadConflicts($contentparameters, $state) { |
| 268 | - if (!isset($this->session) || !isset($this->store) || !isset($this->folderid)) |
|
| 269 | - throw new StatusException("ImportChangesICS->LoadConflicts(): Error, can not load changes for conflict detection. Session, store or folder information not available", SYNC_STATUS_SERVERERROR); |
|
| 273 | + if (!isset($this->session) || !isset($this->store) || !isset($this->folderid)) { |
|
| 274 | + throw new StatusException("ImportChangesICS->LoadConflicts(): Error, can not load changes for conflict detection. Session, store or folder information not available", SYNC_STATUS_SERVERERROR); |
|
| 275 | + } |
|
| 270 | 276 | |
| 271 | 277 | // save data to load changes later if necessary |
| 272 | 278 | $this->conflictsLoaded = false; |
@@ -352,8 +358,9 @@ discard block |
||
| 352 | 358 | $props[PR_SOURCE_KEY] = hex2bin($sk); |
| 353 | 359 | |
| 354 | 360 | // check if message is in the synchronization interval and/or shared+private |
| 355 | - if (!$this->isModificationAllowed($sk)) |
|
| 356 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Message modification is not allowed. Data not saved.", $id, get_class($message)), SYNC_STATUS_SYNCCANNOTBECOMPLETED); |
|
| 361 | + if (!$this->isModificationAllowed($sk)) { |
|
| 362 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Message modification is not allowed. Data not saved.", $id, get_class($message)), SYNC_STATUS_SYNCCANNOTBECOMPLETED); |
|
| 363 | + } |
|
| 357 | 364 | |
| 358 | 365 | // check for conflicts |
| 359 | 366 | $this->lazyLoadConflicts(); |
@@ -362,31 +369,32 @@ discard block |
||
| 362 | 369 | // in these cases the status SYNC_STATUS_CONFLICTCLIENTSERVEROBJECT should be returned, so the mobile client can inform the end user |
| 363 | 370 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Conflict detected. Data from PIM will be dropped! Server overwrites PIM. User is informed.", $id, get_class($message)), SYNC_STATUS_CONFLICTCLIENTSERVEROBJECT, null, LOGLEVEL_INFO); |
| 364 | 371 | return false; |
| 372 | + } else { |
|
| 373 | + ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Conflict detected. Data from Server will be dropped! PIM overwrites server.", $id, get_class($message))); |
|
| 365 | 374 | } |
| 366 | - else |
|
| 367 | - ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Conflict detected. Data from Server will be dropped! PIM overwrites server.", $id, get_class($message))); |
|
| 368 | 375 | } |
| 369 | 376 | if($this->memChanges->IsDeleted($id)) { |
| 370 | 377 | ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Conflict detected. Data from PIM will be dropped! Object was deleted on server.", $id, get_class($message))); |
| 371 | 378 | return false; |
| 372 | 379 | } |
| 380 | + } else { |
|
| 381 | + $flags = SYNC_NEW_MESSAGE; |
|
| 373 | 382 | } |
| 374 | - else |
|
| 375 | - $flags = SYNC_NEW_MESSAGE; |
|
| 376 | 383 | |
| 377 | 384 | if(mapi_importcontentschanges_importmessagechange($this->importer, $props, $flags, $mapimessage)) { |
| 378 | 385 | $this->mapiprovider->SetMessage($mapimessage, $message); |
| 379 | 386 | mapi_savechanges($mapimessage); |
| 380 | 387 | |
| 381 | - if (mapi_last_hresult()) |
|
| 382 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_SYNCCANNOTBECOMPLETED); |
|
| 388 | + if (mapi_last_hresult()) { |
|
| 389 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_SYNCCANNOTBECOMPLETED); |
|
| 390 | + } |
|
| 383 | 391 | |
| 384 | 392 | $sourcekeyprops = mapi_getprops($mapimessage, array (PR_SOURCE_KEY)); |
| 385 | 393 | |
| 386 | 394 | return $this->prefix . bin2hex($sourcekeyprops[PR_SOURCE_KEY]); |
| 395 | + } else { |
|
| 396 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error updating object: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 387 | 397 | } |
| 388 | - else |
|
| 389 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error updating object: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 390 | 398 | } |
| 391 | 399 | |
| 392 | 400 | /** |
@@ -402,22 +410,23 @@ discard block |
||
| 402 | 410 | list(,$sk) = Utils::SplitMessageId($id); |
| 403 | 411 | |
| 404 | 412 | // check if message is in the synchronization interval and/or shared+private |
| 405 | - if (!$this->isModificationAllowed($sk)) |
|
| 406 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Message deletion is not allowed. Deletion not executed.", $id), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 413 | + if (!$this->isModificationAllowed($sk)) { |
|
| 414 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Message deletion is not allowed. Deletion not executed.", $id), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 415 | + } |
|
| 407 | 416 | |
| 408 | 417 | // check for conflicts |
| 409 | 418 | $this->lazyLoadConflicts(); |
| 410 | 419 | if($this->memChanges->IsChanged($id)) { |
| 411 | 420 | ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Conflict detected. Data from Server will be dropped! PIM deleted object.", $id)); |
| 412 | - } |
|
| 413 | - elseif($this->memChanges->IsDeleted($id)) { |
|
| 421 | + } elseif($this->memChanges->IsDeleted($id)) { |
|
| 414 | 422 | ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Conflict detected. Data is already deleted. Request will be ignored.", $id)); |
| 415 | 423 | return true; |
| 416 | 424 | } |
| 417 | 425 | |
| 418 | 426 | // do a 'soft' delete so people can un-delete if necessary |
| 419 | - if(mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($sk)))) |
|
| 420 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Error updating object: 0x%X", $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 427 | + if(mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($sk)))) { |
|
| 428 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Error updating object: 0x%X", $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 429 | + } |
|
| 421 | 430 | |
| 422 | 431 | return true; |
| 423 | 432 | } |
@@ -446,8 +455,9 @@ discard block |
||
| 446 | 455 | if ($this->folderidHex == $fsk || empty($fsk)) { |
| 447 | 456 | |
| 448 | 457 | // check if it is in the synchronization interval and/or shared+private |
| 449 | - if (!$this->isModificationAllowed($sk)) |
|
| 450 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Flag update is not allowed. Flags not updated.", $id, $flags), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 458 | + if (!$this->isModificationAllowed($sk)) { |
|
| 459 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Flag update is not allowed. Flags not updated.", $id, $flags), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 460 | + } |
|
| 451 | 461 | |
| 452 | 462 | // check for conflicts |
| 453 | 463 | /* |
@@ -463,8 +473,9 @@ discard block |
||
| 463 | 473 | |
| 464 | 474 | $readstate = array ( "sourcekey" => hex2bin($sk), "flags" => $flags); |
| 465 | 475 | |
| 466 | - if(!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate) )) |
|
| 467 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Error setting read state: 0x%X", $id, $flags, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 476 | + if(!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate) )) { |
|
| 477 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Error setting read state: 0x%X", $id, $flags, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 478 | + } |
|
| 468 | 479 | } |
| 469 | 480 | // yeah OL sucks - ZP-779 |
| 470 | 481 | else { |
@@ -475,8 +486,9 @@ discard block |
||
| 475 | 486 | $entryid = mapi_msgstore_entryidfromsourcekey($store, hex2bin($fsk), hex2bin($sk)); |
| 476 | 487 | $realMessage = mapi_msgstore_openentry($store, $entryid); |
| 477 | 488 | $flag = 0; |
| 478 | - if ($flags == 0) |
|
| 479 | - $flag |= CLEAR_READ_FLAG; |
|
| 489 | + if ($flags == 0) { |
|
| 490 | + $flag |= CLEAR_READ_FLAG; |
|
| 491 | + } |
|
| 480 | 492 | $p = mapi_message_setreadflag($realMessage, $flag); |
| 481 | 493 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): setting readflag on message: 0x%X", $id, $flags, mapi_last_hresult())); |
| 482 | 494 | } |
@@ -502,8 +514,9 @@ discard block |
||
| 502 | 514 | */ |
| 503 | 515 | public function ImportMessageMove($id, $newfolder) { |
| 504 | 516 | list(,$sk) = Utils::SplitMessageId($id); |
| 505 | - if (strtolower($newfolder) == strtolower(bin2hex($this->folderid)) ) |
|
| 506 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, source and destination are equal", $id, $newfolder), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST); |
|
| 517 | + if (strtolower($newfolder) == strtolower(bin2hex($this->folderid)) ) { |
|
| 518 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, source and destination are equal", $id, $newfolder), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST); |
|
| 519 | + } |
|
| 507 | 520 | |
| 508 | 521 | // Get the entryid of the message we're moving |
| 509 | 522 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid, hex2bin($sk)); |
@@ -526,47 +539,57 @@ discard block |
||
| 526 | 539 | } |
| 527 | 540 | |
| 528 | 541 | // check if it is in the synchronization interval and/or shared+private |
| 529 | - if (!$this->isModificationAllowed($sk)) |
|
| 530 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Source message move is not allowed. Move not performed.", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 542 | + if (!$this->isModificationAllowed($sk)) { |
|
| 543 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Source message move is not allowed. Move not performed.", $id, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 544 | + } |
|
| 531 | 545 | |
| 532 | 546 | // get correct mapi store for the destination folder |
| 533 | 547 | $dststore = ZPush::GetBackend()->GetMAPIStoreForFolderId(ZPush::GetAdditionalSyncFolderStore($newfolder), $newfolder); |
| 534 | - if ($dststore === false) |
|
| 535 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open store of destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 548 | + if ($dststore === false) { |
|
| 549 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open store of destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 550 | + } |
|
| 536 | 551 | |
| 537 | 552 | $dstentryid = mapi_msgstore_entryidfromsourcekey($dststore, hex2bin($newfolder)); |
| 538 | - if(!$dstentryid) |
|
| 539 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 553 | + if(!$dstentryid) { |
|
| 554 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 555 | + } |
|
| 540 | 556 | |
| 541 | 557 | $dstfolder = mapi_msgstore_openentry($dststore, $dstentryid); |
| 542 | - if(!$dstfolder) |
|
| 543 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 558 | + if(!$dstfolder) { |
|
| 559 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 560 | + } |
|
| 544 | 561 | |
| 545 | 562 | $newmessage = mapi_folder_createmessage($dstfolder); |
| 546 | - if (!$newmessage) |
|
| 547 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to create message in destination folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 563 | + if (!$newmessage) { |
|
| 564 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to create message in destination folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
|
| 565 | + } |
|
| 548 | 566 | |
| 549 | 567 | // Copy message |
| 550 | 568 | mapi_copyto($srcmessage, array(), array(), $newmessage); |
| 551 | - if (mapi_last_hresult()) |
|
| 552 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, copy to destination message failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); |
|
| 569 | + if (mapi_last_hresult()) { |
|
| 570 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, copy to destination message failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); |
|
| 571 | + } |
|
| 553 | 572 | |
| 554 | 573 | $srcfolderentryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid); |
| 555 | - if(!$srcfolderentryid) |
|
| 556 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 574 | + if(!$srcfolderentryid) { |
|
| 575 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 576 | + } |
|
| 557 | 577 | |
| 558 | 578 | $srcfolder = mapi_msgstore_openentry($this->store, $srcfolderentryid); |
| 559 | - if (!$srcfolder) |
|
| 560 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 579 | + if (!$srcfolder) { |
|
| 580 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open source folder: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 581 | + } |
|
| 561 | 582 | |
| 562 | 583 | // Save changes |
| 563 | 584 | mapi_savechanges($newmessage); |
| 564 | - if (mapi_last_hresult()) |
|
| 565 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); |
|
| 585 | + if (mapi_last_hresult()) { |
|
| 586 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, mapi_savechanges() failed: 0x%X", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); |
|
| 587 | + } |
|
| 566 | 588 | |
| 567 | 589 | // Delete the old message |
| 568 | - if (!mapi_folder_deletemessages($srcfolder, array($entryid))) |
|
| 569 | - throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, delete of source message failed: 0x%X. Possible duplicates.", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_SOURCEORDESTLOCKED); |
|
| 590 | + if (!mapi_folder_deletemessages($srcfolder, array($entryid))) { |
|
| 591 | + throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, delete of source message failed: 0x%X. Possible duplicates.", $sk, $newfolder, mapi_last_hresult()), SYNC_MOVEITEMSSTATUS_SOURCEORDESTLOCKED); |
|
| 592 | + } |
|
| 570 | 593 | |
| 571 | 594 | $sourcekeyprops = mapi_getprops($newmessage, array (PR_SOURCE_KEY)); |
| 572 | 595 | if (isset($sourcekeyprops[PR_SOURCE_KEY]) && $sourcekeyprops[PR_SOURCE_KEY]) { |
@@ -603,8 +626,9 @@ discard block |
||
| 603 | 626 | $displayname = u2wi($folder->displayname); |
| 604 | 627 | $type = $folder->type; |
| 605 | 628 | |
| 606 | - if (Utils::IsSystemFolder($type)) |
|
| 607 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 629 | + if (Utils::IsSystemFolder($type)) { |
|
| 630 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 631 | + } |
|
| 608 | 632 | |
| 609 | 633 | // create a new folder if $id is not set |
| 610 | 634 | if (!$id) { |
@@ -613,25 +637,27 @@ discard block |
||
| 613 | 637 | $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID, PR_IPM_PUBLIC_FOLDERS_ENTRYID)); |
| 614 | 638 | if (ZPush::GetBackend()->GetImpersonatedUser() == 'system' && isset($parentprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID])) { |
| 615 | 639 | $parentfentryid = $parentprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID]; |
| 616 | - } |
|
| 617 | - elseif (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) { |
|
| 640 | + } elseif (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) { |
|
| 618 | 641 | $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID]; |
| 619 | 642 | } |
| 643 | + } else { |
|
| 644 | + $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent)); |
|
| 620 | 645 | } |
| 621 | - else |
|
| 622 | - $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent)); |
|
| 623 | 646 | |
| 624 | - if (!$parentfentryid) |
|
| 625 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 647 | + if (!$parentfentryid) { |
|
| 648 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 649 | + } |
|
| 626 | 650 | |
| 627 | 651 | $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid); |
| 628 | - if (!$parentfolder) |
|
| 629 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 652 | + if (!$parentfolder) { |
|
| 653 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 654 | + } |
|
| 630 | 655 | |
| 631 | 656 | // mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION |
| 632 | 657 | $newfolder = mapi_folder_createfolder($parentfolder, $displayname, ""); |
| 633 | - if (mapi_last_hresult()) |
|
| 634 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS); |
|
| 658 | + if (mapi_last_hresult()) { |
|
| 659 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS); |
|
| 660 | + } |
|
| 635 | 661 | |
| 636 | 662 | mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type))); |
| 637 | 663 | |
@@ -645,35 +671,38 @@ discard block |
||
| 645 | 671 | $folder->serverid = ZPush::GetDeviceManager()->GetFolderIdForBackendId($folder->BackendId, true, $folderOrigin, $folder->displayname); |
| 646 | 672 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderChange(): Created folder '%s' with id: '%s' backendid: '%s'", $displayname, $folder->serverid, $folder->BackendId)); |
| 647 | 673 | return $folder; |
| 674 | + } else { |
|
| 675 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 648 | 676 | } |
| 649 | - else |
|
| 650 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 651 | 677 | } |
| 652 | 678 | |
| 653 | 679 | // open folder for update |
| 654 | 680 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id)); |
| 655 | - if (!$entryid) |
|
| 656 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 681 | + if (!$entryid) { |
|
| 682 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 683 | + } |
|
| 657 | 684 | |
| 658 | 685 | // check if this is a MAPI default folder |
| 659 | - if ($this->mapiprovider->IsMAPIDefaultFolder($entryid)) |
|
| 660 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, MAPI default folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 686 | + if ($this->mapiprovider->IsMAPIDefaultFolder($entryid)) { |
|
| 687 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, MAPI default folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 688 | + } |
|
| 661 | 689 | |
| 662 | 690 | $mfolder = mapi_msgstore_openentry($this->store, $entryid); |
| 663 | - if (!$mfolder) |
|
| 664 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 691 | + if (!$mfolder) { |
|
| 692 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 693 | + } |
|
| 665 | 694 | |
| 666 | 695 | $props = mapi_getprops($mfolder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS)); |
| 667 | - if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) |
|
| 668 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 696 | + if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) { |
|
| 697 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 698 | + } |
|
| 669 | 699 | |
| 670 | 700 | // get the real parent source key from mapi |
| 671 | 701 | if ($parent == "0") { |
| 672 | 702 | $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID, PR_IPM_PUBLIC_FOLDERS_ENTRYID)); |
| 673 | 703 | if (ZPush::GetBackend()->GetImpersonatedUser() == 'system') { |
| 674 | 704 | $parentfentryid = $parentprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID]; |
| 675 | - } |
|
| 676 | - else { |
|
| 705 | + } else { |
|
| 677 | 706 | $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID]; |
| 678 | 707 | } |
| 679 | 708 | $mapifolder = mapi_msgstore_openentry($this->store, $parentfentryid); |
@@ -686,24 +715,29 @@ discard block |
||
| 686 | 715 | // a changed parent id means that the folder should be moved |
| 687 | 716 | if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) { |
| 688 | 717 | $sourceparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, $props[PR_PARENT_SOURCE_KEY]); |
| 689 | - if(!$sourceparentfentryid) |
|
| 690 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 718 | + if(!$sourceparentfentryid) { |
|
| 719 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 720 | + } |
|
| 691 | 721 | |
| 692 | 722 | $sourceparentfolder = mapi_msgstore_openentry($this->store, $sourceparentfentryid); |
| 693 | - if(!$sourceparentfolder) |
|
| 694 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 723 | + if(!$sourceparentfolder) { |
|
| 724 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND); |
|
| 725 | + } |
|
| 695 | 726 | |
| 696 | 727 | $destparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent)); |
| 697 | - if(!$sourceparentfentryid) |
|
| 698 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 728 | + if(!$sourceparentfentryid) { |
|
| 729 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 730 | + } |
|
| 699 | 731 | |
| 700 | 732 | $destfolder = mapi_msgstore_openentry($this->store, $destparentfentryid); |
| 701 | - if(!$destfolder) |
|
| 702 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 733 | + if(!$destfolder) { |
|
| 734 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 735 | + } |
|
| 703 | 736 | |
| 704 | 737 | // mapi_folder_copyfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION |
| 705 | - if(! mapi_folder_copyfolder($sourceparentfolder, $entryid, $destfolder, $displayname, FOLDER_MOVE)) |
|
| 706 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to move folder: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS); |
|
| 738 | + if(! mapi_folder_copyfolder($sourceparentfolder, $entryid, $destfolder, $displayname, FOLDER_MOVE)) { |
|
| 739 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to move folder: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS); |
|
| 740 | + } |
|
| 707 | 741 | |
| 708 | 742 | // the parent changed, but we got a backendID as parent and have to return an AS folderid - the parent-backendId must be mapped at this point already |
| 709 | 743 | if ($folder->parentid != 0) { |
@@ -718,8 +752,9 @@ discard block |
||
| 718 | 752 | $props = array(PR_DISPLAY_NAME => $displayname); |
| 719 | 753 | mapi_setprops($mfolder, $props); |
| 720 | 754 | mapi_savechanges($mfolder); |
| 721 | - if (mapi_last_hresult()) |
|
| 722 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 755 | + if (mapi_last_hresult()) { |
|
| 756 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 757 | + } |
|
| 723 | 758 | |
| 724 | 759 | ZLog::Write(LOGLEVEL_DEBUG, "Imported changes for folder: $id"); |
| 725 | 760 | return true; |
@@ -740,18 +775,21 @@ discard block |
||
| 740 | 775 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): importing folder deletetion", $id, $parent)); |
| 741 | 776 | |
| 742 | 777 | $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id)); |
| 743 | - if(!$folderentryid) |
|
| 744 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error, unable to resolve folder", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_FOLDERDOESNOTEXIST); |
|
| 778 | + if(!$folderentryid) { |
|
| 779 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error, unable to resolve folder", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_FOLDERDOESNOTEXIST); |
|
| 780 | + } |
|
| 745 | 781 | |
| 746 | 782 | // get the folder type from the MAPIProvider |
| 747 | 783 | $type = $this->mapiprovider->GetFolderType($folderentryid); |
| 748 | 784 | |
| 749 | - if (Utils::IsSystemFolder($type) || $this->mapiprovider->IsMAPIDefaultFolder($folderentryid)) |
|
| 750 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting system/default folder", $id, $parent), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 785 | + if (Utils::IsSystemFolder($type) || $this->mapiprovider->IsMAPIDefaultFolder($folderentryid)) { |
|
| 786 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting system/default folder", $id, $parent), SYNC_FSSTATUS_SYSTEMFOLDER); |
|
| 787 | + } |
|
| 751 | 788 | |
| 752 | 789 | $ret = mapi_importhierarchychanges_importfolderdeletion ($this->importer, 0, array(PR_SOURCE_KEY => hex2bin($id))); |
| 753 | - if (!$ret) |
|
| 754 | - throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting folder: 0x%X", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 790 | + if (!$ret) { |
|
| 791 | + throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting folder: 0x%X", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
|
| 792 | + } |
|
| 755 | 793 | |
| 756 | 794 | return $ret; |
| 757 | 795 | } |
@@ -34,8 +34,9 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $phase2 = true; |
| 36 | 36 | |
| 37 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_PROVISION)) |
|
| 38 | - return false; |
|
| 37 | + if(!self::$decoder->getElementStartTag(SYNC_PROVISION_PROVISION)) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | // Loop through Provision request tags. Possible are: |
| 41 | 42 | // - Remote Wipe |
@@ -55,22 +56,26 @@ discard block |
||
| 55 | 56 | $requestName = SYNC_SETTINGS_DEVICEINFORMATION; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - if (!$requestName) |
|
| 59 | - break; |
|
| 59 | + if (!$requestName) { |
|
| 60 | + break; |
|
| 61 | + } |
|
| 60 | 62 | |
| 61 | 63 | //set is available for OOF, device password and device information |
| 62 | 64 | switch ($requestName) { |
| 63 | 65 | case SYNC_PROVISION_REMOTEWIPE: |
| 64 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
| 65 | - return false; |
|
| 66 | + if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 66 | 69 | |
| 67 | 70 | $instatus = self::$decoder->getElementContent(); |
| 68 | 71 | |
| 69 | - if(!self::$decoder->getElementEndTag()) |
|
| 70 | - return false; |
|
| 72 | + if(!self::$decoder->getElementEndTag()) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | - if(!self::$decoder->getElementEndTag()) |
|
| 73 | - return false; |
|
| 76 | + if(!self::$decoder->getElementEndTag()) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 74 | 79 | |
| 75 | 80 | $phase2 = false; |
| 76 | 81 | $rwstatusWiped = true; |
@@ -78,47 +83,59 @@ discard block |
||
| 78 | 83 | break; |
| 79 | 84 | |
| 80 | 85 | case SYNC_PROVISION_POLICIES: |
| 81 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICY)) |
|
| 82 | - return false; |
|
| 86 | + if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICY)) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 83 | 89 | |
| 84 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYTYPE)) |
|
| 85 | - return false; |
|
| 90 | + if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYTYPE)) { |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | $policytype = self::$decoder->getElementContent(); |
| 88 | 95 | if ($policytype != 'MS-WAP-Provisioning-XML' && $policytype != 'MS-EAS-Provisioning-WBXML') { |
| 89 | 96 | $status = SYNC_PROVISION_STATUS_SERVERERROR; |
| 90 | 97 | } |
| 91 | - if(!self::$decoder->getElementEndTag()) //policytype |
|
| 98 | + if(!self::$decoder->getElementEndTag()) { |
|
| 99 | + //policytype |
|
| 92 | 100 | return false; |
| 101 | + } |
|
| 93 | 102 | |
| 94 | 103 | if (self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYKEY)) { |
| 95 | 104 | $devpolicykey = self::$decoder->getElementContent(); |
| 96 | 105 | |
| 97 | - if(!self::$decoder->getElementEndTag()) |
|
| 98 | - return false; |
|
| 106 | + if(!self::$decoder->getElementEndTag()) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 99 | 109 | |
| 100 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
| 101 | - return false; |
|
| 110 | + if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 102 | 113 | |
| 103 | 114 | $instatus = self::$decoder->getElementContent(); |
| 104 | 115 | |
| 105 | - if(!self::$decoder->getElementEndTag()) |
|
| 106 | - return false; |
|
| 116 | + if(!self::$decoder->getElementEndTag()) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 107 | 119 | |
| 108 | 120 | $phase2 = false; |
| 109 | 121 | } |
| 110 | 122 | |
| 111 | - if(!self::$decoder->getElementEndTag()) //policy |
|
| 123 | + if(!self::$decoder->getElementEndTag()) { |
|
| 124 | + //policy |
|
| 112 | 125 | return false; |
| 126 | + } |
|
| 113 | 127 | |
| 114 | - if(!self::$decoder->getElementEndTag()) //policies |
|
| 128 | + if(!self::$decoder->getElementEndTag()) { |
|
| 129 | + //policies |
|
| 115 | 130 | return false; |
| 131 | + } |
|
| 116 | 132 | break; |
| 117 | 133 | |
| 118 | 134 | case SYNC_SETTINGS_DEVICEINFORMATION: |
| 119 | 135 | // AS14.1 and later clients pass Device Information on the initial Provision request |
| 120 | - if (!self::$decoder->getElementStartTag(SYNC_SETTINGS_SET)) |
|
| 121 | - return false; |
|
| 136 | + if (!self::$decoder->getElementStartTag(SYNC_SETTINGS_SET)) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 122 | 139 | $deviceInfoSet = true; |
| 123 | 140 | $deviceinformation = new SyncDeviceInformation(); |
| 124 | 141 | $deviceinformation->Decode(self::$decoder); |
@@ -126,14 +143,17 @@ discard block |
||
| 126 | 143 | if (! $wipeRequest) { |
| 127 | 144 | // for this operation the device manager is available |
| 128 | 145 | ZPush::GetDeviceManager()->SaveDeviceInformation($deviceinformation); |
| 129 | - } |
|
| 130 | - else { |
|
| 146 | + } else { |
|
| 131 | 147 | ZLog::Write(LOGLEVEL_DEBUG, "Ignoring incoming device information as WIPE is due."); |
| 132 | 148 | } |
| 133 | - if (!self::$decoder->getElementEndTag()) // SYNC_SETTINGS_SET |
|
| 149 | + if (!self::$decoder->getElementEndTag()) { |
|
| 150 | + // SYNC_SETTINGS_SET |
|
| 134 | 151 | return false; |
| 135 | - if (!self::$decoder->getElementEndTag()) // SYNC_SETTINGS_DEVICEINFORMATION |
|
| 152 | + } |
|
| 153 | + if (!self::$decoder->getElementEndTag()) { |
|
| 154 | + // SYNC_SETTINGS_DEVICEINFORMATION |
|
| 136 | 155 | return false; |
| 156 | + } |
|
| 137 | 157 | break; |
| 138 | 158 | |
| 139 | 159 | default: |
@@ -143,8 +163,10 @@ discard block |
||
| 143 | 163 | |
| 144 | 164 | } |
| 145 | 165 | |
| 146 | - if(!self::$decoder->getElementEndTag()) //provision |
|
| 166 | + if(!self::$decoder->getElementEndTag()) { |
|
| 167 | + //provision |
|
| 147 | 168 | return false; |
| 169 | + } |
|
| 148 | 170 | |
| 149 | 171 | if (PROVISIONING !== true) { |
| 150 | 172 | ZLog::Write(LOGLEVEL_INFO, "No policies deployed to device"); |
@@ -191,20 +213,19 @@ discard block |
||
| 191 | 213 | self::$encoder->startTag(SYNC_PROVISION_DATA); |
| 192 | 214 | if ($policytype == 'MS-WAP-Provisioning-XML') { |
| 193 | 215 | self::$encoder->content('<wap-provisioningdoc><characteristic type="SecurityPolicy"><parm name="4131" value="1"/><parm name="4133" value="1"/></characteristic></wap-provisioningdoc>'); |
| 194 | - } |
|
| 195 | - elseif ($policytype == 'MS-EAS-Provisioning-WBXML') { |
|
| 216 | + } elseif ($policytype == 'MS-EAS-Provisioning-WBXML') { |
|
| 196 | 217 | self::$encoder->startTag(SYNC_PROVISION_EASPROVISIONDOC); |
| 197 | 218 | |
| 198 | 219 | // get the provisioning object and log the loaded policy values |
| 199 | 220 | $prov = ZPush::GetProvisioningManager()->GetProvisioningObject(true); |
| 200 | - if (!$prov->Check()) |
|
| 201 | - throw new FatalException("Invalid policies!"); |
|
| 221 | + if (!$prov->Check()) { |
|
| 222 | + throw new FatalException("Invalid policies!"); |
|
| 223 | + } |
|
| 202 | 224 | |
| 203 | 225 | ZPush::GetProvisioningManager()->SavePolicyHash($prov); |
| 204 | 226 | $prov->Encode(self::$encoder); |
| 205 | 227 | self::$encoder->endTag(); |
| 206 | - } |
|
| 207 | - else { |
|
| 228 | + } else { |
|
| 208 | 229 | ZLog::Write(LOGLEVEL_WARN, "Wrong policy type"); |
| 209 | 230 | self::$topCollector->AnnounceInformation("Policytype not supported", true); |
| 210 | 231 | return false; |
@@ -18,35 +18,41 @@ discard block |
||
| 18 | 18 | * @return boolean |
| 19 | 19 | */ |
| 20 | 20 | public function Handle($commandCode) { |
| 21 | - if(!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES)) |
|
| 22 | - return false; |
|
| 21 | + if(!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 23 | 24 | |
| 24 | 25 | $moves = array(); |
| 25 | 26 | while(self::$decoder->getElementStartTag(SYNC_MOVE_MOVE)) { |
| 26 | 27 | $move = array(); |
| 27 | 28 | if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCMSGID)) { |
| 28 | 29 | $move["srcmsgid"] = self::$decoder->getElementContent(); |
| 29 | - if(!self::$decoder->getElementEndTag()) |
|
| 30 | - break; |
|
| 30 | + if(!self::$decoder->getElementEndTag()) { |
|
| 31 | + break; |
|
| 32 | + } |
|
| 31 | 33 | } |
| 32 | 34 | if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCFLDID)) { |
| 33 | 35 | $move["srcfldid"] = self::$decoder->getElementContent(); |
| 34 | - if(!self::$decoder->getElementEndTag()) |
|
| 35 | - break; |
|
| 36 | + if(!self::$decoder->getElementEndTag()) { |
|
| 37 | + break; |
|
| 38 | + } |
|
| 36 | 39 | } |
| 37 | 40 | if(self::$decoder->getElementStartTag(SYNC_MOVE_DSTFLDID)) { |
| 38 | 41 | $move["dstfldid"] = self::$decoder->getElementContent(); |
| 39 | - if(!self::$decoder->getElementEndTag()) |
|
| 40 | - break; |
|
| 42 | + if(!self::$decoder->getElementEndTag()) { |
|
| 43 | + break; |
|
| 44 | + } |
|
| 41 | 45 | } |
| 42 | 46 | array_push($moves, $move); |
| 43 | 47 | |
| 44 | - if(!self::$decoder->getElementEndTag()) |
|
| 45 | - return false; |
|
| 48 | + if(!self::$decoder->getElementEndTag()) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 46 | 51 | } |
| 47 | 52 | |
| 48 | - if(!self::$decoder->getElementEndTag()) |
|
| 49 | - return false; |
|
| 53 | + if(!self::$decoder->getElementEndTag()) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 50 | 56 | |
| 51 | 57 | self::$encoder->StartWBXML(); |
| 52 | 58 | |
@@ -68,28 +74,32 @@ discard block |
||
| 68 | 74 | $sourceBackendFolderId = self::$deviceManager->GetBackendIdForFolderId($move["srcfldid"]); |
| 69 | 75 | |
| 70 | 76 | // if the source folder is an additional folder the backend has to be setup correctly |
| 71 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($sourceBackendFolderId))) |
|
| 72 | - throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id %s/%s", $move["srcfldid"], $sourceBackendFolderId), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 77 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($sourceBackendFolderId))) { |
|
| 78 | + throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id %s/%s", $move["srcfldid"], $sourceBackendFolderId), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 79 | + } |
|
| 73 | 80 | |
| 74 | 81 | $importer = self::$backend->GetImporter($sourceBackendFolderId); |
| 75 | - if ($importer === false) |
|
| 76 | - throw new StatusException(sprintf("HandleMoveItems() could not get an importer for folder id %s/%s", $move["srcfldid"], $sourceBackendFolderId), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 82 | + if ($importer === false) { |
|
| 83 | + throw new StatusException(sprintf("HandleMoveItems() could not get an importer for folder id %s/%s", $move["srcfldid"], $sourceBackendFolderId), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 84 | + } |
|
| 77 | 85 | |
| 78 | 86 | // get saved SyncParameters of the source folder |
| 79 | 87 | $spa = self::$deviceManager->GetStateManager()->GetSynchedFolderState($move["srcfldid"]); |
| 80 | - if (!$spa->HasSyncKey()) |
|
| 81 | - throw new StatusException(sprintf("MoveItems(): Source folder id '%s' is not fully synchronized. Unable to perform operation.", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 88 | + if (!$spa->HasSyncKey()) { |
|
| 89 | + throw new StatusException(sprintf("MoveItems(): Source folder id '%s' is not fully synchronized. Unable to perform operation.", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
|
| 90 | + } |
|
| 82 | 91 | |
| 83 | 92 | $importer->ConfigContentParameters($spa->GetCPO()); |
| 84 | 93 | |
| 85 | 94 | $result = $importer->ImportMessageMove($move["srcmsgid"], self::$deviceManager->GetBackendIdForFolderId($move["dstfldid"])); |
| 86 | 95 | // We discard the standard importer state for now. |
| 87 | - } |
|
| 88 | - catch (StatusException $stex) { |
|
| 89 | - if ($stex->getCode() == SYNC_STATUS_FOLDERHIERARCHYCHANGED) // same as SYNC_FSSTATUS_CODEUNKNOWN |
|
| 96 | + } catch (StatusException $stex) { |
|
| 97 | + if ($stex->getCode() == SYNC_STATUS_FOLDERHIERARCHYCHANGED) { |
|
| 98 | + // same as SYNC_FSSTATUS_CODEUNKNOWN |
|
| 90 | 99 | $status = SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID; |
| 91 | - else |
|
| 92 | - $status = $stex->getCode(); |
|
| 100 | + } else { |
|
| 101 | + $status = $stex->getCode(); |
|
| 102 | + } |
|
| 93 | 103 | } |
| 94 | 104 | |
| 95 | 105 | if ($operationCounter % 10 == 0) { |
@@ -21,13 +21,13 @@ |
||
| 21 | 21 | public function Handle($commandCode) { |
| 22 | 22 | try { |
| 23 | 23 | $folders = self::$backend->GetHierarchy(); |
| 24 | - if (!$folders || empty($folders)) |
|
| 25 | - throw new StatusException("GetHierarchy() did not return any data."); |
|
| 24 | + if (!$folders || empty($folders)) { |
|
| 25 | + throw new StatusException("GetHierarchy() did not return any data."); |
|
| 26 | + } |
|
| 26 | 27 | |
| 27 | 28 | // TODO execute $data->Check() to see if SyncObject is valid |
| 28 | 29 | |
| 29 | - } |
|
| 30 | - catch (StatusException $ex) { |
|
| 30 | + } catch (StatusException $ex) { |
|
| 31 | 31 | return false; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -19,8 +19,9 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function Handle($commandCode) { |
| 21 | 21 | // Parse input |
| 22 | - if(!self::$decoder->getElementStartTag(SYNC_VALIDATECERT_VALIDATECERT)) |
|
| 23 | - return false; |
|
| 22 | + if(!self::$decoder->getElementStartTag(SYNC_VALIDATECERT_VALIDATECERT)) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 24 | 25 | |
| 25 | 26 | $validateCert = new SyncValidateCert(); |
| 26 | 27 | $validateCert->Decode(self::$decoder); |
@@ -28,13 +29,16 @@ discard block |
||
| 28 | 29 | $cert_pem = "-----BEGIN CERTIFICATE-----\n".chunk_split(base64_encode($cert_der), 64, "\n")."-----END CERTIFICATE-----\n"; |
| 29 | 30 | |
| 30 | 31 | $checkpurpose = (defined('CAINFO') && CAINFO) ? openssl_x509_checkpurpose($cert_pem, X509_PURPOSE_SMIME_SIGN, array(CAINFO)) : openssl_x509_checkpurpose($cert_pem, X509_PURPOSE_SMIME_SIGN); |
| 31 | - if ($checkpurpose === true) |
|
| 32 | - $status = SYNC_VALIDATECERTSTATUS_SUCCESS; |
|
| 33 | - else |
|
| 34 | - $status = SYNC_VALIDATECERTSTATUS_CANTVALIDATESIG; |
|
| 35 | - |
|
| 36 | - if(!self::$decoder->getElementEndTag()) |
|
| 37 | - return false; // SYNC_VALIDATECERT_VALIDATECERT |
|
| 32 | + if ($checkpurpose === true) { |
|
| 33 | + $status = SYNC_VALIDATECERTSTATUS_SUCCESS; |
|
| 34 | + } else { |
|
| 35 | + $status = SYNC_VALIDATECERTSTATUS_CANTVALIDATESIG; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if(!self::$decoder->getElementEndTag()) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 41 | + // SYNC_VALIDATECERT_VALIDATECERT |
|
| 38 | 42 | |
| 39 | 43 | self::$encoder->startWBXML(); |
| 40 | 44 | self::$encoder->startTag(SYNC_VALIDATECERT_VALIDATECERT); |
@@ -18,17 +18,21 @@ |
||
| 18 | 18 | * @return boolean |
| 19 | 19 | */ |
| 20 | 20 | public function Handle($commandCode) { |
| 21 | - if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_NOTIFY)) |
|
| 22 | - return false; |
|
| 21 | + if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_NOTIFY)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 23 | 24 | |
| 24 | - if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_DEVICEINFO)) |
|
| 25 | - return false; |
|
| 25 | + if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_DEVICEINFO)) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | - if(!self::$decoder->getElementEndTag()) |
|
| 28 | - return false; |
|
| 29 | + if(!self::$decoder->getElementEndTag()) { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 29 | 32 | |
| 30 | - if(!self::$decoder->getElementEndTag()) |
|
| 31 | - return false; |
|
| 33 | + if(!self::$decoder->getElementEndTag()) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 32 | 36 | |
| 33 | 37 | self::$encoder->StartWBXML(); |
| 34 | 38 | |
@@ -32,27 +32,23 @@ discard block |
||
| 32 | 32 | // Load all collections - do load states, check permissions and allow unconfirmed states |
| 33 | 33 | try { |
| 34 | 34 | $sc->LoadAllCollections(true, true, true, true, false); |
| 35 | - } |
|
| 36 | - catch (StateInvalidException $siex) { |
|
| 35 | + } catch (StateInvalidException $siex) { |
|
| 37 | 36 | // if no params are present, indicate to send params, else do hierarchy sync |
| 38 | 37 | if (!$params_present) { |
| 39 | 38 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
| 40 | 39 | self::$topCollector->AnnounceInformation("StateInvalidException: require PingParameters", true); |
| 41 | - } |
|
| 42 | - elseif (self::$deviceManager->IsHierarchySyncRequired()) { |
|
| 40 | + } elseif (self::$deviceManager->IsHierarchySyncRequired()) { |
|
| 43 | 41 | // we could be in a looping - see LoopDetection->ProcessLoopDetectionIsHierarchySyncAdvised() |
| 44 | 42 | $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED; |
| 45 | 43 | self::$topCollector->AnnounceInformation("Potential loop detection: require HierarchySync", true); |
| 46 | - } |
|
| 47 | - else { |
|
| 44 | + } else { |
|
| 48 | 45 | // we do not have a ping status for this, but SyncCollections should have generated fake changes for the folders which are broken |
| 49 | 46 | $fakechanges = $sc->GetChangedFolderIds(); |
| 50 | 47 | $foundchanges = true; |
| 51 | 48 | |
| 52 | 49 | self::$topCollector->AnnounceInformation("StateInvalidException: force sync", true); |
| 53 | 50 | } |
| 54 | - } |
|
| 55 | - catch (StatusException $stex) { |
|
| 51 | + } catch (StatusException $stex) { |
|
| 56 | 52 | $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED; |
| 57 | 53 | self::$topCollector->AnnounceInformation("StatusException: require HierarchySync", true); |
| 58 | 54 | } |
@@ -103,8 +99,7 @@ discard block |
||
| 103 | 99 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): ignoring folder id '%s' as it's of type UNKNOWN ", $folderid)); |
| 104 | 100 | continue; |
| 105 | 101 | } |
| 106 | - } |
|
| 107 | - catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 102 | + } catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 108 | 103 | ZLog::Write(LOGLEVEL_INFO, sprintf("HandlePing(): unknown collection '%s', triggering HierarchySync", $folderid)); |
| 109 | 104 | $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED; |
| 110 | 105 | } |
@@ -112,36 +107,37 @@ discard block |
||
| 112 | 107 | // Trigger a Sync request because then the device will be forced to resync this folder. |
| 113 | 108 | $fakechanges[$folderid] = 1; |
| 114 | 109 | $foundchanges = true; |
| 115 | - } |
|
| 116 | - else if ($class == $spa->GetContentClass()) { |
|
| 110 | + } else if ($class == $spa->GetContentClass()) { |
|
| 117 | 111 | $pingable[] = $folderid; |
| 118 | 112 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): using saved sync state for '%s' id '%s'", $spa->GetContentClass(), $folderid)); |
| 119 | 113 | } |
| 120 | 114 | } |
| 121 | - if(!self::$decoder->getElementEndTag()) |
|
| 122 | - return false; |
|
| 115 | + if(!self::$decoder->getElementEndTag()) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 123 | 118 | |
| 124 | 119 | // update pingable flags |
| 125 | 120 | foreach ($sc as $folderid => $spa) { |
| 126 | 121 | // if the folderid is in $pingable, we should ping it, else remove the flag |
| 127 | 122 | if (in_array($folderid, $pingable)) { |
| 128 | 123 | $spa->SetPingableFlag(true); |
| 129 | - } |
|
| 130 | - else { |
|
| 124 | + } else { |
|
| 131 | 125 | $spa->DelPingableFlag(); |
| 132 | 126 | } |
| 133 | 127 | } |
| 134 | 128 | } |
| 135 | - if(!self::$decoder->getElementEndTag()) |
|
| 136 | - return false; |
|
| 129 | + if(!self::$decoder->getElementEndTag()) { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 137 | 132 | |
| 138 | 133 | if(!$this->lifetimeBetweenBound($sc->GetLifetime())){ |
| 139 | 134 | $pingstatus = SYNC_PINGSTATUS_HBOUTOFRANGE; |
| 140 | 135 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): ping lifetime not between bound (higher bound:'%d' lower bound:'%d' current lifetime:'%d'. Returning SYNC_PINGSTATUS_HBOUTOFRANGE.", PING_HIGHER_BOUND_LIFETIME, PING_LOWER_BOUND_LIFETIME, $sc->GetLifetime())); |
| 141 | 136 | } |
| 142 | 137 | // save changed data |
| 143 | - foreach ($sc as $folderid => $spa) |
|
| 144 | - $sc->SaveCollection($spa); |
|
| 138 | + foreach ($sc as $folderid => $spa) { |
|
| 139 | + $sc->SaveCollection($spa); |
|
| 140 | + } |
|
| 145 | 141 | } // END SYNC_PING_PING |
| 146 | 142 | else { |
| 147 | 143 | // if no ping initialization data was sent, we check if we have pingable folders |
@@ -149,8 +145,7 @@ discard block |
||
| 149 | 145 | if (! $sc->PingableFolders()) { |
| 150 | 146 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
| 151 | 147 | ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): no pingable folders found and no initialization data sent. Returning SYNC_PINGSTATUS_FAILINGPARAMS."); |
| 152 | - } |
|
| 153 | - elseif(!$this->lifetimeBetweenBound($sc->GetLifetime())){ |
|
| 148 | + } elseif(!$this->lifetimeBetweenBound($sc->GetLifetime())){ |
|
| 154 | 149 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
| 155 | 150 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): ping lifetime not between bound (higher bound:'%d' lower bound:'%d' current lifetime:'%d'. Returning SYNC_PINGSTATUS_FAILINGPARAMS.", PING_HIGHER_BOUND_LIFETIME, PING_LOWER_BOUND_LIFETIME, $sc->GetLifetime())); |
| 156 | 151 | } |
@@ -163,8 +158,7 @@ discard block |
||
| 163 | 158 | self::$deviceManager->DoAutomaticASDeviceSaving(false); |
| 164 | 159 | $foundchanges = $sc->CheckForChanges($sc->GetLifetime(), $interval, true); |
| 165 | 160 | } |
| 166 | - } |
|
| 167 | - catch (StatusException $ste) { |
|
| 161 | + } catch (StatusException $ste) { |
|
| 168 | 162 | switch($ste->getCode()) { |
| 169 | 163 | case SyncCollections::ERROR_NO_COLLECTIONS: |
| 170 | 164 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
@@ -186,19 +180,21 @@ discard block |
||
| 186 | 180 | self::$encoder->startTag(SYNC_PING_PING); |
| 187 | 181 | { |
| 188 | 182 | self::$encoder->startTag(SYNC_PING_STATUS); |
| 189 | - if (isset($pingstatus) && $pingstatus) |
|
| 190 | - self::$encoder->content($pingstatus); |
|
| 191 | - else |
|
| 192 | - self::$encoder->content($foundchanges ? SYNC_PINGSTATUS_CHANGES : SYNC_PINGSTATUS_HBEXPIRED); |
|
| 183 | + if (isset($pingstatus) && $pingstatus) { |
|
| 184 | + self::$encoder->content($pingstatus); |
|
| 185 | + } else { |
|
| 186 | + self::$encoder->content($foundchanges ? SYNC_PINGSTATUS_CHANGES : SYNC_PINGSTATUS_HBEXPIRED); |
|
| 187 | + } |
|
| 193 | 188 | self::$encoder->endTag(); |
| 194 | 189 | |
| 195 | 190 | if (! $pingstatus) { |
| 196 | 191 | self::$encoder->startTag(SYNC_PING_FOLDERS); |
| 197 | 192 | |
| 198 | - if (empty($fakechanges)) |
|
| 199 | - $changes = $sc->GetChangedFolderIds(); |
|
| 200 | - else |
|
| 201 | - $changes = $fakechanges; |
|
| 193 | + if (empty($fakechanges)) { |
|
| 194 | + $changes = $sc->GetChangedFolderIds(); |
|
| 195 | + } else { |
|
| 196 | + $changes = $fakechanges; |
|
| 197 | + } |
|
| 202 | 198 | |
| 203 | 199 | $announceAggregated = false; |
| 204 | 200 | if (count($changes) > 1) { |
@@ -213,8 +209,7 @@ discard block |
||
| 213 | 209 | if (empty($fakechanges)) { |
| 214 | 210 | self::$topCollector->AnnounceInformation(sprintf("Found change in %s", $sc->GetCollection($folderid)->GetContentClass()), true); |
| 215 | 211 | } |
| 216 | - } |
|
| 217 | - else { |
|
| 212 | + } else { |
|
| 218 | 213 | $announceAggregated += $changecount; |
| 219 | 214 | } |
| 220 | 215 | self::$deviceManager->AnnounceProcessStatus($folderid, SYNC_PINGSTATUS_CHANGES); |
@@ -224,13 +219,11 @@ discard block |
||
| 224 | 219 | self::$topCollector->AnnounceInformation(sprintf("Found %d changes in %d folders", $announceAggregated, count($changes)), true); |
| 225 | 220 | } |
| 226 | 221 | self::$encoder->endTag(); |
| 227 | - } |
|
| 228 | - elseif($pingstatus == SYNC_PINGSTATUS_HBOUTOFRANGE){ |
|
| 222 | + } elseif($pingstatus == SYNC_PINGSTATUS_HBOUTOFRANGE){ |
|
| 229 | 223 | self::$encoder->startTag(SYNC_PING_LIFETIME); |
| 230 | 224 | if($sc->GetLifetime() > PING_HIGHER_BOUND_LIFETIME){ |
| 231 | 225 | self::$encoder->content(PING_HIGHER_BOUND_LIFETIME); |
| 232 | - } |
|
| 233 | - else{ |
|
| 226 | + } else{ |
|
| 234 | 227 | self::$encoder->content(PING_LOWER_BOUND_LIFETIME); |
| 235 | 228 | } |
| 236 | 229 | self::$encoder->endTag(); |
@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | public function Handle($commandCode) { |
| 21 | 21 | $requests = Array(); |
| 22 | 22 | |
| 23 | - if(!self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_MEETINGRESPONSE)) |
|
| 24 | - return false; |
|
| 23 | + if(!self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_MEETINGRESPONSE)) { |
|
| 24 | + return false; |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | while(self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_REQUEST)) { |
| 27 | 28 | $req = Array(); |
@@ -29,20 +30,23 @@ discard block |
||
| 29 | 30 | while(WBXMLDecoder::InWhile("meetingResponseRequest")) { |
| 30 | 31 | if(self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_USERRESPONSE)) { |
| 31 | 32 | $req["response"] = self::$decoder->getElementContent(); |
| 32 | - if(!self::$decoder->getElementEndTag()) |
|
| 33 | - return false; |
|
| 33 | + if(!self::$decoder->getElementEndTag()) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | if(self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_FOLDERID)) { |
| 37 | 39 | $req["folderid"] = self::$decoder->getElementContent(); |
| 38 | - if(!self::$decoder->getElementEndTag()) |
|
| 39 | - return false; |
|
| 40 | + if(!self::$decoder->getElementEndTag()) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | if(self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_REQUESTID)) { |
| 43 | 46 | $req["requestid"] = self::$decoder->getElementContent(); |
| 44 | - if(!self::$decoder->getElementEndTag()) |
|
| 45 | - return false; |
|
| 47 | + if(!self::$decoder->getElementEndTag()) { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 46 | 50 | } |
| 47 | 51 | |
| 48 | 52 | $e = self::$decoder->peek(); |
@@ -54,8 +58,9 @@ discard block |
||
| 54 | 58 | array_push($requests, $req); |
| 55 | 59 | } |
| 56 | 60 | |
| 57 | - if(!self::$decoder->getElementEndTag()) |
|
| 58 | - return false; |
|
| 61 | + if(!self::$decoder->getElementEndTag()) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 59 | 64 | |
| 60 | 65 | // output the error code, plus the ID of the calendar item that was generated by the |
| 61 | 66 | // accept of the meeting response |
@@ -69,14 +74,15 @@ discard block |
||
| 69 | 74 | $backendFolderId = self::$deviceManager->GetBackendIdForFolderId($req["folderid"]); |
| 70 | 75 | |
| 71 | 76 | // if the source folder is an additional folder the backend has to be setup correctly |
| 72 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($backendFolderId))) |
|
| 73 | - throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id %s/%s", $req["folderid"], $backendFolderId), SYNC_MEETRESPSTATUS_SERVERERROR); |
|
| 77 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($backendFolderId))) { |
|
| 78 | + throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id %s/%s", $req["folderid"], $backendFolderId), SYNC_MEETRESPSTATUS_SERVERERROR); |
|
| 79 | + } |
|
| 74 | 80 | |
| 75 | 81 | $calendarid = self::$backend->MeetingResponse($req["requestid"], $backendFolderId, $req["response"]); |
| 76 | - if ($calendarid === false) |
|
| 77 | - throw new StatusException("HandleMeetingResponse() not possible", SYNC_MEETRESPSTATUS_SERVERERROR); |
|
| 78 | - } |
|
| 79 | - catch (StatusException $stex) { |
|
| 82 | + if ($calendarid === false) { |
|
| 83 | + throw new StatusException("HandleMeetingResponse() not possible", SYNC_MEETRESPSTATUS_SERVERERROR); |
|
| 84 | + } |
|
| 85 | + } catch (StatusException $stex) { |
|
| 80 | 86 | $status = $stex->getCode(); |
| 81 | 87 | } |
| 82 | 88 | |