-const char parsers_rcs[] = "$Id: parsers.c,v 1.23 2001/09/12 18:08:19 steudten Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.29 2001/09/24 21:09:24 jongfoster Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.29 2001/09/24 21:09:24 jongfoster
+ * Fixing 2 memory leaks that Guy spotted, where the paramater to
+ * enlist() was not being free()d.
+ *
+ * Revision 1.28 2001/09/22 16:32:28 jongfoster
+ * Removing unused #includes.
+ *
+ * Revision 1.27 2001/09/20 15:45:25 steudten
+ *
+ * add casting from size_t to int for printf()
+ * remove local variable shadow s2
+ *
+ * Revision 1.26 2001/09/16 17:05:14 jongfoster
+ * Removing unused #include showarg.h
+ *
+ * Revision 1.25 2001/09/16 13:21:27 jongfoster
+ * Changes to use new list functions.
+ *
+ * Revision 1.24 2001/09/13 23:05:50 jongfoster
+ * Changing the string paramater to the header parsers a "const".
+ *
* Revision 1.23 2001/09/12 18:08:19 steudten
*
* In parse_http_request() header rewriting miss the host value, so
#include "config.h"
+#ifndef _WIN32
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <ctype.h>
+#endif
+
#include <string.h>
#ifndef _WIN32
#include "list.h"
#include "parsers.h"
#include "encode.h"
-#include "filters.h"
-#include "loaders.h"
-#include "showargs.h"
-#include "jcc.h"
#include "ssplit.h"
#include "errlog.h"
#include "jbsockets.h"
#include "miscutil.h"
-#include "cgi.h"
const char parsers_h_rcs[] = PARSERS_H_VERSION;
const struct parsers server_patterns[] = {
+ { "HTTP/1.1 ", 9, server_http11 },
{ "set-cookie:", 11, server_set_cookie },
{ "connection:", 11, crumble },
{ "Content-Type:", 13, content_type },
*********************************************************************/
char *sed(const struct parsers pats[], void (* const more_headers[])(struct client_state *), struct client_state *csp)
{
- struct list *p;
+ struct list_entry *p;
const struct parsers *v;
char *hdr;
void (* const *f)();
for (v = pats; v->str ; v++)
{
- for (p = csp->headers->next; p ; p = p->next)
+ for (p = csp->headers->first; p ; p = p->next)
{
/* Header crunch()ed in previous run? -> ignore */
if (p->str == NULL) continue;
if (strncmpic(p->str, v->str, v->len) == 0)
{
hdr = v->parser(v, p->str, csp);
- freez(p->str);
+ freez((char *)p->str); /* FIXME: Yuck! patching a list...*/
p->str = hdr;
}
}
|| (0 == strcmpic(v[0], "unlock"))
)
{
- http->ssl = 0;
- http->gpc = strdup(v[0]);
- url = v[1];
- http->ver = strdup(v[2]);
+ http->ssl = 0;
+ http->gpc = strdup(v[0]);
+ url = v[1];
+ /* since we don't support HTTP/1.1 we must not send it */
+ if (!strcmpic(v[2], "HTTP/1.1"))
+ {
+ http->ver = strdup("HTTP/1.0");
+ /* change cmd too (forwaring) */
+ freez(http->cmd);
+ http->cmd = strsav(http->cmd, http->gpc);
+ http->cmd = strsav(http->cmd, " ");
+ http->cmd = strsav(http->cmd, url);
+ http->cmd = strsav(http->cmd, " ");
+ http->cmd = strsav(http->cmd, http->ver);
+ }
+ else
+ {
+ http->ver = strdup(v[2]);
+ }
save_url = url;
if (strncmpic(url, "http://", 7) == 0)
if (csp->content_length != 0) /* Content has been modified */
{
char * s2 = (char *) zalloc(100);
- sprintf(s2, "Content-Length: %d", csp->content_length);
+ sprintf(s2, "Content-Length: %d", (int) csp->content_length);
- log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length);
+ log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", (int) csp->content_length);
return(s2);
}
else
/*
* We have a specific (fixed) referer we want to send.
*/
- char * s2;
+ char * s3;
log_error(LOG_LEVEL_HEADER, "modified");
- s2 = strsav( NULL, "Referer: " );
- s2 = strsav( s2, newval );
- return(s2);
+ s3 = strsav( NULL, "Referer: " );
+ s3 = strsav( s3, newval );
+ return(s3);
}
/* Should never get here! */
*********************************************************************/
void client_cookie_adder(struct client_state *csp)
{
- struct list *lst;
+ struct list_entry *lst;
char *tmp = NULL;
char *e;
- for (lst = csp->cookie_list->next; lst ; lst = lst->next)
+ for (lst = csp->cookie_list->first; lst ; lst = lst->next)
{
if (tmp)
{
tmp = strsav(tmp, lst->str);
}
- for (lst = csp->action->multi[ACTION_MULTI_WAFER]->next; lst ; lst = lst->next)
+ for (lst = csp->action->multi[ACTION_MULTI_WAFER]->first; lst ; lst = lst->next)
{
if (tmp)
{
*********************************************************************/
void client_xtra_adder(struct client_state *csp)
{
- struct list *lst;
+ struct list_entry *lst;
- for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->next;
+ for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->first;
lst ; lst = lst->next)
{
log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
log_error(LOG_LEVEL_HEADER, "addh: %s", p);
enlist(csp->headers, p);
+ freez(p);
}
*********************************************************************/
void connection_close_adder(struct client_state *csp)
{
- enlist(csp->headers, strdup("Connection: close"));
+ enlist(csp->headers, "Connection: close");
+}
+
+
+/*********************************************************************
+ *
+ * Function : server_http11
+ *
+ * Description : Rewrite HTTP/1.1 answers to HTTP/1.0 until we add
+ * HTTP/1.1 support. Called from `sed'.
+ *
+ * Parameters :
+ * 1 : v = parser pattern that matched this header
+ * 2 : s = header that matched this pattern
+ * 3 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : "HTTP/1.0" answer.
+ *
+ *********************************************************************/
+char *server_http11(const struct parsers *v, const char *s, struct client_state *csp)
+{
+ char *ret;
+
+ ret = strdup(s);
+ ret[7] = '0'; /* "HTTP/1.1 ..." -> "HTTP/1.0 ..." */
+ return ret;
}
char *cleanhost = strdup(s);
if(csp->force)
+ {
strclean(cleanhost, FORCE_PREFIX);
+ }
return(cleanhost);
}