+static const char C_URL_INFO_HEADER[] =
+ "HTTP/1.0 200 OK\n"
+ "Pragma: no-cache\n"
+ "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
+ "Content-Type: text/html\n\n"
+ "<html>\n"
+ "<head>\n"
+ "<title>Internet Junkbuster: URL Info</title>\n"
+ "</head>\n"
+ BODY
+ "<h1><center>"
+ BANNER
+ "</h1></center>\n"
+ "<p>Information for: <a href=\"http://%s\">http://%s</a></p>\n";
+static const char C_URL_INFO_FOOTER[] =
+ "\n</p>\n"
+ "</body>\n"
+ "</html>\n";
+
+static const char C_URL_INFO_FORM[] =
+ "HTTP/1.0 200 OK\n"
+ "Pragma: no-cache\n"
+ "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
+ "Content-Type: text/html\n\n"
+ "<html>\n"
+ "<head>\n"
+ "<title>Internet Junkbuster: URL Info</title>\n"
+ "</head>\n"
+ BODY
+ "<h1><center>"
+ BANNER
+ "</h1></center>\n"
+ "<form method=\"GET\" action=\"http://i.j.b/show-url-info\">\n"
+ "<p>Please enter a URL, without the leading "http://":</p>"
+ "<p><input type=\"text\" name=\"url\" size=\"80\">"
+ "<input type=\"submit\" value=\"Info\"></p>\n"
+ "</form>\n"
+ "</body>\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
+ *
+ * Description : (please fill me in)
+ *
+ * Parameters :
+ * 1 : http = http_request request for crunched URL
+ * 2 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : ???FIXME
+ *
+ *********************************************************************/
+char *ijb_show_url_info(struct http_request *http, struct client_state *csp)
+{
+ char * query_string = strchr(http->path, '?');
+ char * host = NULL;
+
+ if (query_string != NULL)
+ {
+ query_string = url_decode(query_string + 1);
+ if (strncmpic(query_string, "url=", 4) == 0)
+ {
+ host = strdup(query_string + 4);
+ }
+ freez(query_string);
+ }
+ if (host != NULL)
+ {
+ char * result;
+ char * path;
+ char * s;
+ int port = 80;
+ struct file_list *fl;
+ struct permissions_spec *b;
+ struct url_spec url[1];
+ int permissions = csp->config->default_permissions;
+
+ 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);
+ 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");
+ freez(s);
+
+ s = strchr(host, '/');
+ if (s != NULL)
+ {
+ path = strdup(s);
+ *s = '\0';
+ }
+ else
+ {
+ path = strdup("");
+ }
+ s = strchr(host, ':');
+ if (s != NULL)
+ {
+ *s++ = '\0';
+ port = atoi(s);
+ }
+
+ if (((fl = csp->permissions_list) == NULL) || ((b = fl->f) == NULL))
+ {
+ freez(host);
+ freez(path);
+ result = strsav(result, C_URL_INFO_FOOTER);
+ return result;
+ }
+
+ *url = dsplit(host);
+
+ /* if splitting the domain fails, punt */
+ if (url->dbuf == NULL)
+ {
+ freez(host);
+ freez(path);
+ result = strsav(result, C_URL_INFO_FOOTER);
+ return result;
+ }
+
+ for (b = b->next; NULL != b; b = b->next)
+ {
+ if ((b->url->port == 0) || (b->url->port == port))
+ {
+ if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
+ {
+ if ((b->url->path == NULL) ||
+#ifdef REGEX
+ (regexec(b->url->preg, path, 0, NULL, 0) == 0)
+#else
+ (strncmp(b->url->path, path, b->url->pathlen) == 0)
+#endif
+ )
+ {
+ s = permissions_to_text(b->mask, b->add);
+ 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;
+ }
+ }
+ }
+ }
+
+ freez(url->dbuf);
+ freez(url->dvec);
+
+ freez(host);
+ freez(path);
+
+ s = permissions_to_text(permissions, permissions);
+ 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);
+
+ result = strsav(result, C_URL_INFO_FOOTER);
+ return result;
+ }
+ else
+ {
+ return strdup(C_URL_INFO_FORM);
+ }
+}
+
+