?? sm2write.c
字號:
{
secureMailObj->version = version;
/* Create the Base64 object. We couldn't create it until we had the
* new line issue settled.
*/
if (secureMailObj->base64 != (VtAlgorithmObject)0)
VtDestroyAlgorithmObject(&secureMailObj->base64);
b64Info.base64BlockSize = VOLT_SECURE_MAIL_BASE_64_LINE_LENGTH;
b64Info.newLineCharacter = VT_BASE64_NEW_LINE_LF;
if (writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE].len == 2)
b64Info.newLineCharacter = VT_BASE64_NEW_LINE_CR_LF;
b64Info.errorCheck = VT_BASE64_NO_ERROR_CHECK;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateAlgorithmObject(libCtx, VtAlgorithmImplBase64,
(Pointer)&b64Info, &(secureMailObj->base64));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtEncodeInit(secureMailObj->base64);
if (status != 0)
break;
useHTMLWrapping = (policyCtx != (VtPolicyCtx)0) &&
(writeCtx->messageFormat == VT_MESSAGE_FORMAT_SECURE_MAIL_HTML_V2);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2FormatMessageTag(libCtx,
VoltZDM2MessageBlockStartTagPrefix,
VoltZDM2MessageBlockStartTagSuffix,
(unsigned char*)0, version,
useHTMLWrapping, &messageStartTag);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2FormatMessageTag(libCtx,
VoltZDM2MessageBlockEndTagPrefix,
VoltZDM2MessageBlockEndTagSuffix,
(unsigned char*)0, version,
useHTMLWrapping, &messageEndTag);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2FormatMessageTag(libCtx,
VoltZDM2SecureBlockStartTagPrefix,
VoltZDM2SecureBlockStartTagSuffix,
(unsigned char*)0, version,
0, &secureBlockStartTag);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2FormatMessageTag(libCtx,
VoltZDM2SecureBlockEndTagPrefix,
VoltZDM2SecureBlockEndTagSuffix,
(unsigned char*)0, version,
0, &secureBlockEndTag);
if (status != 0)
break;
temp.data = secureBlockStartTag;
temp.len = Z2Strlen(secureBlockStartTag);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_BLK]));
if (status != 0)
break;
temp.data = secureBlockEndTag;
temp.len = Z2Strlen(secureBlockEndTag);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_BLK]));
if (status != 0)
break;
if (policyCtx != (VtPolicyCtx)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
i = VOLT_POLICY_GET_SECURE_MAIL_HEADER;
status = policyCtx->PolicyGetInfoAlloc(policyCtx,
VOLT_POLICY_GET_SECURE_MAIL_HEADER,
(Pointer)&i, (Pointer *)&messageHeaderItem);
if (status != 0)
break;
}
if (useHTMLWrapping)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateDataNodeObject(libCtx, "", &templateVariablesNode);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureMail2InitTemplateVariables(secureMailObj,
templateVariablesNode, messageHeader, messageStartTag,
messageEndTag, writeCtx->templateCharset);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = policyCtx->PolicyGetInfoAlloc(policyCtx,
VOLT_POLICY_GET_HTML_MESSAGE_BODY_TEMPLATE,
(Pointer)0, (Pointer *)&templateItem);
if (status != 0)
break;
if (templateItem == (VtItem*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_TEMPLATE;
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2FindMessageDataInTemplate(libCtx,
templateItem->data, templateItem->len, &headerText,
&headerLength, &trailerText, &trailerLength);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureMail2ExpandTemplate(libCtx, headerText,
headerLength, templateVariablesNode,
&writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureMail2ExpandTemplate(libCtx, trailerText,
trailerLength, templateVariablesNode,
&writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_MSG]);
if (status != 0)
break;
}
else
{
temp.data = messageStartTag;
temp.len = Z2Strlen(messageStartTag);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]));
if (status != 0)
break;
temp.data = messageEndTag;
temp.len = Z2Strlen(messageEndTag);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_MSG]));
if (status != 0)
break;
if (messageHeaderItem != (VtItem*)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, messageHeaderItem,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_HEADER]));
if (status != 0)
break;
}
}
newLineLen = writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE].len;
/* Sum up the preliminary and trailing lengths.
*/
for (i = VOLT_WRITE_SM_HEAD_INDEX_START;
i <= VOLT_WRITE_SM_HEAD_INDEX_END; ++i)
{
/* Add in the length of the actual data to write out.
* If there is data to write out, add a newLine.
*/
elementLen = writeCtx->itemArray[i].len;
if (elementLen != 0)
elementLen += newLineLen;
writeCtx->prelimLen += elementLen;
}
for (i = VOLT_WRITE_SM_FOOT_INDEX_START;
i <= VOLT_WRITE_SM_FOOT_INDEX_END; ++i)
{
/* Add in the length of the actual data to write out.
* If there is data to write out, add a newLine.
*/
elementLen = writeCtx->itemArray[i].len;
if (elementLen != 0)
elementLen += newLineLen;
writeCtx->trailLen += elementLen;
}
secureMailObj->state = VOLT_SECURE_MAIL_STATE_WRITE_INIT;
}
while (0);
Z2Free(messageStartTag);
Z2Free(secureBlockStartTag);
Z2Free(secureBlockEndTag);
Z2Free(messageEndTag);
VtDestroyDataNodeObject(&templateVariablesNode);
if (messageHeaderItem != (VtItem *)0)
policyCtx->PolicyGetInfoFree(policyCtx, (Pointer)messageHeaderItem);
if (templateItem != (VtItem*)0)
policyCtx->PolicyGetInfoFree(policyCtx, (Pointer)templateItem);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine, "VoltSecureMail2WriteInitCommon", (unsigned char*)0)
return status;
}
int VoltSecureMail2WriteInit (
VtSecureMailObject secureMailObj,
VtPolicyCtx policyCtx,
VtStorageCtx storageCtx,
VtTransportCtx transportCtx,
VtRandomObject random
)
{
int status;
VoltSecureMailWriteCtx* writeCtx = (VoltSecureMailWriteCtx*)(secureMailObj->localCtx);
VoltLibCtx* libCtx = (VoltLibCtx*)(secureMailObj->voltObject.libraryCtx);
VtDataNodeObject attributesNode = (VtDataNodeObject)0;
VtStreamImplMemoryInfo memInfo;
VtStreamObject attributesStream = (VtStreamObject)0;
unsigned int formatFlags;
VtStreamSize attributesSize, readSize;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
do
{
/* Init the subordinate objects.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7WriteInit(secureMailObj->p7SignedData, policyCtx,
storageCtx, transportCtx, random);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7WriteInit(secureMailObj->p7EnvelopedData, policyCtx,
storageCtx, transportCtx, random);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateDataNodeObject(libCtx, VoltZDM2RootAttributeName,
&attributesNode);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureMail2InitMessageAttributes(secureMailObj,
attributesNode, writeCtx->contentType, writeCtx->characterSet,
writeCtx->originalCharacterSet);
if (status != 0)
break;
Z2Memset(&memInfo, 0, sizeof(memInfo));
memInfo.flags = VT_STREAM_OPEN_ON_ACCESS;
memInfo.openMode = VT_STREAM_OPEN_READ_WRITE;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateStreamObject(libCtx, VtStreamImplMemory,
(Pointer)&memInfo, &attributesStream);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(attributesStream, VoltSecureArchiveHeadersName,
Z2Strlen(VoltSecureArchiveHeadersName));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(attributesStream, ": ", 2);
if (status != 0)
break;
formatFlags = VT_DATA_NODE_XML_FORMAT_INDENT_SPACES |
VT_DATA_NODE_XML_FORMAT_SET_NEW_LINE(VT_DATA_NODE_XML_FORMAT_NEW_LINE_LF) |
VT_DATA_NODE_XML_FORMAT_SET_SPACES_PER_INDENT(1) |
VT_DATA_NODE_XML_FORMAT_NEW_LINE_PER_ELEMENT |
VT_DATA_NODE_XML_FORMAT_INDENT_CHILD_ELEMENTS;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDataNodeWriteXML(attributesNode, formatFlags,
attributesStream);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamGetSize(attributesStream, &attributesSize);
if (status != 0)
break;
/* VtDataNodeWriteXML writes a final end of line, which we don't
* want in the contentInfo element (or else we get a spurious
* EOL at the beginning of the actual message text). So we just
* decrement the size so that we don't read the last EOL.
*/
attributesSize--;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(attributesStream, 0, VT_STREAM_FROM_START);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
secureMailObj->contentInfo.data = (unsigned char*)
Z2Malloc(attributesSize, 0);
if (secureMailObj->contentInfo.data == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_MEMORY;
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(attributesStream, secureMailObj->contentInfo.data,
attributesSize, &readSize);
if (readSize != attributesSize)
status = VT_ERROR_STREAM_READ;
if (status != 0)
break;
secureMailObj->contentInfo.len = (unsigned int) attributesSize;
status = VoltSecureMail2WriteInitCommon(secureMailObj, policyCtx,
VOLT_SECURE_MAIL_2_WRITE_VERSION);
if (status != 0)
break;
}
while (0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -