-const char jcc_rcs[] = "$Id: jcc.c,v 1.77 2002/03/07 03:52:06 oes Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.80 2002/03/11 22:07:05 david__schmidt Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.80 2002/03/11 22:07:05 david__schmidt
+ * OS/2 port maintenance:
+ * - Fixed EMX build - it had decayed a little
+ * - Fixed inexplicable crash during FD_ZERO - must be due to a bad macro.
+ * substituted a memset for now.
+ *
+ * Revision 1.79 2002/03/09 20:03:52 jongfoster
+ * - Making various functions return int rather than size_t.
+ * (Undoing a recent change). Since size_t is unsigned on
+ * Windows, functions like read_socket that return -1 on
+ * error cannot return a size_t.
+ *
+ * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
+ * crashes, and also frequently caused JB to jump to 100%
+ * CPU and stay there. (Because it thought it had just
+ * read ((unsigned)-1) == 4Gb of data...)
+ *
+ * - The signature of write_socket has changed, it now simply
+ * returns success=0/failure=nonzero.
+ *
+ * - Trying to get rid of a few warnings --with-debug on
+ * Windows, I've introduced a new type "jb_socket". This is
+ * used for the socket file descriptors. On Windows, this
+ * is SOCKET (a typedef for unsigned). Everywhere else, it's
+ * an int. The error value can't be -1 any more, so it's
+ * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
+ * Windows it maps to the #define INVALID_SOCKET.)
+ *
+ * - The signature of bind_port has changed.
+ *
+ * Revision 1.78 2002/03/08 21:35:04 oes
+ * Added optional group supplement to --user option. Will now use default group of user if no group given
+ *
* Revision 1.77 2002/03/07 03:52:06 oes
* - Fixed compiler warnings etc
* - Improved handling of failed DNS lookups
#define sleep(N) DosSleep(((N) * 100))
#endif
-#if defined(unix)
+#if defined(unix) || defined(__EMX__)
const char *basedir;
const char *pidfile = NULL;
int received_hup_signal = 0;
#define IS_ENABLED_AND IS_TOGGLED_ON_AND IS_NOT_FORCED_AND
char buf[BUFFER_SIZE];
- char *hdr, *p, *req;
+ char *hdr;
+ char *p;
+ char *req;
fd_set rfds;
- int n, maxfd, server_body;
+ int n;
+ jb_socket maxfd;
+ int server_body;
int ms_iis5_hack = 0;
int byte_count = 0;
const struct forward_spec * fwd;
struct http_request *http;
- size_t len; /* for buffer sizes */
+ int len; /* for buffer sizes */
#ifdef FEATURE_KILL_POPUPS
int block_popups; /* bool, 1==will block popups */
int block_popups_now = 0; /* bool, 1==currently blocking popups */
#endif /* def FEATURE_KILL_POPUPS */
pcrs_filter = (csp->rlist != NULL) && /* There are expressions to be used */
- ((csp->action->flags & ACTION_FILTER) != 0);
+ (!list_is_empty(csp->action->multi[ACTION_MULTI_FILTER]));
gif_deanimate = ((csp->action->flags & ACTION_DEANIMATE) != 0);
)
{
/* Write the answer to the client */
- if ((write_socket(csp->cfd, rsp->head, rsp->head_length) != rsp->head_length)
- || (write_socket(csp->cfd, rsp->body, rsp->content_length) != rsp->content_length))
+ if (write_socket(csp->cfd, rsp->head, rsp->head_length)
+ || write_socket(csp->cfd, rsp->body, rsp->content_length))
{
log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
}
csp->sfd = forwarded_connect(fwd, http, csp);
- if (csp->sfd < 0)
+ if (csp->sfd == JB_INVALID_SOCKET)
{
log_error(LOG_LEVEL_CONNECT, "connect to: %s failed: %E",
http->hostport);
/* Write the answer to the client */
if(rsp)
{
- if ((write_socket(csp->cfd, rsp->head, rsp->head_length) != rsp->head_length)
- || (write_socket(csp->cfd, rsp->body, rsp->content_length) != rsp->content_length))
+ if (write_socket(csp->cfd, rsp->head, rsp->head_length)
+ || write_socket(csp->cfd, rsp->body, rsp->content_length))
{
log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
}
* (along with anything else that may be in the buffer)
*/
- len = strlen(hdr);
-
- if ((write_socket(csp->sfd, hdr, len) != len)
- || (flush_socket(csp->sfd, csp ) < 0))
+ if (write_socket(csp->sfd, hdr, strlen(hdr))
+ || (flush_socket(csp->sfd, csp) < 0))
{
log_error(LOG_LEVEL_CONNECT, "write header to: %s failed: %E",
http->hostport);
if(rsp)
{
- if ((write_socket(csp->cfd, rsp->head, rsp->head_length) != rsp->head_length)
- || (write_socket(csp->cfd, rsp->body, rsp->content_length) != rsp->content_length))
+ if (write_socket(csp->cfd, rsp->head, rsp->head_length)
+ || write_socket(csp->cfd, rsp->body, rsp->content_length))
{
log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
}
log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 200 2\n",
csp->ip_addr_str, http->ocmd);
- if (write_socket(csp->cfd, CSUCCEED, sizeof(CSUCCEED)-1) < 0)
+ if (write_socket(csp->cfd, CSUCCEED, sizeof(CSUCCEED)-1))
{
freez(hdr);
return;
while (FOREVER)
{
+#ifdef __OS2__
+ /*
+ * FD_ZERO here seems to point to an errant macro which crashes.
+ * So do this by hand for now...
+ */
+ memset(&rfds,0x00,sizeof(fd_set));
+#else
FD_ZERO(&rfds);
-
+#endif
FD_SET(csp->cfd, &rfds);
FD_SET(csp->sfd, &rfds);
break; /* "game over, man" */
}
- if (write_socket(csp->sfd, buf, len) != len)
+ if (write_socket(csp->sfd, buf, len))
{
log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
return;
if(rsp)
{
- if ((write_socket(csp->cfd, rsp->head, rsp->head_length) != rsp->head_length)
- || (write_socket(csp->cfd, rsp->body, rsp->content_length) != rsp->content_length))
+ if (write_socket(csp->cfd, rsp->head, rsp->head_length)
+ || write_socket(csp->cfd, rsp->body, rsp->content_length))
{
log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
}
log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");
}
- len = strlen(hdr);
-
- if ((write_socket(csp->cfd, hdr, len) != len)
- || (write_socket(csp->cfd, p != NULL ? p : csp->iob->cur, csp->content_length) != (int)csp->content_length))
+ if (write_socket(csp->cfd, hdr, strlen(hdr))
+ || write_socket(csp->cfd, p != NULL ? p : csp->iob->cur, csp->content_length))
{
log_error(LOG_LEVEL_ERROR, "write modified content to client failed: %E");
return;
len = strlen(hdr);
byte_count += len;
- if (((write_socket(csp->cfd, hdr, len) != len)
- || (len = flush_socket(csp->cfd, csp) < 0)))
+ if (write_socket(csp->cfd, hdr, len)
+ || (len = flush_socket(csp->cfd, csp) < 0))
{
log_error(LOG_LEVEL_CONNECT, "write header to client failed: %E");
}
else
{
- if (write_socket(csp->cfd, buf, len) != len)
+ if (write_socket(csp->cfd, buf, len))
{
log_error(LOG_LEVEL_ERROR, "write to client failed: %E");
return;
log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");
}
- len = strlen(hdr);
-
- /* write the server's (modified) header to
- * the client (along with anything else that
- * may be in the buffer)
- */
-
#ifdef FEATURE_KILL_POPUPS
/* Start blocking popups if appropriate. */
content_filter = gif_deanimate_response;
}
-
/*
* Only write if we're not buffering for content modification
*/
- if (!content_filter && ((write_socket(csp->cfd, hdr, len) != len)
- || (len = flush_socket(csp->cfd, csp) < 0)))
+ if (!content_filter)
{
- log_error(LOG_LEVEL_CONNECT, "write header to client failed: %E");
-
- /* the write failed, so don't bother
- * mentioning it to the client...
- * it probably can't hear us anyway.
+ /* write the server's (modified) header to
+ * the client (along with anything else that
+ * may be in the buffer)
*/
- freez(hdr);
- return;
- }
- if(!content_filter) byte_count += len;
+ len = strlen(hdr);
+
+ if (write_socket(csp->cfd, hdr, len)
+ || (len = flush_socket(csp->cfd, csp) < 0))
+ {
+ log_error(LOG_LEVEL_CONNECT, "write header to client failed: %E");
+
+ /* the write failed, so don't bother
+ * mentioning it to the client...
+ * it probably can't hear us anyway.
+ */
+ freez(hdr);
+ return;
+ }
+
+ byte_count += len;
+ }
/* we're finished with the server's header */
chat(csp);
close_socket(csp->cfd);
- if (csp->sfd >= 0)
+ if (csp->sfd != JB_INVALID_SOCKET)
{
close_socket(csp->sfd);
}
* Returns : Port that was opened.
*
*********************************************************************/
-static int bind_port_helper(struct configuration_spec * config)
+static jb_socket bind_port_helper(struct configuration_spec * config)
{
- int bfd;
+ int result;
+ jb_socket bfd;
if ( (config->haddr != NULL)
&& (config->haddr[0] == '1')
config->hport, config->haddr);
}
- bfd = bind_port(config->haddr, config->hport);
+ result = bind_port(config->haddr, config->hport, &bfd);
- if (bfd < 0)
+ if (result < 0)
{
- switch(bfd)
+ switch(result)
{
case -3 :
log_error(LOG_LEVEL_FATAL, "can't bind to %s:%d: "
}
/* shouldn't get here */
- return -1;
+ return JB_INVALID_SOCKET;
}
config->need_bind = 0;
static void listen_loop(void)
{
struct client_state *csp = NULL;
- int bfd;
+ jb_socket bfd;
struct configuration_spec * config;
config = load_config();
}
csp->flags |= CSP_FLAG_ACTIVE;
- csp->sfd = -1;
+ csp->sfd = JB_INVALID_SOCKET;
csp->config = config = load_config();