/usr/share/d-push/lib/request/getitemestimate.php is in d-push 2.0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | <?php
/***********************************************
* File : getitemestimate.php
* Project : Z-Push
* Descr : Provides the GETITEMESTIMATE command
*
* Created : 16.02.2012
*
* Copyright 2007 - 2013 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation with the following additional
* term according to sec. 7:
*
* According to sec. 7 of the GNU Affero General Public License, version 3,
* the terms of the AGPL are supplemented with the following terms:
*
* "Zarafa" is a registered trademark of Zarafa B.V.
* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
* The licensing of the Program under the AGPL does not imply a trademark license.
* Therefore any rights, title and interest in our trademarks remain entirely with us.
*
* However, if you propagate an unmodified version of the Program you are
* allowed to use the term "Z-Push" to indicate that you distribute the Program.
* Furthermore you may use our trademarks where it is necessary to indicate
* the intended purpose of a product or service provided you use it in accordance
* with honest practices in industrial or commercial matters.
* If you want to propagate modified versions of the Program under the name "Z-Push",
* you may only do so if you have a written permission by Zarafa Deutschland GmbH
* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
class GetItemEstimate extends RequestProcessor {
/**
* Handles the GetItemEstimate command
* Returns an estimation of how many items will be synchronized at the next sync
* This is mostly used to show something in the progress bar
*
* @param int $commandCode
*
* @access public
* @return boolean
*/
public function Handle($commandCode) {
$sc = new SyncCollections();
if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE))
return false;
if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERS))
return false;
while(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDER)) {
$spa = new SyncParameters();
$spastatus = false;
// read the folder properties
while (1) {
if(self::$decoder->getElementStartTag(SYNC_SYNCKEY)) {
try {
$spa->SetSyncKey(self::$decoder->getElementContent());
}
catch (StateInvalidException $siex) {
$spastatus = SYNC_GETITEMESTSTATUS_SYNCSTATENOTPRIMED;
}
if(!self::$decoder->getElementEndTag())
return false;
}
elseif(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERID)) {
$spa->SetFolderId( self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
// conversation mode requested
elseif(self::$decoder->getElementStartTag(SYNC_CONVERSATIONMODE)) {
$spa->SetConversationMode(true);
if(($conversationmode = self::$decoder->getElementContent()) !== false) {
$spa->SetConversationMode((boolean)$conversationmode);
if(!self::$decoder->getElementEndTag())
return false;
}
}
// get items estimate does not necessarily send the folder type
elseif(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERTYPE)) {
$spa->SetContentClass(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
//TODO AS 2.5 and filtertype not set
elseif(self::$decoder->getElementStartTag(SYNC_FILTERTYPE)) {
$spa->SetFilterType(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
while(self::$decoder->getElementStartTag(SYNC_OPTIONS)) {
while(1) {
$firstOption = true;
// foldertype definition
if(self::$decoder->getElementStartTag(SYNC_FOLDERTYPE)) {
$foldertype = self::$decoder->getElementContent();
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetItemEstimate(): specified options block with foldertype '%s'", $foldertype));
// switch the foldertype for the next options
$spa->UseCPO($foldertype);
// set to synchronize all changes. The mobile could overwrite this value
$spa->SetFilterType(SYNC_FILTERTYPE_ALL);
if(!self::$decoder->getElementEndTag())
return false;
}
// if no foldertype is defined, use default cpo
else if ($firstOption){
$spa->UseCPO();
// set to synchronize all changes. The mobile could overwrite this value
$spa->SetFilterType(SYNC_FILTERTYPE_ALL);
}
$firstOption = false;
if(self::$decoder->getElementStartTag(SYNC_FILTERTYPE)) {
$spa->SetFilterType(self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
if(self::$decoder->getElementStartTag(SYNC_MAXITEMS)) {
$spa->SetWindowSize($maxitems = self::$decoder->getElementContent());
if(!self::$decoder->getElementEndTag())
return false;
}
$e = self::$decoder->peek();
if($e[EN_TYPE] == EN_TYPE_ENDTAG) {
self::$decoder->getElementEndTag();
break;
}
}
}
$e = self::$decoder->peek();
if($e[EN_TYPE] == EN_TYPE_ENDTAG) {
self::$decoder->getElementEndTag(); //SYNC_GETITEMESTIMATE_FOLDER
break;
}
}
// Process folder data
//In AS 14 request only collectionid is sent, without class
if (! $spa->HasContentClass() && $spa->HasFolderId()) {
try {
$spa->SetContentClass(self::$deviceManager->GetFolderClassFromCacheByID($spa->GetFolderId()));
}
catch (NoHierarchyCacheAvailableException $nhca) {
$spastatus = SYNC_GETITEMESTSTATUS_COLLECTIONINVALID;
}
}
// compatibility mode AS 1.0 - get folderid which was sent during GetHierarchy()
if (! $spa->HasFolderId() && $spa->HasContentClass()) {
$spa->SetFolderId(self::$deviceManager->GetFolderIdFromCacheByClass($spa->GetContentClass()));
}
// Add collection to SC and load state
$sc->AddCollection($spa);
if ($spastatus) {
// the CPO has a folder id now, so we can set the status
$sc->AddParameter($spa, "status", $spastatus);
}
else {
try {
$sc->AddParameter($spa, "state", self::$deviceManager->GetStateManager()->GetSyncState($spa->GetSyncKey()));
// if this is an additional folder the backend has to be setup correctly
if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetFolderId())))
throw new StatusException(sprintf("HandleGetItemEstimate() could not Setup() the backend for folder id '%s'", $spa->GetFolderId()), SYNC_GETITEMESTSTATUS_COLLECTIONINVALID);
}
catch (StateNotFoundException $snfex) {
// ok, the key is invalid. Question is, if the hierarchycache is still ok
//if not, we have to issue SYNC_GETITEMESTSTATUS_COLLECTIONINVALID which triggers a FolderSync
try {
self::$deviceManager->GetFolderClassFromCacheByID($spa->GetFolderId());
// we got here, so the HierarchyCache is ok
$sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_SYNCKKEYINVALID);
}
catch (NoHierarchyCacheAvailableException $nhca) {
$sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_COLLECTIONINVALID);
}
self::$topCollector->AnnounceInformation("StateNotFoundException ". $sc->GetParameter($spa, "status"), true);
}
catch (StatusException $stex) {
if ($stex->getCode() == SYNC_GETITEMESTSTATUS_COLLECTIONINVALID)
$sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_COLLECTIONINVALID);
else
$sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_SYNCSTATENOTPRIMED);
self::$topCollector->AnnounceInformation("StatusException ". $sc->GetParameter($spa, "status"), true);
}
}
}
if(!self::$decoder->getElementEndTag())
return false; //SYNC_GETITEMESTIMATE_FOLDERS
if(!self::$decoder->getElementEndTag())
return false; //SYNC_GETITEMESTIMATE_GETITEMESTIMATE
self::$encoder->startWBXML();
self::$encoder->startTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE);
{
$status = SYNC_GETITEMESTSTATUS_SUCCESS;
// look for changes in all collections
try {
$sc->CountChanges();
}
catch (StatusException $ste) {
$status = SYNC_GETITEMESTSTATUS_COLLECTIONINVALID;
}
$changes = $sc->GetChangedFolderIds();
foreach($sc as $folderid => $spa) {
self::$encoder->startTag(SYNC_GETITEMESTIMATE_RESPONSE);
{
if ($sc->GetParameter($spa, "status"))
$status = $sc->GetParameter($spa, "status");
self::$encoder->startTag(SYNC_GETITEMESTIMATE_STATUS);
self::$encoder->content($status);
self::$encoder->endTag();
self::$encoder->startTag(SYNC_GETITEMESTIMATE_FOLDER);
{
self::$encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERTYPE);
self::$encoder->content($spa->GetContentClass());
self::$encoder->endTag();
self::$encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERID);
self::$encoder->content($spa->GetFolderId());
self::$encoder->endTag();
if (isset($changes[$folderid]) && $changes[$folderid] !== false) {
self::$encoder->startTag(SYNC_GETITEMESTIMATE_ESTIMATE);
self::$encoder->content($changes[$folderid]);
self::$encoder->endTag();
if ($changes[$folderid] > 0)
self::$topCollector->AnnounceInformation(sprintf("%s %d changes", $spa->GetContentClass(), $changes[$folderid]), true);
}
}
self::$encoder->endTag();
}
self::$encoder->endTag();
}
if (array_sum($changes) == 0)
self::$topCollector->AnnounceInformation("No changes found", true);
}
self::$encoder->endTag();
return true;
}
}
?>
|