-const char filters_rcs[] = "$Id: filters.c,v 1.11 2001/05/29 11:53:23 oes Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.12 2001/05/31 17:35:20 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
* Purpose : Declares functions to parse/crunch headers and pages.
* Functions declared include:
* `acl_addr', `add_stats', `block_acl', `block_imageurl',
- * `block_url', `url_permissions', `domaincmp', `dsplit',
+ * `block_url', `url_actions', `domaincmp', `dsplit',
* `filter_popups', `forward_url', 'redirect_url',
* `ij_untrusted_url', `intercept_url', `re_process_buffer',
* `show_proxy_args', 'ijb_send_banner', and `trust_url'
*
* Revisions :
* $Log: filters.c,v $
+ * Revision 1.12 2001/05/31 17:35:20 oes
+ *
+ * - Enhanced domain part globbing with infix and prefix asterisk
+ * matching and optional unanchored operation
+ *
* Revision 1.11 2001/05/29 11:53:23 oes
* "See why" link added to "blocked" page
*
#include "errlog.h"
#include "jbsockets.h"
#include "miscutil.h"
+#include "actions.h"
#ifdef _WIN32
#include "win32.h"
int n;
int factor = 2;
- if ((csp->permissions & PERMIT_BLOCK) == 0)
+ if ((csp->action->flags & ACTION_BLOCK) == 0)
{
return(NULL);
}
}
#endif
- return ((csp->permissions & PERMIT_IMAGE) != 0);
+ return ((csp->action->flags & ACTION_IMAGE) != 0);
}
#endif /* def IMAGE_BLOCKING */
/*********************************************************************
*
- * Function : url_permissions
+ * Function : url_actions
*
- * Description : Gets the permissions for this URL.
+ * Description : Gets the actions for this URL.
*
* Parameters :
* 1 : http = http_request request for blocked URLs
* 2 : csp = Current client state (buffers, headers, etc...)
*
- * Returns : permissions bitmask specifiying what this URL can do.
- * If not on list, will be default_permissions.
+ * Returns : N/A
*
*********************************************************************/
-int url_permissions(struct http_request *http, struct client_state *csp)
+void url_actions(struct http_request *http,
+ struct client_state *csp)
{
struct file_list *fl;
- struct permissions_spec *b;
+ struct url_actions *b;
+
+ init_current_action(csp->action);
+
+ if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
+ {
+ return;
+ }
+
+ apply_url_actions(csp->action, http, b);
+}
+
+
+/*********************************************************************
+ *
+ * Function : apply_url_actions
+ *
+ * Description : Applies a list of URL actions.
+ *
+ * Parameters :
+ * 1 : action = Destination.
+ * 2 : http = Current URL
+ * 3 : b = list of URL actions to apply
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void apply_url_actions(struct current_action_spec *action,
+ struct http_request *http,
+ struct url_actions *b)
+{
struct url_spec url[1];
- int permissions = csp->config->default_permissions;
- if (((fl = csp->permissions_list) == NULL) || ((b = fl->f) == NULL))
+ if (b == NULL)
{
- return(permissions);
+ /* Should never happen */
+ return;
}
*url = dsplit(http->host);
/* if splitting the domain fails, punt */
if (url->dbuf == NULL)
{
- return(permissions);
+ return;
}
for (b = b->next; NULL != b; b = b->next)
#endif
)
{
- permissions &= b->mask;
- permissions |= b->add;
+ merge_current_action(action, b->action);
}
}
}
freez(url->dbuf);
freez(url->dvec);
- return(permissions);
-
}
return ((pn < pattern->dcnt) || ((fn < fqdn->dcnt) && !pattern->unanchored));
+ return(0);
+
}
switch (which_file)
{
case 'p':
- if (csp->permissions_list)
+ if (csp->actions_list)
{
- filename = csp->permissions_list->filename;
- file_description = "Permissions List";
+ filename = csp->actions_list->filename;
+ file_description = "Actions List";
}
break;
case 'f':
"<p>(Click a filename to view it)</p>\n"
"<ul>\n");
- if (csp->permissions_list)
+ if (csp->actions_list)
{
- s = strsav(s, "<li>Permissions List: <a href=\"show-proxy-args?permit\"><code>");
- s = strsav(s, csp->permissions_list->filename);
+ s = strsav(s, "<li>Actions List: <a href=\"show-proxy-args?permit\"><code>");
+ s = strsav(s, csp->actions_list->filename);
s = strsav(s, "</code></a></li>\n");
}
"</html>\n";
-/*********************************************************************
- *
- * Function : permissions_to_text
- *
- * Description : Converts a permissionsfil entry from numeric form
- * ("mask" and "add") to text.
- *
- * Parameters :
- * 1 : mask = As from struct permissions_spec
- * 2 : add = As from struct permissions_spec
- *
- * Returns : A string. Caller must free it.
- *
- *********************************************************************/
-char * permissions_to_text(unsigned mask, unsigned add)
-{
- char * result = strdup("");
-
- /* sanity - prevents "-feature +feature" */
- mask |= add;
-
-#define PERMISSION_TO_TEXT(__bit, __name) \
- if (!(mask & __bit)) \
- { \
- result = strsav(result, " -" __name); \
- } \
- else if (add & __bit) \
- { \
- result = strsav(result, " +" __name); \
- }
-
- PERMISSION_TO_TEXT(PERMIT_COOKIE_SET, "cookies-set");
- PERMISSION_TO_TEXT(PERMIT_COOKIE_READ, "cookies-read");
- PERMISSION_TO_TEXT(PERMIT_RE_FILTER, "filter");
- PERMISSION_TO_TEXT(PERMIT_POPUPS, "popup");
- PERMISSION_TO_TEXT(PERMIT_REFERER, "referer");
- PERMISSION_TO_TEXT(PERMIT_FAST_REDIRECTS, "fast-redirects");
- PERMISSION_TO_TEXT(PERMIT_BLOCK, "block");
- PERMISSION_TO_TEXT(PERMIT_IMAGE, "image");
-
- return result;
-}
-
-
/*********************************************************************
*
* Function : ijb_show_url_info
char * s;
int port = 80;
struct file_list *fl;
- struct permissions_spec *b;
+ struct url_actions *b;
struct url_spec url[1];
- int permissions = csp->config->default_permissions;
+ struct current_action_spec action[1];
+
+ init_current_action(action);
result = (char *)malloc(sizeof(C_URL_INFO_HEADER) + 2 * strlen(host));
sprintf(result, C_URL_INFO_HEADER, host, host);
- s = permissions_to_text(permissions, permissions);
+ s = current_action_to_text(action);
result = strsav(result, "<h3>Defaults:</h3>\n<p><b>{");
result = strsav(result, s);
result = strsav(result, " }</b></p>\n<h3>Patterns affecting the URL:</h3>\n<p>\n");
port = atoi(s);
}
- if (((fl = csp->permissions_list) == NULL) || ((b = fl->f) == NULL))
+ if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
{
freez(host);
freez(path);
#endif
)
{
- s = permissions_to_text(b->mask, b->add);
+ s = actions_to_text(b->action);
result = strsav(result, "<b>{");
result = strsav(result, s);
result = strsav(result, " }</b><br>\n<code>");
result = strsav(result, b->url->spec);
result = strsav(result, "</code><br>\n<br>\n");
freez(s);
- permissions &= b->mask;
- permissions |= b->add;
+
+ merge_current_action(action, b->action);
}
}
}
freez(host);
freez(path);
- s = permissions_to_text(permissions, permissions);
+ s = current_action_to_text(action);
result = strsav(result, "</p>\n<h2>Final Results:</h2>\n<p><b>{");
result = strsav(result, s);
result = strsav(result, " }</b><br>\n<br>\n");
freez(s);
+ free_current_action(action);
+
result = strsav(result, C_URL_INFO_FOOTER);
return result;
}
#ifndef _FILTERS_H
#define _FILTERS_H
-#define FILTERS_H_VERSION "$Id: filters.h,v 1.5 2001/05/27 22:17:04 oes Exp $"
+#define FILTERS_H_VERSION "$Id: filters.h,v 1.6 2001/05/29 09:50:24 jongfoster Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.h,v $
* Purpose : Declares functions to parse/crunch headers and pages.
* Functions declared include:
* `acl_addr', `add_stats', `block_acl', `block_imageurl',
- * `block_url', `url_permissions', `domaincmp', `dsplit',
+ * `block_url', `url_actions', `domaincmp', `dsplit',
* `filter_popups', `forward_url'
* `ij_untrusted_url', `intercept_url', `re_process_buffer',
* `show_proxy_args', and `trust_url'
*
* Revisions :
* $Log: filters.h,v $
+ * Revision 1.6 2001/05/29 09:50:24 jongfoster
+ * Unified blocklist/imagelist/permissionslist.
+ * File format is still under discussion, but the internal changes
+ * are (mostly) done.
+ *
+ * Also modified interceptor behaviour:
+ * - We now intercept all URLs beginning with one of the following
+ * prefixes (and *only* these prefixes):
+ * * http://i.j.b/
+ * * http://ijbswa.sf.net/config/
+ * * http://ijbswa.sourceforge.net/config/
+ * - New interceptors "home page" - go to http://i.j.b/ to see it.
+ * - Internal changes so that intercepted and fast redirect pages
+ * are not replaced with an image.
+ * - Interceptors now have the option to send a binary page direct
+ * to the client. (i.e. ijb-send-banner uses this)
+ * - Implemented show-url-info interceptor. (Which is why I needed
+ * the above interceptors changes - a typical URL is
+ * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
+ * The previous mechanism would not have intercepted that, and
+ * if it had been intercepted then it then it would have replaced
+ * it with an image.)
+ *
* Revision 1.5 2001/05/27 22:17:04 oes
*
* - re_process_buffer no longer writes the modified buffer
extern int block_imageurl(struct http_request *http, struct client_state *csp);
#endif /* def IMAGE_BLOCKING */
-extern int url_permissions(struct http_request *http, struct client_state *csp);
+extern void url_actions(struct http_request *http,
+ struct client_state *csp);
+extern void apply_url_actions(struct current_action_spec *action,
+ struct http_request *http,
+ struct url_actions *b);
+
extern const struct gateway *forward_url(struct http_request *http, struct client_state *csp);
extern struct url_spec dsplit(char *domain);