📄 clientstore.c
字号:
int VoltClientStoreDistrictParameters (
VtStorageCtx storageCtx,
VtTime *storeTime,
VtDistrictObject entry
)
{
HKEY paramKey = (HKEY)0;
HKEY updateKey = (HKEY)0;
int status, ret;
unsigned int paramsTextLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDistrictObject *distObj = (VoltDistrictObject *)entry;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (unsigned char *)0;
unsigned char *password = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
VtTime *theTime;
VtTime currentTime;
VoltTime vTime;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
theTime = storeTime;
ret = ERROR_SUCCESS;
do
{
if (theTime == (VtTime *)0 )
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetTime ((VtLibCtx)libCtx, ¤tTime);
if (status != 0)
break;
theTime = ¤tTime;
}
/* We need the district data as the standard params text.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_STORED;
if (distObj->paramsText == (unsigned char *)0)
break;
paramsTextLen = Z2Strlen (distObj->paramsText);
/* Make sure the district object contains a qualified name.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_REF;
if (distObj->qualDistrictName.data == (unsigned char *)0)
break;
/* Get the time as seconds to store in the registry
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertTimeToSeconds (libCtx, theTime, &vTime);
if (status != 0)
break;
/* Open the registry keys to store params and param updates time
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_OPEN_REGISTRY_KEY;
ret = RegCreateKeyEx (
HKEY_CURRENT_USER, "Software\\Voltage\\VSCOM\\paramUpdates", 0,
NULL, 0, KEY_WRITE, NULL, &updateKey, NULL);
if (ret != ERROR_SUCCESS)
break;
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegCreateKeyEx (
HKEY_CURRENT_USER, "Software\\Voltage\\VSCOM\\parameters", 0,
NULL, 0, KEY_WRITE, NULL, ¶mKey, NULL);
if (ret != ERROR_SUCCESS)
break;
/* Store the values in the registry
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_WRITE_REGISTRY_VALUE ;
ret = RegSetValueEx(
updateKey, distObj->qualDistrictName.data, 0,
REG_BINARY, (unsigned char *)&vTime, sizeof(vTime) );
if (ret != ERROR_SUCCESS)
break;
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegSetValueEx(
paramKey, distObj->qualDistrictName.data, 0,
REG_SZ, distObj->paramsText, paramsTextLen + 1);
if (ret != ERROR_SUCCESS)
break;
status = 0;
} while (0);
/* close the registry keys
*/
if (paramKey != (HKEY)0)
RegCloseKey(paramKey);
if (updateKey != (HKEY)0)
RegCloseKey(updateKey);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, ret, errorType,
(char *)0, "VoltClientStoreDistrictParameters", fnctLine, (char *)0)
return (status);
}
int VoltClientStoreCurrentDistrict (
VtStorageCtx storageCtx,
unsigned char *domainName,
unsigned char *currentDistrict,
VtTime *storeTime,
VtTime *validityStart,
VtTime *validityEnd
)
{
HKEY cdKey = (HKEY)0;
HKEY updateKey = (HKEY)0;
char district[256];
int status, ret, districtLen;
unsigned int distNameLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)(defStorageCtx->fCtx);
VoltFileHandle fileHandle = (VoltFileHandle)0;
unsigned char *distName;
unsigned char *fileName = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
VtTime currentTime;
VtTime *theTime;
VoltTime vTime;
time_t nullTime = 0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
theTime = storeTime;
ret = ERROR_SUCCESS;
if (domainName == (unsigned char *)0)
return 0;
do
{
if (theTime == (VtTime *)0 )
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetTime ((VtLibCtx)libCtx, ¤tTime);
if (status != 0)
break;
theTime = ¤tTime;
}
/* Get the time as seconds to store in the registry
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertTimeToSeconds (libCtx, theTime, &vTime);
if (status != 0)
break;
/* Open the registry keys for distric and district updates
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_OPEN_REGISTRY_KEY;
ret = RegCreateKeyEx (
HKEY_CURRENT_USER, "Software\\Voltage\\VSCOM\\cdUpdates", 0,
NULL, 0, KEY_WRITE, NULL, &updateKey, NULL);
if (ret != ERROR_SUCCESS)
break;
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegCreateKeyEx (
HKEY_CURRENT_USER, "Software\\Voltage\\VSCOM\\currentDistricts", 0,
NULL, 0, KEY_WRITE, NULL, &cdKey, NULL);
if (ret != ERROR_SUCCESS)
break;
/* If currentDistrict is NULL it means we are storing NULL for district.
* The information that the district doesn't exist.
*/
if (currentDistrict == (unsigned char *)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_WRITE_REGISTRY_VALUE ;
ret = RegSetValueEx(
cdKey, domainName, 0, REG_BINARY, (unsigned char *)&nullTime, sizeof (nullTime));
if (ret != ERROR_SUCCESS)
break;
goto updateKey;
}
/* Now we have a valid district. See if a current district
* newer than the district being stored already exists.
*/
distName = currentDistrict;
distNameLen = Z2Strlen (distName);
districtLen = 256;
/* Make sure we have the valid dates for validityStart and validityEnd
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_ENTRY;
if ( (validityStart->month == 0) || (validityEnd->month == 0) )
break;
ret = RegQueryValueEx (
cdKey, domainName, NULL, NULL, (unsigned char *)district, &districtLen);
if (ret == ERROR_SUCCESS)
{
if (Z2Memcmp (district, distName, distNameLen) > 0)
{
/* we already have a newer district. don't do anything.
*/
status = 0;
break;
}
}
/* We either don't have a current district for this domain or we have
* an older district. So we need to write the new district.
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_WRITE_REGISTRY_VALUE ;
ret = RegSetValueEx(
cdKey, domainName, 0, REG_SZ, distName, distNameLen + 1);
if (ret != ERROR_SUCCESS)
break;
/* Now write the update key
*/
updateKey :
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_WRITE_REGISTRY_VALUE ;
ret = RegSetValueEx(
updateKey, domainName, 0, REG_BINARY, (unsigned char *)&vTime, sizeof(vTime) );
if (ret != ERROR_SUCCESS)
break;
status = 0;
} while (0);
if (cdKey != (HKEY)0)
RegCloseKey(cdKey);
if (updateKey != (HKEY)0)
RegCloseKey(updateKey);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, ret, errorType,
(char *)0, "VoltClientStoreCurrentDistrict", fnctLine, (char *)0)
return (status);
}
int VoltClientStorePublicSigningCert (
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtItem *cert
)
{
int status;
unsigned int fileNameLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (unsigned char *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
do
{
/* We need the identity encoded.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_REF;
if (idObj->encoding.data == (unsigned char *)0)
break;
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, idObj->encoding.data, idObj->encoding.len,
VOLT_FILE_NAME_VALUE_TYPE_CERT_CLIENT, &fileName, &fileNameLen);
if (status != 0)
break;
/* Make sure the directories exist.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxCreateDirectories (fileCtx, fileName);
if (status != 0)
break;
/* Open this file to write. If it exists, destory the contents.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, fileName,
VOLT_FILE_MODE_READ_OVERWRITE, 0600);
if (status != 0)
break;
/* Signing certs are stored unencrypted by client.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxWriteFile (
fileCtx, fileHandle, cert->data, cert->len);
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile (fileCtx, &fileHandle);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, 0, errorType,
(char *)0, "VoltClientStorePublicSigningCert", fnctLine, (char *)0)
return (status);
}
int VoltClientStoreAuthToken (
VtStorageCtx storageCtx,
VtDistrictObject reference,
unsigned char *authToken
)
{
int status;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltStoreAuthTokenForDistrict (
storageCtx, reference, authToken,
VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN_CLIENT);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, 0, 0,
(char *)0, "VoltClientStoreAuthToken", fnctLine, (char *)0)
return (status);
}
int VoltClientGetDistrictParameterCount (
VtStorageCtx storageCtx,
VtDistrictObject reference,
unsigned int *count
)
{
HKEY paramKey = (HKEY)0;
DWORD valueCount, paramLen;
int status, ret;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VtDistrictObject tempObject = (VtDistrictObject)0;
VoltDistrictObject *obj = (VoltDistrictObject *)reference;
VtFileNameList *nameList = (VtFileNameList *)0;
unsigned char *qualName, *unqualName;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
qualName = (unsigned char *)0;
unqualName = (unsigned char *)0;
ret = ERROR_SUCCESS;
do
{
if (reference != (VtDistrictObject)0)
{
qualName = obj->qualDistrictName.data;
unqualName = obj->unqualDistrictName.data;
}
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_OPEN_REGISTRY_KEY;
ret = RegOpenKey(
HKEY_CURRENT_USER,
_T("Software\\Voltage\\VSCOM\\parameters"), ¶mKey);
/* If the registry key doesn't exist it doesn't mean an error.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -