-/* $Id: ftp.cc,v 1.36 1996/04/16 05:05:22 wessels Exp $ */
+/* $Id: ftp.cc,v 1.37 1996/04/17 18:06:24 wessels Exp $ */
/*
* DEBUG: Section 9 ftp: FTP
int reply_hdr_state;
} FtpData;
-static void ftpCloseAndFree(fd, data)
+static int ftpStateFree(fd, ftpState)
int fd;
- FtpData *data;
+ FtpData *ftpState;
{
- if (fd >= 0)
- comm_close(fd);
- if (data) {
- if (data->reply_hdr) {
- put_free_8k_page(data->reply_hdr);
- data->reply_hdr = NULL;
- }
- if (data->icp_page_ptr) {
- put_free_8k_page(data->icp_page_ptr);
- data->icp_page_ptr = NULL;
- }
- if (data->icp_rwd_ptr)
- safe_free(data->icp_rwd_ptr);
+ if (ftpState == NULL)
+ return 1;
+ if (ftpState->reply_hdr) {
+ put_free_8k_page(ftpState->reply_hdr);
+ ftpState->reply_hdr = NULL;
}
- xfree(data);
+ if (ftpState->icp_page_ptr) {
+ put_free_8k_page(ftpState->icp_page_ptr);
+ ftpState->icp_page_ptr = NULL;
+ }
+ if (ftpState->icp_rwd_ptr)
+ safe_free(ftpState->icp_rwd_ptr);
+ xfree(ftpState);
+ return 0;
}
int ftp_url_parser(url, data)
entry = data->entry;
debug(9, 4, "ftpLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
squid_error_entry(entry, ERR_LIFETIME_EXP, NULL);
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
}
} else {
/* we can terminate connection right now */
squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
return 0;
}
}
BIT_RESET(entry->flag, CACHABLE);
storeReleaseRequest(entry);
squid_error_entry(entry, ERR_READ_ERROR, xstrerror());
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
}
} else if (len == 0 && entry->mem_obj->e_current_len == 0) {
squid_error_entry(entry,
ERR_ZERO_SIZE_OBJECT,
errno ? xstrerror() : NULL);
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
} else if (len == 0) {
/* Connection closed; retrieval done. */
if (!data->got_marker) {
}
/* update fdstat and fdtable */
storeComplete(entry);
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
} else if (((entry->mem_obj->e_current_len + len) > getFtpMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
/* append the last bit of info we get */
storeAppend(entry, buf, len);
squid_error_entry(entry, ERR_CLIENT_ABORT, NULL);
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
} else {
/* check for a magic marker at the end of the read */
data->got_marker = 0;
if (errflag) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
return;
} else {
comm_set_select_handler(data->ftp_fd,
break; /* cool, we're connected */
default:
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- ftpCloseAndFree(fd, data);
+ comm_close(fd);
return;
}
/* Call the real write handler, now that we're fully connected */
}
/* Pipe/socket created ok */
+ /* register close handler */
+ comm_set_select_handler(data->ftp_fd,
+ COMM_SELECT_CLOSE,
+ ftpStateFree,
+ (void *) data);
+
/* Now connect ... */
if ((status = comm_connect(data->ftp_fd, "localhost", CACHE_FTP_PORT))) {
if (status != EINPROGRESS) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- ftpCloseAndFree(data->ftp_fd, data);
+ comm_close(data->ftp_fd);
return COMM_ERROR;
} else {
debug(9, 5, "ftpStart: FD %d: EINPROGRESS.\n", data->ftp_fd);
-/* $Id: gopher.cc,v 1.27 1996/04/16 16:35:27 wessels Exp $ */
+/* $Id: gopher.cc,v 1.28 1996/04/17 18:06:25 wessels Exp $ */
/*
* DEBUG: Section 10 gopher: GOPHER
char def_gopher_bin[] = "www/unknown";
char def_gopher_text[] = "text/plain";
-static void gopherCloseAndFree(fd, data)
+static int gopherStateFree(fd, gopherState)
int fd;
- GopherData *data;
+ GopherData *gopherState;
{
- if (fd > +0)
- comm_close(fd);
- put_free_4k_page(data->buf);
- xfree(data);
+ if (gopherState == NULL)
+ return 1;
+ put_free_4k_page(gopherState->buf);
+ xfree(gopherState);
+ return 0;
}
default:
cachable = 1;
}
- gopherCloseAndFree(-1, data);
+ gopherStateFree(-1, data);
return cachable;
}
put_free_4k_page(data->icp_page_ptr);
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
return 0;
}
COMM_SELECT_READ | COMM_SELECT_WRITE,
0,
0);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
}
} else {
/* we can terminate connection right now */
squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
return 0;
}
}
BIT_RESET(entry->flag, CACHABLE);
storeReleaseRequest(entry);
squid_error_entry(entry, ERR_READ_ERROR, xstrerror());
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
}
} else if (len == 0 && entry->mem_obj->e_current_len == 0) {
squid_error_entry(entry,
ERR_ZERO_SIZE_OBJECT,
errno ? xstrerror() : NULL);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
} else if (len == 0) {
/* Connection closed; retrieval done. */
/* flush the rest of data in temp buf if there is one. */
entry->expires = squid_curtime + ttlSet(entry);
BIT_RESET(entry->flag, DELAY_SENDING);
storeComplete(entry);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
} else if (((entry->mem_obj->e_current_len + len) > getGopherMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
if (data->conversion != NORMAL)
gopherEndHTML(data);
BIT_RESET(entry->flag, DELAY_SENDING);
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
} else {
if (data->conversion != NORMAL) {
gopherToHTML(data, buf, len);
fd, size, errflag);
if (errflag) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- gopherCloseAndFree(fd, data);
+ comm_close(fd);
if (buf)
put_free_4k_page(buf); /* Allocated by gopherSendRequest. */
return;
if (gopher_url_parser(url, data->host, &data->port,
&data->type_id, data->request)) {
squid_error_entry(entry, ERR_INVALID_URL, NULL);
- gopherCloseAndFree(-1, data);
+ gopherStateFree(-1, data);
return COMM_ERROR;
}
/* Create socket. */
if (sock == COMM_ERROR) {
debug(10, 4, "gopherStart: Failed because we're out of sockets.\n");
squid_error_entry(entry, ERR_NO_FDS, xstrerror());
- gopherCloseAndFree(-1, data);
+ gopherStateFree(-1, data);
return COMM_ERROR;
}
+ comm_set_select_handler(sock,
+ COMM_SELECT_CLOSE,
+ gopherStateFree,
+ (void *) data);
+
/* check if IP is already in cache. It must be.
* It should be done before this route is called.
* Otherwise, we cannot check return code for connect. */
if (!ipcache_gethostbyname(data->host)) {
debug(10, 4, "gopherStart: Called without IP entry in ipcache. OR lookup failed.\n");
squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
- gopherCloseAndFree(sock, data);
+ comm_close(sock);
return COMM_ERROR;
}
if (((data->type_id == GOPHER_INDEX) || (data->type_id == GOPHER_CSO))
}
gopherToHTML(data, (char *) NULL, 0);
storeComplete(entry);
- gopherCloseAndFree(sock, data);
+ comm_close(sock);
return COMM_OK;
}
/* Open connection. */
if ((status = comm_connect(sock, data->host, data->port)) != 0) {
if (status != EINPROGRESS) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- gopherCloseAndFree(sock, data);
+ comm_close(sock);
return COMM_ERROR;
} else {
debug(10, 5, "startGopher: conn %d EINPROGRESS\n", sock);
-/* $Id: wais.cc,v 1.27 1996/04/16 05:13:39 wessels Exp $ */
+/* $Id: wais.cc,v 1.28 1996/04/17 18:06:25 wessels Exp $ */
/*
* DEBUG: Section 24 wais
char request[MAX_URL];
} WAISData;
-static void waisCloseAndFree(fd, data)
+static int waisStateFree(fd, waisState)
int fd;
- WAISData *data;
+ WAISData *waisState;
{
- if (fd >= 0)
- comm_close(fd);
- xfree(data);
+ if (waisState == NULL)
+ return 1;
+ xfree(waisState);
+ return 0;
}
/* This will be called when timeout on read. */
debug(24, 4, "waisReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url);
squid_error_entry(entry, ERR_READ_TIMEOUT, NULL);
comm_set_select_handler(fd, COMM_SELECT_READ, 0, 0);
- waisCloseAndFree(fd, data);
+ comm_close(fd);
}
/* This will be called when socket lifetime is expired. */
debug(24, 4, "waisLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
squid_error_entry(entry, ERR_LIFETIME_EXP, NULL);
comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0);
- waisCloseAndFree(fd, data);
+ comm_close(fd);
}
} else {
/* we can terminate connection right now */
squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL);
- waisCloseAndFree(fd, data);
+ comm_close(fd);
return;
}
}
BIT_RESET(entry->flag, CACHABLE);
storeReleaseRequest(entry);
squid_error_entry(entry, ERR_READ_ERROR, xstrerror());
- waisCloseAndFree(fd, data);
+ comm_close(fd);
}
} else if (len == 0 && entry->mem_obj->e_current_len == 0) {
squid_error_entry(entry,
ERR_ZERO_SIZE_OBJECT,
errno ? xstrerror() : NULL);
- waisCloseAndFree(fd, data);
+ comm_close(fd);
} else if (len == 0) {
/* Connection closed; retrieval done. */
entry->expires = squid_curtime;
storeComplete(entry);
- waisCloseAndFree(fd, data);
+ comm_close(fd);
} else if (((entry->mem_obj->e_current_len + len) > getWAISMax()) &&
!(entry->flag & DELETE_BEHIND)) {
/* accept data, but start to delete behind it */
fd, size, errflag);
if (errflag) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- waisCloseAndFree(fd, data);
+ comm_close(fd);
} else {
/* Schedule read reply. */
comm_set_select_handler(fd,
RequestMethodStr[method], url);
debug(24, 4, " header: %s\n", mime_hdr);
- data = (WAISData *) xcalloc(1, sizeof(WAISData));
- data->entry = entry;
- data->method = method;
- data->relayhost = getWaisRelayHost();
- data->relayport = getWaisRelayPort();
- data->mime_hdr = mime_hdr;
-
if (!getWaisRelayHost()) {
debug(24, 0, "waisStart: Failed because no relay host defined!\n");
squid_error_entry(entry, ERR_NO_RELAY, NULL);
- safe_free(data);
return COMM_ERROR;
}
+
/* Create socket. */
sock = comm_open(COMM_NONBLOCKING, 0, 0, url);
if (sock == COMM_ERROR) {
debug(24, 4, "waisStart: Failed because we're out of sockets.\n");
squid_error_entry(entry, ERR_NO_FDS, xstrerror());
- safe_free(data);
return COMM_ERROR;
}
+
+ data = (WAISData *) xcalloc(1, sizeof(WAISData));
+ data->entry = entry;
+ data->method = method;
+ data->relayhost = getWaisRelayHost();
+ data->relayport = getWaisRelayPort();
+ data->mime_hdr = mime_hdr;
+ comm_set_select_handler(sock,
+ COMM_SELECT_CLOSE,
+ waisStateFree,
+ (void *) data);
+
/* check if IP is already in cache. It must be.
* It should be done before this route is called.
* Otherwise, we cannot check return code for connect. */
if (!ipcache_gethostbyname(data->relayhost)) {
debug(24, 4, "waisstart: Called without IP entry in ipcache. OR lookup failed.\n");
squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
- waisCloseAndFree(sock, data);
+ comm_close(sock);
return COMM_ERROR;
}
/* Open connection. */
if ((status = comm_connect(sock, data->relayhost, data->relayport))) {
if (status != EINPROGRESS) {
squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
- waisCloseAndFree(sock, data);
+ comm_close(sock);
return COMM_ERROR;
} else {
debug(24, 5, "waisStart: FD %d EINPROGRESS\n", sock);