/*
* Collapse multiple cookies on one line
*/
-int req_gets(int sock, char *buf, char *hold, size_t hlen)
+int req_gets(int *sock, char *buf, char *hold, size_t hlen)
{
int a, b;
* transaction.
* \param sock the socket we will put our answer to
*/
-void context_loop(int sock)
+void context_loop(int *sock)
{
struct httprequest *req = NULL;
struct httprequest *last = NULL;
TheSession->urlstrings = NewHash(1,NULL);
TheSession->vars = NewHash(1,NULL);
- TheSession->http_sock = sock;
+ TheSession->http_sock = *sock;
TheSession->lastreq = time(NULL); /* log */
TheSession->gzip_ok = gzip_ok;
#ifdef ENABLE_NLS
body_start = strlen(content);
/** Read the entire input data at once. */
- client_read(WCC->http_sock, &content[body_start], ContentLength);
+ client_read(&WCC->http_sock, &content[body_start], ContentLength);
if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
StrBuf *Content;
output_headers(1, 1, 1, 0, 0, 0);
wprintf("Session: %d<hr />\n", WC->wc_session);
wprintf("Command: <br /><PRE>\n");
- escputs(WC->UrlFragment1);
+ StrEscPuts(WC->UrlFragment1);
wprintf("<br />\n");
- escputs(WC->UrlFragment2);
+ StrEscPuts(WC->UrlFragment2);
wprintf("</PRE><hr />\n");
wprintf("Variables: <br /><PRE>\n");
dump_vars();
int follow_xff = 0; /* Follow X-Forwarded-For: header */
int home_specified = 0; /* did the user specify a homedir? */
int time_to_die = 0; /* Nonzero if server is shutting down */
-extern void *context_loop(int);
+extern void *context_loop(int*);
extern void *housekeeping_loop(void);
extern pthread_mutex_t SessionListMutex;
extern pthread_key_t MyConKey;
* 0 Request timed out.
* -1 Connection is broken, or other error.
*/
-int client_read_to(int sock, char *buf, int bytes, int timeout)
+int client_read_to(int *sock, char *buf, int bytes, int timeout)
{
int len, rlen;
fd_set rfds;
#endif
len = 0;
- while (len < bytes) {
+ while ((len < bytes) && (*sock > 0)) {
FD_ZERO(&rfds);
- FD_SET(sock, &rfds);
+ FD_SET(*sock, &rfds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
- retval = select((sock) + 1, &rfds, NULL, NULL, &tv);
- if (FD_ISSET(sock, &rfds) == 0) {
+ retval = select((*sock) + 1, &rfds, NULL, NULL, &tv);
+ if (FD_ISSET(*sock, &rfds) == 0) {
return (0);
}
- rlen = read(sock, &buf[len], bytes - len);
+ rlen = read(*sock, &buf[len], bytes - len);
if (rlen < 1) {
lprintf(2, "client_read() failed: %s\n",
strerror(errno));
+ if (*sock > 0)
+ close(*sock);
+ *sock = -1;
return (-1);
}
len = len + rlen;
* \param buf the buffer to write to
* \param bytes Number of bytes to read
*/
-int client_read(int sock, char *buf, int bytes)
+int client_read(int *sock, char *buf, int bytes)
{
return (client_read_to(sock, buf, bytes, SLEEPING));
}
* \param bufsiz how many bytes to read
* \return number of bytes read???
*/
-int client_getln(int sock, char *buf, int bufsiz)
+int client_getln(int *sock, char *buf, int bufsiz)
{
int i, retval;
/* Read one character at a time.*/
- for (i = 0;; i++) {
+ for (i = 0; *sock > 0; i++) {
retval = client_read(sock, &buf[i], 1);
+ if (retval < 0)
+ return retval;
if (retval != 1 || buf[i] == '\n' || i == (bufsiz-1))
break;
if ( (!isspace(buf[i])) && (!isprint(buf[i])) ) {
if (fail_this_transaction == 0) {
/* Perform an HTTP transaction... */
- context_loop(ssock);
+ context_loop(&ssock);
/* Shut down SSL/TLS if required... */
#ifdef HAVE_OPENSSL
#endif
/* ...and close the socket. */
- lingering_close(ssock);
+ if (ssock > 0)
+ lingering_close(ssock);
}
}
extern int ndirs;
extern char socket_dir[PATH_MAX];
-int client_getln(int sock, char *buf, int bufsiz);
-int client_read(int sock, char *buf, int bytes);
-int client_read_to(int sock, char *buf, int bytes, int timeout);
+int client_getln(int *sock, char *buf, int bufsiz);
+int client_read(int *sock, char *buf, int bytes);
+int client_read_to(int *sock, char *buf, int bytes, int timeout);
int lprintf(int loglevel, const char *format, ...);
void wc_backtrace(void);