📄 global.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
//
// global.cpp: implementation of the class.
//
// History:
// 2001.10.27. started by (shencan@263.net)
// History:
// 2001.11.07.
// modified the reading of config file. (zoohoo@163.com)
// support max 10 ftp servers.
// fix IPAddress bug
// modified the program run as service
// History
// 2001.12.31
// Add the private various m_execDir of CGlobal. (zoohoo@163.com)
// History
// 2002.02.05
// Add the config param for DeleteNow & UseNow. (zoohoo@163.com)
//////////////////////////////////////////////////////////////////////////////
#if (_MSC_VER >= 1200)
#pragma warning( disable : 4800 ) // one performance warning off
#pragma warning( disable : 4786 ) // warning about too long debug symbol off
#endif
#include "fstream.h"
//#include "precompile.h"
#include "gk.h"
#include <ptlib.h>
#include <ptlib/sockets.h>
#include "global.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif
static const char * CONFIG_FILE = "intfdb.cfg";
static const char * LOG_FILE = "intfdb.log";
int CGlobal::m_isShutdown = 0;
static char * serviceName = "Intfdb";
static char *keyword[]={ //identify the config file
"debug level", //0
"Log file", //1
"Frequency", //2
"OraConnect", //3
// "Username", //4 //for support many server, discarded
// "Password", //5
"DbServer", //4
"DbAccount", //5
"DbPassword", //6
"DbName", //7
"Rollback", //8
"TotalLogSize", //9
"DeleteNow", //10
"UseNow", //11
"MaxDisconnectTimes", //12
"Port", //13 used by watchdog.
"AreaCode", // 14
// The area of User
// 0:normal (default vlaue)
// 1:Henan
// 2:Shen zhen
"FtpAddress", //15
"LocalDir", //16
"ShareDir", //17
"GetFilePath", //18
"PutFilePath", //19
"AccountsType", //20 add by zjl for shanghai 97 2002-09-11
"UserType", //21
"BackupFilePath", //22 add by zjl for JiangShu 97 2002-11-04
"ServerPort" , //23 add by rmg
NULL
};
int GetConfigPath(char pathBuf[], char serverName[]);
CGlobal * CGlobal::m_instance = NULL;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void CGlobal::Rtrim(char* str, size_t size)
{
for(int i=1;i<=(int)size;i++)
{
if(str[size-i] == ' ')
str[size-i] = 0;
else
break;
}
}
void CGlobal::Ltrim(char* str, size_t size)
{
int j=0;
while(str[0] == ' ' && j<(int)size)
{
for(int i=0;i<(int)size-j;i++)
if(str[i+1] != 0)
str[i] = str[i+1];
else
break;
str[i] = 0;
j++;
}
}
int CGlobal::ReadConfigFile()
{
RTRACE(8, "Enter the function ReadConfigFile");
char pathBuf[BUFSIZE], configBuf[BUFSIZE];
RTRACE(3, "The name of service is " << serviceName);
if(GetConfigPath(pathBuf, serviceName) == 1)
return 0; //can not find ConfigFile path
//get the execDir
strncpy(m_execDir, pathBuf, sizeof(m_execDir));
RTRACE(3, "The Intalled directory is " << m_execDir);
sprintf(configBuf, "%s%s", pathBuf, CONFIG_FILE);
::fstream is(configBuf, ios::in | ios::nocreate );
int j, k;
char line[BUFSIZE], c1[BUFSIZE], *p1;
if(is.bad() || !is.good() ) {
RTRACE(1, "open config file fail!\n");
return(0);
}
for(; !is.eof(); ) {
is.getline( line, BUFSIZE );
Ltrim(line, strlen(line));
if( strlen(line) == 0 || line[0] == '#')
continue;
if( line[0] == '[')
//break;
continue;
for(k=0; !( line[k] == '=' || line[k] == '\n' || line[k] == 0); k++);
if(line[k] != '=')
continue;
STRNCPY(c1, line, k, BUFSIZE-1);
Rtrim(c1, MIN(k, BUFSIZE-1)); //modified by zhj
for(j=0; keyword[j] != NULL; j++ )
if( !_stricmp(keyword[j], c1) )
break;
switch(j) {
//the debuglevel
case 0:
m_debugLevel = atoi(line+k+1);
break;
//the log file name
case 1:
char logFileBuf[BUFSIZE];
sprintf(logFileBuf, "%s%s", pathBuf, m_logFile);
strcpy(m_logFile, logFileBuf);
break;
case 4:
STRCPY(m_dbServer, line+k+1, GBLEN);
Ltrim(m_dbServer, BUFSIZE-1); // modified by zhj
break;
case 5:
STRCPY(m_dbAccount, line+k+1, GBLEN);
Ltrim(m_dbAccount, BUFSIZE-1); // modified by zhj
break;
case 6:
STRCPY(m_dbPassword, line+k+1, GBLEN);
Ltrim(m_dbPassword, BUFSIZE-1); // modified by zhj
break;
case 7:
STRCPY(m_dbName, line+k+1, GBLEN);
Ltrim(m_dbName, BUFSIZE-1); // modified by zhj
break;
case 8:
m_rollback = atoi(line+k+1);
break;
case 9: // total log size
{
int totalLogSize = atoi(line + k + 1);
if(totalLogSize != 0)
m_totalLogSize = totalLogSize;
break;
}
case 10: // delete now
{
m_deleteNow = atoi(line + k + 1);
break;
}
case 11: // use now
{
m_useNow = atoi(line + k + 1);
break;
}
case 12: // disconnectTimes
{
m_maxDisconnectTimes = atoi(line + k + 1);
break;
}
case 13: //default port
{
m_port = atoi(line + k + 1);
break;
}
case 23:
{
m_serverport = atoi(line + k + 1);
break;
}
case 14: // arear code
{
m_areacode = atoi(line + k + 1);
break;
}
case 15: // the ftp server infomation
{
// begin to set backup gatekeeper.
p1 = line+k+1;
// for(int i=0 ; ; i++) {
m_negGkList.SetSize(m_ftpNum + 1);
// IPAddress * add = new IPAddress;
m_iPAddress[m_ftpNum] = new IPAddress;
for(k=0; !(p1[k]==':' || p1[k]==0 ); k++);
STRNCPY(c1, p1, k, BUFSIZE-1);
Ltrim(c1, BUFSIZE-1); // modified by zhj
m_iPAddress[m_ftpNum]->m_ip = inet_addr(c1);
p1 += k+1;
for(k=0; !(p1[k]==':' ||isspace(p1[k]) || p1[k]==0 ); k++);
STRNCPY(c1, p1, k, BUFSIZE-1);
m_iPAddress[m_ftpNum]->m_port = atoi(c1);
m_negGkList.SetAt(m_ftpNum, m_iPAddress[m_ftpNum]);
p1 += k+1;
for(k=0; !(p1[k]==':' || isspace(p1[k]) || p1[k] == 0); k++);
STRNCPY(m_username[m_ftpNum], p1, k, BUFSIZE-1);
Ltrim(m_username[m_ftpNum], BUFSIZE-1); // modified by zhj
p1 += k+1;
for(k=0; !(p1[k]==':' || isspace(p1[k]) || p1[k] == 0); k++);
STRNCPY(m_password[m_ftpNum], p1, k, BUFSIZE-1);
Ltrim(m_password[m_ftpNum], BUFSIZE-1); // modified by zhj
m_ftpNum ++;
// if(p1[k]==0)
// break;
// p1 += k+1;
// }
break;
}
case 16: // Local dir
{
STRCPY(m_localDir, line+k+1, GBLEN);
Ltrim(m_localDir, BUFSIZE-1); // modified by zhj
int dirLen = strlen(m_localDir);
if(m_localDir[dirLen-1] != '\\')
{
m_localDir[dirLen] = '\\';
m_localDir[dirLen + 1] = 0;
}
break;
}
case 18: // GetFilePath
{
STRCPY(m_getFilePath, line+k+1, GBLEN);
Ltrim(m_getFilePath, BUFSIZE-1);
break;
}
case 19: // PutFilePath
{
STRCPY(m_putFilePath, line+k+1, GBLEN);
Ltrim(m_putFilePath, BUFSIZE-1);
break;
}
case 20: // AccountsType
{
STRCPY(m_AccountsType, line+k+1, GBLEN);
Ltrim(m_AccountsType, BUFSIZE-1);
break;
}
case 21: // UserType
{
STRCPY(m_UserType, line+k+1, GBLEN);
Ltrim(m_UserType, BUFSIZE-1);
break;
}
case 22: // BackupFilePath
{
STRCPY(m_backupFilePath, line+k+1, GBLEN);
Ltrim(m_backupFilePath, BUFSIZE-1);
break;
}
case 17: // share dir
{
if(m_ftpNum > 0) // not useful for share dir
break;
STRCPY(m_shareDir, line+k+1, GBLEN);
Ltrim(m_shareDir, BUFSIZE-1); // modified by zhj
break;
}
/* case 8:
STRCPY(m_localDir, line+k+1, GBLEN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -