/*
XTroll: A proxy filter for the Reason Hit & Run blog
Copyright (C) 2007 Richard Heurtley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
History:
2008-12-03 v1.4 Added embedded URL removal
2007-12-07 v1.3 Added post content filtering
2007-07-13 v1.2 Added URL replacement
2007-07-12 v1.1 Fixed a problem with chunk decoding
2007-07-11 v1.0 First release
*/
/**---------------------------------------------------------------------------*/
#ifdef __WATCOMC__
#define WINDOWS
#endif
#ifdef _MSC_VER
#define WINDOWS
#endif
#ifndef WINDOWS
#define LINUX
#endif
/**---------------------------------------------------------------------------*/
#include
#include
#include
#include
#include
#include
#ifdef WINDOWS
#include
#endif
#ifdef LINUX
#include
#include
#include
#include
#include
#include
#include
#include
#endif
/**---------------------------------------------------------------------------*/
//#define DEBUG
#define STATE_HEADER (0)
#define STATE_CONTENTLENGTH (1)
#define STATE_CHUNKED (2)
#define memeq !memcmp
#define streq !strcmp
#ifdef LINUX
#define SOCKET int
#define WSAGetLastError() errno
#define closesocket close
#endif
#ifdef WINDOWS
#define socklen_t int
#endif
/**---------------------------------------------------------------------------*/
typedef struct
{
char type; // nlcx
int len;
char text[64+1];
} FILTER;
#define NFILTERS (128)
typedef struct
{
int bufferlen;
int headerlen;
int bodylen;
int nlines;
char *bodyp;
char *lines[1024];
char header[65536];
char buffer[2 * 1024 * 1024];
} LOCAL;
static LOCAL l;
/**---------------------------------------------------------------------------*/
#ifdef LINUX
int _memicmp(char *p, char *q, int nbytes)
{
int rv;
int i;
for (i = 0; i < nbytes; i++, p++, q++)
{
if (toupper(*p) != toupper(*q))
break;
}
if (i < nbytes)
rv = 1;
else
rv = 0;
return(rv);
}
#endif
/**---------------------------------------------------------------------------*/
int streqz(char *p0, char *p1)
{
int rv;
char c0;
char c1;
if (!*p0 || !*p1) // if either string is empty
return(0); // then return no match
for (;;)
{
c0 = *p0++;
c1 = *p1++;
if (!c0 || !c1)
break;
if (c0 != c1)
break;
}
if (!c0 || !c1)
rv = 1;
else
rv = 0;
return(rv);
}
/**---------------------------------------------------------------------------*/
int Embedded(char *p)
{
int rv;
rv =
(
streqz(p, "