From 0fbf932baece16fa5f32b3d5a46771d116d6ea27 Mon Sep 17 00:00:00 2001 From: oes Date: Thu, 7 Mar 2002 03:46:53 +0000 Subject: [PATCH] Fixed compiler warnings etc --- encode.c | 13 +++++++---- killpopup.c | 65 ++++++++++++++++++++++++++++------------------------- miscutil.c | 25 ++++++++++++--------- parsers.c | 23 ++++++++++--------- 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/encode.c b/encode.c index bf300169..01457a7a 100644 --- a/encode.c +++ b/encode.c @@ -1,4 +1,4 @@ -const char encode_rcs[] = "$Id: encode.c,v 1.3 2001/11/13 00:16:40 jongfoster Exp $"; +const char encode_rcs[] = "$Id: encode.c,v 1.4 2002/01/22 23:28:07 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/encode.c,v $ @@ -33,6 +33,11 @@ const char encode_rcs[] = "$Id: encode.c,v 1.3 2001/11/13 00:16:40 jongfoster Ex * * Revisions : * $Log: encode.c,v $ + * Revision 1.4 2002/01/22 23:28:07 jongfoster + * Adding convenience function html_encode_and_free_original() + * Making all functions accept NULL paramaters - in this case, they + * simply return NULL. This allows error-checking to be deferred. + * * Revision 1.3 2001/11/13 00:16:40 jongfoster * Replacing references to malloc.h with the standard stdlib.h * (See ANSI or K&R 2nd Ed) @@ -354,7 +359,7 @@ char * url_encode(const char *s) * Returns : The integer value, or -1 for non-hex characters. * *********************************************************************/ -static int xdtoi(char d) +static int xdtoi(const int d) { if ((d >= '0') && (d <= '9')) { @@ -392,10 +397,10 @@ static int xtoi(const char *s) { int d1, d2; - d1 = xdtoi(*s++); + d1 = xdtoi(*s); if(d1 >= 0) { - d2 = xdtoi(*s); + d2 = xdtoi(*(s+1)); if(d2 >= 0) { return (d1 << 4) + d2; diff --git a/killpopup.c b/killpopup.c index 4b1ceb05..92b646e4 100644 --- a/killpopup.c +++ b/killpopup.c @@ -1,4 +1,4 @@ -const char killpopup_rcs[] = "$Id: killpopup.c,v 1.12 2001/10/25 03:40:48 david__schmidt Exp $"; +const char killpopup_rcs[] = "$Id: killpopup.c,v 1.13 2001/11/13 00:16:40 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/killpopup.c,v $ @@ -32,6 +32,10 @@ const char killpopup_rcs[] = "$Id: killpopup.c,v 1.12 2001/10/25 03:40:48 david_ * * Revisions : * $Log: killpopup.c,v $ + * Revision 1.13 2001/11/13 00:16:40 jongfoster + * Replacing references to malloc.h with the standard stdlib.h + * (See ANSI or K&R 2nd Ed) + * * Revision 1.12 2001/10/25 03:40:48 david__schmidt * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple * threads to call select() simultaneously. So, it's time to do a real, live, @@ -133,59 +137,60 @@ const char killpopup_h_rcs[] = KILLPOPUP_H_VERSION; *********************************************************************/ void filter_popups(char *buff, struct client_state *csp) { - char *popup = NULL; - char *close = NULL; + char *start_p = NULL; + char *close_p = NULL; char *p = NULL; - while ((popup = strstr( buff, "window.open(" )) != NULL) + /* + * replace the window.open( with a harmless JavaScript replacement + * (notice the two single quotes) + */ + while ((start_p = strstr(buff, "window.open(")) != NULL) { - if ( popup ) + if (start_p) { - /* - * replace the window.open( with a harmless JavaScript replacement (notice the two single quotes) - * Guy's idea (thanks) - */ - strncpy(popup, "1;''.concat(", 12); + strncpy(start_p, "1;''.concat(", 12); log_error(LOG_LEVEL_POPUPS, "Blocked popup window open"); csp->flags |= CSP_FLAG_MODIFIED; } } - while ((popup = strstr( buff, ".resizeTo(" )) != NULL) + /* + * replace the .resizeTo( with a harmless JavaScript replacement + */ + while ((start_p = strstr(buff, ".resizeTo(")) != NULL) { - if ( popup ) + if (start_p) { - /* - * replace the .resizeTo( with a harmless JavaScript replacement - * Guy's idea (thanks) - */ - strncpy(popup, ".scrollTo(", 10); + strncpy(start_p, ".scrollTo(", 10); log_error(LOG_LEVEL_POPUPS, "Blocked popup window resize"); csp->flags |= CSP_FLAG_MODIFIED; } } - /* Filter onUnload and onExit */ - popup=strstr( buff, "'); - if (close) + close_p = strchr(start_p, '>'); + if (close_p) { - /* we are now between FIXME: No, we're anywhere! --oes */ - p=strstr(popup, "onUnload"); + /* we are now between */ + p = strstr(start_p, "onUnload"); if (p) { - strncpy(p,"_nU_",4); + strncpy(p, "_nU_", 4); csp->flags |= CSP_FLAG_MODIFIED; } - p=strstr(popup, "onExit"); + p = strstr(start_p, "onExit"); if (p) { - strncpy(p,"_nE_",4); + strncpy(p, "_nE_", 4); csp->flags |= CSP_FLAG_MODIFIED; } } diff --git a/miscutil.c b/miscutil.c index 74b894b7..f79083ef 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.31 2002/03/05 04:52:42 oes Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.32 2002/03/06 23:02:57 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -36,6 +36,9 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.31 2002/03/05 04:52:42 oes Exp * * Revisions : * $Log: miscutil.c,v $ + * Revision 1.32 2002/03/06 23:02:57 jongfoster + * Removing tabs + * * Revision 1.31 2002/03/05 04:52:42 oes * Deleted non-errlog debugging code * @@ -217,7 +220,7 @@ const char miscutil_h_rcs[] = MISCUTIL_H_VERSION; * Returns : Pointer to newly malloc'd memory chunk. * *********************************************************************/ -void *zalloc(int size) +void *zalloc(size_t size) { void * ret; @@ -500,10 +503,10 @@ char *chomp(char *string) *********************************************************************/ char *strsav(char *old, const char *text_to_append) { - int old_len, new_len = 0; + size_t old_len, new_len = 0; char *p; - if (( text_to_append == NULL) || (*text_to_append == '\0')) + if ((text_to_append == NULL) || (*text_to_append == '\0')) { return(old); } @@ -512,7 +515,7 @@ char *strsav(char *old, const char *text_to_append) { if ((p = strdup(text_to_append)) == NULL) { - log_error(LOG_LEVEL_FATAL, "strdup() failed!", new_len); + log_error(LOG_LEVEL_FATAL, "strdup() failed!"); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } return p; @@ -794,25 +797,25 @@ int simplematch(char *pattern, char *text) * * Parameters : * 1 : string = string to be duplicated - * 2 : n = number of bytes to duplicate + * 2 : len = number of bytes to duplicate * * Returns : pointer to copy, or NULL if failiure * *********************************************************************/ -char *bindup(const char *string, int n) +char *bindup(const char *string, size_t len) { - char *dup; + char *duplicate; - if (NULL == (dup = (char *)malloc(n))) + if (NULL == (duplicate = (char *)malloc(len))) { return NULL; } else { - memcpy(dup, string, n); + memcpy(duplicate, string, len); } - return dup; + return duplicate; } diff --git a/parsers.c b/parsers.c index b2bd462e..bb5b31d6 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.46 2002/01/17 21:03:47 jongfoster Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.47 2002/02/20 23:15:13 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -40,6 +40,10 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.46 2002/01/17 21:03:47 jongfoster * * Revisions : * $Log: parsers.c,v $ + * Revision 1.47 2002/02/20 23:15:13 jongfoster + * Parsing functions now handle out-of-memory gracefully by returning + * an error code. + * * Revision 1.46 2002/01/17 21:03:47 jongfoster * Moving all our URL and URL pattern parsing code to urlmatch.c. * @@ -438,19 +442,19 @@ const add_header_func_ptr add_server_headers[] = { * file, the results are not portable. * *********************************************************************/ -int flush_socket(int fd, struct client_state *csp) +size_t flush_socket(int fd, struct client_state *csp) { struct iob *iob = csp->iob; - int n = iob->eod - iob->cur; + size_t len = iob->eod - iob->cur; - if (n <= 0) + if (len <= 0) { return(0); } - n = write_socket(fd, iob->cur, n); + len = write_socket(fd, iob->cur, len); iob->eod = iob->cur = iob->buf; - return(n); + return(len); } @@ -469,10 +473,10 @@ int flush_socket(int fd, struct client_state *csp) * Returns : Number of bytes in the content buffer. * *********************************************************************/ -int add_to_iob(struct client_state *csp, char *buf, int n) +size_t add_to_iob(struct client_state *csp, char *buf, size_t n) { struct iob *iob = csp->iob; - int have, need; + size_t have, need; char *p; have = iob->eod - iob->cur; @@ -486,8 +490,7 @@ int add_to_iob(struct client_state *csp, char *buf, int n) if ((p = (char *)malloc(need + 1)) == NULL) { - log_error(LOG_LEVEL_ERROR, "malloc() iob failed: %E"); - return(-1); + log_error(LOG_LEVEL_FATAL, "malloc() iob failed: %E"); } if (have) -- 2.39.2