📄 define.h
字号:
/***************************************************************
*Copyright (c) 金瀚海网络科技有限公司 All rights reserved
*文件名称: define.h
*模 块 名: 定义文件
*功能描述: 全局常量符号定义
*当前版本: 1.0
*作 者: 彭飞云
*完成日期: 2007-08-20
*修改记录:
* 日期 版本 作者 修改描述
****************************************************************
****************************************************************/
#ifndef DEFINE_H
#define DEFINE_H
#include <pthread.h>
#include <list>
#include <vector>
using namespace std;
/*
#ifndef NS_NAMESPACE
#define NS_NAMESPACE ns
#define NS_BEGIN_NAMESPACE namespace NS_NAMESPACE {
#define NS_END_NAMESPACE }
#define NS_USING_NAMESPACE using namespace ns;
#endif
*/
#ifdef DEBUG
#define TEST_HERE(sentence) printf(sentence);
#else
#define TEST_HERE(sentence)
#endif
//////////////////////////////////////////////////////////////////////////
//错误返回值定义
#define NS_SUCCEEDED 0
#define NS_FAILED -1
#define NS_NOTFOUND -2 //结点未发现
#define NS_EMPTY -3 //队列为空
#define NS_FULL -4 //队列已满
#define NS_TIMEOUT -5 //等待超时
#define NS_CONCUT -6 //连接已标记为断开,且队列为空,符合断开条件
////////////////////////////////////////////////////////////
#define NS_NEWCONN_TIMEOUT 3 //新建连接超时时间,单位秒 目前采用宏,将来应该采用用户定义的策略
#define NS_DEFAULT_TIMEOUT 20 //默认超时,单位秒
#define NS_RW_TIMEOUT 6 //默认读写超时
#define MEMBUFSIZE 1600
#define DEFAULT_LEVEL 0
#define MAX_FD 65535
//////////////////////////////////////////////////////////////////////////
#define LENCENSE_LEN 1024
#define PROTOCOL_NUM 65536
#define LOG_PATH "./log/"
#define LOG_FILE "./log/NetStrobe.log"
#define BAK_LOG_PATH "./log/"
#define INI_PATH "./ini/"
#define INI_FILE "./ini/NetStrobe.ini"
#define MAX_PLUG_SIZE 64
#define NS_RCV_SEND_BUF_SIZE (64 * 1024) // 8192//65535//81920 //(1024*80) 接收发送数据缓冲
#define MAX_DOMAINNAME_SIZE 255
//definition of global command type between InterNet and OutNet;
#define NEW_CONNECTION 0x01 //ok
#define NEW_CONNECTION_SUCC 0x02 //ok
#define NEW_CONNECTION_FAIL 0x03 //ok
#define CANCEL_CONNECTION 0x04 //ok
#define NEW_LISTEN 0x05 //ok
#define NEW_LISTEN_SUCC 0x06 //ok
#define NEW_LISTEN_FAIL 0x07 //ok
#define CLOSE_LISTEN 0x08 //ok
#define NEW_LOCAL_LISTEN 0x09
#define CLOSE_LOCAL_LISTEN 0x10
//Outer computer's stats report.
#define ENET_CONN_STATUS 0x11 //exter-pc status
//control the OuterNet ip setting
#define SET_ENET_ETH 0x12 //OK,exter machine ip setting
#define SET_ENET_ETH_SUCC 0x13
#define SET_ENET_ETH_FAIL 0x14
#define ENET_PC_STATUS 0x15
#define SET_ENET_FIREWALL 0x16 //setting the exter-net firewall
#define SET_ENET_FIREWALL_SUCC 0x17
#define SET_ENET_FIREWALL_FAIL 0x18
#define FIREWARE_REBOOT 0x19 //by 1394 itself OK
//ADDED at 2008-2-28
#define ENET_LISTEN_INFO 0x21
#define ENET_LISTEN_INFO_SUCC 0x22
#define ENET_LISTEN_INFO_FAIL 0x23
#define ENET_REBOOT 0x24 //外网重启指令
#define ENET_CONFIG_INFO 0X25 //外网配置信息
#define ENET_CONFIG_INFO_SUCC 0x26
#define ENET_CONFIG_INFO_FAIL 0x27
#define QUEUE_BUSY 0x28 //队列繁忙
#define QUEUE_IDLE 0x29 //队列空闲
enum IsBackPut{
BACK_PUT = 0, //从后面加入消息
FRONT_PUT //从前面加入消息
};
//the socket fd pair's status
enum ConnStat {
HALF_CONN = 1,
FULL_CONN,
CUT_CONN
};
//for epoll class
enum FDType {
LISTEN = 0,
WRITEABLE,
READABLE
};
//definition of sign indicating it is Inter or Outer
enum NetType{
INTERNAL=0,
EXTERNAL,
NONETTYPE
};
enum DirectionType{
UP = 0,
DOWN
};
enum PluginType {
HTTP = 1,
FTP,
POP3,
SMTP,
SOCK,
DB,
NOPLUGINTYPE//the last forever
};
enum FuncType{
PUB = 1,
PROXY,
NOFUNCTYPE//the last forever
};
//key word filter:subject?content?attachment?
enum KeyWordType{
SUBJECT = 0,
CONTENT,
ATTACHNAME
};
//how to use the keyword?:equal to it? including it? start with it?.....
enum FiltRule{
EQUALTO = 1,
INCLUDING,
STARTWITH,
ENDWITH
};
//Address type:
enum EmlAddrType{
SENDER = 0,
RECEIPIENT,
CCRECEIPIENT,
BCCRECEIPIENT
};
enum AddrType{
IPTYPE = 1,
DOMAINNAMETYPE,
NOADDRTYPE
};
enum MSG_PROTOCOL{
DATA_MESSAGE = 1,
CTRL_MESSAGE
};
struct _PLUG_DESC{
//when start up the plug,this struct is passed into the plugin.
char szPlugName[17];
char szVersion[17];
char szDesc[128];
};
struct CListenInfo{
NetType eNetType; //listenning type:exte-net?inter-net?
PluginType ePluginType; //plugin type
FuncType eFuncType; //function type:pub or proxy?
char szLocalIp[16]; //listenning ip as 192.168.155.166
unsigned short nLocalPort; //listenning port
char szSrvIp[16]; //dest server ip
unsigned short nSrvPort; //dest server port
};
struct _STAT_PARAMS{
short nVPort;//port of exter-net
short nSrcPort;//
char szSrcAddr[MAX_DOMAINNAME_SIZE];
};
struct ENET_CONN_Status{
int iStatID;
_STAT_PARAMS stExterStat;
};
struct ENET_PC_Status{
unsigned int iBytesFromExter;
unsigned int iBytes2Exter;
int iHDSpaceLeftExter;
int iCPURatioExter;
int iRAMInUseExter;
};
//向外网传递配置信息结构
struct ENET_Config_Info {
unsigned short WorkThreadNum;
unsigned short CtrlThreadNum;
//unsigned short DBThreadNum; //外网不需要数据库操作
unsigned long QueueMaxDepth;
char LogLevel;
unsigned long LogMaxSize;
};
struct _CTRL_PARAMS{
//this struct is for the control msg to store the ip and port info.
PluginType ePlugin;//when send stat to plugin,it is necessary
FuncType eFuncType;//the same with the above
unsigned short nLocalPort;
AddrType eLocalAddrType;
char szLocalAddr[MAX_DOMAINNAME_SIZE];
unsigned short nSrvPort;
AddrType eSrvAddrType;
char szSrvAddr[MAX_DOMAINNAME_SIZE];
_CTRL_PARAMS(){
nLocalPort = 0;
eLocalAddrType = NOADDRTYPE;
memset(szLocalAddr,0,MAX_DOMAINNAME_SIZE);
nSrvPort = 0;
eSrvAddrType = NOADDRTYPE;
memset(szSrvAddr,0,MAX_DOMAINNAME_SIZE);
}
};
typedef struct _LOGRECORD_T{
//plugin write statistic data to database
char szTime[12]; //ie,hh:mm:ss:xxx
char szID[16]; //action ID, the definition is not clear to us now
char szUserName[16]; //user name
char szSenderHost[32]; //sender host(or address)
char szRcverHost[32]; //receipient host(address)
char szPluginName[16]; //protocol indication
char szRank[8]; //rank of this log
int iPkgLen; //the package length
char szLinkFileName[16]; //the package file name
int iLinkFileLen; //file length
char szComment[255]; //comment string.
};
struct INET_PC_Status{
//inner net hardware space left
int iBytesFromInter;
int iBytes2Inter;
int iHDSpaceLeftInter;
int iCPURatioInter;
int iRAMInUseInter;
};
struct FWRule
{
char chFWLevel;
//unsigned int RulesNum; //组包时增加计数字段
vector<string> vRules;
};
struct IPSet {
char szIP[16]; //like as 192.168.1.1 ?
char szMask[16];
//unsigned short PortCount; //组包时增加计数字段
vector<unsigned int> vecPort;
};
struct EthSet
{
NetType eNetType; //Inter or Exter net
unsigned short EthNumber;//the number 网卡编号
char Mac[18]; //Mac address ,eg,"00-19-DB-A8-76-34"
char Gateway[16];
char Dns1[16];
char Dns2[16];
char Dns3[16];
int iEffectTime;//effective time for the database to keep the info
//unsigned short IPSetCount; //ip counter //组包时增加计数字段
vector<IPSet> vecIP;// multiple ip per network card;
EthSet()
{
eNetType = NONETTYPE;
memset(Mac,0,18);
iEffectTime = 0;
//IPSetCount = 0;
memset(Dns1,0,16);
memset(Dns2,0,16);
memset(Dns3,0,16);
}
};
struct Eth
{
//unsigned short EthCount; //network card counter //组包时增加计数字段
vector<EthSet> vecEthSet; //multiple network card set
};
enum IsCopy
{
COPY = 0,
NO_COPY
};
struct CMsg
{
public:
CMsg();
CMsg(char* pData, unsigned int uiLen, IsCopy eIsCopy = NO_COPY);
CMsg(const CMsg& cMsg);
CMsg& operator=(const CMsg& cMsg);
virtual ~CMsg();
char* m_pData;
int m_iLen;
};
//for epoll class
struct Eventer
{
//when epoll pop out the events,fd and the other infomation
//is known at once
volatile int inFd; //删除结点仅需要把infd赋0,清空msg队列及可
int outFd; //外部fd,另外一端的
PluginType ePluginType;
FuncType eFuncType;
volatile ConnStat eConnStat;
pthread_cond_t condConnStat;
volatile bool IsBusy; //目标队列状态, 0 表示空闲, 1 表示繁忙 发送方使用
volatile bool IsNotify; //是否已经发送通知 接收方使用
time_t ConnTime;
volatile bool IsTask; //是否已有任务
list<CMsg*> tMsgQueue;
pthread_mutex_t mutexMsg;
unsigned short nLocalPort;
char strLocalIp[16];
unsigned short nSrvPort;
char strSrvIp[16];
Eventer(){
inFd =0;
outFd = 0;
ePluginType = NOPLUGINTYPE;
eFuncType = NOFUNCTYPE;
eConnStat = HALF_CONN;
IsBusy = false;
IsTask = false;
memset(strSrvIp,0,16);
nSrvPort = 0;
memset(strLocalIp,0,16);
nLocalPort = 0;
pthread_mutex_init(&mutexMsg, NULL);
pthread_cond_init(&condConnStat,NULL);
}
~Eventer() {
pthread_mutex_destroy(&mutexMsg);
pthread_cond_destroy(&condConnStat);
}
};
//plugin call the msg_handle,the return value:
#define PLUGIN_SUCCESS 0 //handling successfully
#define PLUGIN_FAILED -1 //handling failed
#define PLUGIN_UNKNOW -2 //unknow command
#endif ///_DEFINE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -