/*
- * $Id: ftp.cc,v 1.114 1997/06/01 18:19:52 wessels Exp $
+ * $Id: ftp.cc,v 1.115 1997/06/02 01:06:11 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
StoreEntry *e = ftpState->entry;
len += ftpState->data.offset;
end = buf + len - 1;
- debug(0, 0, "buf=\n%s|\n", buf);
while (*end != '\r' && *end != '\n' && end > buf)
end--;
usable = end - buf;
if (usable == 0) {
- debug(0, 0, "ftpParseListing: didn't find end\n");
+ debug(9, 1, "ftpParseListing: didn't find end for %s\n", e->url);
return;
}
line = get_free_4k_page();
if (linelen > 4096)
linelen = 4096;
xstrncpy(line, s, linelen);
- debug(0, 0, "%s\n", line);
+ debug(9, 7, "%s\n", line);
if (!strncmp(line, "total", 5))
continue;
t = ftpHtmlifyListEntry(line, ftpState->flags);
request_t *request = ftpState->request;
StoreEntry *entry = ftpState->entry;
EBIT_RESET(ftpState->flags, FTP_IP_LOOKUP_PENDING);
- debug(0, 0, "ftpConnect\n");
assert(fd == ftpState->ctrl.fd);
if (ia == NULL) {
debug(9, 4, "ftpConnect: Unknown host: %s\n", request->host);
comm_close(fd);
return;
}
- debug(0, 0, "ftpConnect: %s is %s\n", request->host,
+ debug(9, 3, "ftpConnect: %s is %s\n", request->host,
inet_ntoa(ia->in_addrs[0]));
- debug(0, 0, "ftpConnect: port %d\n", (int) request->port);
/* Open connection. */
commSetTimeout(fd, Config.Timeout.connect, ftpTimeout, ftpState);
commConnectStart(ftpState->ctrl.fd,
ftpConnectDone(int fd, int status, void *data)
{
FtpStateData *ftpState = data;
- debug(0, 0, "ftpConnectDone\n");
+ debug(9, 3, "ftpConnectDone\n");
if (status == COMM_ERROR) {
squid_error_entry(ftpState->entry, ERR_CONNECT_FAIL, xstrerror());
comm_close(fd);
static void
ftpWriteCommand(const char *buf, FtpStateData * ftpState)
{
- debug(0, 0, "ftpWriteCommand: %s\n", buf);
+ debug(9, 5, "ftpWriteCommand: %s\n", buf);
comm_write(ftpState->ctrl.fd,
xstrdup(buf),
strlen(buf),
{
FtpStateData *ftpState = data;
StoreEntry *entry = ftpState->entry;
- debug(0, 0, "ftpWriteCommandCallback: wrote %d bytes\n", size);
+ debug(9, 7, "ftpWriteCommandCallback: wrote %d bytes\n", size);
if (errflag) {
BIT_RESET(entry->flag, ENTRY_CACHABLE);
storeReleaseRequest(entry);
off_t offset;
size_t linelen;
int code = -1;
- debug(0, 0, "ftpParseControlReply\n");
+ debug(9, 5, "ftpParseControlReply\n");
if (*(buf + len - 1) != '\n')
return NULL;
for (s = buf; s - buf < len; s += strcspn(s, crlf), s += strspn(s, crlf)) {
list = xcalloc(1, sizeof(wordlist));
list->key = xmalloc(linelen - offset);
xstrncpy(list->key, s + offset, linelen - offset);
- debug(38, 0, "%p: %s\n", list->key, list->key);
+ debug(9, 7, "%p: %s\n", list->key, list->key);
*tail = list;
tail = &list->next;
}
char *oldbuf;
wordlist **W;
int len;
- debug(0, 0, "ftpReadControlReply\n");
+ debug(9, 5, "ftpReadControlReply\n");
assert(ftpState->ctrl.offset < ftpState->ctrl.size);
len = read(fd,
ftpState->ctrl.buf + ftpState->ctrl.offset,
return;
}
if (len == 0) {
- debug(38, 0, "Read 0 bytes from FTP control socket?\n");
+ debug(9, 1, "Read 0 bytes from FTP control socket?\n");
BIT_RESET(entry->flag, ENTRY_CACHABLE);
storeReleaseRequest(entry);
squid_error_entry(entry, ERR_READ_ERROR, xstrerror());
ftpState->ctrl.message = ftpParseControlReply(ftpState->ctrl.buf, len,
&ftpState->ctrl.replycode);
if (ftpState->ctrl.message == NULL) {
- debug(0, 0, "ftpReadControlReply: partial server reply\n");
+ debug(9, 5, "ftpReadControlReply: partial server reply\n");
if (len == ftpState->ctrl.size) {
oldbuf = ftpState->ctrl.buf;
ftpState->ctrl.buf = xcalloc(ftpState->ctrl.size << 1, 1);
ftpReadWelcome(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(0, 0, "ftpReadWelcome\n");
+ debug(9, 3, "ftpReadWelcome\n");
if (EBIT_TEST(ftpState->flags, FTP_PASV_ONLY))
ftpState->login_att++;
if (code == 220) {
ftpReadUser(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(0, 0, "ftpReadUser\n");
+ debug(9, 3, "ftpReadUser\n");
if (code == 230) {
ftpReadPass(ftpState);
} else if (code == 331) {
char *t;
char *filename;
char mode;
- debug(0, 0, "ftpReadPass\n");
+ debug(9, 3, "ftpReadPass\n");
if (code == 230) {
t = strrchr(ftpState->request->urlpath, '/');
filename = t ? t + 1 : ftpState->request->urlpath;
wordlist **T;
char *path;
char *d;
- debug(38, 1, "This is ftpReadType\n");
+ debug(9, 3, "This is ftpReadType\n");
if (code == 200) {
if (EBIT_TEST(ftpState->flags, FTP_ROOT_DIR)) {
ftpSendPasv(ftpState);
ftpSendCwd(FtpStateData * ftpState)
{
wordlist *w;
- debug(0, 0, "ftpSendCwd\n");
+ debug(9, 3, "ftpSendCwd\n");
if ((w = ftpState->pathcomps) == NULL) {
- debug(0, 0, "the final component was a directory\n");
+ debug(9, 3, "the final component was a directory\n");
EBIT_SET(ftpState->flags, FTP_ISDIR);
if (!EBIT_TEST(ftpState->flags, FTP_ROOT_DIR))
strcat(ftpState->title_url, "/");
int code = ftpState->ctrl.replycode;
size_t len = 0;
wordlist *w;
- debug(38, 1, "This is ftpReadCwd\n");
+ debug(9, 3, "This is ftpReadCwd\n");
w = ftpState->pathcomps;
assert(w != NULL);
if (code >= 200 && code < 300) {
ftpReadMdtm(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadMdtm\n");
+ debug(9, 3, "This is ftpReadMdtm\n");
if (code == 213) {
ftpState->mdtm = parse_iso3307_time(ftpState->ctrl.last_message);
assert(ftpState->filepath != NULL);
ftpReadSize(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadSize\n");
+ debug(9, 3, "This is ftpReadSize\n");
if (code == 213) {
ftpState->size = atoi(ftpState->ctrl.last_message);
ftpSendPasv(ftpState);
int fd = ftpState->data.fd;
char *buf = ftpState->ctrl.last_message;
LOCAL_ARRAY(char, junk, 1024);
- debug(38, 1, "This is ftpReadPasv\n");
+ debug(9, 3, "This is ftpReadPasv\n");
if (code != 227) {
- debug(38, 0, "PASV not supported by remote end\n");
+ debug(9, 3, "PASV not supported by remote end\n");
ftpSendPort(ftpState);
return;
}
if (strlen(buf) > 1024) {
- debug(38, 0, "Avoiding potential buffer overflow\n");
+ debug(9, 1, "Avoiding potential buffer overflow\n");
ftpSendPort(ftpState);
return;
}
/* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
/* ANSI sez [^0-9] is undefined, it breaks on Watcom cc */
- debug(0, 0, "scanning: %s\n", buf);
+ debug(9, 5, "scanning: %s\n", buf);
n = sscanf(buf, "%[^0123456789]%d,%d,%d,%d,%d,%d",
junk, &h1, &h2, &h3, &h4, &p1, &p2);
if (n != 7 || p1 < 0 || p2 < 0 || p1 > 255 || p2 > 255) {
- debug(38, 0, "Bad 227 reply\n");
- debug(38, 0, "n=%d, p1=%d, p2=%d\n", n, p1, p2);
+ debug(9, 3, "Bad 227 reply\n");
+ debug(9, 3, "n=%d, p1=%d, p2=%d\n", n, p1, p2);
ftpSendPort(ftpState);
return;
}
sprintf(junk, "%d.%d.%d.%d", h1, h2, h3, h4);
if (!safe_inet_addr(junk, NULL)) {
- debug(38, 0, "unsafe address (%s)\n", junk);
+ debug(9, 1, "unsafe address (%s)\n", junk);
ftpSendPort(ftpState);
return;
}
port = ((p1 << 8) + p2);
- debug(0, 0, "ftpReadPasv: connecting to %s, port %d\n", junk, port);
+ debug(9, 5, "ftpReadPasv: connecting to %s, port %d\n", junk, port);
commConnectStart(fd, junk, port, ftpPasvCallback, ftpState);
}
ftpPasvCallback(int fd, int status, void *data)
{
FtpStateData *ftpState = data;
- debug(0, 0, "ftpPasvCallback\n");
+ debug(9, 3, "ftpPasvCallback\n");
if (status == COMM_ERROR) {
squid_error_entry(ftpState->entry, ERR_CONNECT_FAIL, xstrerror());
comm_close(fd);
static void
ftpSendPort(FtpStateData * ftpState)
{
- debug(38, 1, "This is ftpSendPort\n");
+ debug(9, 3, "This is ftpSendPort\n");
EBIT_RESET(ftpState->flags, FTP_PASV_SUPPORTED);
}
static void
ftpReadPort(FtpStateData * ftpState)
{
- debug(38, 1, "This is ftpReadPort\n");
+ debug(9, 3, "This is ftpReadPort\n");
}
static void
ftpRestOrList(FtpStateData * ftpState)
{
- debug(38, 1, "This is ftpRestOrList\n");
+ debug(9, 3, "This is ftpRestOrList\n");
if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) {
sprintf(cbuf, "LIST\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpReadRest(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadRest\n");
+ debug(9, 3, "This is ftpReadRest\n");
assert(ftpState->restart_offset > 0);
if (code == 350) {
assert(ftpState->filepath != NULL);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_RETR;
} else if (code > 0) {
- debug(0, 0, "ftpReadRest: REST not supported\n");
+ debug(9, 3, "ftpReadRest: REST not supported\n");
EBIT_RESET(ftpState->flags, FTP_REST_SUPPORTED);
} else {
ftpFail(ftpState);
ftpReadList(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadList\n");
+ debug(9, 3, "This is ftpReadList\n");
if (code == 150 || code == 125) {
ftpAppendSuccessHeader(ftpState);
commSetSelect(ftpState->data.fd,
ftpReadRetr(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadRetr\n");
+ debug(9, 3, "This is ftpReadRetr\n");
if (code >= 100 && code < 200) {
- debug(0, 0, "reading data channel\n");
+ debug(9, 3, "reading data channel\n");
ftpAppendSuccessHeader(ftpState);
commSetSelect(ftpState->data.fd,
COMM_SELECT_READ,
ftpReadTransferDone(FtpStateData * ftpState)
{
int code = ftpState->ctrl.replycode;
- debug(38, 1, "This is ftpReadTransferDone\n");
+ debug(9, 3, "This is ftpReadTransferDone\n");
if (code != 226) {
- debug(38, 1, "Got code %d after reading data, releasing entry\n");
+ debug(9, 1, "Got code %d after reading data, releasing entry\n");
storeReleaseRequest(ftpState->entry);
}
}
static void
ftpDataTransferDone(FtpStateData * ftpState)
{
- debug(38, 1, "This is ftpDataTransferDone\n");
+ debug(9, 3, "This is ftpDataTransferDone\n");
assert(ftpState->data.fd >= 0);
comm_close(ftpState->data.fd);
ftpState->data.fd = -1;
static void
ftpFail(FtpStateData * ftpState)
{
- debug(0, 0, "ftpFail\n");
+ debug(9, 3, "ftpFail\n");
comm_close(ftpState->ctrl.fd);
}
/*
- * $Id: store.cc,v 1.247 1997/06/01 23:21:50 wessels Exp $
+ * $Id: store.cc,v 1.248 1997/06/02 01:06:17 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
int linecount; /* # lines parsed from cache logfile */
int clashcount; /* # swapfile clashes avoided */
int dupcount; /* # duplicates purged */
+ int need_to_validate;
time_t start;
time_t stop;
char *line_in;
static int scan_revolutions;
static struct _bucketOrder *MaintBucketsOrder = NULL;
-/* Dirty/Clean rebuild status parameter */
-static int store_validating = 0;
-
static MemObject *
new_MemObject(void)
{
if (e->lock_count)
return (int) e->lock_count;
if (e->store_status == STORE_PENDING) {
- if (BIT_TEST(e->flag, ENTRY_DISPATCHED)) {
- debug_trap("storeUnlockObject: PENDING and DISPATCHED with 0 locks");
- debug(20, 1, " --> Key '%s'\n", e->key);
- e->store_status = STORE_ABORTED;
- } else {
- BIT_SET(e->flag, RELEASE_REQUEST);
- }
+ assert(!BIT_TEST(e->flag, ENTRY_DISPATCHED));
+ BIT_SET(e->flag, RELEASE_REQUEST);
}
if (storePendingNClients(e) > 0)
debug_trap("storeUnlockObject: unlocked entry with pending clients\n");
* newer entry. */
debug(20, 1, "WARNING: newer swaplog entry for fileno %08X\n",
sfileno);
+ assert(newer == 0);
/* I'm tempted to remove the swapfile here just to be safe,
* but there is a bad race condition in the NOVM version if
* the swapfile has recently been opened for writing, but
if (++bucketnum >= store_buckets) {
debug(20, 1, " Completed Validation Procedure\n");
debug(20, 1, " Validated %d Entries\n", validnum);
- store_validating = 0;
+ store_rebuilding = 0;
return;
}
link_ptr = hash_get_bucket(store_table, bucketnum);
eventAdd("storeCleanup", storeCleanup, NULL, 0);
return;
}
- if ((validnum % 4096) == 0)
- debug(20, 1, " %7d Entries Validated so far.\n", validnum);
if (!BIT_TEST(e->flag, ENTRY_VALIDATED)) {
storeValidate(e, storeCleanupComplete, e);
- validnum++;
+ if ((++validnum & 0xFFF) == 0)
+ debug(20, 1, " %7d Entries Validated so far.\n", validnum);
}
xfree(curr->key);
xfree(curr);
debug(20, 1, " Took %d seconds (%6.1lf objects/sec).\n",
r > 0 ? r : 0, (double) data->objcount / (r > 0 ? r : 1));
debug(20, 1, " store_swap_size = %dk\n", store_swap_size);
- store_rebuilding = 0;
- safe_free(data->line_in);
- safe_free(data);
- if (store_validating) {
+ if (data->need_to_validate) {
debug(20, 1, "Beginning Validation Procedure\n");
eventAdd("storeCleanup", storeCleanup, NULL, 0);
+ } else {
+ store_rebuilding = 0;
}
+ safe_free(data->line_in);
+ safe_free(data);
}
static void
d->next = RB->rebuild_dir;
RB->rebuild_dir = d;
if (!clean)
- store_validating = 1;
+ RB->need_to_validate = 1;
debug(20, 1, "Rebuilding storage in Cache Dir #%d (%s)\n",
i, clean ? "CLEAN" : "DIRTY");
}
static int recurse_detect = 0;
assert(seen_offset <= mem->e_current_len);
assert(copy_offset >= mem->e_lowest_offset);
- assert(recurse_detect == 0);
+ assert(recurse_detect < 3); /* could == 1 for IMS not modified's */
if ((ci = storeClientListSearch(mem, data)) < 0)
fatal_dump("storeClientCopy: Unregistered client");
sc = &mem->clients[ci];
return;
}
sz = memCopy(mem->data, copy_offset, buf, size);
- recurse_detect = 1;
+ recurse_detect++;
callback(data, buf, sz);
- recurse_detect = 0;
+ recurse_detect--;
/* see if we can get rid of some data if we are in "delete behind" mode . */
if (BIT_TEST(e->flag, DELETE_BEHIND))
storeDeleteBehind(e);
}
debug(51, rm_obj ? 2 : 9, "Removed %d of %d objects from bucket %d\n",
rm_obj, scan_obj, (int) b->bucket);
- /* Don't remove stuff if we're still validating - we could remove good
- * stuff when we don't want to */
- if (store_validating)
- return;
/* Scan row of hash table each second and free storage if we're
* over the high-water mark */
storeGetSwapSpace(0);
r > 0 ? r : 0, (double) n / (r > 0 ? r : 1));
/* touch a timestamp file if we're not still validating */
for (dirn = 0; dirn < ncache_dirs; dirn++) {
- if (!store_validating)
+ if (!store_rebuilding)
file_close(file_open(cln[dirn],
O_WRONLY | O_CREAT | O_TRUNC, NULL, NULL));
safe_free(cur[dirn]);