Home > Uncategorized > create an ISAPI plugin using c++

create an ISAPI plugin using c++

December 9th, 2008

Recently I was assigned a job to cange all the HTML pages in my company website to ASP pages. The site is very old that it had more than 2000 back links from other websites and we wanted a solution which will not change the page rank and search engine rankings.

Renaming the files and changing the internal links was not the best solution so we decided to create an ISAPI plugin to do the required job. All we required was an ISAPI plugin which should rewrite the .html url to .asp url.

ISAPIplugin can be developed only using C++. and C++ was new for me. Some qucik google search gave me the required information to start writing my own ISAPI filter plugin. Here is the sourcode for the plugin.

ISAPI.cpp

#include "stdio.h";
 
#include "stdlib.h";
 
#include "afx.h";
 
#include "afxisapi.h";
 
BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)
 
{
 
pVer->dwFlags = (SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_AUTHENTICATION |
 
SF_NOTIFY_URL_MAP  | SF_NOTIFY_SEND_RAW_DATA | SF_NOTIFY_LOG  | SF_NOTIFY_END_OF_NET_SESSION );
 
// You can subscribe to the notifications you require!
 
pVer->dwFilterVersion = HTTP_FILTER_REVISION;
 
return TRUE;
 
}
 
DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
 
{
 
char buffer[256];
 
DWORD buffSize = sizeof(buffer);
 
HTTP_FILTER_PREPROC_HEADERS *p;
 
CHttpFilterContext *chc;
 
chc = (CHttpFilterContext *)pfc;
 
char *newUrl;
 
switch (NotificationType)  {
 
case SF_NOTIFY_PREPROC_HEADERS :
 
p = (HTTP_FILTER_PREPROC_HEADERS *)pvData;
 
BOOL bHeader = p->GetHeader(pfc,"url",buffer,&buffSize);
 
CString myURL(buffer);
 
if (myURL.Find(".html") != -1)
 
{
 
myURL.Replace(".html",".asp");
 
newUrl = myURL.GetBuffer(myURL.GetLength());
 
p->SetHeader(pfc, "url", newUrl);
 
}
 
return SF_STATUS_REQ_HANDLED_NOTIFICATION;
 
}
 
return SF_STATUS_REQ_NEXT_NOTIFICATION;
 
}

ISAPI.def

LIBRARY           "CDISAPI"
 
EXPORTS
 
HttpFilterProc
 
GetFilterVersion

[Post to Twitter]   [Post to Plurk]   [Post to Digg]   [Post to ping.fm]

Related posts

Shoban Uncategorized

  1. No comments yet.
  1. No trackbacks yet.