⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdmwrite.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 4 页
字号:

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, libCtx, obj, status, 0, errorType,
    (char *)0, "BuildZDMHeaderFooterAlloc", fnctLine, (char *)0)

  return (status);
}

static char *VOLT_CALLING_CONV z5stristr VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx, char *mainStr, char *subStr));

static int FindSort (
   VoltLibCtx *libCtx, char **terms, unsigned int termCount, 
   SearchT *search, int *count, char *templateData
   )
{
  int status, temp;
  unsigned int index, found, sub;
  char *currentAddress;

  status = 0;
  found = 0;

  do
  {
    for (index = 0; index < termCount; ++index)
    {
      search[found].index = -1;
      currentAddress = z5stristr (libCtx, templateData, terms[index]);
      if (currentAddress != (char *)0)
      {
        search[found].index = index;
        search[found].start = currentAddress - templateData;
        search[found].finish =
          (currentAddress - templateData) + Z2Strlen (terms[index]);
        found++;
      }
    }

    *count = found;
    if (found == 0)
      break;

    /* Sort by start. Lowest address first.
     */
    for (index = 0; index < found; ++index)
    {
      for (sub = index + 1; sub < termCount; ++sub)
      {
        if (search[index].start > search[sub].start)
        {
          temp = search[index].index;
          search[index].index = search[sub].index;
          search[sub].index = temp;
        }
      }
    }

    status = 0;

  } while (0);

  return (status);
}

static char *z5stristr (
   VoltLibCtx *libCtx, char *mainStr, char *subStr)
{
  int i, j, subStrLen, mainStrLen;

  if ( (mainStr == (char *)0) || (subStr == (char *)0) )
    return ((char *)0);

  subStrLen = Z2Strlen (subStr);
  mainStrLen = Z2Strlen (mainStr) - subStrLen;

  for (i = 0; i <= mainStrLen; ++i)
  {
    for (j = 0; j < subStrLen; ++j)
    {
      if (Z2Tolower (mainStr[i + j]) != Z2Tolower (subStr[j]))
        break;
    }

    if (j >= subStrLen)
      return (mainStr + i);
  }

  return ((char *)0);
}

#define ZFR_META_MAIL \
"<meta name=\"VoltageZFRVersion\" content=\"1\">\r\n\
<meta name=\"VoltageZFRType\" content=\"VoltageZFRMsg\">\r\n"
#define ZFR_META_LEN           99
#define ZFR_META_TYPE_OFFSET   92
#define ZFR_TYPE_LEN           3
#define ZFR_TYPE_DOC			"Doc"
#define ZFR_TYPE_MSG			"Msg"

static int BuildZDMDataFromMETA (
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   int headerFooter
   )
{
  int status;
  unsigned int offset;
  char *metaValue = ZFR_META_MAIL;
  char *typeDoc = ZFR_TYPE_DOC;
  VtItem *theItem = &(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]);
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  offset = theItem->len;

  do
  {
    /* Place the value.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, headerFooter, metaValue, ZFR_META_LEN);
    if (status != 0)
      break;

    /* If the content is mail, we're done.
     */
    if (obj->formatType == VOLT_MESSAGE_FORMAT_ZDM_MAIL)
      break;

    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ZDM_OBJ;
    if (obj->formatType != VOLT_MESSAGE_FORMAT_ZDM_ATTACHMENT)
      break;

    /* The content is ATTACHMENT, replace the "Msg" with "Doc".
     */
    offset += ZFR_META_TYPE_OFFSET;
    Z2Memcpy (theItem->data + offset, typeDoc, ZFR_TYPE_LEN);

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, libCtx, obj, status, 0, errorType,
    (char *)0, "BuildZDMDataFromMETA", fnctLine, (char *)0)

  return (status);
}

static int BuildZDMDataFromSCRIPT (
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   int headerFooter
   )
{
  /* For the moment, there's nothing to output from SCRIPT.
   * This was Javascript info, but Spam filters are rejecting all
   * email with Javascript, no exceptions, no questions asked.
   */
  return (0);
}

