base
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
/***************************************************************************
|
||||
Anonymous Directory Class ( AnonymousDir.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "AnonymousDir.h"
|
||||
#include "JobData.h"
|
||||
#include "Protocol.h"
|
||||
#include "Configs.h"
|
||||
#include "UtilFn.h"
|
||||
#include "Logger.h"
|
||||
#include "ReportLog.h"
|
||||
|
||||
CAnonymousDir::CAnonymousDir()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CAnonymousDir::~CAnonymousDir()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CAnonymousDir::run( CJobDataMap &jobData )
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
_LOG( LDBG, "Anonymous Directory running...");
|
||||
|
||||
CMyConfig* pConf = CMyConfig::GetInstance();
|
||||
|
||||
if(!pConf)
|
||||
{
|
||||
LOG( LERR, "Config is NULL.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if( rcdb.Init() != 0 )
|
||||
{
|
||||
LOG( LERR, "RCDB Initialization failed.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
bool setAnony = false;
|
||||
|
||||
while(1)
|
||||
{
|
||||
// check info
|
||||
int t = 0;
|
||||
t = ExistInfo(rcdb, jobData);
|
||||
if(t != 1 )
|
||||
{
|
||||
r = t;
|
||||
LOG( LERR, "Base information check error.");
|
||||
break;
|
||||
}
|
||||
|
||||
if( !CheckIdentify(jobData) )
|
||||
{
|
||||
r = JOB_ERR_MISS_PASSWROD;
|
||||
break;
|
||||
}
|
||||
|
||||
int num = atoi(jobData[KEY_REQ_DATA_NUM].c_str());
|
||||
|
||||
vector<string> bodys;
|
||||
StringSplitEx(jobData[KEY_REQ_URI],SDK_DELIMITER,bodys);
|
||||
|
||||
// 2013-03-19 : dadamin
|
||||
// 2개 이상 요청 일 경우 실패로 처리한다.
|
||||
// 해당 기능 수행 중 모호한 상태가 빠질 수 있으므로 에러 리턴함
|
||||
// 2개 중 1개만 성공하고 1개만 실패 했을 때 요청한 client로 응답 보낼 때 부분 에러로
|
||||
// 리턴되어야 하지만, 현재(SDK 관련 로직) 관련 프로토콜상 실패/성공만 체크 하기 때문에
|
||||
// 이런 경우 시스템적으로 불완전한 상태가 될 수 있음
|
||||
|
||||
if(bodys.size() > 1 || num > 1)
|
||||
{
|
||||
r = JOB_ERR_REQ_EXCEED;
|
||||
LOG( LERR, "The number of requests that could not be handled.[REQ CNT:%d].", num);
|
||||
break;
|
||||
}
|
||||
|
||||
string targeturi;
|
||||
if(!bodys.empty())
|
||||
{
|
||||
targeturi = bodys[0];
|
||||
}
|
||||
|
||||
vector<string> anonydirs;
|
||||
if( !rcdb.GetAnonyDir(jobData, targeturi, anonydirs) )
|
||||
{
|
||||
r = JOB_ERR_GET_ANONY_DIR;
|
||||
break;
|
||||
}
|
||||
|
||||
bool sendfhs = false;
|
||||
bool del = false;
|
||||
|
||||
if(IsSubKey(jobData, JOB_ANONY_DIR_SET))
|
||||
{
|
||||
del = false; sendfhs = true;
|
||||
setAnony = anonydirs.size() ? false : true;
|
||||
|
||||
}
|
||||
else if(IsSubKey(jobData, JOB_ANONY_DIR_UNSET))
|
||||
{
|
||||
del = true; sendfhs = true;
|
||||
setAnony = anonydirs.size() ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// JOB_ANONY_DIR_GET
|
||||
sendfhs = false; setAnony = false; del = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(setAnony && !rcdb.BeginTrans())
|
||||
{
|
||||
r = JOB_ERR_RCDB_BEGIN_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
// rcdb
|
||||
if( setAnony && !rcdb.SetAnonyDir(jobData, targeturi, del) )
|
||||
{
|
||||
r = JOB_ERR_SET_ANONY_DIR;
|
||||
break;
|
||||
}
|
||||
|
||||
// 2015.09.10
|
||||
// version 3.5 부터 FHS에서 해당 정보를 주기적으로 갱신 처리함
|
||||
|
||||
rcdb.SetSuccess(true);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(setAnony)
|
||||
{
|
||||
if( !rcdb.EndTrans() )
|
||||
r = JOB_ERR_RCDB_END_TRANS;
|
||||
}
|
||||
|
||||
if(r != 0)
|
||||
{
|
||||
if(!IsSubKey(jobData, JOB_ANONY_DIR_GET))
|
||||
{
|
||||
// pgpool 3.0.9 이전 버전 경우 정적 쿼리 수행 후 동일 세션을 사용 시
|
||||
// pgpool 비정상 종료 현상이 발생하기 때문에 사용한 Pool을 강제 종료 시킴
|
||||
rcdb.ForceClose();
|
||||
}
|
||||
LOG( LERR, "Anonymous Directory(%s) error.[%s@%s:%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str(),
|
||||
jobData[KEY_REQ_URI].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_LOG( LINF, "Anonymous Directory(%s) success.[%s@%s:%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str(),
|
||||
jobData[KEY_REQ_URI].c_str());
|
||||
|
||||
CReportLog rlog;
|
||||
|
||||
if (rlog.Init(pConf->GetAppLogRoot()))
|
||||
{
|
||||
rlog.Write("INF", "[%s] [Anonymous Directory(%s).[%s@%s => %s]]"
|
||||
, PROG_NAME
|
||||
, jobData[KEY_JOBSUB_TYPE].c_str()
|
||||
, jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str()
|
||||
, jobData[KEY_REQ_URI].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
_LOG( LDBG, "Anonymous Directory End.");
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Anonymous Directory Class Header ( AnonymousDir.h)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __ANONYMOUS_DIRECTORY_H__
|
||||
#define __ANONYMOUS_DIRECTORY_H__
|
||||
|
||||
class CJob;
|
||||
|
||||
class CAnonymousDir : public CJob
|
||||
{
|
||||
public:
|
||||
CAnonymousDir();
|
||||
virtual ~CAnonymousDir();
|
||||
|
||||
virtual int run( CJobDataMap &jobData );
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __ANONYMOUS_DIRECTORY_H__
|
||||
@@ -0,0 +1,170 @@
|
||||
/***************************************************************************
|
||||
Argument Parser Class (ArgParser.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/13 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "ArgParser.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
CArgParser::CArgParser(int argc, char** argv)
|
||||
{
|
||||
for (int i=1; i<argc; i++)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "arg i = " << i << "," << argv[i] << endl;
|
||||
#endif // _DEBUG
|
||||
m_args.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CArgParser::~CArgParser()
|
||||
{
|
||||
m_args.clear();
|
||||
}
|
||||
|
||||
void CArgParser::dashes2underscores(const char *input, char *output)
|
||||
{
|
||||
char c = 0;
|
||||
char *o = output;
|
||||
const char *i = input;
|
||||
// first two characters are copied as-is
|
||||
*o = *i++;
|
||||
if (*o++ == '\0')
|
||||
return;
|
||||
*o = *i++;
|
||||
if (*o++ == '\0')
|
||||
return;
|
||||
for (; ((c = *i)); ++i)
|
||||
{
|
||||
if (c == '=')
|
||||
{
|
||||
strcpy(o, i);
|
||||
return;
|
||||
}
|
||||
if (c == '-')
|
||||
*o++ = '_';
|
||||
else
|
||||
*o++ = c;
|
||||
}
|
||||
*o++ = '\0';
|
||||
}
|
||||
|
||||
bool CArgParser::parsewitharg(vector<char*>::iterator &i, std::string *ret, va_list ap)
|
||||
{
|
||||
const char *first = *i;
|
||||
char tmp[strlen(first)+1];
|
||||
dashes2underscores(first, tmp);
|
||||
first = tmp;
|
||||
const char *a;
|
||||
int strlen_a;
|
||||
|
||||
// does this argument match any of the possibilities?
|
||||
while (1)
|
||||
{
|
||||
a = va_arg(ap, char*);
|
||||
if (a == NULL)
|
||||
return false;
|
||||
strlen_a = strlen(a);
|
||||
char a2[strlen_a+1];
|
||||
dashes2underscores(a, a2);
|
||||
if (strncmp(a2, first, strlen(a2)) == 0)
|
||||
{
|
||||
if (first[strlen_a] == '=')
|
||||
{
|
||||
*ret = first + strlen_a + 1;
|
||||
i = m_args.erase(i);
|
||||
return true;
|
||||
}
|
||||
else if (first[strlen_a] == '\0')
|
||||
{
|
||||
// find second part (or not)
|
||||
if (i+1 == m_args.end())
|
||||
{
|
||||
cerr << "[error] Option " << *i << " requires an argument." << std::endl;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
i = m_args.erase(i);
|
||||
*ret = *i;
|
||||
i = m_args.erase(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CArgParser::argparseflag(vector<char*>::iterator &i, ...)
|
||||
{
|
||||
const char *first = *i;
|
||||
char tmp[strlen(first)+1];
|
||||
dashes2underscores(first, tmp);
|
||||
first = tmp;
|
||||
const char *a;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, i);
|
||||
while (1)
|
||||
{
|
||||
a = va_arg(ap, char*);
|
||||
if (a == NULL)
|
||||
{
|
||||
va_end(ap);
|
||||
return false;
|
||||
}
|
||||
|
||||
char a2[strlen(a)+1];
|
||||
dashes2underscores(a, a2);
|
||||
if (strcmp(a2, first) == 0)
|
||||
{
|
||||
i = m_args.erase(i);
|
||||
va_end(ap);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CArgParser::argparsewitharg(vector<char*>::iterator &i, string *ret, ...)
|
||||
{
|
||||
bool r;
|
||||
va_list ap;
|
||||
va_start(ap, ret);
|
||||
r = parsewitharg(i, ret, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CArgParser::checkvalue(const char *c, string *ret/* = NULL*/)
|
||||
{
|
||||
for (vector<char*>::iterator i = m_args.begin(); i != m_args.end(); ++i)
|
||||
{
|
||||
if(ret)
|
||||
{
|
||||
if(argparsewitharg(i,ret, c, (char*)NULL))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(argparseflag(i,c, (char*)NULL))
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/***************************************************************************
|
||||
Argument Parser Class Header ( ArgParser.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/13 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __ARGUMENT_PARSER_H__
|
||||
#define __ARGUMENT_PARSER_H__
|
||||
|
||||
class CArgParser
|
||||
{
|
||||
public:
|
||||
CArgParser(int argc, char** argv);
|
||||
~CArgParser();
|
||||
|
||||
bool argparseflag(vector<char*>::iterator &i, ...);
|
||||
bool argparsewitharg(vector<char*>::iterator &i, string *ret, ...);
|
||||
|
||||
bool checkvalue(const char *c, string *ret = NULL);
|
||||
|
||||
inline bool empty() { return m_args.empty(); }
|
||||
|
||||
protected:
|
||||
void dashes2underscores(const char *input, char *output);
|
||||
bool parsewitharg(vector<char*>::iterator &i, std::string *ret, va_list ap);
|
||||
|
||||
private:
|
||||
vector<char*> m_args;
|
||||
};
|
||||
|
||||
#endif // __ARGUMENT_PARSER_H__
|
||||
@@ -0,0 +1,221 @@
|
||||
/***************************************************************************
|
||||
Client Class (Client.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/19
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/19 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Client.h"
|
||||
#include "Service.h"
|
||||
#include "Parser.h"
|
||||
#include "JobControl.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
CClient::CClient()
|
||||
: m_sfd(-1), m_ssl(NULL), m_parser(NULL)
|
||||
{
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
CClient::CClient(int clientsd, SSL * ssl)
|
||||
: m_sfd(clientsd), m_ssl(ssl), m_parser(NULL)
|
||||
{
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
CClient::~CClient()
|
||||
{
|
||||
if (m_sfd > 0)
|
||||
::close(m_sfd);
|
||||
if(m_ssl)
|
||||
SSL_free(m_ssl);
|
||||
if(m_parser)
|
||||
delete m_parser;
|
||||
}
|
||||
|
||||
void *CClient::_entry_func(void *arg)
|
||||
{
|
||||
ostringstream msg;
|
||||
CClient* pObject = reinterpret_cast<CClient *>(arg);
|
||||
pthread_detach(pthread_self());
|
||||
|
||||
if(pObject->m_ssl)
|
||||
{
|
||||
if( pObject->acceptSSL() != 0)
|
||||
{
|
||||
if(pObject)
|
||||
{
|
||||
delete pObject;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
pObject->SetSocket();
|
||||
|
||||
int nerr = JOB_SUCCESS;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// read header
|
||||
nerr = pObject->ReadHeader();
|
||||
if( nerr != 0 )
|
||||
{
|
||||
nerr = JOB_ERR_READ_HEADER;
|
||||
break;
|
||||
}
|
||||
|
||||
// read body
|
||||
nerr = pObject->ReadBody();
|
||||
if( nerr != 0 )
|
||||
{
|
||||
nerr = JOB_ERR_READ_BODY;
|
||||
break;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
// convert data
|
||||
nerr = pObject->Client2JobData();
|
||||
if( nerr != 0 )
|
||||
break;
|
||||
|
||||
// run job
|
||||
nerr = pObject->AnalyzeJob();
|
||||
break;
|
||||
}
|
||||
|
||||
// send
|
||||
pObject->SendtoClient(nerr);
|
||||
break;
|
||||
}
|
||||
|
||||
if(pObject)
|
||||
{
|
||||
delete pObject;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CClient::acceptSSL()
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
// SSL_accept 블록함수 이므로 해당 로직은 client 쓰레드에서 호출되도록 함.
|
||||
|
||||
// connect the SSL object with a file descriptor
|
||||
// 연결된 소켓과 SSL과의 연결
|
||||
SSL_set_fd (m_ssl, m_sfd);
|
||||
// 가장 중요한 함수, 클라이언트와의 초기 협상과정, 즉 핸드쉐이크 과정을 수행
|
||||
int err = SSL_accept (m_ssl);
|
||||
if( err <= 0 )
|
||||
{
|
||||
msg << "SSL Accept Fail. ["<< ERR_error_string(ERR_get_error(), NULL) <<"]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CClient::Run(CServiceInfo & info)
|
||||
{
|
||||
pthread_t workerthread = 0;
|
||||
|
||||
// Set Parser
|
||||
CParserFactory parserfacotry;
|
||||
m_parser = parserfacotry.CreateParser(info);
|
||||
|
||||
if(m_parser == NULL)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Parser Allocation failed.[" << errno << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// start thread
|
||||
int ret = pthread_create(&workerthread, 0, _entry_func, (void*)this);
|
||||
if (ret != 0)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Client Thread create failed.[" << errno << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sleep(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CClient::SetSocket()
|
||||
{
|
||||
m_parser->SetSocket(m_sfd, m_ssl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CClient::ReadHeader()
|
||||
{
|
||||
int r = 0;
|
||||
r = m_parser->ReadHeader();
|
||||
return r;
|
||||
}
|
||||
|
||||
int CClient::ReadBody()
|
||||
{
|
||||
int r = 0;
|
||||
r = m_parser->ReadBody();
|
||||
return r;
|
||||
}
|
||||
|
||||
int CClient::Client2JobData()
|
||||
{
|
||||
int r = 0;
|
||||
r = m_parser->ConvertJobData((void *)m_job.GetJobData());
|
||||
return r;
|
||||
}
|
||||
|
||||
int CClient::AnalyzeJob()
|
||||
{
|
||||
int r = 0;
|
||||
r = m_job.run();
|
||||
return r;
|
||||
}
|
||||
|
||||
void CClient::SendtoClient(int nCode)
|
||||
{
|
||||
int32_t bodylen = 0;
|
||||
|
||||
if(m_parser == NULL)
|
||||
return;
|
||||
|
||||
bodylen = m_parser->ConvertClient((void *)m_job.GetJobData(), nCode);
|
||||
if(bodylen < 0)
|
||||
{
|
||||
bodylen = 0;
|
||||
nCode = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Body data conversion error.");
|
||||
}
|
||||
|
||||
m_parser->WriteHeader(bodylen);
|
||||
if(bodylen > 0)
|
||||
{
|
||||
m_parser->WriteBoad(bodylen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/***************************************************************************
|
||||
Client Class Header ( Config.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/19
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/19 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CLINET_H__
|
||||
#define __CLINET_H__
|
||||
|
||||
#include "JobControl.h"
|
||||
|
||||
class CServiceInfo;
|
||||
class CParser;
|
||||
|
||||
class CClient
|
||||
{
|
||||
public:
|
||||
CClient();
|
||||
CClient(int clientsd, SSL * ssl);
|
||||
~CClient();
|
||||
|
||||
int Run(CServiceInfo & info);
|
||||
|
||||
int SetSocket();
|
||||
int ReadHeader();
|
||||
int ReadBody();
|
||||
int AnalyzeJob();
|
||||
void SendtoClient(int nCode);
|
||||
|
||||
int Client2JobData();
|
||||
protected:
|
||||
int acceptSSL();
|
||||
|
||||
private:
|
||||
static void *_entry_func(void *arg);
|
||||
|
||||
int m_sfd;
|
||||
SSL* m_ssl;
|
||||
|
||||
CParser * m_parser;
|
||||
CJobControl m_job;
|
||||
};
|
||||
|
||||
#endif // __CLINET_H__
|
||||
@@ -0,0 +1,401 @@
|
||||
/***************************************************************************
|
||||
Config Class (Config.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Configs.h"
|
||||
#include "Config.h"
|
||||
#include "Service.h"
|
||||
|
||||
#define DBPOOL_CNT 2
|
||||
CMyConfig *CMyConfig::m_pInstance = NULL;
|
||||
|
||||
CCommonConfig::CCommonConfig( string szFilename, string szProgramName )
|
||||
: m_szConfigFile(szFilename), m_szProgramName(szProgramName),
|
||||
m_DBPoolCnt(DBPOOL_CNT),
|
||||
m_nLogLevel(0)
|
||||
{
|
||||
}
|
||||
|
||||
CCommonConfig::~CCommonConfig()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCommonConfig::LoadConf()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "CCommonConfig::LoadConf() =>" << endl;
|
||||
#endif // _DEBUG
|
||||
string szValue;
|
||||
|
||||
// Config 처리를 위한 객체 생성
|
||||
Config conf;
|
||||
|
||||
// Config File open
|
||||
if( conf.Open( m_szConfigFile ) == false )
|
||||
{
|
||||
m_szErrMessage = "Config file open failed.[" + m_szConfigFile + "]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// log path
|
||||
if( conf.GetConfig( "COMMON", "DEFAULT_LOG_DIR", szValue ) )
|
||||
{
|
||||
m_szAppLogRoot = szValue;
|
||||
}
|
||||
|
||||
// log level
|
||||
if( conf.GetConfig( "COMMON", "LOG_LEVEL", szValue ) )
|
||||
{
|
||||
m_nLogLevel = atoi( szValue.c_str() );
|
||||
}
|
||||
|
||||
// RC ID
|
||||
if( conf.GetConfig( "COMMON", "RC_ID", szValue ) )
|
||||
{
|
||||
m_szRcid = szValue;
|
||||
}
|
||||
|
||||
// RCDB Access Information
|
||||
if( conf.GetConfig( "COMMON", "RCDB_IP", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbIp = szValue;
|
||||
}
|
||||
if( conf.GetConfig( "COMMON", "RCDB_PORT", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_nRcdbPort = atoi( szValue.c_str() );
|
||||
}
|
||||
if( conf.GetConfig( "COMMON", "RCDB_DB_NAME", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbName = szValue;
|
||||
}
|
||||
if( conf.GetConfig( "COMMON", "RCDB_ACCT", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbAcct = szValue;
|
||||
}
|
||||
if( conf.GetConfig( "COMMON", "RCDB_ACCT_PW", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbAcctPw = szValue;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
PrintValue();
|
||||
#endif // _DEBUG
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCommonConfig::CheckValue()
|
||||
{
|
||||
if(m_szAppLogRoot.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->DEFAULT_LOG_DIR";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_nLogLevel <= 0)
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->LOG_LEVEL";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_szRcid.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RC_ID";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_cDatabaseInfo.m_szRcdbIp.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RCDB_IP";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_cDatabaseInfo.m_nRcdbPort <= 0)
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RCDB_PORT";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_cDatabaseInfo.m_szRcdbName.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RCDB_DB_NAME";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_cDatabaseInfo.m_szRcdbAcct.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RCDB_ACCT";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_cDatabaseInfo.m_szRcdbAcctPw.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + " or COMMON]->RCDB_ACCT_PW";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCommonConfig::PrintValue()
|
||||
{
|
||||
cout << "Log Value : " << m_szAppLogRoot << "," << m_nLogLevel << endl;
|
||||
cout << "RC Value : " << m_szRcid << endl;
|
||||
cout << "RCDB Value : " << m_cDatabaseInfo.m_szRcdbIp << ","
|
||||
<< m_cDatabaseInfo.m_nRcdbPort << "," << m_cDatabaseInfo.m_szRcdbName
|
||||
<< "," << m_cDatabaseInfo.m_szRcdbAcct << "," << m_cDatabaseInfo.m_szRcdbAcctPw << endl;
|
||||
}
|
||||
|
||||
CMyConfig::CMyConfig( string szFilename, string szProgramName)
|
||||
: CCommonConfig(szFilename, szProgramName), m_nFHSCtlTCP(0)
|
||||
{
|
||||
}
|
||||
|
||||
CMyConfig::~CMyConfig()
|
||||
{
|
||||
m_ServiceList.clear();
|
||||
}
|
||||
|
||||
static void StringSplit(string str, string delim, vector<string> &results, bool bUseEmpty /*= false*/)
|
||||
{
|
||||
const string strEmpty("");
|
||||
string::size_type cutAt;
|
||||
|
||||
while( (cutAt = str.find_first_of(delim)) != str.npos )
|
||||
{
|
||||
if(cutAt > 0)
|
||||
{
|
||||
results.push_back(str.substr(0,cutAt));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bUseEmpty && cutAt == 0)
|
||||
results.push_back(strEmpty);
|
||||
}
|
||||
str = str.substr(cutAt+1);
|
||||
}
|
||||
if(str.length() > 0)
|
||||
{
|
||||
results.push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
bool CMyConfig::LoadConf()
|
||||
{
|
||||
CCommonConfig::LoadConf();
|
||||
#ifdef _DEBUG
|
||||
cout << "CMyConfig::LoadConf() =>" << endl;
|
||||
#endif // _DEBUG
|
||||
string szValue;
|
||||
|
||||
// Config 처리를 위한 객체 생성
|
||||
Config conf;
|
||||
|
||||
// Config File open
|
||||
if( conf.Open( m_szConfigFile ) == false )
|
||||
{
|
||||
m_szErrMessage = "Config file open failed.[" + m_szConfigFile + "]";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Config File open
|
||||
if( conf.GetConfig( m_szProgramName, "DEFAULT_LOG_DIR", szValue ) )
|
||||
{
|
||||
m_szAppLogRoot = szValue;
|
||||
}
|
||||
|
||||
// log level
|
||||
if( conf.GetConfig( m_szProgramName, "LOG_LEVEL", szValue ) )
|
||||
{
|
||||
m_nLogLevel = atoi( szValue.c_str() );
|
||||
}
|
||||
|
||||
// RC ID
|
||||
if( conf.GetConfig( m_szProgramName, "RC_ID", szValue ) )
|
||||
{
|
||||
m_szRcid = szValue;
|
||||
}
|
||||
|
||||
// RCDB Access Information
|
||||
if( conf.GetConfig( m_szProgramName, "RCDB_IP", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbIp = szValue;
|
||||
}
|
||||
if( conf.GetConfig( m_szProgramName, "RCDB_PORT", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_nRcdbPort = atoi(szValue.c_str() );
|
||||
}
|
||||
if( conf.GetConfig( m_szProgramName, "RCDB_DB_NAME", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbName = szValue;
|
||||
}
|
||||
if( conf.GetConfig( m_szProgramName, "RCDB_ACCT", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbAcct = szValue;
|
||||
}
|
||||
if( conf.GetConfig( m_szProgramName, "RCDB_ACCT_PW", szValue ) )
|
||||
{
|
||||
m_cDatabaseInfo.m_szRcdbAcctPw = szValue;
|
||||
}
|
||||
|
||||
// Database Connection Poo
|
||||
if (conf.GetConfig(m_szProgramName, "DB_POOL", szValue))
|
||||
{
|
||||
m_DBPoolCnt = atoi(szValue.c_str());
|
||||
}
|
||||
|
||||
// FHS Control Port - TCP
|
||||
if( conf.GetConfig( m_szProgramName, "FHS_CONTROL_TCP_PORT", szValue ) )
|
||||
{
|
||||
m_nFHSCtlTCP = atoi( szValue.c_str() );
|
||||
}
|
||||
|
||||
// RC Domain name
|
||||
if( conf.GetConfig( m_szProgramName, "RC_DOMAIN_NAME", szValue ) )
|
||||
{
|
||||
m_szRCDomain = szValue;
|
||||
}
|
||||
|
||||
// SSL 인증서/ 개인키 파일
|
||||
if( conf.GetConfig( m_szProgramName, "SSL_CERTIFICATE_FILE", szValue ) )
|
||||
{
|
||||
m_szCertFile = szValue;
|
||||
}
|
||||
|
||||
if( conf.GetConfig( m_szProgramName, "SSL_PRIVATEKEY_FILE", szValue ) )
|
||||
{
|
||||
m_szPrivateFile = szValue;
|
||||
}
|
||||
|
||||
// RC Management Service List
|
||||
string k = "=";
|
||||
conf.SetDelimiter(k, "|");
|
||||
vector< string > vec;
|
||||
if(conf.GetConfig(m_szProgramName, "SERVICE_LIST", vec))
|
||||
{
|
||||
for (vector<string>::iterator it = vec.begin() ; it != vec.end(); ++it)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << ' ' << *it << endl;
|
||||
#endif //_DEBUG
|
||||
vector< string > vec2;
|
||||
StringSplit(*it, ",", vec2, true);
|
||||
if(!vec2.empty())
|
||||
{
|
||||
CServiceInfo info;
|
||||
info.m_port = atoi(vec2[0].c_str());
|
||||
|
||||
if (vec2[1].find("XML") != string::npos)
|
||||
info.m_type = CServiceInfo::XML;
|
||||
else if (vec2[1].find("SDK") != string::npos)
|
||||
info.m_type = CServiceInfo::SDK;
|
||||
else if (vec2[1].find("ETC") != string::npos)
|
||||
info.m_type = CServiceInfo::ETC;
|
||||
else if (vec2[1].find("STR") != string::npos)
|
||||
info.m_type = CServiceInfo::STR;
|
||||
else {
|
||||
//nothing
|
||||
}
|
||||
|
||||
info.m_enableSSL = (vec2[2].compare("Y") == 0);
|
||||
|
||||
if(info.m_type != CServiceInfo::UNSET)
|
||||
m_ServiceList.push_back(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
PrintValue();
|
||||
#endif // _DEBUG
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMyConfig::CheckValue()
|
||||
{
|
||||
if( CCommonConfig::CheckValue() )
|
||||
{
|
||||
if( m_nFHSCtlTCP <= 0)
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + "]->FHS_CONTROL_TCP_PORT";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_szRCDomain.empty() )
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + "]->RC_DOMAIN_NAME";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_ServiceList.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + "]->SERVICE_LIST";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_szCertFile.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + "]->SSL_CERTIFICATE_FILE";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_szPrivateFile.empty())
|
||||
{
|
||||
m_szErrMessage = "Config info get failed. [" + m_szProgramName + "]->SSL_PRIVATEKEY_FILE";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMyConfig::PrintValue()
|
||||
{
|
||||
CCommonConfig::PrintValue();
|
||||
|
||||
cout << "SSL Key file :" << m_szCertFile << "," << m_szPrivateFile << endl;
|
||||
cout << "FHSCTL Value : " << m_nFHSCtlTCP << endl;
|
||||
cout << "RC Domain : " << m_szRCDomain << endl;
|
||||
|
||||
cout << "Service info => " << endl;
|
||||
for (list<CServiceInfo>::iterator it= m_ServiceList.begin(); it != m_ServiceList.end(); ++it)
|
||||
{
|
||||
(*it).PrintInfo();
|
||||
}
|
||||
}
|
||||
|
||||
bool CMyConfig::Init( string szProgramName, string szFilename )
|
||||
{
|
||||
if( CMyConfig::m_pInstance == NULL )
|
||||
{
|
||||
CMyConfig::m_pInstance = new CMyConfig(szFilename, szProgramName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMyConfig::Exit()
|
||||
{
|
||||
if( CMyConfig::m_pInstance != NULL )
|
||||
{
|
||||
delete CMyConfig::m_pInstance;
|
||||
CMyConfig::m_pInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CMyConfig* CMyConfig::GetInstance()
|
||||
{
|
||||
return CMyConfig::m_pInstance;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/***************************************************************************
|
||||
Config Class Header ( Config.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __RC_MNGD_CONFIG_H__
|
||||
#define __RC_MNGD_CONFIG_H__
|
||||
|
||||
class CServiceInfo;
|
||||
|
||||
class CDatabaseInfo
|
||||
{
|
||||
public:
|
||||
CDatabaseInfo() : m_nRcdbPort(0) {}
|
||||
~CDatabaseInfo() {}
|
||||
|
||||
public:
|
||||
string m_szRcdbIp;
|
||||
int m_nRcdbPort;
|
||||
string m_szRcdbName;
|
||||
string m_szRcdbAcct;
|
||||
string m_szRcdbAcctPw;
|
||||
|
||||
};
|
||||
|
||||
class CCommonConfig
|
||||
{
|
||||
public:
|
||||
CCommonConfig( string szFilename, string szProgramName );
|
||||
virtual ~CCommonConfig();
|
||||
|
||||
bool LoadConf();
|
||||
bool CheckValue();
|
||||
|
||||
void PrintValue();
|
||||
|
||||
inline const char * GetErrMessage() { return m_szErrMessage.c_str(); }
|
||||
|
||||
inline const char * GetAppLogRoot() { return m_szAppLogRoot.c_str(); }
|
||||
inline int GetAppLogLevel() { return m_nLogLevel; }
|
||||
inline const char * GetRCDomain() { return m_szRCDomain.c_str(); }
|
||||
inline CDatabaseInfo GetDBInfo() { return m_cDatabaseInfo; }
|
||||
inline int GetDBPoolCnt() { return m_DBPoolCnt; }
|
||||
inline const char* GetRCID() { return m_szRcid.c_str(); }
|
||||
|
||||
protected:
|
||||
string m_szConfigFile;
|
||||
string m_szProgramName;
|
||||
|
||||
string m_szErrMessage;
|
||||
|
||||
// RCDB
|
||||
CDatabaseInfo m_cDatabaseInfo;
|
||||
int m_DBPoolCnt;
|
||||
|
||||
// RC
|
||||
string m_szRcid;
|
||||
string m_szRCDomain;
|
||||
|
||||
// log
|
||||
string m_szAppLogRoot;
|
||||
int m_nLogLevel;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class CMyConfig : public CCommonConfig
|
||||
{
|
||||
public:
|
||||
static bool Init( string szProgramName, string szFilename );
|
||||
static void Exit();
|
||||
static CMyConfig* GetInstance();
|
||||
|
||||
private:
|
||||
static CMyConfig* m_pInstance;
|
||||
|
||||
public:
|
||||
bool LoadConf();
|
||||
bool CheckValue();
|
||||
|
||||
void PrintValue();
|
||||
|
||||
inline list<CServiceInfo>& GetServiceList() { return m_ServiceList; }
|
||||
inline int GetFHSControlTCP() { return m_nFHSCtlTCP; }
|
||||
inline const char * GetSSLCertFile() { return m_szCertFile.c_str(); }
|
||||
inline const char * GetSSLPrivateFile() { return m_szPrivateFile.c_str(); }
|
||||
|
||||
protected:
|
||||
CMyConfig( string szFilename, string szProgramName );
|
||||
virtual ~CMyConfig();
|
||||
|
||||
protected:
|
||||
|
||||
// SSL key
|
||||
string m_szCertFile;
|
||||
string m_szPrivateFile;
|
||||
|
||||
// FHS control port
|
||||
int m_nFHSCtlTCP;
|
||||
|
||||
// Service List
|
||||
list<CServiceInfo> m_ServiceList;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // __RC_MNGD_CONFIG_H__
|
||||
@@ -0,0 +1,381 @@
|
||||
/***************************************************************************
|
||||
Convert Base Class ( Convert.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/28
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/28 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "Logger.h"
|
||||
#include "Protocol.h"
|
||||
#include "ConvertServiceOpen.h"
|
||||
#include "ConvertServiceChange.h"
|
||||
#include "ConvertVolumeInfo.h"
|
||||
#include "ConvertAnonymousDir.h"
|
||||
#include "ConvertFileControl.h"
|
||||
|
||||
// Convert base class
|
||||
CConvert::CConvert()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvert::~CConvert()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string CConvert::GetElementValue(const xmlpp::Node* node, string elmentName)
|
||||
{
|
||||
string ret;
|
||||
|
||||
try
|
||||
{
|
||||
xmlpp::Node* n;
|
||||
|
||||
if( elmentName.empty() )
|
||||
{
|
||||
n = const_cast<xmlpp::Node*>(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = node->get_children(elmentName).front();
|
||||
|
||||
if( n == NULL || node->get_children(elmentName).size() == 0 )
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(n);
|
||||
if(nodeElement)
|
||||
{
|
||||
const xmlpp::TextNode* nodetext = nodeElement->get_child_text();
|
||||
if(nodetext)
|
||||
{
|
||||
ret = nodetext->get_content();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CConvert::SetElementValue(xmlpp::Element* elem, string elmentName, string strval)
|
||||
{
|
||||
try
|
||||
{
|
||||
xmlpp::Element* val = elem->add_child(elmentName);
|
||||
val->set_child_text(strval);
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
LOG(LERR,"Exception caught: %s",ex.what() );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string CConvert::GetJobMapValue(void *pDataMap, string key)
|
||||
{
|
||||
string r;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pDataMap);
|
||||
CJobDataMap::iterator it;
|
||||
it = pMap->find(key);
|
||||
if(it != pMap->end())
|
||||
{
|
||||
r = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LDEV2, "Map Data Empty(Key:%s)", key.c_str());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int32_t CConvert::ToClientResult(int nServiceType, int nEnd)
|
||||
{
|
||||
int32_t r = JOB_SUCCESS;
|
||||
|
||||
// rc_tsd와 통신하는 client 호환성을 위한 코드
|
||||
switch(nEnd)
|
||||
{
|
||||
case JOB_SUCCESS:
|
||||
{
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
// rc_tsd와 통신하는 client 호환성을 위한 코드
|
||||
r = SDK_RES_OK_ALL_PASSED;
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
// rc_cchkd와 통신하는 client 호환성을 위한 코드
|
||||
r = ETC_RES_SUCCESS;
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
// rc_mngd에서 정의가 에러 코드 값 그대로 리턴
|
||||
default:
|
||||
r = nEnd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
switch (nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
// rc_tsd와 통신하는 client 호환성을 위한 코드
|
||||
r = SDK_RES_SERVER_ERR;
|
||||
break;
|
||||
default:
|
||||
r = JOB_ERR_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
// Abstract Factory returning a Convert
|
||||
CConvert* CConvertFactory::CreateConvert(string & szBodyType, string & subType)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s]",szBodyType.c_str());
|
||||
CConvert * r = NULL;
|
||||
if( szBodyType.compare(XML_STR_TYPE_OPEN) == 0
|
||||
|| szBodyType.compare(XML_STR_TYPE_MOVE) == 0
|
||||
|| szBodyType.compare(XML_STR_TYPE_OPEN_N_SYNC) == 0
|
||||
|| szBodyType.compare(XML_STR_TYPE_MOVE_N_SYNC) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s|%s]",szBodyType.c_str(),JOB_SERVICE_OPEN);
|
||||
r = new CConvertServiceOpen;
|
||||
}
|
||||
else if( szBodyType.compare(XML_STR_TYPE_CHANGE) == 0 )
|
||||
{
|
||||
if (subType.compare(XML_STR_USER_PASSWORD) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_USER);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_USER_PW);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_STGSIZE) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_STORAGE);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_STORAGE);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_SERVICEDATE) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_PERIOD);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_PERIOD);
|
||||
}
|
||||
else if (subType.compare(XML_STR_TRAFFICLIMIT) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_BAND_VOLUME_LIMIT);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_BAND_VOLUME_LIMIT);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_CUSTOMAUTH) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_EXAUTH_INFO);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_EXAUTH_INFO);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_STATUS) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_STATUS);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_STATUS);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_REPLICA) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_REPLICATION);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_REPLICATION);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_URIIGNORECASE) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_URIIGNORECASEFRORCE) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_SERVICE_CHANGE, XML_STR_SVC_URIIGNORECASEFRORCE);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE_FROCE);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_DELFILEKEEPTIME) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_DEL_FILE_KEEP_TIME);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_DEL_FILE_KEEP_TIME);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_USEDSIZECALCDEPTH) == 0)
|
||||
{
|
||||
_LOG( LDBG, "Convert Factory [%s-%s]",JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_STORAGE_CAL);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_STORAGE_CAL);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_SYNC_LINK) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_SERVICE_CHANGE, JOB_SERVICE_CHG_SYNC);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_SYNC);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_MOVE_REQ) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_SERVICE_CHANGE, JOB_SERVICE_CHG_MOVE_RQE);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_MOVE_RQE);
|
||||
}
|
||||
else if (subType.compare(XML_STR_SVC_MOVE_COPM) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_SERVICE_CHANGE, JOB_SERVICE_CHG_MOVE_COMP);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_MOVE_COMP);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = NULL;
|
||||
}
|
||||
}
|
||||
else if (szBodyType.compare(XML_STR_TYPE_FILE) == 0)
|
||||
{
|
||||
if (subType.compare(XML_STR_FILE_EXIST) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_FILE_CTL, JOB_FILE_CTL_EXIST);
|
||||
r = new CConvertFileControl(JOB_FILE_CTL_EXIST);
|
||||
}
|
||||
else if (subType.compare(XML_STR_FILE_MKDIR) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_FILE_CTL, JOB_FILE_CTL_MKDIR);
|
||||
r = new CConvertFileControl(JOB_FILE_CTL_MKDIR);
|
||||
}
|
||||
else if (subType.compare(XML_STR_FILE_FRONT_10M_MD5) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_FILE_CTL, JOB_FILE_CTL_GET_HASH_10MB);
|
||||
r = new CConvertFileControl(JOB_FILE_CTL_GET_HASH_10MB);
|
||||
}
|
||||
else if (subType.compare(XML_STR_FILE_TOTO_EXTRACT_WITHPLATFORM) == 0)
|
||||
{
|
||||
_LOG(LDBG, "Convert Factory [%s-%s]", JOB_FILE_CTL, JOB_FILE_CTL_TOTO_EXTRACT_WITHPLATFORM);
|
||||
r = new CConvertFileControl(JOB_FILE_CTL_TOTO_EXTRACT_WITHPLATFORM);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = NULL;
|
||||
}
|
||||
|
||||
if ( r == NULL )
|
||||
{
|
||||
LOG(LERR, "Body Type is unknown.[%s]", szBodyType.c_str());
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
CConvert* CConvertFactory::CreateConvert(int nBodyType)
|
||||
{
|
||||
CConvert * r = NULL;
|
||||
switch(nBodyType)
|
||||
{
|
||||
case SDK_REQ_OPEN_SERVICE:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s]",nBodyType,JOB_SERVICE_OPEN);
|
||||
r = new CConvertServiceOpen;
|
||||
break;
|
||||
case SDK_REQ_CHG_USER_INFO:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_USER);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_USER_PW);
|
||||
break;
|
||||
case SDK_REQ_CHG_STORAGE:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_STORAGE);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_STORAGE);
|
||||
break;
|
||||
case SDK_REQ_CHG_BANDWIDTH:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_BANDWIDTH);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_BANDWIDTH);
|
||||
break;
|
||||
case SDK_REQ_CHG_PERIOD:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_PERIOD);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_PERIOD);
|
||||
break;
|
||||
case SDK_REQ_CHG_AUTHINFO:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_SERVICE_CHANGE,JOB_SERVICE_CHG_PRODUCT_AUTHINFO);
|
||||
r = new CConvertServiceChange(JOB_SERVICE_CHG_PRODUCT_AUTHINFO);
|
||||
break;
|
||||
case SDK_REQ_VOLUME_INFO:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s]",nBodyType,JOB_VOLUME_INFO);
|
||||
r = new CConvertVolumeInfo;
|
||||
break;
|
||||
case SDK_REQ_SET_ANONY_DIR:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_ANONY_DIR,JOB_ANONY_DIR_SET);
|
||||
r = new CConvertAnonymosDir(JOB_ANONY_DIR_SET);
|
||||
break;
|
||||
case SDK_REQ_UNSET_ANONY_DIR:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_ANONY_DIR,JOB_ANONY_DIR_UNSET);
|
||||
r = new CConvertAnonymosDir(JOB_ANONY_DIR_UNSET);
|
||||
break;
|
||||
case SDK_REQ_ANONY_DIR:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_ANONY_DIR,JOB_ANONY_DIR_GET);
|
||||
r = new CConvertAnonymosDir(JOB_ANONY_DIR_GET);
|
||||
break;
|
||||
case ETC_REQ_GETFILE_HASH_MD5_10MB:
|
||||
_LOG( LDBG, "Convert Factory [%d|%s-%s]",nBodyType,JOB_FILE_CTL,JOB_FILE_CTL_GET_HASH_10MB);
|
||||
r = new CConvertFileControl(JOB_FILE_CTL_GET_HASH_10MB);
|
||||
break;
|
||||
default:
|
||||
r = NULL;
|
||||
LOG(LERR, "Body Type is unknown.[%d|NULL]",nBodyType);
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
CConvert* CConvertFactory::CreateConvert(xmlpp::Node* node, void *pDataMap/* = NULL*/)
|
||||
{
|
||||
CConvert * r = NULL;
|
||||
|
||||
try
|
||||
{
|
||||
const xmlpp::Element* job = dynamic_cast<const xmlpp::Element*>(node);
|
||||
|
||||
if(job == NULL)
|
||||
{
|
||||
LOG(LERR, "unknown.[job = NULL]");
|
||||
return r;
|
||||
}
|
||||
|
||||
string jobtype = job->get_attribute_value(XML_STR_JOB_TYPE);
|
||||
string subtype = job->get_attribute_value(XML_STR_JOB_TYPE_LIST);
|
||||
|
||||
LOG(LDBG, "XML : %s(%d|%s,%s)", job->get_name().c_str(),
|
||||
(int)job->get_attributes().size(),jobtype.c_str(), subtype.c_str());
|
||||
|
||||
if(pDataMap)
|
||||
{
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pDataMap);
|
||||
pMap->insert(CJobDataPair(KEY_RES_XML_JOB_TYPE, jobtype));
|
||||
pMap->insert(CJobDataPair(KEY_RES_XML_JOB_TYPE_List, subtype));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LWAR, "Map Object is NULL.");
|
||||
}
|
||||
|
||||
r = CreateConvert(jobtype, subtype);
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s" ,ex.what());
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
Convert Header ( Convert.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/28
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/28 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_H__
|
||||
#define __CONVERT_H__
|
||||
|
||||
// XML
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <libxml++/libxml++.h>
|
||||
|
||||
#include "Service.h"
|
||||
#include "JobData.h"
|
||||
#include "Protocol.h"
|
||||
|
||||
///< BYTE ŸÀÔ Á¤ÀÇ
|
||||
#ifndef _BYTE_DEFINED
|
||||
#define _BYTE_DEFINED
|
||||
typedef unsigned char BYTE;
|
||||
#endif // _BYTE_DEFINED
|
||||
|
||||
|
||||
class CConvert
|
||||
{
|
||||
public:
|
||||
CConvert();
|
||||
virtual ~CConvert();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo) = 0;
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen) = 0;
|
||||
int32_t ToClientResult(int nServiceType, int nEnd);
|
||||
protected:
|
||||
string GetElementValue(const xmlpp::Node* node, string elmentName);
|
||||
bool SetElementValue(xmlpp::Element* elem, string elmentName, string strval);
|
||||
string GetJobMapValue(void *pDataMap, string key);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
// Abstract Factory returning a Convert
|
||||
class CConvertFactory
|
||||
{
|
||||
public:
|
||||
CConvert* CreateConvert(int nBodyType);
|
||||
CConvert* CreateConvert(string & szBodyType, string & subKey);
|
||||
CConvert* CreateConvert(xmlpp::Node* node, void *pDataMap = NULL);
|
||||
};
|
||||
|
||||
#endif // __CONVERT_H__
|
||||
@@ -0,0 +1,191 @@
|
||||
/***************************************************************************
|
||||
Convert Anonymous Directory Class ( ConvertAnonymous.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertAnonymousDir.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
CConvertAnonymosDir::CConvertAnonymosDir(string subkey /* = "" */)
|
||||
: m_subkey(subkey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertAnonymosDir::~CConvertAnonymosDir()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertAnonymosDir::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
vector<string> body;
|
||||
StringSplitEx((char *)pFrom,SDK_DELIMITER, body);
|
||||
if (body.size() != 3 )
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Data conversion failed.");
|
||||
break;
|
||||
}
|
||||
|
||||
vector<string> ids;
|
||||
StringSplit(body[0].c_str(),ID_DELIMITER, ids);
|
||||
if (ids.size() != 2 )
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Data conversion failed.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_ANONY_DIR));
|
||||
pMap->insert(CJobDataPair(KEY_JOBSUB_TYPE, m_subkey));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, ids[0]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, ids[1]));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_USER_PASS_CRYPTED, body[1]));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_REG_DATE, body[2]));
|
||||
|
||||
int nAuthRead = body[0].size() + 1 + body[1].size() + 1 + body[2].size();
|
||||
|
||||
LOG(LDBG, "AnonymosDir auth : (%d)%s@%s, %s, %s", nAuthRead,
|
||||
ids[0].c_str(), ids[1].c_str(), body[1].c_str(), body[2].c_str());
|
||||
|
||||
if(m_subkey.compare(JOB_ANONY_DIR_GET) != 0)
|
||||
{
|
||||
|
||||
ostringstream szDataNum;
|
||||
szDataNum << (ntohl(*((int *)((char*)pFrom + nAuthRead))));
|
||||
|
||||
// body start position : auth + data count(4Byte)
|
||||
ostringstream uri;
|
||||
int bodypos = nAuthRead+sizeof(int);
|
||||
char *p = (char*)pFrom + bodypos;
|
||||
int nextpos = 0;
|
||||
for( int i = 0; i < atoi(szDataNum.str().c_str()); ++i)
|
||||
{
|
||||
if ( i > 0 )
|
||||
uri << SDK_DELIMITER;
|
||||
|
||||
LOG(LDBG, "CConvertAnonymosDir::ToJobData Body(%d) %s"
|
||||
, i,(char*) p + nextpos);
|
||||
|
||||
uri << (char*)p + nextpos;
|
||||
|
||||
nextpos += MAX_SIZE_OF_FILENAME; // old
|
||||
}
|
||||
|
||||
LOG(LDBG, "AnonymosDir Data :(%s)%s"
|
||||
, szDataNum.str().c_str(), uri.str().c_str());
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_DATA_NUM, szDataNum.str()));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_URI, uri.str().c_str()));
|
||||
}
|
||||
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertAnonymosDir::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void *r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
if(m_subkey.compare(JOB_ANONY_DIR_GET) == 0)
|
||||
{
|
||||
string ruri = GetJobMapValue(pFrom, KEY_RES_URI);
|
||||
if(ruri.empty())
|
||||
{
|
||||
outlen = 0;
|
||||
LOG(LWAR, "There is no data to be returned.[%s]",JOB_ANONY_DIR_GET);
|
||||
break;
|
||||
}
|
||||
|
||||
vector<string> rdata;
|
||||
char d = SDK_DELIMITER;
|
||||
int len = sizeof(int);
|
||||
|
||||
StringSplitEx(ruri, d, rdata);
|
||||
|
||||
outlen = len + (rdata.size() * MAX_SIZE_OF_FILENAME);
|
||||
BYTE *t = NULL;
|
||||
t = new BYTE[outlen + 1];
|
||||
if(t)
|
||||
{
|
||||
memset(t, 0,outlen + 1);
|
||||
|
||||
*((int *)(t)) = htonl(rdata.size());
|
||||
for (int i = 0; i < (int)rdata.size(); i++)
|
||||
{
|
||||
LOG(LDBG, "ToClientData src(%d) : %s",i, rdata[i].c_str());
|
||||
//snprintf((t + len), MAX_SIZE_OF_FILENAME - 1, "%s", rdata[i].c_str());
|
||||
memcpy((t + len), rdata[i].c_str(), MAX_SIZE_OF_FILENAME);
|
||||
len += MAX_SIZE_OF_FILENAME;
|
||||
}
|
||||
|
||||
t[outlen] = '\0';
|
||||
r = (void*) t;
|
||||
LOG(LDBG, "CConvertAnonymosDir ToClientData(SDK) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation failure.");
|
||||
}
|
||||
}
|
||||
else if(m_subkey.compare(JOB_ANONY_DIR_SET) == 0 || m_subkey.compare(JOB_ANONY_DIR_UNSET) == 0 )
|
||||
{
|
||||
outlen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Convert Anonymous Directory Header ( ConvertAnonymous.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_ANONYMOUS_DIRECTORY_H__
|
||||
#define __CONVERT_ANONYMOUS_DIRECTORY_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertAnonymosDir : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertAnonymosDir(string subkey = "");
|
||||
virtual ~CConvertAnonymosDir();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
};
|
||||
|
||||
#endif // __CONVERT_ANONYMOUS_DIRECTORY_H__
|
||||
@@ -0,0 +1,278 @@
|
||||
/***************************************************************************
|
||||
Convert File Control Class ( ConvertFileControl.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertFileControl.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
#include "Protocol.h"
|
||||
|
||||
#define STR_10MB "10"
|
||||
|
||||
CConvertFileControl::CConvertFileControl(string subkey /* = "" */)
|
||||
: m_subkey(subkey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertFileControl::~CConvertFileControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertFileControl::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::ETC:
|
||||
{
|
||||
if(m_subkey.compare(JOB_FILE_CTL_GET_HASH_10MB) == 0)
|
||||
{
|
||||
EtcReqBodyMD5_10MB *pBody = (EtcReqBodyMD5_10MB*)pFrom;
|
||||
|
||||
vector<string> ids;
|
||||
StringSplit(pBody->userid, ID_DELIMITER, ids);
|
||||
|
||||
if( ids.size() != 2 )
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Unknown type ID.[%s]", pBody->userid);
|
||||
break;
|
||||
}
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, ids[1]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, ids[0]));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_URI, pBody->uri));
|
||||
pMap->insert(CJobDataPair(KEY_GET_CONTENT_LENGTH, pBody->filesize));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_HASH_CHECK_SIZE, STR_10MB)); // 10MB
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_FILE_CTL));
|
||||
pMap->insert(CJobDataPair(KEY_JOBSUB_TYPE, m_subkey));
|
||||
|
||||
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
try
|
||||
{
|
||||
const xmlpp::Node* node = const_cast<xmlpp::Node*>((xmlpp::Node*)pFrom);
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_FILE_CTL));
|
||||
pMap->insert(CJobDataPair(KEY_JOBSUB_TYPE, m_subkey));
|
||||
|
||||
string volumeid = GetElementValue(node, XML_STR_VOLUME_ID);
|
||||
if (volumeid.size())
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_ID, GetElementValue(node, XML_STR_VOLUME_ID)));
|
||||
|
||||
vector<string> ids;
|
||||
StringSplit(volumeid, ID_DELIMITER, ids);
|
||||
if (ids.size() == 2)
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, ids[0]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, ids[1]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_PASSWORD, GetElementValue(node, XML_STR_USER_PASSWORD)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_URI, GetElementValue(node, XML_STR_FILE_URI)));
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertFileControl::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void *r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::ETC:
|
||||
{
|
||||
outlen = 0;
|
||||
if(m_subkey.compare(JOB_FILE_CTL_GET_HASH_10MB) == 0)
|
||||
{
|
||||
string hash = GetJobMapValue(pFrom, KEY_RES_FILE_FRONT_10M_MD5);
|
||||
string uri = GetJobMapValue(pFrom, KEY_REQ_URI);
|
||||
string svcid = GetJobMapValue(pFrom, KEY_SP_SVC_ID);
|
||||
string userid = GetJobMapValue(pFrom, KEY_SP_USER_ID);
|
||||
|
||||
if(!hash.empty())
|
||||
{
|
||||
BYTE * t = NULL;
|
||||
t = new BYTE [sizeof(EtcResBodyMD5_10MB)];
|
||||
if(t)
|
||||
{
|
||||
EtcResBodyMD5_10MB body;
|
||||
snprintf(body.userid, MAX_SIZE_OF_USERID, "%s%s%s",
|
||||
svcid.c_str(), ID_DELIMITER, userid.c_str());
|
||||
strcpy(body.uri, uri.c_str());
|
||||
strcpy(body.hash, hash.c_str());
|
||||
|
||||
outlen = sizeof(body);
|
||||
memcpy(t, &body, outlen);
|
||||
|
||||
r = (void *)t;
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation failure.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
string strtype = XML_STR_JOB_TYPE;
|
||||
string val = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE);
|
||||
string strlist = XML_STR_JOB_TYPE_LIST;
|
||||
string val2 = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE_List);
|
||||
|
||||
string svcid = GetJobMapValue(pFrom, KEY_SP_SVC_ID);
|
||||
string userid = GetJobMapValue(pFrom, KEY_SP_USER_ID);
|
||||
|
||||
string volumeid = svcid + "@" + userid;
|
||||
string rValue = ((nEnd == JOB_SUCCESS) ? JOX_RESULT_OK : JOX_RESULT_FAIL);
|
||||
ostringstream rcode;
|
||||
rcode << nEnd;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "", "");
|
||||
// Response
|
||||
xmlpp::Element* nodeResponses = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeResponses->set_attribute(strtype, val);
|
||||
nodeResponses->set_attribute(strlist, val2);
|
||||
|
||||
SetElementValue(nodeResponses, XML_STR_VOLUME_ID, volumeid);
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT, rValue);
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT_CODE, rcode.str());
|
||||
|
||||
if (nEnd == JOB_SUCCESS)
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_FILE_URI, GetJobMapValue(pFrom, KEY_REQ_URI));
|
||||
|
||||
string f10md5 = GetJobMapValue(pFrom, KEY_RES_FILE_FRONT_10M_MD5);
|
||||
string filelan = GetJobMapValue(pFrom, KEY_RES_FILE_SIZE);
|
||||
string szTotoMd5 = GetJobMapValue(pFrom, KEY_RES_FILE_TOTO_MD5);
|
||||
string szChecksum = GetJobMapValue(pFrom, KEY_RES_FILE_TOTO_CHECKSUM);
|
||||
string szDnaCheckKey = GetJobMapValue(pFrom, KEY_RES_FILE_TOTO_DNAKEY);
|
||||
|
||||
if (val2.find(XML_STR_FILE_MKDIR) == string::npos)
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_FILE_SIZE, filelan);
|
||||
}
|
||||
|
||||
if (val2.find(XML_STR_FILE_FRONT_10M_MD5) != string::npos)
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_FILE_10M_MD5, f10md5);
|
||||
}
|
||||
else if (val2.find(XML_STR_FILE_TOTO_EXTRACT_WITHPLATFORM) != string::npos)
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_TOTO_MD5, szTotoMd5);
|
||||
SetElementValue(nodeResponses, XML_STR_TOTO_FILECHECKSUM, szChecksum);
|
||||
SetElementValue(nodeResponses, XML_STR_TOTO_DNACHKKEY, szDnaCheckKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
// noting
|
||||
}
|
||||
}
|
||||
|
||||
string szData = document.write_to_string();
|
||||
|
||||
BYTE *t = NULL;
|
||||
outlen = szData.size();
|
||||
t = new BYTE[outlen + 1];
|
||||
|
||||
if (t)
|
||||
{
|
||||
memcpy(t, szData.c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*)t;
|
||||
LOG(LDBG, "CConvertServiceChange ToClientData(XML) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Convert File Control Header ( ConvertFileControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_FILE_CONTROL_H__
|
||||
#define __CONVERT_FILE_CONTROL_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertFileControl : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertFileControl(string subkey = "");
|
||||
virtual ~CConvertFileControl();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
};
|
||||
|
||||
#endif // __CONVERT_FILE_CONTROL_H__
|
||||
@@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
Convert Request Service Link Class ( ConvertReqServiceLink.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertReqServiceLink.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
CConvertReqSvcLink::CConvertReqSvcLink(string subkey /* = "" */)
|
||||
: m_subkey(subkey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertReqSvcLink::~CConvertReqSvcLink()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertReqSvcLink::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
//if (m_subkey.compare(JOB_SERVICE_MOVE_REQUEST) == 0 ||
|
||||
// m_subkey.compare(JOB_SERVICE_MOVE_COMPLETE) == 0)
|
||||
//{
|
||||
try
|
||||
{
|
||||
const xmlpp::Node* node = const_cast<xmlpp::Node*>((xmlpp::Node*)pFrom);
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_ID, GetElementValue(node, XML_STR_VOLUME_ID)));
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_SEQ, GetElementValue(node, XML_STR_VOLUME_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_RESP_RESULT, GetElementValue(node, XML_STR_RESULT)));
|
||||
pMap->insert(CJobDataPair(KEY_RESP_RESULT_CODE, GetElementValue(node, XML_STR_RESULT_CODE)));
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// r = JOB_ERR_CONVERT;
|
||||
// LOG(LERR, "Service does not support the conversion.");
|
||||
//}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
string CConvertReqSvcLink::MakeServiceLinkXML(void* pData)
|
||||
{
|
||||
string r;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pData);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "", "");
|
||||
|
||||
xmlpp::Element* nodeRequest = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeRequest->set_attribute(XML_STR_JOB_TYPE, XML_STR_TYPE_CHANGE);
|
||||
nodeRequest->set_attribute(XML_STR_JOB_TYPE_LIST, XML_STR_SVC_SYNC_LINK);
|
||||
|
||||
SetElementValue(nodeRequest, XML_STR_VOLUME_SEQ, GetJobMapValue(pData, KEY_VOLUME_SEQ));
|
||||
SetElementValue(nodeRequest, XML_STR_SELF_RCTS, GetJobMapValue(pData, KEY_SELF_RCTS));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_MASTER_YN, GetJobMapValue(pData, KEY_LINK_MASTER_YN));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_USER_SEQ, GetJobMapValue(pData, KEY_LINK_USER_SEQ));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_SERVICE_SEQ, GetJobMapValue(pData, KEY_LINK_SP_SVC_TRAN_ID));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_RCTS, GetJobMapValue(pData, KEY_LINK_RCTS));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_CODE, GetJobMapValue(pData, KEY_REQ_LINK_CODE));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_ONE_WAY, GetJobMapValue(pData, KEY_REQ_LINK_ONE_WAY));
|
||||
|
||||
r = document.write_to_string();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertReqSvcLink::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void *r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
string szData;
|
||||
|
||||
|
||||
szData = MakeServiceLinkXML(pFrom);
|
||||
|
||||
if (szData.size())
|
||||
{
|
||||
BYTE *t = NULL;
|
||||
outlen = szData.size();
|
||||
t = new BYTE[outlen + 1];
|
||||
|
||||
if (t)
|
||||
{
|
||||
memcpy(t, szData.c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*)t;
|
||||
LOG(LDBG, "CConvertReqSvcMove ToClientData(XML) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
Convert Request Service Link Header ( ConvertReqServiceLink.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_REQ_SERVICE_LINK_H__
|
||||
#define __CONVERT_REQ_SERVICE_LINK_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertReqSvcLink : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertReqSvcLink(string subkey = "");
|
||||
virtual ~CConvertReqSvcLink();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
string MakeServiceLinkXML(void* pData);
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
};
|
||||
|
||||
#endif // __CONVERT_REQ_SERVICE_MOVE_H__
|
||||
@@ -0,0 +1,264 @@
|
||||
/***************************************************************************
|
||||
Convert Request Service Move Class ( ConvertReqServiceMove.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertReqServiceMove.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
CConvertReqSvcMove::CConvertReqSvcMove(string subkey /* = "" */)
|
||||
: m_subkey(subkey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertReqSvcMove::~CConvertReqSvcMove()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertReqSvcMove::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
// move request
|
||||
if (m_subkey.compare(JOB_SERVICE_MOVE_REQUEST) == 0 ||
|
||||
m_subkey.compare(JOB_SERVICE_MOVE_COMPLETE) == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
const xmlpp::Node* node = const_cast<xmlpp::Node*>((xmlpp::Node*)pFrom);
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_ID, GetElementValue(node, XML_STR_VOLUME_ID)));
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_SEQ, GetElementValue(node, XML_STR_VOLUME_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_RESP_RESULT, GetElementValue(node, XML_STR_RESULT)));
|
||||
pMap->insert(CJobDataPair(KEY_RESP_RESULT_CODE, GetElementValue(node, XML_STR_RESULT_CODE)));
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
string CConvertReqSvcMove::MakeMoveRequestXML(void* pData)
|
||||
{
|
||||
string r;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pData);
|
||||
|
||||
const char *_f[] =
|
||||
{
|
||||
// sql << "u.sp_user_id,u.sp_user_seq, u.sp_user_password,";
|
||||
KEY_SP_USER_ID, KEY_SP_USER_SEQ, KEY_SP_USER_PASSWORD,
|
||||
// sql << "s.sp_svc_id, s.sp_svc_tran_id,s.max_str_size,s.sp_svc_begin_date,s.sp_svc_end_date,";
|
||||
KEY_SP_SVC_ID, KEY_SP_SVC_TRAN_ID,
|
||||
KEY_MAX_STR_SIZE, KEY_SP_SVC_BEGIN_DATE, KEY_SP_SVC_END_DATE,
|
||||
// sql << "s.initial_vector,s.private_key,";
|
||||
KEY_INITIAL_VECTOR, KEY_PRIVATE_KEY,
|
||||
// sql << "s.replication_count,s.uri_ignore_case,s.cal_used_depth,s.del_file_keep_time,";
|
||||
KEY_REPLICATION_COUNT, KEY_URI_IGNORE_CASE, KEY_CAL_USED_DEPTH, KEY_DEL_FILE_KEEP_TIME,
|
||||
// sql << "s.validate_sp_session_id_yn,";
|
||||
KEY_VALIDATE_SP_SESSION_ID_YN,
|
||||
// sql << "v.mode,";
|
||||
KEY_REQ_AUTH_MODE,
|
||||
// sql << "v.auth_server,v.auth_path,v.auth_port,v.auth_timeout,";
|
||||
KEY_AUTH_SERVER, KEY_AUTH_PATH, KEY_AUTH_PORT, KEY_AUTH_TIMEOUT,
|
||||
// sql << "v.bill_server,v.bill_path,v.bill_port,v.bill_timeout,";
|
||||
KEY_BILL_SERVER, KEY_BILL_PATH, KEY_BILL_PORT, KEY_BILL_TIMEOUT,
|
||||
// sql << "s.bandwidth_ctrl_yn,";
|
||||
KEY_BANDWIDTH_CTRL_YN,
|
||||
// sql << "b.volume_bandwidth_limit,";
|
||||
KEY_VOLUME_BANDWIDTH_LIMIT,
|
||||
// sql << "r.host_name ";
|
||||
KEY_HOST_NAME,
|
||||
KEY_LINK_MASTER_YN,
|
||||
KEY_LINK_SP_SVC_TRAN_ID, KEY_LINK_RCTS,
|
||||
0
|
||||
};
|
||||
|
||||
const char *o[] =
|
||||
{
|
||||
// sql << "u.sp_user_id,u.sp_user_seq, u.sp_user_password,";
|
||||
XML_STR_USER_ID, XML_STR_USER_SEQ, XML_STR_USER_PASSWORD,
|
||||
// sql << "s.sp_svc_id, s.sp_svc_tran_id,s.max_str_size,s.sp_svc_begin_date,s.sp_svc_end_date,";
|
||||
XML_STR_SVC_ID, XML_STR_SVC_SEQ,
|
||||
XML_STR_SVC_STGSIZE, XML_STR_SVC_START_DATE, XML_STR_SVC_END_DATE,
|
||||
// sql << "s.initial_vector,s.private_key,";
|
||||
XML_STR_SVC_AUTHSTRING, XML_STR_SVC_PRIVATEKEY,
|
||||
// sql << "s.replication_count,s.uri_ignore_case,s.cal_used_depth,s.del_file_keep_time,";
|
||||
XML_STR_SVC_REPLICA, XML_STR_SVC_URIIGNORECASE, XML_STR_SVC_USEDSIZECALCDEPTH, XML_STR_SVC_DELFILEKEEPTIME,
|
||||
// sql << "s.validate_sp_session_id_yn,";
|
||||
XML_STR_CUSTOMAUTH_YN,
|
||||
// sql << "v.mode,";
|
||||
XML_STR_CUSTOMAUTH_MODE,
|
||||
// sql << "v.auth_server,v.auth_path,v.auth_port,v.auth_timeout,";
|
||||
XML_STR_AUTHSERVER, XML_STR_AUTHPATH, XML_STR_AUTHPORT, XML_STR_AUTHTIMEOUT,
|
||||
// sql << "v.bill_server,v.bill_path,v.bill_port,v.bill_timeout,";
|
||||
XML_STR_BILLSERVER, XML_STR_BILLPATH, XML_STR_BILLPORT, XML_STR_BILLTIMEOUT,
|
||||
// sql << "s.bandwidth_ctrl_yn,";
|
||||
XML_STR_TRAFFICLIMIT_YN,
|
||||
// sql << "b.volume_bandwidth_limit,";
|
||||
XML_STR_TRAFFICLIMIT,
|
||||
// sql << "r.host_name ";
|
||||
XML_STR_SVC_DOMAIN,
|
||||
XML_STR_LINK_MASTER_YN,
|
||||
XML_STR_LINK_SERVICE_SEQ, XML_STR_LINK_RCTS,
|
||||
0
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "", "");
|
||||
|
||||
xmlpp::Element* nodeRequest = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeRequest->set_attribute(XML_STR_JOB_TYPE, XML_STR_TYPE_MOVE_N_SYNC);
|
||||
|
||||
for (unsigned int i = 0; _f[i] != NULL; ++i)
|
||||
{
|
||||
SetElementValue(nodeRequest, o[i], GetJobMapValue(pData, _f[i]));
|
||||
}
|
||||
|
||||
r = document.write_to_string();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
string CConvertReqSvcMove::MakeMoveCompleteXML(void* pData)
|
||||
{
|
||||
string r;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pData);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "", "");
|
||||
|
||||
xmlpp::Element* nodeRequest = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeRequest->set_attribute(XML_STR_JOB_TYPE, XML_STR_TYPE_CHANGE);
|
||||
nodeRequest->set_attribute(XML_STR_JOB_TYPE_LIST, XML_STR_SVC_SYNC_LINK);
|
||||
|
||||
SetElementValue(nodeRequest, XML_STR_VOLUME_SEQ, GetJobMapValue(pData, KEY_VOLUME_SEQ));
|
||||
SetElementValue(nodeRequest, XML_STR_SELF_RCTS, GetJobMapValue(pData, KEY_SELF_RCTS));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_MASTER_YN, GetJobMapValue(pData, KEY_LINK_MASTER_YN));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_USER_SEQ, GetJobMapValue(pData, KEY_LINK_USER_SEQ));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_SERVICE_SEQ, GetJobMapValue(pData, KEY_LINK_SP_SVC_TRAN_ID));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_RCTS, GetJobMapValue(pData, KEY_LINK_RCTS));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_CODE, GetJobMapValue(pData, KEY_REQ_LINK_CODE));
|
||||
SetElementValue(nodeRequest, XML_STR_LINK_ONE_WAY, GetJobMapValue(pData, KEY_REQ_LINK_ONE_WAY));
|
||||
|
||||
r = document.write_to_string();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
LOG(LERR, "Exception caught: %s", ex.what());
|
||||
}
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertReqSvcMove::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void *r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
string szData;
|
||||
|
||||
|
||||
if (m_subkey.compare(JOB_SERVICE_MOVE_REQUEST) == 0)
|
||||
{
|
||||
szData = MakeMoveRequestXML(pFrom);
|
||||
}
|
||||
else if (m_subkey.compare(JOB_SERVICE_MOVE_COMPLETE) == 0)
|
||||
{
|
||||
szData = MakeMoveCompleteXML(pFrom);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
}
|
||||
|
||||
if (szData.size())
|
||||
{
|
||||
BYTE *t = NULL;
|
||||
outlen = szData.size();
|
||||
t = new BYTE[outlen + 1];
|
||||
|
||||
if (t)
|
||||
{
|
||||
memcpy(t, szData.c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*)t;
|
||||
LOG(LDBG, "CConvertReqSvcMove ToClientData(XML) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/***************************************************************************
|
||||
Convert Request Service Move Header ( ConvertReqServiceMove.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/18
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/18 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_REQ_SERVICE_MOVE_H__
|
||||
#define __CONVERT_REQ_SERVICE_MOVE_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertReqSvcMove : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertReqSvcMove(string subkey = "");
|
||||
virtual ~CConvertReqSvcMove();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
string MakeMoveRequestXML(void* pData);
|
||||
string MakeMoveCompleteXML(void* pData);
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
};
|
||||
|
||||
#endif // __CONVERT_REQ_SERVICE_MOVE_H__
|
||||
@@ -0,0 +1,259 @@
|
||||
/***************************************************************************
|
||||
Convert Service Change Class ( ConvertServiceChange.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertServiceChange.h"
|
||||
#include "UtilFn.h"
|
||||
#include "Logger.h"
|
||||
|
||||
CConvertServiceChange::CConvertServiceChange(string subkey /* = "" */)
|
||||
: m_subkey(subkey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertServiceChange::~CConvertServiceChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertServiceChange::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
try
|
||||
{
|
||||
const xmlpp::Node* node = const_cast<xmlpp::Node*>((xmlpp::Node*)pFrom);
|
||||
|
||||
string volumeid = GetElementValue(node, XML_STR_VOLUME_ID);
|
||||
string volumeseq = GetElementValue(node, XML_STR_VOLUME_SEQ);
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_SERVICE_CHANGE));
|
||||
pMap->insert(CJobDataPair(KEY_JOBSUB_TYPE, m_subkey));
|
||||
|
||||
if(volumeid.size())
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_ID, GetElementValue(node, XML_STR_VOLUME_ID)));
|
||||
vector<string> ids;
|
||||
StringSplit(volumeid, ID_DELIMITER, ids);
|
||||
if( ids.size() == 2 )
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, ids[0]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID,ids[1]));
|
||||
}
|
||||
}
|
||||
else if (volumeseq.size())
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_SEQ, GetElementValue(node, XML_STR_VOLUME_SEQ)));
|
||||
vector<string> ids;
|
||||
StringSplit(volumeseq, ID_DELIMITER, ids);
|
||||
if (ids.size() == 2)
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_TRAN_ID, ids[0]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_SEQ, ids[1]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, GetElementValue(node, XML_STR_USER_ID)));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_SEQ, GetElementValue(node, XML_STR_USER_SEQ)));
|
||||
}
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_PASSWORD, GetElementValue(node, XML_STR_USER_PASSWORD)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, GetElementValue(node, XML_STR_SVC_STGSIZE)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, GetElementValue(node, XML_STR_SVC_START_DATE)));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, GetElementValue(node, XML_STR_SVC_END_DATE)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_BANDWIDTH_CTRL_YN, GetElementValue(node, XML_STR_TRAFFICLIMIT_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_BANDWIDTH_LIMIT, GetElementValue(node, XML_STR_TRAFFICLIMIT)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_VALIDATE_SP_SESSION_ID_YN, GetElementValue(node, XML_STR_CUSTOMAUTH_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_AUTH_MODE, GetElementValue(node, XML_STR_CUSTOMAUTH_MODE)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_SERVER, GetElementValue(node, XML_STR_AUTHSERVER)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_PATH, GetElementValue(node, XML_STR_AUTHPATH)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_PORT, GetElementValue(node, XML_STR_AUTHPORT)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_TIMEOUT, GetElementValue(node, XML_STR_AUTHTIMEOUT)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_SERVER, GetElementValue(node, XML_STR_BILLSERVER)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_PATH, GetElementValue(node, XML_STR_BILLPATH)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_PORT, GetElementValue(node, XML_STR_BILLPORT)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_TIMEOUT, GetElementValue(node, XML_STR_BILLTIMEOUT)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REPLICATION_COUNT, GetElementValue(node, XML_STR_SVC_REPLICA)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_URI_IGNORE_CASE, GetElementValue(node, XML_STR_SVC_URIIGNORECASE)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_DEL_FILE_KEEP_TIME, GetElementValue(node, XML_STR_SVC_DELFILEKEEPTIME)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_CAL_USED_DEPTH, GetElementValue(node, XML_STR_SVC_USEDSIZECALCDEPTH)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_SVC_STATUS, GetElementValue(node, XML_STR_STATUSCODE)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_LINK_MASTER_YN, GetElementValue(node, XML_STR_LINK_MASTER_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_SELF_RCTS, GetElementValue(node, XML_STR_SELF_RCTS)));
|
||||
pMap->insert(CJobDataPair(KEY_LINK_USER_SEQ, GetElementValue(node, XML_STR_LINK_USER_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_LINK_SP_SVC_TRAN_ID, GetElementValue(node, XML_STR_LINK_SERVICE_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_LINK_RCTS, GetElementValue(node, XML_STR_LINK_RCTS)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_LINK_CODE, GetElementValue(node, XML_STR_LINK_CODE)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_LINK_ONE_WAY, GetElementValue(node, XML_STR_LINK_ONE_WAY)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_MOVE_NOW_RCTS, GetElementValue(node, XML_STR_MOVE_NOW_RCTS)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_MOVE_NEW_RCTS, GetElementValue(node, XML_STR_MOVE_NEW_RCTS)));
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
LOG(LERR,"Exception caught: %s" , ex.what() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
SDKReqBodySpInfo *pBody = (SDKReqBodySpInfo*)pFrom;
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_SERVICE_CHANGE));
|
||||
pMap->insert(CJobDataPair(KEY_JOBSUB_TYPE, m_subkey));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_SEQ, pBody->szSpUserSeq));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, pBody->szSpUserId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_PASSWORD, pBody->szSpUserPassword));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_TRAN_ID, pBody->szSpSvcTranId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, pBody->szSpSvcId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_BEGIN_DATE, pBody->szSpSvcBeginDate));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_END_DATE, pBody->szSpSvcEndDate));
|
||||
pMap->insert(CJobDataPair(KEY_INITIAL_VECTOR, pBody->szInitialVector));
|
||||
pMap->insert(CJobDataPair(KEY_PRIVATE_KEY, pBody->szPrivateKey));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_BANDWIDTH, pBody->szMaxBandwidth));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, pBody->szVolQuota));
|
||||
pBody->szSyncYN;
|
||||
r = pMap->size();
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertServiceChange::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void *r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
string strtype = XML_STR_JOB_TYPE;
|
||||
string val = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE);
|
||||
string strlist = XML_STR_JOB_TYPE_LIST;
|
||||
string val2 = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE_List);
|
||||
|
||||
if(val.empty() && val2.empty())
|
||||
{
|
||||
LOG(LERR, "Unknown job");
|
||||
break;
|
||||
}
|
||||
|
||||
string svcid = GetJobMapValue(pFrom, KEY_SP_SVC_ID);
|
||||
string userid = GetJobMapValue(pFrom, KEY_SP_USER_ID);
|
||||
|
||||
string volumeid = GetJobMapValue(pFrom, KEY_VOLUME_ID);
|
||||
string volumeseq = GetJobMapValue(pFrom, KEY_VOLUME_SEQ);
|
||||
|
||||
if (volumeid.empty())
|
||||
{
|
||||
volumeid = svcid + "@" + userid;
|
||||
}
|
||||
|
||||
string rValue = ((nEnd == JOB_SUCCESS) ? JOX_RESULT_OK : JOX_RESULT_FAIL);
|
||||
ostringstream rcode;
|
||||
rcode << nEnd;
|
||||
|
||||
try
|
||||
{
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "","");
|
||||
// Response
|
||||
xmlpp::Element* nodeResponses = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeResponses->set_attribute(strtype, val);
|
||||
nodeResponses->set_attribute(strlist, val2);
|
||||
if (volumeseq.size())
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_VOLUME_SEQ, volumeseq);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetElementValue(nodeResponses, XML_STR_VOLUME_ID, volumeid);
|
||||
}
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT, rValue);
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT_CODE, rcode.str());
|
||||
|
||||
string szData = document.write_to_string();
|
||||
|
||||
BYTE *t = NULL;
|
||||
outlen= szData.size();
|
||||
t = new BYTE[outlen + 1];
|
||||
|
||||
if(t)
|
||||
{
|
||||
memcpy(t, szData.c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*) t;
|
||||
LOG(LDBG, "CConvertServiceChange ToClientData(XML) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR,"Exception caught: %s" , ex.what() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
outlen = 0;
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Convert Service Change Header ( ConvertServiceChange.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_SERVICE_CHANGE_H__
|
||||
#define __CONVERT_SERVICE_CHANGE_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertServiceChange : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertServiceChange(string subkey = "");
|
||||
virtual ~CConvertServiceChange();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
};
|
||||
|
||||
#endif // __CONVERT_SERVICE_CHANGE_H__
|
||||
@@ -0,0 +1,205 @@
|
||||
/***************************************************************************
|
||||
Convert Service Open Class ( ConvertServiceOpen.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/28
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/28 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertServiceOpen.h"
|
||||
#include "Logger.h"
|
||||
|
||||
CConvertServiceOpen::CConvertServiceOpen()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertServiceOpen::~CConvertServiceOpen()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertServiceOpen::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_SERVICE_OPEN));
|
||||
try
|
||||
{
|
||||
const xmlpp::Node* node = const_cast<xmlpp::Node*>((xmlpp::Node*)pFrom);
|
||||
|
||||
string svcid = GetElementValue(node, XML_STR_SVC_ID);
|
||||
|
||||
// value_list
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, GetElementValue(node, XML_STR_USER_ID)));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_SEQ, GetElementValue(node, XML_STR_USER_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_PASSWORD, GetElementValue(node, XML_STR_USER_PASSWORD)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, svcid));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_TRAN_ID, GetElementValue(node, XML_STR_SVC_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, GetElementValue(node, XML_STR_SVC_STGSIZE)));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_BEGIN_DATE, GetElementValue(node, XML_STR_SVC_START_DATE)));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_END_DATE, GetElementValue(node, XML_STR_SVC_END_DATE)));
|
||||
pMap->insert(CJobDataPair(KEY_INITIAL_VECTOR, GetElementValue(node, XML_STR_SVC_AUTHSTRING)));
|
||||
pMap->insert(CJobDataPair(KEY_PRIVATE_KEY, GetElementValue(node, XML_STR_SVC_PRIVATEKEY)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REPLICATION_COUNT, GetElementValue(node, XML_STR_SVC_REPLICA)));
|
||||
pMap->insert(CJobDataPair(KEY_URI_IGNORE_CASE, GetElementValue(node, XML_STR_SVC_URIIGNORECASE)));
|
||||
pMap->insert(CJobDataPair(KEY_DEL_FILE_KEEP_TIME, GetElementValue(node, XML_STR_SVC_DELFILEKEEPTIME)));
|
||||
pMap->insert(CJobDataPair(KEY_CAL_USED_DEPTH, GetElementValue(node, XML_STR_SVC_USEDSIZECALCDEPTH)));
|
||||
|
||||
string svcDomain = GetElementValue(node, XML_STR_SVC_DOMAIN);
|
||||
if(!svcDomain.empty())
|
||||
pMap->insert(CJobDataPair(KEY_HOST_NAME, svcDomain));
|
||||
|
||||
// 2014.11.03 rc_syncd 설정을 위한 설정
|
||||
pMap->insert(CJobDataPair(KEY_LINK_MASTER_YN, GetElementValue(node, XML_STR_LINK_MASTER_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_LINK_SP_SVC_TRAN_ID, GetElementValue(node, XML_STR_LINK_SERVICE_SEQ)));
|
||||
pMap->insert(CJobDataPair(KEY_LINK_RCTS, GetElementValue(node, XML_STR_LINK_RCTS)));
|
||||
|
||||
// 2014.08.07
|
||||
// 추가 속성에 대한 값을 받을 수 있게 처리함
|
||||
pMap->insert(CJobDataPair(KEY_BANDWIDTH_CTRL_YN, GetElementValue(node, XML_STR_TRAFFICLIMIT_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_VOLUME_BANDWIDTH_LIMIT, GetElementValue(node, XML_STR_TRAFFICLIMIT)));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_VALIDATE_SP_SESSION_ID_YN, GetElementValue(node, XML_STR_CUSTOMAUTH_YN)));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_AUTH_MODE, GetElementValue(node, XML_STR_CUSTOMAUTH_MODE)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_SERVER, GetElementValue(node, XML_STR_AUTHSERVER)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_PATH, GetElementValue(node, XML_STR_AUTHPATH)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_PORT, GetElementValue(node, XML_STR_AUTHPORT)));
|
||||
pMap->insert(CJobDataPair(KEY_AUTH_TIMEOUT, GetElementValue(node, XML_STR_AUTHTIMEOUT)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_SERVER, GetElementValue(node, XML_STR_BILLSERVER)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_PATH, GetElementValue(node, XML_STR_BILLPATH)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_PORT, GetElementValue(node, XML_STR_BILLPORT)));
|
||||
pMap->insert(CJobDataPair(KEY_BILL_TIMEOUT, GetElementValue(node, XML_STR_BILLTIMEOUT)));
|
||||
|
||||
r = pMap->size();
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
LOG(LERR,"Exception caught: %s" , ex.what() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
SDKReqBodySpInfo *pBody = (SDKReqBodySpInfo*)pFrom;
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_SERVICE_OPEN));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_SEQ, pBody->szSpUserSeq));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, pBody->szSpUserId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_PASSWORD, pBody->szSpUserPassword));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_TRAN_ID, pBody->szSpSvcTranId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, pBody->szSpSvcId));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_BEGIN_DATE, pBody->szSpSvcBeginDate));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_END_DATE, pBody->szSpSvcEndDate));
|
||||
pMap->insert(CJobDataPair(KEY_INITIAL_VECTOR, pBody->szInitialVector));
|
||||
pMap->insert(CJobDataPair(KEY_PRIVATE_KEY, pBody->szPrivateKey));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_BANDWIDTH, pBody->szMaxBandwidth));
|
||||
pMap->insert(CJobDataPair(KEY_MAX_STR_SIZE, pBody->szVolQuota));
|
||||
pBody->szSyncYN;
|
||||
r = pMap->size();
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertServiceOpen::ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen)
|
||||
{
|
||||
void * r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
{
|
||||
string strtype = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE);
|
||||
string strlist = GetJobMapValue(pFrom, KEY_RES_XML_JOB_TYPE_List);
|
||||
|
||||
string svcid = GetJobMapValue(pFrom, KEY_SP_SVC_ID);
|
||||
string userid = GetJobMapValue(pFrom, KEY_SP_USER_ID);
|
||||
|
||||
string volumeid = svcid + "@" + userid;
|
||||
string rValue = ((nEnd == JOB_SUCCESS) ? JOX_RESULT_OK : JOX_RESULT_FAIL);
|
||||
ostringstream rcode;
|
||||
rcode << nEnd;
|
||||
|
||||
try
|
||||
{
|
||||
xmlpp::Document document;
|
||||
// root
|
||||
xmlpp::Element* nodeRoot = document.create_root_node(XML_STR_ROOT, "", "");
|
||||
// Response
|
||||
xmlpp::Element* nodeResponses = nodeRoot->add_child(XML_STR_JOB);
|
||||
|
||||
nodeResponses->set_attribute(XML_STR_JOB_TYPE, strtype);
|
||||
if(!strlist.empty())
|
||||
nodeResponses->set_attribute(XML_STR_JOB_TYPE_LIST, strlist);
|
||||
SetElementValue(nodeResponses, XML_STR_VOLUME_ID, volumeid);
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT, rValue);
|
||||
SetElementValue(nodeResponses, XML_STR_RESULT_CODE, rcode.str());
|
||||
|
||||
string szData = document.write_to_string();
|
||||
|
||||
BYTE *t = NULL;
|
||||
outlen= szData.size();
|
||||
t = new BYTE[outlen + 1];
|
||||
|
||||
if(t)
|
||||
{
|
||||
memcpy(t, szData.c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*) t;
|
||||
LOG(LDBG, "CConvertServiceOpen ToClientData(XML) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR,"Exception caught: %s" , ex.what() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
outlen = 0;
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
Convert Service Open Header ( ConvertServiceOpen.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/28
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/28 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_SERVICE_OPNE_H__
|
||||
#define __CONVERT_SERVICE_OPNE_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertServiceOpen : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertServiceOpen();
|
||||
virtual ~CConvertServiceOpen();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nEnd, void* pFrom, int & outlen);
|
||||
protected:
|
||||
|
||||
private:
|
||||
string m_subkey;
|
||||
|
||||
};
|
||||
|
||||
#endif // __CONVERT_SERVICE_OPNE_H__
|
||||
@@ -0,0 +1,136 @@
|
||||
/***************************************************************************
|
||||
Convert Volume Information Class ( ConvertVolumeInfo.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertVolumeInfo.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
CConvertVolumeInfo::CConvertVolumeInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CConvertVolumeInfo::~CConvertVolumeInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CConvertVolumeInfo::ToJobData(int nServiceType, void* pFrom, void *pTo)
|
||||
{
|
||||
int r = 0;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pTo);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
vector<string> body;
|
||||
StringSplitEx((char *)pFrom,SDK_DELIMITER, body);
|
||||
if (body.size() != 3 )
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Data conversion failed.");
|
||||
break;
|
||||
}
|
||||
|
||||
vector<string> ids;
|
||||
StringSplit(body[0].c_str(), ID_DELIMITER, ids);
|
||||
if (ids.size() != 2 )
|
||||
{
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Data conversion failed.");
|
||||
break;
|
||||
}
|
||||
|
||||
LOG(LDBG, "VolumeInfo Body : %s@%s, %s, %s"
|
||||
,ids[0].c_str(), ids[1].c_str(), body[1].c_str(), body[2].c_str() );
|
||||
|
||||
//SDKReqBodySpInfo *pBody = (SDKReqBodySpInfo*)pFrom;
|
||||
pMap->insert(CJobDataPair(KEY_JOB_TYPE, JOB_VOLUME_INFO));
|
||||
pMap->insert(CJobDataPair(KEY_SP_SVC_ID, ids[0]));
|
||||
pMap->insert(CJobDataPair(KEY_SP_USER_ID, ids[1]));
|
||||
|
||||
pMap->insert(CJobDataPair(KEY_REQ_USER_PASS_CRYPTED, body[1]));
|
||||
pMap->insert(CJobDataPair(KEY_REQ_REG_DATE, body[2]));
|
||||
r = pMap->size();
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
r = JOB_ERR_CONVERT;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void* CConvertVolumeInfo::ToClientData(int nServiceType, int nCode, void* pFrom, int & outlen)
|
||||
{
|
||||
void* r = NULL;
|
||||
CJobDataMap *pMap = reinterpret_cast<CJobDataMap *>(pFrom);
|
||||
|
||||
switch(nServiceType)
|
||||
{
|
||||
case CServiceInfo::SDK:
|
||||
{
|
||||
string maxstorage = GetJobMapValue(pFrom, KEY_MAX_STR_SIZE);
|
||||
string used = GetJobMapValue(pFrom, KEY_DIR_USED);
|
||||
|
||||
if(maxstorage.empty() && used.empty() )
|
||||
{
|
||||
outlen = 0;
|
||||
LOG(LWAR, "There is no data to be returned.[%s/%s]",
|
||||
used.c_str(),maxstorage.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
char d = SDK_DELIMITER;
|
||||
ostringstream outdata;
|
||||
outdata << maxstorage << d << used;
|
||||
|
||||
BYTE *t = NULL;
|
||||
outlen= outdata.str().size();
|
||||
t = new BYTE[outlen + 1];
|
||||
if(t)
|
||||
{
|
||||
memcpy(t, outdata.str().c_str(), outlen);
|
||||
t[outlen] = '\0';
|
||||
r = (void*) t;
|
||||
LOG(LDBG, "CConvertVolumeInfo ToClientData(SDK) : %s, %d", (char *)r, outlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
outlen = -1;
|
||||
LOG(LERR, "Memory allocation error.[%d]", errno);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CServiceInfo::XML:
|
||||
case CServiceInfo::ETC:
|
||||
default:
|
||||
outlen = -1;
|
||||
LOG(LERR, "Service does not support the conversion.");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Convert Volume Information Header ( ConvertVolumeInfo.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __CONVERT_VOLUME_INFORMATION_H__
|
||||
#define __CONVERT_VOLUME_INFORMATION_H__
|
||||
|
||||
class CConvert;
|
||||
|
||||
class CConvertVolumeInfo : public CConvert
|
||||
{
|
||||
public:
|
||||
CConvertVolumeInfo();
|
||||
virtual ~CConvertVolumeInfo();
|
||||
|
||||
virtual int ToJobData(int nServiceType, void* pFrom, void *pTo);
|
||||
virtual void *ToClientData(int nServiceType, int nCode, void* pFrom, int & outlen);
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // __CONVERT_VOLUME_INFORMATION_H__
|
||||
@@ -0,0 +1,185 @@
|
||||
/***************************************************************************
|
||||
Database Class
|
||||
-----------------------------------------
|
||||
begin : 2010/03/09
|
||||
copyright : (C) 2010 SolutionBox Inc.
|
||||
author : Service 1 Team
|
||||
email : svc1@solbox.com
|
||||
version : 1.0
|
||||
|
||||
CopyRight(C) 2010 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#include "Database.h"
|
||||
#include "Logger.h"
|
||||
|
||||
|
||||
DataBase::~DataBase()
|
||||
{
|
||||
if(m_PGconn != NULL) {
|
||||
PgCloseDB();
|
||||
}
|
||||
}
|
||||
|
||||
PGconn *DataBase::PgOpenDB(string &strHost, int Port, string &strDBName, string &strAcct, string &strPasswd, int timeout)
|
||||
{
|
||||
ostringstream conninfo;
|
||||
|
||||
conninfo << "host=" << strHost << " port=" << Port << " dbname=" << strDBName <<
|
||||
" user=" << strAcct << " password=" << strPasswd << " connect_timeout=" << timeout
|
||||
<< " application_name=" << PROG_NAME;
|
||||
#ifdef _USE_LIBPQ_KEEPALIVE
|
||||
// This option is supported by at least 9.1.2. and Currently supports Linux systems.
|
||||
conninfo <<" keepalives=1";
|
||||
#endif // _USE_LIBPQ_KEEPALIVE
|
||||
//m_PGconn = PQsetdbLogin(strHost.c_str(), szPort, NULL, NULL, strDBName.c_str(), strAcct.c_str(), strPasswd.c_str());
|
||||
m_PGconn = PQconnectdb(conninfo.str().c_str());
|
||||
if(PQstatus(m_PGconn) == CONNECTION_BAD) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_PGconn;
|
||||
}
|
||||
|
||||
PGconn *DataBase::PgOpenDB(const char *pszDBName)
|
||||
{
|
||||
m_PGconn = PQsetdb(NULL, NULL, NULL, NULL, pszDBName);
|
||||
if(PQstatus(m_PGconn) == CONNECTION_BAD) {
|
||||
return NULL;
|
||||
}
|
||||
return m_PGconn;
|
||||
}
|
||||
|
||||
void DataBase::PgCloseDB()
|
||||
{
|
||||
if(m_PGconn != NULL)
|
||||
{
|
||||
PQfinish(m_PGconn);
|
||||
m_PGconn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int DataBase::PgResult(CFLAG flag)
|
||||
{
|
||||
int fRet = 0;
|
||||
int Result;
|
||||
|
||||
Result = PQresultStatus(m_pRes);
|
||||
switch(Result) {
|
||||
case PGRES_EMPTY_QUERY :
|
||||
fRet = -1;
|
||||
break;
|
||||
case PGRES_BAD_RESPONSE :
|
||||
fRet = -2;
|
||||
break;
|
||||
case PGRES_NONFATAL_ERROR :
|
||||
fRet = -3;
|
||||
break;
|
||||
case PGRES_FATAL_ERROR :
|
||||
fRet = -4;
|
||||
break;
|
||||
case PGRES_TUPLES_OK :
|
||||
fRet = 1;
|
||||
break;
|
||||
case PGRES_COMMAND_OK :
|
||||
fRet = 2;
|
||||
break;
|
||||
}
|
||||
if(fRet < 0) {
|
||||
m_ErrorMessage = PQresultErrorMessage(m_pRes);
|
||||
}
|
||||
m_ResultCode = Result;
|
||||
if(flag == CLEAR && m_pRes) {
|
||||
PQclear(m_pRes);
|
||||
m_pRes = NULL;
|
||||
}
|
||||
return fRet;
|
||||
}
|
||||
|
||||
string &DataBase::GetErrorMessage()
|
||||
{
|
||||
return m_ErrorMessage;
|
||||
}
|
||||
|
||||
int DataBase::GetCmdTuples()
|
||||
{
|
||||
//fprintf(stderr, "DataBase::GetCmdTuples PQcmdTuples %s\n", PQcmdTuples(m_pRes));
|
||||
return (int)atoi(PQcmdTuples(m_pRes));
|
||||
}
|
||||
|
||||
int DataBase::GetNoTuples()
|
||||
{
|
||||
return PQntuples(m_pRes);
|
||||
}
|
||||
|
||||
int DataBase::GetNoFields()
|
||||
{
|
||||
return PQnfields(m_pRes);
|
||||
}
|
||||
|
||||
PGresult *DataBase::GetRes()
|
||||
{
|
||||
return m_pRes;
|
||||
}
|
||||
|
||||
void DataBase::PgClear()
|
||||
{
|
||||
if(m_pRes)
|
||||
{
|
||||
PQclear(m_pRes);
|
||||
m_pRes = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *DataBase::GetValue(int tuple, int field)
|
||||
{
|
||||
return PQgetvalue(m_pRes, tuple, field);
|
||||
}
|
||||
|
||||
int DataBase::PgDoExec(const char *pszQuery)
|
||||
{
|
||||
return this->PgDoExec(pszQuery, NOT_CLEAR);
|
||||
}
|
||||
|
||||
int DataBase::PgDoExec(string &strQuery)
|
||||
{
|
||||
return this->PgDoExec(strQuery.c_str(), NOT_CLEAR);
|
||||
}
|
||||
|
||||
int DataBase::PgDoExec(const char *pszQuery, CFLAG flag)
|
||||
{
|
||||
if(m_PGconn == NULL) return -1;
|
||||
if(PQstatus(m_PGconn) != CONNECTION_OK) return -2;
|
||||
m_pRes = PQexec(m_PGconn, pszQuery);
|
||||
int r = PgResult(flag);
|
||||
return r;
|
||||
}
|
||||
|
||||
int DataBase::PgDoExecParams(char *pszQuery, int nParamCnt, const char * const *paramValues ,CFLAG flag)
|
||||
{
|
||||
if(m_PGconn == NULL) return -1;
|
||||
if(PQstatus(m_PGconn) != CONNECTION_OK) return -2;
|
||||
m_pRes = PQexecParams(m_PGconn, pszQuery, nParamCnt, NULL, paramValues, NULL, NULL, 0);
|
||||
int r = PgResult(flag);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
int DataBase::PgEscapeString(char *to, const char *from, size_t length)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
//PQescapeStringConn(m_PGconn, to, from, length, &retval);
|
||||
PQescapeString(to, from, length);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int DataBase::PgSetClientEncoding(const char *encoding)
|
||||
{
|
||||
return PQsetClientEncoding(m_PGconn, encoding);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/***************************************************************************
|
||||
Database Class
|
||||
-----------------------------------------
|
||||
begin : 2010/03/11
|
||||
copyright : (C) 2010 SolutionBox Inc.
|
||||
author : Service 1 Team
|
||||
email : svc1@solbox.com
|
||||
version : 1.0
|
||||
|
||||
CopyRight(C) 2010 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __DATABASE_H__
|
||||
#define __DATABASE_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#define MaxSizeOfDBQuery 1024*9
|
||||
|
||||
using namespace std;
|
||||
class DataBase
|
||||
{
|
||||
public:
|
||||
enum CFLAG { CLEAR = 1, NOT_CLEAR };
|
||||
DataBase() { m_PGconn = NULL; m_pRes = NULL;}
|
||||
~DataBase();
|
||||
PGconn *PgOpenDB(string &strHost, int Port, string &strDBName, string &strAcct, string &strPasswd, int timeout = 10);
|
||||
PGconn *PgOpenDB(const char *pszDBName);
|
||||
void PgCloseDB();
|
||||
int PgResult(CFLAG flag);
|
||||
PGconn *GetPgConn(){ return m_PGconn;}
|
||||
PGresult *GetRes();
|
||||
void SetRes(PGresult * v) {m_pRes = v;}
|
||||
int GetCmdTuples();
|
||||
int GetNoTuples();
|
||||
int GetNoFields();
|
||||
int GetResultCode() { return m_ResultCode; }
|
||||
char *GetValue(int tuple, int field);
|
||||
void PgClear();
|
||||
int PgDoExec(string &strQuery);
|
||||
int PgDoExec(const char *pszQuery);
|
||||
int PgDoExec(const char *pszQuery, CFLAG flag);
|
||||
int PgDoExecParams(char *pszQuery, int nParamCnt, const char * const *paramValues ,CFLAG flag = NOT_CLEAR);
|
||||
int PgEscapeString(char *to, const char *from, size_t length);
|
||||
int PgSetClientEncoding(const char *encoding);
|
||||
string &GetErrorMessage();
|
||||
private:
|
||||
int m_ResultCode;
|
||||
PGconn *m_PGconn;
|
||||
PGresult *m_pRes;
|
||||
string m_ErrorMessage;
|
||||
};
|
||||
|
||||
#endif // ~__DATABASE_H__
|
||||
@@ -0,0 +1,576 @@
|
||||
/***************************************************************************
|
||||
Database Connection Pool ( DbConnPool.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Configs.h"
|
||||
#include "DbConnPool.h"
|
||||
#include "Database.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
#define GET_SLEEP 1000 // microsecond
|
||||
|
||||
CMasterDBpool *CMasterDBpool::m_inst = NULL;
|
||||
CSlaveDBpool *CSlaveDBpool::m_inst = NULL;
|
||||
|
||||
CConnDBpool::CConnDBpool(CDatabaseInfo info)
|
||||
: m_dbinfo(info), m_exitpool(false), m_lastset(NULL)
|
||||
,m_poolcnt(0), m_isrecreate(false), m_alivetime(-1)
|
||||
,m_tabletype(-1)
|
||||
{
|
||||
pthread_mutex_init(&m_mutex, NULL);
|
||||
pthread_mutex_init(&m_alivemutex, NULL);
|
||||
pthread_cond_init(&m_alivecond, NULL);
|
||||
}
|
||||
|
||||
CConnDBpool::~CConnDBpool()
|
||||
{
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
pthread_mutex_destroy(&m_alivemutex);
|
||||
pthread_cond_destroy(&m_alivecond);
|
||||
}
|
||||
|
||||
int CConnDBpool::MakeConnect( int pool )
|
||||
{
|
||||
ostringstream msg;
|
||||
for(int i=0 ; i < pool ; i++)
|
||||
{
|
||||
DataBase * tmp = new DataBase();
|
||||
|
||||
if( tmp->PgOpenDB( m_dbinfo.m_szRcdbIp, m_dbinfo.m_nRcdbPort,
|
||||
m_dbinfo.m_szRcdbName, m_dbinfo.m_szRcdbAcct, m_dbinfo.m_szRcdbAcctPw ) == NULL )
|
||||
{
|
||||
msg << "Database connect error : " << tmp->GetErrorMessage();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
delete tmp;
|
||||
continue;
|
||||
}
|
||||
|
||||
// XML library(UTF-8 자동 변환) 인코딩 문자를 지원하기 위해서 DB client UTF-8 설정함
|
||||
if (tmp->PgSetClientEncoding("UTF-8") != 0)
|
||||
{
|
||||
msg << "Database Set Client Encoding error : " << tmp->GetErrorMessage();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
delete tmp;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2014.06.06 dadamin
|
||||
// Pool 생성 시 현재 생성된 DB의 형상을 체크한다.
|
||||
if (m_tabletype < 0)
|
||||
{
|
||||
if (SetTargetTableType(tmp) == false)
|
||||
{
|
||||
delete tmp;
|
||||
DestroyPool();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_poolmap.insert(make_pair(tmp, CConnDBpool::POOL_FREE));
|
||||
}
|
||||
|
||||
return m_poolmap.size();
|
||||
}
|
||||
|
||||
int CConnDBpool::CreatePool( int poolcnt /* = 4 */ )
|
||||
{
|
||||
ostringstream msg;
|
||||
// keep alive thread
|
||||
int nRet = pthread_create(&m_keepalive, 0, CConnDBpool::KeepPoolAlive, this);
|
||||
if( nRet )
|
||||
{
|
||||
msg << "Thread create failed.: errno: " << errno;
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// pool
|
||||
m_poolcnt = MakeConnect(poolcnt);
|
||||
|
||||
if (m_poolcnt == 0)
|
||||
{
|
||||
// alive thread end
|
||||
m_exitpool = true;
|
||||
pthread_cond_signal(&m_alivecond);
|
||||
pthread_join(m_keepalive, NULL);
|
||||
m_exitpool = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return m_poolcnt;
|
||||
}
|
||||
|
||||
int CConnDBpool::DestroyPool()
|
||||
{
|
||||
m_exitpool = true;
|
||||
map<DataBase*, short>::iterator iter;
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
while(m_poolmap.size() > 0 )
|
||||
{
|
||||
iter = m_poolmap.begin();
|
||||
if(iter->second == CConnDBpool::POOL_FREE
|
||||
|| iter->second == CConnDBpool::POOL_ERR
|
||||
|| iter->second == CConnDBpool::POOL_CLOSE )
|
||||
{
|
||||
DataBase *data = static_cast<DataBase *>(iter->first);
|
||||
delete (DataBase *) data;
|
||||
m_poolmap.erase(iter);
|
||||
}
|
||||
else
|
||||
sleep(1);
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
//
|
||||
pthread_cond_signal(&m_alivecond);
|
||||
pthread_join(m_keepalive, NULL);
|
||||
|
||||
/*
|
||||
for( iter = m_poolmap.begin(); !m_poolmap.empty()&& iter != m_poolmap.end(); iter++ )
|
||||
{
|
||||
if(iter->second == conndbpool::POOL_FREE)
|
||||
{
|
||||
DataBase *data = static_cast<DataBase *>(iter->first);
|
||||
delete (DataBase *) data;
|
||||
m_poolmap.f
|
||||
m_poolmap.erase(iter);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return m_poolmap.size();
|
||||
}
|
||||
|
||||
DataBase * CConnDBpool::GetConnFromPool(int timeout)
|
||||
{
|
||||
ostringstream msg;
|
||||
DataBase * r = NULL;
|
||||
|
||||
int64_t usetime = 0;
|
||||
int64_t out = timeout*1000*1000;
|
||||
|
||||
time_t t = time(NULL);
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
map<DataBase*, short>::iterator iter = m_poolmap.begin();
|
||||
if(m_lastset)
|
||||
{
|
||||
iter = m_poolmap.find(m_lastset);
|
||||
if( iter != m_poolmap.end() )
|
||||
{
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if( m_poolmap.empty() )
|
||||
{
|
||||
int make = 0;
|
||||
if(m_isrecreate)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
msg << "DB Pool ReCeate.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
#endif // _DEBUG
|
||||
make = MakeConnect(m_poolcnt);
|
||||
}
|
||||
|
||||
if (make == 0)
|
||||
{
|
||||
msg << "DB Pool empty.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( iter == m_poolmap.end() )
|
||||
{
|
||||
iter = m_poolmap.begin();
|
||||
}
|
||||
|
||||
for( ; !m_poolmap.empty()&& iter != m_poolmap.end(); )
|
||||
{
|
||||
if(iter->second == CConnDBpool::POOL_FREE)
|
||||
{
|
||||
iter->second = CConnDBpool::POOL_USE;
|
||||
r = iter->first;
|
||||
m_lastset = r;
|
||||
break;
|
||||
}
|
||||
else if (iter->second == CConnDBpool::POOL_ERR
|
||||
|| iter->second == CConnDBpool::POOL_CLOSE)
|
||||
{
|
||||
bool is_closed = (iter->second == CConnDBpool::POOL_CLOSE);
|
||||
DataBase * d = iter->first;
|
||||
|
||||
if(is_closed)
|
||||
{
|
||||
msg << "Force Closed. And Add Database object.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
MakeConnect(1);
|
||||
}
|
||||
|
||||
m_poolmap.erase(iter++);
|
||||
if(d == m_lastset)
|
||||
m_lastset = NULL;
|
||||
delete d;
|
||||
}
|
||||
else
|
||||
iter++;
|
||||
}
|
||||
|
||||
if( r == NULL)
|
||||
{
|
||||
solusleep(GET_SLEEP);
|
||||
if( usetime > 10*1000*1000)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
msg << "GetConnFromPool have waited longer than 10 seconds.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
#endif // _DEBUG
|
||||
}
|
||||
|
||||
if( out > 0 )
|
||||
{
|
||||
usetime += GET_SLEEP;
|
||||
|
||||
if(usetime > out)
|
||||
{
|
||||
msg << "GetConnFromPool Timeout." << usetime << "," << out <<
|
||||
"," << time(NULL) -t;
|
||||
LOGACONSOLE(LWAR, msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (r == NULL);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void CConnDBpool::ReleaseConnToPool(DataBase * t, short nMode /* = CConnDBpool::POOL_USE */)
|
||||
{
|
||||
//pthread_mutex_lock(&m_mutex);
|
||||
|
||||
map<DataBase*, short>::iterator iter = m_poolmap.find(t);
|
||||
if( iter != m_poolmap.end() )
|
||||
{
|
||||
if(iter->second==CConnDBpool::POOL_USE)
|
||||
{
|
||||
if( nMode == CConnDBpool::POOL_USE)
|
||||
{
|
||||
iter->second = CConnDBpool::POOL_FREE;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter->second = nMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
bool CConnDBpool::IsTimeoutAlive()
|
||||
{
|
||||
bool r = false;
|
||||
pthread_mutex_lock(&m_alivemutex);
|
||||
struct timespec to;
|
||||
|
||||
if(m_alivetime > 0 )
|
||||
to.tv_sec = time(NULL) + m_alivetime;
|
||||
else
|
||||
to.tv_sec = time(NULL) + 5;
|
||||
|
||||
to.tv_nsec = 0;
|
||||
|
||||
int err = pthread_cond_timedwait(&m_alivecond, &m_alivemutex, &to);
|
||||
|
||||
if (err == ETIMEDOUT)
|
||||
{
|
||||
if( m_alivetime > 0 )
|
||||
r = true;
|
||||
}
|
||||
else if ( err == 0 )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "Set Keep alive Timeout : " << m_alivetime << endl;
|
||||
#endif //_DEBUG
|
||||
r = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&m_alivemutex);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CConnDBpool::SendAliveMsg()
|
||||
{
|
||||
ostringstream msg;
|
||||
ostringstream sql;
|
||||
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
map<DataBase*, short>::iterator iter = m_poolmap.begin();
|
||||
map<DataBase*, short>::iterator enditer = m_poolmap.end();
|
||||
|
||||
sql << "SELECT sp_user_seq, sp_svc_tran_id FROM t_sms_sp_svc_product LIMIT 1";
|
||||
while(iter != enditer)
|
||||
{
|
||||
DataBase * d = iter->first;
|
||||
if(iter->second == CConnDBpool::POOL_FREE)
|
||||
{
|
||||
iter->second = CConnDBpool::POOL_USE;
|
||||
d->PgDoExec( const_cast<char*> (sql.str().c_str()) );
|
||||
if( d->PgResult(DataBase::CLEAR) < 0 )
|
||||
{
|
||||
msg << "Send alive : message failed : " << iter->first->GetErrorMessage();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
iter->second=CConnDBpool::POOL_ERR;
|
||||
iter++;
|
||||
//m_poolmap.erase(iter++);
|
||||
//delete d;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter->second = CConnDBpool::POOL_FREE;
|
||||
msg << "Send alive : message success.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
else if (iter->second == CConnDBpool::POOL_ERR)
|
||||
{
|
||||
msg << "Send alive : Error Pool remove.";
|
||||
LOGACONSOLE(LINF, msg);
|
||||
m_poolmap.erase(iter++);
|
||||
delete d;
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
|
||||
if( m_poolmap.empty() )
|
||||
{
|
||||
int make = 0;
|
||||
if(m_isrecreate)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
msg << "DB Pool ReCeate.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
#endif // _DEBUG
|
||||
make = MakeConnect(m_poolcnt);
|
||||
}
|
||||
|
||||
if (make == 0)
|
||||
{
|
||||
msg << "DB Pool empty.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
void* CConnDBpool::KeepPoolAlive( void* pdata )
|
||||
{
|
||||
CConnDBpool* pObject = reinterpret_cast<CConnDBpool *>(pdata);
|
||||
ostringstream msg;
|
||||
|
||||
while( pObject->IsExit() == false )
|
||||
{
|
||||
bool b = pObject->IsTimeoutAlive();
|
||||
msg << "KeepPoolAlive Timeout - run : " << b;
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
if( pObject->IsExit() == false && b )
|
||||
{
|
||||
// send keep alive message
|
||||
pObject->SendAliveMsg();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CConnDBpool::SetKeepAliveTimeout(int sec)
|
||||
{
|
||||
m_alivetime = sec;
|
||||
pthread_cond_signal(&m_alivecond);
|
||||
return m_alivetime;
|
||||
}
|
||||
|
||||
int CConnDBpool::GetFreePoolCnt()
|
||||
{
|
||||
int r = 0;
|
||||
map<DataBase*, short>::iterator iter;
|
||||
// pthread_mutex_lock(&m_mutex);
|
||||
for( iter = m_poolmap.begin(); !m_poolmap.empty()&& iter != m_poolmap.end(); iter++ )
|
||||
{
|
||||
if(iter->second == CConnDBpool::POOL_FREE)
|
||||
{
|
||||
r++;
|
||||
}
|
||||
}
|
||||
// pthread_mutex_unlock(&m_mutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
void CConnDBpool::printstatus(string prefixed)
|
||||
{
|
||||
int f = 0, u = 0;
|
||||
map<DataBase*, short>::iterator iter;
|
||||
|
||||
if(m_exitpool == true ) return;
|
||||
// pthread_mutex_lock(&m_mutex);
|
||||
for( iter = m_poolmap.begin(); !m_poolmap.empty()&& iter != m_poolmap.end(); iter++ )
|
||||
{
|
||||
if(iter->second == CConnDBpool::POOL_FREE)
|
||||
{
|
||||
f++;
|
||||
}
|
||||
else
|
||||
{
|
||||
u++;
|
||||
}
|
||||
}
|
||||
|
||||
ostringstream msg;
|
||||
if( prefixed.empty() == false )
|
||||
msg << "["<< prefixed <<"]";
|
||||
|
||||
msg <<"DB connection Pool - " <<"total : " << m_poolmap.size() << "(" << u <<
|
||||
"/" << f << ")";
|
||||
|
||||
LOGACONSOLE(LINF, msg);
|
||||
}
|
||||
|
||||
// 2014.06.07 dadamin
|
||||
// 현재 DB 형상 체크
|
||||
bool CConnDBpool::SetTargetTableType(DataBase * d)
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
if (d == NULL)
|
||||
return false;
|
||||
|
||||
d->PgDoExec("SELECT * FROM pg_tables WHERE schemaname = 'public' AND tablename = 't_dav_resource'");
|
||||
if (d->PgResult(DataBase::NOT_CLEAR) < 0)
|
||||
{
|
||||
d->PgClear();
|
||||
msg << "Set Target Table Type failed : " << d->GetErrorMessage();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d->GetNoTuples() > 0)
|
||||
{
|
||||
m_tabletype = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tabletype = 1;
|
||||
}
|
||||
|
||||
d->PgClear();
|
||||
msg << "Set Target Table Type : " << m_tabletype;
|
||||
|
||||
LOG(LDBG, msg.str().c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// master db pool
|
||||
CMasterDBpool::CMasterDBpool(CDatabaseInfo info)
|
||||
: CConnDBpool(info)
|
||||
{
|
||||
}
|
||||
|
||||
CMasterDBpool::~CMasterDBpool()
|
||||
{
|
||||
}
|
||||
|
||||
void CMasterDBpool::init(CDatabaseInfo info)
|
||||
{
|
||||
if( CMasterDBpool::m_inst == NULL )
|
||||
{
|
||||
CMasterDBpool::m_inst = new CMasterDBpool(info);
|
||||
}
|
||||
}
|
||||
|
||||
CMasterDBpool* CMasterDBpool::getInstance()
|
||||
{
|
||||
return CMasterDBpool::m_inst;
|
||||
}
|
||||
|
||||
int CMasterDBpool::release()
|
||||
{
|
||||
int r = -1;
|
||||
if( CMasterDBpool::m_inst != NULL )
|
||||
{
|
||||
r = CMasterDBpool::m_inst->DestroyPool();
|
||||
delete CMasterDBpool::m_inst;
|
||||
CMasterDBpool::m_inst = NULL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// slave db pool
|
||||
CSlaveDBpool::CSlaveDBpool(CDatabaseInfo info)
|
||||
: CConnDBpool(info)
|
||||
{
|
||||
}
|
||||
|
||||
CSlaveDBpool::~CSlaveDBpool()
|
||||
{
|
||||
}
|
||||
|
||||
void CSlaveDBpool::init(CDatabaseInfo info)
|
||||
{
|
||||
if( CSlaveDBpool::m_inst == NULL )
|
||||
{
|
||||
CSlaveDBpool::m_inst = new CSlaveDBpool(info);
|
||||
}
|
||||
}
|
||||
|
||||
CSlaveDBpool* CSlaveDBpool::getInstance()
|
||||
{
|
||||
return CSlaveDBpool::m_inst;
|
||||
}
|
||||
|
||||
int CSlaveDBpool::release()
|
||||
{
|
||||
int r = -1;
|
||||
if(CSlaveDBpool::m_inst != NULL )
|
||||
{
|
||||
r = CSlaveDBpool::m_inst->DestroyPool();
|
||||
delete CSlaveDBpool::m_inst;
|
||||
CSlaveDBpool::m_inst = NULL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
Database Connection Pool ( DbConnPool.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/28
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/28 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __DATABASE_CONNECTION_POOL__
|
||||
#define __DATABASE_CONNECTION_POOL__
|
||||
|
||||
class DataBase;
|
||||
class CDatabaseInfo;
|
||||
|
||||
class CConnDBpool
|
||||
{
|
||||
public:
|
||||
enum POOL_STATUSE
|
||||
{
|
||||
POOL_ERR = -1,
|
||||
POOL_FREE = 0,
|
||||
POOL_USE = 1,
|
||||
POOL_CLOSE = 2
|
||||
};
|
||||
public:
|
||||
CConnDBpool(CDatabaseInfo info);
|
||||
virtual ~CConnDBpool();
|
||||
|
||||
int CreatePool( int poolcnt = 4 );
|
||||
int DestroyPool();
|
||||
int MakeConnect( int pool );
|
||||
DataBase* GetConnFromPool(int timeout = 10);
|
||||
void ReleaseConnToPool(DataBase * t, short nMode = CConnDBpool::POOL_USE);
|
||||
int SetKeepAliveTimeout(int sec);
|
||||
|
||||
void printstatus(string prefixed = "");
|
||||
|
||||
int GetFreePoolCnt();
|
||||
|
||||
bool IsExit() { return m_exitpool; }
|
||||
bool IsTimeoutAlive();
|
||||
bool SendAliveMsg();
|
||||
|
||||
void SetDatabaseInfo(CDatabaseInfo info) { m_dbinfo = info; }
|
||||
void SetRecreted(bool setval) { m_isrecreate = setval; }
|
||||
CDatabaseInfo GetDatabaseInfo() { return m_dbinfo; }
|
||||
size_t GetPoolSize() { return m_poolmap.size(); }
|
||||
|
||||
// 2014.06.07 dadamin
|
||||
// ÇöÀç DB Çü»ó üũ
|
||||
bool SetTargetTableType(DataBase * d);
|
||||
int GetTargetTableType() { return m_tabletype; }
|
||||
private:
|
||||
static void* KeepPoolAlive(void*);
|
||||
|
||||
private:
|
||||
CDatabaseInfo m_dbinfo;
|
||||
map<DataBase*, short> m_poolmap;
|
||||
pthread_mutex_t m_mutex;
|
||||
bool m_exitpool;
|
||||
DataBase* m_lastset;
|
||||
int m_poolcnt;
|
||||
bool m_isrecreate;
|
||||
|
||||
int m_alivetime;
|
||||
pthread_t m_keepalive;
|
||||
pthread_cond_t m_alivecond;
|
||||
pthread_mutex_t m_alivemutex;
|
||||
|
||||
// 2014.06.07 dadamin
|
||||
// -1: unset, 0: t_dav_resource, 1: t_meat_[sp_svc_tran_id]
|
||||
int m_tabletype;
|
||||
};
|
||||
|
||||
class CMasterDBpool : public CConnDBpool
|
||||
{
|
||||
public:
|
||||
static void init(CDatabaseInfo info);
|
||||
static CMasterDBpool* getInstance();
|
||||
static int release();
|
||||
|
||||
private:
|
||||
CMasterDBpool(CDatabaseInfo info);
|
||||
~CMasterDBpool();
|
||||
|
||||
private:
|
||||
static CMasterDBpool* m_inst;
|
||||
};
|
||||
|
||||
class CSlaveDBpool : public CConnDBpool
|
||||
{
|
||||
public:
|
||||
static void init(CDatabaseInfo info);
|
||||
static CSlaveDBpool* getInstance();
|
||||
static int release();
|
||||
|
||||
private:
|
||||
CSlaveDBpool(CDatabaseInfo info);
|
||||
~CSlaveDBpool();
|
||||
|
||||
private:
|
||||
static CSlaveDBpool* m_inst;
|
||||
};
|
||||
|
||||
#endif // __DATABASE_CONNECTION_POOL__
|
||||
@@ -0,0 +1,509 @@
|
||||
/***************************************************************************
|
||||
FHS Control Class (FhsControl.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "JobData.h"
|
||||
#include "FhsControl.h"
|
||||
#include "Protocol.h"
|
||||
#include "UtilFn.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#define PRODUCT_ID_LEN 64
|
||||
#define MaxSizeOfSID 128
|
||||
#define OPENDAV_URI_PATH_SIZE 1024
|
||||
//#define URI_PATH_SIZE 2048
|
||||
|
||||
CFhsControl::CFhsControl()
|
||||
: m_broadcastfd(-1), m_bcreated(false)
|
||||
{
|
||||
bzero(&m_broadcastAddr,sizeof(m_broadcastAddr));
|
||||
}
|
||||
|
||||
CFhsControl::~CFhsControl()
|
||||
{
|
||||
if (m_broadcastfd > 0)
|
||||
{
|
||||
::close(m_broadcastfd);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int CFhsControl::ConversionAddr( const char * name )
|
||||
{
|
||||
unsigned int retval;
|
||||
struct addrinfo hints, *result;
|
||||
int error;
|
||||
|
||||
// 전달받은 정보가 잘못된 경우
|
||||
if( (retval = inet_addr(name)) != INADDR_NONE )
|
||||
return retval;
|
||||
|
||||
// getaddrinfo() 함수 호출을 위한 Hint 설정
|
||||
memset( &hints, 0x00, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
// Thread Safe 한 DNS Resolve 처리함수 호출
|
||||
// int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res);
|
||||
error = getaddrinfo( name, NULL, &hints, &result );
|
||||
|
||||
// 오류 발생시
|
||||
if( error != 0 )
|
||||
{
|
||||
LOG( LERR, "name[%s] dns resolve fail. getaddrinfo return error [%d][%s]", name, error, gai_strerror(error) );
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
struct sockaddr_in * addr = (struct sockaddr_in *)result->ai_addr;
|
||||
retval = (unsigned int)(addr->sin_addr.s_addr);
|
||||
|
||||
// DNS Resovle 결과 확인용 코드
|
||||
/*
|
||||
struct addrinfo *temp;
|
||||
for( temp = result; temp; temp = temp->ai_next )
|
||||
{
|
||||
addr = (struct sockaddr_in *)temp->ai_addr;
|
||||
printf ("getaddrinfo result = %s\n",inet_ntoa( addr->sin_addr));
|
||||
}
|
||||
*/
|
||||
|
||||
// getaddrinfo() 함수에서 생성한 메모리 영역 해제 처리.
|
||||
freeaddrinfo(result);
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
bool CFhsControl::Create(const char* rcid, const char * IP, int Port, bool isBroadcast)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
if( rcid == NULL || strlen(rcid) <= 0 )
|
||||
{
|
||||
LOG( LERR, "FHS Control Create failed: RCID empty" );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_rcid = rcid;
|
||||
|
||||
if( isBroadcast )
|
||||
{
|
||||
// case broadcast
|
||||
|
||||
unsigned int hostaddr = ConversionAddr(IP);
|
||||
|
||||
if(hostaddr == INADDR_NONE)
|
||||
return false;
|
||||
|
||||
m_broadcastAddr.sin_family=AF_INET;
|
||||
m_broadcastAddr.sin_addr.s_addr= hostaddr;
|
||||
m_broadcastAddr.sin_port=htons(Port);
|
||||
|
||||
m_broadcastfd = ::socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(m_broadcastfd < 0)
|
||||
{
|
||||
LOG( LERR, "FHS Control Create failed: %s", strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
|
||||
int on = 1;
|
||||
if (::setsockopt(m_broadcastfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0)
|
||||
{
|
||||
LOG( LERR, "FHS Control Create failed::BROADCAST: %s", strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
|
||||
r = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// case ftsd
|
||||
r = m_ftsd.ConnectTarget(string(IP), Port);
|
||||
}
|
||||
|
||||
m_bcreated = r;
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CFhsControl::IsCreated()
|
||||
{
|
||||
if (!m_bcreated)
|
||||
{
|
||||
LOG(LERR, "FHS Control not be initialized.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFhsControl::MkServiceRootDir(CJobDataMap & jobData)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
if (!IsCreated())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(jobData[KEY_SP_USER_SEQ].empty())
|
||||
{
|
||||
LOG( LERR, "User number empty." );
|
||||
return false;
|
||||
}
|
||||
|
||||
if(jobData[KEY_SP_SVC_TRAN_ID].empty())
|
||||
{
|
||||
LOG( LERR, "Service number empty." );
|
||||
return false;
|
||||
}
|
||||
|
||||
struct tm newtime;
|
||||
time_t ltime;
|
||||
ltime=time(<ime);
|
||||
localtime_r(<ime, &newtime);
|
||||
|
||||
MsgHeaderBoardCast header;
|
||||
|
||||
snprintf(header.szTransactionID, MaxSizeOfTID, "%2.2d%2.2d%2.2d%2.2d%2.2d%2.2d-0-0-0"
|
||||
, newtime.tm_year+1900, newtime.tm_mon+1
|
||||
, newtime.tm_mday, newtime.tm_hour
|
||||
, newtime.tm_min, newtime.tm_sec);
|
||||
|
||||
header.ulMode = htonl(BROADCAST_MKDIR_SERVICE_ROOT);
|
||||
snprintf(header.szIssuer, MaxSizeOfIssuer, "%s", PROG_NAME);
|
||||
snprintf(header.szServiceID, (PRODUCT_ID_LEN - 1), "%s", jobData[KEY_SP_USER_SEQ].c_str() );
|
||||
snprintf((header.szServiceID + PRODUCT_ID_LEN), (PRODUCT_ID_LEN - 1), "%s", jobData[KEY_SP_SVC_TRAN_ID].c_str());
|
||||
snprintf(header.szRCID, MaxSizeOfRCID, "%s", m_rcid.c_str());
|
||||
header.ulResult = htonl(OK_ALL_PASSED);
|
||||
header.ulBodyLength = htonl(0);
|
||||
|
||||
size_t len = sizeof(header);
|
||||
socklen_t tolen = sizeof( m_broadcastAddr );
|
||||
int nWrite = sendto( m_broadcastfd, (char *) &header, len, 0x00, (struct sockaddr *)&m_broadcastAddr, tolen );
|
||||
|
||||
if( nWrite < 0 )
|
||||
{
|
||||
LOG( LERR, "Send Message(Service Root Make Request) failed[%s] : "
|
||||
"rcid=%s,user_seq=%s,tran_id=%s",
|
||||
strerror(errno),m_rcid.c_str(),
|
||||
jobData[KEY_SP_USER_SEQ].c_str(),
|
||||
jobData[KEY_SP_SVC_TRAN_ID].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CFhsControl::SendAnonyDir(CJobDataMap & jobData, string targeturi)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
if (!IsCreated())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(jobData[KEY_SP_SVC_ID].empty())
|
||||
{
|
||||
LOG( LERR, "Service ID empty." );
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t ulMode = 0;
|
||||
if(jobData[KEY_JOBSUB_TYPE].compare(JOB_ANONY_DIR_SET) == 0)
|
||||
{
|
||||
ulMode = BROADCAST_ANONY_SET;
|
||||
}
|
||||
else if(jobData[KEY_JOBSUB_TYPE].compare(JOB_ANONY_DIR_UNSET) == 0)
|
||||
{
|
||||
ulMode = BROADCAST_ANONY_UNSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( LERR, "Unknown Job Type[%s].", jobData[KEY_JOBSUB_TYPE].c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
MsgHeaderBoardCast header;
|
||||
|
||||
struct tm newtime;
|
||||
time_t ltime;
|
||||
ltime=time(<ime);
|
||||
localtime_r(<ime, &newtime);
|
||||
|
||||
snprintf(header.szTransactionID, MaxSizeOfTID, "%2.2d%2.2d%2.2d%2.2d%2.2d%2.2d-0-0-0"
|
||||
, newtime.tm_year+1900, newtime.tm_mon+1
|
||||
, newtime.tm_mday, newtime.tm_hour
|
||||
, newtime.tm_min, newtime.tm_sec);
|
||||
|
||||
header.ulMode = htonl(ulMode);
|
||||
|
||||
snprintf(header.szServiceID, MaxSizeOfSID - 1, "%s", jobData[KEY_SP_SVC_ID].c_str() );
|
||||
snprintf(header.szRCID, MaxSizeOfRCID, "%s", m_rcid.c_str());
|
||||
header.ulResult = htonl(OK_ALL_PASSED);
|
||||
header.ulBodyLength = htonl(OPENDAV_URI_PATH_SIZE);
|
||||
|
||||
char szPath[OPENDAV_URI_PATH_SIZE] = {0};
|
||||
snprintf(szPath, OPENDAV_URI_PATH_SIZE - 1, "%s", targeturi.c_str());
|
||||
|
||||
size_t len = sizeof header + OPENDAV_URI_PATH_SIZE;
|
||||
char *psSendBuf = NULL;
|
||||
psSendBuf = new char[len];
|
||||
|
||||
if(psSendBuf != NULL)
|
||||
{
|
||||
memcpy(psSendBuf, (char *)&header, sizeof header);
|
||||
memcpy((psSendBuf + sizeof header), szPath, OPENDAV_URI_PATH_SIZE);
|
||||
|
||||
socklen_t tolen = sizeof( m_broadcastAddr );
|
||||
int nWrite = sendto( m_broadcastfd, (char *) psSendBuf, len, 0x00,
|
||||
(struct sockaddr *)&m_broadcastAddr, tolen );
|
||||
|
||||
delete [] psSendBuf;
|
||||
if( nWrite < 0 )
|
||||
{
|
||||
LOG( LERR, "Send Message(SendAnonyDir) failed[%s] : "
|
||||
"rcid=%s,user_seq=%s,tran_id=%s,uri =%s",
|
||||
strerror(errno),m_rcid.c_str(),
|
||||
jobData[KEY_SP_USER_SEQ].c_str(),
|
||||
jobData[KEY_SP_SVC_TRAN_ID].c_str(), szPath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( LERR, "Memory allocation failure.[%d]", errno);
|
||||
r = false;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
bool CFhsControl::GetFront10MMD5(CJobDataMap & jobData)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
if (!IsCreated())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long long nHashChkSize = atoll(jobData[KEY_REQ_HASH_CHECK_SIZE].c_str());
|
||||
|
||||
if( m_ftsd.SendFileCheckRequest( jobData[KEY_FILENAME_HASH], true, nHashChkSize ) == false )
|
||||
{
|
||||
// Source ftsd 로 전송 실패시
|
||||
LOG( LERR, "File Hash Check Request send fail.[filename_hash:%s]", jobData["filename_hash"].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int nTimeout = 5; // 응답 대기 시간 ( sec )
|
||||
int nResult = 0;
|
||||
|
||||
bool bResultSuccess;
|
||||
string szErrorMessage;
|
||||
string szHashValue;
|
||||
unsigned long long nFileSize = 0;
|
||||
|
||||
|
||||
// 루프를 돌면서 요청에 대한 응답을 대기
|
||||
while(1)
|
||||
{
|
||||
// nTimeout 에 지정된 시간동안 응답대기 시도
|
||||
// GetFileCheckResult() 함수는 SocketControl.h 파일 참고.
|
||||
nResult = m_ftsd.GetFileCheckResult( nTimeout, bResultSuccess, szErrorMessage, nFileSize, szHashValue );
|
||||
|
||||
if( nResult == -1 )
|
||||
{
|
||||
// Socket 통신 관련 오류 또는 접속 종료가 발생한 경우.
|
||||
// 해당 내역 로깅 및 루프 종료
|
||||
r = false;
|
||||
LOG( LERR, "File Hash Check Response wait fail by socket.[%s:%s]"
|
||||
,KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
break;
|
||||
|
||||
}
|
||||
else if( nResult == 0 )
|
||||
{
|
||||
// 지정된 시간 동안 응답대기 중 처리 결과 정보가 아직 수신되지 않은 경우 => Allive Check 패킷 한번 쏘고 다시 Loop 로
|
||||
|
||||
if( m_ftsd.SendAliveCheck() == false )
|
||||
{
|
||||
// Alive 전송 실패시 => Socket 종료 및 오류가 발생한 경우임.
|
||||
r = false;
|
||||
LOG( LERR, "File Hash Check Response wait fail by socket2.[%s:%s]"
|
||||
, KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
// 정상적인 경우 다시 응답대기.
|
||||
continue;
|
||||
}
|
||||
else if( nResult == 1 )
|
||||
{
|
||||
// 요청에 대한 처리결과 정보가 수신된 경우.
|
||||
// 해당 정보 로깅처리.
|
||||
|
||||
if( bResultSuccess == true )
|
||||
{
|
||||
r = true;
|
||||
ostringstream strfilesize;
|
||||
strfilesize << nFileSize;
|
||||
|
||||
jobData[KEY_RES_FILE_SIZE] = strfilesize.str();
|
||||
jobData[KEY_RES_FILE_FRONT_10M_MD5] = szHashValue;
|
||||
|
||||
_LOG(LDBG, "File Front 10MB MD5 : %s", jobData[KEY_RES_FILE_FRONT_10M_MD5].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// 오류 발생시
|
||||
r = false;
|
||||
LOG( LERR, "File Hash Check Response error.[%s][%s:%s]",
|
||||
szErrorMessage.c_str(), KEY_FILENAME_HASH,jobData[KEY_FILENAME_HASH].c_str());
|
||||
|
||||
}
|
||||
|
||||
break; // 응답을 받았으니 응답 대기 루프 종료
|
||||
}
|
||||
else
|
||||
{
|
||||
// Replication 요청에 대한 응답패킷이 아닌 경우.
|
||||
// 해당 패킷은 무시하고 다시 Loop 로
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CFhsControl::GetTotoExtractWithplatform(CJobDataMap & jobData)
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
if (!IsCreated())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ftsd.SendFileCheckTOTORequest(jobData[KEY_FILENAME_HASH]) == false)
|
||||
{
|
||||
// Source ftsd 로 전송 실패시
|
||||
LOG(LERR, "File Hash Check Request send fail.[filename_hash:%s]", jobData["filename_hash"].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int nTimeout = 5; // 응답 대기 시간 ( sec )
|
||||
int nResult = 0;
|
||||
|
||||
bool bResultSuccess;
|
||||
string szErrorMessage;
|
||||
|
||||
// File 추출값 저장 변수
|
||||
string szTotoMd5;
|
||||
string szChecksum;
|
||||
string szDnaCheckKey;
|
||||
unsigned long long nFileSize = 0;
|
||||
|
||||
int ntry = 0;
|
||||
|
||||
// 루프를 돌면서 요청에 대한 응답을 대기
|
||||
while (1)
|
||||
{
|
||||
// nTimeout 에 지정된 시간동안 응답대기 시도
|
||||
// GetFileCheckResult() 함수는 SocketControl.h 파일 참고.
|
||||
nResult = m_ftsd.GetFileCheckTOTOResult(nTimeout, bResultSuccess, szErrorMessage, nFileSize, szTotoMd5, szChecksum, szDnaCheckKey);
|
||||
|
||||
if (nResult == -1)
|
||||
{
|
||||
// Socket 통신 관련 오류 또는 접속 종료가 발생한 경우.
|
||||
// 해당 내역 로깅 및 루프 종료
|
||||
r = false;
|
||||
LOG(LERR, "File Hash Check(Totodisk) Response wait fail by socket.[%s:%s]"
|
||||
, KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
break;
|
||||
|
||||
}
|
||||
else if (nResult == 0)
|
||||
{
|
||||
// 지정된 시간 동안 응답대기 중 처리 결과 정보가 아직 수신되지 않은 경우 => Allive Check 패킷 한번 쏘고 다시 Loop 로
|
||||
|
||||
if (m_ftsd.SendAliveCheck() == false)
|
||||
{
|
||||
// Alive 전송 실패시 => Socket 종료 및 오류가 발생한 경우임.
|
||||
r = false;
|
||||
LOG(LERR, "File Hash Check(Totodisk) Response wait fail by socket2.[%s:%s]"
|
||||
, KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
if (++ntry > 3)
|
||||
{
|
||||
// 3회 재시도 응답 없을 경우 실패처리
|
||||
r = false;
|
||||
LOG(LERR, "File Hash Check(Totodisk) Response wait timeout.[%s:%s]"
|
||||
, KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
break;
|
||||
}
|
||||
// 정상적인 경우 다시 응답대기.
|
||||
continue;
|
||||
}
|
||||
else if (nResult == 1)
|
||||
{
|
||||
// 요청에 대한 처리결과 정보가 수신된 경우.
|
||||
// 해당 정보 로깅처리.
|
||||
|
||||
if (bResultSuccess == true)
|
||||
{
|
||||
r = true;
|
||||
|
||||
ostringstream strfilesize;
|
||||
strfilesize << nFileSize;
|
||||
|
||||
jobData[KEY_RES_FILE_SIZE] = strfilesize.str();
|
||||
jobData[KEY_RES_FILE_TOTO_MD5] = szTotoMd5;
|
||||
jobData[KEY_RES_FILE_TOTO_CHECKSUM] = szChecksum;
|
||||
jobData[KEY_RES_FILE_TOTO_DNAKEY] = szDnaCheckKey;
|
||||
|
||||
_LOG(LINF, "TOTO Result file [%s][%s]", jobData[KEY_REQ_URI].c_str(), jobData[KEY_FILENAME_HASH].c_str());
|
||||
_LOG(LINF, "TOTO Result FHS [%s]", jobData[KEY_HOST_NAME].c_str());
|
||||
_LOG(LINF, "TOTO Result size [%s]", jobData[KEY_RES_FILE_SIZE].c_str());
|
||||
_LOG(LINF, "TOTO Result md5 hash [%s]", jobData[KEY_RES_FILE_TOTO_MD5].c_str());
|
||||
_LOG(LINF, "TOTO Result checksum [%s]", jobData[KEY_RES_FILE_TOTO_CHECKSUM].c_str());
|
||||
_LOG(LINF, "TOTO Result dna key [%s]", jobData[KEY_RES_FILE_TOTO_DNAKEY].c_str());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// 오류 발생시
|
||||
r = false;
|
||||
LOG(LERR, "File Hash Check(Totodisk) Response error.[%s][%s:%s]",
|
||||
szErrorMessage.c_str(), KEY_FILENAME_HASH, jobData[KEY_FILENAME_HASH].c_str());
|
||||
|
||||
}
|
||||
|
||||
break; // 응답을 받았으니 응답 대기 루프 종료
|
||||
}
|
||||
else
|
||||
{
|
||||
// Replication 요청에 대한 응답패킷이 아닌 경우.
|
||||
// 해당 패킷은 무시하고 다시 Loop 로
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/***************************************************************************
|
||||
FHS Control Class Header ( FhsControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __FHS_CONTROL_H__
|
||||
#define __FHS_CONTROL_H__
|
||||
|
||||
#include "FtsdSocketControl.h"
|
||||
|
||||
class CFhsControl
|
||||
{
|
||||
public:
|
||||
CFhsControl();
|
||||
~CFhsControl();
|
||||
|
||||
bool Create(const char * rcid, const char * IP, int Port, bool isBroadcast);
|
||||
|
||||
bool MkServiceRootDir(CJobDataMap & jobData);
|
||||
bool GetFront10MMD5(CJobDataMap & jobData);
|
||||
bool SendAnonyDir(CJobDataMap & jobData, string targeturi);
|
||||
|
||||
bool GetTotoExtractWithplatform(CJobDataMap & jobData);
|
||||
|
||||
bool IsCreated();
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
unsigned int ConversionAddr( const char * name );
|
||||
|
||||
// broadcast
|
||||
int m_broadcastfd;
|
||||
struct sockaddr_in m_broadcastAddr;
|
||||
// ftsd
|
||||
CFtsdSocketControl m_ftsd;
|
||||
|
||||
bool m_bcreated;
|
||||
string m_rcid;
|
||||
};
|
||||
|
||||
|
||||
#endif // __FHS_CONTROL_H__
|
||||
@@ -0,0 +1,211 @@
|
||||
/***************************************************************************
|
||||
File Control Class ( FileControl.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "FileControl.h"
|
||||
#include "JobData.h"
|
||||
#include "Configs.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
CFileControl::CFileControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CFileControl::~CFileControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CFileControl::beforecheck(CJobDataMap & jobData, bool & IgnoreCase)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if (rcdb.Init() != 0)
|
||||
{
|
||||
LOG(LERR, "RCDB Initialization failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
// check info
|
||||
int t = 0;
|
||||
t = ExistInfo(rcdb, jobData);
|
||||
if (t != 1)
|
||||
{
|
||||
r = t;
|
||||
LOG(LERR, "Base information check error.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rcdb.CheckUriIgnoreCase(jobData, IgnoreCase))
|
||||
{
|
||||
r = JOB_ERR_FILE_CHK_IGNORECASE;
|
||||
break;
|
||||
}
|
||||
|
||||
// find file info
|
||||
if (!rcdb.GetFileInfo(jobData, IgnoreCase))
|
||||
{
|
||||
r = JOB_ERR_CHK_FILE_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
} while (false);
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CFileControl::run( CJobDataMap &jobData )
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
_LOG( LDBG, "File Control running...");
|
||||
|
||||
CMyConfig* pConf = CMyConfig::GetInstance();
|
||||
|
||||
if(!pConf)
|
||||
{
|
||||
LOG( LERR, "Config is NULL.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// (FHS 통신 발생 시) DB 점유로 인한 pool 획득 실패 방지를 위해서
|
||||
// 사전 체크 항목 분리함
|
||||
bool ignoreCase = false;
|
||||
r = beforecheck(jobData, ignoreCase);
|
||||
if (r != JOB_SUCCESS)
|
||||
break;
|
||||
|
||||
if (jobData[KEY_HOST_NAME].empty())
|
||||
r = JOB_ERR_FILE_NOT_FOUND;
|
||||
|
||||
if ( IsSubKey(jobData, JOB_FILE_CTL_EXIST) )
|
||||
{
|
||||
jobData[KEY_RES_FILE_SIZE] = jobData[KEY_GET_CONTENT_LENGTH];
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_FILE_CTL_MKDIR))
|
||||
{
|
||||
if (r == JOB_ERR_FILE_NOT_FOUND)
|
||||
{
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if (rcdb.Init() != 0)
|
||||
{
|
||||
LOG(LERR, "RCDB Initialization failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (!rcdb.CheckParentDir(jobData, ignoreCase))
|
||||
{
|
||||
r = JOB_ERR_CHK_PARENT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (jobData[KEY_URI_PARENT].empty())
|
||||
{
|
||||
jobData[KEY_URI_PARENT] = p_name(jobData[KEY_URI]);
|
||||
if (!rcdb.MakeDir(jobData, jobData[KEY_URI_PARENT], ignoreCase))
|
||||
{
|
||||
r = JOB_ERR_FILE_MKDIR_PARENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rcdb.MakeDir(jobData, jobData[KEY_URI], ignoreCase))
|
||||
r = JOB_SUCCESS;
|
||||
else
|
||||
r = JOB_ERR_FILE_MKDIR;
|
||||
} while (false);
|
||||
|
||||
rcdb.Final();
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_FILE_EXIST;
|
||||
}
|
||||
}
|
||||
else if (FindInSubKey(jobData, JOB_FILE_CTL_GET_HASH))
|
||||
{
|
||||
// file exist
|
||||
if (r == JOB_SUCCESS)
|
||||
{
|
||||
CFhsControl fhs;
|
||||
if (!fhs.Create(pConf->GetRCID(), jobData[KEY_HOST_NAME].c_str(), pConf->GetFHSControlTCP(), false))
|
||||
{
|
||||
r = JOB_ERR_CREATION_FAIL;
|
||||
LOG(LERR, "FHS Control Initialization failed.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (IsSubKey(jobData, JOB_FILE_CTL_GET_HASH_10MB))
|
||||
{
|
||||
if (!fhs.GetFront10MMD5(jobData))
|
||||
{
|
||||
r = JOB_ERR_FILE_HASH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_FILE_CTL_TOTO_EXTRACT_WITHPLATFORM))
|
||||
{
|
||||
if (!fhs.GetTotoExtractWithplatform(jobData))
|
||||
{
|
||||
r = JOB_ERR_FILE_HASH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if( r != 0 )
|
||||
{
|
||||
if (r == JOB_ERR_UNKNOWN)
|
||||
LOG(LERR, "Subkey is unknown.");
|
||||
|
||||
LOG( LERR, "File Control(%s|%d) error.[%s@%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(), r,
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_LOG( LINF, "File Control(%s) success.[%s@%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
|
||||
_LOG( LDBG, "File Control end.");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
File Control Class Header ( FileControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __FILE_CONTROL_H__
|
||||
#define __FILE_CONTROL_H__
|
||||
|
||||
class CJob;
|
||||
|
||||
class CFileControl : public CJob
|
||||
{
|
||||
public:
|
||||
CFileControl();
|
||||
virtual ~CFileControl();
|
||||
|
||||
virtual int run( CJobDataMap &jobData );
|
||||
protected:
|
||||
|
||||
int beforecheck(CJobDataMap & jobData, bool & IgnoreCase);
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __FILE_CONTROL_H__
|
||||
@@ -0,0 +1,67 @@
|
||||
/***************************************************************************
|
||||
ftsd control interface ( File Replication & Cache & Move & Delete Control) Header ( FtsdProtocol.h )
|
||||
-----------------------------------------
|
||||
begin : 2010/03/09
|
||||
copyright : (C) 2005 SolutionBox Inc.
|
||||
author : Service 1 Team
|
||||
email : svc1@solbox.com
|
||||
version : 3.2.0.R0811
|
||||
|
||||
CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __FTSD_PROTOCOL_H__
|
||||
#define __FTSD_PROTOCOL_H__
|
||||
|
||||
|
||||
struct FileTransferPacketHeader {
|
||||
|
||||
char stx; // Packet 유효성 관리 코드
|
||||
char type; // Request or Response 여부 ( 0x00: Request, 0x01: Response )
|
||||
char command[4]; // Command Code ( 4 Byte) : 0th control-ftsd, 1th ftsd-ftsd 사용.
|
||||
char result[4]; // Result Code ( 4 Byte )
|
||||
unsigned int data_length; // Packet Data 부분의 길이값 ( Network Byte Order 사용)
|
||||
char extend_code[2]; // 확장 및 Padding bits ( 2 Byte )
|
||||
};
|
||||
|
||||
|
||||
// Packet Header stx 코드
|
||||
#define HEADER_STX_CODE 0x02
|
||||
|
||||
// Packet Header type 구분코드
|
||||
#define HEADER_TYPE_REQUEST 0x00
|
||||
#define HEADER_TYPE_RESPONSE 0x01
|
||||
|
||||
|
||||
// Packet command 공통.
|
||||
#define COMMON_ALIVE_CHECK 0x7F
|
||||
|
||||
// Packet command : control 프로세스 <-> ftsd 통신 ( Command 첫번째 Byte 만 사용 )
|
||||
#define NOT_CONTROL_COMMAND 0x00 // Control 이 전송한 요청이 아닌 경우.
|
||||
#define CONTROL_FILE_REPLICATION 0x01 // Content 복제 생성 요청
|
||||
#define CONTROL_FILE_CACHE 0x02 // Content 에 대해 Cache 폴더로 복제 요청
|
||||
|
||||
#define CONTROL_FILE_CHECK 0x03 // Content 에 대한 존재 여부, Size 확인 및 Hash 추출 요청
|
||||
#define CONTROL_FILE_UNLINK 0x04 // Content 에 대한 unlink 처리 요청
|
||||
|
||||
// NEW 2016-05-04 huibong 토토디스크 지원용 기능 추가 (#27460)
|
||||
#define CONTROL_FILE_CHECK_TOTO 0x05 // 토토디스크 고객사 지원을 위한 MD5 Hash 추출 기능 (2016-05-03 추가)
|
||||
|
||||
|
||||
// Packet Result : type이 Reponse 인 경우에만 세팅됨.( 첫번째 Byte 만 사용시 )
|
||||
#define HEADER_RESULT_SUCCESS 0x00
|
||||
#define HEADER_RESULT_ERROR 0x01
|
||||
|
||||
|
||||
// 기타 정보
|
||||
#define LENGTH_FIELD_SIZE 4 // 가변데이터 형식 사용시 Length 필드의 메모리 크기 (unsigned int)
|
||||
|
||||
|
||||
// unlink 요청시 Mode 설정 정보
|
||||
#define UNLINK_MODE_NORMAL 0 // 해당 Content 가 존재하고 size 값이 정확한 경우에만 삭제, 나머지는 오류
|
||||
#define UNLINK_MODE_FORCE 1 // 해당 Content 가 존재하지 않거나.. Size 값이 틀려도 강제로 삭제 처리.. 오류로 처리되는 상황은 통신, 시스템 오류 발생시.
|
||||
|
||||
|
||||
#endif /* __FTSD_PROTOCOL_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,304 @@
|
||||
/***************************************************************************
|
||||
ftsd control interface ( File Replication & Cache & Move & Delete Control) Header ( FtsdSocketControl.h )
|
||||
-----------------------------------------
|
||||
begin : 2010/03/09
|
||||
copyright : (C) 2005 SolutionBox Inc.
|
||||
author : Service 1 Team
|
||||
email : svc1@solbox.com
|
||||
version : 3.2.0.R0811
|
||||
|
||||
CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of SolutionBox Inc.
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __FTSD_SOCKET_CONTROL_H__
|
||||
#define __FTSD_SOCKET_CONTROL_H__
|
||||
|
||||
#include "BaseSocket.h"
|
||||
#include "FtsdProtocol.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
///< BYTE 타입 정의
|
||||
#ifndef _BYTE_DEFINED
|
||||
#define _BYTE_DEFINED
|
||||
typedef unsigned char BYTE;
|
||||
#endif // _BYTE_DEFINED
|
||||
|
||||
|
||||
#define DEFAULT_SOCKET_TEMP_BUFFER_SIZE 1024 // SocketControl 에서 사용할 임시버퍼 크기.
|
||||
|
||||
class CFtsdSocketControl : public CBaseSocket
|
||||
{
|
||||
private:
|
||||
|
||||
/// @brief Packet Header 변수
|
||||
struct FileTransferPacketHeader m_packetHeader;
|
||||
|
||||
/// @brief m_packetHeader 구조체의 크기를 저장하기 위한 상수
|
||||
const int m_nPacketHeaderLen;
|
||||
|
||||
/// @brief Packet Header 에 저장된 Data 부분의 길이 정보값.
|
||||
unsigned int m_nPacketDataLen;
|
||||
|
||||
/// @brief Packet Data 부분의 수신처리시 임시로 사용할 버퍼.
|
||||
BYTE m_tempBuffer[DEFAULT_SOCKET_TEMP_BUFFER_SIZE];
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/// @brief 생성자.
|
||||
CFtsdSocketControl();
|
||||
|
||||
/// @brief 소멸자.
|
||||
~CFtsdSocketControl();
|
||||
|
||||
|
||||
/// @brief 전달받은 Target 으로 Socket 접속을 수행
|
||||
/// @param szTarget [in] 접속 대상 Host name 또는 IP
|
||||
/// @param nPort [in] 접속 Port
|
||||
/// @return 접속 성공시 true, 실패시 false 반환. ( 오류 내역은 로깅처리됨.)
|
||||
bool ConnectTarget( const std::string& szTarget, int nPort );
|
||||
|
||||
|
||||
/// @brief 대상과 연결된 Socket 을 통해 ftsd 로 File Replication 명령 전송.
|
||||
/// @param szFileName [in] 복제할 원본 Source 파일명 (/stg/node0/186/abcde..)
|
||||
/// @param nFileSize [in] 복제할 원본 Source 파일의 크기.
|
||||
/// @param szTargetTranId [in] RC 간 복제 처리시 변경할 대상 Tran ID 정보 값.
|
||||
/// @param nFileHashCheckLevel [in] File 에 대한 Hash Check Level 정보 ( conf 파일에 지정됨)
|
||||
/// @param bUseInternalIp [in] 내부망을 이용하여 파일 송수신을 수행할지 여부 \n
|
||||
///< 해당값을 true 로 지정시 ftsd 상에서 내부망을 우선 사용하여 파일 복제 시도
|
||||
///< 만약 내부망 사용 불가시 자동으로 외부망 사용.
|
||||
///< RC-RC 간 처리시에는 사용하지 않도록 false 로 지정할 것.
|
||||
/// @param vecTargetFhs [in] 복제 대상 Target FHS Host Name 정보
|
||||
/// @return Replication 복제 요청 메시지 전송 성공시 true, 실패시 false 반환.
|
||||
bool SendFileReplicationRequest(const std::string& szFileName, unsigned long long nFileSize, int nFileHashCheckLevel, bool bUseInternalIp, std::vector< std::string >& vecTargetFhs);
|
||||
bool SendFileReplicationRequest(const std::string& szFileName, unsigned long long nFileSize, const std::string& szTargetTranId, int nFileHashCheckLevel, bool bUseInternalIp, std::vector< std::string >& vecTargetFhs);
|
||||
|
||||
|
||||
/// @brief File Replication 요청에 대한 처리 결과를 ftsd 로 부터 수신한다.
|
||||
/// @param nTimeout [in] 함수 호출에 대한 Blocking 을 방지하기 위한 Timeout 설정값. 단위( second )\n
|
||||
///< 지정된 시간동안 응답을 수신하지 못한 경우 0 을 반환.
|
||||
/// @param bSuccess [out] File Replication 이 정상적으로 수행되었는지 여부 \n
|
||||
///< trnsfer 상에서 오류가 발생한 경우 이 값은 false 가 되며 \n
|
||||
///< szErrorMessage 변수상에 오류내용이 저장됨. \n
|
||||
///< 정상적으로 처리된 경우 true 가 저장되며 \n
|
||||
///< mapSuccessFhs, mapFailFhs 상에 관련 정보가 저장됨.
|
||||
/// @param szErrorMessage [out] bSuccess == false 인 경우 발생된 오류메시지 정보를 저장
|
||||
/// @param mapSuccessFhs [out] bSuccess == true 인 경우 \n
|
||||
///< Replication 처리에 성공한 FHS 및 저장된 File 이름 정보를 저장
|
||||
/// @param mapFailFhs [out] bSuccess == true 인 경우 \n
|
||||
///< Replication 처리에 실패한 FHS Host Name 및 발생된 오류메시지 정보를 저장.
|
||||
///
|
||||
/// @return -1 : Socket 통신 관련 오류 발생하여 ftsd 와 연결이 끊어진 경우 \n
|
||||
///< => ftsd 와 연결이 끝어진것으로 판단하고 오류처리한다. \n
|
||||
///<
|
||||
///< 0 : 입력변수인 nTimeout 에 지정된 시간안에 ftsd 로부터
|
||||
///< Replication 에 대한 처리 결과 정보를 수신하지 못한 경우. \n
|
||||
///< 이 기능은 본 함수 호출시 Blocking 발생을 막기 위한 기능으로서 \n
|
||||
///< 이 값이 반환된 경우 추가 다른 작업을 진행한 후 본 함수를 다시 호출하여 \n
|
||||
///< 응답을 대기할 수 있다. \n
|
||||
///<
|
||||
///< 1 : 파일 복제 처리에 대한 응답을 수신한 경우, Output 인자인 bSuccess 를 확인하여 처리 결과 확인
|
||||
///<
|
||||
///< 2 : ftsd 로 부터 Data 을 수신하였으나 File Replication 요청에 대한 응답이 아닌 경우 \n
|
||||
///< 해당 정보는 본 클래스의 멤버변수 상에 내부적으로 저장된다. ( 단 Alive Packet 은 아님) \n
|
||||
///< 본 결과가 수신된 경우 무시 처리하고 계속 응답을 대기하면 된다.
|
||||
int GetFileReplicationResult( int nTimeout, bool& bSuccess, std::string& szErrorMessage, std::map< std::string, std::string>& mapSuccessFhs, std::map< std::string, std::string>& mapFailFhs );
|
||||
|
||||
|
||||
/// @brief 대상과 연결된 Socket 을 통해 ftsd 로 File Cache 명령 전송.
|
||||
/// @param szFileName [in] Cache 처리할 원본 Source 파일명 (/stg/node0/186/abcde..)
|
||||
/// @param nFileSize [in] Cache 처리할 원본 Source 파일의 크기.
|
||||
/// @param nFileHashCheckLevel [in] File 에 대한 Hash Check Level 정보 ( conf 파일에 지정됨)
|
||||
/// @param bUseInternalIp [in] 내부망을 이용하여 파일 송수신을 수행할지 여부 \n
|
||||
///< 해당값을 true 로 지정시 ftsd 상에서 내부망을 우선 사용하여 파일 복제 시도
|
||||
///< 만약 내부망 사용 불가시 자동으로 외부망 사용.
|
||||
/// @param vecTargetFhs [in] Cache 대상 Target FHS Host Name 정보
|
||||
/// @return Cache 요청 메시지 전송 성공시 true, 실패시 false 반환.
|
||||
bool SendFileCacheRequest(const std::string& szFileName, unsigned long long nFileSize, int nFileHashCheckLevel, bool bUseInternalIp, std::vector< std::string >& vecTargetFhs);
|
||||
|
||||
|
||||
/// @brief File Cache 요청에 대한 처리 결과를 ftsd 로 부터 수신한다.
|
||||
/// @param nTimeout [in] 함수 호출에 대한 Blocking 을 방지하기 위한 Timeout 설정값. 단위( second )\n
|
||||
///< 지정된 시간동안 응답을 수신하지 못한 경우 0 을 반환.
|
||||
/// @param bSuccess [out] File Cache 처리가 정상적으로 수행되었는지 여부 \n
|
||||
///< trnsfer 상에서 오류가 발생한 경우 이 값은 false 가 되며 \n
|
||||
///< szErrorMessage 변수상에 오류내용이 저장됨. \n
|
||||
///< 정상적으로 처리된 경우 true 가 저장되며 \n
|
||||
///< mapSuccessFhs, mapFailFhs 상에 관련 정보가 저장됨.
|
||||
/// @param szErrorMessage [out] bSuccess == false 인 경우 발생된 오류메시지 정보를 저장
|
||||
/// @param mapSuccessFhs [out] bSuccess == true 인 경우 \n
|
||||
///< Cache 처리에 성공한 FHS 및 저장된 File 이름 정보를 저장
|
||||
/// @param mapFailFhs [out] bSuccess == true 인 경우 \n
|
||||
///< Cache 처리에 실패한 FHS Host Name 및 발생된 오류메시지 정보를 저장.
|
||||
///
|
||||
/// @return -1 : Socket 통신 관련 오류 발생하여 ftsd 와 연결이 끊어진 경우 \n
|
||||
///< => ftsd 와 연결이 끝어진것으로 판단하고 오류처리한다. \n
|
||||
///<
|
||||
///< 0 : 입력변수인 nTimeout 에 지정된 시간안에 ftsd 로부터
|
||||
///< Cache 에 대한 처리 결과 정보를 수신하지 못한 경우. \n
|
||||
///< 이 기능은 본 함수 호출시 Blocking 발생을 막기 위한 기능으로서 \n
|
||||
///< 이 값이 반환된 경우 추가 다른 작업을 진행한 후 본 함수를 다시 호출하여 \n
|
||||
///< 응답을 대기할 수 있다. \n
|
||||
///<
|
||||
///< 1 : 파일 Cache 처리에 대한 응답을 수신한 경우, Output 인자인 bSuccess 를 확인하여 처리 결과 확인
|
||||
///<
|
||||
///< 2 : ftsd 로 부터 Data 을 수신하였으나 File Cache 요청에 대한 응답이 아닌 경우 \n
|
||||
///< 해당 정보는 본 클래스의 멤버변수 상에 내부적으로 저장된다. ( 단 Alive Packet 은 아님) \n
|
||||
///< 본 결과가 수신된 경우 무시 처리하고 계속 응답을 대기하면 된다.
|
||||
int GetFileCacheResult( int nTimeout, bool& bSuccess, std::string& szErrorMessage, std::map< std::string, std::string>& mapSuccessFhs, std::map< std::string, std::string>& mapFailFhs );
|
||||
|
||||
|
||||
/// @brief 대상과 연결된 Socket 을 통해 ftsd 로 Content Check 명령 전송.
|
||||
/// @param szFileName [in] 원본 Source 파일명 (/stg/node0/186/abcde..)
|
||||
/// @param bHashCheck [in] Hash 값을 추출할지 여부
|
||||
/// @param nHashCheckSize [in] Hash 값을 추출할 경우 Size 설정값 ( MByte 단위 )\n
|
||||
///< 0 : Content 에 대한 전체 Hash 값을 추출함.
|
||||
///< 숫자 : Content 의 앞 부분부터 지정된 크기 (MByte ) 까지 Hash 값을 추출
|
||||
/// @return Check 요청 메시지 전송 성공시 true, 실패시 false 반환.
|
||||
bool SendFileCheckRequest(const std::string& szFileName, bool bHashCheck, unsigned long long nHashCheckSize );
|
||||
|
||||
|
||||
|
||||
/// @brief File Check 요청에 대한 처리 결과를 ftsd 로 부터 수신한다.
|
||||
/// @param nTimeout [in] 함수 호출에 대한 Blocking 을 방지하기 위한 Timeout 설정값. 단위( second )\n
|
||||
///< 지정된 시간동안 응답을 수신하지 못한 경우 0 을 반환.
|
||||
/// @param bSuccess [out] File Check 처리가 정상적으로 수행되었는지 여부 \n
|
||||
///< ftsd 상에서 오류가 발생한 경우 이 값은 false 가 되며 \n
|
||||
///< szErrorMessage 변수상에 오류내용이 저장됨. \n
|
||||
///< 정상적으로 처리된 경우 true 가 저장되며 \n
|
||||
///< nFileSize, szHashValue 상에 결과 정보가 저장됨.
|
||||
/// @param szErrorMessage [out] bSuccess == false 인 경우 발생된 오류메시지 정보를 저장
|
||||
/// @param nFileSize [out] bSuccess == true 인 경우 요청한 Content 에 대한 file size 정보를 저장. ( Byte 단위 )
|
||||
/// @param szHashValue [out] bSuccess == true 이고... Hash 값 추출을 요청한 경우 추출된 Hash 값 정보를 저장.
|
||||
/// @return -1 : Socket 통신 관련 오류 발생하여 ftsd 와 연결이 끊어진 경우 \n
|
||||
///< => ftsd 와 연결이 끝어진것으로 판단하고 오류처리한다. \n
|
||||
///<
|
||||
///< 0 : 입력변수인 nTimeout 에 지정된 시간안에 ftsd 으로부터 처리 결과 정보를 수신하지 못한 경우. \n
|
||||
///< 이 기능은 본 함수 호출시 Blocking 발생을 막기 위한 기능으로서 \n
|
||||
///< 이 값이 반환된 경우 추가 다른 작업을 진행한 후 본 함수를 다시 호출하여 \n
|
||||
///< 응답을 대기할 수 있다. \n
|
||||
///<
|
||||
///< 1 : 파일 Check 처리에 대한 응답을 수신한 경우, Output 인자인 bSuccess 를 확인하여 처리 결과 확인
|
||||
///<
|
||||
///< 2 : ftsd 으로 부터 Data 을 수신하였으나 File Check 요청에 대한 응답이 아닌 경우 \n
|
||||
///< 해당 정보는 본 클래스의 멤버변수 상에 내부적으로 저장된다. ( 단 Alive Packet 은 아님) \n
|
||||
///< 본 결과가 수신된 경우 무시 처리하고 계속 응답을 대기하면 된다.
|
||||
int GetFileCheckResult( int nTimeout, bool& bSuccess, std::string& szErrorMessage, unsigned long long& nFileSize, std::string& szHashValue );
|
||||
|
||||
|
||||
/// @brief 대상과 연결된 Socket 을 통해 ftsd 로 Unlink 명령 전송.
|
||||
/// @param szFileName [in] 원본 Source 파일명 (/stg/node0/186/abcde..)
|
||||
/// @param nFileSize [in] 원본 파일의 크기 ( Byte 단위 )
|
||||
/// @param bForceUnlink [in] 강제 삭제 처리 여부 ( Defalult false )
|
||||
/// false : 일반모드 - 해당 파일이 존재하고 Size 값이 동일할 경우에만 삭제처리.. 나머지는 오류로 처리.
|
||||
/// true : 강제모드 - 해당 파일이 존재하지 않거나.. Size 가 틀려도 강제로 삭제 처리.. 오류는 통신, 시스템 오류 발생시에만
|
||||
/// @return Unlink 요청 메시지 전송 성공시 true, 실패시 false 반환.
|
||||
bool SendFileUnlinkRequest(const std::string& szFileName, unsigned long long nFileSize, bool bForceUnlink = false );
|
||||
|
||||
/// @brief File Unlink 요청에 대한 처리 결과를 ftsd 로 부터 수신한다.
|
||||
/// @param nTimeout [in] 함수 호출에 대한 Blocking 을 방지하기 위한 Timeout 설정값. 단위( second )\n
|
||||
///< 지정된 시간동안 응답을 수신하지 못한 경우 0 을 반환.
|
||||
/// @param bSuccess [out] File unlink 처리가 정상적으로 수행되었는지 여부 \n
|
||||
///< ftsd 상에서 오류가 발생한 경우 이 값은 false 가 되며 \n
|
||||
///< szErrorMessage 변수상에 오류내용이 저장됨. \n
|
||||
///< 정상적으로 처리된 경우 true 가 저장되며 따로 수신하는 Data 는 없음. \n
|
||||
/// @param szErrorMessage [out] bSuccess == false 인 경우 발생된 오류메시지 정보를 저장
|
||||
/// @return -1 : Socket 통신 관련 오류 발생하여 ftsd 와 연결이 끊어진 경우 \n
|
||||
///< => ftsd 와 연결이 끝어진것으로 판단하고 오류처리한다. \n
|
||||
///<
|
||||
///< 0 : 입력변수인 nTimeout 에 지정된 시간안에 ftsd 으로부터 처리 결과 정보를 수신하지 못한 경우. \n
|
||||
///< 이 기능은 본 함수 호출시 Blocking 발생을 막기 위한 기능으로서 \n
|
||||
///< 이 값이 반환된 경우 추가 다른 작업을 진행한 후 본 함수를 다시 호출하여 \n
|
||||
///< 응답을 대기할 수 있다. \n
|
||||
///<
|
||||
///< 1 : 파일 Unlink 처리에 대한 응답을 수신한 경우, Output 인자인 bSuccess 를 확인하여 처리 결과 확인
|
||||
///<
|
||||
///< 2 : ftsd 으로 부터 Data 을 수신하였으나 File Unlink 요청에 대한 응답이 아닌 경우 \n
|
||||
///< 해당 정보는 본 클래스의 멤버변수 상에 내부적으로 저장된다. ( 단 Alive Packet 은 아님) \n
|
||||
///< 본 결과가 수신된 경우 무시 처리하고 계속 응답을 대기하면 된다.
|
||||
int GetFileUnlinkResult( int nTimeout, bool& bSuccess, std::string& szErrorMessage );
|
||||
|
||||
|
||||
// NEW 2016-05-04 huibong 토토디스크 지원용 기능 추가 (#27460)
|
||||
/// @brief 대상과 연결된 Socket 을 통해 ftsd 로 Content Check 명령 전송. (토토디스크 지원용)
|
||||
/// @param szFileName [in] 원본 Source 파일명 (/stg/node0/186/abcde..)
|
||||
/// @return Check 요청 메시지 전송 성공시 true, 실패시 false 반환.
|
||||
bool SendFileCheckTOTORequest( const std::string& szFileName );
|
||||
|
||||
|
||||
// NEW 2016-05-04 huibong 토토디스크 지원용 기능 추가 (#27460, #27533)
|
||||
/// @brief File Check 요청에 대한 처리 결과를 ftsd 로 부터 수신한다.
|
||||
/// @param nTimeout [in] 함수 호출에 대한 Blocking 을 방지하기 위한 Timeout 설정값. 단위( second )\n
|
||||
///< 지정된 시간동안 응답을 수신하지 못한 경우 0 을 반환.
|
||||
/// @param bSuccess [out] File Check 처리가 정상적으로 수행되었는지 여부 \n
|
||||
///< ftsd 상에서 오류가 발생한 경우 이 값은 false 가 되며 \n
|
||||
///< szErrorMessage 변수상에 오류내용이 저장됨. \n
|
||||
///< 정상적으로 처리된 경우 true 가 저장되며 \n
|
||||
///< nFileSize, szHashValue 상에 결과 정보가 저장됨.
|
||||
/// @param szErrorMessage [out] bSuccess == false 인 경우 발생된 오류메시지 정보를 저장
|
||||
/// @param nFileSize [out] bSuccess == true 인 경우 요청한 Content 에 대한 file size 정보를 저장. ( Byte 단위 )
|
||||
/// @param szTotoMd5 [out] bSuccess == true 인 경우 추출된 totorasa 용 MD5 Hash 값 정보를 저장.
|
||||
/// @param szChecksum [out] bSuccess == true 인 경우 추출된 totorasa 용 Checksum 정보를 저장.
|
||||
/// @param szDnaCheckKey [out] bSuccess == true 인 경우 추출된 totorasa 용 DNA Check key 값 정보를 저장.
|
||||
/// @return -1 : Socket 통신 관련 오류 발생하여 ftsd 와 연결이 끊어진 경우 \n
|
||||
///< => ftsd 와 연결이 끝어진것으로 판단하고 오류처리한다. \n
|
||||
///<
|
||||
///< 0 : 입력변수인 nTimeout 에 지정된 시간안에 ftsd 으로부터 처리 결과 정보를 수신하지 못한 경우. \n
|
||||
///< 이 기능은 본 함수 호출시 Blocking 발생을 막기 위한 기능으로서 \n
|
||||
///< 이 값이 반환된 경우 추가 다른 작업을 진행한 후 본 함수를 다시 호출하여 \n
|
||||
///< 응답을 대기할 수 있다. \n
|
||||
///<
|
||||
///< 1 : 파일 Check 처리에 대한 응답을 수신한 경우, Output 인자인 bSuccess 를 확인하여 처리 결과 확인
|
||||
///<
|
||||
///< 2 : ftsd 으로 부터 Data 을 수신하였으나 File Check 요청에 대한 응답이 아닌 경우 \n
|
||||
///< 해당 정보는 본 클래스의 멤버변수 상에 내부적으로 저장된다. ( 단 Alive Packet 은 아님) \n
|
||||
///< 본 결과가 수신된 경우 무시 처리하고 계속 응답을 대기하면 된다.
|
||||
int GetFileCheckTOTOResult( int nTimeout, bool& bSuccess, std::string& szErrorMessage
|
||||
, unsigned long long& nFileSize, std::string& szTotoMd5, std::string& szChecksum, std::string& szDnaCheckKey );
|
||||
|
||||
|
||||
|
||||
/// @brief 연결된 Socket 통신을 이용하여 내부적으로 정의된 Alive Check 패킷 전송 \n
|
||||
///< => 해당 패킷에 대한 처리는 내부적으로 처리되어 결과값을 확인할 필요는 없다.
|
||||
/// @return Socket 연결 해제 또는 전송 관련 오류 발생시 false, 전송 성공시에는 true 반환.
|
||||
bool SendAliveCheck(void);
|
||||
|
||||
/// @brief Packet Header 정보를 Log 파일에 Logging 처리 ( Debug 처리를 위한 함수)
|
||||
void PrintHeaderToLog(void);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/// @brief Packet Header 부분의 수신 처리를 위한 함수. Alive Check 요청 패킷은 자동으로 무시처리함.
|
||||
/// @param timeout [in] 대기시간.
|
||||
/// @retrun 성공시 true, 오류 발생및 실패시 fasle 반환.
|
||||
bool GetPacketHeader(int timeout = DEFAULT_DATA_RECEIVE_TIMEOUT);
|
||||
|
||||
/// @brief socket 에서 지정된 크기만큼의 데이터를 읽어 출력변수에 저장처리.
|
||||
/// @param size [in] read 할 데이터 크기
|
||||
/// @param value [out] 읽은 데이터를 저장할 string 변수
|
||||
/// @return On success return true, otherwise return false.
|
||||
bool GetPacketData( unsigned int& size, std::string& value );
|
||||
|
||||
/// @brief socket 에서 지정된 크기만큼의 데이터를 읽어 내부 임시버퍼인 m_tempBuffer 에 저장처리.
|
||||
/// @param size [in] read 할 데이터 크기
|
||||
/// @return On success return true, otherwise return false.
|
||||
bool GetPacketData( unsigned int size );
|
||||
|
||||
/// @brief pValue 에 저장된 데이터를 unsigned int 형으로 변환처리 및 Endian 변환
|
||||
unsigned int GetDataToUInt( BYTE * pValue, bool bConvertEndian = true );
|
||||
|
||||
/// @brief pValue 에 저장된 데이터를 unsigned long long (64Byte) 형으로 변환처리.
|
||||
unsigned long long GetDataToUInt64( BYTE * pValue );
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* __FTSD_SOCKET_CONTROL_H__ */
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/***************************************************************************
|
||||
Job Base Class ( Job.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/21
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/21 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "Logger.h"
|
||||
#include "md5.h"
|
||||
|
||||
// job base class
|
||||
CJob::CJob()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CJob::~CJob()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CJob::ExistUser( CRCDBControl &rcdb, CJobDataMap &jobData )
|
||||
{
|
||||
bool exist = false;
|
||||
|
||||
// check
|
||||
if( !rcdb.CheckUserInfo(jobData, exist) )
|
||||
{
|
||||
return JOB_ERR_CHK_USER;
|
||||
}
|
||||
|
||||
if(!exist)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CJob::ExistProduct(CRCDBControl &rcdb, CJobDataMap &jobData )
|
||||
{
|
||||
bool exist = false;
|
||||
if(!rcdb.CheckProductInfo(jobData, exist) )
|
||||
{
|
||||
return JOB_ERR_CHK_PRODUCT;
|
||||
}
|
||||
|
||||
if(!exist)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CJob::ExistInfo(CRCDBControl &rcdb, CJobDataMap &jobData )
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
r = ExistUser(rcdb, jobData);
|
||||
if( r < 0 )
|
||||
return r;
|
||||
|
||||
if( r == 0 )
|
||||
return JOB_ERR_USER_EMPTY;
|
||||
|
||||
r = ExistProduct(rcdb, jobData);
|
||||
|
||||
if( r < 0 )
|
||||
return r;
|
||||
|
||||
if( r == 0 )
|
||||
return JOB_ERR_PRODUCT_EMPTY;
|
||||
|
||||
r = 1;
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CJob::CheckIdentify( CJobDataMap &jobData )
|
||||
{
|
||||
if( jobData[KEY_REQ_USER_PASS_CRYPTED].empty() )
|
||||
{
|
||||
LOG(LWAR, "Requested data to the user password is empty.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ostringstream passwdcrty;
|
||||
|
||||
passwdcrty << jobData[KEY_SP_SVC_ID] << "@" << jobData[KEY_SP_USER_ID]
|
||||
<< jobData[KEY_SP_USER_PASSWORD] << jobData[KEY_REQ_REG_DATE];
|
||||
|
||||
MD5 *md5hasher = new MD5();
|
||||
|
||||
char *pszHashed = NULL;
|
||||
md5hasher->update((unsigned char *)passwdcrty.str().c_str(), passwdcrty.str().size());
|
||||
md5hasher->finalize();
|
||||
pszHashed = md5hasher->hex_digest();
|
||||
|
||||
bool r = true;
|
||||
if( jobData[KEY_REQ_USER_PASS_CRYPTED].compare(pszHashed) != 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LNOT, "Password not match.");
|
||||
}
|
||||
|
||||
if(md5hasher) delete md5hasher;
|
||||
if(pszHashed) delete [] pszHashed;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CJob::IsSubKey (CJobDataMap &jobData, string key)
|
||||
{
|
||||
if(jobData[KEY_JOBSUB_TYPE].compare(key) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CJob::FindInSubKey(CJobDataMap &jobData, string key)
|
||||
{
|
||||
size_t found = jobData[KEY_JOBSUB_TYPE].find(key);
|
||||
if (found != string::npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
Job Header ( Job.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/21
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/21 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __JOB_H__
|
||||
#define __JOB_H__
|
||||
|
||||
#include "RCDBControl.h"
|
||||
#include "FhsControl.h"
|
||||
|
||||
class CJob
|
||||
{
|
||||
public:
|
||||
CJob();
|
||||
virtual ~CJob();
|
||||
|
||||
virtual int run( CJobDataMap &jobData ) = 0;
|
||||
protected:
|
||||
int ExistInfo(CRCDBControl &rcdb, CJobDataMap &jobData );
|
||||
int ExistUser(CRCDBControl &rcdb, CJobDataMap &jobData );
|
||||
int ExistProduct(CRCDBControl &rcdb, CJobDataMap &jobData );
|
||||
bool CheckIdentify( CJobDataMap &jobData );
|
||||
bool IsSubKey (CJobDataMap &jobData, string key);
|
||||
bool FindInSubKey(CJobDataMap &jobData, string key);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // __JOB_H__
|
||||
@@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
Job Control Class (JobControl.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "JobControl.h"
|
||||
#include "Job.h"
|
||||
#include "Logger.h"
|
||||
|
||||
CJobControl::CJobControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CJobControl::~CJobControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CJobControl::run()
|
||||
{
|
||||
CJobFactory jobf;
|
||||
CJob *pJob = NULL;
|
||||
|
||||
pJob = jobf.CreateJob(m_jobData);
|
||||
|
||||
if(pJob == NULL)
|
||||
{
|
||||
// error
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
int r = pJob->run( m_jobData );
|
||||
delete pJob;
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/***************************************************************************
|
||||
Job Control Class Header ( JobControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __JOB_CONTROL_H__
|
||||
#define __JOB_CONTROL_H__
|
||||
|
||||
#include "JobData.h"
|
||||
|
||||
class CJobControl
|
||||
{
|
||||
public:
|
||||
CJobControl();
|
||||
~CJobControl();
|
||||
|
||||
inline CJobDataMap* GetJobData() { return (CJobDataMap*)&m_jobData; }
|
||||
int run();
|
||||
|
||||
protected:
|
||||
CJobDataMap m_jobData;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // __JOB_CONTROL_H__
|
||||
@@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
Job Data Base Class ( JobData.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/27
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/27 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "JobData.h"
|
||||
#include "Logger.h"
|
||||
#include "Job.h"
|
||||
#include "ServiceOpen.h"
|
||||
#include "ServiceChange.h"
|
||||
#include "VolumeInfo.h"
|
||||
#include "AnonymousDir.h"
|
||||
#include "FileControl.h"
|
||||
|
||||
|
||||
// Abstract Factory returning a Job
|
||||
CJob * CJobFactory::CreateJob(CJobDataMap &jobMap)
|
||||
{
|
||||
CJob * r = NULL;
|
||||
|
||||
_LOG( LDBG, "Job Factory [%s]",jobMap[KEY_JOB_TYPE].c_str());
|
||||
|
||||
if( jobMap[KEY_JOB_TYPE].compare(JOB_SERVICE_OPEN) == 0 )
|
||||
{
|
||||
r = new CServiceOpen;
|
||||
}
|
||||
else if( jobMap[KEY_JOB_TYPE].compare(JOB_SERVICE_CHANGE) == 0 )
|
||||
{
|
||||
r = new CServiceChange;
|
||||
}
|
||||
else if( jobMap[KEY_JOB_TYPE].compare(JOB_VOLUME_INFO) == 0 )
|
||||
{
|
||||
r = new CVolumeInfo;
|
||||
}
|
||||
else if( jobMap[KEY_JOB_TYPE].compare(JOB_ANONY_DIR) == 0 )
|
||||
{
|
||||
r = new CAnonymousDir;
|
||||
}
|
||||
else if( jobMap[KEY_JOB_TYPE].compare(JOB_FILE_CTL) == 0 )
|
||||
{
|
||||
r = new CFileControl;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = NULL;
|
||||
LOG(LERR, "Job type is unknown.");
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
/***************************************************************************
|
||||
Job Data Header ( JobData.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/27
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/27 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __JOB_DATA_H__
|
||||
#define __JOB_DATA_H__
|
||||
|
||||
// Map
|
||||
typedef map<string, string> CJobDataMap;
|
||||
typedef pair< string, string > CJobDataPair;
|
||||
|
||||
// Job Define
|
||||
/// key
|
||||
#define KEY_JOB_TYPE "JobType"
|
||||
#define KEY_JOBSUB_TYPE "JobSubType"
|
||||
|
||||
/// kind of job
|
||||
#define JOB_SERVICE_OPEN "ServiceOpen"
|
||||
#define JOB_SERVICE_CHANGE "ServiceChange"
|
||||
#define JOB_SERVICE_CHG_USER JOB_SERVICE_CHANGE"_user"
|
||||
#define JOB_SERVICE_CHG_USER_PW JOB_SERVICE_CHG_USER"_user_password"
|
||||
#define JOB_SERVICE_CHG_PRODUCT JOB_SERVICE_CHANGE"_product"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_STORAGE JOB_SERVICE_CHG_PRODUCT"_storage"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_BANDWIDTH JOB_SERVICE_CHG_PRODUCT"_bandwidth"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_PERIOD JOB_SERVICE_CHG_PRODUCT"_period"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_AUTHINFO JOB_SERVICE_CHG_PRODUCT"_authinfo"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_REPLICATION JOB_SERVICE_CHG_PRODUCT"_replication"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_SYNC_INFO JOB_SERVICE_CHG_PRODUCT"_sync_info"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_STORAGE_CAL JOB_SERVICE_CHG_PRODUCT"_cal_used_depth"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE JOB_SERVICE_CHG_PRODUCT"_uri_ignore_case"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE_FROCE JOB_SERVICE_CHG_PRODUCT"_uri_ignore_case_force"
|
||||
#define JOB_SERVICE_CHG_PRODUCT_DEL_FILE_KEEP_TIME JOB_SERVICE_CHG_PRODUCT"_del_file_keep_time"
|
||||
#define JOB_SERVICE_CHG_EXAUTH JOB_SERVICE_CHANGE"_exauth"
|
||||
#define JOB_SERVICE_CHG_EXAUTH_MODE JOB_SERVICE_CHG_EXAUTH"_mode"
|
||||
#define JOB_SERVICE_CHG_EXAUTH_INFO JOB_SERVICE_CHG_EXAUTH"_info"
|
||||
#define JOB_SERVICE_CHG_EXAUTH_REFERER_CHK JOB_SERVICE_CHG_EXAUTH"_referer_chk"
|
||||
#define JOB_SERVICE_CHG_BAND JOB_SERVICE_CHANGE"_band"
|
||||
#define JOB_SERVICE_CHG_BAND_MODE JOB_SERVICE_CHG_BAND"_mode"
|
||||
#define JOB_SERVICE_CHG_BAND_VOLUME_LIMIT JOB_SERVICE_CHG_BAND"_volume_limit"
|
||||
#define JOB_SERVICE_CHG_BAND_SESSION_LIMIT JOB_SERVICE_CHG_BAND"_session_limit"
|
||||
#define JOB_SERVICE_CHG_STATUS JOB_SERVICE_CHANGE"_status"
|
||||
#define JOB_SERVICE_CHG_SYNC JOB_SERVICE_CHANGE"_sync"
|
||||
#define JOB_SERVICE_CHG_MOVE JOB_SERVICE_CHANGE"_move"
|
||||
#define JOB_SERVICE_CHG_MOVE_RQE JOB_SERVICE_CHG_MOVE"_request"
|
||||
#define JOB_SERVICE_CHG_MOVE_COMP JOB_SERVICE_CHG_MOVE"_complete"
|
||||
#define JOB_VOLUME_INFO "VolumeInfo"
|
||||
#define JOB_ANONY_DIR "AnonyDir"
|
||||
#define JOB_ANONY_DIR_SET JOB_ANONY_DIR"_set"
|
||||
#define JOB_ANONY_DIR_UNSET JOB_ANONY_DIR"_unset"
|
||||
#define JOB_ANONY_DIR_GET JOB_ANONY_DIR"_get"
|
||||
#define JOB_FILE_CTL "FileControl"
|
||||
#define JOB_FILE_CTL_EXIST JOB_FILE_CTL"_exist"
|
||||
#define JOB_FILE_CTL_MKDIR JOB_FILE_CTL"_mkdir"
|
||||
#define JOB_FILE_CTL_GET_HASH JOB_FILE_CTL"_get_hash"
|
||||
#define JOB_FILE_CTL_GET_HASH_10MB JOB_FILE_CTL_GET_HASH"_10MB"
|
||||
#define JOB_FILE_CTL_TOTO_EXTRACT JOB_FILE_CTL_GET_HASH"_TOTO"
|
||||
#define JOB_FILE_CTL_TOTO_EXTRACT_WITHPLATFORM JOB_FILE_CTL_TOTO_EXTRACT"_withplatform"
|
||||
#define JOB_SERVICE_MOVE "SvcMove"
|
||||
#define JOB_SERVICE_MOVE_REQUEST JOB_SERVICE_MOVE"_Request"
|
||||
#define JOB_SERVICE_MOVE_COMPLETE JOB_SERVICE_MOVE"_Complete"
|
||||
|
||||
// service status code
|
||||
#define SERVICE_STATUS_ING "SVC_STATUS_ING" // 서비스 중
|
||||
#define SERVICE_STATUS_CLOSE "SVC_STATUS_CLOSE" // 해지
|
||||
#define SERVICE_STATUS_STOP "SVC_STATUS_STOP" // 중지
|
||||
#define SERVICE_STATUS_REMOVE "SVC_STATUS_REMOVE" // 삭제
|
||||
|
||||
// sync link code
|
||||
#define SYNC_LINK_CODE_LINK "LINK" // 설정
|
||||
#define SYNC_LINK_CODE_UNLINK "UNLINK" // 해제
|
||||
#define SYNC_LINK_ONE_WAY "TRUE" // 요청 받은 링크 정보를 자신만 처리
|
||||
|
||||
/// value key
|
||||
#define KEY_REQ_REG_DATE "Requset_RegDate"
|
||||
#define KEY_REQ_USER_PASS_CRYPTED "Requset_user_pass_Crypted"
|
||||
#define KEY_REQ_URI "Requset_URI"
|
||||
#define KEY_REQ_DATA_NUM "Requset_data_num"
|
||||
#define KEY_REQ_HASH_CHECK_SIZE "Requset_Hach_Chek_Size"
|
||||
#define KEY_REQ_AUTH_MODE "Requset_auth_mode"
|
||||
#define KEY_REQ_BAND_MODE "Requset_band_mode"
|
||||
#define KEY_REQ_EXT_AUTH_SET "Requset_ext_auth_set"
|
||||
#define KEY_REQ_EXT_AUTH_UNSET "Requset_ext_auth_unset"
|
||||
#define KEY_REQ_BAND_LIMIT_SET "Requset_band_limit_set"
|
||||
#define KEY_REQ_BAND_LIMIT_UNSET "Requset_band_limit_unset"
|
||||
#define KEY_REQ_SVC_STATUS "Requset_Service_Status"
|
||||
#define KEY_REQ_LINK_CODE "Requset_Link_Code"
|
||||
#define KEY_REQ_LINK_ONE_WAY "Requset_Link_One_Way"
|
||||
#define KEY_REQ_MOVE_NOW_RCTS "Requset_Move_Now_RCTS"
|
||||
#define KEY_REQ_MOVE_NEW_RCTS "Requset_Move_New_RCTS"
|
||||
#define KEY_RES_URI "Response_URI"
|
||||
#define KEY_RES_FILE_SIZE "Response_file_size"
|
||||
#define KEY_RES_FILE_FRONT_10M_MD5 "Response_file_F_10_MD5"
|
||||
#define KEY_RES_FILE_TOTO_MD5 "Response_file_TOTO_MD5"
|
||||
#define KEY_RES_FILE_TOTO_CHECKSUM "Response_file_TOTO_checksum"
|
||||
#define KEY_RES_FILE_TOTO_DNAKEY "Response_file_TOTO_dnakey"
|
||||
#define KEY_RES_XML_JOB_TYPE "Response_XML_JobType"
|
||||
#define KEY_RES_XML_JOB_TYPE_List "Response_XML_JobType_List"
|
||||
|
||||
|
||||
#define KEY_URI "uri"
|
||||
#define KEY_URI_PARENT "uri_parent"
|
||||
//// t_sms_sp_user
|
||||
#define KEY_SP_USER_SEQ "sp_user_seq"
|
||||
#define KEY_SP_USER_ID "sp_user_id"
|
||||
#define KEY_SP_USER_PASSWORD "sp_user_password"
|
||||
#define KEY_DEL_USER_INFO "del_yn"
|
||||
|
||||
//// t_sms_sp_svc_product
|
||||
#define KEY_SP_SVC_TRAN_ID "sp_svc_tran_id"
|
||||
#define KEY_SP_SVC_ID "sp_svc_id"
|
||||
#define KEY_SP_SVC_BEGIN_DATE "sp_svc_begin_date"
|
||||
#define KEY_SP_SVC_END_DATE "sp_svc_end_date"
|
||||
#define KEY_INITIAL_VECTOR "initial_vector"
|
||||
#define KEY_PRIVATE_KEY "private_key"
|
||||
#define KEY_MAX_BANDWIDTH "max_bandwidth"
|
||||
#define KEY_MAX_STR_SIZE "max_str_size"
|
||||
#define KEY_VALIDATE_SP_SESSION_ID_YN "validate_sp_session_id_yn"
|
||||
#define KEY_BANDWIDTH_CTRL_YN "bandwidth_ctrl_yn"
|
||||
#define KEY_REFERER_CHK_YN "referer_chk_yn"
|
||||
#define KEY_REPLICATION_COUNT "replication_count"
|
||||
#define KEY_CAL_USED_DEPTH "cal_used_depth"
|
||||
#define KEY_URI_IGNORE_CASE "uri_ignore_case"
|
||||
#define KEY_DEL_FILE_KEEP_TIME "del_file_keep_time"
|
||||
#define KEY_DEL_PRODUCT "del_yn"
|
||||
|
||||
|
||||
//// t_sms_sp_svc_product_val
|
||||
#define KEY_AUTH_SERVER "auth_server"
|
||||
#define KEY_AUTH_PATH "auth_path"
|
||||
#define KEY_AUTH_PORT "auth_port"
|
||||
#define KEY_AUTH_TIMEOUT "auth_timeout"
|
||||
#define KEY_BILL_SERVER "bill_server"
|
||||
#define KEY_BILL_PATH "bill_path"
|
||||
#define KEY_BILL_PORT "bill_port"
|
||||
#define KEY_BILL_TIMEOUT "bill_timeout"
|
||||
#define KEY_REFERER_CHK_URL "referer_chk_url"
|
||||
#define KEY_REFERER_CHK_FILETYPE "referer_chk_filetype"
|
||||
|
||||
//// t_sms_sp_svc_product_band
|
||||
#define KEY_VOLUME_BANDWIDTH_LIMIT "volume_bandwidth_limit"
|
||||
#define KEY_SESSION_BANDWIDTH_LIMIT "session_bandwidth_limit"
|
||||
|
||||
//// t_sms_sp_svc_product_sync
|
||||
#define KEY_LINK_MASTER_YN "master_yn"
|
||||
#define KEY_LINK_SP_SVC_TRAN_ID "linked_sp_svc_tran_id"
|
||||
#define KEY_LINK_RCTS "linked_rcts"
|
||||
|
||||
//// t_dav_use_dir
|
||||
#define KEY_DIR_USED "dir_used"
|
||||
#define KEY_DEL_DIR_USED "del_yn"
|
||||
|
||||
//// meta table
|
||||
#define KEY_HOST_NAME "host_name"
|
||||
#define KEY_RESOURCE_TYPE "resource_type"
|
||||
#define KEY_FILENAME_HASH "filename_hash"
|
||||
#define KEY_GET_CONTENT_LENGTH "get_content_length"
|
||||
#define KEY_DEL_ROOT "del_yn"
|
||||
|
||||
///// internal data
|
||||
#define KEY_SYNC_LIST "sync_list"
|
||||
#define KEY_SELF_RCTS "self_rcts"
|
||||
#define KEY_LINK_USER_SEQ "linked_user_seq"
|
||||
|
||||
///// response
|
||||
#define KEY_RESP_RESULT "Result"
|
||||
#define KEY_RESP_RESULT_CODE "ResultCode"
|
||||
#define KEY_VOLUME_ID "VolumeID"
|
||||
#define KEY_VOLUME_SEQ "VolumeSEQ"
|
||||
|
||||
#define JOB_SUCCESS 0
|
||||
#define JOB_SKIP 1
|
||||
|
||||
#define JOX_RESULT_OK "OK"
|
||||
#define JOX_RESULT_FAIL "Failed"
|
||||
|
||||
///// Job Error
|
||||
#define JOB_ERR_UNKNOWN -1
|
||||
#define JOB_ERR_INITIALIZATION JOB_ERR_UNKNOWN-1
|
||||
#define JOB_ERR_CREATION_FAIL JOB_ERR_INITIALIZATION-1
|
||||
#define JOB_ERR_ALLOCATION_FAIL JOB_ERR_INITIALIZATION-2
|
||||
#define JOB_ERR_RCDB_BEGIN_TRANS JOB_ERR_INITIALIZATION-3
|
||||
#define JOB_ERR_RCDB_END_TRANS JOB_ERR_INITIALIZATION-4
|
||||
#define JOB_ERR_READ_HEADER JOB_ERR_INITIALIZATION-5
|
||||
#define JOB_ERR_READ_BODY JOB_ERR_INITIALIZATION-6
|
||||
#define JOB_ERR_CONVERT JOB_ERR_INITIALIZATION-7 // -9
|
||||
#define JOB_ERR_CHK -100
|
||||
#define JOB_ERR_CHK_USER JOB_ERR_CHK-1
|
||||
#define JOB_ERR_CHK_PRODUCT JOB_ERR_CHK-2
|
||||
#define JOB_ERR_CHK_ANOTHER_PRODUCT JOB_ERR_CHK-3
|
||||
#define JOB_ERR_CHK_PRODUCT_EXTAUTH JOB_ERR_CHK-4
|
||||
#define JOB_ERR_CHK_PRODUCT_BAND JOB_ERR_CHK-5
|
||||
#define JOB_ERR_CHK_PRODUCT_SYNC JOB_ERR_CHK-6
|
||||
#define JOB_ERR_CHK_VOLUME_INFO JOB_ERR_CHK-7
|
||||
#define JOB_ERR_CHK_ROOT_INFO JOB_ERR_CHK-8
|
||||
#define JOB_ERR_CHK_HAS_FILE JOB_ERR_CHK-9
|
||||
#define JOB_ERR_CHK_POLICY_IGNORECASE JOB_ERR_CHK-10
|
||||
#define JOB_ERR_CHK_FILE_INFO JOB_ERR_CHK-11
|
||||
#define JOB_ERR_CHK_PARENT JOB_ERR_CHK-12 // -112
|
||||
#define JOB_ERR_SET -200
|
||||
#define JOB_ERR_SET_USER JOB_ERR_SET-1
|
||||
#define JOB_ERR_SET_PRODUCT JOB_ERR_SET-2
|
||||
#define JOB_ERR_SET_PRODUCT_EXTAUTH JOB_ERR_SET-3
|
||||
#define JOB_ERR_SET_PRODUCT_BAND JOB_ERR_SET-4
|
||||
#define JOB_ERR_SET_PRODUCT_SYNC JOB_ERR_SET-5
|
||||
#define JOB_ERR_SET_PRODUCT_MOVE JOB_ERR_SET-6
|
||||
#define JOB_ERR_SET_VOLUME_INFO JOB_ERR_SET-7
|
||||
#define JOB_ERR_SET_ROOT_INFO JOB_ERR_SET-8
|
||||
#define JOB_ERR_SET_ANONY_DIR JOB_ERR_SET-9
|
||||
#define JOB_ERR_DEL_ROOT_INFO JOB_ERR_SET-10
|
||||
#define JOB_ERR_DEL_VOLUME_INFO JOB_ERR_SET-11
|
||||
#define JOB_ERR_DEL_PRODUCT_BAND JOB_ERR_SET-12
|
||||
#define JOB_ERR_DEL_PRODUCT_EXTAUTH JOB_ERR_SET-13
|
||||
#define JOB_ERR_DEL_PRODUCT_SYNC JOB_ERR_SET-14
|
||||
#define JOB_ERR_DEL_PRODUCT JOB_ERR_SET-15
|
||||
#define JOB_ERR_DEL_USER JOB_ERR_SET-16 // -216
|
||||
#define JOB_ERR_JOB -300
|
||||
#define JOB_ERR_NOT_FOUND_JOB JOB_ERR_JOB-1
|
||||
// 2015-03-11 dadamin
|
||||
// JOB_ERR_USER_EMPTY(-302), JOB_ERR_PRODUCT_EMPTY(-303) 값은
|
||||
// WebAdmin에서 참조 하므로 해당 값은 변경될 수 없음
|
||||
#define JOB_ERR_USER_EMPTY JOB_ERR_JOB-2
|
||||
#define JOB_ERR_PRODUCT_EMPTY JOB_ERR_JOB-3
|
||||
#define JOB_ERR_USER_DIFF JOB_ERR_JOB-4
|
||||
#define JOB_ERR_PRODUCT_DIFF JOB_ERR_JOB-5
|
||||
#define JOB_ERR_MISS_PASSWROD JOB_ERR_JOB-6
|
||||
#define JOB_ERR_MK_ROOT JOB_ERR_JOB-7
|
||||
#define JOB_ERR_GET_VOLUME_INFO JOB_ERR_JOB-8
|
||||
#define JOB_ERR_REQ_EXCEED JOB_ERR_JOB-9
|
||||
#define JOB_ERR_GET_ANONY_DIR JOB_ERR_JOB-10
|
||||
#define JOB_ERR_SEND_ANONY_DIR JOB_ERR_JOB-11
|
||||
#define JOB_ERR_HAS_FILE JOB_ERR_JOB-12 // - 312
|
||||
#define JOB_ERR_FILE -400
|
||||
#define JOB_ERR_FILE_HASH JOB_ERR_FILE-1
|
||||
#define JOB_ERR_FILE_EXIST JOB_ERR_FILE-2
|
||||
#define JOB_ERR_FILE_CHK_IGNORECASE JOB_ERR_FILE-3
|
||||
#define JOB_ERR_FILE_NOT_FOUND JOB_ERR_FILE-4
|
||||
#define JOB_ERR_FILE_MKDIR_PARENT JOB_ERR_FILE-5
|
||||
#define JOB_ERR_FILE_MKDIR JOB_ERR_FILE-6
|
||||
|
||||
class CJob;
|
||||
// Abstract Factory returning a Job
|
||||
class CJobFactory
|
||||
{
|
||||
public:
|
||||
CJob* CreateJob(CJobDataMap &jobMap);
|
||||
};
|
||||
|
||||
#endif // __JOB_DATA_H__
|
||||
@@ -0,0 +1,108 @@
|
||||
#****************************************************************************
|
||||
# Makefile for rc_mngd ( RC Management Daemon )
|
||||
# -----------------------------------------
|
||||
#
|
||||
# begin : 2013/02/13
|
||||
# copyright : (C) 2013 Solbox Inc.
|
||||
# author : Development 1 Team
|
||||
# - 2013/02/13 - 1st dadamin
|
||||
# email : dev1@solbox.com
|
||||
# version : 3.2.0
|
||||
#
|
||||
# CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
# Redistribution and use in source and binary forms, with or with out
|
||||
# modification, are not permitted in outside of Solbox Inc.
|
||||
#*****************************************************************************
|
||||
|
||||
# Program info
|
||||
PROG_NAME = rc_mngd
|
||||
REVISION = 1373
|
||||
BUILD_DATE = `date +%Y%m%d%H%M%S`
|
||||
PROG_VERSION = 3.5.0.$(REVISION)-$(BUILD_DATE)
|
||||
CONFIG_NAME = rcts.conf
|
||||
INSTALL_HOME = /user/service
|
||||
INSTALL_BIN = $(INSTALL_HOME)/bin
|
||||
INSTALL_CONFIG = $(INSTALL_HOME)/etc
|
||||
INSTALL_LOG_HOME = $(INSTALL_HOME)/logs
|
||||
DEFAULT_CONFIG_FILE = $(INSTALL_CONFIG)/$(CONFIG_NAME)
|
||||
|
||||
# Compiler info
|
||||
CC = /usr/bin/g++
|
||||
|
||||
CFLAGS = -Wall -O3 -g -Wreturn-type -Wunused -Wuninitialized\
|
||||
-Wparentheses -Wshadow -Wpointer-arith -Woverloaded-virtual\
|
||||
-minline-all-stringops -fstack-protector-all\
|
||||
-D_THREAD_SAFE -D_REENTRANT -D_PTHREADS -Wno-unused -Wno-non-virtual-dtor
|
||||
|
||||
LFLAGS = --fast-math -march=native
|
||||
|
||||
# DEBUG or RELEASE Mode select
|
||||
ifeq ($(DEBUG), yes)
|
||||
PROG_VERSION = 3.3.0.$(REVISION)D-$(BUILD_DATE)
|
||||
|
||||
CFLAGS = -Wall -O0 -g -Wreturn-type -Wunused\
|
||||
-Wparentheses -Wshadow -Wpointer-arith -Woverloaded-virtual\
|
||||
-minline-all-stringops -fstack-protector-all\
|
||||
-fno-rtti -D_THREAD_SAFE -D_REENTRANT -D_PTHREADS -Wno-unused -Wno-non-virtual-dtor\
|
||||
|
||||
DFLAGS = -D_DEBUG -DPROG_NAME=\"$(PROG_NAME)\" -DPROG_VERSION=\"$(PROG_VERSION)\"\
|
||||
-DDEFAULT_CONFIG_FILE=\"$(DEFAULT_CONFIG_FILE)\"
|
||||
else
|
||||
DFLAGS = -DPROG_NAME=\"$(PROG_NAME)\" -DPROG_VERSION=\"$(PROG_VERSION)\"\
|
||||
-DDEFAULT_CONFIG_FILE=\"$(DEFAULT_CONFIG_FILE)\"
|
||||
endif
|
||||
|
||||
|
||||
# Application Enviroment
|
||||
APP = $(PROG_NAME)
|
||||
|
||||
#XML EVIRONMENT VARIABLE
|
||||
XML++_INCLUDES = `pkg-config libxml++-2.6 --cflags`
|
||||
XML++_LIBS = `pkg-config libxml++-2.6 --libs`
|
||||
|
||||
DIR_LIB = -L../lib
|
||||
DIR_INCLUDE = -I./. -I../lib -I/user/db/pgsql/include ${XML++_INCLUDES}
|
||||
|
||||
#LIBS = -lpthread -lssl ../lib/libInterCommon.a /user/db/pgsql/lib/libpq.a ${XML++_LIBS}
|
||||
LIBS = -lpthread -lssl -lcrypto ../lib/libInterCommon.a /user/db/pgsql/lib/libpq.a ${XML++_LIBS}
|
||||
|
||||
OBJ = Job.o Convert.o JobData.o FtsdSocketControl.o FhsControl.o DbConnPool.o\
|
||||
Database.o RCDBControl.o SocketControl.o JobControl.o Parser.o Client.o\
|
||||
UtilFn.o Service.o Worker.o Signals.o Configs.o ArgParser.o main.o\
|
||||
ConvertServiceOpen.o ServiceOpen.o\
|
||||
ConvertServiceChange.o ServiceChange.o\
|
||||
ConvertVolumeInfo.o VolumeInfo.o\
|
||||
ConvertAnonymousDir.o AnonymousDir.o\
|
||||
ConvertFileControl.o FileControl.o\
|
||||
ConvertReqServiceMove.o ConvertReqServiceLink.o\
|
||||
RcMngdControl.o\
|
||||
|
||||
############################
|
||||
|
||||
all:$(APP)
|
||||
sync
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) $(CFLAGS) -o $@ -c $^ $(DFLAGS) $(DIR_INCLUDE)
|
||||
|
||||
$(PROG_NAME): $(OBJ)
|
||||
$(CC) $(LFLAGS) -o $@ $^ $(DFLAGS) $(DIR_LIB) $(LIBS)
|
||||
|
||||
clean:
|
||||
-rm -f *.o *.core core.* .out *.log
|
||||
-rm -f $(APP)
|
||||
-rm -f $(DUMP_PATH)/core.*
|
||||
sync
|
||||
|
||||
|
||||
install : $(APP)
|
||||
-mkdir -p $(INSTALL_HOME)
|
||||
-mkdir -p $(INSTALL_BIN)
|
||||
-mkdir -p $(INSTALL_CONFIG)
|
||||
-mkdir -p $(INSTALL_LOG_HOME)
|
||||
-mkdir -p $(DUMP_PATH)
|
||||
-cp -f $(APP) $(INSTALL_BIN)/$(APP)
|
||||
-cp -i ../conf/$(CONFIG_NAME) $(INSTALL_CONF)/$(CONFIG_NAME)
|
||||
sync
|
||||
|
||||
# End of Makefile
|
||||
@@ -0,0 +1,802 @@
|
||||
/***************************************************************************
|
||||
Parser Class (Parser.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/19
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/19 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Parser.h"
|
||||
#include "Service.h"
|
||||
#include "SocketControl.h"
|
||||
#include "Convert.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// CParser
|
||||
CParser::CParser()
|
||||
: m_sock(NULL), m_resp(JOB_ERR_UNKNOWN)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CParser::~CParser()
|
||||
{
|
||||
if(m_sock)
|
||||
delete m_sock;
|
||||
}
|
||||
|
||||
int CParser::SetSocket(int sfd, SSL* ssl)
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
if(m_sock != NULL)
|
||||
{
|
||||
msg << "The socket is already assigned." ;
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_sock = new CSocketControl(sfd, ssl);
|
||||
if( m_sock == NULL)
|
||||
{
|
||||
msg << "Socket allocation failed.[errno:" << errno << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_sock->SetOption();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CXMLParser
|
||||
CXMLParser::CXMLParser()
|
||||
: m_pBodyData(NULL), m_Job(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CXMLParser::~CXMLParser()
|
||||
{
|
||||
if(m_pBodyData)
|
||||
delete [] m_pBodyData;
|
||||
}
|
||||
|
||||
int CXMLParser::ReadHeader()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "XML Parser : ReadHeader()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
int n = m_sock->ReadData(&m_header, sizeof m_header);
|
||||
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "XML Parser : GetHeader() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
else if ( n == 0 )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_header.ulBodyLength = ntohl(m_header.ulBodyLength);
|
||||
}
|
||||
|
||||
msg << "XML Parser ReadHeader Data: " << m_header.ulBodyLength;
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CXMLParser::Parsering(const char * pstrxml)
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
try
|
||||
{
|
||||
m_xmlparser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
|
||||
m_xmlparser.parse_memory(pstrxml);
|
||||
if (m_xmlparser)
|
||||
{
|
||||
// check xml verify and get job
|
||||
if (!GetXMJobLNode())
|
||||
{
|
||||
msg << "Failure to acquire a job of requests.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
msg << "XML Parsing Exception caught: " << ex.what();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -3;
|
||||
}
|
||||
|
||||
msg << "XML Parsing unknown error.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CXMLParser::ReadBody()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "XML Parser : ReadBody()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
m_pBodyData = new BYTE [m_header.ulBodyLength +1];
|
||||
|
||||
int n = m_sock->ReadData(m_pBodyData, m_header.ulBodyLength);
|
||||
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "XML Parser : ReadBody() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBodyData[m_header.ulBodyLength]= '\0';
|
||||
}
|
||||
|
||||
msg << "XML Parser : Body Data [" << m_sock->GetMyIPString() << "]";
|
||||
LOGACONSOLE(LINF, msg);
|
||||
msg << "################ Data Start ################";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
msg << "################ Text ################" << endl;
|
||||
msg << (char*) m_pBodyData;
|
||||
LOGACONSOLE(LINF, msg);
|
||||
msg << "################ Binary ################";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
_LOG_HEX_(LDBG, m_pBodyData, m_header.ulBodyLength);
|
||||
msg << "################ Data End ################";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
return Parsering((char*)m_pBodyData);
|
||||
}
|
||||
|
||||
bool CXMLParser::GetXMJobLNode()
|
||||
{
|
||||
bool r = true;
|
||||
|
||||
ostringstream msg;
|
||||
try
|
||||
{
|
||||
xmlpp::Document *doc = m_xmlparser.get_document();
|
||||
xmlpp::Element *root = doc->get_root_node();
|
||||
|
||||
// check root
|
||||
if(root->get_name() != XML_STR_ROOT)
|
||||
{
|
||||
r = false;
|
||||
msg << "XML root node different.[" << root->get_name() << ","
|
||||
<< PROG_NAME <<"]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlpp::Node::NodeList request = root->get_children(XML_STR_JOB);
|
||||
|
||||
// check value
|
||||
if( request.size() != 1 )
|
||||
{
|
||||
r = false;
|
||||
msg << "Request empty or 1 over.[size :"<< request.size() << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg << "Request size.[" << request.size() << "]" ;
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
m_Job = request.front();
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
r = false;
|
||||
msg << "XML Parsing Exception caught: " << ex.what();
|
||||
LOGACONSOLE(LERR, msg);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CXMLParser::ConvertJobData(void *pData)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "XML Parser : Convert Job Data";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CConvertFactory f;
|
||||
|
||||
// Body type
|
||||
CConvert * convert = f.CreateConvert(const_cast<xmlpp::Node*>(m_Job), pData);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
int r = convert->ToJobData(CServiceInfo::XML, m_Job, pData);
|
||||
|
||||
delete convert;
|
||||
|
||||
return (r >= 0 ? 0 : -1 );
|
||||
}
|
||||
|
||||
int CXMLParser::ConvertClient(void *pData, int nCode/* = 0*/)
|
||||
{
|
||||
int r = 0;
|
||||
CConvertFactory f;
|
||||
ostringstream msg;
|
||||
|
||||
CConvert * convert = f.CreateConvert(m_Job, pData);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
if(m_pBodyData)
|
||||
{
|
||||
delete [] m_pBodyData;
|
||||
m_pBodyData = NULL;
|
||||
}
|
||||
|
||||
m_resp = convert->ToClientResult(CServiceInfo::XML, nCode);
|
||||
m_pBodyData = (BYTE *) convert->ToClientData(CServiceInfo::XML, nCode, pData, r);
|
||||
|
||||
delete convert;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CXMLParser::WriteHeader(int32_t bodylen /* = 0 */)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
m_header.ulBodyLength = htonl(bodylen) ;
|
||||
|
||||
if( m_sock->WriteData(&m_header , sizeof m_header) < 0 )
|
||||
{
|
||||
msg << "XML Parser : WriteHeader() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CXMLParser::WriteBoad(int32_t bodylen)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
if( m_sock->WriteData(m_pBodyData , bodylen) < 0 )
|
||||
{
|
||||
msg << "XML Parser : WriteBoad() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// CSDKParser
|
||||
CSDKParser::CSDKParser()
|
||||
: m_pBodyData(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSDKParser::~CSDKParser()
|
||||
{
|
||||
if(m_pBodyData)
|
||||
delete [] m_pBodyData;
|
||||
}
|
||||
|
||||
int CSDKParser::ReadHeader()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "SDK Parser : ReadHeader()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
int n = m_sock->ReadData(&m_header, sizeof m_header) ;
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "SDK Parser : ReadHeader() Error.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
else if( n == 0 )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_header.ulMode = ntohl(m_header.ulMode);
|
||||
m_header.ulResult = ntohl(m_header.ulResult);
|
||||
m_header.ulBodyLength = ntohl(m_header.ulBodyLength);
|
||||
}
|
||||
|
||||
|
||||
msg << "SDK Parser ReadHeader Data: " << m_header.szTransactionID << ","
|
||||
<< m_header.ulMode << "," << m_header.szIssuer << ","
|
||||
<< m_header.szServiceID << "," << m_header.ulResult << ","
|
||||
<< m_header.ulBodyLength;
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CSDKParser::ReadBody()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "SDK Parser : ReadtBoad()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
m_pBodyData = new BYTE[m_header.ulBodyLength+1];
|
||||
|
||||
int n = m_sock->ReadData(m_pBodyData, m_header.ulBodyLength);
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "SDK Parser : ReadtBoad() Error.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBodyData[m_header.ulBodyLength] = '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CSDKParser::ConvertJobData(void *pData)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "SDK Parser : Convert Job Data";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CConvertFactory f;
|
||||
|
||||
// Body type
|
||||
CConvert * convert = f.CreateConvert(m_header.ulMode);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
int r = convert->ToJobData(CServiceInfo::SDK, m_pBodyData, pData);
|
||||
|
||||
delete convert;
|
||||
|
||||
return (r >= 0 ? 0 : -1 );
|
||||
}
|
||||
|
||||
int CSDKParser::ConvertClient(void *pData, int nCode /*= 0*/)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
ostringstream msg;
|
||||
msg << "SDK Parser : Convert Client Data";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CConvertFactory f;
|
||||
|
||||
// Body type
|
||||
CConvert * convert = f.CreateConvert(m_header.ulMode);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
if(m_pBodyData)
|
||||
{
|
||||
delete [] m_pBodyData;
|
||||
m_pBodyData = NULL;
|
||||
}
|
||||
|
||||
m_resp = convert->ToClientResult(CServiceInfo::SDK, nCode);
|
||||
m_pBodyData = (BYTE*) convert->ToClientData(CServiceInfo::SDK, nCode, pData ,r);
|
||||
|
||||
if( r > 0 && m_pBodyData )
|
||||
{
|
||||
LOG(LDBG, "ConvertClient : %s, %d", (char *)m_pBodyData, r);
|
||||
}
|
||||
|
||||
delete convert;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CSDKParser::WriteHeader(int32_t bodylen /* = 0 */)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
m_header.szTransactionID;
|
||||
m_header.ulMode = htonl(m_header.ulMode);
|
||||
strcpy(m_header.szIssuer, PROG_NAME);
|
||||
m_header.szServiceID;
|
||||
|
||||
m_header.ulResult = htonl(m_resp);
|
||||
|
||||
m_header.ulBodyLength = htonl(bodylen);
|
||||
|
||||
LOG(LDBG, "WriteHeader : %s, 0X%0X, %d",m_header.szTransactionID,
|
||||
ntohl(m_header.ulResult), bodylen );
|
||||
|
||||
if( m_sock->WriteData(&m_header , sizeof m_header) < 0 )
|
||||
{
|
||||
msg << "SDK Parser : WriteHeader() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CSDKParser::WriteBoad(int32_t bodylen)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
LOG(LDBG, "WriteBoad : %s",(char *) m_pBodyData);
|
||||
|
||||
if( m_sock->WriteData(m_pBodyData, bodylen) < 0 )
|
||||
{
|
||||
msg << "SDK Parser : WriteBoad() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// CEtcParser
|
||||
CEtcParser::CEtcParser()
|
||||
: m_pBodyData(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEtcParser::~CEtcParser()
|
||||
{
|
||||
if(m_pBodyData)
|
||||
delete [] m_pBodyData;
|
||||
}
|
||||
|
||||
int CEtcParser::ReadHeader()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Etc Parser : ReadHeader()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
int n = m_sock->ReadData(&m_header, sizeof m_header) ;
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "Etc Parser : ReadHeader() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
else if ( n == 0 )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_header.op_num = ntohl(m_header.op_num);
|
||||
m_header.op_ret_code = ntohl(m_header.op_ret_code);
|
||||
}
|
||||
|
||||
|
||||
msg << "SDK Parser ReadHeader Data: " << m_header.op_num << ","
|
||||
<< m_header.op_ret_code;
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CEtcParser::ReadBody()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Etc Parser : ReadBoyd()";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
size_t len = 0;
|
||||
switch(m_header.op_num)
|
||||
{
|
||||
case ETC_REQ_GETFILE_HASH_MD5_10MB:
|
||||
len = sizeof(EtcReqBodyMD5_10MB);
|
||||
break;
|
||||
default:
|
||||
msg << "Etc Parser : Body type is unknown.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
m_pBodyData = new BYTE[len+1];
|
||||
int n = m_sock->ReadData(m_pBodyData, len);
|
||||
if( n < 0 )
|
||||
{
|
||||
msg << "Etc Parser : ReadBody() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBodyData[len] = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CEtcParser::ConvertJobData(void *pData)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Etc Parser : Convert Job Data";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CConvertFactory f;
|
||||
|
||||
// Body type
|
||||
CConvert * convert = f.CreateConvert(m_header.op_num);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
int r = convert->ToJobData(CServiceInfo::ETC, m_pBodyData, pData);
|
||||
|
||||
delete convert;
|
||||
|
||||
return (r >= 0 ? 0 : -1 );
|
||||
}
|
||||
|
||||
int CEtcParser::ConvertClient(void *pData, int nCode /*= 0*/)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
ostringstream msg;
|
||||
msg << "ETC Parser : Convert Client Data";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CConvertFactory f;
|
||||
|
||||
// Body type
|
||||
CConvert * convert = f.CreateConvert(m_header.op_num);
|
||||
if(convert == NULL)
|
||||
{
|
||||
// error
|
||||
msg << "Convert Object creation fail.";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
if(m_pBodyData)
|
||||
{
|
||||
delete [] m_pBodyData;
|
||||
m_pBodyData = NULL;
|
||||
}
|
||||
|
||||
m_resp = convert->ToClientResult(CServiceInfo::ETC, nCode);
|
||||
m_pBodyData = (BYTE*) convert->ToClientData(CServiceInfo::ETC, nCode, pData ,r);
|
||||
|
||||
if( r > 0 && m_pBodyData )
|
||||
{
|
||||
LOG(LDBG, "ConvertClient : %s, %d", (char *)m_pBodyData, r);
|
||||
}
|
||||
|
||||
delete convert;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CEtcParser::WriteHeader(int32_t bodylen /* = 0 */)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
m_header.op_num = htonl(m_header.op_num);
|
||||
|
||||
m_header.op_ret_code = htonl(m_resp);
|
||||
|
||||
LOG(LDBG, "WriteHeader : %d, %d", htonl(m_header.op_num), ntohl(m_header.op_ret_code));
|
||||
|
||||
if( m_sock->WriteData(&m_header , sizeof m_header) < 0 )
|
||||
{
|
||||
msg << "Etc Parser : WriteHeader() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CEtcParser::WriteBoad(int32_t bodylen)
|
||||
{
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
LOG(LDBG, "WriteBoad : %s",(char *) m_pBodyData);
|
||||
|
||||
if( m_sock->WriteData(m_pBodyData, bodylen) < 0 )
|
||||
{
|
||||
msg << "ETC Parser : WriteBoad() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// CStrXMLParser
|
||||
CStrXMLParser::CStrXMLParser()
|
||||
{
|
||||
}
|
||||
|
||||
CStrXMLParser::~CStrXMLParser()
|
||||
{
|
||||
}
|
||||
|
||||
int CStrXMLParser::ReadHeader()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CStrXMLParser::ReadBody()
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
const size_t buffsize = 1024;
|
||||
char buff[buffsize+1] = { 0 };
|
||||
ssize_t r = 0;
|
||||
|
||||
string::size_type offset = 0;
|
||||
|
||||
// 통신 종단 메시지
|
||||
string findString = "\\n\\n";
|
||||
string findString2 = "\n\n";
|
||||
while ((r = m_sock->ReadDataEx(buff, buffsize)) > 0)
|
||||
{
|
||||
buff[r] = '\0';
|
||||
m_readdata.append(buff);
|
||||
|
||||
// 2016.05.11 토토디스트 ASP와 통신 종단 메세지 처리
|
||||
offset = m_readdata.find(findString);
|
||||
if (offset != string::npos)
|
||||
{
|
||||
m_readdata.replace(offset, findString.length(), "\n");
|
||||
break;
|
||||
}
|
||||
|
||||
offset = m_readdata.find(findString2);
|
||||
if (offset != string::npos)
|
||||
{
|
||||
m_readdata.replace(offset, findString2.length(), "\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
msg << "XML Parser : Body Data [" << m_sock->GetMyIPString() << "]";
|
||||
LOGACONSOLE(LINF, msg);
|
||||
msg << "################ Data Start ################";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
msg << "################ Text ################" << endl;
|
||||
msg << m_readdata;
|
||||
LOGACONSOLE(LINF, msg);
|
||||
msg << "################ Data End ################";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
|
||||
return Parsering(m_readdata.c_str());
|
||||
}
|
||||
|
||||
int CStrXMLParser::ConvertJobData(void *pData)
|
||||
{
|
||||
return CXMLParser::ConvertJobData(pData);
|
||||
}
|
||||
|
||||
int CStrXMLParser::ConvertClient(void *pData, int nCode /* = 0 */)
|
||||
{
|
||||
return CXMLParser::ConvertClient(pData, nCode);
|
||||
}
|
||||
|
||||
int CStrXMLParser::WriteHeader(int32_t bodylen /* = 0 */)
|
||||
{
|
||||
//return 0;
|
||||
return CXMLParser::WriteBoad(bodylen);
|
||||
}
|
||||
|
||||
int CStrXMLParser::WriteBoad(int32_t bodylen /* = 0 */)
|
||||
{
|
||||
//return CXMLParser::WriteBoad(bodylen);
|
||||
int r = 0;
|
||||
ostringstream msg;
|
||||
|
||||
string s = "\n";
|
||||
|
||||
if (m_sock->WriteData((void*)s.c_str(), s.size()) < 0)
|
||||
{
|
||||
msg << "XML Parser : WriteBoad() Error.";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// Abstract Factory returning a Parser
|
||||
CParser* CParserFactory::CreateParser(CServiceInfo &info)
|
||||
{
|
||||
switch(info.m_type)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
_LOG( LDBG, "Parser Factory [type:XML,Port:%d]", info.m_port );
|
||||
return new CXMLParser();
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
_LOG( LDBG, "Parser Factory [type:SDK,Port:%d]", info.m_port );
|
||||
return new CSDKParser();
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
_LOG( LDBG, "Parser Factory [type:ETC,Port:%d]", info.m_port );
|
||||
return new CEtcParser();
|
||||
break;
|
||||
case CServiceInfo::STR:
|
||||
_LOG(LDBG, "Parser Factory [type:STR,Port:%d]", info.m_port);
|
||||
return new CStrXMLParser();
|
||||
break;
|
||||
default:
|
||||
LOG(LERR, "Parser type is unknown.");
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/***************************************************************************
|
||||
Parser Class Header ( Parser.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/19
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/19 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __PARSER_H__
|
||||
#define __PARSER_H__
|
||||
|
||||
// XML
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <libxml++/libxml++.h>
|
||||
|
||||
#include "Protocol.h"
|
||||
|
||||
///< BYTE ŸÀÔ Á¤ÀÇ
|
||||
#ifndef _BYTE_DEFINED
|
||||
#define _BYTE_DEFINED
|
||||
typedef unsigned char BYTE;
|
||||
#endif // _BYTE_DEFINED
|
||||
|
||||
class CServiceInfo;
|
||||
class CSocketControl;
|
||||
|
||||
// Parser Class
|
||||
class CParser
|
||||
{
|
||||
public:
|
||||
CParser();
|
||||
virtual ~CParser();
|
||||
|
||||
int SetSocket(int sfd, SSL* ssl);
|
||||
virtual int ReadHeader() = 0;
|
||||
virtual int ReadBody() = 0;
|
||||
|
||||
virtual int ConvertJobData(void *pData) = 0;
|
||||
|
||||
virtual int WriteHeader(int32_t bodylen = 0) = 0;
|
||||
virtual int WriteBoad(int32_t bodylen = 0) = 0;
|
||||
|
||||
virtual int ConvertClient(void *pData, int nCode = 0) = 0;
|
||||
protected:
|
||||
CSocketControl * m_sock;
|
||||
int32_t m_resp;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class CXMLParser : public CParser
|
||||
{
|
||||
public:
|
||||
CXMLParser();
|
||||
virtual ~CXMLParser();
|
||||
|
||||
virtual int ReadHeader() ;
|
||||
virtual int ReadBody();
|
||||
|
||||
virtual int ConvertJobData(void *pData);
|
||||
|
||||
virtual int WriteHeader(int32_t bodylen = 0);
|
||||
virtual int WriteBoad(int32_t bodylen = 0);
|
||||
|
||||
virtual int ConvertClient(void *pData, int nCode = 0);
|
||||
|
||||
xmlpp::Node* GetXMLJobNode() { return m_Job; }
|
||||
protected:
|
||||
bool GetXMJobLNode();
|
||||
int Parsering(const char * pstrxml);
|
||||
|
||||
private:
|
||||
MgeHeaderXML m_header;
|
||||
BYTE* m_pBodyData;
|
||||
|
||||
xmlpp::DomParser m_xmlparser;
|
||||
//xmlpp::Node::NodeList m_reqList;
|
||||
xmlpp::Node* m_Job;
|
||||
};
|
||||
|
||||
class CSDKParser : public CParser
|
||||
{
|
||||
public:
|
||||
CSDKParser();
|
||||
virtual ~CSDKParser();
|
||||
|
||||
virtual int ReadHeader();
|
||||
virtual int ReadBody();
|
||||
|
||||
virtual int ConvertJobData(void *pData);
|
||||
|
||||
virtual int WriteHeader(int32_t bodylen = 0);
|
||||
virtual int WriteBoad(int32_t bodylen = 0);
|
||||
|
||||
virtual int ConvertClient(void *pData, int nCode = 0);
|
||||
protected:
|
||||
|
||||
private:
|
||||
MgeHeaderSDK m_header;
|
||||
BYTE* m_pBodyData;
|
||||
};
|
||||
|
||||
class CEtcParser : public CParser
|
||||
{
|
||||
public:
|
||||
CEtcParser();
|
||||
virtual ~CEtcParser();
|
||||
|
||||
virtual int ReadHeader();
|
||||
virtual int ReadBody();
|
||||
|
||||
virtual int ConvertJobData(void *pData);
|
||||
|
||||
virtual int WriteHeader(int32_t bodylen = 0);
|
||||
virtual int WriteBoad(int32_t bodylen = 0);
|
||||
|
||||
virtual int ConvertClient(void *pData, int nCode = 0);
|
||||
protected:
|
||||
|
||||
private:
|
||||
MgeHeaderEtc m_header;
|
||||
BYTE* m_pBodyData;
|
||||
};
|
||||
|
||||
class CStrXMLParser : public CXMLParser
|
||||
{
|
||||
public:
|
||||
CStrXMLParser();
|
||||
virtual ~CStrXMLParser();
|
||||
|
||||
virtual int ReadHeader();
|
||||
virtual int ReadBody();
|
||||
|
||||
virtual int ConvertJobData(void *pData);
|
||||
|
||||
virtual int WriteHeader(int32_t bodylen = 0);
|
||||
virtual int WriteBoad(int32_t bodylen = 0);
|
||||
|
||||
virtual int ConvertClient(void *pData, int nCode = 0);
|
||||
protected:
|
||||
|
||||
private:
|
||||
string m_readdata;
|
||||
};
|
||||
|
||||
// Abstract Factory returning a Parser
|
||||
class CParserFactory
|
||||
{
|
||||
public:
|
||||
CParser* CreateParser(CServiceInfo &info);
|
||||
};
|
||||
#endif // __PARSER_H__
|
||||
@@ -0,0 +1,251 @@
|
||||
/***************************************************************************
|
||||
Protocol Header ( Protocol.h )
|
||||
-----------------------------------------
|
||||
begin : 2013/02/23
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2011 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __RC_MMNGD_PROTOCOL_H__
|
||||
#define __RC_MMNGD_PROTOCOL_H__
|
||||
|
||||
// protocol
|
||||
#define ID_DELIMITER "@"
|
||||
/// Client <-> rc_mngd
|
||||
//// XML
|
||||
typedef struct _s_message_header_xml
|
||||
{
|
||||
uint32_t ulBodyLength;
|
||||
_s_message_header_xml ()
|
||||
: ulBodyLength(-1) {};
|
||||
} MgeHeaderXML;
|
||||
|
||||
///// XML name
|
||||
#define XML_STR_ROOT "CloudStorage"
|
||||
#define XML_STR_JOB "Job"
|
||||
#define XML_STR_JOB_TYPE "Type"
|
||||
#define XML_STR_JOB_TYPE_LIST "List"
|
||||
#define XML_STR_USER_ID "UserID"
|
||||
#define XML_STR_USER_SEQ "USER_SEQ"
|
||||
#define XML_STR_USER_PASSWORD "Password"
|
||||
#define XML_STR_SVC_ID "ServiceID"
|
||||
#define XML_STR_SVC_SEQ "SVC_SEQ"
|
||||
#define XML_STR_SVC_STGSIZE "StgSize"
|
||||
#define XML_STR_SVC_SERVICEDATE "ServiceDate"
|
||||
#define XML_STR_SVC_START_DATE "StartDate"
|
||||
#define XML_STR_SVC_END_DATE "EndDate"
|
||||
#define XML_STR_SVC_AUTHSTRING "SvcAuthString"
|
||||
#define XML_STR_SVC_PRIVATEKEY "SvcPrivatekey"
|
||||
#define XML_STR_SVC_REPLICA "Replica"
|
||||
#define XML_STR_SVC_URIIGNORECASE "UriIgnoreCase"
|
||||
#define XML_STR_SVC_URIIGNORECASEFRORCE "UriIgnoreCaseForce"
|
||||
#define XML_STR_SVC_DELFILEKEEPTIME "DelFileKeepTime"
|
||||
#define XML_STR_SVC_USEDSIZECALCDEPTH "UsedSizeCalcDepth"
|
||||
#define XML_STR_SVC_MASTERSERVICEID "MasterServiceID"
|
||||
#define XML_STR_SVC_DOMAIN "Service_Domain"
|
||||
#define XML_STR_SVC_SYNC_LINK "SyncLink"
|
||||
#define XML_STR_SVC_MOVE_REQ "MoveRequest"
|
||||
#define XML_STR_SVC_MOVE_COPM "MoveComplete"
|
||||
#define XML_STR_ETC "Etc"
|
||||
#define XML_STR_VOLUME_ID "VolumeID"
|
||||
#define XML_STR_VOLUME_SEQ "VolumeSEQ"
|
||||
#define XML_STR_TRAFFICLIMIT_YN "TrafficLimit_YN"
|
||||
#define XML_STR_TRAFFICLIMIT "TrafficLimit"
|
||||
#define XML_STR_SVC_CUSTOMAUTH "CustomAuth"
|
||||
#define XML_STR_CUSTOMAUTH_YN "CustomAuth_YN"
|
||||
#define XML_STR_CUSTOMAUTH_MODE "CustomAuth_Mode"
|
||||
#define XML_STR_AUTHSERVER "AuthServer"
|
||||
#define XML_STR_AUTHPATH "AuthPath"
|
||||
#define XML_STR_AUTHPORT "AuthPort"
|
||||
#define XML_STR_AUTHTIMEOUT "AuthTimeOut"
|
||||
#define XML_STR_BILLSERVER "BillServer"
|
||||
#define XML_STR_BILLPATH "BillPath"
|
||||
#define XML_STR_BILLPORT "BillPort"
|
||||
#define XML_STR_BILLTIMEOUT "BillTimeOut"
|
||||
#define XML_STR_SVC_STATUS "ServiceStatus"
|
||||
#define XML_STR_STATUSCODE "StatusCode"
|
||||
#define XML_STR_RESULT "Result"
|
||||
#define XML_STR_RESULT_CODE "ResultCode"
|
||||
#define XML_STR_SELF_RCTS "SelfRCTS"
|
||||
#define XML_STR_LINK_MASTER_YN "Master_YN"
|
||||
#define XML_STR_LINK_USER_SEQ "LinkUserSeq"
|
||||
#define XML_STR_LINK_SERVICE_SEQ "LinkServiceSeq"
|
||||
#define XML_STR_LINK_RCTS "LinkRCTS"
|
||||
#define XML_STR_LINK_CODE "LinkCode"
|
||||
#define XML_STR_LINK_ONE_WAY "LinkOneWay"
|
||||
#define XML_STR_MOVE_NOW_RCTS "NowRCTS"
|
||||
#define XML_STR_MOVE_NEW_RCTS "NewRCTS"
|
||||
#define XML_STR_FILE_EXIST "Exist"
|
||||
#define XML_STR_FILE_MKDIR "mkdir"
|
||||
#define XML_STR_FILE_FRONT_10M_MD5 "Front_10M_MD5"
|
||||
#define XML_STR_FILE_TOTO_EXTRACT "TotoExtract"
|
||||
#define XML_STR_FILE_TOTO_EXTRACT_WITHPLATFORM XML_STR_FILE_TOTO_EXTRACT"_withplatform"
|
||||
#define XML_STR_FILE_URI "URI"
|
||||
#define XML_STR_FILE_SIZE "FileSize"
|
||||
#define XML_STR_FILE_10M_MD5 "10M_MD5"
|
||||
#define XML_STR_TOTO_MD5 "Toto_MD5"
|
||||
#define XML_STR_TOTO_FILECHECKSUM "Toto_fileChecksum"
|
||||
#define XML_STR_TOTO_DNACHKKEY "Toto_DnaCheckKey"
|
||||
|
||||
|
||||
///// XML type
|
||||
#define XML_STR_TYPE_OPEN "Open"
|
||||
#define XML_STR_TYPE_OPEN_N_SYNC "OpenS"
|
||||
#define XML_STR_TYPE_MOVE "Move"
|
||||
#define XML_STR_TYPE_MOVE_N_SYNC "MoveS"
|
||||
#define XML_STR_TYPE_CHANGE "Change"
|
||||
#define XML_STR_TYPE_FILE "File"
|
||||
|
||||
|
||||
//// SDK
|
||||
#define MaxSizeOfTID 52
|
||||
#define MaxSizeOfIssuer 128
|
||||
#define MaxSizeOfSID 128
|
||||
|
||||
#define SDK_DELIMITER 0x1b
|
||||
|
||||
typedef struct _s_message_header_sdk
|
||||
{
|
||||
char szTransactionID[MaxSizeOfTID];
|
||||
uint32_t ulMode;
|
||||
char szIssuer[MaxSizeOfIssuer];
|
||||
char szServiceID[MaxSizeOfSID];
|
||||
uint32_t ulResult;
|
||||
uint32_t ulBodyLength;
|
||||
_s_message_header_sdk ()
|
||||
: ulMode(-1), ulResult(-1), ulBodyLength(-1)
|
||||
{
|
||||
memset(szTransactionID, 0, sizeof szTransactionID);
|
||||
memset(szIssuer, 0, sizeof szIssuer);
|
||||
memset(szServiceID, 0, sizeof szServiceID);
|
||||
};
|
||||
} MgeHeaderSDK;
|
||||
|
||||
typedef struct _s_req_sdk_sp_info_t
|
||||
{
|
||||
char szSpUserSeq[16];
|
||||
char szSpUserId[32];
|
||||
char szSpUserPassword[33];
|
||||
char szSpSvcTranId[32];
|
||||
char szSpSvcId[32];
|
||||
char szSpSvcBeginDate[32];
|
||||
char szSpSvcEndDate[32];
|
||||
char szInitialVector[28];
|
||||
char szPrivateKey[28];
|
||||
char szMaxBandwidth[38];
|
||||
char szVolQuota[52];
|
||||
char szSyncYN[2];
|
||||
_s_req_sdk_sp_info_t()
|
||||
{
|
||||
memset(szSpUserSeq, 0, sizeof szSpUserSeq); memset(szSpUserId, 0, sizeof szSpUserId);
|
||||
memset(szSpUserPassword, 0, sizeof szSpUserPassword); memset(szSpSvcTranId, 0, sizeof szSpSvcTranId);
|
||||
memset(szSpSvcId, 0, sizeof szSpSvcId); memset(szSpSvcBeginDate, 0, sizeof szSpSvcBeginDate);
|
||||
memset(szSpSvcEndDate, 0, sizeof szSpSvcEndDate); memset(szInitialVector, 0, sizeof szInitialVector);
|
||||
memset(szPrivateKey, 0, sizeof szPrivateKey); memset(szMaxBandwidth, 0, sizeof szMaxBandwidth);
|
||||
memset(szVolQuota, 0, sizeof szVolQuota); memset(szSyncYN, 0, sizeof szSyncYN);
|
||||
}
|
||||
|
||||
} SDKReqBodySpInfo;
|
||||
|
||||
///// body tyep
|
||||
#define SDK_REQ_OPEN_SERVICE 0x0002 // old : MSG_MODE_CCSYNC_RCSYNC_DATA_INPUT
|
||||
#define SDK_REQ_CHG_USER_INFO 0x001a // old : MSG_MODE_CCSYNC_RCSYNC_CHANGE_USER_DATA
|
||||
#define SDK_REQ_CHG_STORAGE 0x0201 // old : MSG_MODE_CCSYNC_RCSYNC_CHANGE_STORAGE
|
||||
#define SDK_REQ_CHG_BANDWIDTH 0x0204 // old : MSG_MODE_CCSYNC_RCSYNC_CHANGE_BANDWIDTH
|
||||
#define SDK_REQ_CHG_PERIOD 0x0207 // old : MSG_MODE_CCSYNC_RCSYNC_CHANGE_PERIOD
|
||||
#define SDK_REQ_CHG_AUTHINFO 0x020a // old : MSG_MODE_CCSYNC_RCSYNC_CHANGE_AUTHINFO
|
||||
#define SDK_REQ_VOLUME_INFO 0x0012 // old : MSG_MODE_SPCONS_RCTRAN_VOLUME_SIZE
|
||||
#define SDK_REQ_SET_ANONY_DIR 0x0014 // old : MSG_MODE_SPCONS_RCTRAN_SET_ANONY
|
||||
#define SDK_REQ_UNSET_ANONY_DIR 0x0018 // old : MSG_MODE_SPCONS_RCTRAN_UNSET_ANONY
|
||||
#define SDK_REQ_ANONY_DIR 0x0030 // old : MSG_MODE_SPCONS_RCTRAN_RETRIVE_ANONY
|
||||
|
||||
///// Response code
|
||||
#define SDK_RES_OK_ALL_PASSED 0x1000 // old : OK_ALL_PASSED
|
||||
#define SDK_RES_SERVER_ERR 0x9000 // old : INT_ODINARY_STATE
|
||||
|
||||
//// ETC
|
||||
#define MAX_SIZE_OF_USERID 64
|
||||
#define MAX_SIZE_OF_FILENAME 2048
|
||||
#define MAX_SIZE_OF_FILESIZE 64
|
||||
#define MAX_SIZE_OF_HASH 128
|
||||
|
||||
typedef struct _s_message_header_etc
|
||||
{
|
||||
uint32_t op_num;
|
||||
uint32_t op_ret_code; // 요청시 0 세팅
|
||||
_s_message_header_etc ()
|
||||
: op_num(-1), op_ret_code(-1) {};
|
||||
} MgeHeaderEtc;
|
||||
|
||||
////// body type
|
||||
#define ETC_REQ_GETFILE_HASH_MD5_10MB 100 // old : REQ_GETFILE_HASH_MD5_10MB
|
||||
|
||||
typedef struct _s_etc_body_md5_10
|
||||
{
|
||||
char userid[MAX_SIZE_OF_USERID]; // 요청 userid
|
||||
char uri[MAX_SIZE_OF_FILENAME]; // 요청 uri
|
||||
char filesize[MAX_SIZE_OF_FILESIZE]; // 요청 컨텐츠의 파일 크기
|
||||
|
||||
_s_etc_body_md5_10 ()
|
||||
{
|
||||
memset(userid, 0, sizeof userid);
|
||||
memset(uri, 0, sizeof userid);
|
||||
memset(filesize, 0, sizeof filesize);
|
||||
};
|
||||
} EtcReqBodyMD5_10MB;
|
||||
|
||||
///// Response code
|
||||
#define ETC_RES_SUCCESS 0 // old : RESP_SUCCESS
|
||||
|
||||
///// Response type
|
||||
typedef struct _s_etc_md5_10_res {
|
||||
char userid[MAX_SIZE_OF_USERID]; // 요청 userid 그대로
|
||||
char uri[MAX_SIZE_OF_FILENAME]; // 요청 uri 그대로
|
||||
char hash[MAX_SIZE_OF_HASH]; // 추출 해쉬 값
|
||||
|
||||
_s_etc_md5_10_res()
|
||||
{
|
||||
memset(userid, 0, sizeof userid);
|
||||
memset(uri, 0, sizeof uri);
|
||||
memset(hash, 0, sizeof hash);
|
||||
};
|
||||
} EtcResBodyMD5_10MB;
|
||||
|
||||
/// RCTS <-> FHS
|
||||
//// RCTS -> vmasd
|
||||
///// body tyep
|
||||
#define BROADCAST_MKDIR_SERVICE_ROOT 0x0005 // old : MSG_MODE_RCTRAN_VMA_SUBROOT_CREATE
|
||||
|
||||
///// code
|
||||
#define OK_ALL_PASSED SDK_RES_OK_ALL_PASSED
|
||||
|
||||
//// RCTS -> opendav-listener
|
||||
///// body tyep
|
||||
#define BROADCAST_ANONY_SET 0x0015 // old : MSG_MODE_RCTRAN_APACHE_SET_ANONY
|
||||
#define BROADCAST_ANONY_UNSET 0x0019 // old : MSG_MODE_RCTRAN_APACHE_UNSET_ANONY
|
||||
|
||||
#define MaxSizeOfRCID 32
|
||||
typedef struct _s_broadcast_message_header
|
||||
{
|
||||
char szTransactionID[MaxSizeOfTID];
|
||||
uint32_t ulMode;
|
||||
char szIssuer[MaxSizeOfIssuer];
|
||||
char szServiceID[MaxSizeOfSID];
|
||||
char szRCID[MaxSizeOfRCID];
|
||||
uint32_t ulResult;
|
||||
uint32_t ulBodyLength;
|
||||
_s_broadcast_message_header()
|
||||
: ulMode(0), ulResult(0), ulBodyLength(0)
|
||||
{
|
||||
memset(szTransactionID, 0, sizeof szTransactionID);
|
||||
memset(szIssuer, 0, sizeof szIssuer);
|
||||
memset(szServiceID, 0, sizeof szServiceID);
|
||||
}
|
||||
} MsgHeaderBoardCast;
|
||||
|
||||
#endif // ___RC_MMNGD_PROTOCOL_H__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,131 @@
|
||||
/***************************************************************************
|
||||
RCDB Control Class Header ( RCDBControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __RCDB_CONTROL_H__
|
||||
#define __RCDB_CONTROL_H__
|
||||
|
||||
#include "JobData.h"
|
||||
|
||||
class DataBase;
|
||||
|
||||
class CRCDBControl
|
||||
{
|
||||
public:
|
||||
CRCDBControl();
|
||||
~CRCDBControl();
|
||||
|
||||
int Init();
|
||||
int Final();
|
||||
|
||||
bool BeginTrans();
|
||||
bool EndTrans();
|
||||
|
||||
bool GetVolumeInformation(CJobDataMap & jobData);
|
||||
bool GetAnonyDir(CJobDataMap & jobData, string targeturi, vector<string> & rdata);
|
||||
bool GetFileInfo(CJobDataMap & jobData, bool IgnoreCase = false);
|
||||
|
||||
bool CheckUserInfo(CJobDataMap & jobData, bool & exist); // check t_sms_sp_user
|
||||
bool CheckAnotherProduct(CJobDataMap & jobData, bool & exist); // check t_sms_sp_svc_product
|
||||
bool CheckProductInfo(CJobDataMap & jobData, bool & exist); // check t_sms_sp_svc_product
|
||||
bool CheckProductExtAuth(CJobDataMap & jobData, bool & exist); // check t_sms_sp_svc_product_val
|
||||
bool CheckProductExtBand(CJobDataMap & jobData, bool & exist); // check t_sms_sp_svc_product_band
|
||||
bool CheckProductSync(CJobDataMap & jobData, bool & exist); // check t_sms_sp_svc_product_sync
|
||||
bool CheckVolumeInfo(CJobDataMap & jobData, bool & exist); // check t_dav_use_dir
|
||||
bool CheckRootInfo(CJobDataMap & jobData, bool & exist); // check meta table
|
||||
bool CheckParentDir(CJobDataMap & jobData, bool & IgnoreCase); // check parent dir
|
||||
bool HasFile(CJobDataMap & jobData, bool & exist); // file in meta table
|
||||
bool CheckUriIgnoreCase(CJobDataMap & jobData, bool & IgnoreCase); // check uri ignore case
|
||||
bool GetTotalCntFiles(CJobDataMap & jobData, uint64_t & total, uint64_t limit = 0); // total count file
|
||||
bool GetServiceInfoAll(CJobDataMap & jobData); // get service information all
|
||||
bool GetSyncLink(CJobDataMap & jobData); // get sync link information of service
|
||||
|
||||
|
||||
bool SetUserInfo(CJobDataMap & jobData, bool & exist); // Set t_sms_sp_user
|
||||
bool SetProductInfo(CJobDataMap & jobData, bool & exist); // Set t_sms_sp_svc_product
|
||||
bool SetProductExtAuth(CJobDataMap & jobData, bool & exist); // Set t_sms_sp_svc_product_val
|
||||
bool SetProductBand(CJobDataMap & jobData, bool & exist); // Set t_sms_sp_svc_product_band
|
||||
bool SetProductSync(CJobDataMap & jobData, bool & exist); // Set t_sms_sp_svc_product_sync
|
||||
bool SetVolumeInfo(CJobDataMap & jobData, bool & exist); // Set t_dav_use_dir
|
||||
bool SetRootInfo(CJobDataMap & jobData, bool & exist); // Set meta table root
|
||||
bool SetAnonyDir(CJobDataMap & jobData, string targeturi, bool isdel = false); // Set t_dav_anonymous
|
||||
bool SetMetaIgnoreCase(CJobDataMap & jobData, bool IgnoreCase); // Set meta table ignore case
|
||||
bool MakeDir(CJobDataMap & jobData, string & spath, bool & IgnoreCase); // Make Dir
|
||||
bool DropMetaTable(CJobDataMap & jobData); // DROP meta table
|
||||
|
||||
inline void SetSuccess(bool success) { m_success = success; }
|
||||
inline bool IsSucces() { return m_success; }
|
||||
inline void SetUsed(short nMode ) { m_used = nMode; }
|
||||
inline short GetUsed() { return m_used; }
|
||||
void ForceClose();
|
||||
protected:
|
||||
// t_sms_sp_user
|
||||
bool InsertUerInfo(CJobDataMap & jobData);
|
||||
bool UpdateUserInfo(CJobDataMap & jobData);
|
||||
bool DeleteUserInfo(CJobDataMap & jobData);
|
||||
// t_sms_sp_svc_product
|
||||
bool InsertProductInfo(CJobDataMap & jobData);
|
||||
bool UpdateProductInfo(CJobDataMap & jobData);
|
||||
bool DeleteProductInfo(CJobDataMap & jobData);
|
||||
// t_sms_sp_svc_product_val
|
||||
bool InsertProductExtAuth(CJobDataMap & jobData);
|
||||
bool UpdateProductExtAuth(CJobDataMap & jobData);
|
||||
bool DeleteProductExtAuth(CJobDataMap & jobData);
|
||||
// t_sms_sp_svc_product_band
|
||||
bool InsertProductBand(CJobDataMap & jobData);
|
||||
bool UpdateProductBand(CJobDataMap & jobData);
|
||||
bool DeleteProductBand(CJobDataMap & jobData);
|
||||
// t_sms_sp_svc_product_sync
|
||||
bool InsertProductSync(CJobDataMap & jobData);
|
||||
bool DeleteProductSync(CJobDataMap & jobData);
|
||||
// t_dav_t_dav_use_dir
|
||||
bool InsertUseDir(CJobDataMap & jobData);
|
||||
bool DeleteUseDir(CJobDataMap & jobData);
|
||||
// meta table
|
||||
bool InsertRootInfo(CJobDataMap & jobData);
|
||||
bool UpdateRootInfo(CJobDataMap & jobData);
|
||||
bool DeleteRootInfo(CJobDataMap & jobData);
|
||||
// t_dav_anonymous
|
||||
bool DeleteAnonymous(CJobDataMap & jobData, string &targeturi);
|
||||
bool InsertAnonymous(CJobDataMap & jobData, string &targeturi);
|
||||
|
||||
bool CheckJobDataUserInfo(CJobDataMap & jobData, bool & hasuserseq, bool & hasuserid);
|
||||
bool CheckJobDataSvcProduct(CJobDataMap & jobData, bool & hastranid, bool & hassvcid);
|
||||
bool SetDB2JobData(bool & has, CJobDataMap & jobData, string valkey, const char * val);
|
||||
bool SetDB2JobData(CJobDataMap & jobData, string valkey, const char * val, bool force = false);
|
||||
|
||||
bool GetTargetFHS(string & targethost);
|
||||
|
||||
string InsertStr(CJobDataMap & jobData, const char* key, int index, const char **paramValues);
|
||||
string UpdateStr(CJobDataMap & jobData, const char* key, int index, const char **paramValues);
|
||||
string UpdateStr(CJobDataMap & jobData, const char* key);
|
||||
string WhereStr(CJobDataMap & jobData, const char* key, int &index, const char **paramValues, bool IgnoreCase = false);
|
||||
bool DoSQL(string sql, int nParamCnt = 0, const char * const *paramValues = NULL);
|
||||
bool DoSetSQL(string sql, int nParamCnt = 0, const char * const *paramValues = NULL);
|
||||
|
||||
// 2014.06.07 dadamin
|
||||
// ¸ÞŸ Å×À̺í¸í ¹Ýȯ
|
||||
string GetMataTableName(const char* tranid);
|
||||
private:
|
||||
DataBase* m_pDB;
|
||||
short m_used;
|
||||
bool m_success;
|
||||
|
||||
// 2014.06.07 dadamin
|
||||
// -1: unset, 0: t_dav_resource, 1: t_meat_[sp_svc_tran_id]
|
||||
int m_tabletype;
|
||||
bool m_usedisplay;
|
||||
};
|
||||
|
||||
#endif // __RCDB_CONTROL_H__
|
||||
@@ -0,0 +1,485 @@
|
||||
/***************************************************************************
|
||||
rc_mngd Control Class (RcMngdControl.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2015/02/04
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2015/02/04 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.4.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "RcMngdControl.h"
|
||||
#include "Logger.h"
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "openssl/ssl.h"
|
||||
#include "openssl/bio.h"
|
||||
#include "openssl/err.h"
|
||||
#include "BaseSocket.h"
|
||||
#include "RCDBControl.h"
|
||||
#include "Convert.h"
|
||||
#include "ConvertReqServiceMove.h"
|
||||
#include "ConvertReqServiceLink.h"
|
||||
#include "Service.h"
|
||||
#include "Parser.h"
|
||||
|
||||
|
||||
CRcMngdControl::CRcMngdControl()
|
||||
: m_ctx(NULL), m_bio(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CRcMngdControl::~CRcMngdControl()
|
||||
{
|
||||
// Close the connection and free the context
|
||||
if (m_bio)
|
||||
{
|
||||
BIO_free_all(m_bio);
|
||||
}
|
||||
|
||||
if (m_ctx)
|
||||
{
|
||||
SSL_CTX_free(m_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
bool CRcMngdControl::Connect(const char* ip, int port, bool usessl)
|
||||
{
|
||||
if (!usessl)
|
||||
{
|
||||
LOG(LERR, "Only SSL support.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set up the library
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
|
||||
// Setup the connection
|
||||
|
||||
SSL_METHOD *meth = (SSL_METHOD*)SSLv3_method();
|
||||
|
||||
// Set the SSL context
|
||||
m_ctx = SSL_CTX_new(meth);
|
||||
if (m_ctx == NULL)
|
||||
{
|
||||
LOG(LERR, "Error ctx.(%s)", ERR_error_string(ERR_get_error(), NULL));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bio = BIO_new_ssl_connect(m_ctx);
|
||||
|
||||
//Set the SSL_MODE_AUTO_RETRY flag */
|
||||
SSL * ssl;
|
||||
BIO_get_ssl(m_bio, &ssl);
|
||||
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
// Create and setup the connection
|
||||
ostringstream connstr;
|
||||
connstr << ip << ":" << port;
|
||||
BIO_set_conn_hostname(m_bio, connstr.str().c_str());
|
||||
|
||||
if (BIO_do_connect(m_bio) <= 0)
|
||||
{
|
||||
LOG(LERR, "Error attempting to connect.[host:%s](%s)",
|
||||
ip,ERR_error_string(ERR_get_error(), NULL));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_targetrcts = ip;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::SendHeader(int bodylen)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
int nH = htonl(bodylen);
|
||||
if (BIO_write(m_bio, &nH, 4) <= 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Error Send Header.(%s)", ERR_error_string(ERR_get_error(), NULL));
|
||||
}
|
||||
else
|
||||
{
|
||||
r = true;
|
||||
LOG(LDBG, "Send Header success.");
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::SendBody(const char * buf, int snedlen)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
// send body
|
||||
if (BIO_write(m_bio, buf, snedlen) <= 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Error Send Body.(%s)", ERR_error_string(ERR_get_error(), NULL));
|
||||
}
|
||||
else
|
||||
{
|
||||
r = true;
|
||||
LOG(LDBG, "Send Body success.");
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::ReadHeader(int & outlen)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
int h = 0;
|
||||
int n = BIO_read(m_bio, &h, 4);
|
||||
if (n < 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Error Read Header.(%s)", ERR_error_string(ERR_get_error(), NULL));
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Server closed.[Header].(err:%d)", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = true;
|
||||
outlen = ntohl(h);
|
||||
LOG(LDBG, "Read Header success.[body size : %d]", outlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::ReadBody(char * out, int & outlen)
|
||||
{
|
||||
bool r = false;
|
||||
string buf;
|
||||
|
||||
int n = BIO_read(m_bio, out, outlen);
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Error Read Body.(%s)", ERR_error_string(ERR_get_error(), NULL));
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
r = false;
|
||||
LOG(LERR, "Server closed.[Body].(err:%d)", errno);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
r = true;
|
||||
LOG(LDBG, "Read Body success.[%s]", out);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::MoveRequest(const char* userseq, const char* svcseq, const char * rcts)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
// get all information (이관 서비스 관련 모든 정보)
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if (rcdb.Init() != 0)
|
||||
{
|
||||
LOG(LERR, "RCDB Initialization failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
CJobDataMap jobData;
|
||||
jobData[KEY_SP_USER_SEQ] = userseq;
|
||||
jobData[KEY_SP_SVC_TRAN_ID] = svcseq;
|
||||
|
||||
if (rcdb.GetServiceInfoAll(jobData) == false)
|
||||
{
|
||||
rcdb.Final();
|
||||
return false;
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
// make xml
|
||||
CConvertReqSvcMove c(JOB_SERVICE_MOVE_REQUEST);
|
||||
|
||||
jobData[KEY_LINK_MASTER_YN] = "N";
|
||||
jobData[KEY_LINK_SP_SVC_TRAN_ID] = svcseq;
|
||||
jobData[KEY_LINK_RCTS] = rcts;
|
||||
|
||||
int o;
|
||||
char* pBodyData = (char*)c.ToClientData(CServiceInfo::XML, 0, &jobData, o);
|
||||
|
||||
if (pBodyData)
|
||||
{
|
||||
// send
|
||||
if (SendHeader(o))
|
||||
{
|
||||
if (SendBody(pBodyData, o))
|
||||
{
|
||||
SSL * ssl;
|
||||
BIO_get_ssl(m_bio, &ssl);
|
||||
|
||||
CXMLParser parser;
|
||||
parser.SetSocket(SOCKET_NOT_VALID, ssl);
|
||||
if (parser.ReadHeader() == 0)
|
||||
{
|
||||
if (parser.ReadBody() == 0)
|
||||
{
|
||||
if (c.ToJobData(CServiceInfo::XML, parser.GetXMLJobNode(), &jobData) > 0)
|
||||
{
|
||||
LOG(LINF, "Move(%s) RMNGD <=> RMNGD result: [%s@%s : %s => %s (%s,%s)]",
|
||||
JOB_SERVICE_MOVE_REQUEST,
|
||||
jobData[KEY_SP_SVC_TRAN_ID].c_str(),
|
||||
jobData[KEY_SP_USER_SEQ].c_str(),
|
||||
rcts,
|
||||
m_targetrcts.c_str(),
|
||||
jobData[KEY_RESP_RESULT].c_str(),
|
||||
jobData[KEY_RESP_RESULT_CODE].c_str());
|
||||
|
||||
if (jobData[KEY_RESP_RESULT].compare(JOX_RESULT_OK) == 0)
|
||||
{
|
||||
r = SetSync(userseq, svcseq, true, svcseq, SYNC_LINK_CODE_LINK);
|
||||
|
||||
LOG(LDBG, "Move Request : [%s => %s]",
|
||||
jobData[KEY_VOLUME_ID].c_str(),
|
||||
(r ? "OK" : "FAIL"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] pBodyData;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::MoveCompleted(const char* userseq, const char* svcseq, const char* rcts)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
// make xml
|
||||
CConvertReqSvcMove c(JOB_SERVICE_MOVE_COMPLETE);
|
||||
|
||||
CJobDataMap jobData;
|
||||
|
||||
string sid = svcseq;
|
||||
sid += "@";
|
||||
sid += userseq;
|
||||
|
||||
jobData[KEY_VOLUME_SEQ] = sid;
|
||||
jobData[KEY_LINK_MASTER_YN] = "N";
|
||||
jobData[KEY_SELF_RCTS] = m_targetrcts;
|
||||
jobData[KEY_LINK_USER_SEQ] = userseq;
|
||||
jobData[KEY_LINK_SP_SVC_TRAN_ID] = svcseq;
|
||||
jobData[KEY_LINK_RCTS] = rcts;
|
||||
jobData[KEY_REQ_LINK_CODE] = SYNC_LINK_CODE_UNLINK;
|
||||
jobData[KEY_REQ_LINK_ONE_WAY] = SYNC_LINK_ONE_WAY;
|
||||
|
||||
int o;
|
||||
char* pBodyData = (char*)c.ToClientData(CServiceInfo::XML, 0, &jobData, o);
|
||||
|
||||
if (pBodyData)
|
||||
{
|
||||
if (SendHeader(o))
|
||||
{
|
||||
if (SendBody(pBodyData, o))
|
||||
{
|
||||
SSL * ssl;
|
||||
BIO_get_ssl(m_bio, &ssl);
|
||||
|
||||
CXMLParser parser;
|
||||
parser.SetSocket(SOCKET_NOT_VALID, ssl);
|
||||
|
||||
if (parser.ReadHeader() == 0)
|
||||
{
|
||||
if (parser.ReadBody() == 0)
|
||||
{
|
||||
if (c.ToJobData(CServiceInfo::XML, parser.GetXMLJobNode(), &jobData) > 0)
|
||||
{
|
||||
LOG(LINF, "Move(%s) RMNGD <=> RMNGD result: [%s : %s => %s (%s,%s)]",
|
||||
JOB_SERVICE_MOVE_COMPLETE,
|
||||
jobData[KEY_VOLUME_SEQ].c_str(),
|
||||
rcts,
|
||||
m_targetrcts.c_str(),
|
||||
jobData[KEY_RESP_RESULT].c_str(),
|
||||
jobData[KEY_RESP_RESULT_CODE].c_str());
|
||||
|
||||
if (jobData[KEY_RESP_RESULT].compare(JOX_RESULT_OK) == 0)
|
||||
{
|
||||
r = SetSync(userseq, svcseq, true, svcseq, SYNC_LINK_CODE_UNLINK);
|
||||
|
||||
LOG(LDBG, "Move Completed : [%s => %s]",
|
||||
jobData[KEY_VOLUME_SEQ].c_str(),
|
||||
(r ? "OK" : "FAIL"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] pBodyData;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::LinkRequest(struct LinkInfo& self, struct LinkInfo& target, const char* linkcode)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
// make xml
|
||||
CConvertReqSvcLink c("");
|
||||
|
||||
CJobDataMap jobData;
|
||||
|
||||
string tsid = self.linksvcseq;
|
||||
tsid += "@";
|
||||
tsid += self.linkuserseq;
|
||||
|
||||
jobData[KEY_VOLUME_SEQ] = tsid;
|
||||
jobData[KEY_LINK_MASTER_YN] = (target.master ? "Y" : "N");
|
||||
jobData[KEY_SELF_RCTS] = self.linkrcts;
|
||||
jobData[KEY_LINK_USER_SEQ] = target.linkuserseq;
|
||||
jobData[KEY_LINK_SP_SVC_TRAN_ID] = target.linksvcseq;
|
||||
jobData[KEY_LINK_RCTS] = target.linkrcts;
|
||||
jobData[KEY_REQ_LINK_CODE] = linkcode;
|
||||
jobData[KEY_REQ_LINK_ONE_WAY] = SYNC_LINK_ONE_WAY;
|
||||
|
||||
int o;
|
||||
char* pBodyData = (char*)c.ToClientData(CServiceInfo::XML, 0, &jobData, o);
|
||||
|
||||
if (pBodyData)
|
||||
{
|
||||
if (SendHeader(o))
|
||||
{
|
||||
if (SendBody(pBodyData, o))
|
||||
{
|
||||
SSL * ssl;
|
||||
BIO_get_ssl(m_bio, &ssl);
|
||||
|
||||
CXMLParser parser;
|
||||
parser.SetSocket(SOCKET_NOT_VALID, ssl);
|
||||
|
||||
if (parser.ReadHeader() == 0)
|
||||
{
|
||||
if (parser.ReadBody() == 0)
|
||||
{
|
||||
if (c.ToJobData(CServiceInfo::XML, parser.GetXMLJobNode(), &jobData) > 0)
|
||||
{
|
||||
|
||||
LOG(LINF, "Link(%s) RMNGD <=> RMNGD result: [%s(%s@%s) => %s(%s) : %s,%s]",
|
||||
linkcode,
|
||||
jobData[KEY_LINK_RCTS].c_str(),
|
||||
jobData[KEY_LINK_SP_SVC_TRAN_ID].c_str(),
|
||||
jobData[KEY_LINK_USER_SEQ].c_str(),
|
||||
m_targetrcts.c_str(),
|
||||
jobData[KEY_VOLUME_SEQ].c_str(),
|
||||
jobData[KEY_RESP_RESULT].c_str(),
|
||||
jobData[KEY_RESP_RESULT_CODE].c_str());
|
||||
|
||||
if (jobData[KEY_RESP_RESULT].compare(JOX_RESULT_OK) == 0)
|
||||
{
|
||||
r = SetSync(target.linkuserseq.c_str(), target.linksvcseq.c_str(), self.master, self.linksvcseq.c_str(), linkcode);
|
||||
|
||||
LOG(LDBG, "Link result : [%s => %s]",
|
||||
jobData[KEY_VOLUME_SEQ].c_str(),
|
||||
(r ? "OK" : "FAIL"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] pBodyData;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::ChkSync(const char* userseq, const char* svcseq)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
//
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if (rcdb.Init() != 0)
|
||||
{
|
||||
LOG(LERR, "RCDB Initialization failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
CJobDataMap jobData;
|
||||
jobData[KEY_SP_USER_SEQ] = userseq;
|
||||
jobData[KEY_SP_SVC_TRAN_ID] = svcseq;
|
||||
|
||||
if (rcdb.GetSyncLink(jobData) == false)
|
||||
{
|
||||
rcdb.Final();
|
||||
return false;
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
LOG(LDEV2, "Get Sync Service Info : %s", jobData[KEY_SYNC_LIST].c_str());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::SetSync(const char* userseq, const char* svcseq, bool mstaer, const char* linksvcseq, const char* linkcode)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
//
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if (rcdb.Init() != 0)
|
||||
{
|
||||
LOG(LERR, "RCDB Initialization failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool exist = false;
|
||||
CJobDataMap jobData;
|
||||
jobData[KEY_REQ_LINK_CODE] = linkcode;
|
||||
jobData[KEY_SP_USER_SEQ] = userseq;
|
||||
jobData[KEY_SP_SVC_TRAN_ID] = svcseq;
|
||||
|
||||
jobData[KEY_LINK_MASTER_YN] = (mstaer ? "Y" : "N");
|
||||
jobData[KEY_LINK_SP_SVC_TRAN_ID] = linksvcseq;
|
||||
jobData[KEY_LINK_RCTS] = m_targetrcts;
|
||||
|
||||
if (rcdb.CheckProductSync(jobData, exist) == true)
|
||||
{
|
||||
r = rcdb.SetProductSync(jobData, exist);
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CRcMngdControl::ChangeRcts(const char* userseq, const char* svcseq, bool masteryn)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/***************************************************************************
|
||||
rc_mngd Control Class Header ( RcMngdControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2015/02/04
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2015/02/04 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.4.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __RC_MNGD_CONTROL_H__
|
||||
#define __RC_MNGD_CONTROL_H__
|
||||
|
||||
struct LinkInfo
|
||||
{
|
||||
bool master;
|
||||
string linkuserseq;
|
||||
string linksvcseq;
|
||||
string linkrcts;
|
||||
};
|
||||
|
||||
class CRcMngdControl
|
||||
{
|
||||
public:
|
||||
CRcMngdControl();
|
||||
~CRcMngdControl();
|
||||
|
||||
bool Connect(const char* ip, int port, bool usessl = true);
|
||||
|
||||
bool MoveRequest(const char* userseq, const char* svcseq, const char* rcts);
|
||||
bool MoveCompleted(const char* userseq, const char* svcseq, const char* rcts);
|
||||
bool LinkRequest(struct LinkInfo& selfself, struct LinkInfo& target, const char* linkcode);
|
||||
bool ChkSync(const char* userseq, const char* svcseq);
|
||||
bool SetSync(const char* userseq, const char* svcseq, bool mstaer, const char* linksvcseq, const char* linkcode);
|
||||
bool ChangeRcts(const char* svcseq, const char * syncsvcseq, bool masteryn);
|
||||
|
||||
protected:
|
||||
bool SendHeader(int bodylen);
|
||||
bool SendBody(const char * buf, int snedlen);
|
||||
|
||||
bool ReadHeader(int & outlen);
|
||||
bool ReadBody(char * out, int & outlen);
|
||||
|
||||
|
||||
private:
|
||||
string m_targetrcts;
|
||||
SSL_CTX * m_ctx;
|
||||
BIO * m_bio;
|
||||
|
||||
};
|
||||
|
||||
#endif // __FHS_CONTROL_H__
|
||||
@@ -0,0 +1,653 @@
|
||||
/***************************************************************************
|
||||
Service Class (Service.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Service.h"
|
||||
#include "Client.h"
|
||||
#include "Configs.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEFAULT_ACCEPT_WAIT_COUNT 30
|
||||
|
||||
#define ACCEPT_TIMEOUT 60
|
||||
|
||||
// class CService
|
||||
CService::CService()
|
||||
: m_done(false), m_ipv6(false), m_listenfd(-1), m_ctx(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
CService::CService(CServiceInfo& info)
|
||||
: m_done(false), m_ipv6(false), m_listenfd(-1), m_ctx(NULL), m_info(info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CService::~CService()
|
||||
{
|
||||
if(m_ctx)
|
||||
SSL_CTX_free(m_ctx);
|
||||
}
|
||||
|
||||
SSL* CService::CerateSSL(int nClientfd)
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
SSL* ret = NULL;
|
||||
|
||||
// TCP connection is ready. Do server side SSL.
|
||||
// create a new SSL structure for a connection
|
||||
// SSL 구조체 생성
|
||||
ret = SSL_new(m_ctx);
|
||||
if(ret == NULL)
|
||||
{
|
||||
msg << "Couldn't allocation SSL. [Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// connect the SSL object with a file descriptor
|
||||
// 연결된 소켓과 SSL과의 연결
|
||||
//SSL_set_fd (ret, nClientfd);
|
||||
// 가장 중요한 함수, 클라이언트와의 초기 협상과정, 즉 핸드쉐이크 과정을 수행
|
||||
//int err = SSL_accept (ret);
|
||||
//if( err < 0 )
|
||||
//{
|
||||
// msg << "SSL Accept Fail. ["<< err <<"][Port : " << m_info.m_port << "]";
|
||||
// SSL_free(ret);
|
||||
// LOGACONSOLE(LERR, msg);
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int password_cb(char *buf,int num,int rwflag,void *userdata)
|
||||
{
|
||||
const char *password = "rootsecurity";
|
||||
strncpy(buf, password, num);
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
SSL_CTX * CService::initializeCTX()
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
SSL_METHOD *meth;
|
||||
SSL_CTX *ctx = NULL;
|
||||
|
||||
/* Global system initialization*/
|
||||
// 기본적인 알고리즘 로드
|
||||
SSL_library_init();
|
||||
// 모든 에러 스트링 로드
|
||||
SSL_load_error_strings();
|
||||
|
||||
/* Create our context*/
|
||||
// SSL 버전3 프로토콜 사용
|
||||
meth=(SSL_METHOD *)SSLv3_method();
|
||||
// SSL 컨텍스트 생성
|
||||
ctx=SSL_CTX_new(meth);
|
||||
if( ctx == NULL)
|
||||
{
|
||||
//ERR_print_errors_fp(stderr);
|
||||
msg << "Couldn't allocation CTX. [Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Private Key File Loading 시 요구되는 패스워드를 자동으로 입력한다.
|
||||
SSL_CTX_set_default_passwd_cb(ctx,password_cb);
|
||||
|
||||
char ca_path[256];
|
||||
/* Load our keys and certificates*/
|
||||
// 자신의 인증서를 파일에서 로딩한다.
|
||||
snprintf( ca_path, sizeof(ca_path), CMyConfig::GetInstance()->GetSSLCertFile());
|
||||
if(!(SSL_CTX_use_certificate_file(ctx,ca_path,SSL_FILETYPE_PEM)))
|
||||
{
|
||||
msg << "Couldn't read certificate file. [Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
SSL_CTX_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 자신의 개인키를 파일에서 로딩한다.
|
||||
snprintf( ca_path, sizeof(ca_path), CMyConfig::GetInstance()->GetSSLPrivateFile());
|
||||
if(!(SSL_CTX_use_PrivateKey_file(ctx,ca_path,SSL_FILETYPE_PEM)))
|
||||
{
|
||||
msg << "Couldn't read key file. [Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
SSL_CTX_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 읽은 인증서와 개인키가 맞는지 확인 한다.
|
||||
if( !SSL_CTX_check_private_key(ctx))
|
||||
{
|
||||
msg << "Private Key does not match the certificate public key. [Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
SSL_CTX_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int CService::TCPListen()
|
||||
{
|
||||
ostringstream msg;
|
||||
#ifdef AF_INET6
|
||||
m_listenfd = ::socket( AF_INET6, SOCK_STREAM, 0 );
|
||||
if(m_listenfd > 0)
|
||||
{
|
||||
msg << "Enable IPv6 Socket.";
|
||||
LOGACONSOLE(LINF, msg);
|
||||
m_ipv6 = true;
|
||||
}
|
||||
#endif // AF_INET6
|
||||
if(m_ipv6 == false)
|
||||
m_listenfd = ::socket( AF_INET, SOCK_STREAM, 0 );
|
||||
|
||||
if( m_listenfd == -1 )
|
||||
{
|
||||
msg << "Listen socket create failed.[" << errno << "]["
|
||||
<< strerror(errno) << "] [Port : " << m_info.m_port << "]";
|
||||
LOG( LERR, "%s", msg.str().c_str());
|
||||
cerr << msg.str() << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
// Socket Port Reuse Option Set
|
||||
int opt = 1;
|
||||
result = ::setsockopt( m_listenfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt) );
|
||||
if( result != 0 )
|
||||
{
|
||||
msg << "Listen socket option[SO_REUSEADDR] set failed. [" << errno
|
||||
<< "][" << strerror(errno) << "][Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Keep Alive Option set
|
||||
opt = 1;
|
||||
result = ::setsockopt( m_listenfd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt) );
|
||||
if( result != 0 )
|
||||
{
|
||||
msg << "Listen socket option[SO_KEEPALIVE] set failed. [" << errno
|
||||
<< "][" << strerror(errno) << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Recv Timeout 설정
|
||||
// 만일 리스너 소켓에 SO_RCVTIMEO를 지정하면, accept(2) 호출시에 지정된 타임아웃 동안 새로운 접속이 없으면
|
||||
// recv(2)처럼 EAGAIN에러로 리턴된다.
|
||||
struct timeval tv_timeo = { ACCEPT_TIMEOUT, 0 };
|
||||
result = ::setsockopt( m_listenfd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, sizeof(tv_timeo));
|
||||
if( result != 0 )
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG( LERR, "SO_RCVTIMEO set error.[%d][%s]", errorNum, strerror(errorNum));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef AF_INET6
|
||||
if(m_ipv6)
|
||||
{
|
||||
struct sockaddr_in6 listenSockAddrv6;
|
||||
socklen_t listenSockLen = 0;
|
||||
memset(&listenSockAddrv6, 0x00, sizeof(listenSockAddrv6));
|
||||
|
||||
listenSockAddrv6.sin6_family = AF_INET;
|
||||
listenSockAddrv6.sin6_flowinfo = 0;
|
||||
listenSockAddrv6.sin6_port = htons( m_info.m_port );
|
||||
listenSockAddrv6.sin6_addr = in6addr_any;
|
||||
|
||||
listenSockLen = sizeof(listenSockAddrv6);
|
||||
|
||||
// Socket Bind
|
||||
result = ::bind( m_listenfd, (struct sockaddr *)&listenSockAddrv6, listenSockLen);
|
||||
if( result != 0 )
|
||||
{
|
||||
msg << "Listen socket bind failed. [" << errno << "][" << strerror(errno)
|
||||
<< "][Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif //AF_INET6
|
||||
{
|
||||
struct sockaddr_in listenSockAddr;
|
||||
socklen_t listenSockLen = 0;
|
||||
bzero(&listenSockAddr,sizeof(listenSockAddr));
|
||||
|
||||
listenSockAddr.sin_family = AF_INET;
|
||||
listenSockAddr.sin_port = htons( m_info.m_port );
|
||||
listenSockAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
||||
|
||||
listenSockLen = sizeof(listenSockAddr);
|
||||
|
||||
// Socket Bind
|
||||
result = ::bind( m_listenfd, (struct sockaddr *)&listenSockAddr, listenSockLen);
|
||||
if( result != 0 )
|
||||
{
|
||||
msg << "Listen socket bind failed. [" << errno << "][" << strerror(errno)
|
||||
<< "][Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Socket Listen
|
||||
result = ::listen( m_listenfd, DEFAULT_ACCEPT_WAIT_COUNT );
|
||||
if( result != 0 )
|
||||
{
|
||||
msg << "Listen socket listen failed. [" << errno << "][" << strerror(errno)
|
||||
<< "][Port : " << m_info.m_port << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int CService::init()
|
||||
{
|
||||
int ret = 0;
|
||||
ret = TCPListen();
|
||||
|
||||
if(m_info.m_enableSSL)
|
||||
{
|
||||
m_ctx = initializeCTX();
|
||||
if( m_ctx == NULL )
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CService::Accept()
|
||||
{
|
||||
ostringstream msg;
|
||||
|
||||
// 접속 요청을 변수 생성 및 초기화.
|
||||
int nClientfd;
|
||||
struct sockaddr_in clientSockAddr;
|
||||
socklen_t clientSockLen = sizeof(clientSockAddr);
|
||||
|
||||
while(!m_done)
|
||||
{
|
||||
msg << "Client Waiting... [Port:" << m_info.m_port << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
nClientfd = ::accept( m_listenfd, (struct sockaddr *) &clientSockAddr, &clientSockLen );
|
||||
|
||||
if( nClientfd == -1 )
|
||||
{
|
||||
if( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
|
||||
{
|
||||
msg << "Service : client accept Warning. [" << errno << "]["
|
||||
<< strerror(errno) << "][Port : " << m_info.m_port << "]";
|
||||
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 오류발생시 해당 내역 로깅처리.
|
||||
msg << "Service : client accept failed. [" << errno << "]["
|
||||
<< strerror(errno) << "][Port : " << m_info.m_port << "]";
|
||||
|
||||
LOGACONSOLE(LERR, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 정상적인 Client 인 경우
|
||||
#ifdef _DEBUG
|
||||
cout << "Connection from " << nClientfd << "," <<
|
||||
clientSockAddr.sin_addr.s_addr << ", Port " << clientSockAddr.sin_port<< endl;
|
||||
#endif // _DEBUG
|
||||
|
||||
SSL* ssl = NULL;
|
||||
|
||||
if(m_info.m_enableSSL == 1)
|
||||
{
|
||||
ssl = CerateSSL(nClientfd);
|
||||
if(ssl == NULL)
|
||||
{
|
||||
// error
|
||||
::close( nClientfd );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
RunClient(nClientfd, ssl);
|
||||
}
|
||||
}
|
||||
|
||||
// exit
|
||||
if(m_listenfd >= 0)
|
||||
{
|
||||
::close(m_listenfd);
|
||||
m_listenfd = -1;
|
||||
}
|
||||
|
||||
if(m_info.m_enableSSL)
|
||||
{
|
||||
ERR_remove_state(0);
|
||||
EVP_cleanup();
|
||||
}
|
||||
|
||||
msg << "Service end.[Port : " << m_info.m_port << ",Type: "
|
||||
<< m_info.m_type << ",SSL:" << m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CService::Acceptv6()
|
||||
{
|
||||
ostringstream msg;
|
||||
#ifdef AF_INET6
|
||||
// 접속 요청을 변수 생성 및 초기화.
|
||||
int nClientfd;
|
||||
struct sockaddr_in6 clientSockAddr;
|
||||
socklen_t clientSockLen = sizeof(clientSockAddr);
|
||||
|
||||
while(!m_done)
|
||||
{
|
||||
msg << "Client(v6) Waiting... [Port:" << m_info.m_port << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
nClientfd = ::accept( m_listenfd, (struct sockaddr *) &clientSockAddr, &clientSockLen );
|
||||
|
||||
if( nClientfd == -1 )
|
||||
{
|
||||
if( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
|
||||
{
|
||||
msg << "Service(v6) : client accept Warning. [" << errno << "]["
|
||||
<< strerror(errno) << "][Port : " << m_info.m_port << "]";
|
||||
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 오류발생시 해당 내역 로깅처리.
|
||||
msg << "Service(v6) : client accept failed. [" << errno << "]["
|
||||
<< strerror(errno) << "][Port : " << m_info.m_port << "]";
|
||||
|
||||
LOGACONSOLE(LERR, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 정상적인 Client 인 경우
|
||||
#ifdef _DEBUG
|
||||
cout << "Connection(v6) from " << nClientfd;
|
||||
#endif // _DEBUG
|
||||
|
||||
SSL* ssl = NULL;
|
||||
|
||||
if(m_info.m_enableSSL == 1)
|
||||
{
|
||||
ssl = CerateSSL(nClientfd);
|
||||
if(ssl == NULL)
|
||||
{
|
||||
// error
|
||||
::close( nClientfd );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
RunClient(nClientfd, ssl);
|
||||
}
|
||||
}
|
||||
|
||||
// exit
|
||||
if(m_listenfd >= 0)
|
||||
{
|
||||
::close(m_listenfd);
|
||||
m_listenfd = -1;
|
||||
}
|
||||
|
||||
if(m_info.m_enableSSL)
|
||||
{
|
||||
ERR_remove_state(0);
|
||||
EVP_cleanup();
|
||||
}
|
||||
|
||||
msg << "Service(v6) end.[Port : " << m_info.m_port << ",Type: "
|
||||
<< m_info.m_type << ",SSL:" << m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
#endif //AF_INET6
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *CService::entry()
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Service start.[Port : " << m_info.m_port << ",Type: "
|
||||
<< m_info.m_type << ",SSL:" << m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
if(m_ipv6)
|
||||
Acceptv6();
|
||||
else
|
||||
Accept();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *CService::_entry_func(void *arg)
|
||||
{
|
||||
void *r = ((CService*)arg)->entry();
|
||||
return r;
|
||||
}
|
||||
|
||||
int CService::Start()
|
||||
{
|
||||
// start thread
|
||||
int ret = pthread_create(&m_threadid, 0, _entry_func, (void*)this);
|
||||
if (ret != 0)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Service Thread create failed.[" << errno << "]";
|
||||
LOGACONSOLE(LERR, msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sleep(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CService::Stop()
|
||||
{
|
||||
m_done = true;
|
||||
|
||||
if (m_listenfd >= 0)
|
||||
{
|
||||
::shutdown(m_listenfd, SHUT_RDWR);
|
||||
}
|
||||
|
||||
if( m_threadid > 0 )
|
||||
{
|
||||
int status = pthread_join(m_threadid, NULL);
|
||||
m_threadid = 0;
|
||||
}
|
||||
|
||||
if (m_listenfd >= 0)
|
||||
{
|
||||
::close(m_listenfd);
|
||||
m_listenfd = -1;
|
||||
}
|
||||
m_done = false;
|
||||
}
|
||||
|
||||
// class CXMLService
|
||||
CXMLService::CXMLService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CXMLService::CXMLService(CServiceInfo& info)
|
||||
: CService(info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CXMLService::~CXMLService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CXMLService::RunClient(int nClientfd, SSL *ssl /* = NULL */)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "XML Service start.[port : " << m_info.m_port << ",SSL:"
|
||||
<< m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
|
||||
CClient * client = new CClient(nClientfd, ssl);
|
||||
|
||||
if( client->Run(m_info) != 0 )
|
||||
delete client;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// class CSDKService
|
||||
CSDKService::CSDKService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSDKService::CSDKService(CServiceInfo& info)
|
||||
: CService(info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSDKService::~CSDKService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CSDKService::RunClient(int nClientfd, SSL *ssl /* = NULL */)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "SDK Service start.[port : " << m_info.m_port << ",SSL:"
|
||||
<< m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CClient * client = new CClient(nClientfd, ssl);
|
||||
|
||||
if( client->Run(m_info) != 0 )
|
||||
delete client;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// class CEtcService
|
||||
CEtcService::CEtcService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEtcService::CEtcService(CServiceInfo& info)
|
||||
: CService(info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEtcService::~CEtcService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CEtcService::RunClient(int nClientfd, SSL *ssl /* = NULL */)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Etc Service start.[port : " << m_info.m_port << ",SSL:"
|
||||
<< m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CClient * client = new CClient(nClientfd, ssl);
|
||||
|
||||
if( client->Run(m_info) != 0 )
|
||||
delete client;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// class CStrService
|
||||
CStrService::CStrService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CStrService::CStrService(CServiceInfo& info)
|
||||
: CService(info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CStrService::~CStrService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CStrService::RunClient(int nClientfd, SSL *ssl /* = NULL */)
|
||||
{
|
||||
ostringstream msg;
|
||||
msg << "Str Service start.[port : " << m_info.m_port << ",SSL:"
|
||||
<< m_info.m_enableSSL << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
CClient * client = new CClient(nClientfd, ssl);
|
||||
|
||||
if (client->Run(m_info) != 0)
|
||||
delete client;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Abstract Factory returning a Service
|
||||
CService* CSericeFactory::CreateSerice(CServiceInfo &info)
|
||||
{
|
||||
switch(info.m_type)
|
||||
{
|
||||
case CServiceInfo::XML:
|
||||
_LOG( LDBG, "Service Factory [type:XML,Port:%d]", info.m_port );
|
||||
return new CXMLService(info);
|
||||
break;
|
||||
case CServiceInfo::SDK:
|
||||
_LOG( LDBG, "Service Factory [type:SDK,Port:%d]", info.m_port );
|
||||
return new CSDKService(info);
|
||||
break;
|
||||
case CServiceInfo::ETC:
|
||||
_LOG( LDBG, "Service Factory [type:ETC,Port:%d]", info.m_port );
|
||||
return new CEtcService(info);
|
||||
break;
|
||||
case CServiceInfo::STR:
|
||||
_LOG(LDBG, "Service Factory [type:STR,Port:%d]", info.m_port);
|
||||
return new CStrService(info);
|
||||
break;
|
||||
default:
|
||||
LOG(LERR, "Service type is unknown.");
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/***************************************************************************
|
||||
Service Class Header ( Config.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __SERVICE_H__
|
||||
#define __SERVICE_H__
|
||||
|
||||
class CServiceInfo
|
||||
{
|
||||
public:
|
||||
CServiceInfo()
|
||||
: m_port(0), m_type(CServiceInfo::UNSET), m_enableSSL(false) {}
|
||||
CServiceInfo(const CServiceInfo &info)
|
||||
: m_port(info.m_port), m_type(info.m_type), m_enableSSL(info.m_enableSSL) {}
|
||||
|
||||
~CServiceInfo() {}
|
||||
|
||||
void PrintInfo()
|
||||
{
|
||||
cout << m_port << "," << m_type << "," << m_enableSSL << endl;
|
||||
};
|
||||
|
||||
enum SERVICE_TYPE {
|
||||
UNSET = -1,
|
||||
XML = 0,
|
||||
SDK = 1,
|
||||
ETC = 2,
|
||||
STR = 3
|
||||
};
|
||||
public:
|
||||
int m_port;
|
||||
enum SERVICE_TYPE m_type;
|
||||
bool m_enableSSL;
|
||||
|
||||
};
|
||||
|
||||
class CService
|
||||
{
|
||||
public:
|
||||
CService();
|
||||
CService(CServiceInfo& info);
|
||||
virtual ~CService();
|
||||
|
||||
void SetInfo(CServiceInfo& info) { m_info = info; }
|
||||
|
||||
int GetPort() { return m_info.m_port; }
|
||||
bool EnableSSL() { return m_info.m_enableSSL; }
|
||||
|
||||
int init();
|
||||
int Start();
|
||||
void Stop();
|
||||
|
||||
protected:
|
||||
void *entry();
|
||||
virtual int RunClient(int nClientfd, SSL *ssl = NULL) = 0;
|
||||
|
||||
int TCPListen();
|
||||
SSL_CTX * initializeCTX();
|
||||
SSL* CerateSSL(int nClientfd);
|
||||
|
||||
int Accept();
|
||||
int Acceptv6();
|
||||
|
||||
pthread_t m_threadid;
|
||||
bool m_done;
|
||||
|
||||
bool m_ipv6;
|
||||
int m_listenfd;
|
||||
SSL_CTX * m_ctx;
|
||||
|
||||
CServiceInfo m_info;
|
||||
private:
|
||||
static void *_entry_func(void *arg);
|
||||
};
|
||||
|
||||
class CXMLService : public CService
|
||||
{
|
||||
public:
|
||||
CXMLService();
|
||||
CXMLService(CServiceInfo& info) ;
|
||||
|
||||
virtual ~CXMLService();
|
||||
|
||||
protected:
|
||||
virtual int RunClient(int nClientfd, SSL *ssl = NULL);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class CSDKService : public CService
|
||||
{
|
||||
public:
|
||||
CSDKService();
|
||||
CSDKService(CServiceInfo& info) ;
|
||||
|
||||
virtual ~CSDKService();
|
||||
|
||||
protected:
|
||||
virtual int RunClient(int nClientfd, SSL *ssl = NULL);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class CEtcService : public CService
|
||||
{
|
||||
public:
|
||||
CEtcService();
|
||||
CEtcService(CServiceInfo& info);
|
||||
|
||||
virtual ~CEtcService();
|
||||
|
||||
protected:
|
||||
virtual int RunClient(int nClientfd, SSL *ssl = NULL);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class CStrService : public CService
|
||||
{
|
||||
public:
|
||||
CStrService();
|
||||
CStrService(CServiceInfo& info);
|
||||
|
||||
virtual ~CStrService();
|
||||
|
||||
protected:
|
||||
virtual int RunClient(int nClientfd, SSL *ssl = NULL);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
// Abstract Factory returning a Service
|
||||
class CSericeFactory
|
||||
{
|
||||
public:
|
||||
CService* CreateSerice(CServiceInfo &info);
|
||||
};
|
||||
#endif // __SERVICE_H__
|
||||
@@ -0,0 +1,674 @@
|
||||
/***************************************************************************
|
||||
Service Change Class (ServiceChange.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "ServiceChange.h"
|
||||
#include "RcMngdControl.h"
|
||||
#include "JobData.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#define RCTX_XML_SSL_PORT 13112
|
||||
|
||||
CServiceChange::CServiceChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CServiceChange::~CServiceChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CServiceChange::run( CJobDataMap &jobData )
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
_LOG( LDBG, "Job Service Change running...");
|
||||
|
||||
// rcdb
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if( rcdb.Init() != 0 )
|
||||
{
|
||||
LOG( LERR, "RCDB Initialization failed.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
int t = 0;
|
||||
bool userexist = true;
|
||||
bool productexist = true;
|
||||
|
||||
// check user info : Must have.
|
||||
t = ExistUser(rcdb, jobData);
|
||||
if ( t < 0 )
|
||||
{
|
||||
r = t;
|
||||
LOG(LERR, "user information check error.");
|
||||
break;
|
||||
}
|
||||
|
||||
if(t == 0)
|
||||
{
|
||||
r = JOB_ERR_USER_EMPTY;
|
||||
LOG(LERR, "In order to change the service information, user information is required.");
|
||||
break;
|
||||
}
|
||||
|
||||
// check product info
|
||||
if( FindInSubKey(jobData, JOB_SERVICE_CHG_USER) == false)
|
||||
{
|
||||
t = ExistProduct(rcdb, jobData);
|
||||
if( t < 0 )
|
||||
{
|
||||
r = t;
|
||||
LOG(LERR, "Service Product check error.");
|
||||
break;
|
||||
}
|
||||
|
||||
if ( t == 0 )
|
||||
{
|
||||
r = JOB_ERR_PRODUCT_EMPTY;
|
||||
LOG(LERR, "In order to change the service information, basic service information is required.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// change user
|
||||
if( FindInSubKey(jobData, JOB_SERVICE_CHG_USER))
|
||||
{
|
||||
// check subkey
|
||||
if(IsSubKey(jobData, JOB_SERVICE_CHG_USER_PW))
|
||||
{
|
||||
// change user info
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_NOT_FOUND_JOB;
|
||||
}
|
||||
|
||||
if(r != JOB_ERR_NOT_FOUND_JOB)
|
||||
{
|
||||
r = SetUser(rcdb, jobData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// change product
|
||||
if( FindInSubKey(jobData, JOB_SERVICE_CHG_PRODUCT))
|
||||
{
|
||||
if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_STORAGE))
|
||||
{
|
||||
// change storage
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_BANDWIDTH))
|
||||
{
|
||||
// change bandwidth
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_PERIOD))
|
||||
{
|
||||
// change period
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_AUTHINFO))
|
||||
{
|
||||
// change auth
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_REPLICATION))
|
||||
{
|
||||
// change replication_count
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_STORAGE_CAL))
|
||||
{
|
||||
// change cal_used_depth
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE))
|
||||
{
|
||||
// change uri_ignore_case
|
||||
// 2014.06.16 dadamin
|
||||
// 정책 체크하여 t_sms_sp_svc_product 값을 변경함
|
||||
r = ChkPolicyIgnoreCase(rcdb, jobData);
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_IGNORE_CASE_FROCE))
|
||||
{
|
||||
// change uri_ignore_case
|
||||
// 2014.06.16 dadamin
|
||||
// 정책 체크 없이 t_sms_sp_svc_product 값을 변경함
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_PRODUCT_DEL_FILE_KEEP_TIME))
|
||||
{
|
||||
// change del_file_keep_time
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_NOT_FOUND_JOB;
|
||||
}
|
||||
|
||||
if(r == JOB_SUCCESS)
|
||||
{
|
||||
r = SetProduct(rcdb, jobData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// change extension auth
|
||||
if ( FindInSubKey(jobData, JOB_SERVICE_CHG_EXAUTH) )
|
||||
{
|
||||
if (IsSubKey(jobData, JOB_SERVICE_CHG_EXAUTH_MODE))
|
||||
{
|
||||
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_EXAUTH_INFO))
|
||||
{
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_EXAUTH_REFERER_CHK))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_NOT_FOUND_JOB;
|
||||
}
|
||||
|
||||
if (r == JOB_SUCCESS)
|
||||
{
|
||||
if(jobData[KEY_REQ_EXT_AUTH_SET].compare("1") == 0 )
|
||||
{
|
||||
jobData[KEY_VALIDATE_SP_SESSION_ID_YN] = "Y";
|
||||
}
|
||||
else if ( jobData[KEY_REQ_EXT_AUTH_UNSET].compare("1") == 0 )
|
||||
{
|
||||
jobData[KEY_VALIDATE_SP_SESSION_ID_YN] = "N";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
r = SetExtAuth(rcdb, jobData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// change bandwidth control
|
||||
if ( FindInSubKey(jobData, JOB_SERVICE_CHG_BAND) )
|
||||
{
|
||||
if (IsSubKey(jobData, JOB_SERVICE_CHG_BAND_MODE))
|
||||
{
|
||||
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_BAND_VOLUME_LIMIT))
|
||||
{
|
||||
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_BAND_SESSION_LIMIT))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_NOT_FOUND_JOB;
|
||||
}
|
||||
|
||||
if (r == JOB_SUCCESS)
|
||||
{
|
||||
if(jobData[KEY_REQ_BAND_LIMIT_SET].compare("1") == 0 )
|
||||
{
|
||||
jobData[KEY_BANDWIDTH_CTRL_YN] = "Y";
|
||||
}
|
||||
else if ( jobData[KEY_REQ_BAND_LIMIT_UNSET].compare("1") == 0 )
|
||||
{
|
||||
jobData[KEY_BANDWIDTH_CTRL_YN] = "N";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
r = SetBandCtl(rcdb, jobData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// change status
|
||||
if (FindInSubKey(jobData, JOB_SERVICE_CHG_STATUS))
|
||||
{
|
||||
if (jobData[KEY_REQ_SVC_STATUS].compare(SERVICE_STATUS_REMOVE) == 0)
|
||||
{
|
||||
r = RemoveService(rcdb, jobData);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_SUCCESS;
|
||||
LOG(LWAR, "Service Change(%s|%s) job SKIP & SUCCESS.[%s@%s][code:%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(), jobData[KEY_REQ_SVC_STATUS].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str(),
|
||||
jobData[KEY_REQ_SVC_STATUS].c_str());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// change sync
|
||||
if (FindInSubKey(jobData, JOB_SERVICE_CHG_SYNC))
|
||||
{
|
||||
jobData[KEY_REQ_SVC_STATUS] = jobData[KEY_REQ_LINK_CODE];
|
||||
r = SetSyncLink(rcdb, jobData);
|
||||
break;
|
||||
}
|
||||
|
||||
// change rcts
|
||||
if (FindInSubKey(jobData, JOB_SERVICE_CHG_MOVE))
|
||||
{
|
||||
if (IsSubKey(jobData, JOB_SERVICE_CHG_MOVE_RQE))
|
||||
{
|
||||
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_MOVE_COMP))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
r = JOB_ERR_NOT_FOUND_JOB;
|
||||
}
|
||||
|
||||
if (r == JOB_SUCCESS)
|
||||
{
|
||||
r = SetSvcMove(rcdb, jobData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (r == JOB_SKIP)
|
||||
{
|
||||
LOG(LNOT, "Service Change(%s|%s) SKIP.[%s@%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(), jobData[KEY_REQ_SVC_STATUS].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
else if (r != JOB_SUCCESS)
|
||||
{
|
||||
// pgpool 3.0.9 이전 버전 경우 다이나믹 쿼리 수행 후 동일 세션을 사용 시
|
||||
// pgpool 비정상 종료 현상이 발생하기 때문에 사용한 Pool을 강제 종료 시킴
|
||||
rcdb.ForceClose();
|
||||
LOG(LERR, "Service Change(%s|%s) error.[%d][%s@%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(), jobData[KEY_REQ_SVC_STATUS].c_str(), r,
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_LOG(LINF, "Service Change(%s|%s) success.[%s@%s]",
|
||||
jobData[KEY_JOBSUB_TYPE].c_str(), jobData[KEY_REQ_SVC_STATUS].c_str(),
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
_LOG( LDBG, "Job Service Change End.");
|
||||
return r ;
|
||||
}
|
||||
|
||||
int CServiceChange::SetUser(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
|
||||
bool userexist = true;
|
||||
do
|
||||
{
|
||||
// set
|
||||
if( rcdb.SetUserInfo(jobData, userexist) == false)
|
||||
{
|
||||
r = JOB_ERR_SET_USER;
|
||||
}
|
||||
|
||||
} while (false);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::SetProduct(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
|
||||
int r = JOB_SUCCESS;
|
||||
|
||||
bool product = true;
|
||||
do
|
||||
{
|
||||
// set
|
||||
|
||||
if ( rcdb.SetProductInfo(jobData, product) == false )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::SetExtAuth(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
|
||||
bool product = true, exist = true;
|
||||
do
|
||||
{
|
||||
// check info
|
||||
if( rcdb.CheckProductExtAuth(jobData, exist) == false)
|
||||
{
|
||||
r= JOB_ERR_CHK_PRODUCT_EXTAUTH;
|
||||
break;
|
||||
}
|
||||
|
||||
// set
|
||||
if( !rcdb.BeginTrans() )
|
||||
{
|
||||
r = JOB_ERR_RCDB_BEGIN_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( rcdb.SetProductInfo(jobData, product) == false )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT;
|
||||
}
|
||||
|
||||
if ( r == 0 )
|
||||
{
|
||||
if( rcdb.SetProductExtAuth(jobData, exist) == false )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT_EXTAUTH;
|
||||
}
|
||||
}
|
||||
|
||||
rcdb.SetSuccess( (r == 0) );
|
||||
if( !rcdb.EndTrans() )
|
||||
{
|
||||
r = JOB_ERR_RCDB_END_TRANS;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::SetBandCtl(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
bool product = true, exist = true;
|
||||
do
|
||||
{
|
||||
// check info
|
||||
if( rcdb.CheckProductExtBand(jobData, exist) == false)
|
||||
{
|
||||
r= JOB_ERR_CHK_PRODUCT_BAND;
|
||||
break;
|
||||
}
|
||||
|
||||
// set
|
||||
if( !rcdb.BeginTrans() )
|
||||
{
|
||||
r = JOB_ERR_RCDB_BEGIN_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( rcdb.SetProductInfo(jobData, product) == false )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT;
|
||||
}
|
||||
|
||||
if ( r == 0 && rcdb.SetProductBand(jobData, exist) == false )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT_EXTAUTH;
|
||||
}
|
||||
|
||||
rcdb.SetSuccess((r == JOB_SUCCESS));
|
||||
if( !rcdb.EndTrans() )
|
||||
{
|
||||
r = JOB_ERR_RCDB_END_TRANS;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::SetSyncLink(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
|
||||
if (jobData[KEY_REQ_LINK_ONE_WAY] == SYNC_LINK_ONE_WAY)
|
||||
{
|
||||
bool exist = false;
|
||||
if (rcdb.CheckProductSync(jobData, exist) == true)
|
||||
{
|
||||
if (rcdb.SetProductSync(jobData, exist) == false)
|
||||
r = JOB_ERR_SET_PRODUCT_SYNC;
|
||||
}
|
||||
else
|
||||
r = JOB_ERR_SET_PRODUCT_SYNC;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRcMngdControl ctl;
|
||||
if (ctl.Connect(jobData[KEY_LINK_RCTS].c_str(), RCTX_XML_SSL_PORT))
|
||||
{
|
||||
struct LinkInfo s, t;
|
||||
|
||||
s.master = (jobData[KEY_LINK_MASTER_YN] == "Y" ? true : false);
|
||||
s.linkuserseq = jobData[KEY_LINK_USER_SEQ];
|
||||
s.linksvcseq = jobData[KEY_LINK_SP_SVC_TRAN_ID];
|
||||
s.linkrcts = jobData[KEY_LINK_RCTS];
|
||||
|
||||
t.master = (jobData[KEY_LINK_MASTER_YN] == "Y" ? false : true);
|
||||
t.linkuserseq = jobData[KEY_SP_USER_SEQ];
|
||||
t.linksvcseq = jobData[KEY_SP_SVC_TRAN_ID];
|
||||
t.linkrcts = jobData[KEY_SELF_RCTS];
|
||||
|
||||
if (ctl.LinkRequest(s, t, jobData[KEY_REQ_LINK_CODE].c_str()) == false)
|
||||
r = JOB_ERR_SET_PRODUCT_SYNC;
|
||||
}
|
||||
else
|
||||
r = JOB_ERR_SET_PRODUCT_SYNC;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::SetSvcMove(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
CRcMngdControl ctl;
|
||||
if (ctl.Connect(jobData[KEY_REQ_MOVE_NEW_RCTS].c_str(), RCTX_XML_SSL_PORT))
|
||||
{
|
||||
if (IsSubKey(jobData, JOB_SERVICE_CHG_MOVE_RQE))
|
||||
{
|
||||
if (ctl.MoveRequest(jobData[KEY_SP_USER_SEQ].c_str(),
|
||||
jobData[KEY_SP_SVC_TRAN_ID].c_str(),
|
||||
jobData[KEY_REQ_MOVE_NOW_RCTS].c_str()) == false)
|
||||
r = JOB_ERR_SET_PRODUCT_MOVE;
|
||||
}
|
||||
else if (IsSubKey(jobData, JOB_SERVICE_CHG_MOVE_COMP))
|
||||
{
|
||||
if (ctl.MoveCompleted(jobData[KEY_SP_USER_SEQ].c_str(),
|
||||
jobData[KEY_SP_SVC_TRAN_ID].c_str(),
|
||||
jobData[KEY_REQ_MOVE_NOW_RCTS].c_str()) == false)
|
||||
r = JOB_ERR_SET_PRODUCT_MOVE;
|
||||
}
|
||||
}
|
||||
else
|
||||
r = JOB_ERR_SET_PRODUCT_MOVE;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CServiceChange::RemoveService(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
bool exist = true, another = true;
|
||||
jobData[KEY_DEL_DIR_USED] = "Y";
|
||||
jobData[KEY_DEL_ROOT] = "Y";
|
||||
jobData[KEY_BANDWIDTH_CTRL_YN] = "N";
|
||||
jobData[KEY_VALIDATE_SP_SESSION_ID_YN] = "N";
|
||||
jobData[KEY_DEL_PRODUCT] = "Y";
|
||||
jobData[KEY_DEL_USER_INFO] = "Y";
|
||||
jobData[KEY_REQ_LINK_CODE] = SYNC_LINK_CODE_UNLINK;
|
||||
|
||||
if (rcdb.HasFile(jobData, exist))
|
||||
{
|
||||
if (!exist)
|
||||
{
|
||||
exist = true;
|
||||
do
|
||||
{
|
||||
if (!rcdb.CheckAnotherProduct(jobData, another))
|
||||
{
|
||||
r = JOB_ERR_CHK_ANOTHER_PRODUCT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rcdb.BeginTrans())
|
||||
{
|
||||
r = JOB_ERR_RCDB_BEGIN_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
// del root
|
||||
if (!rcdb.SetRootInfo(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_ROOT_INFO;
|
||||
}
|
||||
|
||||
// del volume info
|
||||
if (r == 0 && !rcdb.SetVolumeInfo(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_VOLUME_INFO;
|
||||
}
|
||||
|
||||
// del product band
|
||||
if (r == 0 && !rcdb.SetProductBand(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_PRODUCT_BAND;
|
||||
}
|
||||
|
||||
// del product extension auth
|
||||
if (r == 0 && !rcdb.SetProductExtAuth(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_PRODUCT_EXTAUTH;
|
||||
}
|
||||
|
||||
// del product sync
|
||||
if (r == 0 && !rcdb.SetProductSync(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_PRODUCT_SYNC;
|
||||
}
|
||||
|
||||
// del product
|
||||
if (r == 0 && !rcdb.SetProductInfo(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_PRODUCT;
|
||||
}
|
||||
|
||||
// del user
|
||||
if (r == 0 && another == false && !rcdb.SetUserInfo(jobData, exist))
|
||||
{
|
||||
r = JOB_ERR_DEL_USER;
|
||||
}
|
||||
|
||||
rcdb.SetSuccess((r == 0));
|
||||
if (!rcdb.EndTrans())
|
||||
{
|
||||
r = JOB_ERR_RCDB_END_TRANS;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
else
|
||||
r = JOB_ERR_HAS_FILE;
|
||||
}
|
||||
else
|
||||
r = JOB_ERR_CHK_HAS_FILE;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#define POLICY_IGNORECASE_LIMIT 500
|
||||
int CServiceChange::ChkPolicyIgnoreCase(CRCDBControl &rcdb, CJobDataMap &jobData)
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
|
||||
bool ignorecase = false;
|
||||
bool b = rcdb.CheckUriIgnoreCase(jobData, ignorecase);
|
||||
|
||||
if (b == false)
|
||||
return JOB_ERR_CHK_POLICY_IGNORECASE;
|
||||
|
||||
// 메타 정보 체크
|
||||
uint64_t total = 0;
|
||||
uint64_t limit = POLICY_IGNORECASE_LIMIT + 1;
|
||||
b = rcdb.GetTotalCntFiles(jobData, total, limit);
|
||||
|
||||
if (b == false)
|
||||
return JOB_ERR_CHK_POLICY_IGNORECASE;
|
||||
|
||||
if (ignorecase)
|
||||
{
|
||||
// 무시 => 구분(가능)
|
||||
if (jobData[KEY_URI_IGNORE_CASE] == "N")
|
||||
{
|
||||
// 메타 정보 500 rows 초과 : 변경 허용되지 않음
|
||||
if (total == limit)
|
||||
{
|
||||
LOG(LWAR, "Ignore case does not allow for change(%d over).[%s: Y => N]"
|
||||
, POLICY_IGNORECASE_LIMIT, jobData[KEY_SP_SVC_TRAN_ID].c_str());
|
||||
r = JOB_SKIP;
|
||||
}
|
||||
else
|
||||
{
|
||||
//r = JOB_SUCCESS;
|
||||
// 메타 변경 작업
|
||||
if (rcdb.SetMetaIgnoreCase(jobData, false) == true)
|
||||
r = JOB_SUCCESS;
|
||||
else
|
||||
r = JOB_ERR_CHK_POLICY_IGNORECASE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 구분 => 무시(불가능)
|
||||
if (jobData[KEY_URI_IGNORE_CASE] == "Y")
|
||||
{
|
||||
// 메타 정보 0 : 변경 허용
|
||||
if (total == 0)
|
||||
// tran_id 숫자이므로 메타 정보 변경 필요 없음
|
||||
r = JOB_SUCCESS;
|
||||
else
|
||||
{
|
||||
r = JOB_SKIP;
|
||||
LOG(LWAR, "Ignore case does not allow for change.[%s: N => Y]"
|
||||
, jobData[KEY_SP_SVC_TRAN_ID].c_str());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/***************************************************************************
|
||||
Service Change Class Header ( ServiceChange.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __SERVICE_CHANGE_H__
|
||||
#define __SERVICE_CHANGE_H__
|
||||
|
||||
class CJob;
|
||||
|
||||
class CServiceChange : public CJob
|
||||
{
|
||||
public:
|
||||
CServiceChange();
|
||||
virtual ~CServiceChange();
|
||||
|
||||
virtual int run( CJobDataMap &jobData );
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
int SetUser(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int SetProduct(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int SetExtAuth(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int SetBandCtl(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int SetSyncLink(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int SetSvcMove(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int RemoveService(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
int ChkPolicyIgnoreCase(CRCDBControl &rcdb, CJobDataMap &jobData);
|
||||
};
|
||||
|
||||
|
||||
#endif // __SERVICE_CHANGE_H__
|
||||
@@ -0,0 +1,205 @@
|
||||
/***************************************************************************
|
||||
Service Open Class (ServiceOpen.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "ServiceOpen.h"
|
||||
#include "JobData.h"
|
||||
#include "Configs.h"
|
||||
#include "Logger.h"
|
||||
|
||||
CServiceOpen::CServiceOpen()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CServiceOpen::~CServiceOpen()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CServiceOpen::run( CJobDataMap &jobData )
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
_LOG( LDBG, "Job Service Open running...");
|
||||
|
||||
CMyConfig* pConf = CMyConfig::GetInstance();
|
||||
|
||||
if(!pConf)
|
||||
{
|
||||
LOG( LERR, "Config is NULL.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
// rcdb
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if( rcdb.Init() != 0 )
|
||||
{
|
||||
LOG( LERR, "RCDB Initialization failed.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
// 2014.07.15
|
||||
// fimngd 주기적(3분)으로 생성하기 때문에 서비스 시 개통 시 fhs로 신호 보낼 필요 없음
|
||||
|
||||
// check relation value
|
||||
if( !jobData[KEY_AUTH_SERVER].empty() )
|
||||
{
|
||||
jobData[KEY_VALIDATE_SP_SESSION_ID_YN] = "Y";
|
||||
if(!jobData[KEY_REFERER_CHK_URL].empty())
|
||||
{
|
||||
jobData[KEY_REFERER_CHK_YN] = "Y";
|
||||
}
|
||||
}
|
||||
|
||||
if(!jobData[KEY_VOLUME_BANDWIDTH_LIMIT].empty() || !jobData[KEY_SESSION_BANDWIDTH_LIMIT].empty())
|
||||
{
|
||||
jobData[KEY_BANDWIDTH_CTRL_YN] = "Y";
|
||||
}
|
||||
|
||||
bool existuser = false, existproduct = false;
|
||||
bool existproductauth = false, existproductband = false, existproductsync = false;
|
||||
bool existvolume = false, existroot = false;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// check
|
||||
if( !rcdb.CheckUserInfo(jobData, existuser) )
|
||||
{
|
||||
r = JOB_ERR_CHK_USER;
|
||||
break;
|
||||
}
|
||||
|
||||
if(existuser && !rcdb.CheckProductInfo(jobData, existproduct) )
|
||||
{
|
||||
r = JOB_ERR_CHK_PRODUCT;
|
||||
break;
|
||||
}
|
||||
|
||||
if( existproduct && !rcdb.CheckProductExtAuth(jobData, existproductauth) )
|
||||
{
|
||||
r = JOB_ERR_CHK_PRODUCT_EXTAUTH;
|
||||
break;
|
||||
}
|
||||
|
||||
if( existproduct && !rcdb.CheckProductExtBand(jobData, existproductband) )
|
||||
{
|
||||
r = JOB_ERR_CHK_PRODUCT_BAND;
|
||||
break;
|
||||
}
|
||||
|
||||
if (existproduct && !rcdb.CheckProductSync(jobData, existproductsync))
|
||||
{
|
||||
r = JOB_ERR_CHK_PRODUCT_SYNC;
|
||||
break;
|
||||
}
|
||||
|
||||
if( existproduct && !rcdb.CheckVolumeInfo(jobData, existvolume) )
|
||||
{
|
||||
r = JOB_ERR_CHK_VOLUME_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
if( existproduct && !rcdb.CheckRootInfo(jobData, existroot) )
|
||||
{
|
||||
r = JOB_ERR_CHK_ROOT_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !rcdb.BeginTrans() )
|
||||
{
|
||||
r = JOB_ERR_RCDB_BEGIN_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
// set
|
||||
if( !rcdb.SetUserInfo(jobData, existuser) )
|
||||
{
|
||||
r = JOB_ERR_SET_USER;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !rcdb.SetProductInfo(jobData, existproduct) )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !rcdb.SetProductExtAuth(jobData, existproductauth) )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT_EXTAUTH;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !rcdb.SetProductBand(jobData, existproductband) )
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT_BAND;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rcdb.SetProductSync(jobData, existproductsync))
|
||||
{
|
||||
r = JOB_ERR_SET_PRODUCT_SYNC;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !rcdb.SetRootInfo(jobData, existroot) )
|
||||
{
|
||||
r = JOB_ERR_SET_ROOT_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
// 2014.01.08 pgpool 비정상 종료 현상 때문에 쿼리 실행 순서 변경
|
||||
// root 생성 후 볼륨 용량 정보 관련 테이블 생성되도록 변경함
|
||||
if (!rcdb.SetVolumeInfo(jobData, existvolume))
|
||||
{
|
||||
r = JOB_ERR_SET_VOLUME_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
} while(false);
|
||||
|
||||
if(r == JOB_SUCCESS)
|
||||
rcdb.SetSuccess(true);
|
||||
else
|
||||
rcdb.SetSuccess(false);
|
||||
|
||||
if( !rcdb.EndTrans() )
|
||||
r = JOB_ERR_RCDB_END_TRANS;
|
||||
break;
|
||||
}
|
||||
|
||||
if(r != 0)
|
||||
{
|
||||
// pgpool 3.0.9 이전 버전 경우 정적 쿼리 수행 후 동일 세션을 사용 시
|
||||
// pgpool 비정상 종료 현상이 발생하기 때문에 사용한 Pool을 강제 종료 시킴
|
||||
rcdb.ForceClose();
|
||||
LOG( LERR, "Service Open error.[%d][%s@%s]", r,
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_LOG( LINF, "Service Open [%s@%s].",
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
_LOG( LDBG, "Job Service Open End.");
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Service Open Class Header ( ServiceOpen.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/26
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/26 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __SERVICE_OPEN_H__
|
||||
#define __SERVICE_OPEN_H__
|
||||
|
||||
class CJob;
|
||||
|
||||
class CServiceOpen : public CJob
|
||||
{
|
||||
public:
|
||||
CServiceOpen();
|
||||
virtual ~CServiceOpen();
|
||||
|
||||
virtual int run( CJobDataMap &jobData );
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __SERVICE_OPEN_H__
|
||||
@@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
Signal Function (Signals.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/01/22
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/01/20 - 1st dadamin
|
||||
email : svc1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Signals.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void SetSighandler(int signum, signal_handler_t handler, int flag)
|
||||
{
|
||||
sigset_t set;
|
||||
sigfillset( &set );
|
||||
sigprocmask( SIG_SETMASK, &set, NULL ); /* 신호 처리기 처리 설정 위한 블록 */
|
||||
|
||||
int ret;
|
||||
struct sigaction oldact;
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
|
||||
act.sa_handler = handler;
|
||||
sigfillset(&act.sa_mask);
|
||||
act.sa_flags = flag;
|
||||
|
||||
ret = sigaction(signum, &act, &oldact);
|
||||
if (ret != 0) {
|
||||
char buf[1024];
|
||||
snprintf(buf, sizeof(buf), "SetSighandler: sigaction returned "
|
||||
"%d when trying to install a signal handler for %s\n",
|
||||
ret, sys_siglist[signum]);
|
||||
|
||||
cerr << buf << endl;
|
||||
LOG( LERR, "[PID:%d] %s", getpid(), buf);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sigemptyset(&set); /* 신호 처리기 처리 설정 위한 블록 해제 */
|
||||
sigprocmask(SIG_SETMASK, &set, NULL);
|
||||
}
|
||||
|
||||
void SetIgnoreSignal(bool isDaemon)
|
||||
{
|
||||
SetSighandler(SIGPIPE, SIG_IGN, 0); // 파이프 디스크립터 오류 발생시 Process가 죽는 것은 방지하기 위하여 설정
|
||||
SetSighandler(SIGHUP, SIG_IGN, 0); // Process를 기동시킨 관리자의 로그아웃시 발생 시그널
|
||||
SetSighandler(SIGQUIT, SIG_IGN, 0); // 키보드에 의한 Abort 신호 처리 => ?
|
||||
|
||||
if(isDaemon == true)
|
||||
{
|
||||
SetSighandler(SIGINT, SIG_IGN, 0); // ^C 키를 누른 경우 받는 신호 => demon 으로 기동되기 땜시 이 신호 못받음
|
||||
}
|
||||
}
|
||||
|
||||
void SetSIGCHLD(signal_handler_t handler)
|
||||
{
|
||||
SetSighandler(SIGCHLD, handler, 0);
|
||||
}
|
||||
|
||||
void SetSIGTERM(bool isDaemon, signal_handler_t handler)
|
||||
{
|
||||
SetSighandler(SIGTERM, handler, 0);
|
||||
if (isDaemon == false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "SetSIGTERM Console : set SIGINT" << endl;
|
||||
#endif // _DEBUG
|
||||
SetSighandler(SIGINT, handler, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
Signal Function Header ( Signals.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/01/22
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/01/20 - 1st dadamin
|
||||
email : svc1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __SIGNAL_FUNCTION_H__
|
||||
#define __SIGNAL_FUNCTION_H__
|
||||
|
||||
typedef void (*signal_handler_t)(int);
|
||||
|
||||
extern void SetSighandler(int signum, signal_handler_t handler, int flag);
|
||||
|
||||
extern void SetIgnoreSignal(bool isDaemon);
|
||||
|
||||
extern void SetSIGCHLD(signal_handler_t handler);
|
||||
|
||||
extern void SetSIGTERM(bool isDaemon, signal_handler_t handler);
|
||||
|
||||
#endif // __SIGNAL_FUNCTION_H__
|
||||
@@ -0,0 +1,414 @@
|
||||
/***************************************************************************
|
||||
Socket Control Class (SocketControl.cpp)
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "SocketControl.h"
|
||||
#include "Logger.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
#define SOCKET_TIMEOUT 5
|
||||
|
||||
CSocketControl::CSocketControl()
|
||||
: CBaseSocket( SOCKET_NOT_VALID ), m_ssl(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSocketControl::CSocketControl( const int & socket, SSL * ssl)
|
||||
: CBaseSocket( socket ), m_ssl(ssl)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSocketControl::~CSocketControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CSocketControl::SetOption()
|
||||
{
|
||||
if( m_sock == SOCKET_NOT_VALID )
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
/* Time wait 방지 */
|
||||
struct linger ling;
|
||||
|
||||
ling.l_onoff = 1;
|
||||
ling.l_linger = 10; /* 0 for abortive disconnect */
|
||||
|
||||
result = setsockopt(m_sock, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
|
||||
if( result != 0 )
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG( LERR, "SO_LINGER set error.[%d][%s]", errorNum, strerror(errorNum));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct timeval tv_timeo = { SOCKET_TIMEOUT, 0 };
|
||||
/* Recv Timeout 설정. */
|
||||
result = setsockopt( m_sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, sizeof(tv_timeo));
|
||||
if( result != 0 )
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG( LERR, "SO_RCVTIMEO set error.[%d][%s]", errorNum, strerror(errorNum));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Send Timeout 설정. */
|
||||
result = setsockopt( m_sock, SOL_SOCKET, SO_SNDTIMEO, &tv_timeo, sizeof(tv_timeo));
|
||||
if( result != 0 )
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG( LERR, "SO_SNDTIMEO set error.[%d][%s]", errorNum, strerror(errorNum));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::ReadnSSL( void *vptr, size_t n )
|
||||
{
|
||||
ssize_t nread = 0;
|
||||
size_t nleft = n;
|
||||
char * ptr = (char *)vptr;
|
||||
|
||||
while(nleft > 0)
|
||||
{
|
||||
if((nread = SSL_read(m_ssl, ptr, nleft)) < 0)
|
||||
{
|
||||
int error_code = SSL_get_error(m_ssl, nread);
|
||||
LOG( LDBG, "SSL read error code [%d]", error_code);
|
||||
|
||||
switch( error_code)
|
||||
{
|
||||
char tempBuffer[1024];
|
||||
memset(tempBuffer, 0x00, sizeof(tempBuffer));
|
||||
|
||||
case SSL_ERROR_NONE:
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
nread = 0;
|
||||
LOG( LWAR, "SSL read sleep [%d]", error_code);
|
||||
solusleep(50000);
|
||||
break;
|
||||
case SSL_ERROR_WANT_CONNECT:
|
||||
case SSL_ERROR_WANT_ACCEPT:
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
case SSL_ERROR_SYSCALL:
|
||||
case SSL_ERROR_SSL:
|
||||
ERR_error_string_n(ERR_get_error(), tempBuffer, sizeof(tempBuffer));
|
||||
LOG( LERR, "SSL Read Error :[%s]", tempBuffer);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(nread == 0)
|
||||
{
|
||||
LOG(LWAR, "SSL read return 0.[%zd]", nread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nleft -= nread;
|
||||
ptr += nread;
|
||||
}
|
||||
|
||||
return n;/* ?? */
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::WritenSSL(void *vptr, size_t n)
|
||||
{
|
||||
size_t nleft;
|
||||
ssize_t nwritten;
|
||||
|
||||
const char * ptr = (const char *)vptr;
|
||||
nleft = n;
|
||||
|
||||
int tryCount = 0;
|
||||
|
||||
while(nleft > 0)
|
||||
{
|
||||
//fprintf(stderr, "[%s] ssl write before nleft[%d]\n", __func__, nleft);
|
||||
nwritten = SSL_write( m_ssl, ptr, nleft);
|
||||
//fprintf(stderr, "[%s] ssl write after n[%d]\n", __func__, nwritten);
|
||||
|
||||
|
||||
if( nwritten < 0 )
|
||||
{
|
||||
int error_code = SSL_get_error(m_ssl, nwritten);
|
||||
LOG( LDBG, "SSL Write error code [%d]", error_code);
|
||||
|
||||
switch( error_code )
|
||||
{
|
||||
char tempBuffer[1024];
|
||||
|
||||
memset(tempBuffer, 0x00, sizeof(tempBuffer));
|
||||
|
||||
case SSL_ERROR_NONE:
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
nwritten = 0;
|
||||
++tryCount;
|
||||
LOG( LWAR, "SSL Write sleep [%d]", error_code);
|
||||
solusleep(50000);
|
||||
break;
|
||||
case SSL_ERROR_WANT_CONNECT:
|
||||
case SSL_ERROR_WANT_ACCEPT:
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
case SSL_ERROR_SYSCALL:
|
||||
case SSL_ERROR_SSL:
|
||||
ERR_error_string_n(ERR_get_error(), tempBuffer, sizeof(tempBuffer));
|
||||
LOG( LERR, "SSL Write Error [%s]", tempBuffer);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if( nwritten == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( tryCount > 60 )
|
||||
{
|
||||
LOG( LERR, "SSL Write Try Count Over !!!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nleft -= nwritten;
|
||||
ptr += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::ReadData(void *vptr, size_t n)
|
||||
{
|
||||
ssize_t nret = 0;
|
||||
|
||||
if(m_ssl)
|
||||
nret = ReadnSSL(vptr, n);
|
||||
else
|
||||
nret = ReadNTimeout(vptr, n);
|
||||
|
||||
ostringstream msg;
|
||||
msg << "Socket ReadData() result.[" << nret << "]";
|
||||
LOGACONSOLE( LDBG, msg);
|
||||
|
||||
return nret;
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::ReadDataEx(void *vptr, size_t n)
|
||||
{
|
||||
ssize_t nret = 0;
|
||||
|
||||
if (m_ssl)
|
||||
nret = ReadSSL(vptr, n);
|
||||
else
|
||||
nret = ReadTimeout(vptr, n);
|
||||
|
||||
ostringstream msg;
|
||||
msg << "Socket ReadDataEx() result.[" << nret << "]";
|
||||
LOGACONSOLE(LDBG, msg);
|
||||
|
||||
return nret;
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::ReadTimeout(void *vptr, size_t n, int timeout)
|
||||
{
|
||||
if (IsValidSocket() == false)
|
||||
return 0;
|
||||
|
||||
ssize_t nRead = 0;
|
||||
char * ptr = (char *)vptr;
|
||||
|
||||
struct timeval timeOver;
|
||||
int result;
|
||||
|
||||
fd_set selectFds;
|
||||
FD_ZERO(&selectFds);
|
||||
|
||||
|
||||
timeOver.tv_sec = timeout;
|
||||
timeOver.tv_usec = 0;
|
||||
FD_SET(m_sock, &selectFds);
|
||||
|
||||
do {
|
||||
result = select(m_sock + 1, &selectFds, (fd_set *)NULL, (fd_set *)NULL, &timeOver);
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
if (FD_ISSET(m_sock, &selectFds))
|
||||
{
|
||||
if ((nRead = read(m_sock, ptr, n)) < 0)
|
||||
{
|
||||
int errorNum = errno;
|
||||
if (errorNum == EINTR || errorNum == EAGAIN || errorNum == EWOULDBLOCK)
|
||||
{
|
||||
nRead = 0;
|
||||
continue;
|
||||
}
|
||||
else if (errorNum == ECONNRESET || errorNum == EPIPE)
|
||||
{
|
||||
// 2015-08-28 CHG huibong EPIPE(32) 오류 발생시.. 연결 종료로 처리되도록 수정
|
||||
m_bConnected = false;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LERR, "read func fail.[%d][%s]", errorNum, strerror(errorNum));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (nRead == 0)
|
||||
{
|
||||
m_bConnected = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (result == 0) // Timeout
|
||||
{
|
||||
//LOG( LDBG, "read timeout");
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG(LERR, "select func error.[%d][%s]", errorNum, strerror(errorNum));
|
||||
|
||||
return -1;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::ReadSSL(void *vptr, size_t n)
|
||||
{
|
||||
ssize_t nread = 0;
|
||||
char * ptr = (char *)vptr;
|
||||
|
||||
if ((nread = SSL_read(m_ssl, ptr, n)) < 0)
|
||||
{
|
||||
int error_code = SSL_get_error(m_ssl, nread);
|
||||
LOG(LDBG, "SSL read error code [%d]", error_code);
|
||||
|
||||
switch (error_code)
|
||||
{
|
||||
char tempBuffer[1024];
|
||||
memset(tempBuffer, 0x00, sizeof(tempBuffer));
|
||||
|
||||
case SSL_ERROR_NONE:
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
nread = 0;
|
||||
LOG(LWAR, "SSL read sleep [%d]", error_code);
|
||||
solusleep(50000);
|
||||
break;
|
||||
case SSL_ERROR_WANT_CONNECT:
|
||||
case SSL_ERROR_WANT_ACCEPT:
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
case SSL_ERROR_SYSCALL:
|
||||
case SSL_ERROR_SSL:
|
||||
ERR_error_string_n(ERR_get_error(), tempBuffer, sizeof(tempBuffer));
|
||||
LOG(LERR, "SSL Read Error :[%s]", tempBuffer);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (nread == 0)
|
||||
{
|
||||
LOG(LWAR, "SSL read return 0.[%zd]", nread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return nread;/* ?? */
|
||||
}
|
||||
|
||||
ssize_t CSocketControl::WriteData(void *vptr, size_t n)
|
||||
{
|
||||
ssize_t nret = 0;
|
||||
|
||||
if(m_ssl)
|
||||
nret = WritenSSL(vptr, n);
|
||||
else
|
||||
nret = WriteN(vptr, n);
|
||||
|
||||
ostringstream msg;
|
||||
msg << "Socket WriteData() result.[" << nret << "]";
|
||||
LOGACONSOLE( LDBG, msg);
|
||||
|
||||
return nret;
|
||||
}
|
||||
|
||||
string CSocketControl::GetMyIPString()
|
||||
{
|
||||
string r;
|
||||
union {
|
||||
struct sockaddr s;
|
||||
struct sockaddr_in v4;
|
||||
#ifdef AF_INET6
|
||||
struct sockaddr_in6 v6;
|
||||
#endif // AF_INET6
|
||||
} u;
|
||||
|
||||
if (m_sock == SOCKET_NOT_VALID) return r;
|
||||
|
||||
|
||||
socklen_t slen = sizeof(u);
|
||||
|
||||
|
||||
if (getsockname(m_sock, &u.s, &slen) == 0)
|
||||
{
|
||||
#ifdef AF_INET6
|
||||
if (u.s.sa_family == AF_INET6)
|
||||
{
|
||||
socklen_t clientSockLen;
|
||||
char tempBuffer[INET6_ADDRSTRLEN] = {0};
|
||||
|
||||
clientSockLen = sizeof(u.v6);
|
||||
|
||||
if (inet_ntop(AF_INET6, (void *)&u.v6.sin6_addr, tempBuffer, sizeof(tempBuffer)) != NULL)
|
||||
{
|
||||
r = tempBuffer;
|
||||
}
|
||||
|
||||
|
||||
} else
|
||||
#endif // AF_INET6
|
||||
if (u.s.sa_family == AF_INET)
|
||||
{
|
||||
socklen_t clientSockLen;
|
||||
char tempBuffer[INET_ADDRSTRLEN] = {0};
|
||||
|
||||
clientSockLen = sizeof(&u.v4);
|
||||
|
||||
if (inet_ntop(AF_INET, (void *)& u.v4.sin_addr, tempBuffer, sizeof(tempBuffer)) != NULL)
|
||||
{
|
||||
r = tempBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( LERR, "My IP String : UNKNOWN??");
|
||||
}
|
||||
}
|
||||
|
||||
LOG( LDBG, "My IP String : %s",r.c_str());
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
Socket Control Class Header ( JobControl.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/20
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/20 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __SOCKET_CONTROL_H__
|
||||
#define __SOCKET_CONTROL_H__
|
||||
|
||||
#include "BaseSocket.h"
|
||||
|
||||
class CSocketControl : public CBaseSocket
|
||||
{
|
||||
public:
|
||||
CSocketControl();
|
||||
CSocketControl( const int & socket, SSL * ssl );
|
||||
|
||||
~CSocketControl();
|
||||
|
||||
int SetOption();
|
||||
|
||||
ssize_t ReadData(void *vptr, size_t n);
|
||||
ssize_t ReadDataEx(void *vptr, size_t n);
|
||||
ssize_t WriteData(void *vptr, size_t n);
|
||||
|
||||
ssize_t ReadnSSL(void *vptr, size_t n);
|
||||
ssize_t WritenSSL(void *vptr, size_t n);
|
||||
|
||||
ssize_t ReadTimeout(void *vptr, size_t n, int timeout = DEFAULT_DATA_RECEIVE_TIMEOUT);
|
||||
ssize_t ReadSSL(void *vptr, size_t n);
|
||||
|
||||
string GetMyIPString();
|
||||
protected:
|
||||
|
||||
private:
|
||||
SSL* m_ssl;
|
||||
};
|
||||
|
||||
#endif // __SOCKET_CONTROL_H__
|
||||
@@ -0,0 +1,99 @@
|
||||
/***************************************************************************
|
||||
Utility function ( UtilFn.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "UtilFn.h"
|
||||
#include "Logger.h"
|
||||
|
||||
uint64_t GetTimeStamp()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
|
||||
}
|
||||
|
||||
void StringSplit(string str, string delim, vector<string> &results)
|
||||
{
|
||||
const string strEmpty("");
|
||||
string::size_type cutAt;
|
||||
|
||||
while( (cutAt = str.find_first_of(delim)) != str.npos )
|
||||
{
|
||||
if(cutAt > 0)
|
||||
{
|
||||
results.push_back(str.substr(0,cutAt));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cutAt == 0)
|
||||
results.push_back(strEmpty);
|
||||
}
|
||||
str = str.substr(cutAt+1);
|
||||
}
|
||||
if(str.length() > 0)
|
||||
{
|
||||
results.push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
void StringSplitEx(string str, char delim, vector<string> &results)
|
||||
{
|
||||
const string strEmpty("");
|
||||
string::size_type cutAt;
|
||||
|
||||
while( (cutAt = str.find_first_of(delim)) != str.npos )
|
||||
{
|
||||
if(cutAt > 0)
|
||||
{
|
||||
results.push_back(str.substr(0,cutAt));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cutAt == 0)
|
||||
results.push_back(strEmpty);
|
||||
}
|
||||
str = str.substr(cutAt+1);
|
||||
}
|
||||
if(str.length() > 0)
|
||||
{
|
||||
results.push_back(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
string p_name(string const & path)
|
||||
{
|
||||
return path.substr(0, path.find_last_of("/\\"));
|
||||
}
|
||||
|
||||
void solusleep(unsigned long usec)
|
||||
{
|
||||
// usleep 사용시 multi thread 환경에서 block 발생 가능성이 존재
|
||||
// 이에 nanosleep 함수를 사용토록 수정 처리함.
|
||||
struct timespec sleep;
|
||||
|
||||
if (usec >= 1000000)
|
||||
{
|
||||
sleep.tv_sec = (int)(usec / 1000000);
|
||||
sleep.tv_nsec = (usec - ((long)sleep.tv_sec * 1000000)) * 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep.tv_sec = 0;
|
||||
sleep.tv_nsec = usec * 1000;
|
||||
}
|
||||
|
||||
nanosleep(&sleep, NULL);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/***************************************************************************
|
||||
Utility function Header ( ConvertVolumeInfo.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __UTILITY_FUNCTION_H__
|
||||
#define __UTILITY_FUNCTION_H__
|
||||
|
||||
uint64_t GetTimeStamp();
|
||||
|
||||
void StringSplit(string str, string delim, vector<string> &results);
|
||||
void StringSplitEx(string str, char delim, vector<string> &results);
|
||||
|
||||
string p_name(string const & path);
|
||||
void solusleep(unsigned long usec);
|
||||
|
||||
#endif // __UTILITY_FUNCTION_H__
|
||||
@@ -0,0 +1,92 @@
|
||||
/***************************************************************************
|
||||
Volume Information Class ( VolumeInfo.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Job.h"
|
||||
#include "VolumeInfo.h"
|
||||
#include "JobData.h"
|
||||
#include "Logger.h"
|
||||
|
||||
CVolumeInfo::CVolumeInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CVolumeInfo::~CVolumeInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CVolumeInfo::run( CJobDataMap &jobData )
|
||||
{
|
||||
int r = JOB_SUCCESS;
|
||||
_LOG( LDBG, "Job Volume Information running...");
|
||||
|
||||
// rcdb
|
||||
CRCDBControl rcdb;
|
||||
|
||||
if( rcdb.Init() != 0 )
|
||||
{
|
||||
LOG( LERR, "RCDB Initialization failed.");
|
||||
return JOB_ERR_CREATION_FAIL;
|
||||
}
|
||||
|
||||
bool userexist = false, productexist = false;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
int t = 0;
|
||||
// check info
|
||||
t = ExistInfo(rcdb, jobData);
|
||||
if ( t != 1 )
|
||||
{
|
||||
r = t;
|
||||
LOG( LERR, "Base information check error.");
|
||||
break;
|
||||
}
|
||||
|
||||
// check password
|
||||
if( !CheckIdentify(jobData) )
|
||||
{
|
||||
r = JOB_ERR_MISS_PASSWROD;
|
||||
break;
|
||||
}
|
||||
|
||||
// find volume info
|
||||
if( !rcdb.GetVolumeInformation(jobData) )
|
||||
{
|
||||
r = JOB_ERR_GET_VOLUME_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(r != 0)
|
||||
{
|
||||
LOG(LERR, "Volume Information error.[%d][%s@%s]", r,
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_LOG(LINF, "Volume Information success.[%s@%s]",
|
||||
jobData[KEY_SP_SVC_ID].c_str(), jobData[KEY_SP_USER_ID].c_str());
|
||||
}
|
||||
|
||||
rcdb.Final();
|
||||
|
||||
_LOG( LDBG, "Job Volume Information End.");
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
Volume Information Class Header ( VolumeInfo.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/03/14
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/03/14 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __VOLUME_INFORMATION_H__
|
||||
#define __VOLUME_INFORMATION_H__
|
||||
|
||||
class CJob;
|
||||
|
||||
class CVolumeInfo : public CJob
|
||||
{
|
||||
public:
|
||||
CVolumeInfo();
|
||||
virtual ~CVolumeInfo();
|
||||
|
||||
virtual int run( CJobDataMap &jobData );
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __VOLUME_INFORMATION_H__
|
||||
@@ -0,0 +1,170 @@
|
||||
/***************************************************************************
|
||||
rc_mngd Worker ( Worker.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "Worker.h"
|
||||
#include "Signals.h"
|
||||
#include "Logger.h"
|
||||
#include "Configs.h"
|
||||
#include "Service.h"
|
||||
#include "DbConnPool.h"
|
||||
#include "UtilFn.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define DBPOOL_KEEPALIVE_TIMEOUT 300 // 5 min
|
||||
|
||||
static int _isExit = 0;
|
||||
|
||||
/// @brief Worker Process 생성(fork) 처리 함수
|
||||
/// @return 생성 성공시 true, 실패시에는 false 를 반환.
|
||||
bool MakeProcessWorker( bool isDaemon )
|
||||
{
|
||||
pid_t processId;
|
||||
|
||||
// Worker 프로세스 fork
|
||||
processId = fork();
|
||||
if( processId < 0 ) // Fork fail
|
||||
{
|
||||
int errorNum = errno;
|
||||
LOG( LERR, "Worker Process create failed. [%d][%s]", errorNum, strerror(errorNum) );
|
||||
return false;
|
||||
}
|
||||
else if( processId == 0 ) // Child Process => Worker Process
|
||||
{
|
||||
// Worker Process Main 함수 호출 및 종료처리.
|
||||
WorkerMain( isDaemon );
|
||||
exit( EXIT_SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parent Process => Logging
|
||||
LOG( LWAR, "Worker Process create success. PID[%d]" , processId);
|
||||
// 잠시 대기
|
||||
solusleep(100000);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void SigTermWorker( int nSignalNumber )
|
||||
{
|
||||
if(_isExit) return;
|
||||
_isExit = 1;
|
||||
|
||||
ostringstream msg;
|
||||
// Signal Number 에 따른 로깅처리.
|
||||
if( nSignalNumber == SIGTERM )
|
||||
{
|
||||
msg << "Worker Process [" << getpid() << "] exit job start by user signal [SIGTERM]";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg << "Worker Process [" << getpid() << "] exit job start by user signal ["<< nSignalNumber <<"]";
|
||||
}
|
||||
|
||||
cout << msg.str() << endl;
|
||||
_LOG(LWAR, msg.str().c_str());
|
||||
}
|
||||
|
||||
/// @brief Worker Process 의 main 함수
|
||||
int WorkerMain( bool isDaemon )
|
||||
{
|
||||
// Set Signal Handler
|
||||
SetIgnoreSignal(isDaemon);
|
||||
SetSIGTERM(isDaemon, SigTermWorker);
|
||||
|
||||
// create DB connection
|
||||
CMasterDBpool::init(CMyConfig::GetInstance()->GetDBInfo());
|
||||
if (CMasterDBpool::getInstance()->CreatePool(CMyConfig::GetInstance()->GetDBPoolCnt()) <= 0)
|
||||
{
|
||||
LOG(LERR, "database connection pool created fail.");
|
||||
_isExit = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
CMasterDBpool::getInstance()->SetKeepAliveTimeout(DBPOOL_KEEPALIVE_TIMEOUT);
|
||||
CMasterDBpool::getInstance()->SetRecreted(true);
|
||||
}
|
||||
|
||||
_LOG(LINF, "RCDB : %s Type.", CMasterDBpool::getInstance()->GetTargetTableType() == 1 ? "NEW" : "OLD");
|
||||
|
||||
// Start Service
|
||||
list<CServiceInfo> infos =
|
||||
CMyConfig::GetInstance()->GetServiceList();
|
||||
|
||||
CSericeFactory servicefactory;
|
||||
list<CService *> services;
|
||||
for (list<CServiceInfo>::iterator it= infos.begin(); it != infos.end(); ++it)
|
||||
{
|
||||
CServiceInfo info = *it;
|
||||
#ifdef _DEBUG
|
||||
cout << "Service : " ; info.PrintInfo();
|
||||
#endif //_DEBUG
|
||||
CService *d = servicefactory.CreateSerice(info);
|
||||
if(d && d->init() == 0)
|
||||
{
|
||||
services.push_back(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LERR, "Service initialization failed.[%d,%d]",info.m_type,info.m_port);
|
||||
_isExit = 2;
|
||||
}
|
||||
}
|
||||
|
||||
for (list<CService*>::iterator it= services.begin(); it != services.end(); ++it)
|
||||
{
|
||||
(*it)->Start();
|
||||
}
|
||||
|
||||
// signal wait
|
||||
while ( _isExit == 0 )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "Working ..." << endl;
|
||||
#endif //_DEBUG
|
||||
pause();
|
||||
}
|
||||
|
||||
if(_isExit > 1 )
|
||||
{
|
||||
LOG( LERR, "Worker process create failed. Exit...");
|
||||
kill(0, SIGTERM);
|
||||
}
|
||||
|
||||
// Process 종료 처리.
|
||||
while(!services.empty())
|
||||
{
|
||||
CService* pService = services.front();
|
||||
pService->Stop();
|
||||
|
||||
if(pService)
|
||||
delete pService;
|
||||
services.pop_front();
|
||||
}
|
||||
|
||||
_LOG( LWAR, "Worker Process[%d] exit.. Good Bye..", getpid());
|
||||
CMasterDBpool::release();
|
||||
CLogger::Exit();
|
||||
CMyConfig::Exit();
|
||||
|
||||
// 잠시 대기 후 종료처리.
|
||||
solusleep(500000);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/***************************************************************************
|
||||
rc_mngd Worker Header ( Worker.h )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/15
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/15 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __WORKER_PROCESS_H__
|
||||
#define __WORKER_PROCESS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @brief Worker Process 생성(fork) 처리 함수
|
||||
/// @return 생성 성공시 true, 실패시에는 false 를 반환.
|
||||
bool MakeProcessWorker( bool isDaemon );
|
||||
|
||||
/// @brief Worker Process 의 main 함수
|
||||
/// @return
|
||||
int WorkerMain( bool isDaemon );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __WORKER_PROCESS_H__ */
|
||||
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
/****************************************************************************
|
||||
rc_mngd Main ( main.cpp )
|
||||
-----------------------------------------
|
||||
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
- 2013/02/13 - 1st dadamin
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2005 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
*****************************************************************************/
|
||||
#include "rc_mngd.h"
|
||||
#include "ArgParser.h"
|
||||
#include "Configs.h"
|
||||
#include "Logger.h"
|
||||
#include "Signals.h"
|
||||
#include "Worker.h"
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
static bool _isExit = false;
|
||||
static bool _isDaemon = true;
|
||||
|
||||
// print Version
|
||||
static void Version()
|
||||
{
|
||||
cerr << "Version : " PROG_NAME " " PROG_VERSION << endl;
|
||||
}
|
||||
|
||||
// print usage
|
||||
static void Usage()
|
||||
{
|
||||
cerr << "usage: " PROG_NAME " [-c file]" << endl;
|
||||
cerr << " [-v] [-h] [-D]" << endl;
|
||||
cerr << " -v : show version number" << endl;
|
||||
cerr << " -h : list available command line options (this page)" << endl;
|
||||
cerr << " -D : run console mode" << endl;
|
||||
cerr << " -c file : process directive reading config files" << endl;
|
||||
cerr << endl << endl;
|
||||
cerr << PROG_NAME <<" is RC control daemon." << endl;
|
||||
cerr << "Service Open/Move, Storage Usage, etc " << endl;
|
||||
}
|
||||
|
||||
// signal function
|
||||
static void SigTermMain( int nSignalNumber )
|
||||
{
|
||||
if(_isExit) return;
|
||||
_isExit = true;
|
||||
|
||||
ostringstream msg;
|
||||
// Signal Number 에 따른 로깅처리.
|
||||
if( nSignalNumber == SIGTERM )
|
||||
{
|
||||
msg << "Main Process [" << getpid() << "] exit job start by user signal [SIGTERM]";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg << "Main Process [" << getpid() << "] exit job start by user signal ["<< nSignalNumber <<"]";
|
||||
}
|
||||
|
||||
cout << msg.str() << endl;
|
||||
_LOG(LWAR, msg.str().c_str());
|
||||
|
||||
// KILL - Child
|
||||
kill(0, SIGTERM);
|
||||
|
||||
// waitpid
|
||||
while(waitpid(-1, NULL, WNOHANG) > 0);
|
||||
}
|
||||
|
||||
static void SigChldMain( int nSignalNumber )
|
||||
{
|
||||
pid_t killPid;
|
||||
int nKillStatus;
|
||||
|
||||
while( ( killPid = waitpid( -1, &nKillStatus, WNOHANG ) ) > 0 )
|
||||
{
|
||||
|
||||
if(WIFEXITED(nKillStatus))
|
||||
{
|
||||
// 자식 프로세스가 정상적으로 종료되었는지 검사.
|
||||
LOG( LWAR, "Worker process[%d] killed by signal[SIGTERM]", killPid);
|
||||
}
|
||||
else if( WIFSIGNALED( nKillStatus ) )
|
||||
{
|
||||
// 자식 프로세스가 Signal 에 의해 종료되었는지 검사.
|
||||
LOG( LWAR, "Worker process[%d] killed by signal[%d]", killPid, WTERMSIG( nKillStatus ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( LWAR, "Worker process[%d] killed. Not signal", killPid );
|
||||
}
|
||||
|
||||
// Worker Process 재생성 처리.
|
||||
if( MakeProcessWorker(_isDaemon ) == false )
|
||||
{
|
||||
// Worker Process 재성성 실패시 => 그냥 로깅
|
||||
LOG( LERR, "Worker process recreate failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG( LWAR, "Worker process recreate success by SIGCHLD");
|
||||
}
|
||||
}
|
||||
|
||||
// 오류 발생시 해당 내역 로깅
|
||||
if( killPid < 0 )
|
||||
{
|
||||
LOG( LERR, "Main process error: SIG_CHLD receive but waitpid return error[%d][%s]", errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
// check running Process
|
||||
static bool IsCurrentProcessRun()
|
||||
{
|
||||
char tempBuffer[512];
|
||||
FILE * fd = NULL;
|
||||
bool bRun = false;
|
||||
snprintf( tempBuffer, sizeof(tempBuffer), "pgrep -x %s | sort", PROG_NAME );
|
||||
fd = popen( tempBuffer, "r" );
|
||||
if( fd == NULL )
|
||||
{
|
||||
cerr << "[error] Process duplication check failed.[popen error][" << strerror(errno) << "]" << endl;
|
||||
// 오류 발생시 true 반환하여 프로세스 실행 방지처리
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset( tempBuffer, 0x00, sizeof(tempBuffer) );
|
||||
while( fgets( tempBuffer, sizeof(tempBuffer)-1, fd) != NULL )
|
||||
{
|
||||
string tempPid( tempBuffer );
|
||||
//Trim(tempPid);
|
||||
if( atoi( tempPid.c_str() ) != getpid() )
|
||||
{
|
||||
cout << "[info] Process duplication found. pid[" << atoi( tempPid.c_str() ) << "]" << endl;
|
||||
bRun = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pclose( fd );
|
||||
return bRun;
|
||||
}
|
||||
}
|
||||
|
||||
// main function
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
string strConfPath = DEFAULT_CONFIG_FILE;
|
||||
|
||||
// parse Input argument
|
||||
CArgParser argparser(argc, argv);
|
||||
|
||||
if( argparser.checkvalue("-v") )
|
||||
{
|
||||
Version();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
if( argparser.checkvalue("-h") )
|
||||
{
|
||||
Usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ( argparser.checkvalue("-D") )
|
||||
{
|
||||
_isDaemon = false;
|
||||
}
|
||||
|
||||
string val;
|
||||
if ( argparser.checkvalue("-c", &val) )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
cout << "Change conf path " << strConfPath << " to " << val << endl;
|
||||
#endif // _DEBUG
|
||||
strConfPath = val;
|
||||
}
|
||||
|
||||
if(!argparser.empty())
|
||||
{
|
||||
cerr<< "[error] can't understand argument." << endl;
|
||||
Usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Check the program will duplicate
|
||||
if( IsCurrentProcessRun() )
|
||||
{
|
||||
cerr << "[warning] Process [" << PROG_NAME << "] is already running...." << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//initialized Config object
|
||||
if(CMyConfig::Init( PROG_NAME, strConfPath ) == false)
|
||||
{
|
||||
cerr << "[error] Failed to initialize the config object." << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// load config
|
||||
if( CMyConfig::GetInstance()->LoadConf() == false )
|
||||
{
|
||||
cerr << "[error] Config load error." << CMyConfig::GetInstance()->GetErrMessage() << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (CMyConfig::GetInstance()->CheckValue() == false)
|
||||
{
|
||||
cerr << "[error] Config load error." << CMyConfig::GetInstance()->GetErrMessage() << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// initialized Log object
|
||||
if( CLogger::Init( PROG_NAME, CMyConfig::GetInstance()->GetAppLogRoot(),
|
||||
CMyConfig::GetInstance()->GetAppLogLevel() ) == false )
|
||||
{
|
||||
cerr << "[error] Failed to initialize the log object." << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cout << PROG_NAME << (_isDaemon ? " Daemonize" : " Console Mode")
|
||||
<< "......." << endl;
|
||||
|
||||
// daemonize
|
||||
if(_isDaemon && daemon(1,0) == -1 )
|
||||
{
|
||||
cerr << "[error] Failed Daemonize.(errno : " << errno << ")" << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
_LOG( LINF, "Main Process [%d] Starting...", getpid());
|
||||
|
||||
// set up signal handlers, now that we've daemonized/forked.
|
||||
SetIgnoreSignal(_isDaemon);
|
||||
SetSIGCHLD(SigChldMain);
|
||||
SetSIGTERM(_isDaemon, SigTermMain);
|
||||
|
||||
// run work
|
||||
MakeProcessWorker(_isDaemon );
|
||||
|
||||
// signal wait
|
||||
while( _isExit == false )
|
||||
{
|
||||
pause();
|
||||
}
|
||||
|
||||
// end
|
||||
_LOG( LINF, "Main Process [%d] exit job end. Good Bye..", getpid());
|
||||
CLogger::Exit();
|
||||
CMyConfig::Exit();
|
||||
cout << PROG_NAME << " End." << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/***************************************************************************
|
||||
RC Management Daemon Global Setting ( rc_mngd.h )
|
||||
-----------------------------------------
|
||||
begin : 2013/02/13
|
||||
copyright : (C) 2013 Solbox Inc.
|
||||
author : Development 1 Team
|
||||
email : dev1@solbox.com
|
||||
version : 3.2.0
|
||||
|
||||
CopyRight(C) 2011 Solbox Inc. All Rights reserved.
|
||||
Redistribution and use in source and binary forms, with or with out
|
||||
modification, are not permitted in outside of Solbox Inc.
|
||||
***************************************************************************/
|
||||
#ifndef __RC_MMNGD_H__
|
||||
#define __RC_MMNGD_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define LOGACONSOLE(level, msg) \
|
||||
if(level >= LDBG) {\
|
||||
_LOG( level, "%s", msg.str().c_str());\
|
||||
cout << msg.str() << endl; msg.str("");}\
|
||||
else {\
|
||||
LOG( level, "%s", msg.str().c_str());\
|
||||
cerr << msg.str() << endl; msg.str("");}\
|
||||
msg.str("");
|
||||
|
||||
#endif // __RC_MMNGD_H__
|
||||
Reference in New Issue
Block a user