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_PROCESSOR 00037 #define INCL_SYNCML_PROCESSOR 00038 00040 #include "base/globalsdef.h" 00041 #include "base/util/ArrayList.h" 00042 #include "base/util/XMLProcessor.h" 00043 #include "spds/SyncSource.h" 00044 #include "spds/SyncItem.h" 00045 #include "spds/SyncItemStatus.h" 00046 #include "syncml/core/TagNames.h" 00047 #include "syncml/core/ObjectDel.h" 00048 #include "syncml/parser/Parser.h" 00049 #include "spds/SyncReport.h" 00050 #include "spds/SyncItemKeys.h" 00051 00052 BEGIN_NAMESPACE 00053 00054 /* 00055 * This class is responsible for the processing of the incoming messages. 00056 */ 00057 00058 class SyncMLProcessor : public XMLProcessor { 00059 00060 private: 00061 00062 /* 00063 * It include the common part of getSyncHdrStatusCode and getAlertStatusCode 00064 */ 00065 int getStatusCode(SyncBody* syncBody, SyncSource* source, const char* commandName); 00066 /* 00067 * Returns the status code for the SyncHeader command included 00068 * in the message sent by the client. 00069 * 00070 * @param syncBody - the SyncBody content 00071 */ 00072 int getSyncHeaderStatusCode(Status* s); 00073 /* 00074 * Returns the status code for the Alert relative to the given source. 00075 * 00076 * @param syncBody - the SyncBody content 00077 * @param sourceName - the name of the source 00078 */ 00079 int getAlertStatusCode(Status* status, const char* sourceName); 00080 00081 /* 00082 * Return the command of the given commandName 00083 */ 00084 AbstractCommand* getCommand(SyncBody* syncBody, const char* commandName, int index); 00085 00086 /* 00087 * To get a generic array element. It returns the <index> arrayElement it founds. 00088 * 0-based. 00089 */ 00090 ArrayElement* getArrayElement(ArrayList* list, int index); 00091 00092 public: 00093 00094 /* 00095 * Constructor 00096 */ 00097 SyncMLProcessor(); 00098 00099 /* 00100 * Process a generic syncml message and return a SyncML object 00101 */ 00102 SyncML* processMsg(char* msg); 00103 00104 /* 00105 * Processes the initialization response. Returns 0 in case of success, an 00106 * error code in case of error. 00107 * 00108 * @param msg the response from the server 00109 */ 00110 int processInitResponse(SyncSource& source, SyncML* syncml, Alert* alert); 00111 00112 int processSyncHdrStatus(SyncML* syncml); 00113 int processAlertStatus(SyncSource& source, SyncML* syncml, ArrayList* alerts); 00114 00115 int processServerAlert(SyncSource& source, SyncML* syncml); 00116 00126 ArrayList* processGetCommand(AbstractCommand* cmd, DevInf* devInf); 00127 00137 ArrayList* processPutCommand(AbstractCommand* cmd, AbstractSyncConfig& config); 00138 00149 bool processServerDevInf(AbstractCommand* cmd, AbstractSyncConfig& config); 00150 00151 /* 00152 * Get the chal from a syncBody object. It is used to get the auth type and next nonce if needed 00153 */ 00154 Chal* getChal(SyncBody* syncBody); 00155 00156 /* 00157 * Get server credential. It is used by the SyncManager to get the server credentials and check them 00158 */ 00159 Cred* getServerCred(SyncHdr* syncHdr); 00160 00161 00162 /* 00163 * Process the SyncBody and looks for the item status of the sent items. 00164 * It calls the setItemStatus method of the sync source. 00165 */ 00166 int processItemStatus(SyncSource& source, SyncBody* syncBody, SyncItemKeys& syncItemKeys); 00167 00168 /* 00169 * Processes the response and get the Sync command of the given source 00170 * 00171 * @param source the source 00172 * @param syncml the syncML Object the response from the server 00173 */ 00174 Sync* processSyncResponse(SyncSource& source, SyncML* syncml); 00175 00176 /* 00177 * Processes the map message response. Returns 0 in case of success. 00178 * Currently it return always 0. TBD 00179 * 00180 * @param source the source 00181 * @param msg the response from the server 00182 */ 00183 int processMapResponse(SyncSource& source, SyncBody* syncBody); 00184 00185 /* 00186 * Returns the SyncHeader/RespURI element of the given message. If the element is not 00187 * found it returns NULL. The returned respURI is allocated with the new operator 00188 * and must be discarded with delete by the caller. 00189 * 00190 * @param msg - the SyncHdr message - NOT NULL 00191 */ 00192 const char* getRespURI(SyncHdr* msg); 00193 00194 /* 00195 * Returns an ArrayList containing the command given by commandName. It uses the getCommand method 00196 */ 00197 ArrayList* getCommands(SyncBody* syncBody, const char* commandName); 00198 00199 /* To retrieve a (NULL terminated) list of source names from list of Alert commands from server. 00200 * @return: a new array of source names (NULL terminated) - must be freed by the caller. 00201 */ 00202 char** getSortedSourcesFromServer(SyncML* syncml, int sourcesNumber); 00203 00204 /* To retrieve a Sync pointer from ArrayList of Sync objects. 00205 * It gets the order like the server sends 00206 */ 00207 Sync* getSyncResponse(SyncML* syncml, int index); 00208 }; 00209 00210 00211 END_NAMESPACE 00212 00214 #endif