HTTPExampleEngine

Login to reply to this topic.
Mon, 2007-12-31 11:25
Joined: 2007-07-31
Forum posts: 123

Hi all,

when i include the following files..

HTTPExampleEngine.h and
HTTPExampleEngine.cpp

in in my project for the http Handling it gives lot of errors...

the file ' MHTTPAuthenticationCallback.h' can not be opened.
undefined identifier 'MHTTPTransactionCallback'
undefined identifier 'MHTTPTransaction'
undefined identifier 'MHTTPHeaders'

i have included following library files.....
LIBRARY euser.lib apparc.lib cone.lib eikcore.lib
LIBRARY eikcoctl.lib avkon.lib
LIBRARY http.lib // HTTP APIs
LIBRARY InetProtUtil.lib // TUriParser
LIBRARY eikdlg.lib
LIBRARY bafl.lib // String pool APIs
LIBRARY eikctl.lib // CEikRichTextEditor
LIBRARY MediaClientAudio.lib
LIBRARY MediaClientAudioStream.lib
LIBRARY commonengine.lib // StringLoader
LIBRARY MMFServerbaseclasses.lib //for codec

//////////////////////////////// HTTPExampleEngine.h //////////////////////////////////////////
#ifndef HTTPEXAMPLEENGINE_H
#define HTTPEXAMPLEENGINE_H

// INCLUDES
// System includes
#include // CBase
#include // MHTTPAuthenticationCallback
#include // MHTTPDataSupplier
#include // MHTTPTransactionCallback
#include // RHTTPSession
#include // RHTTPTransaction

// CONSTANTS

// FORWARD DECLARATIONS
class CHTTPFormEncoder; // data supplier class for http post request for html data

// CLASS DECLARATION

/**
*
* @class MHTTPExampleEngineObserver HTTPExampleEngine.h
* @brief This is the engine observer interface
*
*/
class MHTTPExampleEngineObserver // for passing passing progress event to the AppUI
{
public:
virtual void ResponseStatusL(TInt aStatusCode, const TDesC& aStatusText) = 0;
virtual void ResponseReceivedL(const TDesC& aResponseBuffer) = 0;
};

/**
*
* @class CHTTPExampleEngine HTTPExampleEngine.h
* @brief This is the engine class, responsible for HTTP transactions.
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*
*/
class CHTTPExampleEngine : public CBase,
public MHTTPTransactionCallback // for receive progress event
{
public:
static CHTTPExampleEngine* NewL(MHTTPExampleEngineObserver& aObserver);
~CHTTPExampleEngine();

void GetRequestL(const TDesC& aUri);
void PostRequestL(const TDesC& aName);

// Cancel an outstanding transaction
void Cancel();

private: // from MHTTPTransactionCallback
virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);

private:
CHTTPExampleEngine(MHTTPExampleEngineObserver& aObserver);
void ConstructL();

void ParseUriL(const TDesC& aUri);// Convert the URI to an 8-bit descriptor
// then set iUriParser to point at it
void AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue);

private:
RHTTPSession iSession;
RHTTPTransaction iTransaction;

HBufC* iResponseBuffer;
HBufC8* iUri;
TUriParser8 iUriParser;
CHTTPFormEncoder* iFormEncoder;

MHTTPExampleEngineObserver& iObserver;
};

#endif // #ifndef HTTPEXAMPLEENGINE_H

// End of File

////////////////////////////////////// HTTPExampleEngine.cpp //////////////////////////////////////

/**
*
* @brief Definition of CHTTPExampleEngine
* This is to maintain http connection and session
* @version 1.0
*/

// Class include
#include "HTTPExampleEngine.h"

// System includes
#include // CHTTPFormEncoder
#include // HTTP string table#include // RHTTPHeaders
#include

// User includes
#include "HTTPExample.hrh" // EMaxNameLength

