|
//***********************************************************************
// (c) Copyright 1999-2003 Santronics Software, Inc. All Rights Reserved.
//***********************************************************************
// File Name : spserver.h
// Subsystem : Protocal Server
// Date : 03/03/2003
// Author : Hector Santos, Santronics Software, Inc.
// VERSION : 1.00P
//
// Revision History:
// Version Date Author Comments
// ------- -------- ------ -------------------------------------------
// v1.00P 03/03/03 HLS Public Release version (non-SSL version)
//***********************************************************************
#ifndef __SPSERVER_H
#define __SPSERVER_H
#include <afx.h>
#include <process.h>
#include <tchar.h>
#include "thread.h"
#include "socketio.h"
////////////////////////////////////////////////////////////////////
#define MAX_SEND_BUFFER_LEN 4096
#define MAX_SEND_OUTPUT 4096
#define SPCMD(cls, cmd, func) \
{cmd, (BOOL (CSPServer::*)(char *))(cls::func)}
////////////////////////////////////////////////////////////////////
/**
* This class implements a state-based simple protocol server.
*
* A simple protocol server is essential for protocols such as SMTP, POP3,
* and more. This class handles all the socket related communications
* So that one may focus on the implementation of the protocol itself.
*
* Usage requires the creation of a child class that implements the STATE
* functions for the protocol.
*/
class CSPServer: public CThread {
public:
/**
* Used internally in CSPServer
* Structure maintains list of protocol commands used
* in simple protocol servers.
*/
struct TSPDispatch {
char *cmd;
BOOL (CSPServer::*f)(char *args);
};
CSPServer(CSocketIO *s, TSPDispatch *dispatch, long maxconnect = 25);
~CSPServer();
void ProcessCommand(char *cmdline);
BOOL GetSubCommand(char *s, DWORD len){return GetCommand(s, len);}
void SetTimeoutSeconds(const DWORD secs) { dwTimeoutSeconds = secs; }
DWORD GetTimeoutSeconds() { return dwTimeoutSeconds; }
virtual void DumpReceivedByte(int b) {}
protected:
virtual void Go();
protected:
CSocketIO *Control;
virtual void SendWelcome() {}
virtual BOOL CheckAbort();
virtual BOOL PreprocessLine(char *s) { return FALSE; }
virtual void SessionTrace(const char *szTag, const char *s) {}
virtual void SendCommandError(const char *cmdline);
virtual void Cleanup() {}
virtual BOOL QueryAllowTimeoutDisconnect() { return TRUE; }
virtual void OnWaitReceivedDataAbandoned() {}
virtual void OnReceiveByteError(const int error) {};
void SetDispatchTable(TSPDispatch *dispatch) { Dispatch = dispatch; }
const char *GetCurrentCommandName() { return commandname; }
BOOL Send(const TCHAR *format, ...);
BOOL Done;
DWORD LastCommandTime;
const char *commandname;
DWORD dwTimeoutSeconds;
private:
TSPDispatch *Dispatch;
BOOL GetCommand(char *s, DWORD len);
long MaxConnections;
};
#endif
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.