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