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

📄 urlutil.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 "vsdistrict.h"
#include "voltfile.h"
#include "deftrans.h"
#include "errorctx.h"

int mIcRegisterWithBrowser (
   VoltLibCtx *libCtx
   )
{
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, VT_ERROR_UNIMPLEMENTED, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "mIcRegisterWithBrowser", (char *)0)

  return (VT_ERROR_UNIMPLEMENTED);
}

#if VOLT_OS == VOLT_WINDOWS_32

#include <tchar.h>
#include <windows.h>
#include <wininet.h>
#include <process.h>

static BOOL GotoURLReg (LPCTSTR lpszUrl, int nShowCmd);
static LONG GetRegKey (HKEY hKeyBase, LPCTSTR lpSubKey, LPTSTR lpszRetData);


int mDoActivateURL (
   VoltLibCtx *libCtx,
   unsigned char *url
   )
{
  BOOL bRet;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  bRet = GotoURLReg ((LPCTSTR)url, SW_SHOWNORMAL);
  if (bRet == TRUE)
    return (0);

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, VT_ERROR_NETWORK_CONNECT, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "mDoActivateURL", (char *)0)

  return (VT_ERROR_NETWORK_CONNECT);
}

static BOOL GotoURLReg (
   LPCTSTR lpszUrl,
   int nShowCmd
   )
{
  BOOL bRetVal = FALSE;

  TCHAR pszKey[VOLT_MAX_PATH + VOLT_MAX_PATH];
  PROCESS_INFORMATION ProcessInformation;
  
#if VOLT_COMPILER != VOLT_MS_EVC_4_0
  STARTUPINFO StartupInfo =
  {
    sizeof(STARTUPINFO),
    NULL,
    NULL,
    NULL,
    0, 0,
    0, 0,
    0, 0,
    0,
    STARTF_USESHOWWINDOW,
    nShowCmd,
    0,
    NULL,
    NULL,
    NULL,
    NULL
  };
#else
  //ignore value
  STARTUPINFO StartupInfo =
  {
    sizeof(STARTUPINFO),
    NULL,
    NULL,
    NULL,
    0, 0,
    0, 0,
    0, 0,
    0,
    0,
    0,
    0,
    NULL,
    NULL,
    NULL,
    NULL
  };
#endif

  /* get the .htm regkey and lookup the program
   */
  if (GetRegKey (HKEY_CLASSES_ROOT, _T(".htm"), pszKey) == ERROR_SUCCESS)
  {
    lstrcat (pszKey, _T("\\shell\\open\\command"));

    if (GetRegKey (HKEY_CLASSES_ROOT, pszKey, pszKey) == ERROR_SUCCESS)
    {
      LPTSTR lpchPos = _tcsstr(pszKey, _T("\"%1\""));

      // if no quotes
      if (lpchPos == NULL)
      {
        // now check for %1, without the quotes
        lpchPos = _tcsstr (pszKey, _T("%1"));

        if (lpchPos == NULL)
          // if no parameter
          lpchPos = pszKey + lstrlen (pszKey) - 1;
        else
          // remove the parameter
          *lpchPos = _T('\0');
      }
      else
      {
        // remove the parameter
        *lpchPos = _T('\0');
      }

      lstrcat (lpchPos, _T(" "));
      lstrcat (lpchPos, lpszUrl);

      bRetVal = CreateProcess (
        NULL,
        pszKey,
        NULL,
        NULL,
        FALSE,
        0,
        NULL,
        NULL,
        &StartupInfo,
        &ProcessInformation);
      if (bRetVal)
      {
        CloseHandle(ProcessInformation.hProcess);
        CloseHandle(ProcessInformation.hThread);
      }
    }
  }

  return bRetVal;
}

static LONG GetRegKey (
   HKEY hKeyBase,
   LPCTSTR lpSubKey,
   LPTSTR lpszRetData
   )
{
  HKEY hKey;
  LONG lRetVal;

  lRetVal = RegOpenKeyEx (hKeyBase, lpSubKey, 0, KEY_QUERY_VALUE, &hKey);

  if (lRetVal == ERROR_SUCCESS)
  {
    TCHAR pszData[VOLT_MAX_PATH];
    DWORD dwDataSize = sizeof(pszData);

    lRetVal = RegQueryValueEx (
      hKey, NULL, NULL, NULL, (LPBYTE)pszData, &dwDataSize);
    if (lRetVal == ERROR_SUCCESS)
      lstrcpy (lpszRetData, pszData);

    RegCloseKey (hKey);
  }

  return lRetVal;
}

#else

int mDoActivateURL (
   VoltLibCtx *libCtx,
   unsigned char *url
   )
{
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, VT_ERROR_UNIMPLEMENTED, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "mDoActivateURL", (char *)0)

  return (VT_ERROR_UNIMPLEMENTED);
}

#endif /* VOLT_OS == VOLT_WINDOWS_32 */

⌨️ 快捷键说明

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