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 class SyncMLBuilder { 00052 00053 public: 00054 SyncMLBuilder(); 00055 ~SyncMLBuilder(); 00056 SyncMLBuilder(char* t, char* d); 00057 00058 /* 00059 * Convert the SyncML object into an xml message 00060 */ 00061 char* prepareMsg(SyncML* syncml); 00062 00063 /* 00064 * Convert the SyncML object into an xml message 00065 */ 00066 SyncML* prepareSyncML(ArrayList* commands, bool final); 00067 00068 /* 00069 * Set init parameters. 00070 * 00071 */ 00072 void set(const char* t, const char* d); 00073 00074 /* 00075 * Prepare the init SyncML* message with credential and db alert to sync 00076 * 00077 * @param maxMsgSize used as MaxMsgSize value in Meta part of the message unless 0 00078 * @param maxObjSize used as MaxObjSize value in Meta part of the message unless 0 00079 */ 00080 SyncML* prepareInitObject(Cred* cred, ArrayList* alerts, ArrayList* commands, 00081 unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0); 00082 00083 /* 00084 * Prepare the SyncHdr message with credential if not null 00085 * 00086 * @param maxMsgSize used as MaxMsgSize value in Meta part of the message unless 0 00087 * @param maxObjSize used as MaxObjSize value in Meta part of the message unless 0 00088 */ 00089 SyncHdr* prepareSyncHdr(Cred* cred, unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0); 00090 00091 /* 00092 * Prepare the init alert 00093 */ 00094 Alert* prepareInitAlert(SyncSource& source, unsigned long maxObjSize = 0); 00095 00096 /* 00097 * Prepare the special init alert for Address Change Notification 00098 */ 00099 Alert* prepareAddrChangeAlert(SyncSource& source); 00100 00101 /* 00102 * Prepare alert with a specific code, defaults to 222 which requests 00103 * the server changes. 00104 */ 00105 Alert* prepareAlert(SyncSource& source, int code=222); 00106 00107 /* 00108 * Prepare the status for Sync Header 00109 */ 00110 Status* prepareSyncHdrStatus(Chal* chal, int data); 00111 00112 /* 00113 * Prepare the status for Alert command 00114 */ 00115 Status* prepareAlertStatus(SyncSource& s, ArrayList* alert, int authStatusCode); 00116 00117 /* 00118 * Prepare the status for Item command. COMMAND could be ADD, REPLACE, DEL 00119 */ 00120 Status* prepareItemStatus(const char* COMMAND, const char* key, const char* cmdRef, int code); 00121 00122 /* 00123 * Add the status to the corrent list of commands. It is responsible to collapse the status if needed 00124 */ 00125 void addItemStatus(ArrayList* previousStatus, Status* status); 00126 00127 /* 00128 * Prepare the status for Sync command 00129 */ 00130 Status* prepareSyncStatus(SyncSource& source, Sync* sync); 00131 00135 Status* prepareCmdStatus(AbstractCommand &cmd, int status); 00136 00141 AbstractCommand *prepareDevInf(AbstractCommand *cmd, DevInf &devInf); 00142 00146 AbstractCommand* prepareServerDevInf(); 00147 00148 /* 00149 * Prepare the Sync object. It doesn't contain any items. It is to prepare the insert of items 00150 */ 00151 Sync* prepareSyncCommand(SyncSource& source); 00152 00153 /* 00154 * Prepare the Map object. It doesn't containt anything. It is to prepare the insert of map items 00155 */ 00156 Map* prepareMapCommand(SyncSource& source); 00157 00158 /* 00159 * Prepare the MapItem. It could contain only one MapItem 00160 */ 00161 MapItem* prepareMapItem(SyncMap* syncMap); 00162 00163 /* 00164 * @param[in, out] syncItemOffset number of bytes of item data already sent, continue there and update it 00165 * @param maxBytes maximum amount of item data to send; always send at least one byte to ensure progress 00166 * @param[out] sentBytes number of bytes actually included in message 00167 */ 00168 ArrayList* prepareItem(SyncItem* syncItem, 00169 long &syncItemOffset, long maxBytes, long &sentBytes, 00170 const char* type, const char* COMMAND); 00171 /* 00172 * @param syncItem 00173 * @param chunk the chunk item to be added 00174 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00175 * @return item the Item object to be added in the list of command 00176 */ 00177 Item* prepareItemChunk(SyncItem* syncItem, 00178 Chunk* chunk, 00179 const char* COMMAND); 00180 00181 00182 /* 00183 * Add the MapItem to the Map command. 00184 */ 00185 void addMapItem(Map* map, MapItem* mapItem); 00186 00187 /* 00188 * Add a SyncItem into the modificationCommand. It is responsible to collapse if needed. 00189 * If the modificationCommand is NULL, then this is the first item and modificationCommand 00190 * is initialized. 00191 * 00192 * @param[in, out] modificationCommand new items are added here, created if necessary 00193 * @param[in, out] syncItemOffset number of bytes of item data already sent, continue there and update it 00194 * @param maxBytes maximum amount of item data to send; always send at least one byte to ensure progress 00195 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00196 * @param syncItem item to be added, NULL causes the call to return without doing anything 00197 * @param defaultType fallback if the syncItem does not define a type 00198 * @return number of bytes of item data included 00199 */ 00200 long addItem(ModificationCommand* &modificationCommand, 00201 long &syncItemOffset, long maxBytes, 00202 const char* COMMAND, SyncItem* syncItem, 00203 const char* defaultType); 00204 00205 /* 00206 * Add a Chunk into the modificationCommand. 00207 * If the modificationCommand is NULL, then this is the first item and modificationCommand 00208 * is initialized. 00209 * 00210 * @param[in, out] modificationCommand new items are added here, created if necessary 00211 * @param COMMAND REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME 00212 * @param syncItem 00213 * @param chunk chunk item to be added, NULL causes the call to return without doing anything 00214 * @param defaultType fallback if the syncItem does not define a type 00215 * @return number of bytes of item data included, that is the chunk size 00216 */ 00217 long addChunk(ModificationCommand* &modificationCommand, 00218 const char* COMMAND, SyncItem* syncItem, Chunk* chunk, 00219 const char* defaultType); 00220 /* 00221 * Reset the cmdID counter 00222 */ 00223 void resetCommandID(); 00224 00225 /* 00226 * increase the msgID counter 00227 */ 00228 void increaseMsgRef(); 00229 00230 /* 00231 * reset MsgId counter 00232 */ 00233 00234 void resetMessageID(); 00235 00236 /* 00237 * reset MsgRef counter 00238 */ 00239 void resetMsgRef(); 00240 00241 private: 00242 00243 void initialize(); 00244 00245 char* target; 00246 char* device; 00247 00254 ComplexData* getComplexData(Chunk* chunk); 00255 00256 unsigned long sessionID; 00257 unsigned int msgID ; 00258 unsigned int cmdID ; 00259 unsigned int msgRef ; 00260 00261 ComplexData* getComplexData(SyncItem* syncItem, long &syncItemOffset, long maxBytes, long &sentBytes); 00262 00263 }; 00264 00265 00266 END_NAMESPACE 00267 00269 #endif