#if defined(_WIN32)
# define WIN32_LEAN_AND_MEAN 1
# include <windows.h>
# define DLLHANDLE HMODULE
# define LOADERLIB "p6loader.dll"
# define LOADLIB(fn) LoadLibraryA((fn))
# define LOADSYMBOL(h,s) GetProcAddress((HMODULE)(h),(s))
# define FREELIB(h) FreeLibrary((HMODULE)(h))
#else
# include <string.h>
# include <dlfcn.h>
# include <unistd.h>
# define DLLHANDLE void*
# define LOADERLIB "libp6loader.so"
# define LOADLIB(fn) dlopen((fn),RTLD_NOW)
# define LOADSYMBOL(h,s) dlsym((h),(s))
# define FREELIB(h) !dlclose((h))
#endif
#include <stdio.h>
#include <stdlib.h>
#undef P6ASSERT
#define P6ASSERT(x)
using namespace P6R;
DLLHANDLE ghDll = NULL;
P6DLLAPI gAPI;
{
if(!dest || !cDest || !source) return eInvalidArg;
if(pcCopied) *pcCopied = 0;
for(i=0;0 != source[i] && i < cDest-1;i++) dest[i] = source[i];
dest[i] = '\0';
if(pcCopied) *pcCopied = i;
if(0 != source[i])
return eTooBig;
return err;
}
#if defined(__linux__)
__attribute__((constructor)) void on_load(void)
{
Dl_info dl_info;
dladdr((void *)on_load,&dl_info);
strlcpy(&gszModuleDir[0],
P6CNTOF(gszModuleDir),dl_info.dli_fname,NULL);
}
#endif
{
if(!dest || !cDest || !source) return eInvalidArg;
if(pcCopied) *pcCopied = 0;
if(len2 > (cDest - len1 - 1)) {
return eTooBig;
}
for(i=len1;j<len2 && i<cDest-1;i++,j++)
dest[i] = source[j];
dest[i] = '\0';
if(pcCopied) *pcCopied = j;
return err;
}
{
if(NULL != (pszOrignalPath =
new(std::nothrow)
P6CHAR[P6MAXPATH])) {
FILE *pFile = NULL;
err = eOk;
strlcpy(pszOrignalPath,P6MAXPATH,pszPath,NULL);
strlcpy(pszConfFile,P6MAXPATH,pszPath,NULL);
strlcat(pszConfFile,P6MAXPATH,"/install.conf",NULL);
if(NULL != (pFile = fopen(pszConfFile,"r"))) {
if(NULL == fgets(pBuffer,cBuffer,pFile)) {
strlcpy(pBuffer,cBuffer,pszOrignalPath,NULL);
}
else {
}
fclose(pFile);
}
else {
strlcpy(pBuffer,cBuffer,pszOrignalPath,NULL);
err = eOk;
}
delete [] pszOrignalPath;
}
delete [] pszConfFile;
}
return err;
}
{
if(!pBuffer || !cBuffer)
return eInvalidArg;
pBuffer[0] = '\0';
#if defined(_WIN32)
HMODULE hm = NULL;
if (0 != GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | \
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR) &getModuleDir,
&hm)) {
if(0 != GetModuleFileNameA(hm,pBuffer,cBuffer)) {
while(*pTmp) {
if('\\' == *pTmp) *pTmp = '/';
pTmp++;
}
pszEnd = strrchr(pBuffer,'/');
if(NULL != pszEnd) *pszEnd = '\0';
err = readInstallConf(pBuffer,pBuffer,cBuffer);
}
}
else {
err = eFail;
}
#elif defined(__linux__)
if(gszModuleDir[0]) {
strlcpy(pBuffer,cBuffer,&gszModuleDir[0],NULL);
pszEnd = strrchr(pBuffer,'/');
if(NULL != pszEnd) *pszEnd = '\0';
err = readInstallConf(pBuffer,pBuffer,cBuffer);
}
else {
err = P6R::eFail;
}
#else
#pragma error("Unsupported Operating System. Code must be added to handle this OS")
#endif
return err;
}
{
if(!pMemory || !nBytes)
return;
while(nBytes) {
*pTmp = (
P6CHAR) nValue & 0xff;
pTmp++;
nBytes--;
}
}
{
P6ERR err = eDllNotFound;
setMem(&gAPI,0,sizeof(gAPI));
strcat(&szLib[0],"/");
strcat(&szLib[0],LOADERLIB);
if(NULL != (ghDll = LOADLIB(&szLib[0]))) {
gAPI.p6CreateInstance = (
P6CREATEINSTANCE) LOADSYMBOL(ghDll,
"p6CreateInstance");
gAPI.p6UUIDToString = (
P6UUIDTOSTRING) LOADSYMBOL(ghDll,
"p6UUIDToString");
gAPI.p6StringToUUID = (
P6STRINGTOUUID) LOADSYMBOL(ghDll,
"p6StringToUUID");
gAPI.p6UUIDToWString = (
P6UUIDTOWSTRING) LOADSYMBOL(ghDll,
"p6UUIDToWString");
gAPI.p6WStringToUUID = (
P6WSTRINGTOUUID) LOADSYMBOL(ghDll,
"p6WStringToUUID");
gAPI.p6GetDirectory = (
P6GETDIRECTORY) LOADSYMBOL(ghDll,
"p6GetDirectory");
gAPI.p6ErrToStr = (
P6ERRTOSTR) LOADSYMBOL(ghDll,
"p6ErrToStr");
gAPI.p6ErrToWStr = (
P6ERRTOWSTR) LOADSYMBOL(ghDll,
"p6ErrToWStr");
gAPI.p6AtomicInc32 = (
P6ATOMICINC32) LOADSYMBOL(ghDll,
"p6AtomicInc32");
gAPI.p6AtomicDec32 = (
P6ATOMICDEC32) LOADSYMBOL(ghDll,
"p6AtomicDec32");
gAPI.p6AtomicAdd32 = (
P6ATOMICADD32) LOADSYMBOL(ghDll,
"p6AtomicAdd32");
gAPI.p6AtomicSet32 = (
P6ATOMICSET32) LOADSYMBOL(ghDll,
"p6AtomicSet32");
gAPI.p6AtomicSet64 = (
P6ATOMICSET64) LOADSYMBOL(ghDll,
"p6AtomicSet64");
gAPI.p6AtomicSetPtr = (
P6ATOMICSETPTR) LOADSYMBOL(ghDll,
"p6AtomicSetPtr");
gAPI.p6HashData = (
P6HASHDATA) LOADSYMBOL(ghDll,
"p6HashData");
gAPI.p6HashString = (
P6HASHSTRING) LOADSYMBOL(ghDll,
"p6HashString");
gAPI.p6HashStringW = (
P6HASHSTRINGW) LOADSYMBOL(ghDll,
"p6HashStringW");
gAPI.p6HashBCSTR = (
P6HASHBCSTR) LOADSYMBOL(ghDll,
"p6HashBCSTR");
gAPI.p6HashBWCSTR = (
P6HASHBWCSTR) LOADSYMBOL(ghDll,
"p6HashBWCSTR");
gAPI.p6HashUINT32 = (
P6HASHUINT32) LOADSYMBOL(ghDll,
"p6HashUINT32");
gAPI.p6HashUINT64 = (
P6HASHUINT64) LOADSYMBOL(ghDll,
"p6HashUINT64");
gAPI.p6HashUINT64to32 = (
P6HASHUINT64TO32) LOADSYMBOL(ghDll,
"p6HashUINT64to32");
gAPI.p6TraceAddref = (
P6TRACEADDREF) LOADSYMBOL(ghDll,
"p6TraceAddref");
gAPI.p6TraceRelease = (
P6TRACERELEASE) LOADSYMBOL(ghDll,
"p6TraceRelease");
if(gp6InitializeLoader && \
gp6CleanupLoader && \
gAPI.p6CreateInstance && \
gAPI.p6CreateCryptoInstance && \
gAPI.p6GetCryptoProviderVersion && \
gAPI.p6GetRuntimeIface && \
gAPI.p6GetThreadLogger && \
gAPI.p6UUIDToString && \
gAPI.p6StringToUUID && \
gAPI.p6UUIDToWString && \
gAPI.p6WStringToUUID && \
gAPI.p6ErrToStr && \
gAPI.p6ErrToWStr && \
gAPI.p6AtomicInc32 && \
gAPI.p6AtomicDec32 && \
gAPI.p6AtomicAdd32 && \
gAPI.p6AtomicSet32 &&\
gAPI.p6AtomicSet64 &&\
gAPI.p6AtomicSetPtr &&\
gAPI.p6HashData &&\
gAPI.p6HashString &&\
gAPI.p6HashStringW &&\
gAPI.p6HashBCSTR &&\
gAPI.p6HashBWCSTR &&\
gAPI.p6HashUINT32 &&\
gAPI.p6HashUINT64 &&\
gAPI.p6HashUINT64to32 &&\
gAPI.p6TraceAddref && \
gAPI.p6TraceRelease) {
err = eOk;
}
else {
if(!gp6InitializeLoader) fprintf(stderr,"ERROR: Symbol Not Found [ p6InitializeLoader ]\n");
if(!gp6CleanupLoader) fprintf(stderr,"ERROR: Symbol Not Found [ p6CleanupLoader ]\n");
if(!gAPI.p6CreateInstance) fprintf(stderr,"ERROR: Symbol Not Found [ p6CreateInstance ]\n");
if(!gAPI.p6CreateCryptoInstance) fprintf(stderr,"ERROR: Symbol Not Found [ p6CreateCryptoInstance ]\n");
if(!gAPI.p6GetCryptoProviderVersion) fprintf(stderr,"ERROR: Symbol Not Found [ p6GetCryptoProviderVersion ]\n");
if(!gAPI.p6GetRuntimeVersion) fprintf(stderr,"ERROR: Symbol Not Found [ p6GetRuntimeVersion ]\n");
if(!gAPI.p6GetThreadLogger) fprintf(stderr,"ERROR: Symbol Not Found [ p6GetThreadLogger ]\n");
if(!gAPI.p6UUIDToString) fprintf(stderr,"ERROR: Symbol Not Found [ p6UUIDToString ]\n");
if(!gAPI.p6StringToUUID) fprintf(stderr,"ERROR: Symbol Not Found [ p6StringToUUID ]\n");
if(!gAPI.p6UUIDToWString) fprintf(stderr,"ERROR: Symbol Not Found [ p6UUIDToWString ]\n");
if(!gAPI.p6WStringToUUID) fprintf(stderr,"ERROR: Symbol Not Found [ p6WStringToUUID ]\n");
if(!gAPI.p6GetRuntimeIface) fprintf(stderr,"ERROR: Symbol Not Found [ p6GetRuntimeIface ]\n");
if(!gAPI.p6GetDirectory) fprintf(stderr,"ERROR: Symbol Not Found [ gp6GetDirectory ]\n");
if(!gAPI.p6ErrToStr) fprintf(stderr,"ERROR: Symbol Not Found [ p6ErrToStr ]\n");
if(!gAPI.p6ErrToWStr) fprintf(stderr,"ERROR: Symbol Not Found [ p6ErrToWStr ]\n");
if(!gAPI.p6AtomicInc32) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicInc32 ]\n");
if(!gAPI.p6AtomicDec32) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicDec32 ]\n");
if(!gAPI.p6AtomicAdd32) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicAdd32 ]\n");
if(!gAPI.p6AtomicSet32) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicSet32 ]\n");
if(!gAPI.p6AtomicSet64) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicSet64 ]\n");
if(!gAPI.p6AtomicSetPtr) fprintf(stderr,"ERROR: Symbol Not Found [ p6AtomicSetptr ]\n");
if(!gAPI.p6HashData) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashData ]\n");
if(!gAPI.p6HashString) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashString ]\n");
if(!gAPI.p6HashStringW) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashStringW ]\n");
if(!gAPI.p6HashBCSTR) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashBCSTR ]\n");
if(!gAPI.p6HashBWCSTR) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashBWCSTR ]\n");
if(!gAPI.p6HashUINT32) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashUINT32 ]\n");
if(!gAPI.p6HashUINT64) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashUINT64 ]\n");
if(!gAPI.p6HashUINT64to32) fprintf(stderr,"ERROR: Symbol Not Found [ p6HashUINT64to32 ]\n");
if(!gAPI.p6TraceAddref) fprintf(stderr,"ERROR: Symbol Not Found [ p6TraceAddref ]\n");
if(!gAPI.p6TraceRelease) fprintf(stderr,"ERROR: Symbol Not Found [ p6TraceRelease ]\n");
err = eNotFound;
}
}
else {
#if defined(_WIN32)
fprintf(stderr,"ERROR: Failed to dynamially load '%s' [ %x ]\nERROR: OS Error: %x\n",&szLib[0],err,::GetLastError());
#else
fprintf(stderr,"ERROR: Failed to dynamially load '%s' [ %x ]\nERROR: OS Error: %s\n",&szLib[0],err,dlerror());
#endif
}
}
return err;
}
static void unloadSymbols()
{
if(NULL != ghDll) {
(void) FREELIB(ghDll);
}
}
{
if(
P6FAILED(err = gp6InitializeLoader(pLogSink,nVerbosity,fFlags))) {
fprintf(stderr,
"ERROR: p6InitializeLoader() Failed [ %s ]\n",gAPI.p6ErrToStr(err,&szErr[0],
P6CHARCNT(szErr)));
}
}
return err;
}
{
P6ERR err = gp6CleanupLoader();
unloadSymbols();
return err;
}
{
if(!gAPI.p6GetRuntimeVersion) return eNotInitialized;
return gAPI.p6GetRuntimeVersion(pVerInfo);
}
{
if(!pBuffer || !cBuffer)
return eInvalidArg;
return gAPI.p6UUIDToString(uuid,pBuffer,cBuffer);
}
{
if(!gAPI.p6StringToUUID) return eNotInitialized;
return gAPI.p6StringToUUID(pszUUID, uuid);
}
{
if(!pBuffer || !cBuffer)
return eInvalidArg;
return gAPI.p6UUIDToWString(uuid,pBuffer,cBuffer);
}
{
if(!gAPI.p6WStringToUUID) return eNotInitialized;
return gAPI.p6WStringToUUID(pszUUID,uuid);
}
{
if(!gAPI.p6GetRuntimeIface) return eNotInitialized;
return gAPI.p6GetRuntimeIface(iid, ppIface);
}
{
if(!gAPI.p6CreateInstance) return eNotInitialized;
return gAPI.p6CreateInstance(pOuter,cid,iid,ppIface);
}
{
if(!gAPI.p6CreateCryptoInstance) return eNotInitialized;
return gAPI.p6CreateCryptoInstance(cid,iid,ppIface);
}
{
if(!gAPI.p6GetCryptoProviderVersion) return eNotInitialized;
return gAPI.p6GetCryptoProviderVersion(pBuffer,cBuffer,pcWritten,bVerbose);
}
{
if(!gAPI.p6GetDirectory) return eNotInitialized;
return gAPI.p6GetDirectory(nDir,pBuffer,cBuffer,pcWritten);
}
{
if(!gAPI.p6ErrToStr) return NULL;
return gAPI.p6ErrToStr(err,pszBuffer,cBuffer);
}
{
if(!gAPI.p6ErrToWStr) return NULL;
return gAPI.p6ErrToWStr(err,pszBuffer,cBuffer);
}
{
if(!gAPI.p6AtomicInc32) return 0;
return gAPI.p6AtomicInc32(pVar);
}
{
if(!gAPI.p6AtomicDec32) return 0;
return gAPI.p6AtomicDec32(pVar);
}
{
if(!gAPI.p6AtomicAdd32) return 0;
return gAPI.p6AtomicAdd32(pVar,value);
}
{
if(!gAPI.p6AtomicSet32) return 0;
return gAPI.p6AtomicSet32(pVar,value);
}
{
if(!gAPI.p6AtomicSet64) return 0;
return gAPI.p6AtomicSet64(pVar,value);
}
{
if(!gAPI.p6HashData) return 0;
return gAPI.p6HashData(pData,cData,hash);
}
{
if(!gAPI.p6HashString) return 0;
return gAPI.p6HashString(pszString);
}
{
if(!gAPI.p6HashStringW) return 0;
return gAPI.p6HashStringW(pszString);
}
{
if(!gAPI.p6HashBCSTR) return 0;
return gAPI.p6HashBCSTR(pbcsString);
}
{
if(!gAPI.p6HashBWCSTR) return 0;
return gAPI.p6HashBWCSTR(pbwcsString);
}
{
if(!gAPI.p6HashUINT32) return 0;
return gAPI.p6HashUINT32(nInteger);
}
{
if(!gAPI.p6HashUINT64) return 0;
return gAPI.p6HashUINT64(nInteger);
}
{
if(!gAPI.p6HashUINT64to32) return 0;
return gAPI.p6HashUINT64to32(nInteger);
}
{
if(!gAPI.p6TraceAddref) return eNotInitialized;
return gAPI.p6TraceAddref(pszClassname,cClassSize,classAddr,refCount,pSerialNumber);
}
{
if(!gAPI.p6TraceRelease) return eNotInitialized;
return gAPI.p6TraceRelease(pszClassname,classAddr,refCount,pSerialNumber);
}
{
return eOk;
}
{
return eNotImplemented;
}