// CONSTANTS
// HTTP header values
_LIT8(KUserAgent, "HTTPExample (1.0)"); // Name of this client app
_LIT8(KAccept, "audio/*"); // Accept any (but only) text content
_LIT8(KPostParamName, "NAME"); // Name of the parameter sent in a POST request
_LIT8(KPostContentType, "text/plain"); // Content type sent in a POST request

// URL for POST request.
//_LIT8(KPostUri, "http://cgi.www.emccsoft.com/cgi-bin/www.emccsoft.com/post.pl");
//_LIT8(KPostUri, "http://www.magpiemobile.com/cgi-bin/book_post.cgi");
_LIT8(KPostUri,"http://192.168.1.124/cgi-bin/printenv.pl");

// ================= MEMBER FUNCTIONS =======================

/**
* 2-phase constructor
*
* @param aObserver An observer of this engine (e.g. the UI)
*/
CHTTPExampleEngine* CHTTPExampleEngine::NewL(MHTTPExampleEngineObserver& aObserver)
{
CHTTPExampleEngine* self = new (ELeave) CHTTPExampleEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}

/**
* C++ constructor
*
* @param aObserver An observer of this engine (e.g. the UI)
*/
CHTTPExampleEngine::CHTTPExampleEngine(MHTTPExampleEngineObserver& aObserver)
: iObserver(aObserver)
{
}

/**
* 2nd-phase constructor
*/
void CHTTPExampleEngine::ConstructL()
{
// Open the RHTTPSession
iSession.OpenL();

// Construct the form encoder
iFormEncoder = CHTTPFormEncoder::NewL();
}

/**
* C++ destructor
*/
CHTTPExampleEngine::~CHTTPExampleEngine()
{
// Close session
iSession.Close(); // Will also close any open transactions
delete iResponseBuffer;
delete iFormEncoder;
delete iUri;
}

/**
* Override of pure virtual method in MHTTPTransactionCallback.
* Called to report progress by a currently outstanding transaction.
*
* @param aTransaction The transaction reporting progress
* @param aEvent The event being notified
*/
void CHTTPExampleEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseHeaders:
{
// HTTP response headers have been received.
// Pass status information to observer.
RHTTPResponse resp = aTransaction.Response();

// Get status code
TInt statusCode = resp.StatusCode();

// Get status text
RStringF statusStr = resp.StatusText();
HBufC* statusBuf = HBufC::NewLC(statusStr.DesC().Length());
statusBuf->Des().Copy(statusStr.DesC());

// Inform observer
iObserver.ResponseStatusL(statusCode, *statusBuf);

CleanupStack::PopAndDestroy(statusBuf);
}
break;

case THTTPEvent::EGotResponseBodyData:
{
// Get text of response body
MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
TPtrC8 ptr;
dataSupplier->GetNextDataPart(ptr);

// Convert to 16-bit descriptor
HBufC* buf = HBufC::NewLC(ptr.Length());
buf->Des().Copy(ptr);

// Append to iResponseBuffer
if (!iResponseBuffer)
{
iResponseBuffer = buf->AllocL();
}
else
{
iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length() + buf->Length());
iResponseBuffer->Des().Append(*buf);
}

//nn: Here the data is content in a 16 bit descriptor
// want to write it to a file or play it.

// Release buf
if (iResponseBuffer->Length()>=40960)
{
// to chk the progerss of program
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("OK"));
delete informationNote;
iObserver.ResponseReceivedL(*iResponseBuffer);
iResponseBuffer=NULL;
}
CleanupStack::PopAndDestroy(buf);

// Release the body data
dataSupplier->ReleaseData();

//nm: Pass the response buffer by reference to the observer
//iObserver.ResponseReceivedL(*iResponseBuffer);
}
break;

case THTTPEvent::EResponseComplete:
{
// Pass the response buffer by reference to the observer
//iObserver.ResponseReceivedL(*iResponseBuffer);

//should AppUi called it ? Because we pass info to AppUi through d Observer
}
break;
}
}

