In article <199609301043.MAA04662@nixalsverdrus.msro.detemobil.de>, fessel@DeTeMobil.DE (Jan-Hinrich Fessel) writes:
>I do think the redirector-facility is a hot shot and requires some work, esp.
>better error-handling to become usable in production systems. There should be
>a way to restart redirectors in case they exit, and an option to restart them
>automatically after some time-period has expired. If this features are
>availible, it is acceptable to dump core if no redirector is restartable, but
>as it stands now, you must keep a script have an eye on squid...
>
>When i use perl as redirector, the problem is that perl may eventually hit
>some memory limits and exit...
Here is the source code (in C) of a redirector which is used extensively
by our squid without a single problem. It doesn't allocate any memory after
startup.
Richard.
/*
** rredir - redirect to local directory
**
** version 0.1, 7 sep 1996
** - initial version (Richard Huveneers <Richard.Huveneers@hekkihek.hacom.nl>)
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#define ACCESS_LOCAL_DIR "/var/lib/httpd/htdocs/local/rredir"
#define REDIRECT_TO_URL "http://www.hacom.nl/local/rredir"
#define BUFFER_SIZE (16*1024)
int main()
{
char buf[BUFFER_SIZE];
char *s, *t;
int tlu = 0;
/* make standard output line buffered */
if (setvbuf(stdout, NULL, _IOLBF, 0) != 0) return 1;
/* speed up the access() calls below */
if (chdir(ACCESS_LOCAL_DIR) == -1) return 1;
/* scan standard input */
while (fgets(buf, BUFFER_SIZE, stdin) != NULL)
{
/* check for too long urls */
if (strchr(buf, '\n') == NULL)
{
tlu = 1;
continue;
}
if (tlu) goto dont_redirect;
/* determine end of url */
if ((s = strchr(buf, ' ')) == NULL) goto dont_redirect;
*s = '\0';
/* determine first character of filename */
if ((s = strrchr(buf, '/')) == NULL) goto dont_redirect;
s++;
/* security: do not redirect to hidden files, the current
** directory or the parent directory */
if (*s == '.' || *s == '\0') goto dont_redirect;
/* map filename to lower case */
for (t = s; *t != '\0'; t++) *t = (char) tolower((int) *t);
/* check for a local copy of this file */
if (access(s, R_OK) == 0)
{
(void) printf("%s/%s\n", REDIRECT_TO_URL, s);
continue;
}
dont_redirect:
tlu = 0;
(void) printf("\n");
}
return 0;
}
Received on Mon Sep 30 1996 - 11:09:57 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:33:06 MST