zeroconf/zeroconfsharing/bjrhttpserver.cpp
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) 2001-2008 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
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    19
#include <uri8.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    20
#include <e32base.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    21
//#include <http.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    22
#include <httpclientserver.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    23
#include <chttpformencoder.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    24
#include <ssl.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    25
#include <signed.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    26
#include <commdbconnpref.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    27
#include "bjrhttpserver.h"
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    28
#include <escapeutils.h>
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    29
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    30
const TChar KHttpSlash          = '/';
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    31
const TChar KFileSlash          = '\\';
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    32
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    33
// format for output of data/time values
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    34
//_LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    35
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    36
// Format for hook file name and location for hooks
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    37
//_LIT(KHookFormat, "Z:\\httptest\\%S.esk");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    38
//_LIT(KHookDir, "C:\\System\\Data\\");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    39
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    40
//_LIT(KEnterProx, "Enter Proxy authority");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    41
//_LIT(KEnterHook, "Enter Hook name (preface with '-' to delete)");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    42
//_LIT(KEnterSessId, "Enter Session ID (positive integer or 'none')");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    43
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    44
_LIT8 (KAbsDocumentRoot, "/Images/");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    45
_LIT8 (KRelDocumentRoot, "/Images");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    46
_LIT8 (KRoot, "c:\\data\\");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    47
_LIT8 (KHomePage, "Images/index.html");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    48
_LIT8 (KFound, "Found");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    49
_LIT8 (KOk, "OK");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    50
_LIT8 (KNotFound, "Not Found");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    51
_LIT8(KTextContent, "text/");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    52
_LIT8(KImageContent, "image/");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    53
_LIT(KHtml, "html");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    54
_LIT8(KGif, "gif");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    55
/*  If the file httpexampleclient.txt exists in the root directory of a drive
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    56
    it will be used to provide default initial values for when setting the URL, 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    57
    proxy, etc. The file format is:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    58
        [var] = [value]
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    59
    for example:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    60
        PROXY = my.proxy.co.uk:5473
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    61
        URL = http://www.example.org/dir/file.html
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    62
    whitespace is ignored.
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    63
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    64
    Note: these are the the values set at run time, they are merely the default
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    65
    options presented to the user. In the above example the proxy is not turned
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    66
    on by default, but the string "my.proxy.co.uk:5473" is presetned as the default
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    67
    option when the use hits "p", saving them the need to have to type it in. 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    68
    */
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    69
// Defaults
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    70
_LIT(KDefaultFileFormat,"%c:\\httpexampleserver.txt");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    71
_LIT(KHookString, "HOOK");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    72
_LIT(KProxyString, "PROXY");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    73
_LIT(KURLString, "URL");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    74
_LIT(KSessionIdString, "SESSIONID");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    75
//_LIT(KNone, "none");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    76
//_LIT(KSchemeHttps, "https");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    77
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    78
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    79
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    80
// File system root
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    81
//_LIT(KFileSystemRoot,"C:\\");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    82
//added on July13,09
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    83
_LIT(KFileName,"c:\\logs\\logs.txt");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    84
_LIT(KFileName2,"c:\\logs\\logs2.txt");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    85
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    86
_LIT(KServerLog,"c:\\httpserverlog.txt");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    87
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    88
const TInt endpos = 0;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    89
enum THttpExampleClientPanics
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    90
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    91
    EReqBodySumitBufferNotAllocated,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    92
    KBodyWithInvalidSize,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    93
    KCouldntNotifyBodyDataPart
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    94
    };
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    95
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    96
// Size of buffer used when submitting request bodies
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    97
//const TInt KMaxSubmitSize = 1024;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    98
//const TInt KMaxHeaderNameLen = 32;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
    99