/**
*/
TInt CHTTPExampleEngine::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
{
return aError;
}

/**
* Initiate a GET request
*
* @param aUri The URI to get
*/
void CHTTPExampleEngine::GetRequestL(const TDesC& aUri)
{
// Parse the URI
ParseUriL(aUri);

// Create the transaction
iTransaction = iSession.OpenTransactionL(iUriParser, *this,
iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()));

// Set transaction headers
RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
AddHeaderL(headers, HTTP::EUserAgent, KUserAgent);
AddHeaderL(headers, HTTP::EAccept, KAccept);

// Submit the request
iTransaction.SubmitL();
}

/**
* Initiate a POST request
*
* @param aName The user's name
*/
void CHTTPExampleEngine::PostRequestL(const TDesC& aName)
{
// Build form encoder
// Start by removing any previous content
delete iFormEncoder;
iFormEncoder = NULL;
iFormEncoder = CHTTPFormEncoder::NewL();
TBuf8 buf8;
buf8.Copy(aName);
iFormEncoder->AddFieldL(KPostParamName, buf8);

// Create transaction
iUriParser.Parse(KPostUri);
iTransaction = iSession.OpenTransactionL(iUriParser, *this,
iSession.StringPool().StringF(HTTP::EPOST, RHTTPSession::GetTable()));

// Set transaction headers
RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
AddHeaderL(headers, HTTP::EUserAgent, KUserAgent);
AddHeaderL(headers, HTTP::EAccept, KAccept);
AddHeaderL(headers, HTTP::EContentType, KPostContentType);

// Set the form encoder as the data supplier
iTransaction.Request().SetBody(*iFormEncoder);

// Submit the request
iTransaction.SubmitL();
}

//
// Utility methods
//

/**
* Parse a URI
*
* @param aUri The URI to be parsed
*/
void CHTTPExampleEngine::ParseUriL(const TDesC& aUri)
{
// Convert the URI to an 8-bit descriptor
// then set iUriParser to point at it
delete iUri;
iUri = NULL;
iUri = HBufC8::NewL(aUri.Length());
iUri->Des().Copy(aUri);
User::LeaveIfError(iUriParser.Parse(*iUri));
}

/**
* Add a header to a header set
*
* @param aHeaders The header set to be modified
* @param aHeaderField The name of the header to be added
* @param aHeaderValue The value for the header to be added
*/
void CHTTPExampleEngine::AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue)
{
RStringPool stringPool = iSession.StringPool();
RStringF valStr = stringPool.OpenFStringL(aHeaderValue);
THTTPHdrVal headerVal(valStr);
aHeaders.SetFieldL(stringPool.StringF(aHeaderField, RHTTPSession::GetTable()), headerVal);
valStr.Close();
}

/**
* Cancel any outstanding transaction
*/
void CHTTPExampleEngine::Cancel()
{
iTransaction.Cancel();
}


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++


Mon, 2007-12-31 11:44
Joined: 2005-11-20
Forum posts: 1058
Re: HTTPExampleEngine

The HTTP header files are in a subdirectory http. Did you specify that subdirectory in your include statements? It does not look that way, and that may be the problem.

An import should look like this:

#include <http\MHTTPAuthenticationCallback.h>


René Brunner

Mon, 2007-12-31 12:15
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

Hi rburnner,

i was a VC++ programmer but due to some reason i decided to switch myself in Symbian C++ .I want to know is it a good decesion according to the future....What is the future of Symbian C++ in comparison with VC++?

thanks...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Mon, 2007-12-31 12:21
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

The above files
HTTPExampleEngine.h and
HTTPExampleEngine.cpp

Which i have added in my project was working properly in the previous Example code "HTTPExample" .it was not needed to include like this #include .

please help...

Thanks...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Mon, 2007-12-31 12:46
Joined: 2005-11-20
Forum posts: 1058
Re: HTTPExampleEngine

I am not sure what you mean.

Anyway, for me the following error line that you posted

