You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
455 lines
11 KiB
C++
455 lines
11 KiB
C++
// BlackFinder.cpp : Defines the entry point for the DLL application.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include <vector>
|
|
#include "BlackFinder.h"
|
|
#include "BlackList.h"
|
|
#include "global.h"
|
|
#include "WriteLog.h"
|
|
|
|
using namespace std;
|
|
|
|
static vector<CBlackList *> gBlackList;
|
|
HINSTANCE hDll = NULL;
|
|
FARPROC pFnOnDll = NULL;
|
|
|
|
BOOL APIENTRY DllMain( HANDLE hModule,
|
|
DWORD ul_reason_for_call,
|
|
LPVOID lpReserved
|
|
)
|
|
{
|
|
switch (ul_reason_for_call)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
hDll = ::LoadLibrary("kernel32.dll");
|
|
if(hDll)
|
|
{
|
|
pFnOnDll = ::GetProcAddress(hDll, "OpenThread");
|
|
}
|
|
|
|
break;
|
|
case DLL_THREAD_ATTACH:
|
|
break;
|
|
case DLL_THREAD_DETACH:
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
if(hDll)
|
|
{
|
|
::FreeLibrary(hDll);
|
|
}
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
CBlackList* GetHashObj(HANDLE p, const bool bRemove)
|
|
{
|
|
for (vector<CBlackList *>::iterator it = gBlackList.begin(); it != gBlackList.end(); it++)
|
|
{
|
|
if (*it == (CBlackList *)p)
|
|
{
|
|
if (bRemove)
|
|
{
|
|
gBlackList.erase(it);
|
|
}
|
|
return (CBlackList *)p;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HANDLE HASH_CreateList()
|
|
{
|
|
if (!pFnOnDll)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
CBlackList *p = new CBlackList();
|
|
// WriteLog("HASH_CreateList p=%p", p);
|
|
|
|
if (p != NULL)
|
|
{
|
|
p->SetOpenThreadPtr((PFN_OpenThread)pFnOnDll);
|
|
|
|
gBlackList.push_back(p);
|
|
return (HANDLE)p;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_DestroyList(HANDLE hHandle)
|
|
{
|
|
CBlackList *p = GetHashObj(hHandle, true);
|
|
if (p != NULL)
|
|
{
|
|
delete p;
|
|
return S_OK;
|
|
}
|
|
return ERR_INVALID_HANDLE;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_LoadList(
|
|
HANDLE hHandle,char * pDBFFileName,char * pStrKeyFieldName)
|
|
|
|
{
|
|
|
|
int ilen;
|
|
|
|
WriteLog("HASH_LoadList para handle = %d,name = %s, key = %s",hHandle,pDBFFileName,pStrKeyFieldName);
|
|
if ((!hHandle) || (!pDBFFileName) || (!pStrKeyFieldName))
|
|
{
|
|
WriteLog("HASH_LoadList %d ²ÎÊý´íÎó",hHandle);
|
|
return ERR_LOAD_LIST_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pDBFFileName);
|
|
if( (ilen <=0) || ( ilen >= 256) )
|
|
{
|
|
WriteLog("HASH_LoadList %d pDBFFileName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_LOAD_LIST_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pStrKeyFieldName);
|
|
if( (ilen <=0) || ( ilen >= MAX_PRIKEYNAME_LEN) )
|
|
{
|
|
WriteLog("HASH_LoadList %d pStrKeyFieldName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_LOAD_LIST_FAIL;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
if (pObj->Load(pDBFFileName, pStrKeyFieldName))
|
|
{
|
|
return S_OK;
|
|
}
|
|
else
|
|
{
|
|
// WriteLog("HASH_LoadList¼ÓÔØÊ§°Ü(%s)", pDBFFileName);
|
|
return ERR_LOAD_LIST_FAIL;
|
|
}
|
|
}
|
|
WriteLog("HASH_doLoadList:ÎÞЧµÄ¾ä±úhandle=%p", hHandle);
|
|
|
|
return ERR_INVALID_HANDLE;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_LoadListBack(
|
|
HANDLE hHandle,HANDLE hMsgWnd,ULONG iMsgValue,ULONG iListId,
|
|
char * pMainDBFFileName,char * pSlaveDBFFileName,char * pStrKeyFieldName)
|
|
{
|
|
|
|
|
|
int ilen;
|
|
WriteLog("HASH_LoadListBack para handle = %d,msgwnd = %d ,iMsgValue = %d, ListId =%d,pMainDBFFileName = %s,pSlaveDBFFileName = %s, pStrKeyFieldName = %s",
|
|
hHandle,hMsgWnd,iMsgValue,iListId,pMainDBFFileName,pSlaveDBFFileName,pStrKeyFieldName);
|
|
|
|
if ((!hHandle) || (!hMsgWnd) || (!pMainDBFFileName)
|
|
|| (!pSlaveDBFFileName) || (!pStrKeyFieldName))
|
|
{
|
|
WriteLog("HASH_LoadListBack ²ÎÊý´íÎó");
|
|
return ERR_LOAD_LIST_BACK_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pMainDBFFileName);
|
|
if( (ilen <=0) || ( ilen >= 256) )
|
|
{
|
|
WriteLog("HASH_LoadListBack %d pDBFFileName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_LOAD_LIST_BACK_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pSlaveDBFFileName);
|
|
if( (ilen <=0) || ( ilen >= 256) )
|
|
{
|
|
WriteLog("HASH_LoadListBack %d pSlaveDBFFileName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_LOAD_LIST_BACK_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pStrKeyFieldName);
|
|
if( (ilen <=0) || ( ilen >= MAX_PRIKEYNAME_LEN) )
|
|
{
|
|
WriteLog("HASH_LoadListBack %d pStrKeyFieldName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_LOAD_LIST_BACK_FAIL;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
if(pObj->LoadListBack((HANDLE)hMsgWnd, iMsgValue, iListId, pMainDBFFileName, pSlaveDBFFileName, pStrKeyFieldName) == S_OK)
|
|
{
|
|
return S_OK;
|
|
}
|
|
else
|
|
{
|
|
WriteLog("HASH_LoadListBack¼ÓÔØÊ§°Ü(main %s)(slave %s)", pMainDBFFileName,pSlaveDBFFileName);
|
|
return ERR_LOAD_LIST_BACK_FAIL;
|
|
}
|
|
}
|
|
|
|
WriteLog("HASH_LoadListBack:ÎÞЧµÄ¾ä±úhandle=%p", hHandle);
|
|
return ERR_INVALID_HANDLE;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_Find(
|
|
HANDLE hHandle,char * pStrKeyValue,char * pRetBuffer,int RetBufferLen)
|
|
|
|
{
|
|
int iRet;
|
|
string stemp;
|
|
string sname;
|
|
|
|
if ((!hHandle) || (!pStrKeyValue) || (!pRetBuffer) || (RetBufferLen <= 0))
|
|
{
|
|
WriteLog("HASH_Find %d ²ÎÊý´íÎó",hHandle);
|
|
return 0;
|
|
}
|
|
|
|
iRet =strlen(pStrKeyValue);
|
|
if(iRet <=0)
|
|
{
|
|
WriteLog("HASH_Find %d pStrKeyValue Ϊ¿Õ",hHandle);
|
|
return 0;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
bool bFound = false;
|
|
|
|
sname = pObj->GetDbfFileName();
|
|
stemp = pObj->GetPriKeyName();
|
|
// WriteLog("start find table %s prikey %s key %s",sname.c_str(),stemp.c_str(),pStrKeyValue);
|
|
string sInfo = pObj->Find(pStrKeyValue, bFound, false);
|
|
if (RetBufferLen > sInfo.length()) {
|
|
strcpy(pRetBuffer, sInfo.c_str());
|
|
}
|
|
else
|
|
{
|
|
WriteLog("HASH_Find:´æ´¢¿Õ¼ä·ÖÅä¹ýС");
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1001,\"ERRORINFO\":\"´æ´¢¿Õ¼ä·ÖÅä¹ýС\"}");
|
|
|
|
// return ERR_FIND_FAIL;
|
|
return 0;
|
|
}
|
|
|
|
if (bFound)
|
|
{
|
|
iRet = strlen(pRetBuffer);
|
|
stemp = pObj->GetPriKeyName();
|
|
// WriteLog("find key %s prikey is %s ·µ»Ø %s ³¤¶È %d",pStrKeyValue,stemp.c_str(),pRetBuffer,iRet);
|
|
return iRet;
|
|
}
|
|
else
|
|
{
|
|
//return ERR_FIND_FAIL;
|
|
//iRet = strlen(pRetBuffer);
|
|
stemp = pObj->GetPriKeyName();
|
|
//WriteLog("find key %s prikey is %s ʧ°Ü ·µ»Ø %s",pStrKeyValue,stemp.c_str(),sInfo.c_str());
|
|
// WriteLog("find key %s ʧ°Ü",pStrKeyValue);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1000,\"ERRORINFO\":\"ÎÞЧµÄ¾ä±ú\"}");
|
|
WriteLog("HASH_Find:ÎÞЧµÄ¾ä±ú");
|
|
// return ERR_FIND_FAIL;
|
|
return 0;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_Find2(
|
|
HANDLE hHandle,char * pStrKeyValue,char * pRetBuffer,int RetBufferLen)
|
|
{
|
|
|
|
int iRet;
|
|
string stemp;
|
|
string sname;
|
|
if ((!hHandle) || (!pStrKeyValue) || (!pRetBuffer) || (RetBufferLen <= 0))
|
|
{
|
|
WriteLog("HASH_Find2 ²ÎÊý´íÎó");
|
|
return 0;
|
|
}
|
|
|
|
iRet =strlen(pStrKeyValue);
|
|
if(iRet <=0)
|
|
{
|
|
WriteLog("HASH_Find2 %d pStrKeyValue Ϊ¿Õ",hHandle);
|
|
return 0;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
sname = pObj->GetDbfFileName();
|
|
stemp = pObj->GetPriKeyName();
|
|
// WriteLog("start find table %s prikey %s key %s",sname.c_str(),stemp.c_str(),pStrKeyValue);
|
|
|
|
|
|
bool bFound = false;
|
|
string sInfo = pObj->Find(pStrKeyValue, bFound, true);
|
|
if (RetBufferLen > sInfo.length())
|
|
{
|
|
strcpy(pRetBuffer, sInfo.c_str());
|
|
}
|
|
else
|
|
{
|
|
WriteLog("HASH_Find2:´æ´¢¿Õ¼ä·ÖÅä¹ýС");
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1001,\"ERRORINFO\":\"´æ´¢¿Õ¼ä·ÖÅä¹ýС\"}");
|
|
return 0;
|
|
}
|
|
if (bFound)
|
|
{
|
|
iRet = strlen(pRetBuffer);
|
|
stemp = pObj->GetPriKeyName();
|
|
// WriteLog("find key %s table is %s prikey is %s ·µ»Ø %s ³¤¶È %d",pStrKeyValue,sname.c_str(),stemp.c_str(),pRetBuffer,iRet);
|
|
return iRet;
|
|
}
|
|
else
|
|
{
|
|
stemp = pObj->GetPriKeyName();
|
|
|
|
// WriteLog("find key %s table is %s prikey is %s ʧ°Ü,·µ»Ø%s",pStrKeyValue,sname.c_str(),stemp.c_str(),sInfo.c_str());
|
|
// WriteLog("find key %s ʧ°Ü",pStrKeyValue);
|
|
return 0;
|
|
}
|
|
}
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1000,\"ERRORINFO\":\"ÎÞЧµÄ¾ä±ú\"}");
|
|
WriteLog("HASH_Find2:ÎÞЧµÄ¾ä±ú");
|
|
return 0;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_Find3(
|
|
/* [in] */ HANDLE hHandle,
|
|
/* [in] */ char * pStrWhere,
|
|
/* [out] */char * pRetBuffer,
|
|
int RetBufferLen
|
|
)
|
|
{
|
|
int iRet;
|
|
string stemp;
|
|
string sname;
|
|
if ((!hHandle) || (!pStrWhere) || (!pRetBuffer) || (RetBufferLen <= 0))
|
|
{
|
|
WriteLog("HASH_Find3 ²ÎÊý´íÎó");
|
|
return 0;
|
|
}
|
|
|
|
iRet =strlen(pStrWhere);
|
|
if(iRet <=0)
|
|
{
|
|
WriteLog("HASH_Find3 %d pStrWhere Ϊ¿Õ",hHandle);
|
|
return 0;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
sname = pObj->GetDbfFileName();
|
|
// stemp = pObj->GetPriKeyName();
|
|
// WriteLog("start find3 table %s where %s ",sname.c_str(),pStrWhere);
|
|
|
|
|
|
bool bFound = false;
|
|
string sInfo = pObj->FinDSqWhere(pStrWhere, bFound);
|
|
if (RetBufferLen > sInfo.length())
|
|
{
|
|
strcpy(pRetBuffer, sInfo.c_str());
|
|
}
|
|
else
|
|
{
|
|
WriteLog("HASH_Find3:´æ´¢¿Õ¼ä·ÖÅä¹ýС");
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1001,\"ERRORINFO\":\"´æ´¢¿Õ¼ä·ÖÅä¹ýС\"}");
|
|
return 0;
|
|
}
|
|
if (bFound)
|
|
{
|
|
iRet = strlen(pRetBuffer);
|
|
|
|
// WriteLog("find key %s table is %s prikey is %s ·µ»Ø %s ³¤¶È %d",pStrKeyValue,sname.c_str(),stemp.c_str(),pRetBuffer,iRet);
|
|
return iRet;
|
|
}
|
|
else
|
|
{
|
|
//stemp = pObj->GetPriKeyName();
|
|
// WriteLog("find3 where %s table is %s ʧ°Ü,·µ»Ø%s",pStrWhere,sname.c_str(),sInfo.c_str());
|
|
// WriteLog("find key %s ʧ°Ü",pStrKeyValue);
|
|
return 0;
|
|
}
|
|
}
|
|
strcpy(pRetBuffer, "{\"RETCODE\":-1000,\"ERRORINFO\":\"ÎÞЧµÄ¾ä±ú\"}");
|
|
WriteLog("HASH_Find2:ÎÞЧµÄ¾ä±ú");
|
|
return 0;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_BackOnline(
|
|
HANDLE hHandle,char * pBlackFilePath,char * pBlackFileName)
|
|
|
|
{
|
|
int ilen;
|
|
WriteLog("HASH_BackOnline para handle = %d,pBlackFilePath = %s,pBlackFileName = %s",
|
|
hHandle,pBlackFilePath,pBlackFileName);
|
|
|
|
if ((!hHandle) || (!pBlackFilePath) || (!pBlackFileName))
|
|
{
|
|
WriteLog("HASH_BackOnline ²ÎÊý´íÎó");
|
|
return ERR_BACK_ON_LINE_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pBlackFilePath);
|
|
if( (ilen <=0) || ( ilen >= 256) )
|
|
{
|
|
WriteLog("HASH_BackOnline %d pBlackFilePath ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_BACK_ON_LINE_FAIL;
|
|
}
|
|
|
|
ilen =strlen(pBlackFileName);
|
|
if( (ilen <=0) || ( ilen >= 256) )
|
|
{
|
|
WriteLog("HASH_BackOnline %d pBlackFileName ³¤¶È´íÎó %d",hHandle,ilen);
|
|
return ERR_BACK_ON_LINE_FAIL;
|
|
}
|
|
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
if (pObj->BackOnline(pBlackFilePath, pBlackFileName) == S_OK)
|
|
{
|
|
return S_OK;
|
|
}
|
|
else {
|
|
WriteLog("HASH_BackOnlineʧ°Ü,HANDLE=%p, BlackFileName=%s", pObj, pBlackFileName);
|
|
return ERR_BACK_ON_LINE_FAIL;
|
|
}
|
|
}
|
|
|
|
WriteLog("HASH_BackOnline:ÎÞЧµÄ¾ä±úhandle=%p", hHandle);
|
|
return ERR_INVALID_HANDLE;
|
|
}
|
|
|
|
extern "C" BLACKFINDER_API HRESULT HASH_GetVerInfo(
|
|
HANDLE hHandle,char * pVerFieldName,char * pRetBuffer,int RetBufferLen)
|
|
{
|
|
if ((!hHandle) || (!pVerFieldName) || (!pRetBuffer) || (RetBufferLen <= 0))
|
|
{
|
|
WriteLog("HASH_GetVerInfo ²ÎÊý´íÎó");
|
|
return ERR_GET_VER_FAIL;
|
|
}
|
|
|
|
strcpy(pRetBuffer, "");
|
|
CBlackList *pObj = GetHashObj(hHandle, false);
|
|
if (pObj != NULL)
|
|
{
|
|
int RecordCount = 0;
|
|
string strVer = pObj->GetVerInfo(pVerFieldName, RecordCount);
|
|
if (strVer.length() < RetBufferLen)
|
|
{
|
|
strcpy(pRetBuffer, strVer.c_str());
|
|
}
|
|
return RecordCount;
|
|
}
|
|
WriteLog("HASH_GetVerInfo:ÎÞЧµÄ¾ä±ú:%s", pVerFieldName);
|
|
return ERR_INVALID_HANDLE;
|
|
}
|
|
|