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

📄 urlpolicy.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "localpolicy.h"
#include "vsdistrict.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;

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

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

  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;

  do
  {
    /* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
     */
    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.
     */
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;
    policyInfo = (VtWinINetHttpTimeInfo *)info;
    if (policyInfo->url == (unsigned char *)0)
      break;

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

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

  } while (0);

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

  return (status);
}

#else

/* Unix Implementation
*/

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

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

  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;  

  do
  {
    /* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
     */
    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.
     */
    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;
    status = mDoHTTP (
      &reqInfo, &xmlString, &responseCode,
      curlInfo->url, 0, (char *)(curlInfo->trustStore), 
      curlInfo->timeout, (void *)0);
    if (status != 0)
      break;

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

  } while (0);

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

  return (status);
}

#endif

⌨️ 快捷键说明

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