base
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user