|
#include "stdafx.h"
#include "string.h"
#include <atlbase.h>
#include <atlcoll.h>
#include <atlstr.h>
typedef CAtlMap<CString, CString> APPMAP;
APPMAP _appMap;
HANDLE _hModule;
int FindDirectory(char *s);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
_hModule = hModule;
return TRUE;
}
BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)
{
char sBuf1[5000];
pVer->dwFilterVersion = pVer->dwServerFilterVersion;//HTTP_FILTER_REVISION;
pVer->dwFlags = SF_NOTIFY_PREPROC_HEADERS|SF_NOTIFY_ORDER_HIGH ;
strcpy(pVer->lpszFilterDesc, "MultiSite");
//Load config
GetModuleFileName((HMODULE)_hModule, sBuf1, sizeof(sBuf1));
char * p = strrchr(sBuf1, '\\');
*p = 0;
strcat(sBuf1, "\\config.ini");
CString sConfigFile = sBuf1;
sBuf1[0] = 0;
DWORD dwSize = sizeof(sBuf1);
dwSize = GetPrivateProfileSection("websites", sBuf1, dwSize, sConfigFile);
char *s = sBuf1;
while(true)
{
int iLen = strlen(s);
if( iLen == 0 )
break;
CString sName, sValue;
char *p = s;
while(( *p != '=') && (*p != 0 ))
p++;
*p = 0;
p++;
sName = s;
sValue = p;
_appMap[sName.MakeLower().Trim()] = sValue.Trim();
s += iLen + 1;
}
return TRUE;
}
DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
{
char sBuf[1000];
char sBuf1[1000];
DWORD dwSize = sizeof(sBuf);
char *s = sBuf;
int iLen = 0;
HTTP_FILTER_PREPROC_HEADERS *tmp = (PHTTP_FILTER_PREPROC_HEADERS)pvData;
if( NotificationType == SF_NOTIFY_PREPROC_HEADERS )
{
int iIndex = 0;
tmp->GetHeader(pfc, const_cast<char*>("Host:"), sBuf, &dwSize);
sBuf[dwSize] = 0;
//strip out www. if Host starts with it.
strlwr(sBuf);
if( ( dwSize > 4) && ( sBuf[0] == 'w' ) && ( sBuf[1] == 'w' ) && ( sBuf[2] == 'w' ) && ( sBuf[3] == '.' ) )
iIndex = 4;
APPMAP::CPair *pr =_appMap.Lookup(&sBuf[iIndex]);
if( pr == NULL )
return SF_STATUS_REQ_NEXT_NOTIFICATION; //have nothing to do.
dwSize = sizeof(sBuf);
tmp->GetHeader(pfc, const_cast<char*>("URL"), sBuf, &dwSize);
sBuf[dwSize] = 0;
//we got the directory. Let's check that it is not = to our folder. if yes then we do nothing.
int iLen = FindDirectory(sBuf);
if(( iLen == pr->m_value.GetLength() ) && ( _strnicmp( sBuf, pr->m_value, iLen) == 0 ))
return SF_STATUS_REQ_NEXT_NOTIFICATION; //Do nothing
//Append our folder to the URL.
strcpy(sBuf1, pr->m_value);
strcat(sBuf1, sBuf);
tmp->SetHeader(pfc, const_cast<char*>("URL"), sBuf1);
}
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
//returns the lenght from "/" to the next "/"
inline int FindDirectory(char *s)
{
if( *s != '/' )
return 0; //it must always start with '/' or we will not know what to do.
int iLen = 1;
s++;
while(( *s != 0 ) && ( *s != '/' ))
{
s++;
iLen++;
}
return iLen;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.