⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctpmessage.h

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 H
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#ifndef INCL_CTP_MESSAGE
    #define INCL_CTP_MESSAGE
/** @cond DEV */
    
    #include "stdio.h"     
    #include <stdio.h>
    #include <windows.h>
    #include "syncml/core/SyncNotification.h" 
    #include "CTPParam.h"

    #include <list>
    
    using namespace std;

    /**
    * Commands
    */
    #define CM_AUTH        0x01
    #define CM_READY       0x02
    #define CM_BYE         0x03
    
    /**
    * Status
    */
    #define ST_OK          0x20
    #define ST_JUMP        0x37
    #define ST_ERROR       0x50
    #define ST_UNAUTHORIZED 0x41
    #define ST_FORBIDDEN   0x43
    #define ST_SYNC        0x29
    #define ST_RETRY       0x53
        

    #define MAX_MESSAGE_SIZE        4096
        

    class CTPMessage {

    private:
        
        /**
        * It represents the notification <san> message from the server.
        * It is no used if the CTPMessage is created from the client to 
        * communicate with the server
        */
        SyncNotification* np;

        
        /**
        * The length of the package to be sent to the server. Used together
        * to the toByte method.
        * For the parse method this value should be set at the beginning
        * with the value of the messageLength + 2.
        */
        int packageLength;
        
        /**
        * The lenght of the message inside the package. This value is retrieved
        * from the first 2 bytes of the package.
        */
        int bufferLength;
        
        /**
        * The buffer field has a different meaning based on the action it is performing.        
        * Parse action: The field contains the value of the status associated.
        * The same could be retrieved from the Params list.
        * if genericCommand is OK  : buffer is the <nonce> (if exists)
        * if genericCommand is JUMP: buffer is the <to> 
        * if genericCommand is ERROR: buffer is the <description> 
        * if genericCommand is UNAUTHORIZED: buffer is the <nonce> 
        * if genericCommand is FORBIDDEN: buffer is the NULL 
        * if genericCommand is SYNC: buffer is the NULL (SyncNotification is populated)
        * if genericCommand is RETRY: buffer is the <sleep> (not yet implemented)
        
        * Format action: to create the package to be returned after a toByte action
        */
        char* buffer;
        /**
        * the length of from property
        */
        int fromLength;
        void setFromLength(int v) { fromLength = v; }

        /**
        * Used only when the status is JUMP. It represent the <from> Param sent by the
        * server. The <to> is in the buffer property
        */
        char* from;
        

        /**
        * the version of the protocol
        * to set in exadecimal mode 0x10 for 1.0 version...
        */ 
        char protocolVersion;
        
        /**
        * the generic command could be a command or a status.
        * The commands are 
        *       AUTH, 
        *       READY, 
        *       BYE 
        * sent from client to server
        * The status are 
        *       OK,
                JUMP,
                ERROR,
                UNAUTHORIZED,
                FORBIDDEN,
                SYNC,
                RETRY (not yet implemented)

        * Command and status are in exadecimal representation
        */ 
        char genericCommand;
        
        /**
        * init the variables
        */
        void initialize();

    public:        
        

        /**
        * List containing the param(s) to be exchanged in the message.
        * It is public to permit to have access to all list methods
        * (to conside to make it private if it not necessary to access them)
        */
        list<CTPParam> params;

        /**
        * Used to create an empty class to be populated by the client.
        */
        CTPMessage();
        
        /**
        * Used to create a filled class populated with the server package.
        * @param package the package sent by the server
        * @param maxPackageLen  optional, the length of the package sent (if already known)
        */
        CTPMessage(const char* package, int maxPackageLen = 0);
        
        /**
        * Destructor
        */
        ~CTPMessage();
        
        /**
        * Used to populated all the fields with the server properties.
        * @param package the package sent by the server to be parsed
        * @param maxPackageLen  optional, the length of the package sent (if already known)
        * @return 0 if the parse action works properly, -1 there is an error.
        */
        int parse(const char* package, int maxPackageLen = 0);
        
        /**
        * Used to create the byte array of the package using all the not-NULL fields .
        * @return the pointer to the internally allocated package
        * NOTE: the length of the byte array is in the packageLength field
        */
        char* toByte();
        
        /**
        * set the package length of the just created byte array to be sent
        * to the server
        */
        void setPackageLength(int v) { packageLength = v; }
        
        /**
        * return the package length of the just created byte array 
        */
        int getPackageLength() { return packageLength; }
        
        /**
        * set the message length
        */
        void setBufferLength(int v) { bufferLength = v; }
        
        /**
        * get the message length
        */
        int getBufferLength()      { return bufferLength; }

        /**
        * get the allocated buffer internally. It needs to get the action
        * due to the parting method
        */
        char* getBuffer() { return buffer; }
       
        /**
        * Used to set the command from client to server
        */
        void setGenericCommand(char c) { genericCommand = c; }

        /**
        * Used to get the status from server to client
        */
        char getGenericCommand() { return genericCommand; }
        
        /**
        * Used to set the protocol version 
        */
        void setProtocolVersion(char c) { protocolVersion = c; }

        /**
        * Used to get the protocol version
        */
        char getProtocolVersion() { return protocolVersion; }
        
        /**
        * Return the internal SyncNotification
        */
        SyncNotification* getSyncNotification() { return np; }
        
        /**
        * get the from field length
        */
        int getFromLength()      { return fromLength; }

        /**
        * get the allocated buffer internally. It needs to get the action
        * due to the parting method
        */
        char* getFrom() { return from; }
            
        /**
        * add CTPParam to the internal public params list member. This method is
        * only to avoid to add directly 
        */
        void addParam(CTPParam* p);
    };

    
/** @endcond */
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -