zeroconf/zeroconfsharing/bjrhttpserver.h
author guru.kini@nokia.com
Wed, 21 Jul 2010 14:28:48 +0530
changeset 21 ff5174af067c
permissions -rw-r--r--
ZeroConf Sharing Application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     1
/*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     3
* All rights reserved.
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     4
* This component and the accompanying materials are made available
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     6
* which accompanies this distribution, and is available
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     8
*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
     9
* Initial Contributors:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    11
*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    12
* Contributors:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    13
*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    14
* Description: 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    15
*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    16
*/
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    17
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    18
#include <e32test.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    19
#include <f32file.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    20
#include <httpclientserver/mhttpauthenticationcallback.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    21
#include <httpclientserver/mhttptransactioncallback.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    22
#include <httpclientserver/mhttpdatasupplier.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    23
#include <httpclientserver/framework/logging.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    24
#include <httpclientserver/mhttpsessioneventcallback.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    25
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    26
class CHttpExampleUtils;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    27
class CHttpServerTransactionBase;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    28
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    29
class MTransactionNotify
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    30
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    31
    public:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    32
    virtual void OnTransactionCompleted ( CHttpServerTransactionBase* iTrans ) =0;      
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    33
    };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    34
class CHttpServer : public CBase,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    35
                    public MHTTPTransactionCreationCallback,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    36
                    public MTransactionNotify,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    37
                    public MHTTPSessionEventCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    38
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    39
public:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    40
    virtual ~CHttpServer();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    41
    static CHttpServer* NewLC();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    42
    static CHttpServer* NewL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    43
    //void StartClientL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    44
    void SetupClientL ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    45
    //virtual void StartHttpServer();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    46
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    47
    void ProcessSelectionL ( TInt aSelection );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    48
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    49
    TInt GetLocalHost ( TSockAddr& aAddr );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    50
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    51
    TDesC8& GetIPAddress();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    52
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    53
    void StartConnectionL(TInt aIapId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    54
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    55
protected:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    56
    CHttpServer();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    57
    void ConstructL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    58
private:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    59
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    60
    enum TMenuItems
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    61
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    62
        EStart = 1,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    63
        EStop,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    64
        EExit,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    65
        };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    66
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    67
    void ResetTimeElapsed();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    68
    void DisplayTimeElapsed();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    69
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    70
    void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    71
    void SetDefaults(TDes& aURL, TDes& aProxy, TDes& aHook, TDes& aSessionId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    72
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    73
    // From MHTTPTransactionCreationCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    74
    RHTTPTransaction NewTransactionL ( const TUriC8& aUri, RStringF aMethod );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    75
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    76
    void OnTransactionCompleted ( CHttpServerTransactionBase* iTrans );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    77
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    78
    // From MHTTPSessionEventCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    79
    virtual void MHFSessionRunL ( const THTTPSessionEvent& aEvent );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    80
    virtual TInt MHFSessionRunError ( TInt aError, const THTTPSessionEvent& aEvent );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    81
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    82
    void CleanupTransactions ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    83
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    84
private:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    85
    TTime iLastTimeStamp;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    86
    TInt iDataChunkCount;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    87
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    88
    RHTTPClientServerSession     iSess;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    89
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    90
    RFs iFileServ;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    91
    TBool iManualPost;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    92
    //CHttpExampleUtils* iUtils;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    93
    RArray <CHttpServerTransactionBase*> iTransactions;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    94
    RFile iLogFile;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    95
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    96
    RBuf8 iIPAddr;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    97
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    98
    // Connection
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    99
    RConnection iConnection;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   100
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   101
    // SocketServer
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   102
    RSocketServ iSocketServ;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   103
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   104
    __FLOG_DECLARATION_MEMBER;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   105
    };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   106
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   107
class CHttpServerTransactionBase : public CBase, public MHTTPTransactionCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   108
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   109
public:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   110
    virtual ~CHttpServerTransactionBase ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   111
    RHTTPTransaction Transaction ()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   112
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   113
        return iTransaction;    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   114
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   115
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   116
protected:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   117
    CHttpServerTransactionBase ( MTransactionNotify& aNotify, /*CHttpExampleUtils& aUtils,*/ RFs& aFileServ );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   118
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   119
    void SetHeaderL(RStringPool& aStringPool, RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   120
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   121
    void ConstructL ( RHTTPClientServerSession& aSession, const TUriC8& aUri, RStringF aMethod );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   122
    protected:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   123
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   124
    // methods from MHTTPTransactionCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   125
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   126
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   127
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   128
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   129
protected:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   130
    MTransactionNotify& iNotify;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   131
    RFs&                iFileServ;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   132
    //CHttpExampleUtils&  iUtils; // not owned                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   133
    RFile               iFile;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   134
    RHTTPTransaction    iTransaction;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   135
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   136
    __FLOG_DECLARATION_MEMBER;  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   137
    };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   138
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   139
class CHttpDataTransmitter : public CHttpServerTransactionBase, public MHTTPDataSupplier
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   140
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   141
public: 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   142
    static CHttpDataTransmitter* NewL ( MTransactionNotify& aNotify, /*CHttpExampleUtils& aUtils,*/ RFs& aFileServ, RHTTPClientServerSession& aSession, const TUriC8& aUri, RStringF aMethod );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   143
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   144
    TInt OpenFile( const TDesC8& aHttpPath );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   145
private:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   146
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   147
    // methods from MHTTPTransactionCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   148
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   149
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   150
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   151
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   152
    // From MHTTPDataSupplier
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   153
    virtual TBool GetNextDataPart(TPtrC8& aDataPart);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   154
    virtual void ReleaseData();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   155
    virtual TInt OverallDataSize();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   156
    virtual TInt Reset();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   157
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   158
private:    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   159
    CHttpDataTransmitter (MTransactionNotify& aNotify,/*CHttpExampleUtils& aUtils,*/ RFs& aFileServ);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   160
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   161
private:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   162
    TBuf8 <4096>    iData;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   163
    TInt            iDataToSend;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   164
    TBuf8<32>       iContentType;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   165
    TBool           iTransSubmitted;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   166
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   167
    __FLOG_DECLARATION_MEMBER;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   168
    };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   169