-const char parsers_rcs[] = "$Id: parsers.c,v 1.55 2002/05/08 16:01:07 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.56 2002/05/12 15:34:22 jongfoster Exp $";
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
+ * File : $Source: /cvsroot/ijbswa//current/Attic/parsers.c,v $
*
* Purpose : Declares functions to parse/crunch headers and pages.
* Functions declared include:
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.56 2002/05/12 15:34:22 jongfoster
+ * Fixing typo in a comment
+ *
* Revision 1.55 2002/05/08 16:01:07 oes
* Optimized add_to_iob:
* - Use realloc instead of malloc(), memcpy(), free()
{ "cookie:", 7, client_send_cookie },
{ "x-forwarded-for:", 16, client_x_forwarded },
{ "Accept-Encoding:", 16, client_accept_encoding },
- { "TE:", 3, client_te },
- { "Host:", 5, crumble },
+ { "TE:", 3, client_te },
+ { "Host:", 5, client_host },
/* { "if-modified-since:", 18, crumble }, */
{ "Keep-Alive:", 11, crumble },
{ "connection:", 11, crumble },
{ "proxy-connection:", 17, crumble },
+ { "max-forwards:", 13, client_max_forwards },
{ NULL, 0, NULL }
};
return JB_ERR_OK;
}
+
+/*********************************************************************
+ *
+ * Function : client_max_forwards
+ *
+ * Description : If the HTTP method is OPTIONS or TRACE, subtract one
+ * from the value of the Max-Forwards header field.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : header = On input, pointer to header to modify.
+ * On output, pointer to the modified header, or NULL
+ * to remove the header. This function frees the
+ * original string if necessary.
+ *
+ * Returns : JB_ERR_OK on success, or
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err client_max_forwards(struct client_state *csp, char **header)
+{
+ unsigned int max_forwards;
+
+ if ((0 == strcmpic(csp->http->gpc, "trace"))
+ || (0 == strcmpic(csp->http->gpc, "options")))
+ {
+ if (1 == sscanf(*header, "Max-Forwards: %u", &max_forwards))
+ {
+ if (max_forwards-- >= 1)
+ {
+ sprintf(*header, "Max-Forwards: %u", max_forwards);
+ log_error(LOG_LEVEL_HEADER, "Max forwards of %s request now %d", csp->http->gpc, max_forwards);
+ }
+ else
+ {
+ log_error(LOG_LEVEL_ERROR, "Non-intercepted %s request with Max-Forwards zero!", csp->http->gpc);
+ }
+ }
+ }
+
+ return JB_ERR_OK;
+}
+
+
+/*********************************************************************
+ *
+ * Function : client_host
+ *
+ * Description : If the request URI did not contain host and
+ * port information, parse and evaluate the Host
+ * header field.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : header = On input, pointer to header to modify.
+ * On output, pointer to the modified header, or NULL
+ * to remove the header. This function frees the
+ * original string if necessary.
+ *
+ * Returns : JB_ERR_OK on success, or
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err client_host(struct client_state *csp, char **header)
+{
+ char *p, *q;
+
+ if (!csp->http->hostport || (*csp->http->hostport == '*') ||
+ *csp->http->hostport == ' ' || *csp->http->hostport == '\0')
+ {
+
+ if (NULL == (p = strdup((*header)+6)))
+ {
+ return JB_ERR_MEMORY;
+ }
+ chomp(p);
+ if (NULL == (q = strdup(p)))
+ {
+ freez(p);
+ return JB_ERR_MEMORY;
+ }
+
+ freez(csp->http->hostport);
+ csp->http->hostport = p;
+ freez(csp->http->host);
+ csp->http->host = q;
+ q = strchr(csp->http->host, ':');
+ if (q != NULL)
+ {
+ /* Terminate hostname and evaluate port string */
+ *q++ = '\0';
+ csp->http->port = atoi(q);
+ }
+ else
+ {
+ csp->http->port = csp->http->ssl ? 443 : 80;
+ }
+
+ log_error(LOG_LEVEL_HEADER, "New host and port from Host field: %s = %s:%d",
+ csp->http->hostport, csp->http->host, csp->http->port);
+ }
+
+ return JB_ERR_OK;
+}
+
+
/* the following functions add headers directly to the header list */
/*********************************************************************
*
* Function : client_host_adder
*
- * Description : (re)adds the host header. Called from `sed'.
+ * Description : Adds the Host: header field if it is missing.
+ * Called from `sed'.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
jb_err client_host_adder(struct client_state *csp)
{
char *p;
- char *pos;
jb_err err;
if ( !csp->http->hostport || !*(csp->http->hostport))
return JB_ERR_OK;
}
- p = strdup("Host: ");
/*
- ** remove 'user:pass@' from 'proto://user:pass@host'
- */
- if ( (pos = strchr( csp->http->hostport, '@')) != NULL )
+ * remove 'user:pass@' from 'proto://user:pass@host'
+ */
+ if ( (p = strchr( csp->http->hostport, '@')) != NULL )
{
- string_append(&p, pos+1);
+ p++;
}
else
{
- string_append(&p, csp->http->hostport);
+ p = csp->http->hostport;
}
- if (p == NULL)
- {
- return JB_ERR_MEMORY;
- }
-
- log_error(LOG_LEVEL_HEADER, "addh: %s", p);
-
- err = enlist(csp->headers, p);
-
- freez(p);
-
+ log_error(LOG_LEVEL_HEADER, "addh-unique: Host: %s", p);
+ err = enlist_unique_header(csp->headers, "Host", p);
return err;
+
}
#ifndef PARSERS_H_INCLUDED
#define PARSERS_H_INCLUDED
-#define PARSERS_H_VERSION "$Id: parsers.h,v 1.25 2002/03/26 22:29:55 swa Exp $"
+#define PARSERS_H_VERSION "$Id: parsers.h,v 1.26 2002/05/08 15:59:53 oes Exp $"
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/parsers.h,v $
+ * File : $Source: /cvsroot/ijbswa//current/Attic/parsers.h,v $
*
* Purpose : Declares functions to parse/crunch headers and pages.
* Functions declared include:
*
* Revisions :
* $Log: parsers.h,v $
+ * Revision 1.26 2002/05/08 15:59:53 oes
+ * Changed add_to_iob signature (now returns jb_err)
+ *
* Revision 1.25 2002/03/26 22:29:55 swa
* we have a new homepage!
*
extern jb_err client_x_forwarded (struct client_state *csp, char **header);
extern jb_err client_accept_encoding (struct client_state *csp, char **header);
extern jb_err client_te (struct client_state *csp, char **header);
+extern jb_err client_max_forwards (struct client_state *csp, char **header);
+extern jb_err client_host(struct client_state *csp, char **header);
+
extern jb_err client_host_adder (struct client_state *csp);
extern jb_err client_cookie_adder (struct client_state *csp);