/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
#ifndef XPT_HTTP_TRANS_H
#define XPT_HTTP_TRANS_H


/*********************/
/* Required includes */
/*********************/

#include <xptTransport.h>
#include "xpttypes.h"
#include "xpt-http.h"
#include "openssl/ssl.h"


#ifdef __cplusplus
extern "C" {
#endif


typedef struct _http_transport_info {
    BufferSize_t                  cbSize;        // size of this structure
} HttpTransportInfo_t,  *HttpTransportInfoPtr_t;

struct _http_transport_service_client_info {
    TcpFirewallInfo_t       firewallInfo;
    StringBuffer_t          proxyString;
    StringBuffer_t          pchServerAddress;
};

struct _http_transport_service_server_info {
    StringBuffer_t                pchSenderAddress;
    char *                        pchServerPort;
    Socket_t                      serverSocket;
};

typedef struct _http_transport_service_info {
    BufferSize_t                         cbSize;    // size of this structure
    Bool_t                               socketClient;
    /*
     * Change to support HTTPS. 
     */
    Bool_t                               sslSocket;
    union {
        struct _http_transport_service_client_info clientInfo;
        struct _http_transport_service_server_info serverInfo;
    } info;

} HttpTransportServiceInfo_t,  *HttpTransportServiceInfoPtr_t;

struct _http_transport_conn_client_info {
    char tmp;
};

struct _http_transport_conn_server_info {
    char tmp;
};

typedef enum  { HTTP_TRANSPORT_OPEN, HTTP_TRANSPORT_SENDING, HTTP_TRANSPORT_RECEIVING, HTTP_TRANSPORT_CLOSED } HttpTransportConnState_t ;

typedef struct _http_transport_conn_info {
    BufferSize_t                  cbSize;        // size of this structure
    Bool_t                        smlClient;
    Socket_t                      socket;
    HttpTransportServiceInfoPtr_t pServiceInfo;
    HttpHandle_t                  http;
    HttpDocumentContext_t         docContext;
    /*
     * Change to support HTTPS. 
     */
    SSL_CTX*                      pCtx;
    SSL*                          pSSL;

    union {
        struct _http_transport_conn_client_info clientInfo;
        struct _http_transport_conn_server_info serverInfo;
    } info;
} HttpTransportConnInfo_t,  *HttpTransportConnInfoPtr_t;



Ret_t XPTAPI  HTTP_selectProtocol(void *privateTransportInfo,
                                     const char *metaInformation,
                                     unsigned int flags,
                                     void **pPrivateServiceInfo);

Ret_t XPTAPI HTTP_deselectProtocol(void *privateServiceInfo);


Ret_t XPTAPI HTTP_openCommunication(void *privateServiceInfo,
                                    int role,
                                    void **pPrivateConnectionInfo);

Ret_t XPTAPI  HTTP_closeCommunication(void *privateConnectionInfo);

Ret_t XPTAPI  HTTP_beginExchange(void *privateConnectionInfo);

Ret_t XPTAPI  HTTP_endExchange(void *privateConnectionInfo);

Ret_t XPTAPI  HTTP_receiveData(void *privateConnectionInfo,
                               void *buffer, size_t bufferLen,
                               size_t *dataLen);

Ret_t XPTAPI  HTTP_sendData(void *privateConnectionInfo,
                            const void *buffer, size_t bufferLen,
                            size_t *bytesSent);

Ret_t XPTAPI  HTTP_sendComplete(void *privateConnectionInfo);

Ret_t XPTAPI  HTTP_setDocumentInfo(void *privateConnectionInfo,
                                   const XptCommunicationInfo_t *pDoc);


Ret_t XPTAPI  HTTP_getDocumentInfo(void *privateConnectionInfo,
                                   XptCommunicationInfo_t *pDoc);


#ifdef __cplusplus
}
#endif

#endif