//const TInt KMaxHeaderValueLen = 128;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   100
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   101
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   102
//
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   103
// Implementation of CHttpServer
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   104
//
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
// Supplied as the name of the test program to CHttpExampleUtils
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   108
_LIT(KHttpExampleClientTestName, "HttpExampleServer");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   109
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   110
CHttpServer::CHttpServer () 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   111
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   112
    __FLOG_OPEN ( "http", "httpexampleserver.txt" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   113
    __FLOG_0 ( _T8 ( "CHttpServer::CHttpServer "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   114
    // Initial timestamp is time now
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   115
    ResetTimeElapsed(); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   116
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   117
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   118
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   119
CHttpServer::~CHttpServer()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   120
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   121
    __FLOG_0 ( _T8 ( "CHttpServer::~CHttpServer"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   122
    CleanupTransactions ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   123
    //iLogFile.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   124
    iSess.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   125
    //delete iUtils;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   126
    iFileServ.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   127
    iConnection.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   128
    iSocketServ.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   129
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   130
    iIPAddr.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   131
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   132
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   133
CHttpServer* CHttpServer::NewLC()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   134
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   135
    CHttpServer* me = new(ELeave) CHttpServer;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   136
    CleanupStack::PushL(me);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   137
    me->ConstructL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   138
    return me;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   139
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   140
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   141
CHttpServer* CHttpServer::NewL()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   142
    {   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   143
    CHttpServer* me = NewLC();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   144
    CleanupStack::Pop(me);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   145
    return me;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   146
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   147
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   148
void CHttpServer::ConstructL()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   149
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   150
    __FLOG_0 ( _T8 ( "CHttpServer::ConstructL"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   151
    //iUtils = CHttpExampleUtils::NewL(KHttpExampleClientTestName, *this );   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   152
    User::LeaveIfError(iFileServ.Connect());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   153
    iLogFile.Replace(iFileServ,KServerLog,EFileWrite);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   154
    _LIT8(Kmsg,"\nChttpServer::ConstructL");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   155
    iLogFile.Write(Kmsg);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   156
    User::LeaveIfError( iSocketServ.Connect() );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   157
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   158
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   159
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   160
RHTTPTransaction CHttpServer::NewTransactionL ( const TUriC8& aUri, RStringF aMethod )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   161
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   162
    __FLOG_0 ( _T8 ( "CHttpServer::NewTransactionL "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   163
    CHttpServerTransactionBase* trans = CHttpDataTransmitter::NewL (*this, /*iUtils,*/ iFileServ, iSess, aUri, aMethod);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   164
    iTransactions.Append(trans);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   165
    return trans->Transaction ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   166
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   167
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   168
// to avoid code bloat
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   169
#define CHECKVAL(name)  if(var==K ##name##String)   {a##name.Copy(val);}
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   170
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   171
void CHttpServer::SetDefaults(TDes& aURL, TDes& aProxy, TDes& aHook, TDes& aSessionId)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   172
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   173
    __FLOG_4 ( _T8 ( "CHttpServer::SetDefaults [aURL=%S,aProxy=%S,aHook=%S,aSessionId=%S]"), &aURL, &aProxy, &aHook, &aSessionId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   174
    TFileName filename;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   175
    RFile file;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   176
    filename.Format(KDefaultFileFormat, 'C');
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   177
    TInt err = file.Open(iFileServ, filename, EFileRead);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   178
    if(err != KErrNone) 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   179
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   180
        filename.Format(KDefaultFileFormat, 'Z');
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   181
        err = file.Open(iFileServ, filename, EFileRead);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   182
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   183
    if(err == KErrNone) 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   184
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   185
        TFileText line;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   186
        line.Set(file);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   187
        TInt err = line.Read(filename);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   188
        while(err == KErrNone || err ==KErrTooBig) 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   189
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   190
            filename.Trim();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   191
            TInt div = filename.Locate('=');
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   192
            if(div>0) 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   193
                {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   194
                TInt i;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   195
                for (i=div-1;i>0 && filename[i]==' ';i--);  // ibid
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   196
                TPtrC var = filename.Left(i+1);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   197
                for (i=div+1;i<filename.Length() && filename[i]==' ';i++);  //ibid
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   198
                TPtrC val = filename.Right(filename.Length()-i);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   199
                CHECKVAL(Hook)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   200
                else CHECKVAL(Proxy)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   201
                else CHECKVAL(URL)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   202
                else CHECKVAL(SessionId);   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   203
                __FLOG_3 ( _T8 ( "CHttpServer::SetDefaults [URL=%S,Proxy=%S,SessionId=%S]"), &aURL, &aProxy, &aSessionId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   204
                }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   205
            err = line.Read(filename);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   206
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   207
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   208
        file.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   209
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   210
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   211
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   212
void CHttpServer::SetupClientL ()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   213
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   214
    __FLOG_0 ( _T8 ( "CHttpServer::SetupClientL "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   215
    ResetTimeElapsed();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   216
    TBuf<256> url;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   217
    TBuf<256> prox;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   218
    TBuf<256> hook;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   219
    TBuf<16> sessid;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   220
    SetDefaults(url, prox, hook, sessid);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   221
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   222
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   223
    //iUtils->Test().Console()->ClearScreen();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   224
    _LIT(KSelectOption, "\n\n Select an option \n\n");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   225
    //iUtils->Test().Printf(KSelectOption);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   226
    _LIT(KPossibleSelectionsText, " 1 Start \n 2 Stop \n 3 Exit\n");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   227
    _LIT(KPossibleSelections,"123");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   228
    //iUtils->RequestSelection ( KPossibleSelectionsText, KPossibleSelections );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   229
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   230
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   231
void CHttpServer::StartConnectionL(TInt aIapId)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   232
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   233
    // Connection preferences
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   234
    TCommDbConnPref commDbConnPref;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   235
    TUint32 iap(aIapId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   236
    _LIT8(Kmsg,"\nCHttpServer::StartConnectionL");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   237
    iLogFile.Write(Kmsg);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   238
    commDbConnPref.SetIapId( iap );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   239
    commDbConnPref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   240
    commDbConnPref.SetBearerSet( ECommDbBearerWLAN );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   241
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   242
    User::LeaveIfError( iConnection.Open( iSocketServ ) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   243
    User::LeaveIfError( iConnection.Start( commDbConnPref ) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   244
    _LIT8(Kmsg2,"\nConnection started");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   245
    iLogFile.Write(Kmsg2);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   246
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   247
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   248
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   249
TInt CHttpServer::GetLocalHost ( TSockAddr& aAddr )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   250
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   251
    RSocket socket;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   252
    TInt err = socket.Open ( iSocketServ, KAfInet, KSockStream, KProtocolInetTcp );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   253
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   254
    if ( err == KErrNone )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   255
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   256
        TInetAddr localHost;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   257
        localHost.SetAddress ( KInetAddrAny );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   258
        TPckgBuf<TSoInetIfQuery> query;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   259
        query ().iDstAddr = localHost;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   260
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   261
        err = socket.GetOpt ( KSoInetIfQueryByDstAddr, KSolInetIfQuery, query );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   262
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   263
        if ( err == KErrNone )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   264
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   265
            // its local IP address
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   266
            localHost = query ().iSrcAddr;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   267
            aAddr = localHost;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   268
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   269
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   270
    socket.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   271
    return err;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   272
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   273
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   274
TDesC8& CHttpServer::GetIPAddress()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   275
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   276
    return iIPAddr;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   277
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   278
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   279
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   280
void CHttpServer::ProcessSelectionL ( TInt aSelection )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   281
    {   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   282
    __FLOG_1 ( _T8 ( "CHttpServer::ProcessSelection  [aSelection =%d]"), aSelection );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   283
    //_LIT8(Kmsg,"\n CHttpServer::ProcessSelection");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   284
    //iLogFile.Write(Kmsg);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   285
    switch ( aSelection )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   286
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   287
        case EStart: 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   288
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   289
            _LIT8 ( KHTTPServer, "HTTd/TCP" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   290
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   291
            //_LIT8(Kmsg2,"Opening server RHTTPClientServerSession - ");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   292
            //iLogFile.Write(Kmsg2);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   293
            //iLogFile.Write(KHTTPServer);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   294
            // Open the RHTTPClientServerSession
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   295
            _LIT8(Kmsg2,"\nTrying to connect...");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   296
            iLogFile.Write(Kmsg2);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   297
            //StartConnectionL(aIapId);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   298
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   299
            iSess.OpenL ( KHTTPServer () );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   300
            _LIT8(Kmsg3,"\nRHTTPClientServerSession opened");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   301
            iLogFile.Write(Kmsg3);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   302
            /*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   303
            RHTTPConnectionInfo connInfo = iSess.ConnectionInfo();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   304
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   305
            //Attach to socket server
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   306
            connInfo.SetPropertyL( iSess.StringPool().StringF(HTTP::EHttpSocketServ,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   307
                                     RHTTPClientServerSession::GetTable() ),
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   308
                                     THTTPHdrVal(iSocketServ.Handle() ) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   309
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   310
            //Attach to connection
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   311
            TInt connPtr = reinterpret_cast<TInt>( &iConnection );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   312
            connInfo.SetPropertyL( iSess.StringPool().StringF(
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   313
                                     HTTP::EHttpSocketConnection,
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   314
                                     RHTTPClientServerSession::GetTable() ),
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   315
                                     THTTPHdrVal(connPtr) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   316
            */
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   317
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   318
            iSess.RegisterDocumentRootL ( KAbsDocumentRoot, *this );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   319
            _LIT8(Kmsg4,"\nDocumentRoot registered");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   320
            iLogFile.Write(Kmsg4);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   321
            iSess.SetSessionEventCallback ( this );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   322
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   323
            //iUtils->Test ().Console ()->ClearScreen ();         
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   324
            _LIT ( KServerStartedMsg, "Http Server Started at Root..." );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   325
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   326
            //_LIT8(Kmsg3,"server started");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   327
            //iLogFile.Write(Kmsg3);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   328
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   329
            //iUtils->Test ().Printf ( KServerStartedMsg );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   330
            __FLOG_0 ( _T8 ( "Http Server Started at Root... "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   331
                        
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   332
            RStringPool stringPool = iSess.StringPool ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   333
            THTTPHdrVal ipValue;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   334
            iSess.PropertySet ().Property ( stringPool.StringF ( HTTP::ELocalHost, RHTTPClientServerSession::GetTable () ), ipValue );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   335
            //RBuf ipBuf;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   336
            //ipBuf.Create ( ipValue.StrF ().DesC ().Length () );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   337
            //ipBuf.Copy ( ipValue.StrF ().DesC () );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   338
            //iUtils->Test ().Printf ( _L ( "http://" ) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   339
            //iUtils->Test ().Printf ( ipBuf );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   340
            //iUtils->Test ().Printf ( _L ( "/pws/" ) );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   341
            //ipBuf.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   342
            TInt length = ipValue.StrF ().DesC ().Length ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   343
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   344
            iIPAddr.Create(length);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   345
            iIPAddr.Copy(ipValue.StrF ().DesC ());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   346
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   347
            _LIT8(Kmsg5,"\nIP addr obtained");
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   348
            iLogFile.Write(Kmsg5);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   349
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   350
          
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   351
            _LIT ( KSelectOption, "\n\n Select an option \n\n" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   352
            //iUtils->Test ().Printf ( KSelectOption );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   353
            _LIT ( KPossibleSelectionsText, " 2 Stop \n 3 Exit\n" );            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   354
            _LIT ( KPossibleSelections,"23" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   355
            //iUtils->RequestSelection ( KPossibleSelectionsText, KPossibleSelections );  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   356
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   357
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   358
        case EStop:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   359
            {           
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   360
            //iUtils->Test ().Console ()->ClearScreen ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   361
            _LIT ( KServerStoppedMsg, "Server Stopped..." );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   362
            //iUtils->Test ().Printf ( KServerStoppedMsg );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   363
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   364
            CleanupTransactions ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   365
            iSess.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   366
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   367
            //SetupClientL ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   368
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   369
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   370
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   371
        case EExit:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   372
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   373
            //CActiveScheduler::Stop ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   374
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   375
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   376
        default: 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   377
             break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   378
        } 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   379
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   380
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   381
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   382
void CHttpServer::CleanupTransactions ()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   383
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   384
    __FLOG_0 ( _T8 ( "CHttpServer::CleanupTransactions "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   385
    TInt i = iTransactions.Count () - 1;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   386
    while ( iTransactions.Count () )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   387
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   388
        iTransactions[i]->Transaction ().Cancel ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   389
        CHttpServerTransactionBase* trans = iTransactions[i];
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   390
        iTransactions.Remove ( i );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   391
        delete trans;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   392
        --i;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   393
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   394
    iTransactions.Close (); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   395
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   396
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   397
void CHttpServer::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   398
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   399
    __FLOG_1 ( _T8 ( "CHttpServer::SetHeaderL [aHdrField=%d]"), aHdrField);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   400
    RStringF valStr = iSess.StringPool().OpenFStringL(aHdrValue);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   401
    CleanupClosePushL(valStr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   402
    THTTPHdrVal val(valStr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   403
    aHeaders.SetFieldL(iSess.StringPool().StringF(aHdrField,RHTTPClientServerSession::GetTable()), val);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   404
    CleanupStack::PopAndDestroy(&valStr); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   405
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   406
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   407
void CHttpServer::ResetTimeElapsed()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   408
// Resets timestamp to time now
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   409
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   410
    __FLOG_0 ( _T8 ( "CHttpServer::ResetTimeElapsed"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   411
    iLastTimeStamp.UniversalTime(); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   412
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   413
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   414
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   415
void CHttpServer::DisplayTimeElapsed()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   416
// Calculate elapsed time since last measurement, and display
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   417
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   418
    __FLOG_0 ( _T8 ( "CHttpServer::DisplayTimeElapsed"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   419
    TTime timeNow;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   420
    timeNow.UniversalTime();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   421
    TTimeIntervalMicroSeconds elapsedMicroSec =
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   422
                                    timeNow.MicroSecondsFrom(iLastTimeStamp);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   423
    iLastTimeStamp = timeNow;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   424
    /*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   425
    iUtils->Test().Printf(
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   426
        _L("Time elapsed since last measurement is: %d ms\n"),
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   427
        elapsedMicroSec.Int64()/1000
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   428
        );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   429
    */
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   430
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   431
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   432
void CHttpServer::OnTransactionCompleted ( CHttpServerTransactionBase* iTrans )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   433
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   434
    __FLOG_1 ( _T8 ( "CHttpServer::OnTransactionCompleted  [iTrans =0x%X]"), iTrans );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   435
    for ( TInt i = 0; i < iTransactions.Count (); ++i)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   436
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   437
        if (iTransactions[i] == iTrans)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   438
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   439
            delete iTrans;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   440
            iTransactions.Remove (i);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   441
            break;              
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   442
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   443
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   444
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   445
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   446
void CHttpServer::MHFSessionRunL ( const THTTPSessionEvent& aEvent )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   447
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   448
    if ( aEvent.iStatus < 0 )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   449
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   450
        iSess.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   451
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   452
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   453
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   454
TInt CHttpServer::MHFSessionRunError ( TInt /*aError*/, const THTTPSessionEvent& /*aEvent*/ )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   455
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   456
    return KErrNone;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   457
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   458
/*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   459
void CHttpServer::StartHttpServer()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   460
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   461
    SetupClientL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   462
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   463
*/
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   464
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   465
// ------------------------------------------------------
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   466
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   467
CHttpServerTransactionBase::~CHttpServerTransactionBase ()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   468
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   469
    __FLOG_0 ( _T8 ( "CHttpServerTransactionBase::~CHttpServerTransactionBase   "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   470
    iFile.Close ();     
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   471
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   472
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   473
CHttpServerTransactionBase::CHttpServerTransactionBase ( MTransactionNotify& aNotify,/*CHttpExampleUtils& aUtils,*/ RFs& aFileServ )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   474
: iNotify (aNotify), 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   475
iFileServ ( aFileServ )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   476
//iUtils ( aUtils )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   477
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   478
    __FLOG_OPEN ( "http", "httpexampleserver.txt" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   479
    __FLOG_0 ( _T8 ( "CHttpServerTransactionBase::CHttpServerTransactionBase "));       
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   480
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   481
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   482
void CHttpServerTransactionBase::ConstructL ( RHTTPClientServerSession& aSession, const TUriC8& aUri, RStringF aMethod )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   483
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   484
    __FLOG_0 ( _T8 ( "CHttpServerTransactionBase::ConstructL "));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   485
    iTransaction = aSession.OpenTransactionL(aUri, *this, aMethod);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   486
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   487
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   488
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   489
void CHttpServerTransactionBase::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   490
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   491
    __FLOG_0 ( _T8 ( "CHttpServerTransactionBase::MHFRunL"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   492
    switch(aEvent.iStatus)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   493
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   494
    case THTTPEvent::ESucceeded:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   495
    case THTTPEvent::EFailed:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   496
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   497
        aTransaction.Close();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   498
        iNotify.OnTransactionCompleted(this);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   499
        } break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   500
    default:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   501
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   502
        if (aEvent.iStatus < 0)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   503
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   504
            aTransaction.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   505
            iNotify.OnTransactionCompleted ( this );            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   506
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   507
        } break;        
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   508
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   509
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   510
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   511
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   512
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   513
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   514
TInt CHttpServerTransactionBase::MHFRunError(TInt aError, RHTTPTransaction /* aTransaction */, const THTTPEvent& /* aEvent */)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   515
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   516
    __FLOG_1 ( _T8 ( "CHttpServerTransactionBase::MHFRunError [aError=%d]"), aError);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   517
    //iUtils.Test().Printf(_L("MHFRunError fired with error code %d\n"), aError);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   518
    return KErrNone;    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   519
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   520
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   521
void CHttpServerTransactionBase::SetHeaderL(RStringPool& aStringPool, RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   522
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   523
    __FLOG_1 ( _T8 ( "CHttpServerTransactionBase::SetHeaderL [aHdrField=%d]"), aHdrField);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   524
    RStringF valStr = aStringPool.OpenFStringL(aHdrValue);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   525
    CleanupClosePushL(valStr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   526
    THTTPHdrVal val(valStr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   527
    aHeaders.SetFieldL(aStringPool.StringF(aHdrField,RHTTPClientServerSession::GetTable()), val);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   528
    CleanupStack::PopAndDestroy(&valStr); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   529
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   530
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   531
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   532
// -------------------------------------------------------
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   533
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   534
CHttpDataTransmitter* 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
   535
    {   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   536
    CHttpDataTransmitter* self = new (ELeave) CHttpDataTransmitter (aNotify, /*aUtils,*/ aFileServ);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   537
    CleanupStack::PushL ( self );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   538
    self->ConstructL ( aSession, aUri, aMethod );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   539
    CleanupStack::Pop (); // self
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   540
    return self;    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   541
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   542
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   543
//
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   544
// methods from MHTTPTransactionCallback
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   545
//
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   546
void CHttpDataTransmitter::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   547
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   548
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::MHFRunL"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   549
    switch (aEvent.iStatus)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   550
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   551
        case THTTPEvent::EGotRequestHeaders:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   552
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   553
            const TUriC8& uri = aTransaction.Request ().URI ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   554
            const TDesC8& uriDes = uri.UriDes ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   555
            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   556
            if ( uriDes.CompareF ( KAbsDocumentRoot ) == 0 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   557
                    || uriDes.CompareF ( KRelDocumentRoot ) == 0 )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   558
                {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   559
                RHTTPResponse response = aTransaction.Response ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   560
                RStringPool stringPool = aTransaction.Session ().StringPool ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   561
                RHTTPHeaders headers = response.GetHeaderCollection();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   562
                TBuf8<128> referer;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   563
                referer.Copy (_L("http://"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   564
                RStringF hostStr = stringPool.StringF (HTTP::EHost, RHTTPClientServerSession::GetTable());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   565
                THTTPHdrVal hostVal;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   566
                aTransaction.Request().GetHeaderCollection().GetField(hostStr, 0, hostVal);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   567
                referer.Append(hostVal.StrF().DesC());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   568
                referer.Append(KHttpSlash);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   569
//              SetHeaderL (stringPool, headers, HTTP::EReferer, referer);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   570
                referer.Append(KHomePage);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   571
                // Root path. Redirect to the home page.
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   572
                SetHeaderL (stringPool, headers, HTTP::ELocation, referer);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   573
                THTTPHdrVal hdr (0);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   574
                headers.SetFieldL (stringPool.StringF (HTTP::EContentLength, RHTTPClientServerSession::GetTable()), hdr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   575
                response.SetStatusCode(HTTPStatus::EFound);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   576
                RStringF statusText = stringPool.OpenFStringL ( KFound );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   577
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   578
                response.SetStatusText (statusText);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   579
                statusText.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   580
                aTransaction.SubmitL ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   581
                //iTransSubmitted = ETrue;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   582
                }           
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   583
            } 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   584
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   585
        case THTTPEvent::EGotRequestBodyData:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   586
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   587
            User::Invariant ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   588
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   589
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   590
        case THTTPEvent::ERequestComplete:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   591
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   592
            if ( !iTransSubmitted )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   593
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   594
            const TDesC8& uriDes = aTransaction.Request ().URI ().UriDes();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   595
//          __FLOG_1 ( _T8 ("CHttpdProtocolHandler::MHFRunL: [uriDes = %S]"), uriDes );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   596
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   597
            if ( OpenFile (uriDes) == KErrNone )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   598
                {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   599
                __FLOG_0 ( _T8 ( "CHttpDataTransmitter::MHFRunL: Sending Ok"));             
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   600
                RHTTPResponse response = aTransaction.Response();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   601
                response.SetBody(*this);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   602
                RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   603
                RStringPool stringPool = aTransaction.Session().StringPool();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   604
                SetHeaderL(stringPool, headers, HTTP::EContentType, iContentType);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   605
                response.SetStatusCode (HTTPStatus::EOk);   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   606
                RStringF statusText = stringPool.OpenFStringL ( KOk );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   607
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   608
                response.SetStatusText (statusText);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   609
                statusText.Close ();    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   610
                THTTPHdrVal hdr (OverallDataSize());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   611
                headers.SetFieldL (stringPool.StringF (HTTP::EContentLength, RHTTPClientServerSession::GetTable()), hdr);                                           
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   612
                }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   613
            else
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   614
                {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   615
                __FLOG_0 ( _T8 ( "CHttpDataTransmitter::MHFRunL: Sending Not Found"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   616
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   617
                RHTTPResponse response = aTransaction.Response();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   618
                response.SetStatusCode (HTTPStatus::ENotFound);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   619
                RStringF statusText = aTransaction.Session().StringPool().OpenFStringL ( KNotFound );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   620
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   621
                response.SetStatusText (statusText);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   622
                statusText.Close ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   623
                THTTPHdrVal hdr (0);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   624
                response.GetHeaderCollection().SetFieldL (aTransaction.Session().StringPool().StringF (HTTP::EContentLength, RHTTPClientServerSession::GetTable()), hdr);                                                                                   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   625
                }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   626
            aTransaction.SubmitL ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   627
            iTransSubmitted = ETrue;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   628
                
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   629
            }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   630
            } 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   631
            break;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   632
        default:
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   633
            CHttpServerTransactionBase::MHFRunL(aTransaction, aEvent);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   634
        }       
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   635
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   636
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   637
TInt CHttpDataTransmitter::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   638
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   639
    __FLOG_1 ( _T8 ( "CHttpDataTransmitter::MHFRunError [aError=%d]"), aError);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   640
    return CHttpServerTransactionBase::MHFRunError(aError, aTransaction, aEvent);   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   641
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   642
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   643
TInt CHttpDataTransmitter::OpenFile( const TDesC8& aHttpPath )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   644
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   645
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::OpenFile"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   646
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   647
    TBuf8<256> fileName;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   648
    fileName.Copy(KRoot);           
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   649
    if (aHttpPath.Locate(KHttpSlash) == 0)  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   650
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   651
        // Skip that
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   652
        TPtrC8 ptr (aHttpPath.Mid(1));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   653
        fileName.Append(ptr);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   654
        //replace forward slash with backward
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   655
        for ( TInt index = 0; index < fileName.Length (); index++ )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   656
            {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   657
            if ( fileName[index] == TChar ( KHttpSlash ) )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   658
                {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   659
                fileName[index] = TChar ( '\\' );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   660
                }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   661
            }   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   662
        }           
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   663
        
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   664
    HBufC* fileName16 = EscapeUtils::ConvertToUnicodeFromUtf8L (fileName);  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   665
    TInt err = iFile.Open(iFileServ, *fileName16, EFileShareReadersOnly);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   666
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   667
    TPtr ptr2 ( fileName16->Des() );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   668
    //iUtils.Test().Printf(_L("File Name: %S"), &ptr2);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   669
    __FLOG_1 ( _T8 ( "CHttpDataTransmitter::OpenFile [Error=%d]"), err);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   670
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   671
    // For Hardware
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   672
    if ( err != KErrNone )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   673
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   674
        ptr2[0] = TChar ( 'Z' );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   675
        err = iFile.Open ( iFileServ, ptr2, EFileShareReadersOnly );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   676
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   677
    __FLOG_1 ( _T8 ( "CHttpDataTransmitter::OpenFile [Error=%d]"), err);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   678
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   679
    if ( err != KErrNone )  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   680
        {       
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   681
        delete fileName16;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   682
        return err;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   683
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   684
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   685
    TParse parser;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   686
    parser.Set(ptr2, NULL, NULL);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   687
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   688
    if ( ptr2.Find(KHtml) != KErrNotFound )
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   689
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   690
        iContentType.Copy(KTextContent);            
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   691
        iContentType.Copy(KHtml);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   692
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   693
    else
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   694
        {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   695
        iContentType.Copy(KImageContent);   
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   696
        iContentType.Copy(KGif);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   697
        }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   698
    delete fileName16;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   699
    iFile.Size(iDataToSend);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   700
    return KErrNone;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   701
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   702
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   703
CHttpDataTransmitter::CHttpDataTransmitter (MTransactionNotify& aNotify,/*CHttpExampleUtils& aUtils,*/ RFs& aFileServ)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   704
: CHttpServerTransactionBase (aNotify, /*aUtils,*/ aFileServ)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   705
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   706
    __FLOG_OPEN ( "http", "httpexampleserver.txt" );
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   707
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::CHttpDataTransmitter "));       
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   708
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   709
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   710
TBool CHttpDataTransmitter::GetNextDataPart(TPtrC8& aDataPart)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   711
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   712
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::GetNextDataPart"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   713
    iFile.Read (iData); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   714
    iDataToSend -= iData.Length ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   715
    aDataPart.Set (iData);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   716
    return iDataToSend == 0;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   717
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   718
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   719
void CHttpDataTransmitter::ReleaseData()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   720
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   721
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::ReleaseData"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   722
    iData.SetLength (0);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   723
    if (iDataToSend > 0)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   724
        iTransaction.NotifyNewRequestBodyPartL ();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   725
    else
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   726
        iFile.Close ();     
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   727
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   728
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   729
TInt CHttpDataTransmitter::OverallDataSize()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   730
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   731
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::OverallDataSize"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   732
    TInt size;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   733
    iFile.Size (size);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   734
    return size;    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   735
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   736
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   737
TInt CHttpDataTransmitter::Reset()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   738
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   739
    __FLOG_0 ( _T8 ( "CHttpDataTransmitter::Reset"));
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   740
    return KErrNone;    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   741
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   742
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   743
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   744
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   745
/*
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   746
// ------------------------------------------------------------
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   747
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   748
LOCAL_D void TestL()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   749
// Create a test object, invoke the tests using it and remove
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   750
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   751
        
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   752
    //TRAPD(err,CHttpExampleUtils::InitCommsL()); 
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   753
    // create an active scheduler to use
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   754
    CActiveScheduler* scheduler = new(ELeave) CActiveScheduler();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   755
    CleanupStack::PushL(scheduler);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   756
    CActiveScheduler::Install(scheduler);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   757
  
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   758
    // Create and start the client
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   759
    CHttpServer* httpCli = CHttpServer::NewL();         
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   760
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   761
    CZeroconfClient* browser = CZeroconfClient::NewL(*httpCli);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   762
    browser->ConnectL();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   763
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   764
    CActiveScheduler::Start();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   765
    //
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   766
    CleanupStack::PopAndDestroy(1); //  scheduler
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   767
    delete httpCli;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   768
    delete browser;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   769
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   770
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   771
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   772
GLDEF_C TInt E32Main()
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   773
// Main program - run the tests within a TRAP harness, reporting any errors that
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   774
// occur via the panic mechanism. Test for memory leaks using heap marking.
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   775
    {
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   776
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   777
    __UHEAP_MARK;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   778
    CTrapCleanup* tc=CTrapCleanup::New();
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   779
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   780
    TRAPD(err,TestL());
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   781
    
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   782
    if (err!=KErrNone)
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   783
        User::Panic(_L("Test failed with error code: %i"), err);
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   784
    delete tc;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   785
    __UHEAP_MARKEND;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   786
    return KErrNone;
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   787
    }
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   788
*/
ff5174af067c ZeroConf Sharing Application
guru.kini@nokia.com
parents:
diff changeset
   789