/* location is an array of VtItem's. Each element of location is a
 * VtItem whose data field points to an existing byte arrat that is a
 * ZDR location.
 * locationCount is an array of unsigned int's, each the count of how
 * many identities use the corresponding location.
 */
typedef struct
{
  unsigned int count;
  unsigned int *locationCount;
  VtItem *location;
  VtIdentityObject *recipientSelections;
} VoltZDRLocationList;

/* Get the ZDR address.
 */
static int VOLT_CALLING_CONV GetFormAddressAlloc VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   VoltZDRLocationList *locationList,
   char **address,
   unsigned int *addressLen
));

static int VOLT_CALLING_CONV GetFormRecipientAlloc VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   VoltZDRLocationList *locationList,
   char *address,
   unsigned int addressLen,
   char **formRecips,
   unsigned int *formRecipsLen
));

#define ZFR_FORM_ACTION_1 \
"<form name=\"ZFRmain\" method=\"post\" action=\""
#define ZFR_FORM_ACTION_1_LEN  43
#define ZFR_FORM_ACTION_2 \
"\">\r\n<input type=\"hidden\" name=\"ZFRversion\" value=\"1\">\
\r\n<input type=\"hidden\" name=\"ZFRtype\" value=\"VoltageZFRMsg\">\
\r\n<input type=\"hidden\" name=\"ZFRdata\" value=\""
#define ZFR_FORM_ACTION_2_LEN   158
#define ZFR_FORM_ACTION_OFFSET  108

#define ZFR_FORM_FOOT_1      "\r\n\">\r\n"
#define ZFR_FORM_FOOT_1_LEN  6
#define ZFR_FORM_FOOT_2      "\">\r\n"
#define ZFR_FORM_FOOT_2_LEN  4

#define ZFR_FORM_TABLE_START \
"\r\n  <table border=\"0\" cellpadding=\"0\" cellspacing=\"10\">\
\r\n    <tr>\
\r\n      <td>\
\r\n         <b>Please select your e-mail address:</b> &nbsp;&nbsp;&nbsp;&nbsp;<br>\
\r\n         <select size=\"1\" name=\"ZFRidentity\">\
\r\n           <option value=\"#\" selected>Select one</option>\r\n"
#define ZFR_FORM_TABLE_START_LEN  266
#define ZFR_FORM_TABLE_END \
"         </select>\
\r\n      </td>\
\r\n    </tr>\
\r\n    <tr>\
\r\n      <td>\
\r\n        <input type=\"submit\" value=\"Submit\" name=\"ZFRsubmit\">\
\r\n      </td>\
\r\n    </tr>\
\r\n  </table>\
\r\n\r\n</form>\r\n"
#define ZFR_FORM_TABLE_END_LEN  176

