All pastes #958446 Raw Edit

Stuff

public text v1 · immutable
#958446 ·published 2008-03-26 18:59 UTC
rendered paste body
this isapi filter will output anything that is getting requested like http://localhost/helloWorld will answer with hello world, it registers the  SF_NOTIFY_URL_MAP event and therefore it works, but i also need to read cookies, and to do that i need to register SF_NOTIFY_PREPROC_HEADERS , and when i do that i cannot read the url...........
  
 
library DomainMapper;
 
uses
  Windows,
  SysUtils,
  Classes,
  HTTPApp,
  ISAPI2,
  ComObj;
 
//kmemtable husk
 

  const
  SF_MAX_FILTER_DESC_LEN = (256 + 1);
 
  SF_NOTIFY_SECURE_PORT = $00000001;
  SF_NOTIFY_NONSECURE_PORT = $00000002;
  SF_NOTIFY_READ_RAW_DATA = $00008000;
  SF_NOTIFY_PREPROC_HEADERS = $00004000;
  SF_NOTIFY_AUTHENTICATION = $00002000;
  SF_NOTIFY_URL_MAP = $00001000;
  SF_NOTIFY_ACCESS_DENIED = $00000800;
  SF_NOTIFY_SEND_RAW_DATA = $00000400;
  SF_NOTIFY_LOG     = $00000200;
  SF_NOTIFY_END_OF_NET_SESSION = $00000100;
 
  SF_NOTIFY_ORDER_HIGH    = $00080000;
  SF_NOTIFY_ORDER_MEDIUM  = $00040000;
  SF_NOTIFY_ORDER_LOW     = $00020000;
  SF_NOTIFY_ORDER_DEFAULT = SF_NOTIFY_ORDER_LOW;
  SF_NOTIFY_ORDER_MASK    = SF_NOTIFY_ORDER_HIGH or SF_NOTIFY_ORDER_MEDIUM or
    SF_NOTIFY_ORDER_LOW;
 
  SF_STATUS_REQ_FINISHED  = $8000000;
  SF_STATUS_REQ_FINISHED_KEEP_CONN = $8000001;
  SF_STATUS_REQ_NEXT_NOTIFICATION = $8000002;
  SF_STATUS_REQ_HANDLED_NOTIFICATION = $8000003;
  SF_STATUS_REQ_ERROR     = $8000004;
  SF_STATUS_REQ_READ_NEXT = $8000005;
 
type
  PHTTP_FILTER_VERSION = ^HTTP_FILTER_VERSION;
 
  HTTP_FILTER_VERSION = record
    dwServerFilterVersion: DWORD;
    dwFilterVersion: DWORD;
    lpszFilterDesc: array[0..SF_MAX_FILTER_DESC_LEN - 1] of char;
    dwFlags: DWORD;
  end;
 
  THTTP_FILTER_VERSION  = HTTP_FILTER_VERSION;
  LPHTTP_FILTER_VERSION = PHTTP_FILTER_VERSION;
 
  LPVOID = POINTER;
 
  TFilterGetServerVariableProc = function(var pfc; VariableName: PChar; Buffer: Pointer;
    var Size: DWORD): BOOL; stdcall;
  TFilterAddResponseHeadersProc = function(var pfc; lpszHeaders: PChar;
    dwReserved: DWORD): BOOL; stdcall;
  TFilterWriteClientProc = function(var pfc; Buffer: Pointer;
    var Bytes: DWORD; dwReserved: DWORD): BOOL; stdcall;
  TFilterAllocMemProc = function(var pfc; cbSize: DWORD;
    dwReserved: DWORD): Pointer; stdcall;
  TFilterServerSupportFunctionProc = function(var pfc; sfReq: DWORD;
    pData: Pointer; ul1, ul2: DWORD): BOOL; stdcall;
 
  PHTTP_FILTER_CONTEXT = ^THTTP_FILTER_CONTEXT;
 
  THTTP_FILTER_CONTEXT = record
    cbSize:      DWORD;
    Revision:    DWORD;
    ServerContext: Pointer;
    ulReserved:  DWORD;
    fIsSecurePort: BOOL;
    pFilterContext: Pointer;
    GetServerVariable: TFilterGetServerVariableProc;
    AddResponseHeaders: TFilterAddResponseHeadersProc;
    WriteClient: TFilterWriteClientProc;
    AllocMem:    TFilterAllocMemProc;
    ServerSupportFunction: TFilterServerSupportFunctionProc;
  end;
  HTTP_FILTER_CONTEXT = THTTP_FILTER_CONTEXT;
 
  PCardinal = ^cardinal;
  TGetServerVariable = function(var pfc: THTTP_FILTER_CONTEXT;
    VariableName: PChar; Buffer: LPVOID;
    BuffSize: PCardinal): BOOL; stdcall;
 
  TGetHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT; lpszName: PChar;
    var lpvBuffer; var lpdwSize: DWORD): BOOL  ;
  TSetHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT;
    lpszName, lpszValue: PChar): BOOL   ;
  TAddHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT;
    lpszName, lpszValue: PChar): BOOL  ;
 
  PHTTP_FILTER_PREPROC_HEADERS = ^THTTP_FILTER_PREPROC_HEADERS;
 
  THTTP_FILTER_PREPROC_HEADERS = record
    GetHeader:  TGetHeaderProc;
    SetHeader:  TSetHeaderProc;
    AddHeader:  TAddHeaderProc;
    dwReserved: DWORD;
  end;
 

  function HttpFilterProc(var FilterContext: HTTP_FILTER_CONTEXT; NotificationType: DWORD; pvNotification: LPVOID): DWORD; stdcall; export;
  var
    CookieBuffer: array[0..4096] of char;
    URLBuffer: string;
    URLBufferSize: cardinal;
    slashPosInUrl: integer;
    topRootFolder: string;
    requestedURL: string;
    Data:      THTTP_FILTER_PREPROC_HEADERS;
    redirectResponseHtml: string;
    cookieSize: cardinal;
    ssoCookie: string;
 
  begin
       if (NotificationType = SF_NOTIFY_URL_MAP )  then
       begin
       Data := THTTP_FILTER_PREPROC_HEADERS(pvNotification^);
 
      cookieSize := SizeOf(CookieBuffer);
      FillChar(CookieBuffer, cookieSize, 0);
      TGetServerVariable(FilterContext.GetServerVariable)  (FilterContext, 'URL', @CookieBuffer[0], @cookieSize);
      FilterContext.WriteClient(FilterContext, @CookieBuffer[0]   ,cookieSize, 0);
          Result := SF_STATUS_REQ_FINISHED;
 
  end;
  end;
 
 
 
  function TerminateFilter(Flags: DWORD): DWORD; stdcall; export;
  begin
    Result := 1;
  end;
 

  function GetFilterVersion(var pVer: HTTP_FILTER_VERSION): BOOL; stdcall; export;
  begin
    with pVer do
    begin
      dwFilterVersion := MakeLong(0 {minor}, 1 {major});
      StrPCopy(lpszFilterDesc, '');
      dwFlags := SF_NOTIFY_ORDER_DEFAULT or  SF_NOTIFY_URL_MAP;
    end;
    Result := True;
  end;
 
