用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

803 lines
47 KiB

10 months ago
<EFBFBD><EFBFBD>#include "FileStream.h"
#include <time.h>
#include <memory.h>
#include <vector>
#include <algorithm>
/*******************************************************************************
{|ParamObject<EFBFBD>[<EFBFBD>s<EFBFBD>Nx
*******************************************************************************/
static std::string tolowerstring(std::string& str)
{
transform(str.begin(), str.end(), str.begin(), ::towlower);
return str;
}
ParamObject::ParamObject()
{
curr_pos=0;
}
ParamObject::~ParamObject()
{
curr_pos=0;
}
//\<EFBFBD>SYN*N<EFBFBD>[a<EFBFBD><EFBFBD>v@b g<EFBFBD>Spe<EFBFBD>R0Rُ*N<EFBFBD>[a<EFBFBD>-N
void ParamObject ::AppendForm(ParamObject *other)
{
if(other!=NULL)
{
//\<EFBFBD>e<EFBFBD>[a<EFBFBD> gHeW[<EFBFBD><EFBFBD>pe<EFBFBD>b<EFBFBD>0R,g<EFBFBD>[a<EFBFBD>-N
mParamsBuffer.AppendBlobContent(other->mParamsBuffer.GetBlobPtr(),other->mParamsBuffer.GetBlobLength());
//ub<EFBFBD>Spe<EFBFBD>e<EFBFBD>v"}_
std::map<std::string,unsigned long>::iterator itrOther;
std::map<std::string,unsigned long>::iterator itrFind;
for(itrOther= other->paramNames.begin(); itrOther!=other->paramNames.end(); )
{
//\<EFBFBD>kN*N<EFBFBD>Spe<EFBFBD>v TW[<EFBFBD>T<EFBFBD>[<EFBFBD>[<EFBFBD>^W[&{Am-N<EFBFBD><EFBFBD><EFBFBD>YMOn>e0Rmap-N
//<EFBFBD>Y<EFBFBD>g,g<EFBFBD>[a<EFBFBD><EFBFBD>] gdk<EFBFBD>Spe <EFBFBD>1\\,g<EFBFBD>[a<EFBFBD>-N<EFBFBD>Spen:NPARAMS_UNVALID_TYPE<EFBFBD>eHe<EFBFBD><EFBFBD><EFBFBD>p
itrFind = paramNames.find(itrOther->first);
if( itrFind!= paramNames.end())
{
//\,g<EFBFBD>[a<EFBFBD>-N<EFBFBD>] g<EFBFBD>v T T<EFBFBD>y<EFBFBD><EFBFBD><EFBFBD>p<EFBFBD><EFBFBD>n:N<EFBFBD>eHe<EFBFBD><EFBFBD><EFBFBD>p
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+ itrFind->second );
pNode->type = PARAMS_UNVALID_TYPE;
//v^<EFBFBD>f<EFBFBD>e<EFBFBD>[<EFBFBD>vMOn<EFBFBD>Oo`
itrFind->second = mParamsBuffer.GetBlobLength() + itrOther->second ;
}
else
{
paramNames.insert(std::map<std::string,unsigned long>::value_type(itrOther->first,mParamsBuffer.GetBlobLength()+itrOther->second ));
}
itrOther++;
}
Refresh();
}
}
void ParamObject::ReName(const char *src_paramname, const char *dst_paramname)
{
std::map<std::string,unsigned long>::iterator itr;
//<EFBFBD>Y<EFBFBD>gdst_paramname<EFBFBD>]<EFBFBD>~X[(W <EFBFBD>R NAQ<EFBFBD><EFBFBD>9ebdst_paramname
itr = paramNames.find(dst_paramname);
if(itr!=paramNames.end())
{
throw ERPException(EERROR,SYSTEM_ERROR,"can,t rename [%s] to [%s] , param [%s] exist!",src_paramname,dst_paramname,dst_paramname);
}
itr = paramNames.find(src_paramname);
if(itr==paramNames.end())
{
throw ERPException(EERROR,SYSTEM_ERROR,"can,t rename [%s] to [%s] , param [%s] not exist!",src_paramname,dst_paramname,src_paramname);
}
unsigned int node_start_pos;
ParamNode rNode;
BlobBuffer TmpParamsBuffer;
//HQ<EFBFBD><EFBFBD><EFBFBD>{MOn <EFBFBD>~b0R<EFBFBD>S<EFBFBD>~<EFBFBD>p<EFBFBD>vpenc
node_start_pos = itr->second;
memcpy((unsigned char*)&rNode, (unsigned char*)mParamsBuffer.GetBlobPtr()+node_start_pos, sizeof(ParamNode));
paramNames.erase(itr);
//<EFBFBD>f<EFBFBD>e"}_<P
//paramNames.Insert(key,length);
paramNames.insert(std::map<std::string,unsigned long>::value_type(dst_paramname,node_start_pos));
//<EFBFBD>f<EFBFBD>epenc<P
strncpy(rNode.name, dst_paramname,sizeof(rNode.name));
memcpy((unsigned char*)mParamsBuffer.GetBlobPtr()+node_start_pos, (unsigned char*)&rNode ,sizeof(ParamNode));
}
/*
----7R<EFBFBD>epenc <EFBFBD>͑<EFBFBD>e<EFBFBD>cR <EFBFBD>nzz<EFBFBD>eHe<EFBFBD><EFBFBD><EFBFBD>p,
RM<EFBFBD>NWW'Y<EFBFBD>QX[ <EFBFBD>6qT<EFBFBD>bpencN*NN*N<EFBFBD><EFBFBD>S
*/
void ParamObject::Refresh()
{
if(getParamCount()<1)
return;
BlobBuffer TmpParamsBuffer;
unsigned int start_pos =0;
unsigned int end_pos =0;
ParamNode *pNode;
//BiNode *pFindBiNode;
for( ; start_pos< mParamsBuffer.GetBlobLength() ; start_pos = end_pos)
{
//<EFBFBD><EFBFBD><EFBFBD>{MOn
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr() +start_pos );
end_pos += sizeof(ParamNode)+pNode->length;
//<EFBFBD>Y<EFBFBD>g/f gHe<EFBFBD><EFBFBD><EFBFBD>p <EFBFBD>1\ub<EFBFBD>e<EFBFBD>v<EFBFBD>Spe"}_ <EFBFBD>v^<EFBFBD>b<EFBFBD>pencۏ4N<EFBFBD>e<EFBFBD>Q-N
if(pNode->type!=PARAMS_UNVALID_TYPE)
{
//<EFBFBD><EFBFBD>HQ<EFBFBD>f<EFBFBD>e@b g gHe<EFBFBD>~<EFBFBD>p<EFBFBD>v"}_
itr = paramNames.find(pNode->name);
if(itr != paramNames.end())
itr->second = TmpParamsBuffer.GetBlobLength();
//<EFBFBD>Q<EFBFBD>b<EFBFBD>penc0R<EFBFBD>e<EFBFBD>v'Y<EFBFBD>QX[-N--
TmpParamsBuffer.AppendBlobContent(mParamsBuffer.GetBlobPtr()+start_pos , end_pos-start_pos);
}
}
mParamsBuffer.SetBlobContent(TmpParamsBuffer.GetBlobPtr(),TmpParamsBuffer.GetBlobLength() );
First();
}
//--- Rd<EFBFBD><EFBFBD>g*N<EFBFBD>Spe-----------
void ParamObject::remove(const char *paramName)
{
std::map<std::string,unsigned long>::iterator itr;
itr = paramNames.find(paramName);
if(itr==paramNames.end())
{
return;
}
unsigned int node_start_pos;
ParamNode rNode;
BlobBuffer TmpParamsBuffer;
//HQ<EFBFBD><EFBFBD><EFBFBD>{MOn
node_start_pos = itr->second;
memcpy((unsigned char*)&rNode, (unsigned char*)mParamsBuffer.GetBlobPtr()+node_start_pos, sizeof(ParamNode));
TmpParamsBuffer.SetBlobContent(mParamsBuffer.GetBlobPtr(),node_start_pos);
TmpParamsBuffer.AppendBlobContent(mParamsBuffer.GetBlobPtr()+ node_start_pos+sizeof(ParamNode)+ rNode.length,mParamsBuffer.GetBlobLength()-rNode.length);
mParamsBuffer.SetBlobContent(TmpParamsBuffer.GetBlobPtr(),TmpParamsBuffer.GetBlobLength());
paramNames.erase(itr);
//͑<EFBFBD>^dk<EFBFBD>SpeTb<EFBFBD>@b g<EFBFBD>Spe<EFBFBD>v<EFBFBD>Spe"}_
ParamNode *pNode;
for( ; node_start_pos<mParamsBuffer.GetBlobLength(); )
{
//<EFBFBD><EFBFBD><EFBFBD>{MOn
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+node_start_pos );
std::map<std::string,unsigned long>::iterator itr;
itr = paramNames.find(pNode->name);
if(itr!= paramNames.end())
{
itr->second = node_start_pos;
}
node_start_pos += sizeof(ParamNode)+pNode->length;
}
}
//nzz<EFBFBD>Spe<EFBFBD>[a<EFBFBD>-N<EFBFBD>v<EFBFBD>Q<EFBFBD>[
void ParamObject::Clear()
{
paramNames.clear();
mParamsBuffer.ClearContent();
curr_pos=0;
}
//<EFBFBD>OX[te<EFBFBD>W<EFBFBD>Spe
void ParamObject::putInteger(const char *paramName,int paramValue)
{
char sValue[64];
sprintf(sValue, "%d",paramValue );
putString( paramName,sValue,PARAMS_INTEGER);
}
void ParamObject::putIntegerNull(const char *paramName,int paramValue)
{
char sValue[64];
if( paramValue==0 )
sValue[0] = '\0';
else
sprintf(sValue, "%d",paramValue );
putString( paramName,sValue,PARAMS_INTEGER );
}
//<EFBFBD>OX[<EFBFBD>te<EFBFBD>W<EFBFBD>Spe
void ParamObject::putLong(const char *paramName,long paramValue)
{
char sValue[64];
sprintf(sValue, "%ld",paramValue );
putString( paramName,sValue ,PARAMS_LONG);
}
//<EFBFBD>OX[nm<EFBFBD>p<EFBFBD>W2N<EFBFBD>Spe
void ParamObject::putFloat(const char *paramName,float paramValue,
const int Precision)
{
char sFmtString[25];
char sValue[64];
sprintf(sFmtString, "%%.%df",Precision );
sprintf(sValue, sFmtString,paramValue );
putString( paramName,sValue,PARAMS_FLOAT);
}
//<EFBFBD>OX[<EFBFBD>S<EFBFBD>|<EFBFBD>^<EFBFBD>Spe
void ParamObject::putDouble(const char *paramName,double paramValue,
const int Precision)
{
char sFmtString[25];
char sValue[64];
sprintf(sFmtString, "%%.%dlf",Precision );
sprintf(sValue, sFmtString,paramValue );
putString( paramName,sValue,PARAMS_DOUBLE);
}
/*
<EFBFBD>OX[W[&{2N<EFBFBD>Spe0R<EFBFBD>[a<EFBFBD>-N <EFBFBD>
<EFBFBD>l <EFBFBD><EFBFBD>[<EFBFBD>NW[&{2N<EFBFBD>Spe <EFBFBD>02Hr,g:N<EFBFBD>N<EFBFBD>cؚHe<EFBFBD>s <EFBFBD>\'\0'W[&{_NX[<EFBFBD>P0R<EFBFBD>^R-N<EFBFBD>N
ُ7h<EFBFBD>v݋(WGetString<EFBFBD>e1\<EFBFBD>S<EFBFBD>N N(u<EFBFBD>b<EFBFBD>W[&{2NUS<EFBFBD>rYt
*/
void ParamObject::putString(const char *paramName,const char *paramValue,unsigned char dataType/*=PARAMS_STRING*/)
{
unsigned int start_pos;
std::map<std::string,unsigned long>::iterator itr;
itr = paramNames.find(paramName);
if(itr!= paramNames.end())
{
start_pos =itr->second;
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr() +start_pos );
pNode->type = PARAMS_UNVALID_TYPE; //\<EFBFBD>S g<EFBFBD><EFBFBD><EFBFBD>p<EFBFBD><EFBFBD>n:N<EFBFBD>eHe<EFBFBD><EFBFBD><EFBFBD>p
paramNames.erase(itr);
}
putStream(paramName,(const unsigned char *)paramValue,strlen(paramValue),false,dataType);
}
//<EFBFBD>OX[<EFBFBD>SpeAm0R<EFBFBD>[a<EFBFBD>-N
void ParamObject::putStream(const char *paramName,const unsigned char *paramValue,unsigned int len
,bool redu_check,const unsigned char dataType)
{
if(redu_check)
{
std::map<std::string,unsigned long>::iterator itr;
itr = paramNames.find(paramName);
if(itr!=paramNames.end() && dataType==PARAMS_STREAM)
{
throw ERPException(EERROR,SYSTEM_ERROR,"<EFBFBD>]<EFBFBD>~ g<EFBFBD>SpeAm[%s] <EFBFBD> N<EFBFBD><EFBFBD>͑ YX[>edk<EFBFBD>SpeAm<EFBFBD>",paramName);
}
}
//<EFBFBD>e<EFBFBD>^"}_
//paramNames.Insert(key,length);
unsigned long size = mParamsBuffer.GetBlobLength();
paramNames.insert(std::map<std::string,unsigned long>::value_type(paramName,size));
ParamNode cNode;
memset(&cNode,'\0',sizeof(ParamNode));
memset(cNode.name,'\0',sizeof(cNode.name));
cNode.length = len;
cNode.type = dataType;
strncpy(cNode.name, paramName, sizeof(cNode.name));
mParamsBuffer.AppendBlobContent((unsigned char *)&cNode,sizeof(ParamNode));
mParamsBuffer.AppendBlobContent(paramValue,cNode.length);
}
void ParamObject::putBlob(const char *paramName,BlobBuffer &blob)
{
putStream(paramName,blob.GetBlobPtr() ,blob.GetBlobLength(),true,PARAMS_BLOB );
}
/*
//<EFBFBD>OX[<EFBFBD>^R<EFBFBD>Spe
void ParamObject::putDataSet(const char *paramName,DataSet &dataset)
{
BlobBuffer blobBuffer;
dataset.Serialize(blobBuffer) ;
putStream( paramName,blobBuffer.GetBlobPtr(),blobBuffer.GetBlobLength(),true,PARAMS_DATASET );
}
*/
///ec<EFBFBD>Spe<EFBFBD>[a<EFBFBD>L]WY
void ParamObject::putParamObject(const char *paramName,ParamObject &object)
{
BlobBuffer blobBuffer;
object.SaveToBlob(blobBuffer);
putStream( paramName,blobBuffer.GetBlobPtr(),blobBuffer.GetBlobLength(),true,PARAMS_ParamObject );
}
//<EFBFBD><EFBFBD><EFBFBD>Ste<EFBFBD>W<EFBFBD>Spe
int ParamObject::getInteger(const char *paramName)
{
return(atoi(getString(paramName,PARAMS_INTEGER).c_str()));
}
//<EFBFBD><EFBFBD><EFBFBD>S<EFBFBD>te<EFBFBD>W<EFBFBD>Spe
long ParamObject::getLong(const char *paramName)
{
return(atol(getString(paramName,PARAMS_LONG).c_str()));
}
//<EFBFBD>Sc<EFBFBD>[<EFBFBD>Spe(W<EFBFBD>[a<EFBFBD>-N<EFBFBD>vc<EFBFBD><EFBFBD>MOn
int ParamObject::getParamPos(const char *paramName,unsigned char **stream,unsigned int &length,unsigned char &pNodeType,const unsigned char dataType)
{
unsigned int pos;
*stream =0;
std::map<std::string,unsigned long>::iterator itr;
std::string sName(paramName);
itr = paramNames.find(sName);
if(itr== paramNames.end())
{
return 0;
}
pos =itr->second;
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+pos );
if (0 == strcmp(pNode->name, paramName))
{
*stream = (unsigned char *)mParamsBuffer.GetBlobPtr() + pos + sizeof(ParamNode);
pNodeType = pNode->type;
length = pNode->length;
}
else
length = 0;
return (0==*stream)? 0:1;
}
//<EFBFBD><EFBFBD>W[&{2N<EFBFBD>W<EFBFBD>Spe <EFBFBD> N<EFBFBD><EFBFBD>Q<EFBFBD><EFBFBD>~_g&{'\0' <EFBFBD><EFBFBD>V:Nput<EFBFBD>v<EFBFBD>eP<EFBFBD>]\<EFBFBD>~_g&{'\0'X[eQ
std::string ParamObject::getString(const char *paramName,unsigned char dataType/*=PARAMS_STRING*/)
{
std::string sTemp="";
unsigned char tail_char;
unsigned int length;
unsigned char NodeType;
unsigned char *pParamPos;
if(0!= getParamPos(paramName,&pParamPos,length,NodeType,dataType))
{
//<EFBFBD>VPutStream<EFBFBD>e*gYtW[&{2N<EFBFBD>v<EFBFBD>~_g&{'\0' <EFBFBD>(Wُ̑<EFBFBD><EFBFBD><EFBFBD><EFBFBD>R
N
tail_char = *(pParamPos + length);
*(pParamPos + length) ='\0';
sTemp = (char *)(pParamPos);
*(pParamPos + length) =tail_char;
}
else
throw ERPException(EERROR,SYSTEM_ERROR,"parameter[%s]not found<EFBFBD>",paramName);
return sTemp;
}
bool ParamObject::getBlob(const char *paramName, BlobBuffer &blob,bool bException)
{
unsigned int length=0;
unsigned char *pParamPos = getBlobEx(paramName, length);
if (NULL == pParamPos)
{
if (0 == length)
{
if (bException)
throw ERPException(EERROR, SYSTEM_ERROR, "blob parameter[%s]not found<EFBFBD>", paramName);
else
return false;
}
else
{
if (bException)
throw ERPException(EERROR, SYSTEM_ERROR, "not a blob parameter[%s]<EFBFBD>", paramName);
else
return false;
}
}
else
blob.SetBlobContent(pParamPos, length);
return true;
}
unsigned char *ParamObject::getBlobEx(const char *paramName, unsigned int &length)
{
unsigned char NodeType;
unsigned char *pParamPos;
if (0 != getParamPos(paramName, &pParamPos, length, NodeType, PARAMS_BLOB))
{
if (PARAMS_BLOB == NodeType)
{
return pParamPos;
}
else
return NULL;
}
else
return NULL;
}
//$R<EFBFBD>e/f&T g<EFBFBD><EFBFBD>g<EFBFBD>Spe
bool ParamObject::isExist(const char *paramName)
{
//return paramNames.Find(DataSet::MyHash(paramName,strlen(paramName)));
return (paramNames.find(paramName)!=paramNames.end());
}
//<EFBFBD><EFBFBD>nm<EFBFBD>p<EFBFBD>W<EFBFBD>Spe
float ParamObject::getFloat(const char *paramName )
{
return (float)(atof(getString(paramName,PARAMS_FLOAT).c_str()));
}
//<EFBFBD><EFBFBD><EFBFBD>S<EFBFBD>|<EFBFBD>^<EFBFBD>Spe
double ParamObject::getDouble(const char *paramName )
{
return(atof(getString(paramName,PARAMS_DOUBLE).c_str()));
}
/*
//<EFBFBD><EFBFBD><EFBFBD>S<EFBFBD>^R<EFBFBD>Spe
void ParamObject::getDataSet(const char *paramName,DataSet &dataset )
{
unsigned int len;
unsigned char NodeType;
unsigned char *stream;
if(getParamPos(paramName,&stream,len,NodeType,PARAMS_DATASET))
{
if(PARAMS_DATASET==NodeType)
{
try
{
dataset.UnSerialize(stream,len);
dataset.setName(paramName);
}
catch(ERPException &e )
{
char c_time[128];
tm *temptm;
time_t temptime;
temptime= time(0);
temptm = localtime(&temptime);
sprintf(c_time,"%dt^%02dg%02d<EFBFBD>e %02d:%02d:%02d",
temptm->tm_year+1900,temptm->tm_mon+1,temptm->tm_mday,
temptm->tm_hour,temptm->tm_min,temptm->tm_sec);
WriteLog("ParamObject.log","a+",c_time,dataset.GetFieldNames().c_str());
sprintf(c_time,"%d%02d%02d%02d%02d%02d__8^penc.log",
temptm->tm_year+1900,temptm->tm_mon+1,temptm->tm_mday,
temptm->tm_hour,temptm->tm_min,temptm->tm_sec );
SaveToFile(c_time);
throw e;
}
}
else
throw ERPException(EERROR,SYSTEM_ERROR,"DataSet parameter[%s]not found<EFBFBD>",paramName);
}
else
{
throw ERPException(EERROR,SYSTEM_ERROR,"DataSet parameter[%s]not found<EFBFBD>",paramName);
}
}
*/
//<EFBFBD><EFBFBD><EFBFBD>SL]WY<EFBFBD>v<EFBFBD>Spe<EFBFBD>[a<EFBFBD>
void ParamObject::getParamObject(const char *paramName,ParamObject &obj)
{
unsigned int len;
unsigned char NodeType;
unsigned char *stream;
if(getParamPos(paramName,&stream,len,NodeType,PARAMS_ParamObject))
{
if(PARAMS_ParamObject==NodeType)
{
try
{
obj.LoadFromStream((const unsigned char *)stream,len);
}
catch(ERPException &e )
{
char c_time[128];
tm *temptm;
time_t temptime;
temptime= time(0);
temptm = localtime(&temptime);
sprintf(c_time,"%dt^%02dg%02d<EFBFBD>e %02d:%02d:%02d",
temptm->tm_year+1900,temptm->tm_mon+1,temptm->tm_mday,
temptm->tm_hour,temptm->tm_min,temptm->tm_sec);
sprintf(c_time,"%d%02d%02d%02d%02d%02d__8^penc.log",
temptm->tm_year+1900,temptm->tm_mon+1,temptm->tm_mday,
temptm->tm_hour,temptm->tm_min,temptm->tm_sec );
SaveToFile(c_time);
throw e;
}
}
else
throw ERPException(EERROR,SYSTEM_ERROR,"ParamObject parameter[%s]not found<EFBFBD>",paramName);
}
else
{
throw ERPException(EERROR,SYSTEM_ERROR,"ParamObject parameter[%s]not found<EFBFBD>",paramName);
}
}
//S_MR<EFBFBD>SpecT,{N*N<EFBFBD>Spe
void ParamObject::First()
{
curr_pos=0;
}
//S_MR<EFBFBD>SpecT NN*N<EFBFBD>Spe
void ParamObject::Next()
{
if(curr_pos>=mParamsBuffer.GetBlobLength())
return;
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
curr_pos +=sizeof(ParamNode)+pNode->length;
if(pNode->type==PARAMS_UNVALID_TYPE)
Next();
}
//$R<EFBFBD>e/f&T<EFBFBD>]0R<EFBFBD>N<EFBFBD>~>\
int ParamObject::Eof()
{
return (mParamsBuffer.GetBlobLength()==curr_pos)? 1:0;
}
//<EFBFBD>_0RS_MR<EFBFBD>Spe<EFBFBD>v T<EFBFBD>y
std::string ParamObject::getParamName()
{
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
return (pNode->name);
}
//<EFBFBD>_0RS_MR<EFBFBD>Spe<EFBFBD>v T<EFBFBD>y
int ParamObject::getParamType()
{
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
return (pNode->type);
}
//<EFBFBD>_0RS_MR<EFBFBD>Spe<EFBFBD>v<P
int ParamObject::getParamValue(unsigned char **value)
{
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
if(pNode->length<1)
{
throw ERPException(EERROR,SYSTEM_ERROR,"<EFBFBD><EFBFBD><EFBFBD>Spe NX[(W<EFBFBD>");
}
*value=new unsigned char[pNode->length];
memcpy((unsigned char *)*value,(unsigned char *)mParamsBuffer.GetBlobPtr()+curr_pos+sizeof(ParamNode),pNode->length);
return pNode->length;
}
void ParamObject::getParamValue(BlobBuffer *pBlob,unsigned char fillEndChar)
{
ParamNode *pNode;
pNode = (ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
if(pNode->length<1)
{
throw ERPException(EERROR,SYSTEM_ERROR,"<EFBFBD><EFBFBD><EFBFBD>Spe NX[(W<EFBFBD>");
}
pBlob->SetBlobContent((unsigned char *)mParamsBuffer.GetBlobPtr()+curr_pos+sizeof(ParamNode),pNode->length);
if(1==fillEndChar)
pBlob->AppendBlobContentChar('\0');
}
//<EFBFBD>_0RS_MR<EFBFBD>v<EFBFBD>Spe<EFBFBD>vW[&{2N<P <EFBFBD><EFBFBD>Y<EFBFBD>gS_MR<EFBFBD>Spe/fAm1\ԏ<EFBFBD>Vzz
std::string ParamObject::getParamValue()
{
ParamNode *pNode;
pNode =(ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
if(PARAMS_STREAM==pNode->type)
return "Am";
return std::string((char*)mParamsBuffer.GetBlobPtr() + curr_pos + sizeof(ParamNode), pNode->length);
/* std::vector<char> buffer(pNode->length + 1);
std::memcpy(buffer.data(), (char*)mParamsBuffer.GetBlobPtr() + curr_pos + sizeof(ParamNode), pNode->length);
std::memset(buffer.data() + pNode->length, '\0', 1);
return buffer.data();
*/
}
//--ԏ<EFBFBD>V<EFBFBD>[E<EFBFBD>W[<EFBFBD><EFBFBD>Amc<EFBFBD><EFBFBD>-----
const unsigned char *ParamObject::getBytePtr()
{
return mParamsBuffer.GetBlobPtr();
}
//---ԏ<EFBFBD>V<EFBFBD>[E<EFBFBD>W[<EFBFBD><EFBFBD>Am'Y\----
unsigned int ParamObject::getByteLength()
{
return mParamsBuffer.GetBlobLength();
}
//ԏ<EFBFBD>VS_<EFBFBD><EFBFBD>W[<EFBFBD><EFBFBD>;`<EFBFBD><EFBFBD>^
unsigned int ParamObject::getAllByteLength()
{
return mParamsBuffer.GetBlobBufferLength();
}
//clone
void ParamObject::Clone(ParamObject *pObject)
{
mParamsBuffer.SetBlobContent(pObject->mParamsBuffer.GetBlobPtr(),pObject->mParamsBuffer.GetBlobLength());
curr_pos =0; //S_MRc<EFBFBD><EFBFBD>MOn
InitParamNames();
}
//<EFBFBD>NBlob<EFBFBD>[a<EFBFBD>-N<EFBFBD>S<EFBFBD>^RS
void ParamObject::LoadFromBlob(BlobBuffer &blob)
{
LoadFromStream(blob.GetBlobPtr(),blob.GetBlobLength());
}
//<EFBFBD>^RS0RBlob<EFBFBD>[a<EFBFBD>-N
void ParamObject::SaveToBlob(BlobBuffer &blob)
{
blob.SetBlobContent(mParamsBuffer.GetBlobPtr(),mParamsBuffer.GetBlobLength());
}
/*/////////////////////////////////////////////////////////////////////////////
load param from the stream buffer
initial the paramnames
/////////////////////////////////////////////////////////////////////////////*/
void ParamObject::LoadFromStream(const unsigned char*in_buffer,unsigned int len)
{
mParamsBuffer.SetBlobContent(in_buffer,len);
curr_pos = 0; //S_MRc<EFBFBD><EFBFBD>MOn
InitParamNames();
}
//load the ParamObject from the file which has the ParamObject format
void ParamObject::LoadFromFile(const char *file_name)
{
mParamsBuffer.LoadBlobFromFile(file_name);
curr_pos = 0; //S_MRc<EFBFBD><EFBFBD>MOn
InitParamNames();
}
//save the ParamObject as the ParamObject format
void ParamObject::SaveToFile(const char *file_name)
{
mParamsBuffer.SaveBlobToFile(file_name);
}
/*/////////////////////////////////////////////////////////////////////////////
----regenerate the param names and the index ---
////////////////////////////////////////////////////////////////////////////*/
void ParamObject::InitParamNames()
{
ParamNode *pNode;
curr_pos=0;
paramNames.clear();
//unsigned int key;
std::map<std::string,unsigned long>::iterator itr;
while(curr_pos< mParamsBuffer.GetBlobLength())
{
pNode =(ParamNode *)( (unsigned char*)mParamsBuffer.GetBlobPtr()+curr_pos );
/*
key = DataSet::MyHash(pNode->name,strlen(pNode->name));
if(paramNames.Find(key))
paramNames.Delete(key);
paramNames.Insert(key,curr_pos);
*/
itr = paramNames.find(pNode->name);
if(itr != paramNames.end())
paramNames.erase(itr);
paramNames.insert(std::map<std::string,unsigned long>::value_type(pNode->name,curr_pos));
curr_pos+=sizeof(ParamNode)+pNode->length;
}
curr_pos=0;
}
//ԏ<EFBFBD>V<EFBFBD>Spe*Npe <EFBFBD><EFBFBD>Y<EFBFBD>g gY!kputstring TN*N<EFBFBD>Spe <EFBFBD>Rsize<EFBFBD>eaIN <EFBFBD>
unsigned int ParamObject::getParamCount()
{
return paramNames.size();
}
void ParamObject::WriteLog(const char *file_name,const char *open_flag, const char *head_title,const char *text)
{
FILE *fp;
fp = fopen(file_name,open_flag);
fprintf(fp,"%s\n",head_title);
if(NULL==text)
{
First();
while( !Eof() )
{
fprintf(fp," %s=%s\n",getParamName().c_str(), getParamValue().c_str());
Next();
}
}
else
fprintf(fp," %s=%s\n",getParamName().c_str(),text);
fclose(fp);
}
CFileStream::CFileStream(const CFileStream &other)
{
}
CFileStream &CFileStream::operator=(const CFileStream &)
{
return *this;
}
CFileStream::CFileStream()
{
}
CFileStream::~CFileStream()
{
}
//<EFBFBD>ReQ<EFBFBD>e<EFBFBD>N
bool CFileStream::PutFile(const char *fileName, BlobBuffer &blob)
{
//9e:N N:SR'Y\<EFBFBD>Q'T <EFBFBD>soui ui<EFBFBD>^'Y\<EFBFBD>Q<EFBFBD>k<EFBFBD><EFBFBD>qN<EFBFBD><EFBFBD>.
std::string file_name(fileName);
file_name = tolowerstring(file_name);
this->putBlob(file_name.c_str(), blob);
return true;
}
//<EFBFBD>ReQ<EFBFBD>e<EFBFBD>N
bool CFileStream::GetFile(const char *fileName, BlobBuffer &blob)
{
//9e:N N:SR'Y\<EFBFBD>Q'T <EFBFBD>soui ui<EFBFBD>^'Y\<EFBFBD>Q<EFBFBD>k<EFBFBD><EFBFBD>qN<EFBFBD><EFBFBD>.
std::string file_name(fileName);
file_name = tolowerstring(file_name);
#ifdef _DEBUG
return getBlob(file_name.c_str(), blob, true);
#else
return getBlob(file_name.c_str(), blob, false);
#endif
}
int CFileStream::GetFileCount()
{
return getParamCount();
}
const unsigned char *CFileStream::GetAllBasePtr()
{
return getBytePtr(); //ԏ<EFBFBD>V<EFBFBD>Q<EFBFBD><EFBFBD>W[<EFBFBD><EFBFBD>Am<EFBFBD>vc<EFBFBD><EFBFBD>
}
unsigned long CFileStream::GetFileSize(const char *fileName)
{
unsigned int length = 0;
if (NULL != getBlobEx(fileName, length))
return length;
else
return 0;
}
const unsigned char *CFileStream::GetFilePtr(const char *fileName)
{
unsigned int length = 0;
unsigned char *pParamPos = getBlobEx(fileName, length);
return pParamPos;
}
unsigned int CFileStream::GetAllSize()
{
return getByteLength();
}