static int BuildZDMDataFromFORM (
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   int headerFooter
   )
{
  int status;
  unsigned int addressLen, formRecipsLen, offset, formFootLen;
  char *formAction1 = ZFR_FORM_ACTION_1;
  char *formAction2 = ZFR_FORM_ACTION_2;
  char *formFoot1 = ZFR_FORM_FOOT_1;
  char *formFoot = ZFR_FORM_FOOT_2;
  char *formTableStart = ZFR_FORM_TABLE_START;
  char *formTableEnd = ZFR_FORM_TABLE_END;
  char *typeDoc = ZFR_TYPE_DOC;
  char *address = (char *)0;
  char *formRecips = (char *)0;
  VoltZDRLocationList locationList;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  Z2Memset (&locationList, 0, sizeof (VoltZDRLocationList));
  formFootLen = ZFR_FORM_FOOT_2_LEN;

  do
  {
    /* First, build the "action" line.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 0, formAction1, ZFR_FORM_ACTION_1_LEN);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = GetFormAddressAlloc (
      libCtx, obj, writeCtx, policyCtx, storageCtx, transportCtx,
      &locationList, &address, &addressLen);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 0, address, addressLen);
    if (status != 0)
      break;

    /* What is the offset where the Msg or Doc will be.
     */
    offset = writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG].len;
    offset += ZFR_FORM_ACTION_OFFSET;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 0, formAction2, ZFR_FORM_ACTION_2_LEN);
    if (status != 0)
      break;

    /* If the content is ATTACHMENT, replace the "Msg" with "Doc".
     */
    if (obj->formatType == VOLT_MESSAGE_FORMAT_ZDM_ATTACHMENT)
      Z2Memcpy (
        writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG].data + offset,
        typeDoc, ZFR_TYPE_LEN);

    /* Now move on to the footer. Finish off the input data value, then
     * build the table. The first element will start with \r\n if
     * there's already something in the buffer. It will not have the
     * leading \r\n if there is nothing in the buffer.
     */
    if (writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_MSG].data !=
      (unsigned char *)0)
    {
      formFoot = formFoot1;
      formFootLen = ZFR_FORM_FOOT_1_LEN;
    }

    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 1, formFoot, formFootLen);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 1, formTableStart, ZFR_FORM_TABLE_START_LEN);
    if (status != 0)
      break;

    /* Write out the selections.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = GetFormRecipientAlloc (
      libCtx, obj, writeCtx, policyCtx, storageCtx, transportCtx,
      &locationList, address, addressLen, &formRecips, &formRecipsLen);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 1, formRecips, formRecipsLen);
    if (status != 0)
      break;

    /* Finish the table.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddZDMHeaderFooterData (
      libCtx, obj, writeCtx, 1, formTableEnd, ZFR_FORM_TABLE_END_LEN);
    if (status != 0)
      break;

  } while (0);

  if (locationList.location != (VtItem *)0)
    Z2Free (locationList.location);
  if (locationList.locationCount != (unsigned int *)0)
    Z2Free (locationList.locationCount);
  if (locationList.recipientSelections != (VtIdentityObject *)0)
    Z2Free (locationList.recipientSelections);

  if (address != (char *)0)
    Z2Free (address);
  if (formRecips != (char *)0)
    Z2Free (formRecips);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, libCtx, obj, status, 0, 0,
    (char *)0, "BuildZDMDataFromFORM", fnctLine, (char *)0)

  return (status);
}

static int AddZDMHeaderFooterData (
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   int headerFooter,
   char *theData,
   unsigned int theDataLen
   )
{
  int status;
  unsigned int totalLen;
  VtItem *theItem = &(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]);
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  if (headerFooter == 0)
    theItem = &(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]);
  else
    theItem = &(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_MSG]);

  do
  {
    /* Append this new data to the end of the chosen VtItem.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    totalLen = theItem->len + theDataLen;
    theItem->data = (unsigned char *)Z2Realloc (
      theItem->data, totalLen);
    if (theItem->data == (unsigned char *)0)
      break;

    Z2Memcpy (theItem->data + theItem->len, theData, theDataLen);
    theItem->len += theDataLen;

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, libCtx, obj, status, 0, VT_ERROR_TYPE_PRIMARY,
    (char *)0, "AddZDMHeaderFooterData", fnctLine, (char *)0)

  return (status);
}

static int VOLT_CALLING_CONV AddToLocationList VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtIdentityObject idToAdd,
   VtItem *location,
   VoltZDRLocationList *locationList
));

static int VOLT_CALLING_CONV GetZDRLocationFromDistrict VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtDistrictObject district,
   VtItem **zdrLocation
));

static int VOLT_CALLING_CONV GetZDRLocationFromIdentity VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtIdentityObject idObj,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   VtItem **zdrLocation
));

/* The caller passes a pointer to an existing VtItem, the function will
 * set the data and len fields, the data will point to allocated memory
 * containing the location. If there is no location, set the data field
 * to NULL.
 */
static int VOLT_CALLING_CONV GetSenderZDRLocationAlloc VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   VtItem *location
));

static int VOLT_CALLING_CONV CopyZDRLocation VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtItem *location,
   char **address,
   unsigned int *addressLen
));

static int GetFormAddressAlloc(
   VoltLibCtx *libCtx,
   VoltSecureMailObject *obj,
   VoltSecureMailWriteCtx *writeCtx,
   VtPolicyCtx policyCtx,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -