00001 /* 00002 * Funambol is a mobile platform developed by Funambol, Inc. 00003 * Copyright (C) 2003 - 2007 Funambol, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Affero General Public License version 3 as published by 00007 * the Free Software Foundation with the addition of the following permission 00008 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 00009 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 00010 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU Affero General Public License 00018 * along with this program; if not, see http://www.gnu.org/licenses or write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00020 * MA 02110-1301 USA. 00021 * 00022 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 00023 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com. 00024 * 00025 * The interactive user interfaces in modified source and object code versions 00026 * of this program must display Appropriate Legal Notices, as required under 00027 * Section 5 of the GNU Affero General Public License version 3. 00028 * 00029 * In accordance with Section 7(b) of the GNU Affero General Public License 00030 * version 3, these Appropriate Legal Notices must retain the display of the 00031 * "Powered by Funambol" logo. If the display of the logo is not reasonably 00032 * feasible for technical reasons, the Appropriate Legal Notices must display 00033 * the words "Powered by Funambol". 00034 */ 00035 00036 #ifndef INCL_SYNCML_BUILDER 00037 #define INCL_SYNCML_BUILDER 00038 00040 #include "spds/DataTransformer.h" 00041 #include "spds/SyncSource.h" 00042 #include "spds/SyncMap.h" 00043 #include "syncml/core/TagNames.h" 00044 #include "syncml/core/ObjectDel.h" 00045 #include "syncml/formatter/Formatter.h" 00046 #include "base/globalsdef.h" 00047 #include "spds/Chunk.h" 00048 00049 BEGIN_NAMESPACE 00050 00051 typedef enum { 00052 SYNCML_DM_1_1 = 101, 00053 SYNCML_DM_1_2, 00054 SYNCML_1_0 = 200, 00055 SYNCML_1_1, 00056 SYNCML_1_2 00057 } SyncMLProtocolFlavour; 00058 00059 00060 class SyncMLBuilder { 00061 public: 00062 SyncMLBuilder(SyncMLProtocolFlavour protocol = SYNCML_1_2); 00063 ~SyncMLBuilder(); 00064 SyncMLBuilder(char* t, char* d, SyncMLProtocolFlavour protocol = SYNCML_1_2); 00065 00066 /* 00067 * Convert the SyncML object into an xml message 00068 */ 00069 char* prepareMsg(SyncML* syncml); 00070 00071 /* 00072 * Convert the SyncML object into an xml message 00073 */ 00074 SyncML* prepareSyncML(ArrayList* commands, bool final); 00075 00076 /* 00077 * Set init parameters. 00078 * 00079 */ 00080 void set(const char* t, const char* d); 00081 00082 /* 00083 * Prepare the init SyncML* message with credential and db alert to sync 00084 * 00085 * @param maxMsgSize used as MaxMsgSize value in Meta part of the message unless 0 00086 * @param maxObjSize used as MaxObjSize value in Meta part of the message unless 0 00087 */ 00088 SyncML* prepareInitObject(Cred* cred, ArrayList* alerts, ArrayList* commands, 00089 unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0); 00090 00091 /* 00092 * Prepare the SyncHdr message with credential if not null 00093 * 00094 * @param maxMsgSize used as MaxMsgSize value in Meta part of the message unless 0 00095 * @param maxObjSize used as MaxObjSize value in Meta part of the message unless 0 00096 */ 00097 SyncHdr* prepareSyncHdr(Cred* cred, unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0); 00098 00099 /* 00100 * Prepare the init alert 00101 */ 00102 Alert* prepareInitAlert(SyncSource& source, unsigned long maxObjSize = 0); 00103 00104 /* 00105 * Prepare the special init alert for Address Change Notification 00106 */ 00107 Alert* prepareAddrChangeAlert(SyncSource& source); 00108 00109 /* 00110 * Prepare alert with a specific code, defaults to 222 which requests 00111 * the server changes. 00112 */ 00113 Alert* prepareAlert(SyncSource& source, int code=222); 00114 00115 /* 00116 * Prepare the status for Sync Header 00117 */ 00118 Status* prepareSyncHdrStatus(Chal* chal, int data); 00119 00120 /* 00121 * Prepare the status for Alert command 00122 */ 00123 Status* prepareAlertStatus(SyncSource& s, ArrayList* alert, int authStatusCode); 00124 00125 /* 00126 * Prepare the status for Item command. COMMAND could be ADD, REPLACE, DEL 00127 */ 00128 Status* prepareItemStatus(const char* COMMAND, const char* key, const char* cmdRef, int code); 00129 00130 /* 00131 * Add the status to the corrent list of commands. It is responsible to collapse the status if needed 00132 */ 00133 void addItemStatus(ArrayList* previousStatus, Status* status); 00134 00135 /* 00136 * Prepare the status for Sync command 00137 */ 00138 Status* prepareSyncStatus(SyncSource& source, Sync* sync); 00139 00143 Status* prepareCmdStatus(AbstractCommand &cmd, int status); 00144 00149 AbstractCommand *prepareDevInf(AbstractCommand *cmd, DevInf &devInf); 00150 00154 AbstractCommand* prepareServerDevInf(); 00155 00156 /* 00157 * Prepare the Sync object. It doesn't contain any items. It is to prepare the insert of items 00158 */ 00159 Sync* prepareSyncCommand(SyncSource& source); 00160 00161 /* 00162 * Prepare the Map object. It doesn't containt anything. It is to prepare the insert of map items 00163 */ 00164 Map* prepareMapCommand(SyncSource& source); 00165 00166 /* 00167 * Prepare the MapItem. It could contain only one MapItem 00168 */ 00169 MapItem* prepareMapItem(SyncMap* syncMap); 00170 00171 /* 00172 * @param[in, out] syncItemOffset number of bytes of item data already sent, continue there and update it 00173 * @param maxBytes maximum amount of item data to send; always send at least one byte to ensure progress 00174 * @param[out] sentBytes number of bytes actually included in message 00175 */ 00176 ArrayList* prepareItem(SyncItem* syncItem, 00177 long &syncItemOffset, long maxBytes, long &sentBytes, 00178 const char* type, const char* COMMAND); 00179 /* 00180 * @param syncItem 00181 * @param chunk the chunk item to be added 00182 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00183 * @return item the Item object to be added in the list of command 00184 */ 00185 Item* prepareItemChunk(SyncItem* syncItem, 00186 Chunk* chunk, 00187 const char* COMMAND); 00188 00189 00190 /* 00191 * Add the MapItem to the Map command. 00192 */ 00193 void addMapItem(Map* map, MapItem* mapItem); 00194 00195 /* 00196 * Add a SyncItem into the modificationCommand. It is responsible to collapse if needed. 00197 * If the modificationCommand is NULL, then this is the first item and modificationCommand 00198 * is initialized. 00199 * 00200 * @param[in, out] modificationCommand new items are added here, created if necessary 00201 * @param[in, out] syncItemOffset number of bytes of item data already sent, continue there and update it 00202 * @param maxBytes maximum amount of item data to send; always send at least one byte to ensure progress 00203 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00204 * @param syncItem item to be added, NULL causes the call to return without doing anything 00205 * @param defaultType fallback if the syncItem does not define a type 00206 * @return number of bytes of item data included 00207 */ 00208 long addItem(ModificationCommand* &modificationCommand, 00209 long &syncItemOffset, long maxBytes, 00210 const char* COMMAND, SyncItem* syncItem, 00211 const char* defaultType); 00212 00213 /* 00214 * Add a Chunk into the modificationCommand. 00215 * If the modificationCommand is NULL, then this is the first item and modificationCommand 00216 * is initialized. 00217 * 00218 * @param[in, out] modificationCommand new items are added here, created if necessary 00219 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00220 * @param syncItem 00221 * @param chunk chunk item to be added, NULL causes the call to return without doing anything 00222 * @param defaultType fallback if the syncItem does not define a type 00223 * @return number of bytes of item data included, that is the chunk size 00224 */ 00225 long addChunk(ModificationCommand* &modificationCommand, 00226 const char* COMMAND, SyncItem* syncItem, Chunk* chunk, 00227 const char* defaultType); 00228 /* 00229 * Reset the cmdID counter 00230 */ 00231 void resetCommandID(); 00232 00233 /* 00234 * increase the msgID counter 00235 */ 00236 void increaseMsgRef(); 00237 00238 /* 00239 * reset MsgId counter 00240 */ 00241 00242 void resetMessageID(); 00243 00244 /* 00245 * reset MsgRef counter 00246 */ 00247 void resetMsgRef(); 00248 00249 private: 00250 00251 void initialize(); 00252 00253 char* target; 00254 char* device; 00255 00256 SyncMLProtocolFlavour protocol; 00257 00264 ComplexData* getComplexData(Chunk* chunk); 00265 00266 unsigned long sessionID; 00267 unsigned int msgID ; 00268 unsigned int cmdID ; 00269 unsigned int msgRef ; 00270 00271 ComplexData* getComplexData(SyncItem* syncItem, long &syncItemOffset, long maxBytes, long &sentBytes); 00272 00273 }; 00274 00275 00276 END_NAMESPACE 00277 00279 #endif