1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : settings.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : Provides the SETTINGS command |
---|
6 | * |
---|
7 | * Created : 16.02.2012 |
---|
8 | * |
---|
9 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
10 | * |
---|
11 | * This program is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
13 | * as published by the Free Software Foundation with the following additional |
---|
14 | * term according to sec. 7: |
---|
15 | * |
---|
16 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
17 | * the terms of the AGPL are supplemented with the following terms: |
---|
18 | * |
---|
19 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
20 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
21 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
22 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
23 | * |
---|
24 | * However, if you propagate an unmodified version of the Program you are |
---|
25 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
26 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
27 | * the intended purpose of a product or service provided you use it in accordance |
---|
28 | * with honest practices in industrial or commercial matters. |
---|
29 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
30 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
31 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
32 | * |
---|
33 | * This program is distributed in the hope that it will be useful, |
---|
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
36 | * GNU Affero General Public License for more details. |
---|
37 | * |
---|
38 | * You should have received a copy of the GNU Affero General Public License |
---|
39 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
40 | * |
---|
41 | * Consult LICENSE file for details |
---|
42 | ************************************************/ |
---|
43 | |
---|
44 | class Settings extends RequestProcessor { |
---|
45 | |
---|
46 | /** |
---|
47 | * Handles the Settings command |
---|
48 | * |
---|
49 | * @param int $commandCode |
---|
50 | * |
---|
51 | * @access public |
---|
52 | * @return boolean |
---|
53 | */ |
---|
54 | public function Handle($commandCode) { |
---|
55 | if (!self::$decoder->getElementStartTag(SYNC_SETTINGS_SETTINGS)) |
---|
56 | return false; |
---|
57 | |
---|
58 | //save the request parameters |
---|
59 | $request = array(); |
---|
60 | |
---|
61 | // Loop through properties. Possible are: |
---|
62 | // - Out of office |
---|
63 | // - DevicePassword |
---|
64 | // - DeviceInformation |
---|
65 | // - UserInformation |
---|
66 | // Each of them should only be once per request. Each property must be processed in order. |
---|
67 | while (1) { |
---|
68 | $propertyName = ""; |
---|
69 | if (self::$decoder->getElementStartTag(SYNC_SETTINGS_OOF)) { |
---|
70 | $propertyName = SYNC_SETTINGS_OOF; |
---|
71 | } |
---|
72 | if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEPW)) { |
---|
73 | $propertyName = SYNC_SETTINGS_DEVICEPW; |
---|
74 | } |
---|
75 | if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEINFORMATION)) { |
---|
76 | $propertyName = SYNC_SETTINGS_DEVICEINFORMATION; |
---|
77 | } |
---|
78 | if (self::$decoder->getElementStartTag(SYNC_SETTINGS_USERINFORMATION)) { |
---|
79 | $propertyName = SYNC_SETTINGS_USERINFORMATION; |
---|
80 | } |
---|
81 | //TODO - check if it is necessary |
---|
82 | //no property name available - break |
---|
83 | if (!$propertyName) |
---|
84 | break; |
---|
85 | |
---|
86 | //the property name is followed by either get or set |
---|
87 | if (self::$decoder->getElementStartTag(SYNC_SETTINGS_GET)) { |
---|
88 | //get is only available for OOF and user information |
---|
89 | switch ($propertyName) { |
---|
90 | case SYNC_SETTINGS_OOF: |
---|
91 | $oofGet = new SyncOOF(); |
---|
92 | $oofGet->Decode(self::$decoder); |
---|
93 | if(!self::$decoder->getElementEndTag()) |
---|
94 | return false; // SYNC_SETTINGS_GET |
---|
95 | break; |
---|
96 | |
---|
97 | case SYNC_SETTINGS_USERINFORMATION: |
---|
98 | $userInformation = new SyncUserInformation(); |
---|
99 | break; |
---|
100 | |
---|
101 | default: |
---|
102 | //TODO: a special status code needed? |
---|
103 | ZLog::Write(LOGLEVEL_WARN, sprintf ("This property ('%s') is not allowed to use get in request", $propertyName)); |
---|
104 | } |
---|
105 | } |
---|
106 | elseif (self::$decoder->getElementStartTag(SYNC_SETTINGS_SET)) { |
---|
107 | //set is available for OOF, device password and device information |
---|
108 | switch ($propertyName) { |
---|
109 | case SYNC_SETTINGS_OOF: |
---|
110 | $oofSet = new SyncOOF(); |
---|
111 | $oofSet->Decode(self::$decoder); |
---|
112 | //TODO check - do it after while(1) finished? |
---|
113 | break; |
---|
114 | |
---|
115 | case SYNC_SETTINGS_DEVICEPW: |
---|
116 | //TODO device password |
---|
117 | $devicepassword = new SyncDevicePassword(); |
---|
118 | $devicepassword->Decode(self::$decoder); |
---|
119 | break; |
---|
120 | |
---|
121 | case SYNC_SETTINGS_DEVICEINFORMATION: |
---|
122 | $deviceinformation = new SyncDeviceInformation(); |
---|
123 | $deviceinformation->Decode(self::$decoder); |
---|
124 | self::$deviceManager->SaveDeviceInformation($deviceinformation); |
---|
125 | break; |
---|
126 | |
---|
127 | default: |
---|
128 | //TODO: a special status code needed? |
---|
129 | ZLog::Write(LOGLEVEL_WARN, sprintf ("This property ('%s') is not allowed to use set in request", $propertyName)); |
---|
130 | } |
---|
131 | |
---|
132 | if(!self::$decoder->getElementEndTag()) |
---|
133 | return false; // SYNC_SETTINGS_SET |
---|
134 | } |
---|
135 | else { |
---|
136 | ZLog::Write(LOGLEVEL_WARN, sprintf("Neither get nor set found for property '%s'", $propertyName)); |
---|
137 | return false; |
---|
138 | } |
---|
139 | |
---|
140 | if(!self::$decoder->getElementEndTag()) |
---|
141 | return false; // SYNC_SETTINGS_OOF or SYNC_SETTINGS_DEVICEPW or SYNC_SETTINGS_DEVICEINFORMATION or SYNC_SETTINGS_USERINFORMATION |
---|
142 | |
---|
143 | //break if it reached the endtag |
---|
144 | $e = self::$decoder->peek(); |
---|
145 | if($e[EN_TYPE] == EN_TYPE_ENDTAG) { |
---|
146 | self::$decoder->getElementEndTag(); //SYNC_SETTINGS_SETTINGS |
---|
147 | break; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | $status = SYNC_SETTINGSSTATUS_SUCCESS; |
---|
152 | |
---|
153 | //TODO put it in try catch block |
---|
154 | //TODO implement Settings in the backend |
---|
155 | //TODO save device information in device manager |
---|
156 | //TODO status handling |
---|
157 | // $data = self::$backend->Settings($request); |
---|
158 | |
---|
159 | self::$encoder->startWBXML(); |
---|
160 | self::$encoder->startTag(SYNC_SETTINGS_SETTINGS); |
---|
161 | |
---|
162 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
163 | self::$encoder->content($status); |
---|
164 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
165 | |
---|
166 | //get oof settings |
---|
167 | if (isset($oofGet)) { |
---|
168 | $oofGet = self::$backend->Settings($oofGet); |
---|
169 | self::$encoder->startTag(SYNC_SETTINGS_OOF); |
---|
170 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
171 | self::$encoder->content($oofGet->Status); |
---|
172 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
173 | |
---|
174 | self::$encoder->startTag(SYNC_SETTINGS_GET); |
---|
175 | $oofGet->Encode(self::$encoder); |
---|
176 | self::$encoder->endTag(); //SYNC_SETTINGS_GET |
---|
177 | self::$encoder->endTag(); //SYNC_SETTINGS_OOF |
---|
178 | } |
---|
179 | |
---|
180 | //get user information |
---|
181 | //TODO none email address found |
---|
182 | if (isset($userInformation)) { |
---|
183 | self::$backend->Settings($userInformation); |
---|
184 | self::$encoder->startTag(SYNC_SETTINGS_USERINFORMATION); |
---|
185 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
186 | self::$encoder->content($userInformation->Status); |
---|
187 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
188 | |
---|
189 | self::$encoder->startTag(SYNC_SETTINGS_GET); |
---|
190 | $userInformation->Encode(self::$encoder); |
---|
191 | self::$encoder->endTag(); //SYNC_SETTINGS_GET |
---|
192 | self::$encoder->endTag(); //SYNC_SETTINGS_USERINFORMATION |
---|
193 | } |
---|
194 | |
---|
195 | //set out of office |
---|
196 | if (isset($oofSet)) { |
---|
197 | $oofSet = self::$backend->Settings($oofSet); |
---|
198 | self::$encoder->startTag(SYNC_SETTINGS_OOF); |
---|
199 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
200 | self::$encoder->content($oofSet->Status); |
---|
201 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
202 | self::$encoder->endTag(); //SYNC_SETTINGS_OOF |
---|
203 | } |
---|
204 | |
---|
205 | //set device passwort |
---|
206 | if (isset($devicepassword)) { |
---|
207 | self::$encoder->startTag(SYNC_SETTINGS_DEVICEPW); |
---|
208 | self::$encoder->startTag(SYNC_SETTINGS_SET); |
---|
209 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
210 | self::$encoder->content($devicepassword->Status); |
---|
211 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
212 | self::$encoder->endTag(); //SYNC_SETTINGS_SET |
---|
213 | self::$encoder->endTag(); //SYNC_SETTINGS_DEVICEPW |
---|
214 | } |
---|
215 | |
---|
216 | //set device information |
---|
217 | if (isset($deviceinformation)) { |
---|
218 | self::$encoder->startTag(SYNC_SETTINGS_DEVICEINFORMATION); |
---|
219 | self::$encoder->startTag(SYNC_SETTINGS_SET); |
---|
220 | self::$encoder->startTag(SYNC_SETTINGS_STATUS); |
---|
221 | self::$encoder->content($deviceinformation->Status); |
---|
222 | self::$encoder->endTag(); //SYNC_SETTINGS_STATUS |
---|
223 | self::$encoder->endTag(); //SYNC_SETTINGS_SET |
---|
224 | self::$encoder->endTag(); //SYNC_SETTINGS_DEVICEINFORMATION |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | self::$encoder->endTag(); //SYNC_SETTINGS_SETTINGS |
---|
229 | |
---|
230 | return true; |
---|
231 | } |
---|
232 | } |
---|
233 | ?> |
---|