src/include/common/spds/SyncMLProcessor.h

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         /*
00116         * Get the chal from a syncBody object. It is used to get the auth type and next nonce if needed
00117         */
00118         Chal* getChal(SyncBody* syncBody);
00119 
00120         /*
00121         * Get server credential. It is used by the SyncManager to get the server credentials and check them
00122         */
00123         Cred* getServerCred(SyncHdr* syncHdr);
00124 
00125 
00126         /*
00127          * Process the SyncBody and looks for the item status of the sent items.
00128          * It calls the setItemStatus method of the sync source.
00129          */
00130         int processItemStatus(SyncSource& source, SyncBody* syncBody);
00131 
00132         /*
00133          * Processes the response and get the Sync command of the given source
00134          *
00135          * @param source the source
00136          * @param syncml the syncML Object the response from the server
00137          */
00138         Sync* processSyncResponse(SyncSource& source, SyncML* syncml);
00139 
00140         /*
00141          * Processes the map message response. Returns 0 in case of success.
00142          * Currently it return always 0. TBD
00143          *
00144          * @param source the source
00145          * @param msg the response from the server
00146          */
00147         int processMapResponse(SyncSource& source, SyncBody* syncBody);
00148 
00149         /*
00150          * Returns the SyncHeader/RespURI element of the given message. If the element is not
00151          * found it returns NULL. The returned respURI is allocated with the new operator
00152          * and must be discarded with delete by the caller.
00153          *
00154          * @param msg - the SyncHdr message - NOT NULL
00155          */
00156         const char* getRespURI(SyncHdr* msg);
00157 
00158         /*
00159          * Returns an ArrayList containing the command given by commandName. It uses the getCommand method
00160          */
00161         ArrayList* getCommands(SyncBody* syncBody, const char* commandName);
00162 
00163         /* To retrieve a (NULL terminated) list of source names from list of Alert commands from server.
00164          * @return: a new array of source names (NULL terminated) - must be freed by the caller.
00165          */
00166         char** getSortedSourcesFromServer(SyncML* syncml, int sourcesNumber);
00167 
00168         /* To retrieve a Sync pointer from ArrayList of Sync objects.
00169          * It gets the order like the server sends
00170          */
00171         Sync* getSyncResponse(SyncML* syncml, int index);
00172     };
00173 
00174 
00175 END_NAMESPACE
00176 
00178 #endif

Generated on Tue Jun 10 17:20:21 2008 for Funambol C++ Client Library by  doxygen 1.5.2