Tool to debug IE/WinINet URL processing

Hi,

  This command line utility prints out how WinINet, which is used by
Internet Explorer, processes URLs, via InternetCombineUrl which com-
bines a base reference with a relative reference, and via Internet-
CrackUrl, which splits URLs into various components. Sample output:

  % crack $:
  Absolute:  $:
  Scheme:    $
  HostName:
  UserName:
  Password:
  UrlPath:
  ExtraInfo:
  
  % crack http://example.org $:
  Absolute:  http://example.org/$:
  Scheme:    http
  HostName:  example.org
  UserName:
  Password:
  UrlPath:   /$:
  ExtraInfo:

Code is follows:

  #undef UNICODE
  #include <Windows.h>
  #include <WinInet.h>
  #include <stdio.h>
  
  #pragma comment(lib, "wininet.lib")
  
  int
  main(int argc, char *argv[]) {
  
    if (argc != 2 && argc != 3) {
      printf("Usage: `%s <URL>`, or `%s <Base> <Relative>`\n",
        argv[0], argv[0]);
      return 1;
    }
  
    DWORD length = 1024;
    char temp[1024];
    char* absolute = argv[1];
  
    if (argc == 3) {
      if (!InternetCombineUrl(argv[1], argv[2], temp, &length, 0))
        return GetLastError();
      absolute = temp;
    }
  
    URL_COMPONENTS parts;
  
    memset(&parts, 0, sizeof(parts));
  
    parts.dwStructSize      = sizeof(parts);
    parts.dwSchemeLength    = 1;
    parts.dwHostNameLength  = 1;
    parts.dwUserNameLength  = 1;
    parts.dwPasswordLength  = 1;
    parts.dwUrlPathLength   = 1;
    parts.dwExtraInfoLength = 1;
  
    if (!InternetCrackUrl(absolute, strlen(absolute), 0, &parts))
      return GetLastError();
  
    printf(""
      "Absolute:  %s\n"
      "Scheme:    %.*s\n"
      "HostName:  %.*s\n"
      "UserName:  %.*s\n"
      "Password:  %.*s\n"
      "UrlPath:   %.*s\n"
      "ExtraInfo: %.*s\n",
      absolute,
      parts.dwSchemeLength,
      parts.lpszScheme,
      parts.dwHostNameLength,
      parts.lpszHostName,
      parts.dwUserNameLength,
      parts.lpszUserName,
      parts.dwPasswordLength,
      parts.lpszPassword,
      parts.dwUrlPathLength,
      parts.lpszUrlPath,
      parts.dwExtraInfoLength,
      parts.lpszExtraInfo
    );
  
    return 0;
  }
  
regards,
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Monday, 1 August 2011 20:06:31 UTC