From ae6704a51522180202416c36a30a4d6d2914a0f5 Mon Sep 17 00:00:00 2001 From: jongfoster Date: Thu, 13 Sep 2001 23:05:50 +0000 Subject: [PATCH] Changing the string paramater to the header parsers a "const". --- parsers.c | 87 +++++++++++++++++++++++++++++++------------------------ parsers.h | 29 ++++++++++--------- project.h | 11 +++++-- 3 files changed, 74 insertions(+), 53 deletions(-) diff --git a/parsers.c b/parsers.c index 1d705db7..f7496175 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.22 2001/09/10 10:58:53 oes Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.23 2001/09/12 18:08:19 steudten Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -41,6 +41,12 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.22 2001/09/10 10:58:53 oes Exp $" * * Revisions : * $Log: parsers.c,v $ + * Revision 1.23 2001/09/12 18:08:19 steudten + * + * In parse_http_request() header rewriting miss the host value, so + * from http://www.mydomain.com the result was just " / " not + * http://www.mydomain.com/ in case we forward. + * * Revision 1.22 2001/09/10 10:58:53 oes * Silenced compiler warnings * @@ -714,7 +720,7 @@ void parse_http_request(char *req, struct http_request *http, struct client_stat * Returns : Always NULL. * *********************************************************************/ -char *crumble(const struct parsers *v, char *s, struct client_state *csp) +char *crumble(const struct parsers *v, const char *s, struct client_state *csp) { log_error(LOG_LEVEL_HEADER, "crunch!"); return(NULL); @@ -736,7 +742,7 @@ char *crumble(const struct parsers *v, char *s, struct client_state *csp) * Returns : A duplicate string pointer to this header (ie. pass thru) * *********************************************************************/ -char *content_type(const struct parsers *v, char *s, struct client_state *csp) +char *content_type(const struct parsers *v, const char *s, struct client_state *csp) { if (strstr(s, " text/") || strstr(s, "application/x-javascript")) csp->content_type = CT_TEXT; @@ -765,15 +771,15 @@ char *content_type(const struct parsers *v, char *s, struct client_state *csp) * Returns : A duplicate string pointer to this header (ie. pass thru) * *********************************************************************/ -char *content_length(const struct parsers *v, char *s, struct client_state *csp) +char *content_length(const struct parsers *v, const char *s, struct client_state *csp) { if (csp->content_length != 0) /* Content has been modified */ { - s = (char *) zalloc(100); - sprintf(s, "Content-Length: %d", csp->content_length); + char * s2 = (char *) zalloc(100); + sprintf(s2, "Content-Length: %d", csp->content_length); - log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length); - return(s); + log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length); + return(s2); } else { @@ -799,9 +805,10 @@ char *content_length(const struct parsers *v, char *s, struct client_state *csp) * or modified header * *********************************************************************/ -char *client_referrer(const struct parsers *v, char *s, struct client_state *csp) +char *client_referrer(const struct parsers *v, const char *s, struct client_state *csp) { const char * newval; + char * s2; #ifdef FEATURE_FORCE_LOAD /* Since the referrer can include the prefix even * even if the request itself is non-forced, we must @@ -843,11 +850,11 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp * to fool stupid checks for in-site links */ log_error(LOG_LEVEL_HEADER, "crunch+forge!"); - s = strsav(NULL, "Referer: "); - s = strsav(s, "http://"); - s = strsav(s, csp->http->hostport); - s = strsav(s, "/"); - return(s); + s2 = strsav(NULL, "Referer: "); + s2 = strsav(s2, "http://"); + s2 = strsav(s2, csp->http->hostport); + s2 = strsav(s2, "/"); + return(s2); } /* @@ -858,12 +865,13 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp /* * We have a specific (fixed) referer we want to send. */ + char * s2; log_error(LOG_LEVEL_HEADER, "modified"); - s = strsav( NULL, "Referer: " ); - s = strsav( s, newval ); - return(s); + s2 = strsav( NULL, "Referer: " ); + s2 = strsav( s2, newval ); + return(s2); } /* Should never get here! */ @@ -876,11 +884,11 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp * to fool stupid checks for in-site links */ log_error(LOG_LEVEL_HEADER, "crunch+forge!"); - s = strsav(NULL, "Referer: "); - s = strsav(s, "http://"); - s = strsav(s, csp->http->hostport); - s = strsav(s, "/"); - return(s); + s2 = strsav(NULL, "Referer: "); + s2 = strsav(s2, "http://"); + s2 = strsav(s2, csp->http->hostport); + s2 = strsav(s2, "/"); + return(s2); } @@ -901,9 +909,10 @@ char *client_referrer(const struct parsers *v, char *s, struct client_state *csp * a malloc'ed string pointer to this header (ie. pass thru). * *********************************************************************/ -char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) +char *client_uagent(const struct parsers *v, const char *s, struct client_state *csp) { const char * newval; + char * s2; /* Save the client's User-Agent: value */ if (strlen(s) >= 12) @@ -934,9 +943,9 @@ char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) log_error(LOG_LEVEL_HEADER, "modified"); - s = strsav( NULL, "User-Agent: " ); - s = strsav( s, newval ); - return(s); + s2 = strsav( NULL, "User-Agent: " ); + s2 = strsav( s2, newval ); + return(s2); } @@ -955,7 +964,7 @@ char *client_uagent(const struct parsers *v, char *s, struct client_state *csp) * Returns : NULL if crunched, or a malloc'ed string to original header * *********************************************************************/ -char *client_ua(const struct parsers *v, char *s, struct client_state *csp) +char *client_ua(const struct parsers *v, const char *s, struct client_state *csp) { if ((csp->action->flags & ACTION_HIDE_USER_AGENT) == 0) { @@ -985,9 +994,10 @@ char *client_ua(const struct parsers *v, char *s, struct client_state *csp) * modified/original header. * *********************************************************************/ -char *client_from(const struct parsers *v, char *s, struct client_state *csp) +char *client_from(const struct parsers *v, const char *s, struct client_state *csp) { const char * newval; + char * s2; if ((csp->action->flags & ACTION_HIDE_FROM) == 0) { @@ -1007,9 +1017,9 @@ char *client_from(const struct parsers *v, char *s, struct client_state *csp) log_error(LOG_LEVEL_HEADER, " modified"); - s = strsav( NULL, "From: " ); - s = strsav( s, newval ); - return(s); + s2 = strsav( NULL, "From: " ); + s2 = strsav( s2, newval ); + return(s2); } @@ -1030,7 +1040,7 @@ char *client_from(const struct parsers *v, char *s, struct client_state *csp) * Returns : Always NULL. * *********************************************************************/ -char *client_send_cookie(const struct parsers *v, char *s, struct client_state *csp) +char *client_send_cookie(const struct parsers *v, const char *s, struct client_state *csp) { if ((csp->action->flags & ACTION_NO_COOKIE_READ) == 0) { @@ -1065,7 +1075,7 @@ char *client_send_cookie(const struct parsers *v, char *s, struct client_state * * Returns : Always NULL. * *********************************************************************/ -char *client_x_forwarded(const struct parsers *v, char *s, struct client_state *csp) +char *client_x_forwarded(const struct parsers *v, const char *s, struct client_state *csp) { if ((csp->action->flags & ACTION_HIDE_FORWARDED) == 0) { @@ -1100,7 +1110,7 @@ char *client_x_forwarded(const struct parsers *v, char *s, struct client_state * * Returns : Duplicate of argument s. * *********************************************************************/ -char *client_accept(const struct parsers *v, char *s, struct client_state *csp) +char *client_accept(const struct parsers *v, const char *s, struct client_state *csp) { #ifdef FEATURE_IMAGE_DETECT_MSIE if (strstr (s, "image/gif")) @@ -1196,9 +1206,10 @@ void client_cookie_adder(struct client_state *csp) *********************************************************************/ void client_xtra_adder(struct client_state *csp) { - struct list *lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]; + struct list *lst; - for (lst = lst->next; lst ; lst = lst->next) + for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->next; + lst ; lst = lst->next) { log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str); enlist(csp->headers, lst->str); @@ -1284,7 +1295,7 @@ void connection_close_adder(struct client_state *csp) * Returns : `crumble' or a newly malloc'ed string. * *********************************************************************/ -char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp) +char *server_set_cookie(const struct parsers *v, const char *s, struct client_state *csp) { #ifdef FEATURE_COOKIE_JAR if (csp->config->jar) @@ -1319,7 +1330,7 @@ char *server_set_cookie(const struct parsers *v, char *s, struct client_state *c * Returns : A malloc'ed pointer to the cleaned host header * *********************************************************************/ -char *client_host(const struct parsers *v, char *s, struct client_state *csp) +char *client_host(const struct parsers *v, const char *s, struct client_state *csp) { char *cleanhost = strdup(s); diff --git a/parsers.h b/parsers.h index 458d2c7c..843c2b52 100644 --- a/parsers.h +++ b/parsers.h @@ -1,6 +1,6 @@ #ifndef PARSERS_H_INCLUDED #define PARSERS_H_INCLUDED -#define PARSERS_H_VERSION "$Id: parsers.h,v 1.10 2001/07/30 22:08:36 jongfoster Exp $" +#define PARSERS_H_VERSION "$Id: parsers.h,v 1.11 2001/07/31 14:46:53 oes Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.h,v $ @@ -43,6 +43,9 @@ * * Revisions : * $Log: parsers.h,v $ + * Revision 1.11 2001/07/31 14:46:53 oes + * Added prototype for connection_close_adder + * * Revision 1.10 2001/07/30 22:08:36 jongfoster * Tidying up #defines: * - All feature #defines are now of the form FEATURE_xxx @@ -115,32 +118,32 @@ extern char *sed(const struct parsers pats[], void (* const more_headers[])(stru extern void free_http_request(struct http_request *http); extern void parse_http_request(char *req, struct http_request *http, struct client_state *csp); -extern char *crumble(const struct parsers *v, char *s, struct client_state *csp); +extern char *crumble(const struct parsers *v, const char *s, struct client_state *csp); -extern char *client_referrer(const struct parsers *v, char *s, struct client_state *csp); -extern char *client_uagent(const struct parsers *v, char *s, struct client_state *csp); -extern char *client_ua(const struct parsers *v, char *s, struct client_state *csp); -extern char *client_from(const struct parsers *v, char *s, struct client_state *csp); -extern char *client_send_cookie(const struct parsers *v, char *s, struct client_state *csp); -extern char *client_x_forwarded(const struct parsers *v, char *s, struct client_state *csp); +extern char *client_referrer(const struct parsers *v, const char *s, struct client_state *csp); +extern char *client_uagent(const struct parsers *v, const char *s, struct client_state *csp); +extern char *client_ua(const struct parsers *v, const char *s, struct client_state *csp); +extern char *client_from(const struct parsers *v, const char *s, struct client_state *csp); +extern char *client_send_cookie(const struct parsers *v, const char *s, struct client_state *csp); +extern char *client_x_forwarded(const struct parsers *v, const char *s, struct client_state *csp); extern void client_cookie_adder(struct client_state *csp); extern void client_xtra_adder(struct client_state *csp); extern void connection_close_adder(struct client_state *csp); extern void client_x_forwarded_adder(struct client_state *csp); -extern char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp); +extern char *server_set_cookie(const struct parsers *v, const char *s, struct client_state *csp); -extern char *content_type(const struct parsers *v, char *s, struct client_state *csp); -extern char *content_length(const struct parsers *v, char *s, struct client_state *csp); +extern char *content_type(const struct parsers *v, const char *s, struct client_state *csp); +extern char *content_length(const struct parsers *v, const char *s, struct client_state *csp); #ifdef FEATURE_FORCE_LOAD -char *client_host(const struct parsers *v, char *s, struct client_state *csp); +char *client_host(const struct parsers *v, const char *s, struct client_state *csp); int strclean(const char *string, const char *substring); #endif /* def FEATURE_FORCE_LOAD */ #if defined(FEATURE_IMAGE_DETECT_MSIE) -extern char *client_accept(const struct parsers *v, char *s, struct client_state *csp); +extern char *client_accept(const struct parsers *v, const char *s, struct client_state *csp); #endif /* defined(FEATURE_IMAGE_DETECT_MSIE) */ /* Revision control strings from this header and associated .c file */ diff --git a/project.h b/project.h index bd89848e..e0f526e1 100644 --- a/project.h +++ b/project.h @@ -1,6 +1,6 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED -#define PROJECT_H_VERSION "$Id: project.h,v 1.26 2001/07/30 22:08:36 jongfoster Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.27 2001/08/05 16:06:20 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -36,6 +36,13 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.27 2001/08/05 16:06:20 jongfoster + * Modifiying "struct map" so that there are now separate header and + * "map_entry" structures. This means that functions which modify a + * map no longer need to return a pointer to the modified map. + * Also, it no longer reverses the order of the entries (which may be + * important with some advanced template substitutions). + * * Revision 1.26 2001/07/30 22:08:36 jongfoster * Tidying up #defines: * - All feature #defines are now of the form FEATURE_xxx @@ -604,7 +611,7 @@ struct parsers { char *str; char len; - char *(*parser)(const struct parsers *, char *, struct client_state *); + char *(*parser)(const struct parsers *, const char *, struct client_state *); }; struct cgi_dispatcher -- 2.39.2