CCLibrary.h是提供给应用include的文件,与CCLbrary.c一起提供必要的宏供应用调用。
#ifndef __CC_LIBRARY__
#define __CC_LIBRARY__
#if defined(__WITH_CC__)
#include "CCDataType.h"
extern int cc_TelnetServer_Create();
extern int cc_InitData(const char* prompt, const char* ip, unsigned short port, int max);
extern int cc_Run();
extern int cc_IsRun();
extern int cc_RegCmd(const char* cmd, const char* help, const _cc_cmdcallback callback);
extern void cc_Destroy();
extern int cc_CmdOutput(struct _cc_telnet_clientdata* client, const char* fmt, );
#define CC_CREATE(prompt, ip, port, max) \
{ \
cc_InitData(prompt, ip, port, max); \
cc_Run(); \
}
#define CC_DESTROY() \
{\
cc_Destroy(); \
}
#define CC_ISRUN() cc_IsRun()
#define CC_REGCMD(cmd, help, callback) cc_RegCmd(cmd, help, callback)
#define CC_CMD_OUTPUT cc_CmdOutput
#else
#define CC_CREATE(prompt, ip, port, max) {}
#define CC_DESTROY() {}
#define CC_ISRUN() 0
#define CC_REGCMD(cmd, help, callback) {}
#define CC_CMD_OUTPUT(client, fmt, ) {}
#endif
#endif
#include <memory.h>
#include <string.h>
#include "CCDataType.h"
#include "CCCmd.h"
#include "CCLibrary.h"
/**//* -------------------------------- */
struct _cc_data cc_Global;
DWORD WINAPI cc_TelnetCreate(LPVOID param)
{
return cc_TelnetServer_Create();
}
/**//* Export method */
int cc_InitData(const char* prompt, const char* ip, unsigned short port, int max)
{
memset(&cc_Global, 0, sizeof(cc_Global));
strncpy(cc_Global.telnet.prompt, prompt, sizeof(cc_Global.telnet.prompt));
strncpy(cc_Global.telnet.ip, ip, sizeof(cc_Global.telnet.ip));
cc_Global.telnet.port = port;
cc_Global.telnet.max = max;
cc_Global.telnet.run = 0;
cc_Global.telnet.sock = INVALID_SOCKET;
return cc_RegDefaultCmds();
}
void cc_Destroy()
{
cc_TelnetServer_Final();
}
int cc_Run()
{
DWORD id = 0;
HANDLE thread = CreateThread(NULL, 0, cc_TelnetCreate, NULL, 0, &id);
if(thread == NULL)
return -1;
cc_Global.telnet.run = 1;
return 0;
}
int cc_IsRun()
{
return cc_Global.telnet.run;
}