[7589] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : backend.php |
---|
| 4 | * Project : Z-Push |
---|
| 5 | * Descr : This is what C++ people |
---|
| 6 | * (and PHP5) would call an |
---|
| 7 | * abstract class. The |
---|
| 8 | * backend module itself is |
---|
| 9 | * responsible for converting any |
---|
| 10 | * necessary types and formats. |
---|
| 11 | * |
---|
| 12 | * If you wish to implement a new |
---|
| 13 | * backend, all you need to do is |
---|
| 14 | * to subclass the following class |
---|
| 15 | * (or implement an IBackend) |
---|
| 16 | * and place the subclassed file in |
---|
| 17 | * the backend/yourBackend directory. You can |
---|
| 18 | * then use your backend by |
---|
| 19 | * specifying it in the config.php file |
---|
| 20 | * |
---|
| 21 | * Created : 01.10.2007 |
---|
| 22 | * |
---|
| 23 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
| 24 | * |
---|
| 25 | * This program is free software: you can redistribute it and/or modify |
---|
| 26 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
| 27 | * as published by the Free Software Foundation with the following additional |
---|
| 28 | * term according to sec. 7: |
---|
| 29 | * |
---|
| 30 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
| 31 | * the terms of the AGPL are supplemented with the following terms: |
---|
| 32 | * |
---|
| 33 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
| 34 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
| 35 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
| 36 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
| 37 | * |
---|
| 38 | * However, if you propagate an unmodified version of the Program you are |
---|
| 39 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
| 40 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
| 41 | * the intended purpose of a product or service provided you use it in accordance |
---|
| 42 | * with honest practices in industrial or commercial matters. |
---|
| 43 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
| 44 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
| 45 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
| 46 | * |
---|
| 47 | * This program is distributed in the hope that it will be useful, |
---|
| 48 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 49 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 50 | * GNU Affero General Public License for more details. |
---|
| 51 | * |
---|
| 52 | * You should have received a copy of the GNU Affero General Public License |
---|
| 53 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 54 | * |
---|
| 55 | * Consult LICENSE file for details |
---|
| 56 | ************************************************/ |
---|
| 57 | |
---|
| 58 | abstract class Backend implements IBackend { |
---|
| 59 | protected $permanentStorage; |
---|
| 60 | protected $stateStorage; |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * Constructor |
---|
| 64 | * |
---|
| 65 | * @access public |
---|
| 66 | */ |
---|
| 67 | public function Backend() { |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * Returns a IStateMachine implementation used to save states |
---|
| 72 | * The default StateMachine should be used here, so, false is fine |
---|
| 73 | * |
---|
| 74 | * @access public |
---|
| 75 | * @return boolean/object |
---|
| 76 | */ |
---|
| 77 | public function GetStateMachine() { |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * Returns a ISearchProvider implementation used for searches |
---|
| 83 | * the SearchProvider is just a stub |
---|
| 84 | * |
---|
| 85 | * @access public |
---|
| 86 | * @return object Implementation of ISearchProvider |
---|
| 87 | */ |
---|
| 88 | public function GetSearchProvider() { |
---|
| 89 | return new SearchProvider(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * Indicates which AS version is supported by the backend. |
---|
| 94 | * By default AS version 2.5 (ASV_25) is returned (Z-Push 1 standard). |
---|
| 95 | * Subclasses can overwrite this method to set another AS version |
---|
| 96 | * |
---|
| 97 | * @access public |
---|
| 98 | * @return string AS version constant |
---|
| 99 | */ |
---|
| 100 | public function GetSupportedASVersion() { |
---|
| 101 | return ZPush::ASV_25; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /********************************************************************* |
---|
| 105 | * Methods to be implemented |
---|
| 106 | * |
---|
| 107 | * public function Logon($username, $domain, $password); |
---|
| 108 | * public function Setup($store, $checkACLonly = false, $folderid = false); |
---|
| 109 | * public function Logoff(); |
---|
| 110 | * public function GetHierarchy(); |
---|
| 111 | * public function GetImporter($folderid = false); |
---|
| 112 | * public function GetExporter($folderid = false); |
---|
| 113 | * public function SendMail($sm); |
---|
| 114 | * public function Fetch($folderid, $id, $contentparameters); |
---|
| 115 | * public function GetWasteBasket(); |
---|
| 116 | * public function GetAttachmentData($attname); |
---|
| 117 | * public function MeetingResponse($requestid, $folderid, $response); |
---|
| 118 | * |
---|
| 119 | */ |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Deletes all contents of the specified folder. |
---|
| 123 | * This is generally used to empty the trash (wastebasked), but could also be used on any |
---|
| 124 | * other folder. |
---|
| 125 | * |
---|
| 126 | * @param string $folderid |
---|
| 127 | * @param boolean $includeSubfolders (opt) also delete sub folders, default true |
---|
| 128 | * |
---|
| 129 | * @access public |
---|
| 130 | * @return boolean |
---|
| 131 | * @throws StatusException |
---|
| 132 | */ |
---|
| 133 | public function EmptyFolder($folderid, $includeSubfolders = true) { |
---|
| 134 | return false; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | * Indicates if the backend has a ChangesSink. |
---|
| 139 | * A sink is an active notification mechanism which does not need polling. |
---|
| 140 | * |
---|
| 141 | * @access public |
---|
| 142 | * @return boolean |
---|
| 143 | */ |
---|
| 144 | public function HasChangesSink() { |
---|
| 145 | return false; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * The folder should be considered by the sink. |
---|
| 150 | * Folders which were not initialized should not result in a notification |
---|
| 151 | * of IBacken->ChangesSink(). |
---|
| 152 | * |
---|
| 153 | * @param string $folderid |
---|
| 154 | * |
---|
| 155 | * @access public |
---|
| 156 | * @return boolean false if there is any problem with that folder |
---|
| 157 | */ |
---|
| 158 | public function ChangesSinkInitialize($folderid) { |
---|
| 159 | return false; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * The actual ChangesSink. |
---|
| 164 | * For max. the $timeout value this method should block and if no changes |
---|
| 165 | * are available return an empty array. |
---|
| 166 | * If changes are available a list of folderids is expected. |
---|
| 167 | * |
---|
| 168 | * @param int $timeout max. amount of seconds to block |
---|
| 169 | * |
---|
| 170 | * @access public |
---|
| 171 | * @return array |
---|
| 172 | */ |
---|
| 173 | public function ChangesSink($timeout = 30) { |
---|
| 174 | return array(); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | /** |
---|
| 178 | * Applies settings to and gets informations from the device |
---|
| 179 | * |
---|
| 180 | * @param SyncObject $settings (SyncOOF or SyncUserInformation possible) |
---|
| 181 | * |
---|
| 182 | * @access public |
---|
| 183 | * @return SyncObject $settings |
---|
| 184 | */ |
---|
| 185 | public function Settings($settings) { |
---|
| 186 | if ($settings instanceof SyncOOF || $settings instanceof SyncUserInformation) |
---|
| 187 | $settings->Status = SYNC_SETTINGSSTATUS_SUCCESS; |
---|
| 188 | return $settings; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | /**---------------------------------------------------------------------------------------------------------- |
---|
| 193 | * Protected methods for BackendStorage |
---|
| 194 | * |
---|
| 195 | * Backends can use a permanent and a state related storage to save additional data |
---|
| 196 | * used during the synchronization. |
---|
| 197 | * |
---|
| 198 | * While permament storage is bound to the device and user, state related data works linked |
---|
| 199 | * to the regular states (and its counters). |
---|
| 200 | * |
---|
| 201 | * Both consist of a StateObject, while the backend can decide what to save in it. |
---|
| 202 | * |
---|
| 203 | * Before using $this->permanentStorage and $this->stateStorage the initilize methods have to be |
---|
| 204 | * called from the backend. |
---|
| 205 | * |
---|
| 206 | * Backend->LogOff() must call $this->SaveStorages() so the data is written to disk! |
---|
| 207 | * |
---|
| 208 | * These methods are an abstraction layer for StateManager->Get/SetBackendStorage() |
---|
| 209 | * which can also be used independently. |
---|
| 210 | */ |
---|
| 211 | |
---|
| 212 | /** |
---|
| 213 | * Loads the permanent storage data of the user and device |
---|
| 214 | * |
---|
| 215 | * @access protected |
---|
| 216 | * @return |
---|
| 217 | */ |
---|
| 218 | protected function InitializePermanentStorage() { |
---|
| 219 | if (!isset($this->permanentStorage)) { |
---|
| 220 | try { |
---|
| 221 | $this->permanentStorage = ZPush::GetDeviceManager()->GetStateManager()->GetBackendStorage(StateManager::BACKENDSTORAGE_PERMANENT); |
---|
| 222 | } |
---|
| 223 | catch (StateNotYetAvailableException $snyae) { |
---|
| 224 | $this->permanentStorage = new StateObject(); |
---|
| 225 | } |
---|
| 226 | catch(StateNotFoundException $snfe) { |
---|
| 227 | $this->permanentStorage = new StateObject(); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | * Loads the state related storage data of the user and device |
---|
| 234 | * All data not necessary for the next state should be removed |
---|
| 235 | * |
---|
| 236 | * @access protected |
---|
| 237 | * @return |
---|
| 238 | */ |
---|
| 239 | protected function InitializeStateStorage() { |
---|
| 240 | if (!isset($this->stateStorage)) { |
---|
| 241 | try { |
---|
| 242 | $this->stateStorage = ZPush::GetDeviceManager()->GetStateManager()->GetBackendStorage(StateManager::BACKENDSTORAGE_STATE); |
---|
| 243 | } |
---|
| 244 | catch (StateNotYetAvailableException $snyae) { |
---|
| 245 | $this->stateStorage = new StateObject(); |
---|
| 246 | } |
---|
| 247 | catch(StateNotFoundException $snfe) { |
---|
| 248 | $this->stateStorage = new StateObject(); |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /** |
---|
| 254 | * Saves the permanent and state related storage data of the user and device |
---|
| 255 | * if they were loaded previousily |
---|
| 256 | * If the backend storage is used this should be called |
---|
| 257 | * |
---|
| 258 | * @access protected |
---|
| 259 | * @return |
---|
| 260 | */ |
---|
| 261 | protected function SaveStorages() { |
---|
| 262 | if (isset($this->permanentStorage)) { |
---|
| 263 | try { |
---|
| 264 | ZPush::GetDeviceManager()->GetStateManager()->SetBackendStorage($this->permanentStorage, StateManager::BACKENDSTORAGE_PERMANENT); |
---|
| 265 | } |
---|
| 266 | catch (StateNotYetAvailableException $snyae) { } |
---|
| 267 | catch(StateNotFoundException $snfe) { } |
---|
| 268 | } |
---|
| 269 | if (isset($this->stateStorage)) { |
---|
| 270 | try { |
---|
| 271 | $this->storage_state = ZPush::GetDeviceManager()->GetStateManager()->SetBackendStorage($this->stateStorage, StateManager::BACKENDSTORAGE_STATE); |
---|
| 272 | } |
---|
| 273 | catch (StateNotYetAvailableException $snyae) { } |
---|
| 274 | catch(StateNotFoundException $snfe) { } |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | } |
---|
| 279 | ?> |
---|