File: aspfool.cpp

package info (click to toggle)
viewcvs 0.9.2%2Bcvs.1.0.dev.2004.07.28-4.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 1,452 kB
  • ctags: 1,355
  • sloc: python: 10,099; cpp: 840; ansic: 763; yacc: 526; sh: 163; makefile: 115
file content (59 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <httpfilt.h>
#include <tchar.h>

// Returns 0 if doesn't exist, 1 if it is a file, 2 if it is a directory
int inline file_exists(TCHAR const * filename)
{
  WIN32_FIND_DATA fd;
  HANDLE fh = FindFirstFile(filename, &fd);
  if (fh == INVALID_HANDLE_VALUE)
    return 0;
  else
  {
    FindClose(fh);
    return fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? 2 : 1;
  }
}

BOOL WINAPI GetFilterVersion(HTTP_FILTER_VERSION * pVer)
{
  pVer->dwFilterVersion = HTTP_FILTER_REVISION;
  pVer->dwFlags = SF_NOTIFY_URL_MAP | SF_NOTIFY_ORDER_DEFAULT;
  return TRUE;
}

DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pn)
{
  switch(notificationType)
  {
    case SF_NOTIFY_URL_MAP:
      HTTP_FILTER_URL_MAP & um = *((HTTP_FILTER_URL_MAP *)pn);

      if (!file_exists(um.pszPhysicalPath))
      {
        size_t pathlen = _tcslen(um.pszPhysicalPath);
        size_t m = pathlen - _tcslen(um.pszURL);
        
        for(size_t i = pathlen - 1; i > m; --i)
        {
          TCHAR c = um.pszPhysicalPath[i];
          if (c == '\\')
          {
            um.pszPhysicalPath[i] = 0;
            int r = file_exists(um.pszPhysicalPath);
            if (r == 1)
              break;
            else
            {
              um.pszPhysicalPath[i] = c;
              if (r == 2) break;
            }
          }
        }
      }  
  }
  return SF_STATUS_REQ_NEXT_NOTIFICATION;
}