exports
  GetFilterVersion,
  HttpFilterProc,
  TerminateFilter;
begin
end.








------------------------------------------------------------------------------------
----------------------------------CUT NEXT ISAPI FILTER-----------------------------

Here i register SF_NOTIFY_PREPROC_HEADERS and therefore i cannot read the url, it just comes out blank :(
 
I need to register  SF_NOTIFY_PREPROC_HEADERS  because when i do that i can read the cookies in the request
since i need to check if the url bust me protected i need the url, and then i need the cookie to test if the user is allowed access,
but i really cant find a way to get both............any suggestions?
 
 
library DomainMapper;
 
uses
  Windows,
  SysUtils,
  Classes,
  HTTPApp,
  ISAPI2,
  ComObj;
 
//kmemtable husk
 

  const
  SF_MAX_FILTER_DESC_LEN = (256 + 1);
 
  SF_NOTIFY_SECURE_PORT = $00000001;
  SF_NOTIFY_NONSECURE_PORT = $00000002;
  SF_NOTIFY_READ_RAW_DATA = $00008000;
  SF_NOTIFY_PREPROC_HEADERS = $00004000;
  SF_NOTIFY_AUTHENTICATION = $00002000;
  SF_NOTIFY_URL_MAP = $00001000;
  SF_NOTIFY_ACCESS_DENIED = $00000800;
  SF_NOTIFY_SEND_RAW_DATA = $00000400;
  SF_NOTIFY_LOG     = $00000200;
  SF_NOTIFY_END_OF_NET_SESSION = $00000100;
 
  SF_NOTIFY_ORDER_HIGH    = $00080000;
  SF_NOTIFY_ORDER_MEDIUM  = $00040000;
  SF_NOTIFY_ORDER_LOW     = $00020000;
  SF_NOTIFY_ORDER_DEFAULT = SF_NOTIFY_ORDER_LOW;
  SF_NOTIFY_ORDER_MASK    = SF_NOTIFY_ORDER_HIGH or SF_NOTIFY_ORDER_MEDIUM or
    SF_NOTIFY_ORDER_LOW;
 
  SF_STATUS_REQ_FINISHED  = $8000000;
  SF_STATUS_REQ_FINISHED_KEEP_CONN = $8000001;
  SF_STATUS_REQ_NEXT_NOTIFICATION = $8000002;
  SF_STATUS_REQ_HANDLED_NOTIFICATION = $8000003;
  SF_STATUS_REQ_ERROR     = $8000004;
  SF_STATUS_REQ_READ_NEXT = $8000005;
 
type
  PHTTP_FILTER_VERSION = ^HTTP_FILTER_VERSION;
 
  HTTP_FILTER_VERSION = record
    dwServerFilterVersion: DWORD;
    dwFilterVersion: DWORD;
    lpszFilterDesc: array[0..SF_MAX_FILTER_DESC_LEN - 1] of char;
    dwFlags: DWORD;
  end;
 
  THTTP_FILTER_VERSION  = HTTP_FILTER_VERSION;
  LPHTTP_FILTER_VERSION = PHTTP_FILTER_VERSION;
 
  LPVOID = POINTER;
 
  TFilterGetServerVariableProc = function(var pfc; VariableName: PChar; Buffer: Pointer;
    var Size: DWORD): BOOL; stdcall;
  TFilterAddResponseHeadersProc = function(var pfc; lpszHeaders: PChar;
    dwReserved: DWORD): BOOL; stdcall;
  TFilterWriteClientProc = function(var pfc; Buffer: Pointer;
    var Bytes: DWORD; dwReserved: DWORD): BOOL; stdcall;
  TFilterAllocMemProc = function(var pfc; cbSize: DWORD;
    dwReserved: DWORD): Pointer; stdcall;
  TFilterServerSupportFunctionProc = function(var pfc; sfReq: DWORD;
    pData: Pointer; ul1, ul2: DWORD): BOOL; stdcall;
 
  PHTTP_FILTER_CONTEXT = ^THTTP_FILTER_CONTEXT;
 
  THTTP_FILTER_CONTEXT = record
    cbSize:      DWORD;
    Revision:    DWORD;
    ServerContext: Pointer;
    ulReserved:  DWORD;
    fIsSecurePort: BOOL;
    pFilterContext: Pointer;
    GetServerVariable: TFilterGetServerVariableProc;
    AddResponseHeaders: TFilterAddResponseHeadersProc;
    WriteClient: TFilterWriteClientProc;
    AllocMem:    TFilterAllocMemProc;
    ServerSupportFunction: TFilterServerSupportFunctionProc;
  end;
  HTTP_FILTER_CONTEXT = THTTP_FILTER_CONTEXT;
 
  PCardinal = ^cardinal;
  TGetServerVariable = function(var pfc: THTTP_FILTER_CONTEXT;
    VariableName: PChar; Buffer: LPVOID;
    BuffSize: PCardinal): BOOL; stdcall;
 
  TGetHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT; lpszName: PChar;
    var lpvBuffer; var lpdwSize: DWORD): BOOL  ;
  TSetHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT;
    lpszName, lpszValue: PChar): BOOL   ;
  TAddHeaderProc = function(var pfc: THTTP_FILTER_CONTEXT;
    lpszName, lpszValue: PChar): BOOL  ;
 
  PHTTP_FILTER_PREPROC_HEADERS = ^THTTP_FILTER_PREPROC_HEADERS;
 
  THTTP_FILTER_PREPROC_HEADERS = record
    GetHeader:  TGetHeaderProc;
    SetHeader:  TSetHeaderProc;
    AddHeader:  TAddHeaderProc;
    dwReserved: DWORD;
  end;
 

  function HttpFilterProc(var FilterContext: HTTP_FILTER_CONTEXT; NotificationType: DWORD; pvNotification: LPVOID): DWORD; stdcall; export;
  var
    CookieBuffer: array[0..4096] of char;
    URLBuffer: string;
    URLBufferSize: cardinal;
    slashPosInUrl: integer;
    topRootFolder: string;
    requestedURL: string;
    Data:      THTTP_FILTER_PREPROC_HEADERS;
    redirectResponseHtml: string;
    cookieSize: cardinal;
    ssoCookie: string;
 
  begin
       if (NotificationType = SF_NOTIFY_PREPROC_HEADERS )  then
       begin
       Data := THTTP_FILTER_PREPROC_HEADERS(pvNotification^);
 
      cookieSize := SizeOf(CookieBuffer);
      FillChar(CookieBuffer, cookieSize, 0);
      TGetServerVariable(FilterContext.GetServerVariable)  (FilterContext, 'URL', @CookieBuffer[0], @cookieSize);
      FilterContext.WriteClient(FilterContext, @CookieBuffer[0]   ,cookieSize, 0);
          Result := SF_STATUS_REQ_FINISHED;
 
  end;
  end;
 
 
 
  function TerminateFilter(Flags: DWORD): DWORD; stdcall; export;
  begin
    Result := 1;
  end;
 

  function GetFilterVersion(var pVer: HTTP_FILTER_VERSION): BOOL; stdcall; export;
  begin
    with pVer do
    begin
      dwFilterVersion := MakeLong(0 {minor}, 1 {major});
      StrPCopy(lpszFilterDesc, '');
      dwFlags := SF_NOTIFY_ORDER_DEFAULT or  SF_NOTIFY_PREPROC_HEADERS;
    end;
    Result := True;
  end;
 
exports
  GetFilterVersion,
  HttpFilterProc,
  TerminateFilter;
begin
end.