📄 httpserver.h
字号:
/**
* HttpServer classes definitions:
* CHttpApplication - The main application
* CHttpDocument - The application's main document class
* CHttpAppUi - User interface
* CHttpView - User interface's main view
* CHttpContainer - Main view's container
* CHttpSocketEngine - The socket listener engine
*
* Copyright (C) SWelcom 2004
* Created by Kenneth Falck <kennu@swelcom.fi>
*
* This file is part of HttpServer.
*
* HttpServer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* HttpServer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HttpServer; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __HTTPSERVER_H
#define __HTTPSERVER_H
#include <e32std.h>
#include <eikenv.h>
#include <eikdoc.h>
#include <aknapp.h>
#include <aknviewappui.h>
#include <aknview.h>
#include <es_sock.h>
#include <in_sock.h>
#include <apgwgnam.h>
#include <HttpServer.rsg>
#include "HttpServer.hrh"
#define MAXLINELEN 1024
class CHttpApplication: public CAknApplication
{
private:
CApaDocument *CreateDocumentL(); // inherited from CApaApplication
TUid AppDllUid() const;
};
class CHttpDocument: public CEikDocument
{
public:
static CHttpDocument *NewL(CEikApplication &app);
CHttpDocument(CEikApplication &app);
void ConstructL();
~CHttpDocument();
void UpdateTaskNameL(CApaWindowGroupName *aWgName);
private:
TBool hidden;
CEikAppUi *CreateAppUiL(); // inherited from CEikDocument
};
class CHttpView;
class CHttpSocketEngine;
class CHttpAppUi: public CAknViewAppUi
{
public:
CHttpAppUi *NewL();
CHttpAppUi();
void ConstructL();
~CHttpAppUi();
CHttpView *View() { return view; }
static TInt StaticDelayedInitialize(TAny *ptr);
void DelayedInitializeL();
private:
void HandleCommandL(TInt cmd); // inherited from CEikAppUi
CHttpView *view;
CHttpSocketEngine *socketengine;
CPeriodic *periodic;
};
class CHttpContainer;
class CHttpView: public CAknView
{
public:
CHttpView();
void ConstructL();
virtual ~CHttpView();
TUid Id() const;
void HandleCommandL(TInt cmd);
void PrintL(const TDesC &str);
private:
void DoActivateL(const TVwsViewId &previd, TUid custmsgid, const TDesC8 &custmsg);
void DoDeactivate();
CHttpContainer *container;
};
class CHttpContainer: public CCoeControl
{
public:
CHttpContainer(CHttpView *view);
void ConstructL(const TRect &rc);
virtual ~CHttpContainer();
void PrintL(const TDesC &str);
private:
void Draw(const TRect &rc) const;
TBuf <100> line[10];
int lines;
};
class CHttpSocketEngine: public CActive
{
public:
CHttpSocketEngine(TInt aPriority);
void ConstructL(CHttpAppUi *nappui);
~CHttpSocketEngine();
TBool ToggleListeningL();
TBool IsListening();
void StartListeningL(TBool nomsg=EFalse);
void StopListeningL();
void RunL();
void DoCancel();
private:
TBool ReadLine(RSocket &client, TDes8 &buf);
TInt ReadBuffer(RSocket &client, TDes8 &buf);
TInt ReadChunkSize(RSocket &client);
TInt ReadChunk(RSocket &client, TInt chunksize, TDes8 &buf);
void HandleClientL(RSocket &client);
void ProcessRequestL(RSocket &client, TDesC8 &method, TDesC8 &url, TInt contentlength, TBool chunked);
void SendResponse(RSocket &client, const TDesC8 &response);
TBool ReadFileL(const TDesC8 &relpath, TDes8 &content);
CHttpAppUi *appui;
CHttpView *view;
TBool listening;
TBuf8 <MAXLINELEN> linebuf;
TBuf8 <MAXLINELEN> readbuf;
TBuf8 <MAXLINELEN> buf;
TBuf8 <MAXLINELEN> request;
TBuf <MAXLINELEN*2+1> debug;
RSocketServ iSocketServ;
RSocket iServerSocket;
RSocket iClientSocket;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -