📄 zdmparams.c
字号:
VtUtf8StringList *descriptors;
VoltContentMaterial *currentElement;
char *labelType = "content-type: ";
char *labelName = "file-name=";
char *found;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
if ((obj->state & VOLT_SECURE_MAIL_STATE_WRITE) != 0)
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
else
readCtx = (VoltSecureMailReadCtx *)(obj->localCtx);
switch (paramSelector)
{
case VT_ZDM_PARAM_RECIPIENT_LIST:
/* If getting, the SecureMail object must be set to read.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ZDM_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
break;
/* Get the list out of the enveloper.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList, getInfo);
break;
case VT_ZDM_PARAM_FILE_NAME:
/* The ZDM message must be attachment, and there must be a file
* name captured.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->formatType != VOLT_MESSAGE_FORMAT_ZDM_ATTACHMENT)
break;
/* If this is an object to write, the file name is in the
* writeCtx->fileName.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (writeCtx != (VoltSecureMailWriteCtx *)0)
{
if (writeCtx->fileName.data == (unsigned char *)0)
break;
*getInfo = (Pointer)(writeCtx->fileName.data);
status = 0;
break;
}
/* The file name has not yet been found. Find it now.
* Get all the content descriptors.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetZDMParam (
zdmObj, VtZDMParamContentDescriptors, (Pointer *)&descriptors);
if (status != 0)
break;
/* Search through the list, find the string that begins
* "file-name=".
*/
labelLen = 10;
found = (char *)0;
for (index = 0; index < descriptors->count; ++index)
{
found = Strstr (
descriptors->utf8Strings[index], labelName, (VtLibCtx)libCtx);
if (found != (char *)0)
break;
}
/* If we went through the list and did not find file-name, the
* info is unavailable.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (found == (char *)0)
break;
/* Find the semicolon.
*/
labelName = found + labelLen;
labelLen = Z2Strlen (labelName);
found = Strchr (labelName, ';', (VtLibCtx)libCtx);
if (found != (char *)0)
labelLen = (unsigned int)found - (unsigned int)labelName;
/* Store the name in fileName.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
readCtx->fileName.data = (unsigned char *)Z2Realloc (
readCtx->fileName.data, labelLen + 1);
if (readCtx->fileName.data == (unsigned char *)0)
break;
Z2Memcpy (readCtx->fileName.data, labelName, labelLen);
readCtx->fileName.data[labelLen] = 0;
*getInfo = (Pointer)(readCtx->fileName.data);
status = 0;
break;
case VT_ZDM_PARAM_SIGNER_LIST:
/* The object must be done reading a message.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_SECURE_MAIL_STATE_READ_COMPLETE)
break;
/* Get the info out of the P7 object.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7SignedData, VtPkcs7ParamSignerList, getInfo);
break;
case VT_ZDM_PARAM_CONTENT_TYPE:
/* If this is an object to write, the content-type is in the
* contentInfo.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (writeCtx != (VoltSecureMailWriteCtx *)0)
{
if (obj->contentInfo.data == (unsigned char *)0)
break;
*getInfo = (Pointer)(obj->contentInfo.data);
status = 0;
break;
}
/* Get all the content descriptors.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetZDMParam (
zdmObj, VtZDMParamContentDescriptors, (Pointer *)&descriptors);
if (status != 0)
break;
/* Search through the list, find the string that begins
* "content-type:".
*/
labelLen = 14;
found = (char *)0;
for (index = 0; index < descriptors->count; ++index)
{
found = Strstr (
descriptors->utf8Strings[index], labelType, (VtLibCtx)libCtx);
if (found != (char *)0)
break;
}
/* If we went through the list and did not find file-name, the
* info is unavailable.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (found == (char *)0)
break;
/* Find the semicolon.
*/
labelType = found + labelLen;
labelLen = Z2Strlen (labelType);
found = Strchr (labelType, ';', (VtLibCtx)libCtx);
if (found != (char *)0)
labelLen = (unsigned int)found - (unsigned int)labelType;
/* Store the name in contentInfo.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->contentInfo.data = (unsigned char *)Z2Realloc (
obj->contentInfo.data, labelLen + 1);
if (obj->contentInfo.data == (unsigned char *)0)
break;
Z2Memcpy (obj->contentInfo.data, labelType, labelLen);
obj->contentInfo.data[labelLen] = 0;
*getInfo = (Pointer)(obj->contentInfo.data);
status = 0;
break;
case VT_ZDM_PARAM_CONTENT_DESCRIPTORS:
/* Make sure this object is set to read SecureMail and that the
* content descriptors have been read.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ZDM_OBJ;
if (readCtx->contentMaterialState !=
VOLT_CONTENT_MATERIAL_STATE_COMPLETE)
break;
/* If the list is not yet computed, compute it now.
*/
if (readCtx->contentDescriptors.count != readCtx->contentMaterialCount)
{
/* The buffer size is the size of an array, we'll just fill it
* with the pointers to the data already copied.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = readCtx->contentMaterialCount * sizeof (unsigned char *);
readCtx->contentDescriptors.utf8Strings = (unsigned char **)Z2Realloc (
readCtx->contentDescriptors.utf8Strings, bufferSize);
if (readCtx->contentDescriptors.utf8Strings == (unsigned char **)0)
break;
Z2Memset (readCtx->contentDescriptors.utf8Strings, 0, bufferSize);
readCtx->contentDescriptors.count = readCtx->contentMaterialCount;
/* Load up all the addresses.
*/
currentElement = readCtx->contentMaterial;
for (index = 0; index < readCtx->contentMaterialCount; ++index)
{
readCtx->contentDescriptors.utf8Strings[index] =
currentElement->material.data;
currentElement = (VoltContentMaterial *)(currentElement->nextElement);
}
}
*getInfo = (Pointer)&(readCtx->contentDescriptors);
status = 0;
break;
case VT_ZDM_PARAM_MESSAGE_TIME:
/* The object must be done reading a message.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_SECURE_MAIL_STATE_READ_COMPLETE)
break;
/* Get the info out of the P7 object.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7SignedData, VtPkcs7ParamSigningTime, getInfo);
break;
case VT_ZDM_PARAM_SUBJECT_LINE:
default:
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
}
return (status);
}
int VoltZDMParamCommon (
VtZDMObject zdmObj,
Pointer info,
unsigned int flag,
unsigned int paramFlags,
int selector
)
{
int status;
VoltZDMObject *obj = (VoltZDMObject *)zdmObj;
VtLibCtx libCtx = (VtLibCtx)(obj->voltObject.libraryCtx);
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
if (flag == VOLT_ZDM_SET_TYPE_FLAG)
{
/* The caller wants to set, is that allowed?
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if ((paramFlags & VT_ZDM_SET_SUPPORTED) == 0)
break;
/* If the associated info is supposed to be NULL, make sure the
* input is NULL. If it's supposed to be non-NULL, make sure of
* that.
*/
if ((info == (Pointer)0) &&
((paramFlags & VT_ZDM_SET_INFO_REQUIRED) != 0))
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
break;
}
if (obj->SetParam == (VZDMSetParam)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_INVALID_IMPL;
break;
}
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = obj->SetParam (zdmObj, selector, info);
break;
}
/* The flag was not SET, so if it's not GET, error.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_ZDM_GET_TYPE_FLAG)
break;
/* The caller wants to get, is that allowed?
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if ((paramFlags & VT_ZDM_GET_SUPPORTED) == 0)
break;
if (obj->GetParam == (VZDMGetParam)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_IMPL;
break;
}
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = obj->GetParam(zdmObj, selector, (Pointer *)info);
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, libCtx, status, errorType, fnctLine,
"VoltZDMParamCommon", (unsigned char *)0)
return status;
}
int VtZDMParamMessageType (
VtZDMObject zdmObj,
Pointer info,
unsigned int flag
)
{
int status;
VtLibCtx libCtx = (VtLibCtx)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
if (zdmObj != (VtZDMObject)0)
libCtx = zdmObj->voltObject.libraryCtx;
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltZDMParamCommon (
zdmObj, info, flag, VT_ZDM_SET_SUPPORTED | VT_ZDM_SET_INFO_REQUIRED,
VT_ZDM_PARAM_MESSAGE_TYPE);
VOLT_LOG_ERROR_COMPARE (
status, libCtx, status, 0, fnctLine,
"VtZDMParamMessageType", (unsigned char *)0)
return (status);
}
int VtZDMParamSenderId (
VtZDMObject zdmObj,
Pointer info,
unsigned int flag
)
{
int status;
VtLibCtx libCtx = (VtLibCtx)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
do
{
if (zdmObj != (VtZDMObject)0)
libCtx = zdmObj->voltObject.libraryCtx;
if ((flag == VOLT_ZDM_SET_TYPE_FLAG) && (info != (Pointer)0) &&
VOLT_OBJECT_TYPE_NOT_EQUAL(info, VOLT_OBJECT_TYPE_IDENTITY))
{
VOLT_SET_FNCT_LINE(fnctLine)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
VOLT_SET_ERROR_TYPE(errorType, 0)
status = VoltZDMParamCommon (
zdmObj, info, flag, VT_ZDM_SET_SUPPORTED | VT_ZDM_SET_INFO_REQUIRED,
VT_ZDM_PARAM_SENDER_ID);
}
while (0);
VOLT_LOG_ERROR_COMPARE (
status, libCtx, status, errorType,
fnctLine, "VtZDMParamSenderId", (unsigned char *)0)
return (status);
}
int VtZDMParamSenderInfo (
VtZDMObject zdmObj,
Pointer info,
unsigned int flag
)
{
int status;
VtLibCtx libCtx = (VtLibCtx)0;
VtZDMSenderInfo* senderInfo;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
do
{
if (zdmObj != (VtZDMObject)0)
libCtx = zdmObj->voltObject.libraryCtx;
if ((flag == VOLT_ZDM_SET_TYPE_FLAG) && (info != (Pointer)0))
{
senderInfo = (VtZDMSenderInfo*)info;
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
if ((senderInfo->privateKey != (VtKeyObject)0) &&
VOLT_OBJECT_TYPE_NOT_EQUAL(senderInfo->privateKey, VOLT_OBJECT_TYPE_KEY))
break;
VOLT_SET_FNCT_LINE(fnctLine)
if ((senderInfo->senderId != (VtIdentityObject)0) &&
VOLT_OBJECT_TYPE_NOT_EQUAL(senderInfo->senderId, VOLT_OBJECT_TYPE_IDENTITY))
break;
VOLT_SET_FNCT_LINE(fnctLine)
if ((senderInfo->signerCert != (VtCertObject)0) &&
VOLT_OBJECT_TYPE_NOT_EQUAL(senderInfo->signerCert, VOLT_OBJECT_TYPE_CERT))
break;
}
VOLT_SET_ERROR_TYPE(errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltZDMParamCommon (
zdmObj, info, flag, VT_ZDM_SET_SUPPORTED | VT_ZDM_SET_INFO_REQUIRED,
VT_ZDM_PARAM_SENDER_INFO);
}
while (0);
VOLT_LOG_ERROR_COMPARE (
status, libCtx, status, errorType, fnctLine,
"VtZDMParamSenderInfo", (unsigned char *)0)
return (status);
}
int VtZDMParamRecipientList (
VtZDMObject zdmObj,
Pointer info,
unsigned int flag
)
{
int status;
VtLibCtx libCtx = (VtLibCtx)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
do
{
if (zdmObj != (VtZDMObject)0)
libCtx = zdmObj->voltObject.libraryCtx;
if ((flag == VOLT_ZDM_SET_TYPE_FLAG) && (info != (Pointer)0) &&
VOLT_OBJECT_TYPE_NOT_EQUAL(info, VOLT_OBJECT_TYPE_IDENTITY_LIST))
{
VOLT_SET_FNCT_LINE(fnctLine)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
break;
}
VOLT_SET_ERROR_TYPE(errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltZDMParamCommon (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -