You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Robert S. Thau" <rs...@ai.mit.edu> on 1996/07/10 21:21:26 UTC

PICS support module...

Here's another possibility for 1.2 and future releases (and maybe
contributed module status in the meantime).  As I mentioned to the
group at the time, I was at a PICS interoperability bake-off a few
weeks ago, and so as not to be the only guy without software, I threw
together a PICS support module for Apache.  It's the basic simplest
possible thing --- it supports a <PICS-label> sectioning directive
for config files, which allows for stuff like:

  <PICS-label>
  (PICS-1.1 "http://www.funky-rate.com/v1.0"
     l r (beat 6.6 volume 11 groove-thang 0.02)
       comment "It's got a beat, but no way can you dance to it")
  </PICS-label>

to appear in .htaccess files (or <Directory>, <VirtualHost>, etc., as
per usual for Apache per-directory state directives, and subject to
control of AllowOverride FileInfo).

Unfortunately, it's taken me until now to get a straight answer about
whether what this module does is actually PICS-compliant enough to be
more of a blessing than a curse on the community as a whole, and it
didn't seem worth bugging the Apache developers in the meantime.  On
balance, it seems, they like it.  (The issue is that I don't send the
Protocol: response header, since I'm not actually parsing
Protocol-request:, and I don't want to claim to the client, in effect,
that I'm doing PEP when I really am not.  As I said, the PEP
developers seem happy enough with this situation).

FWIW, what this does is to put PICS-label headers on affected
documents.  Here's the interoperability round-up; Netscape doesn't
support PICS yet at all, but plans to.  Microsoft currently reads PICS
labels out of HTTP documents, via <META> tags, but doesn't read PICS
labels from HTTP headers.  According to their PICS manager, they
currently aren't likely to do that for their 3.0 final release, but
the capability is likely to show up in early 4.0 betas, and would be
*more* likely to show up if Apache PICS support became widespread in
the meantime.

So it goes.  At any rate, here's the code:

/* copyright 1996 Robert S. Thau */

/*
 * mod_pics_kludge... provide an easy way to set a default PICS label
 * across an entire hierarchy.
 *
 * This defines a <PICS-label> sectioning directive.  If this occurs in any
 * config file:
 *
 *     <PICS-label>
 *     label-text...
 *     </PICS-label>
 *
 * the label-text will be output in a PICS-label header for all requests
 * in which the config file in question is in scope, save only that for nested
 * config files, the innermost <PICS-label> is the one that applies, and that
 * an *empty* PICS-label section turns the feature off (in case a CGI script
 * in an otherwise label-stamped hierarchy, say, wants to decide its own
 * labeling on the fly).
 *
 * This is controlled by AllowOverride FileInfo.
 */

#include "httpd.h"
#include "http_config.h"

extern module pics_kludge_module;

static void *make_pics_kludge_state (pool *p, char *d) {
    return pcalloc (p, sizeof (char *));
}

static char *pics_kludge_section (cmd_parms *cmd, void *pksc) {
    char **pics_kludge_ptr = (char**)pksc;
    char *stuff = "";
    char *endp;
    char buf[512];
    int seen_end = 0;

    while (fgets (buf, sizeof(buf), cmd->infile)) {
	if (!strcasecmp (buf, "</PICS-label>\n")) {
	    seen_end = 1;
	    break;
	}

	/* Strip off newlines to avoid doubling them in the eventual
	 * response header list...
	 */

	endp = buf + strlen(buf) - 1;
	if (*endp == '\n') *endp = '\0';
	
	stuff = pstrcat (cmd->temp_pool, stuff, buf, NULL);
    }

    if (!seen_end) return "Unterminated <PICS-label>";
    
    if (*stuff)
	*pics_kludge_ptr = pstrdup (cmd->pool, stuff);
    else
	*pics_kludge_ptr = NULL;
	
    return NULL;
}

static int pics_kludge_fixup (request_rec *r) {
    char **stuff = (char **)get_module_config (r->per_dir_config,
					       &pics_kludge_module);

    if (!*stuff) return DECLINED;

    table_set (r->headers_out, "PICS-label", *stuff);
    return DECLINED;
}

static command_rec pics_kludge_cmds[] = {
    { "<PICS-label>", pics_kludge_section, NULL, OR_FILEINFO, NO_ARGS,
      "a PICS label beginning on the *following* line, until </PICS-label>\n"
      "on a line of its own" },
    { NULL }
};

module pics_kludge_module = {
   STANDARD_MODULE_STUFF,
   NULL,			/* initializer */
   make_pics_kludge_state,	/* dir config creater */
   NULL,			/* dir merger --- default is to override */
   NULL,			/* server config */
   NULL,			/* merge server configs */
   pics_kludge_cmds,		/* command table */
   NULL,			/* handlers */
   NULL,			/* filename translation */
   NULL,			/* check_user_id */
   NULL,			/* check auth */
   NULL,			/* check access */
   NULL,			/* type_checker */
   pics_kludge_fixup,		/* fixups */
   NULL,			/* logger */
};