📄 smparams.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "stringutil.h"
#include "errorctx.h"
int VtSecureMailParamRecipientList (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VoltSecureMailWriteCtx *writeCtx;
VtSecureMailObject targetImpl;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
{
/* The SecureMail object must be set to write.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* Set the enveloper with this list.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList, info);
if (status != 0)
break;
/* We need a reference to the recipient list.
*/
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList,
(Pointer *)&(writeCtx->recipListRef));
}
else if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
{
/* If getting, the SecureMail object must be set to read.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_GENERIC)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetTargetObjectForGenericSecureMailReader(
obj, &targetImpl);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetSecureMailParam(targetImpl,
VtSecureMailParamRecipientList, (Pointer*)info);
}
else
{
/* Get the list out of the enveloper.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList, (Pointer *)info);
}
}
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, secureMailObj, status, 0, errorType,
(char *)0, "VtSecureMailParamRecipientList", fnctLine, (char *)0)
return (status);
}
int VtSecureMailParamRecipientInfoList (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VoltSecureMailWriteCtx *writeCtx;
VtSecureMailObject targetImpl;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
{
/* The SecureMail object must be set to write.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* Set the enveloper with this list.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientInfoList, info);
if (status != 0)
break;
/* We need a reference to the recipient list.
*/
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList,
(Pointer *)&(writeCtx->recipListRef));
}
else if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
{
/* If getting, the SecureMail object must be set to read.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_GENERIC)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetTargetObjectForGenericSecureMailReader(
obj, &targetImpl);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetSecureMailParam(targetImpl,
VtSecureMailParamRecipientInfoList, (Pointer*)info);
}
else
{
/* Get the list out of the enveloper.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientInfoList, (Pointer *)info);
}
}
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, secureMailObj, status, 0, errorType,
(char *)0, "VtSecureMailParamRecipientInfoList", fnctLine, (char *)0)
return (status);
}
int VtSecureMailParamRecipientIndex (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VtSecureMailObject targetImpl;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This Param cannot Get info.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
break;
/* The SecureMail object must be set to read.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_GENERIC)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetTargetObjectForGenericSecureMailReader(
obj, &targetImpl);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetSecureMailParam(targetImpl,
VtSecureMailParamRecipientIndex, info);
}
else
{
/* Set the enveloper with this list.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientIndex, info);
}
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, secureMailObj, status, 0, errorType,
(char *)0, "VtSecureMailParamRecipientIndex", fnctLine, (char *)0)
return (status);
}
int VtSecureMailParamContentType (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int index, valueLen, labelLen, currentLen;
Pointer *getInfo;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltSecureMailWriteCtx* writeCtx;
VoltSecureMail2ReadCtx* readCtx;
VtUtf8StringList *descriptors;
char *label = "content-type: ";
VtSecureMailObject targetImpl;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
labelLen = 14;
do
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
{
/* The SecureMail object must be set to write.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* The info must be a UTF-8 string.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_2)
{
writeCtx = (VoltSecureMailWriteCtx*) secureMailObj->localCtx;
/* Free up existing string */
if (writeCtx->contentType != (unsigned char*)0);
{
Z2Free(writeCtx->contentType);
writeCtx->contentType = (unsigned char*)0;
}
/* Copy to writeCtx
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = Strdup(info, (char**)&writeCtx->contentType, libCtx);
}
else
{
/* If there's already a content-type in the contentInfo, error.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->contentInfo.data != (unsigned char *)0)
break;
/* How long is the input value.
*/
valueLen = Z2Strlen (info);
/* Copy it into the object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->contentInfo.data = (unsigned char *)Z2Malloc (valueLen + 1, 0);
if (obj->contentInfo.data == (unsigned char *)0)
break;
Z2Memcpy (obj->contentInfo.data, info, valueLen + 1);
/* We'll write out everything except the NULL-terminating
* character.
*/
obj->contentInfo.len = valueLen;
}
status = 0;
}
else if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
break;
if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_GENERIC)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetTargetObjectForGenericSecureMailReader(
obj, &targetImpl);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetSecureMailParam(targetImpl,
VtSecureMailParamContentType, (Pointer*)info);
}
else if (obj->formatType == VOLT_MESSAGE_FORMAT_SECURE_MAIL_2)
{
readCtx = (VoltSecureMail2ReadCtx*) secureMailObj->localCtx;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (readCtx->contentType == (unsigned char*)0)
break;
*(Pointer*)info = readCtx->contentType;
}
else
{
/* Get all the content descriptors.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetSecureMailParam (
secureMailObj, VtSecureMailParamContentDescriptors,
(Pointer *)&descriptors);
if (status != 0)
break;
/* Search through the list, find the string that begins
* "content-type:".
*/
for (index = 0; index < descriptors->count; ++index)
{
currentLen = Z2Strlen (descriptors->utf8Strings[index]);
if (currentLen < labelLen)
continue;
if (Z2Memcmp (descriptors->utf8Strings[index], label, labelLen) == 0)
break;
}
/* If we found a match, we broke out of the for loop early. If we
* went through the entire list, there was no match.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (index >= descriptors->count)
break;
getInfo = (Pointer *)info;
*getInfo = (Pointer)(descriptors->utf8Strings[index] + labelLen);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -