-const char filters_rcs[] = "$Id: filters.c,v 1.41 2001/11/13 00:14:07 jongfoster Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.44 2002/03/07 03:49:31 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
*
* Revisions :
* $Log: filters.c,v $
+ * Revision 1.44 2002/03/07 03:49:31 oes
+ * - Fixed compiler warnings etc
+ * - Changed built-in images from GIF to PNG
+ * (with regard to Unisys patent issue)
+ * - Added a 4x4 pattern PNG which is less intrusive
+ * than the logo but also clearly marks the deleted banners
+ *
+ * Revision 1.43 2002/01/22 23:51:59 jongfoster
+ * Replacing strsav() with the safer string_append().
+ *
+ * Adding missing html_encode() to error message generators. Where encoded
+ * and unencoded versions of a string were provided, removing the unencoded
+ * one.
+ *
+ * Revision 1.42 2002/01/17 21:00:32 jongfoster
+ * Moving all our URL and URL pattern parsing code to urlmatch.c.
+ *
+ * Using a single, simple url_match(pattern,url) function - rather than
+ * the 3-line match routine which was repeated all over the place.
+ *
+ * Renaming free_url to free_url_spec, since it frees a struct url_spec.
+ *
+ * Using parse_http_url() to parse URLs without faking a HTTP
+ * request line for parse_http_request().
+ *
* Revision 1.41 2001/11/13 00:14:07 jongfoster
* Fixing stupid bug now I've figured out what || means.
* (It always returns 0 or 1, not one of it's paramaters.)
*
* Function : acl_addr
*
- * Description : Called from `load_aclfile' to parse an ACL address.
+ * Description : Called from `load_config' to parse an ACL address.
*
* Parameters :
* 1 : aspec = String specifying ACL address.
aca->addr = ntohl(resolve_hostname_to_ip(aspec));
- if (aca->addr == -1)
+ if (aca->addr == INADDR_NONE)
{
- log_error(LOG_LEVEL_ERROR, "can't resolve address for %s", aspec);
return(-1);
}
/* and handle accordingly: */
if ((p == NULL) || (0 == strcmpic(p, "logo")))
{
- rsp->body = bindup(image_junkbuster_gif_data, image_junkbuster_gif_length);
+ rsp->body = bindup(image_logo_data, image_logo_length);
if (rsp->body == NULL)
{
free_http_response(rsp);
return cgi_error_memory();
}
- rsp->content_length = image_junkbuster_gif_length;
+ rsp->content_length = image_logo_length;
- if (enlist_unique_header(rsp->headers, "Content-Type", "image/gif"))
+ if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE))
{
free_http_response(rsp);
return cgi_error_memory();
else if (0 == strcmpic(p, "blank"))
{
- rsp->body = bindup(image_blank_gif_data, image_blank_gif_length);
+ rsp->body = bindup(image_blank_data, image_blank_length);
+ if (rsp->body == NULL)
+ {
+ free_http_response(rsp);
+ return cgi_error_memory();
+ }
+ rsp->content_length = image_blank_length;
+
+ if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE))
+ {
+ free_http_response(rsp);
+ return cgi_error_memory();
+ }
+ }
+
+ else if (0 == strcmpic(p, "pattern"))
+ {
+ rsp->body = bindup(image_pattern_data, image_pattern_length);
if (rsp->body == NULL)
{
free_http_response(rsp);
return cgi_error_memory();
}
- rsp->content_length = image_blank_gif_length;
+ rsp->content_length = image_pattern_length;
- if (enlist_unique_header(rsp->headers, "Content-Type", "image/gif"))
+ if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE))
{
free_http_response(rsp);
return cgi_error_memory();
*/
err = map(exports, "hostport", 1, csp->http->hostport, 1);
if (!err) err = map(exports, "path", 1, csp->http->path, 1);
- if (!err) err = map(exports, "hostport-html", 1, html_encode(csp->http->hostport), 0);
- if (!err) err = map(exports, "path-html", 1, html_encode(csp->http->path), 0);
if (NULL != (p = get_header_value(csp->headers, "Referer:")))
{
- if (!err) err = map(exports, "referrer", 1, p, 1);
- if (!err) err = map(exports, "referrer-html", 1, html_encode(p), 0);
+ if (!err) err = map(exports, "referrer", 1, html_encode(p), 0);
}
else
{
if (!err) err = map(exports, "referrer", 1, "unknown", 1);
- if (!err) err = map(exports, "referrer-html", 1, "unknown", 1);
}
if (err)
struct block_spec *b;
struct url_spec **trusted_url;
struct http_request rhttp[1];
- char *p, *h;
+ const char * referer;
jb_err err;
/*
}
}
- if (NULL == (h = get_header_value(csp->headers, "Referer:")))
+ if (NULL == (referer = get_header_value(csp->headers, "Referer:")))
{
/* no referrer was supplied */
return 1;
* Parse the URL from the referrer
*/
- err = parse_http_url(h, rhttp, csp);
+ err = parse_http_url(referer, rhttp, csp);
if (err)
{
return 1;
if ((fp = fopen(csp->config->trustfile, "a")))
{
- h = NULL;
+ char * path;
+ char * path_end;
+ char * new_entry = strdup("~");
- h = strsav(h, "~");
- h = strsav(h, csp->http->hostport);
+ string_append(&new_entry, csp->http->hostport);
- p = csp->http->path;
- if ((*p++ == '/')
- && (*p++ == '~'))
+ path = csp->http->path;
+ if ( (path[0] == '/')
+ && (path[1] == '~')
+ && ((path_end = strchr(path + 2, '/')) != NULL))
{
/* since this path points into a user's home space
* be sure to include this spec in the trustfile.
*/
- if ((p = strchr(p, '/')))
+ int path_len = path_end - path; /* save offset */
+ path = strdup(path); /* Copy string */
+ if (path != NULL)
{
- *p = '\0'; /* FIXME: writing to csp->http->path is a bad idea */
- h = strsav(h, csp->http->path);
- h = strsav(h, "/");
+ path_end = path + path_len; /* regenerate ptr to new buffer */
+ *(path_end + 1) = '\0'; /* Truncate path after '/' */
}
+ string_join(&new_entry, path);
+ }
+
+ if (new_entry != NULL)
+ {
+ fprintf(fp, "%s\n", new_entry);
+ free(new_entry);
+ }
+ else
+ {
+ /* FIXME: No way to handle out-of memory, so mostly ignoring it */
+ log_error(LOG_LEVEL_ERROR, "Out of memory adding pattern to trust file");
}
- fprintf(fp, "%s\n", h);
- freez(h);
fclose(fp);
}
return 0;
{
struct binbuffer *in, *out;
char *p;
- int size = csp->iob->eod - csp->iob->cur;
+ size_t size = csp->iob->eod - csp->iob->cur;
/*
* If the body has a "chunked" transfer-encoding,