@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | define('SSLCERT_FILE', null); |
14 | 14 | define('SSLCERT_PASS', null); |
15 | 15 | |
16 | -$supported_classes = array ( |
|
16 | +$supported_classes = array( |
|
17 | 17 | "IPF.Note" => "SYNC_FOLDER_TYPE_USER_MAIL", |
18 | 18 | "IPF.Task" => "SYNC_FOLDER_TYPE_USER_TASK", |
19 | 19 | "IPF.Appointment" => "SYNC_FOLDER_TYPE_USER_APPOINTMENT", |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | -function listfolders_zarafa_admin_setup ($mapi, $user, $pass, $sslcert_file, $sslcert_pass) { |
|
83 | +function listfolders_zarafa_admin_setup($mapi, $user, $pass, $sslcert_file, $sslcert_pass) { |
|
84 | 84 | $session = @mapi_logon_zarafa($user, $pass, $mapi, $sslcert_file, $sslcert_pass, 0, 'script', 'script'); |
85 | 85 | |
86 | 86 | if (!$session) { |
87 | - echo "User '$user' could not login. The script will exit. Errorcode: 0x". sprintf("%x", mapi_last_hresult()) . "\n"; |
|
87 | + echo "User '$user' could not login. The script will exit. Errorcode: 0x".sprintf("%x", mapi_last_hresult())."\n"; |
|
88 | 88 | exit(1); |
89 | 89 | } |
90 | 90 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | } |
100 | 100 | $zarafauserinfo['admin'] = 1; |
101 | - $admin = (isset($zarafauserinfo['admin']) && $zarafauserinfo['admin'])?true:false; |
|
101 | + $admin = (isset($zarafauserinfo['admin']) && $zarafauserinfo['admin']) ?true:false; |
|
102 | 102 | |
103 | 103 | if (!$stores || !$storeslist || !$adminStore || !$admin) { |
104 | 104 | echo "There was error trying to log in as admin or retrieving admin info. The script will exit.\n"; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | -function listfolders_getlist ($adminStore, $session, $user) { |
|
112 | +function listfolders_getlist($adminStore, $session, $user) { |
|
113 | 113 | global $supported_classes; |
114 | 114 | |
115 | 115 | if (strtoupper($user) == 'SYSTEM') { |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | $storestables = @mapi_getmsgstorestable($session); |
118 | 118 | $result = @mapi_last_hresult(); |
119 | 119 | |
120 | - if ($result == NOERROR){ |
|
120 | + if ($result == NOERROR) { |
|
121 | 121 | $rows = @mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_MDB_PROVIDER)); |
122 | 122 | |
123 | - foreach($rows as $row) { |
|
123 | + foreach ($rows as $row) { |
|
124 | 124 | if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) { |
125 | 125 | if (!isset($row[PR_ENTRYID])) { |
126 | 126 | echo "Public folder are not available.\nIf this is a multi-tenancy system, use -u and -p and login with an admin user of the company.\nThe script will exit.\n"; |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | $hresult = mapi_last_hresult(); |
140 | 140 | |
141 | 141 | // Cache the store for later use |
142 | - if($hresult != NOERROR) { |
|
142 | + if ($hresult != NOERROR) { |
|
143 | 143 | echo "Could not open store for '$user'. The script will exit.\n"; |
144 | 144 | exit (1); |
145 | 145 | } |
146 | 146 | |
147 | 147 | if (strtoupper($user) != 'SYSTEM') { |
148 | 148 | $inbox = mapi_msgstore_getreceivefolder($userStore); |
149 | - if(mapi_last_hresult() != NOERROR) { |
|
149 | + if (mapi_last_hresult() != NOERROR) { |
|
150 | 150 | printf("Could not open inbox for %s (0x%08X). The script will exit.\n", $user, mapi_last_hresult()); |
151 | 151 | exit (1); |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | $h_table = @mapi_folder_gethierarchytable($root, CONVENIENT_DEPTH); |
159 | 159 | $subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_FOLDER_TYPE, PR_ATTR_HIDDEN)); |
160 | 160 | |
161 | - echo "Available folders in store '$user':\n" . str_repeat("-", 50) . "\n"; |
|
162 | - foreach($subfolders as $folder) { |
|
161 | + echo "Available folders in store '$user':\n".str_repeat("-", 50)."\n"; |
|
162 | + foreach ($subfolders as $folder) { |
|
163 | 163 | // do not display hidden and search folders |
164 | 164 | if ((isset($folder[PR_ATTR_HIDDEN]) && $folder[PR_ATTR_HIDDEN]) || |
165 | 165 | (isset($folder[PR_FOLDER_TYPE]) && $folder[PR_FOLDER_TYPE] == FOLDER_SEARCH)) { |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) { |
180 | - echo "Folder name:\t". $folder[PR_DISPLAY_NAME] . "\n"; |
|
181 | - echo "Folder ID:\t". bin2hex($folder[PR_SOURCE_KEY]) . "\n"; |
|
182 | - echo "Type:\t\t". $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n"; |
|
180 | + echo "Folder name:\t".$folder[PR_DISPLAY_NAME]."\n"; |
|
181 | + echo "Folder ID:\t".bin2hex($folder[PR_SOURCE_KEY])."\n"; |
|
182 | + echo "Type:\t\t".$supported_classes[$folder[PR_CONTAINER_CLASS]]."\n"; |
|
183 | 183 | echo "\n"; |
184 | 184 | } |
185 | 185 | } |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | return ($version <= $vs[1]); |
193 | 193 | } |
194 | 194 | |
195 | - if (extension_loaded("mapi")){ |
|
196 | - if (version_compare(phpversion("mapi"), $version) == -1){ |
|
195 | + if (extension_loaded("mapi")) { |
|
196 | + if (version_compare(phpversion("mapi"), $version) == -1) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | } |
@@ -57,8 +57,9 @@ discard block |
||
57 | 57 | $user = "SYSTEM"; |
58 | 58 | $pass = ""; |
59 | 59 | |
60 | - if (isset($options['h'])) |
|
61 | - $mapi = $options['h']; |
|
60 | + if (isset($options['h'])) { |
|
61 | + $mapi = $options['h']; |
|
62 | + } |
|
62 | 63 | |
63 | 64 | // accept a remote user |
64 | 65 | if (isset($options['u']) && isset($options['p'])) { |
@@ -74,8 +75,7 @@ discard block |
||
74 | 75 | $zarafaAdmin = listfolders_zarafa_admin_setup($mapi, $user, $pass, $sslcert_file, $sslcert_pass); |
75 | 76 | if (isset($zarafaAdmin['adminStore']) && isset($options['l'])) { |
76 | 77 | listfolders_getlist($zarafaAdmin['adminStore'], $zarafaAdmin['session'], trim($options['l'])); |
77 | - } |
|
78 | - else { |
|
78 | + } else { |
|
79 | 79 | echo "Usage:\nlistfolders.php [actions] [options]\n\nActions: [-l username]\n\t-l username\tlist folders of user, for public folder use 'SYSTEM'\n\nGlobal options: [-h path] [[-u remoteuser] [-p password]] [[-c certificate_path] [-p password]]\n\t-h path\t\tconnect through <path>, e.g. file:///var/run/socket or https://10.0.0.1:237/grommunio\n\t-u remoteuser\tlogin as authenticated administration user\n\t-c certificate\tlogin with a ssl certificate located in this location, e.g. /etc/zarafa/ssl/client.pem\n\t-p password\tpassword of the remoteuser or certificate\n\n"; |
80 | 80 | } |
81 | 81 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
134 | + } else { |
|
135 | + $entryid = @mapi_msgstore_createentryid($adminStore, $user); |
|
134 | 136 | } |
135 | - else |
|
136 | - $entryid = @mapi_msgstore_createentryid($adminStore, $user); |
|
137 | 137 | |
138 | 138 | $userStore = @mapi_openmsgstore($session, $entryid); |
139 | 139 | $hresult = mapi_last_hresult(); |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | if (version_compare(phpversion("mapi"), $version) == -1){ |
197 | 197 | return false; |
198 | 198 | } |
199 | + } else { |
|
200 | + return false; |
|
199 | 201 | } |
200 | - else |
|
201 | - return false; |
|
202 | 202 | |
203 | 203 | return true; |
204 | 204 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | return $this->position; |
120 | 120 | } |
121 | 121 | |
122 | - /** |
|
122 | + /** |
|
123 | 123 | * Indicates if 'end of file' is reached |
124 | 124 | * |
125 | 125 | * @access public |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ); |
160 | 160 | } |
161 | 161 | |
162 | - /** |
|
162 | + /** |
|
163 | 163 | * Instantiates a MAPIStreamWrapper |
164 | 164 | * |
165 | 165 | * @param mapistream $mapistream The stream to be wrapped |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @access public |
169 | 169 | * @return MAPIStreamWrapper |
170 | 170 | */ |
171 | - static public function Open($mapistream, $truncatehtmlsafe = false) { |
|
171 | + static public function Open($mapistream, $truncatehtmlsafe = false) { |
|
172 | 172 | $context = stream_context_create(array(self::PROTOCOL => array('stream' => &$mapistream, 'truncatehtmlsafe' => $truncatehtmlsafe))); |
173 | 173 | return fopen(self::PROTOCOL . "://",'r', false, $context); |
174 | 174 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $len = ($this->position + $len > $this->streamlength) ? ($this->streamlength - $this->position) : $len; |
70 | 70 | |
71 | 71 | // read 4 additional bytes from the stream so we can always truncate correctly |
72 | - if ($this->toTruncate && $this->position+$len >= $this->streamlength) { |
|
72 | + if ($this->toTruncate && $this->position + $len >= $this->streamlength) { |
|
73 | 73 | $len += 4; |
74 | 74 | } |
75 | 75 | if ($this->mapistream) { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return boolean |
97 | 97 | */ |
98 | 98 | public function stream_seek($offset, $whence = SEEK_SET) { |
99 | - switch($whence) { |
|
99 | + switch ($whence) { |
|
100 | 100 | case SEEK_SET: |
101 | 101 | $mapiWhence = STREAM_SEEK_SET; |
102 | 102 | break; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | static public function Open($mapistream, $truncatehtmlsafe = false) { |
172 | 172 | $context = stream_context_create(array(self::PROTOCOL => array('stream' => &$mapistream, 'truncatehtmlsafe' => $truncatehtmlsafe))); |
173 | - return fopen(self::PROTOCOL . "://",'r', false, $context); |
|
173 | + return fopen(self::PROTOCOL."://", 'r', false, $context); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 |
@@ -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); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $folderidForBackendId = ZPush::GetDeviceManager()->GetFolderIdForBackendId($this->folderidHex); |
62 | 62 | // Only append backend id if the mapping backendid<->folderid is available. |
63 | 63 | if ($folderidForBackendId != $this->folderidHex) { |
64 | - $this->prefix = $folderidForBackendId . ':'; |
|
64 | + $this->prefix = $folderidForBackendId.':'; |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | else { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if ($entryid) |
79 | 79 | $folder = mapi_msgstore_openentry($store, $entryid); |
80 | 80 | |
81 | - if(!$folder) { |
|
81 | + if (!$folder) { |
|
82 | 82 | $this->importer = false; |
83 | 83 | |
84 | 84 | // We throw an general error SYNC_FSSTATUS_CODEUNKNOWN (12) which is also SYNC_STATUS_FOLDERHIERARCHYCHANGED (12) |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $this->mapiprovider = new MAPIProvider($this->session, $this->store); |
90 | 90 | |
91 | 91 | if ($folderid) { |
92 | - $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportContentsChanges, 0 , 0); |
|
92 | + $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportContentsChanges, 0, 0); |
|
93 | 93 | } |
94 | 94 | else { |
95 | - $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportHierarchyChanges, 0 , 0); |
|
95 | + $this->importer = mapi_openproperty($folder, PR_COLLECTOR, IID_IExchangeImportHierarchyChanges, 0, 0); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | // Put the state information in a stream that can be used by ICS |
117 | 117 | $stream = mapi_stream_create(); |
118 | - if(strlen($state) == 0) |
|
118 | + if (strlen($state) == 0) |
|
119 | 119 | $state = hex2bin("0000000000000000"); |
120 | 120 | |
121 | 121 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->Config(): initializing importer with state: 0x%s", bin2hex($state))); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function ConfigContentParameters($contentparameters) { |
149 | 149 | $filtertype = $contentparameters->GetFilterType(); |
150 | - switch($contentparameters->GetContentClass()) { |
|
150 | + switch ($contentparameters->GetContentClass()) { |
|
151 | 151 | case "Email": |
152 | 152 | $this->cutoffdate = ($filtertype) ? Utils::GetCutOffDate($filtertype) : false; |
153 | 153 | break; |
@@ -172,22 +172,22 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function GetState() { |
174 | 174 | $error = false; |
175 | - if(!isset($this->statestream) || $this->importer === false) |
|
175 | + if (!isset($this->statestream) || $this->importer === false) |
|
176 | 176 | $error = true; |
177 | 177 | |
178 | 178 | if ($error === false && $this->folderid !== false && function_exists("mapi_importcontentschanges_updatestate")) |
179 | - if(mapi_importcontentschanges_updatestate($this->importer, $this->statestream) != true) |
|
179 | + if (mapi_importcontentschanges_updatestate($this->importer, $this->statestream) != true) |
|
180 | 180 | $error = true; |
181 | 181 | |
182 | 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); |
|
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); |
|
184 | 184 | |
185 | 185 | mapi_stream_seek($this->statestream, 0, STREAM_SEEK_SET); |
186 | 186 | |
187 | 187 | $state = ""; |
188 | - while(true) { |
|
188 | + while (true) { |
|
189 | 189 | $data = mapi_stream_read($this->statestream, 4096); |
190 | - if(strlen($data)) |
|
190 | + if (strlen($data)) |
|
191 | 191 | $state .= $data; |
192 | 192 | else |
193 | 193 | break; |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | |
218 | 218 | // open the existing object |
219 | 219 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid, hex2bin($messageid)); |
220 | - if(!$entryid) { |
|
220 | + if (!$entryid) { |
|
221 | 221 | ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->isModificationAllowed('%s'): Error, unable to resolve message id: 0x%X", $messageid, mapi_last_hresult())); |
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | |
225 | 225 | $mapimessage = mapi_msgstore_openentry($this->store, $entryid); |
226 | - if(!$mapimessage) { |
|
226 | + if (!$mapimessage) { |
|
227 | 227 | ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->isModificationAllowed('%s'): Error, unable to open entry id: 0x%X", $messageid, mapi_last_hresult())); |
228 | 228 | return false; |
229 | 229 | } |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | // check the sync interval |
232 | 232 | if ($this->cutoffdate !== false) { |
233 | 233 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->isModificationAllowed('%s'): cut off date is: %s", $messageid, $this->cutoffdate)); |
234 | - if ( ($this->contentClass == "Email" && !MAPIUtils::IsInEmailSyncInterval($this->store, $mapimessage, $this->cutoffdate)) || |
|
235 | - ($this->contentClass == "Calendar" && !MAPIUtils::IsInCalendarSyncInterval($this->store, $mapimessage, $this->cutoffdate)) ) { |
|
234 | + if (($this->contentClass == "Email" && !MAPIUtils::IsInEmailSyncInterval($this->store, $mapimessage, $this->cutoffdate)) || |
|
235 | + ($this->contentClass == "Calendar" && !MAPIUtils::IsInCalendarSyncInterval($this->store, $mapimessage, $this->cutoffdate))) { |
|
236 | 236 | |
237 | 237 | ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->isModificationAllowed('%s'): Message in %s is outside the sync interval. Data not saved.", $messageid, $this->contentClass)); |
238 | 238 | return false; |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | $started = time(); |
312 | 312 | $exported = 0; |
313 | 313 | try { |
314 | - while(is_array($exporter->Synchronize())) { |
|
314 | + while (is_array($exporter->Synchronize())) { |
|
315 | 315 | $exported++; |
316 | 316 | |
317 | 317 | // stop if this takes more than 15 seconds and there are more than 5 changes still to be exported |
318 | 318 | // within 20 seconds this should be finished or it will not be performed |
319 | - if ((time() - $started) > 15 && ($potConflicts - $exported) > 5 ) { |
|
320 | - ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->lazyLoadConflicts(): conflict detection cancelled as operation is too slow. In %d seconds only %d from %d changes were processed.",(time() - $started), $exported, $potConflicts)); |
|
319 | + if ((time() - $started) > 15 && ($potConflicts - $exported) > 5) { |
|
320 | + ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->lazyLoadConflicts(): conflict detection cancelled as operation is too slow. In %d seconds only %d from %d changes were processed.", (time() - $started), $exported, $potConflicts)); |
|
321 | 321 | $this->conflictsLoaded = true; |
322 | 322 | return; |
323 | 323 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | } |
326 | 326 | // something really bad happened while exporting changes |
327 | 327 | catch (StatusException $stex) { |
328 | - ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->lazyLoadConflicts(): got StatusException code %d while exporting changes. Ignore and mark conflicts as loaded.",$stex->getCode())); |
|
328 | + ZLog::Write(LOGLEVEL_WARN, sprintf("ImportChangesICS->lazyLoadConflicts(): got StatusException code %d while exporting changes. Ignore and mark conflicts as loaded.", $stex->getCode())); |
|
329 | 329 | } |
330 | 330 | $this->conflictsLoaded = true; |
331 | 331 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | $props[PR_PARENT_SOURCE_KEY] = $this->folderid; |
348 | 348 | |
349 | 349 | // set the PR_SOURCE_KEY if available or mark it as new message |
350 | - if($id) { |
|
350 | + if ($id) { |
|
351 | 351 | list(, $sk) = Utils::SplitMessageId($id); |
352 | 352 | $props[PR_SOURCE_KEY] = hex2bin($sk); |
353 | 353 | |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | // check for conflicts |
359 | 359 | $this->lazyLoadConflicts(); |
360 | - if($this->memChanges->IsChanged($id)) { |
|
360 | + if ($this->memChanges->IsChanged($id)) { |
|
361 | 361 | if ($this->flags & SYNC_CONFLICT_OVERWRITE_PIM) { |
362 | 362 | // in these cases the status SYNC_STATUS_CONFLICTCLIENTSERVEROBJECT should be returned, so the mobile client can inform the end user |
363 | 363 | 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); |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | else |
367 | 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 | 368 | } |
369 | - if($this->memChanges->IsDeleted($id)) { |
|
369 | + if ($this->memChanges->IsDeleted($id)) { |
|
370 | 370 | 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 | 371 | return false; |
372 | 372 | } |
@@ -374,16 +374,16 @@ discard block |
||
374 | 374 | else |
375 | 375 | $flags = SYNC_NEW_MESSAGE; |
376 | 376 | |
377 | - if(mapi_importcontentschanges_importmessagechange($this->importer, $props, $flags, $mapimessage)) { |
|
377 | + if (mapi_importcontentschanges_importmessagechange($this->importer, $props, $flags, $mapimessage)) { |
|
378 | 378 | $this->mapiprovider->SetMessage($mapimessage, $message); |
379 | 379 | mapi_savechanges($mapimessage); |
380 | 380 | |
381 | 381 | if (mapi_last_hresult()) |
382 | 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); |
383 | 383 | |
384 | - $sourcekeyprops = mapi_getprops($mapimessage, array (PR_SOURCE_KEY)); |
|
384 | + $sourcekeyprops = mapi_getprops($mapimessage, array(PR_SOURCE_KEY)); |
|
385 | 385 | |
386 | - return $this->prefix . bin2hex($sourcekeyprops[PR_SOURCE_KEY]); |
|
386 | + return $this->prefix.bin2hex($sourcekeyprops[PR_SOURCE_KEY]); |
|
387 | 387 | } |
388 | 388 | else |
389 | 389 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageChange('%s','%s'): Error updating object: 0x%X", $id, get_class($message), mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
@@ -407,16 +407,16 @@ discard block |
||
407 | 407 | |
408 | 408 | // check for conflicts |
409 | 409 | $this->lazyLoadConflicts(); |
410 | - if($this->memChanges->IsChanged($id)) { |
|
410 | + if ($this->memChanges->IsChanged($id)) { |
|
411 | 411 | ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Conflict detected. Data from Server will be dropped! PIM deleted object.", $id)); |
412 | 412 | } |
413 | - elseif($this->memChanges->IsDeleted($id)) { |
|
413 | + elseif ($this->memChanges->IsDeleted($id)) { |
|
414 | 414 | ZLog::Write(LOGLEVEL_INFO, sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Conflict detected. Data is already deleted. Request will be ignored.", $id)); |
415 | 415 | return true; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // do a 'soft' delete so people can un-delete if necessary |
419 | - if(mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($sk)))) |
|
419 | + if (mapi_importcontentschanges_importmessagedeletion($this->importer, 1, array(hex2bin($sk)))) |
|
420 | 420 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageDeletion('%s'): Error updating object: 0x%X", $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
421 | 421 | |
422 | 422 | return true; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @throws StatusException |
436 | 436 | */ |
437 | 437 | public function ImportMessageReadFlag($id, $flags, $categories = array()) { |
438 | - list($fsk,$sk) = Utils::SplitMessageId($id); |
|
438 | + list($fsk, $sk) = Utils::SplitMessageId($id); |
|
439 | 439 | |
440 | 440 | // if $fsk is set, we convert it into a backend id. |
441 | 441 | if ($fsk) { |
@@ -461,9 +461,9 @@ discard block |
||
461 | 461 | } |
462 | 462 | */ |
463 | 463 | |
464 | - $readstate = array ( "sourcekey" => hex2bin($sk), "flags" => $flags); |
|
464 | + $readstate = array("sourcekey" => hex2bin($sk), "flags" => $flags); |
|
465 | 465 | |
466 | - if(!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate) )) |
|
466 | + if (!mapi_importcontentschanges_importperuserreadstatechange($this->importer, array($readstate))) |
|
467 | 467 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageReadFlag('%s','%d'): Error setting read state: 0x%X", $id, $flags, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
468 | 468 | } |
469 | 469 | // yeah OL sucks - ZP-779 |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | */ |
503 | 503 | public function ImportMessageMove($id, $newfolder) { |
504 | 504 | list(,$sk) = Utils::SplitMessageId($id); |
505 | - if (strtolower($newfolder) == strtolower(bin2hex($this->folderid)) ) |
|
505 | + if (strtolower($newfolder) == strtolower(bin2hex($this->folderid))) |
|
506 | 506 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, source and destination are equal", $id, $newfolder), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST); |
507 | 507 | |
508 | 508 | // Get the entryid of the message we're moving |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | $srcmessage = mapi_msgstore_openentry($this->store, $entryid); |
515 | 515 | } |
516 | 516 | |
517 | - if(!$entryid || !$srcmessage) { |
|
517 | + if (!$entryid || !$srcmessage) { |
|
518 | 518 | $code = SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID; |
519 | 519 | $mapiLastHresult = mapi_last_hresult(); |
520 | 520 | // if we move to the trash and the source message is not found, we can also just tell the mobile that we successfully moved to avoid errors (ZP-624) |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open store of destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
536 | 536 | |
537 | 537 | $dstentryid = mapi_msgstore_entryidfromsourcekey($dststore, hex2bin($newfolder)); |
538 | - if(!$dstentryid) |
|
538 | + if (!$dstentryid) |
|
539 | 539 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
540 | 540 | |
541 | 541 | $dstfolder = mapi_msgstore_openentry($dststore, $dstentryid); |
542 | - if(!$dstfolder) |
|
542 | + if (!$dstfolder) |
|
543 | 543 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to open destination folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDDESTID); |
544 | 544 | |
545 | 545 | $newmessage = mapi_folder_createmessage($dstfolder); |
@@ -552,7 +552,7 @@ discard block |
||
552 | 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); |
553 | 553 | |
554 | 554 | $srcfolderentryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid); |
555 | - if(!$srcfolderentryid) |
|
555 | + if (!$srcfolderentryid) |
|
556 | 556 | throw new StatusException(sprintf("ImportChangesICS->ImportMessageMove('%s','%s'): Error, unable to resolve source folder", $sk, $newfolder), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
557 | 557 | |
558 | 558 | $srcfolder = mapi_msgstore_openentry($this->store, $srcfolderentryid); |
@@ -568,15 +568,15 @@ discard block |
||
568 | 568 | if (!mapi_folder_deletemessages($srcfolder, array($entryid))) |
569 | 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); |
570 | 570 | |
571 | - $sourcekeyprops = mapi_getprops($newmessage, array (PR_SOURCE_KEY)); |
|
571 | + $sourcekeyprops = mapi_getprops($newmessage, array(PR_SOURCE_KEY)); |
|
572 | 572 | if (isset($sourcekeyprops[PR_SOURCE_KEY]) && $sourcekeyprops[PR_SOURCE_KEY]) { |
573 | 573 | $prefix = ""; |
574 | 574 | // prepend the destination short folderid, if it exists |
575 | 575 | $destShortId = ZPush::GetDeviceManager()->GetFolderIdForBackendId($newfolder); |
576 | 576 | if ($destShortId !== $newfolder) { |
577 | - $prefix = $destShortId .":"; |
|
577 | + $prefix = $destShortId.":"; |
|
578 | 578 | } |
579 | - return $prefix . bin2hex($sourcekeyprops[PR_SOURCE_KEY]); |
|
579 | + return $prefix.bin2hex($sourcekeyprops[PR_SOURCE_KEY]); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | return false; |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * @throws StatusException |
598 | 598 | */ |
599 | 599 | public function ImportFolderChange($folder) { |
600 | - $id = isset($folder->BackendId)?$folder->BackendId : false; |
|
600 | + $id = isset($folder->BackendId) ? $folder->BackendId : false; |
|
601 | 601 | $parent = $folder->parentid; |
602 | 602 | $parent_org = $folder->parentid; |
603 | 603 | $displayname = u2wi($folder->displayname); |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | |
636 | 636 | mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type))); |
637 | 637 | |
638 | - $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY)); |
|
638 | + $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY)); |
|
639 | 639 | if (isset($props[PR_SOURCE_KEY])) { |
640 | 640 | $folder->BackendId = bin2hex($props[PR_SOURCE_KEY]); |
641 | 641 | $folderOrigin = DeviceManager::FLD_ORIGIN_USER; |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | if (!$mfolder) |
664 | 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); |
665 | 665 | |
666 | - $props = mapi_getprops($mfolder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS)); |
|
666 | + $props = mapi_getprops($mfolder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS)); |
|
667 | 667 | if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) |
668 | 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); |
669 | 669 | |
@@ -686,23 +686,23 @@ discard block |
||
686 | 686 | // a changed parent id means that the folder should be moved |
687 | 687 | if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) { |
688 | 688 | $sourceparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, $props[PR_PARENT_SOURCE_KEY]); |
689 | - if(!$sourceparentfentryid) |
|
689 | + if (!$sourceparentfentryid) |
|
690 | 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); |
691 | 691 | |
692 | 692 | $sourceparentfolder = mapi_msgstore_openentry($this->store, $sourceparentfentryid); |
693 | - if(!$sourceparentfolder) |
|
693 | + if (!$sourceparentfolder) |
|
694 | 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); |
695 | 695 | |
696 | 696 | $destparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent)); |
697 | - if(!$sourceparentfentryid) |
|
697 | + if (!$sourceparentfentryid) |
|
698 | 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); |
699 | 699 | |
700 | 700 | $destfolder = mapi_msgstore_openentry($this->store, $destparentfentryid); |
701 | - if(!$destfolder) |
|
701 | + if (!$destfolder) |
|
702 | 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); |
703 | 703 | |
704 | 704 | // 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)) |
|
705 | + if (!mapi_folder_copyfolder($sourceparentfolder, $entryid, $destfolder, $displayname, FOLDER_MOVE)) |
|
706 | 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); |
707 | 707 | |
708 | 708 | // 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 |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): importing folder deletetion", $id, $parent)); |
741 | 741 | |
742 | 742 | $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id)); |
743 | - if(!$folderentryid) |
|
743 | + if (!$folderentryid) |
|
744 | 744 | throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error, unable to resolve folder", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_FOLDERDOESNOTEXIST); |
745 | 745 | |
746 | 746 | // get the folder type from the MAPIProvider |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | if (Utils::IsSystemFolder($type) || $this->mapiprovider->IsMAPIDefaultFolder($folderentryid)) |
750 | 750 | throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting system/default folder", $id, $parent), SYNC_FSSTATUS_SYSTEMFOLDER); |
751 | 751 | |
752 | - $ret = mapi_importhierarchychanges_importfolderdeletion ($this->importer, 0, array(PR_SOURCE_KEY => hex2bin($id))); |
|
752 | + $ret = mapi_importhierarchychanges_importfolderdeletion($this->importer, 0, array(PR_SOURCE_KEY => hex2bin($id))); |
|
753 | 753 | if (!$ret) |
754 | 754 | throw new StatusException(sprintf("ImportChangesICS->ImportFolderDeletion('%s','%s'): Error deleting folder: 0x%X", $id, $parent, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR); |
755 | 755 |
@@ -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 | } |
@@ -184,7 +184,7 @@ |
||
184 | 184 | self::$encoder->endTag(); |
185 | 185 | |
186 | 186 | self::$encoder->startTag(SYNC_PROVISION_POLICYKEY); |
187 | - self::$encoder->content($policykey); |
|
187 | + self::$encoder->content($policykey); |
|
188 | 188 | self::$encoder->endTag(); |
189 | 189 | |
190 | 190 | if ($phase2 && $policystatus === SYNC_PROVISION_POLICYSTATUS_SUCCESS) { |
@@ -24,17 +24,17 @@ discard block |
||
24 | 24 | $rwstatus = ZPush::GetProvisioningManager()->GetProvisioningWipeStatus(); |
25 | 25 | $rwstatusWiped = false; |
26 | 26 | $deviceInfoSet = false; |
27 | - $wipeRequest = ! ($rwstatus < SYNC_PROVISION_RWSTATUS_PENDING); |
|
27 | + $wipeRequest = !($rwstatus < SYNC_PROVISION_RWSTATUS_PENDING); |
|
28 | 28 | |
29 | 29 | // if this is a regular provisioning require that an authenticated remote user |
30 | - if (! $wipeRequest) { |
|
30 | + if (!$wipeRequest) { |
|
31 | 31 | ZLog::Write(LOGLEVEL_DEBUG, "RequestProcessor::HandleProvision(): Forcing delayed Authentication"); |
32 | 32 | self::Authenticate(); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $phase2 = true; |
36 | 36 | |
37 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_PROVISION)) |
|
37 | + if (!self::$decoder->getElementStartTag(SYNC_PROVISION_PROVISION)) |
|
38 | 38 | return false; |
39 | 39 | |
40 | 40 | // Loop through Provision request tags. Possible are: |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | // - Policies |
44 | 44 | // Each of them should only be once per request. |
45 | 45 | WBXMLDecoder::ResetInWhile("provisioningMain"); |
46 | - while(WBXMLDecoder::InWhile("provisioningMain")) { |
|
46 | + while (WBXMLDecoder::InWhile("provisioningMain")) { |
|
47 | 47 | $requestName = ""; |
48 | 48 | if (self::$decoder->getElementStartTag(SYNC_PROVISION_REMOTEWIPE)) { |
49 | 49 | $requestName = SYNC_PROVISION_REMOTEWIPE; |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | //set is available for OOF, device password and device information |
62 | 62 | switch ($requestName) { |
63 | 63 | case SYNC_PROVISION_REMOTEWIPE: |
64 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
64 | + if (!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
65 | 65 | return false; |
66 | 66 | |
67 | 67 | $instatus = self::$decoder->getElementContent(); |
68 | 68 | |
69 | - if(!self::$decoder->getElementEndTag()) |
|
69 | + if (!self::$decoder->getElementEndTag()) |
|
70 | 70 | return false; |
71 | 71 | |
72 | - if(!self::$decoder->getElementEndTag()) |
|
72 | + if (!self::$decoder->getElementEndTag()) |
|
73 | 73 | return false; |
74 | 74 | |
75 | 75 | $phase2 = false; |
@@ -78,40 +78,40 @@ discard block |
||
78 | 78 | break; |
79 | 79 | |
80 | 80 | case SYNC_PROVISION_POLICIES: |
81 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICY)) |
|
81 | + if (!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICY)) |
|
82 | 82 | return false; |
83 | 83 | |
84 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYTYPE)) |
|
84 | + if (!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYTYPE)) |
|
85 | 85 | return false; |
86 | 86 | |
87 | 87 | $policytype = self::$decoder->getElementContent(); |
88 | 88 | if ($policytype != 'MS-WAP-Provisioning-XML' && $policytype != 'MS-EAS-Provisioning-WBXML') { |
89 | 89 | $status = SYNC_PROVISION_STATUS_SERVERERROR; |
90 | 90 | } |
91 | - if(!self::$decoder->getElementEndTag()) //policytype |
|
91 | + if (!self::$decoder->getElementEndTag()) //policytype |
|
92 | 92 | return false; |
93 | 93 | |
94 | 94 | if (self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYKEY)) { |
95 | 95 | $devpolicykey = self::$decoder->getElementContent(); |
96 | 96 | |
97 | - if(!self::$decoder->getElementEndTag()) |
|
97 | + if (!self::$decoder->getElementEndTag()) |
|
98 | 98 | return false; |
99 | 99 | |
100 | - if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
100 | + if (!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS)) |
|
101 | 101 | return false; |
102 | 102 | |
103 | 103 | $instatus = self::$decoder->getElementContent(); |
104 | 104 | |
105 | - if(!self::$decoder->getElementEndTag()) |
|
105 | + if (!self::$decoder->getElementEndTag()) |
|
106 | 106 | return false; |
107 | 107 | |
108 | 108 | $phase2 = false; |
109 | 109 | } |
110 | 110 | |
111 | - if(!self::$decoder->getElementEndTag()) //policy |
|
111 | + if (!self::$decoder->getElementEndTag()) //policy |
|
112 | 112 | return false; |
113 | 113 | |
114 | - if(!self::$decoder->getElementEndTag()) //policies |
|
114 | + if (!self::$decoder->getElementEndTag()) //policies |
|
115 | 115 | return false; |
116 | 116 | break; |
117 | 117 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $deviceinformation = new SyncDeviceInformation(); |
124 | 124 | $deviceinformation->Decode(self::$decoder); |
125 | 125 | $deviceinformation->Status = SYNC_SETTINGSSTATUS_SUCCESS; |
126 | - if (! $wipeRequest) { |
|
126 | + if (!$wipeRequest) { |
|
127 | 127 | // for this operation the device manager is available |
128 | 128 | ZPush::GetDeviceManager()->SaveDeviceInformation($deviceinformation); |
129 | 129 | } |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | |
139 | 139 | default: |
140 | 140 | //TODO: a special status code needed? |
141 | - ZLog::Write(LOGLEVEL_WARN, sprintf ("This property ('%s') is not allowed to be used in a provision request", $requestName)); |
|
141 | + ZLog::Write(LOGLEVEL_WARN, sprintf("This property ('%s') is not allowed to be used in a provision request", $requestName)); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | - if(!self::$decoder->getElementEndTag()) //provision |
|
146 | + if (!self::$decoder->getElementEndTag()) //provision |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | if (PROVISIONING !== true) { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | self::$encoder->startTag(SYNC_PROVISION_POLICIES); |
174 | 174 | self::$encoder->startTag(SYNC_PROVISION_POLICY); |
175 | 175 | |
176 | - if(isset($policytype)) { |
|
176 | + if (isset($policytype)) { |
|
177 | 177 | self::$encoder->startTag(SYNC_PROVISION_POLICYTYPE); |
178 | 178 | self::$encoder->content($policytype); |
179 | 179 | self::$encoder->endTag(); |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | } |
212 | 212 | self::$topCollector->AnnounceInformation("Updated provisioning", true); |
213 | 213 | |
214 | - self::$encoder->endTag();//data |
|
214 | + self::$encoder->endTag(); //data |
|
215 | 215 | } |
216 | - self::$encoder->endTag();//policy |
|
216 | + self::$encoder->endTag(); //policy |
|
217 | 217 | self::$encoder->endTag(); //policies |
218 | 218 | } |
219 | 219 | |
220 | 220 | //set the new final policy key in the provisioning manager |
221 | - if (!$phase2 && ! $wipeRequest) { |
|
221 | + if (!$phase2 && !$wipeRequest) { |
|
222 | 222 | ZPush::GetProvisioningManager()->SetProvisioningPolicyKey($policykey); |
223 | 223 | self::$topCollector->AnnounceInformation("Policies deployed", true); |
224 | 224 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | //wipe data if a higher RWSTATUS is requested |
227 | 227 | if ($rwstatus > SYNC_PROVISION_RWSTATUS_OK && $policystatus === SYNC_PROVISION_POLICYSTATUS_SUCCESS) { |
228 | 228 | self::$encoder->startTag(SYNC_PROVISION_REMOTEWIPE, false, true); |
229 | - ZPush::GetProvisioningManager()->SetProvisioningWipeStatus(($rwstatusWiped)?SYNC_PROVISION_RWSTATUS_WIPED:SYNC_PROVISION_RWSTATUS_REQUESTED); |
|
230 | - self::$topCollector->AnnounceInformation(sprintf("Remote wipe %s", ($rwstatusWiped)?"executed":"requested"), true); |
|
229 | + ZPush::GetProvisioningManager()->SetProvisioningWipeStatus(($rwstatusWiped) ?SYNC_PROVISION_RWSTATUS_WIPED:SYNC_PROVISION_RWSTATUS_REQUESTED); |
|
230 | + self::$topCollector->AnnounceInformation(sprintf("Remote wipe %s", ($rwstatusWiped) ? "executed" : "requested"), true); |
|
231 | 231 | } |
232 | 232 | |
233 | - self::$encoder->endTag();//provision |
|
233 | + self::$encoder->endTag(); //provision |
|
234 | 234 | |
235 | 235 | return true; |
236 | 236 | } |
@@ -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,34 +18,34 @@ discard block |
||
18 | 18 | * @return boolean |
19 | 19 | */ |
20 | 20 | public function Handle($commandCode) { |
21 | - if(!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES)) |
|
21 | + if (!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES)) |
|
22 | 22 | return false; |
23 | 23 | |
24 | 24 | $moves = array(); |
25 | - while(self::$decoder->getElementStartTag(SYNC_MOVE_MOVE)) { |
|
25 | + while (self::$decoder->getElementStartTag(SYNC_MOVE_MOVE)) { |
|
26 | 26 | $move = array(); |
27 | - if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCMSGID)) { |
|
27 | + if (self::$decoder->getElementStartTag(SYNC_MOVE_SRCMSGID)) { |
|
28 | 28 | $move["srcmsgid"] = self::$decoder->getElementContent(); |
29 | - if(!self::$decoder->getElementEndTag()) |
|
29 | + if (!self::$decoder->getElementEndTag()) |
|
30 | 30 | break; |
31 | 31 | } |
32 | - if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCFLDID)) { |
|
32 | + if (self::$decoder->getElementStartTag(SYNC_MOVE_SRCFLDID)) { |
|
33 | 33 | $move["srcfldid"] = self::$decoder->getElementContent(); |
34 | - if(!self::$decoder->getElementEndTag()) |
|
34 | + if (!self::$decoder->getElementEndTag()) |
|
35 | 35 | break; |
36 | 36 | } |
37 | - if(self::$decoder->getElementStartTag(SYNC_MOVE_DSTFLDID)) { |
|
37 | + if (self::$decoder->getElementStartTag(SYNC_MOVE_DSTFLDID)) { |
|
38 | 38 | $move["dstfldid"] = self::$decoder->getElementContent(); |
39 | - if(!self::$decoder->getElementEndTag()) |
|
39 | + if (!self::$decoder->getElementEndTag()) |
|
40 | 40 | break; |
41 | 41 | } |
42 | 42 | array_push($moves, $move); |
43 | 43 | |
44 | - if(!self::$decoder->getElementEndTag()) |
|
44 | + if (!self::$decoder->getElementEndTag()) |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | - if(!self::$decoder->getElementEndTag()) |
|
48 | + if (!self::$decoder->getElementEndTag()) |
|
49 | 49 | return false; |
50 | 50 | |
51 | 51 | self::$encoder->StartWBXML(); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $operationResults = array(); |
56 | 56 | $operationCounter = 0; |
57 | 57 | $operationTotal = count($moves); |
58 | - foreach($moves as $move) { |
|
58 | + foreach ($moves as $move) { |
|
59 | 59 | $operationCounter++; |
60 | 60 | self::$encoder->startTag(SYNC_MOVE_RESPONSE); |
61 | 61 | self::$encoder->startTag(SYNC_MOVE_SRCMSGID); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | self::$encoder->endTag(); |
108 | 108 | |
109 | 109 | self::$encoder->startTag(SYNC_MOVE_DSTMSGID); |
110 | - self::$encoder->content( (($result !== false ) ? $result : $move["srcmsgid"])); |
|
110 | + self::$encoder->content((($result !== false) ? $result : $move["srcmsgid"])); |
|
111 | 111 | self::$encoder->endTag(); |
112 | 112 | self::$encoder->endTag(); |
113 | 113 | } |
@@ -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,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function Handle($commandCode) { |
21 | 21 | // Parse input |
22 | - if(!self::$decoder->getElementStartTag(SYNC_VALIDATECERT_VALIDATECERT)) |
|
22 | + if (!self::$decoder->getElementStartTag(SYNC_VALIDATECERT_VALIDATECERT)) |
|
23 | 23 | return false; |
24 | 24 | |
25 | 25 | $validateCert = new SyncValidateCert(); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | else |
34 | 34 | $status = SYNC_VALIDATECERTSTATUS_CANTVALIDATESIG; |
35 | 35 | |
36 | - if(!self::$decoder->getElementEndTag()) |
|
36 | + if (!self::$decoder->getElementEndTag()) |
|
37 | 37 | return false; // SYNC_VALIDATECERT_VALIDATECERT |
38 | 38 | |
39 | 39 | self::$encoder->startWBXML(); |
@@ -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,16 +18,16 @@ |
||
18 | 18 | * @return boolean |
19 | 19 | */ |
20 | 20 | public function Handle($commandCode) { |
21 | - if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_NOTIFY)) |
|
21 | + if (!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_NOTIFY)) |
|
22 | 22 | return false; |
23 | 23 | |
24 | - if(!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_DEVICEINFO)) |
|
24 | + if (!self::$decoder->getElementStartTag(SYNC_AIRNOTIFY_DEVICEINFO)) |
|
25 | 25 | return false; |
26 | 26 | |
27 | - if(!self::$decoder->getElementEndTag()) |
|
27 | + if (!self::$decoder->getElementEndTag()) |
|
28 | 28 | return false; |
29 | 29 | |
30 | - if(!self::$decoder->getElementEndTag()) |
|
30 | + if (!self::$decoder->getElementEndTag()) |
|
31 | 31 | return false; |
32 | 32 | |
33 | 33 | self::$encoder->StartWBXML(); |
@@ -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 |
@@ -60,40 +60,40 @@ discard block |
||
60 | 60 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): reference PolicyKey for PING: %s", $sc->GetReferencePolicyKey())); |
61 | 61 | |
62 | 62 | // receive PING initialization data |
63 | - if($params_present) { |
|
63 | + if ($params_present) { |
|
64 | 64 | self::$topCollector->AnnounceInformation("Processing PING data"); |
65 | 65 | ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): initialization data received"); |
66 | 66 | |
67 | - if(self::$decoder->getElementStartTag(SYNC_PING_LIFETIME)) { |
|
67 | + if (self::$decoder->getElementStartTag(SYNC_PING_LIFETIME)) { |
|
68 | 68 | $sc->SetLifetime(self::$decoder->getElementContent()); |
69 | 69 | self::$decoder->getElementEndTag(); |
70 | 70 | } |
71 | 71 | |
72 | - if(($el = self::$decoder->getElementStartTag(SYNC_PING_FOLDERS)) && $el[EN_FLAGS] & EN_FLAGS_CONTENT) { |
|
72 | + if (($el = self::$decoder->getElementStartTag(SYNC_PING_FOLDERS)) && $el[EN_FLAGS] & EN_FLAGS_CONTENT) { |
|
73 | 73 | // cache requested (pingable) folderids |
74 | 74 | $pingable = array(); |
75 | 75 | |
76 | - while(self::$decoder->getElementStartTag(SYNC_PING_FOLDER)) { |
|
76 | + while (self::$decoder->getElementStartTag(SYNC_PING_FOLDER)) { |
|
77 | 77 | WBXMLDecoder::ResetInWhile("pingFolder"); |
78 | - while(WBXMLDecoder::InWhile("pingFolder")) { |
|
79 | - if(self::$decoder->getElementStartTag(SYNC_PING_SERVERENTRYID)) { |
|
78 | + while (WBXMLDecoder::InWhile("pingFolder")) { |
|
79 | + if (self::$decoder->getElementStartTag(SYNC_PING_SERVERENTRYID)) { |
|
80 | 80 | $folderid = self::$decoder->getElementContent(); |
81 | 81 | self::$decoder->getElementEndTag(); |
82 | 82 | } |
83 | - if(self::$decoder->getElementStartTag(SYNC_PING_FOLDERTYPE)) { |
|
83 | + if (self::$decoder->getElementStartTag(SYNC_PING_FOLDERTYPE)) { |
|
84 | 84 | $class = self::$decoder->getElementContent(); |
85 | 85 | self::$decoder->getElementEndTag(); |
86 | 86 | } |
87 | 87 | |
88 | 88 | $e = self::$decoder->peek(); |
89 | - if($e[EN_TYPE] == EN_TYPE_ENDTAG) { |
|
89 | + if ($e[EN_TYPE] == EN_TYPE_ENDTAG) { |
|
90 | 90 | self::$decoder->getElementEndTag(); |
91 | 91 | break; |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | $spa = $sc->GetCollection($folderid); |
96 | - if (! $spa) { |
|
96 | + if (!$spa) { |
|
97 | 97 | // The requested collection is not synchronized. |
98 | 98 | // check if the HierarchyCache is available, if not, trigger a HierarchySync |
99 | 99 | try { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): using saved sync state for '%s' id '%s'", $spa->GetContentClass(), $folderid)); |
119 | 119 | } |
120 | 120 | } |
121 | - if(!self::$decoder->getElementEndTag()) |
|
121 | + if (!self::$decoder->getElementEndTag()) |
|
122 | 122 | return false; |
123 | 123 | |
124 | 124 | // update pingable flags |
@@ -127,15 +127,15 @@ discard block |
||
127 | 127 | if (in_array($folderid, $pingable)) { |
128 | 128 | $spa->SetPingableFlag(true); |
129 | 129 | } |
130 | - else { |
|
130 | + else { |
|
131 | 131 | $spa->DelPingableFlag(); |
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
135 | - if(!self::$decoder->getElementEndTag()) |
|
135 | + if (!self::$decoder->getElementEndTag()) |
|
136 | 136 | return false; |
137 | 137 | |
138 | - if(!$this->lifetimeBetweenBound($sc->GetLifetime())){ |
|
138 | + if (!$this->lifetimeBetweenBound($sc->GetLifetime())) { |
|
139 | 139 | $pingstatus = SYNC_PINGSTATUS_HBOUTOFRANGE; |
140 | 140 | 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 | 141 | } |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | else { |
147 | 147 | // if no ping initialization data was sent, we check if we have pingable folders |
148 | 148 | // if not, we indicate that there is nothing to do. |
149 | - if (! $sc->PingableFolders()) { |
|
149 | + if (!$sc->PingableFolders()) { |
|
150 | 150 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
151 | 151 | ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): no pingable folders found and no initialization data sent. Returning SYNC_PINGSTATUS_FAILINGPARAMS."); |
152 | 152 | } |
153 | - elseif(!$this->lifetimeBetweenBound($sc->GetLifetime())){ |
|
153 | + elseif (!$this->lifetimeBetweenBound($sc->GetLifetime())) { |
|
154 | 154 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
155 | 155 | 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 | 156 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | catch (StatusException $ste) { |
168 | - switch($ste->getCode()) { |
|
168 | + switch ($ste->getCode()) { |
|
169 | 169 | case SyncCollections::ERROR_NO_COLLECTIONS: |
170 | 170 | $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; |
171 | 171 | break; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | self::$encoder->content($foundchanges ? SYNC_PINGSTATUS_CHANGES : SYNC_PINGSTATUS_HBEXPIRED); |
193 | 193 | self::$encoder->endTag(); |
194 | 194 | |
195 | - if (! $pingstatus) { |
|
195 | + if (!$pingstatus) { |
|
196 | 196 | self::$encoder->startTag(SYNC_PING_FOLDERS); |
197 | 197 | |
198 | 198 | if (empty($fakechanges)) |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | } |
226 | 226 | self::$encoder->endTag(); |
227 | 227 | } |
228 | - elseif($pingstatus == SYNC_PINGSTATUS_HBOUTOFRANGE){ |
|
228 | + elseif ($pingstatus == SYNC_PINGSTATUS_HBOUTOFRANGE) { |
|
229 | 229 | self::$encoder->startTag(SYNC_PING_LIFETIME); |
230 | - if($sc->GetLifetime() > PING_HIGHER_BOUND_LIFETIME){ |
|
230 | + if ($sc->GetLifetime() > PING_HIGHER_BOUND_LIFETIME) { |
|
231 | 231 | self::$encoder->content(PING_HIGHER_BOUND_LIFETIME); |
232 | 232 | } |
233 | - else{ |
|
233 | + else { |
|
234 | 234 | self::$encoder->content(PING_LOWER_BOUND_LIFETIME); |
235 | 235 | } |
236 | 236 | self::$encoder->endTag(); |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | * @access private |
254 | 254 | * @return boolean |
255 | 255 | */ |
256 | - private function lifetimeBetweenBound($lifetime){ |
|
257 | - if(PING_HIGHER_BOUND_LIFETIME !== false && PING_LOWER_BOUND_LIFETIME !== false){ |
|
256 | + private function lifetimeBetweenBound($lifetime) { |
|
257 | + if (PING_HIGHER_BOUND_LIFETIME !== false && PING_LOWER_BOUND_LIFETIME !== false) { |
|
258 | 258 | return ($lifetime <= PING_HIGHER_BOUND_LIFETIME && $lifetime >= PING_LOWER_BOUND_LIFETIME); |
259 | 259 | } |
260 | - if(PING_HIGHER_BOUND_LIFETIME !== false){ |
|
260 | + if (PING_HIGHER_BOUND_LIFETIME !== false) { |
|
261 | 261 | return $lifetime <= PING_HIGHER_BOUND_LIFETIME; |
262 | 262 | } |
263 | - if(PING_LOWER_BOUND_LIFETIME !== false){ |
|
263 | + if (PING_LOWER_BOUND_LIFETIME !== false) { |
|
264 | 264 | return $lifetime >= PING_LOWER_BOUND_LIFETIME; |
265 | 265 | } |
266 | 266 | return true; |
@@ -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(); |