the file ' MHTTPAuthenticationCallback.h' can not be opened.

tells me that you have an include statement somewhere for a header file 'MHTTPAuthenticationCallback.h' (a file name that is itself probably correct) that the compiler cannot find. I think the compiler cannot find it because your include statement does not specify the subdirectory 'http', as I said in my first post.


What is the future of Symbian C++ in comparison with VC++?

I personally tend to think that the future is what *I* make out of it. Don't ask me where more programmers will be needed in the future, for Symbian C++ or VC++, but I am sure that both will continue into the future and need programmers. So my thinking goes like this: If I am good, I will find a job, doing Symbian C++ or VC++, if I am not good, I won't have a job, whatever happens to those two systems. I try not to worry about the future in general, because I have near zero influence there, but care about *my* future that I can and should influence.


René Brunner

Tue, 2008-01-01 10:35
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

Hi,

To test the correctness of the code, i created a header file and a source file in the header file i included
MHTTPAuthenticationCallback.h file and added the library file http.lib in mmp file but still following error is comming.

the file ' MHTTPAuthenticationCallback.h' can not be opened.
undefined identifier 'MHTTPTransactionCallback'


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Tue, 2008-01-01 10:57
Joined: 2005-11-20
Forum posts: 1058
Re: HTTPExampleEngine

Can you please post the exact source line that you used to include that header file?


René Brunner

Wed, 2008-01-02 08:34
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

i created a file a.h and a.cpp

//-----This is a.h----------------------------------//
#include <MHTTPAuthenticationCallback.h>
class A
{
public:
void Display();
};

//-----This is a.cpp----------------------------------//
void A::Display()
{
}

error is comming.

the file ' MHTTPAuthenticationCallback.h' can not be opened.
undefined identifier 'MHTTPTransactionCallback'


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-02 08:49
Joined: 2005-11-20
Forum posts: 1058
Re: HTTPExampleEngine

Thanks. Now compare your include line with the one that I gave already in my earlier post:

#include <http\MHTTPAuthenticationCallback.h>

Do you see the difference? That's what I meant by giving the subdirectory in the include line.


René Brunner

Wed, 2008-01-02 09:09
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

now following error is coming
ecom.h can not be opened
cauthenticationfilterinterface.h line 15


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-02 09:40
Joined: 2005-11-20
Forum posts: 1058
Re: HTTPExampleEngine

ecom.h needs "ecom\" instead of "http\", but otherwise same story...

You find the exact locations of header files in the S60 SDK documentation, mostly. Just look closely for any subdirectories given in include lines.


René Brunner

Wed, 2008-01-02 10:59
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

in an another application it is decleared simply as
#include <MHTTPAuthenticationCallback.h>
and it is working fine in that application...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-02 12:58
Joined: 2007-09-20
Forum posts: 95
Re: HTTPExampleEngine

Add the path of the directory to your mmp file under "Systeminclude" path.
If the path is defined in systeminclude path of mmp file, then there is no need to specify the sub-directory.


Chao,
Raghav

Thu, 2008-01-03 09:51
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

i added the path of the directory in SYSTEMINCLUDE path of mmp file but stll problem exist...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Thu, 2008-01-03 11:38
Joined: 2007-09-20
Forum posts: 95
Re: HTTPExampleEngine

The mmp file should look something like:

SYSTEMINCLUDE   \epoc32\include
SYSTEMINCLUDE   \epoc32\include\http
SYSTEMINCLUDE   \epoc32\include\ecom

source file:

#include <MHTTPAuthenticationCallback.h>
#include <ecom.h>

Make file has to be re-generated after modifying the mmp file before generating the target.


Chao,
Raghav

Thu, 2008-01-03 12:43
Joined: 2007-07-31
Forum posts: 123
Re: HTTPExampleEngine

Hi raghav_an,

Thank you very much for the great help....

i got the solution...

now my code is working properly....

Thank you very much...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

  • Login to reply to this topic.