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