?? zdmwrite.c
字號:
VtPolicyCtx policyCtx,
VtStorageCtx storageCtx,
VtTransportCtx transportCtx,
VtItem *location
)
{
int status;
unsigned int theTag, lengthLen, valueLen;
UInt32 lenLo, lenHi;
VtIdentityObject senderId;
VtItem *getLocation;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
location->data = (unsigned char *)0;
location->len = 0;
do
{
/* If there's no sender ID Object, we can't get the location.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
senderId = writeCtx->senderIdRef;
status = VT_ERROR_INVALID_ZDM_INPUT;
if (senderId == (VtIdentityObject)0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = GetZDRLocationFromIdentity (
libCtx, senderId, policyCtx, storageCtx, transportCtx, &getLocation);
if (status != 0)
break;
if (getLocation == (VtItem *)0)
break;
/* The location returned is TLV of some encoding.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeTagAndLen (
libCtx, getLocation->data, getLocation->len, &theTag, &lengthLen,
&lenLo, &lenHi, sizeof (unsigned int));
if (status != 0)
break;
valueLen = (unsigned int)lenLo;
/* Copy the location. We have to copy because we don't know if this
* value is in the newId (which we'll destroy) or not.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
location->data = (unsigned char *)Z2Malloc (valueLen, 0);
if (location->data == (unsigned char *)0)
break;
Z2Memcpy (location->data, getLocation->data + lengthLen + 1, valueLen);
location->len = valueLen;
status = 0;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, obj, status, 0, errorType,
(char *)0, "GetSenderZDRLocationAlloc", fnctLine, (char *)0)
return (status);
}
static int GetZDRLocationFromDistrict (
VoltLibCtx *libCtx,
VtDistrictObject district,
VtItem **zdrLocation
)
{
int status;
unsigned int index;
VtX509ExtensionList *extList;
unsigned char zdrLocationOid[VoltParamExtOldZdrOidBytesLen] =
{ VoltParamExtOldZdrOidBytes };
VOLT_DECLARE_FNCT_LINE (fnctLine)
*zdrLocation = (VtItem *)0;
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetDistrictParam (
district, VtDistrictParamExtensions, (Pointer *)&extList);
if (status == VT_ERROR_GET_INFO_UNAVAILABLE)
{
status = 0;
break;
}
if (status != 0)
break;
/* Run through the list of extensions, is the ZDR location
* extension there?
*/
for (index = 0; index < extList->count; ++index)
{
if (extList->extensions[index].oid.len !=
VoltParamExtOldZdrOidBytesLen)
continue;
if (Z2Memcmp (
extList->extensions[index].oid.data, zdrLocationOid,
VoltParamExtOldZdrOidBytesLen) != 0)
continue;
/* This is the ZDR location extension, return the value.
*/
*zdrLocation = &(extList->extensions[index].value);
break;
}
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, district, status, 0, 0,
(char *)0, "GetZDRLocationFromDistrict", fnctLine, (char *)0)
return (status);
}
static int GetZDRLocationFromIdentity (
VoltLibCtx *libCtx,
VtIdentityObject idObj,
VtPolicyCtx policyCtx,
VtStorageCtx storageCtx,
VtTransportCtx transportCtx,
VtItem **zdrLocation
)
{
int status;
VtDistrictObject getDist;
VOLT_DECLARE_FNCT_LINE (fnctLine)
*zdrLocation = (VtItem *)0;
do
{
/* To get a ZDR location from an identity, get the district from
* that identity, get the district extensions from that district,
* and get the ZDR location extension from the extension list.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetIdentityParam (
idObj, VtIdentityParamDistrict, (Pointer *)&getDist);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtObtainIBEParams (
getDist, policyCtx, storageCtx, transportCtx);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = GetZDRLocationFromDistrict (libCtx, getDist, zdrLocation);
if (status != 0)
break;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, idObj, status, 0, 0,
(char *)0, "GetZDRLocationFromIdentity", fnctLine, (char *)0)
return (status);
}
#define ZFR_FORM_OPTION_PART_1 \
" <option value=\""
#define ZFR_FORM_OPTION_PART_2 \
"?pub="
#define ZFR_FORM_OPTION_PART_3 \
"\">"
#define ZFR_FORM_OPTION_PART_4 \
" (Authenticated By "
#define ZFR_FORM_OPTION_PART_5 \
")"
#define ZFR_FORM_OPTION_PART_6 \
"</option>\r\n"
#define ZFR_FORM_OPTION_PART_1_LEN 26
#define ZFR_FORM_OPTION_PART_2_LEN 5
#define ZFR_FORM_OPTION_PART_3_LEN 2
#define ZFR_FORM_OPTION_PART_4_LEN 19
#define ZFR_FORM_OPTION_PART_5_LEN 1
#define ZFR_FORM_OPTION_PART_6_LEN 11
static int GetFormRecipientAlloc (
VoltLibCtx *libCtx,
VoltSecureMailObject *obj,
VoltSecureMailWriteCtx *writeCtx,
VtPolicyCtx policyCtx,
VtStorageCtx storageCtx,
VtTransportCtx transportCtx,
VoltZDRLocationList *locationList,
char *address,
unsigned int addressLen,
char **formRecips,
unsigned int *formRecipsLen
)
{
int status;
unsigned int index, count, emailLen, domainNameLen;
unsigned int indexB, offset, encodingLen, b64Size, b64Len, urlLen;
VtIdentityObject getId;
VtDistrictObject distObj = (VtDistrictObject)0;
VtAlgorithmObject b64 = (VtAlgorithmObject)0;
unsigned char *encoding = (unsigned char *)0;
unsigned char *b64Data = (unsigned char *)0;
unsigned char *domainName = (unsigned char *)0;
VtEmailInfo *emailInfo;
char *part1 = ZFR_FORM_OPTION_PART_1;
char *part2 = ZFR_FORM_OPTION_PART_2;
char *part3 = ZFR_FORM_OPTION_PART_3;
char *part4 = ZFR_FORM_OPTION_PART_4;
char *part5 = ZFR_FORM_OPTION_PART_5;
char *part6 = ZFR_FORM_OPTION_PART_6;
VtBase64Info b64Info;
VtItem *zdrLocation;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
*formRecips = (char *)0;
*formRecipsLen = 0;
b64Size = 0;
do
{
/* We can't use the base64 object in the writeCtx, we need one that
* will encode without carriage return/line feed.
*/
b64Info.base64BlockSize = 76;
b64Info.newLineCharacter = VT_BASE64_NO_NEW_LINE;
b64Info.errorCheck = VT_BASE64_NO_ERROR_CHECK;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateAlgorithmObject (
(VtLibCtx)libCtx, VtAlgorithmImplBase64, (Pointer)&b64Info, &b64);
if (status != 0)
break;
/* For each recipient, get the encodedID, base64 encode it,
* then URLEncode the B64.
*/
offset = 0;
for (index = 0; index < locationList->count; ++index)
{
/* This must contain an email address. Plus, the option will
* contain the email address.
*/
getId = locationList->recipientSelections[index];
zdrLocation = &(locationList->location[index]);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetIdentityParam (
getId, VtIdentityParam822Email, (Pointer *)&emailInfo);
if (status != 0)
continue;
emailLen = Z2Strlen (emailInfo->emailAddress);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeIdentity (
getId, VT_ENCODE_IBCS_2_V_DISTRICT, policyCtx, storageCtx,
transportCtx, (unsigned char *)0, 0, &encodingLen);
if (status == 0)
status = VT_ERROR_GENERAL;
if (status != VT_ERROR_BUFFER_TOO_SMALL)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
encoding = (unsigned char *)Z2Realloc (encoding, offset + encodingLen);
if (encoding == (unsigned char *)0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeIdentity (
getId, VT_ENCODE_IBCS_2_V_DISTRICT, policyCtx, storageCtx,
transportCtx, encoding + offset, encodingLen, &encodingLen);
if (status != 0)
break;
/* Get the district information for the identity. Currently
* We use domain names. We can use district names in future.
*/
distObj = getId->district;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetDistrictParam (
distObj, VtDistrictParamDomainName, (Pointer *)&domainName);
if (status != 0)
break;
domainNameLen = Z2Strlen (domainName);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeInit (b64);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeFinal (
b64, (VtRandomObject)0, encoding + offset, encodingLen,
(unsigned char *)b64Data, b64Size, &b64Len);
if (status == VT_ERROR_BUFFER_TOO_SMALL)
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
b64Data = (unsigned char *)Z2Realloc (b64Data, b64Len);
if (b64Data == (unsigned char *)0)
break;
b64Size = b64Len;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeFinal (
b64, (VtRandomObject)0, encoding + offset, encodingLen,
(unsigned char *)b64Data, b64Size, &b64Len);
}
if (status != 0)
break;
/* Part 3: URL Encode,
* Replace + with %3D
* / with %2F
* = with %3D
*/
count = 0;
for (indexB = 0; indexB < b64Len; ++indexB)
{
if ( (b64Data[indexB] == '+') || (b64Data[indexB] == '/') ||
(b64Data[indexB] == '=') )
count++;
}
urlLen = b64Len + (2 * count);
/* Add in the lengths of the other elements that make up the
* total option.
*/
urlLen +=
ZFR_FORM_OPTION_PART_1_LEN + ZFR_FORM_OPTION_PART_2_LEN +
ZFR_FORM_OPTION_PART_3_LEN + ZFR_FORM_OPTION_PART_4_LEN +
domainNameLen + ZFR_FORM_OPTION_PART_5_LEN +
ZFR_FORM_OPTION_PART_6_LEN + zdrLocation->len + emailLen;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
encoding = (unsigned char *)Z2Realloc (encoding, offset + urlLen);
if (encoding == (unsigned char *)0)
break;
/* Put in PART_1.
*/
Z2Memcpy (encoding + offset, part1, ZFR_FORM_OPTION_PART_1_LEN);
offset += ZFR_FORM_OPTION_PART_1_LEN;
/* Next is the address (ZDR location).
*/
Z2Memcpy (encoding + offset, zdrLocation->data, zdrLocation->len);
offset += zdrLocation->len;
/* Now PART_2.
*/
Z2Memcpy (encoding + offset, part2, ZFR_FORM_OPTION_PART_2_LEN);
offset += ZFR_FORM_OPTION_PART_2_LEN;
/* Now comes the URL encoded data.
*/
for (indexB = 0; indexB < b64Len; ++indexB)
{
if (b64Data[indexB] == '+')
{
encoding[offset] = (unsigned char)'%';
encoding[offset + 1] = (unsigned char)'2';
encoding[offset + 2] = (unsigned char)'B';
offset += 3;
}
else if (b64Data[indexB] == '/')
{
encoding[offset] = (unsigned char)'%';
encoding[offset + 1] = (unsigned char)'2';
encoding[offset + 2] = (unsigned char)'F';
offset += 3;
}
else if (b64Data[indexB] == '=')
{
encoding[offset] = (unsigned char)'%';
encoding[offset + 1] = (unsigned char)'3';
encoding[offset + 2] = (unsigned char)'D';
offset += 3;
}
else
{
encoding[offset] = (unsigned char)(b64Data[indexB]);
offset++;
}
}
/* PART_3 is next.
*/
Z2Memcpy (encoding + offset, part3, ZFR_FORM_OPTION_PART_3_LEN);
offset += ZFR_FORM_OPTION_PART_3_LEN;
/* The email address goes here.
*/
Z2Memcpy (encoding + offset, emailInfo->emailAddress, emailLen);
offset += emailLen;
/* The district information goes here
*/
Z2Memcpy (encoding + offset, part4, ZFR_FORM_OPTION_PART_4_LEN);
offset += ZFR_FORM_OPTION_PART_4_LEN;
Z2Memcpy (encoding + offset, domainName, domainNameLen);
offset += domainNameLen;
Z2Memcpy (encoding + offset, part5, ZFR_FORM_OPTION_PART_5_LEN);
offset += ZFR_FORM_OPTION_PART_5_LEN;
/* Finally, PART_6.
*/
Z2Memcpy (encoding + offset, part6, ZFR_FORM_OPTION_PART_6_LEN);
offset += ZFR_FORM_OPTION_PART_6_LEN;
status = 0;
}
if (status != 0)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ZDM_INPUT;
if (offset == 0)
break;
*formRecips = encoding;
*formRecipsLen = offset;
status = 0;
} while (0);
VtDestroyAlgorithmObject (&b64);
if (b64Data != (unsigned char *)0)
Z2Free (b64Data);
/* If no error, we're done.
*/
if (status == 0)
return (0);
/* If there was an error, free this memory.
*/
if (encoding != (unsigned char *)0)
Z2Free (encoding);
VOLT_LOG_ERROR_INFO (
libCtx, obj, status, 0, errorType,
(char *)0, "GetFormRecipientAlloc", fnctLine, (char *)0)
return (status);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -