-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 $
*
* 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)
* 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'))
{
{
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;
-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 $
*
* 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,
*********************************************************************/
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, "<body");
- if (!popup) popup=strstr( buff, "<BODY");
- if (!popup) popup=strstr( buff, "<Body");
- if (!popup) popup=strstr( buff, "<BOdy");
- if (popup)
+ /*
+ * Filter onUnload and onExit
+ */
+ start_p = strstr(buff, "<body");
+ if (!start_p) start_p = strstr(buff, "<BODY");
+ if (!start_p) start_p = strstr(buff, "<Body");
+ if (!start_p) start_p = strstr(buff, "<BOdy");
+ if (start_p)
{
- close=strchr(popup,'>');
- if (close)
+ close_p = strchr(start_p, '>');
+ if (close_p)
{
- /* we are now between <body and the ending > FIXME: No, we're anywhere! --oes */
- p=strstr(popup, "onUnload");
+ /* we are now between <body and the ending > */
+ 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;
}
}
-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 $
*
* 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
*
* Returns : Pointer to newly malloc'd memory chunk.
*
*********************************************************************/
-void *zalloc(int size)
+void *zalloc(size_t size)
{
void * ret;
*********************************************************************/
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);
}
{
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;
*
* 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;
}
-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 $
*
* 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.
*
* 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);
}
* 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;
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)