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/util/ArrayList.h" 00041 #include "base/util/XMLProcessor.h" 00042 #include "spds/SyncSource.h" 00043 #include "spds/SyncItem.h" 00044 #include "spds/SyncItemStatus.h" 00045 #include "syncml/core/TagNames.h" 00046 #include "syncml/core/ObjectDel.h" 00047 #include "syncml/parser/Parser.h" 00048 #include "spds/SyncReport.h" 00049 00050 /* 00051 * This class is responsible for the processing of the incoming messages. 00052 */ 00053 00054 class __declspec(dllexport) SyncMLProcessor : public XMLProcessor { 00055 00056 private: 00057 00058 /* 00059 * It include the common part of getSyncHdrStatusCode and getAlertStatusCode 00060 */ 00061 int getStatusCode(SyncBody* syncBody, SyncSource* source, const char* commandName); 00062 /* 00063 * Returns the status code for the SyncHeader command included 00064 * in the message sent by the client. 00065 * 00066 * @param syncBody - the SyncBody content 00067 */ 00068 int getSyncHeaderStatusCode(Status* s); 00069 /* 00070 * Returns the status code for the Alert relative to the given source. 00071 * 00072 * @param syncBody - the SyncBody content 00073 * @param sourceName - the name of the source 00074 */ 00075 int getAlertStatusCode(Status* status, const char* sourceName); 00076 00077 /* 00078 * Return the command of the given commandName 00079 */ 00080 AbstractCommand* getCommand(SyncBody* syncBody, const char* commandName, int index); 00081 00082 /* 00083 * To get a generic array element. It returns the <index> arrayElement it founds. 00084 * 0-based. 00085 */ 00086 ArrayElement* getArrayElement(ArrayList* list, int index); 00087 00088 public: 00089 00090 /* 00091 * Constructor 00092 */ 00093 SyncMLProcessor(); 00094 00095 /* 00096 * Process a generic syncml message and return a SyncML object 00097 */ 00098 SyncML* processMsg(char* msg); 00099 00100 /* 00101 * Processes the initialization response. Returns 0 in case of success, an 00102 * error code in case of error. 00103 * 00104 * @param msg the response from the server 00105 */ 00106 int processInitResponse(SyncSource& source, SyncML* syncml, Alert* alert); 00107 00108 int processSyncHdrStatus(SyncML* syncml); 00109 int processAlertStatus(SyncSource& source, SyncML* syncml, ArrayList* alerts); 00110 00111 int processServerAlert(SyncSource& source, SyncML* syncml); 00112 /* 00113 * Get the chal from a syncBody object. It is used to get the auth type and next nonce if needed 00114 */ 00115 Chal* getChal(SyncBody* syncBody); 00116 00117 /* 00118 * Get server credential. It is used by the SyncManager to get the server credentials and check them 00119 */ 00120 Cred* getServerCred(SyncHdr* syncHdr); 00121 00122 00123 /* 00124 * Process the SyncBody and looks for the item status of the sent items. 00125 * It calls the setItemStatus method of the sync source. 00126 */ 00127 int processItemStatus(SyncSource& source, SyncBody* syncBody); 00128 00129 /* 00130 * Processes the response and get the Sync command of the given source 00131 * 00132 * @param source the source 00133 * @param syncml the syncML Object the response from the server 00134 */ 00135 Sync* processSyncResponse(SyncSource& source, SyncML* syncml); 00136 00137 /* 00138 * Processes the map message response. Returns 0 in case of success. 00139 * Currently it return always 0. TBD 00140 * 00141 * @param source the source 00142 * @param msg the response from the server 00143 */ 00144 int processMapResponse(SyncSource& source, SyncBody* syncBody); 00145 00146 /* 00147 * Returns the SyncHeader/RespURI element of the given message. If the element is not 00148 * found it returns NULL. The returned respURI is allocated with the new operator 00149 * and must be discarded with delete by the caller. 00150 * 00151 * @param msg - the SyncHdr message - NOT NULL 00152 */ 00153 const char* getRespURI(SyncHdr* msg); 00154 00155 /* 00156 * Returns an ArrayList containing the command given by commandName. It uses the getCommand method 00157 */ 00158 ArrayList* getCommands(SyncBody* syncBody, const char* commandName); 00159 00160 /* To retrieve a (NULL terminated) list of source names from list of Alert commands from server. 00161 * @return: a new array of source names (NULL terminated) - must be freed by the caller. 00162 */ 00163 char** getSortedSourcesFromServer(SyncML* syncml, int sourcesNumber); 00164 00165 /* To retrieve a Sync pointer from ArrayList of Sync objects. 00166 * It gets the order like the server sends 00167 */ 00168 Sync* getSyncResponse(SyncML* syncml, int index); 00169 }; 00170 00172 #endif