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

📄 urlpolicy.c

📁 IBE是一种非对称密码技术
💻 C
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "localpolicy.h"
#include "vsdistrict.h"
#include "errorctx.h"

/* URL based Policy implementation. Policy is fetched from an internet URL.
 */

/* This is For windows Only
*/
#if VOLT_OS == VOLT_WINDOWS_32

int VtPolicyImplXmlURLWinINet (
   VtPolicyCtx *policyCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  VtWinINetHttpTimeInfo policyInfo;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  policyInfo.url = (unsigned char *)info;
  policyInfo.timeout = 10000;

  VOLT_SET_FNCT_LINE (fnctLine)
  status = VtPolicyImplXmlURLWinINetTime (
    policyCtx, (Pointer)&policyInfo, flag);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, *policyCtx, status, 0, 0,
    (char *)0, "VtPolicyImplXmlURLWinINet", fnctLine, (char *)0)

  return (status);
}

int VtPolicyImplXmlURLWinINetTime (
   VtPolicyCtx *policyCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  unsigned int responseCode;
  VoltPolicyCtx *ctx = (VoltPolicyCtx *)(*policyCtx);
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  char *xmlString = (char *)0;  
  VtWinINetHttpTimeInfo *policyInfo = (VtWinINetHttpTimeInfo *)0;
  VoltHttpRequestInfo reqInfo;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_POLICY_CTX_SET_TYPE_FLAG)
      break;

    /* What we download from the URL is simply the XML string that is
     * the argument to VtPolicyImplXmlBuffer. So download that string,
     * then call VtPolicyImplXmlBuffer.
     */

    /* Make sure the info is correct.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    policyInfo = (VtWinINetHttpTimeInfo *)info;
    if (policyInfo->url == (unsigned char *)0)
      break;

    /* Download here.
     */
    reqInfo.requestType = VOLT_REQUEST_TYPE_GET;
    reqInfo.requestData = (Pointer)libCtx;
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mDoHTTP (
      &reqInfo, &xmlString, &responseCode, policyInfo->url,
      0, (char *)0, policyInfo->timeout, (void *)0);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtPolicyImplXmlBuffer (policyCtx, (Pointer)xmlString, flag);

  } while (0);

  if (xmlString != (char *)0)
    Z2Free (xmlString);

  VOLT_LOG_ERROR_INFO (
    0, *policyCtx, status, 0, errorType,
    (char *)0, "VtPolicyImplXmlURLWinINetTime", fnctLine, (char *)0)

  return (status);
}

#else

/* Unix Implementation
*/

int VtPolicyImplXmlURLCurl (
   VtPolicyCtx *policyCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  VtCurlHttpInfo *curlInfo;
  VtCurlHttpTimeInfo newInfo;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
  VOLT_SET_FNCT_LINE (fnctLine)
  status = VT_ERROR_INVALID_ASSOCIATED_INFO;
  if (info != (Pointer)0)
  {
    curlInfo = (VtCurlHttpInfo *)info;
    newInfo.url = curlInfo->url;
    newInfo.trustStore = curlInfo->trustStore;
    newInfo.timeout = 10000;
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtPolicyImplXmlURLCurlTime (policyCtx, (Pointer)&newInfo, flag);
  }

  VOLT_LOG_ERROR_INFO (
    0, *policyCtx, status, 0, errorType,
    (char *)0, "VtPolicyImplXmlURLCurl", fnctLine, (char *)0)

  return (status);
}

int VtPolicyImplXmlURLCurlTime (
   VtPolicyCtx *policyCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  unsigned int responseCode;
  VoltPolicyCtx *ctx = (VoltPolicyCtx *)(*policyCtx);
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VtCurlHttpTimeInfo *curlInfo;
  VoltHttpRequestInfo reqInfo;
  char *xmlString = (char *)0;  
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_POLICY_CTX_SET_TYPE_FLAG)
      break;

    /* What we download from the URL is simply the XML string that is
     * the argument to VtPolicyImplXmlBuffer. So download that string,
     * then call VtPolicyImplXmlBuffer.
     */

    /* Make sure the info is correct.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    curlInfo = (VtCurlHttpTimeInfo *)info;

    /* Download here.
     */
    reqInfo.requestType = VOLT_REQUEST_TYPE_GET;
    reqInfo.requestData = (Pointer)libCtx;
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mDoHTTP (
      &reqInfo, &xmlString, &responseCode,
      curlInfo->url, 0, (char *)(curlInfo->trustStore), 
      curlInfo->timeout, (void *)0);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtPolicyImplXmlBuffer (policyCtx, (Pointer)xmlString, flag);

  } while (0);

  if (xmlString != (char *)0)
    Z2Free (xmlString);

  VOLT_LOG_ERROR_INFO (
    0, *policyCtx, status, 0, errorType,
    (char *)0, "VtPolicyImplXmlURLCurlTime", fnctLine, (char *)0)

  return (status);
}

#endif

⌨️ 快捷键说明

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