From b671cc68ba4466217767054c00a521478de6c403 Mon Sep 17 00:00:00 2001 From: hno <> Date: Thu, 16 Aug 2001 06:16:15 +0000 Subject: [PATCH] WIN32/Cygwin fixes by Guido - Better GetOSVersion function, more squid "aware", added support for Windows XP and future Windows versions. - Added trap in WIN32_Subsystem_Init() for unknown or unsupported (WIN32s) Windows version. - Fixed compile warning in comm.c - Changed exit() WIN32 hook, now less intrusive And some ident fixes --- helpers/basic_auth/LDAP/squid_ldap_auth.c | 116 ++++---- helpers/ntlm_auth/SMB/ntlm.h | 2 +- src/HttpReply.cc | 8 +- src/cache_cf.cc | 28 +- src/comm.cc | 5 +- src/defines.h | 4 +- src/disk.cc | 4 +- src/dns_internal.cc | 5 +- src/fs/coss/async_io.cc | 330 +++++++++++----------- src/fs/coss/async_io.h | 58 ++-- src/fs/coss/store_dir_coss.cc | 10 +- src/globals.h | 4 +- src/main.cc | 6 +- src/protos.h | 6 +- src/repl/lru/store_repl_lru.cc | 10 +- src/stat.cc | 4 +- src/store_dir.cc | 8 +- src/tools.cc | 7 +- src/win32.cc | 32 ++- 19 files changed, 330 insertions(+), 317 deletions(-) diff --git a/helpers/basic_auth/LDAP/squid_ldap_auth.c b/helpers/basic_auth/LDAP/squid_ldap_auth.c index b6e45035d4..7abb84e8ce 100644 --- a/helpers/basic_auth/LDAP/squid_ldap_auth.c +++ b/helpers/basic_auth/LDAP/squid_ldap_auth.c @@ -11,7 +11,7 @@ * National Research Council * * Usage: squid_ldap_auth -b basedn [-s searchscope] - * [-f searchfilter] [-D binddn -w bindpasswd] + * [-f searchfilter] [-D binddn -w bindpasswd] * [-u attr] [-p] [-R] * * Dependencies: You need to get the OpenLDAP libraries @@ -25,7 +25,7 @@ * Changes: * 2001-05-02: Henrik Nordstrom * - Support newer OpenLDAP 2.x libraries using the - * revised Internet Draft API which unfortunately + * revised Internet Draft API which unfortunately * is not backwards compatible with RFC1823.. * 2001-04-15: Henrik Nordstrom * - Added command line option for basedn @@ -64,31 +64,38 @@ static int checkLDAP(LDAP * ld, char *userid, char *password); /* Yuck.. we need to glue to different versions of the API */ #if defined(LDAP_API_VERSION) && LDAP_API_VERSION > 1823 -static int squid_ldap_errno(LDAP *ld) +static int +squid_ldap_errno(LDAP * ld) { int err = 0; ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &err); return err; } -static void squid_ldap_set_aliasderef(LDAP *ld, int deref) +static void +squid_ldap_set_aliasderef(LDAP * ld, int deref) { ldap_set_option(ld, LDAP_OPT_DEREF, &deref); } -static void squid_ldap_set_referrals(LDAP *ld, int referrals) +static void +squid_ldap_set_referrals(LDAP * ld, int referrals) { int *value = referrals ? LDAP_OPT_ON : LDAP_OPT_OFF; ldap_set_option(ld, LDAP_OPT_REFERRALS, value); } + #else -static int squid_ldap_errno(LDAP *ld) +static int +squid_ldap_errno(LDAP * ld) { return ld->ld_errno; } -static void squid_ldap_set_aliasderef(LDAP *ld, int deref) +static void +squid_ldap_set_aliasderef(LDAP * ld, int deref) { ld->ld_deref = deref; } -static void squid_ldap_set_referrals(LDAP *ld, int referrals) +static void +squid_ldap_set_referrals(LDAP * ld, int referrals) { if (referrals) ld->ld_options |= ~LDAP_OPT_REFERRALS; @@ -111,13 +118,13 @@ main(int argc, char **argv) while (argc > 2 && argv[1][0] == '-') { char *value = ""; char option = argv[1][1]; - switch(option) { + switch (option) { case 'p': case 'R': break; default: if (strlen(argv[1]) > 2) { - value = argv[1]+2; + value = argv[1] + 2; } else { value = argv[2]; argv++; @@ -127,57 +134,57 @@ main(int argc, char **argv) } argv++; argc--; - switch(option) { + switch (option) { case 'b': - basedn = value; - break; + basedn = value; + break; case 'f': - searchfilter = value; - break; + searchfilter = value; + break; case 'u': - userattr = value; - break; + userattr = value; + break; case 's': - if (strcmp(value, "base") == 0) - searchscope = LDAP_SCOPE_BASE; - else if (strcmp(value, "one") == 0) - searchscope = LDAP_SCOPE_ONELEVEL; - else if (strcmp(value, "sub") == 0) - searchscope = LDAP_SCOPE_SUBTREE; - else { - fprintf(stderr, "squid_ldap_auth: ERROR: Unknown search scope '%s'\n", value); - exit(1); - } - break; + if (strcmp(value, "base") == 0) + searchscope = LDAP_SCOPE_BASE; + else if (strcmp(value, "one") == 0) + searchscope = LDAP_SCOPE_ONELEVEL; + else if (strcmp(value, "sub") == 0) + searchscope = LDAP_SCOPE_SUBTREE; + else { + fprintf(stderr, "squid_ldap_auth: ERROR: Unknown search scope '%s'\n", value); + exit(1); + } + break; case 'a': - if (strcmp(value, "never") == 0) - aliasderef = LDAP_DEREF_NEVER; - else if (strcmp(value, "always") == 0) - aliasderef = LDAP_DEREF_ALWAYS; - else if (strcmp(value, "search") == 0) - aliasderef = LDAP_DEREF_SEARCHING; - else if (strcmp(value, "find") == 0) - aliasderef = LDAP_DEREF_FINDING; - else { - fprintf(stderr, "squid_ldap_auth: ERROR: Unknown alias dereference method '%s'\n", value); - exit(1); - } - break; + if (strcmp(value, "never") == 0) + aliasderef = LDAP_DEREF_NEVER; + else if (strcmp(value, "always") == 0) + aliasderef = LDAP_DEREF_ALWAYS; + else if (strcmp(value, "search") == 0) + aliasderef = LDAP_DEREF_SEARCHING; + else if (strcmp(value, "find") == 0) + aliasderef = LDAP_DEREF_FINDING; + else { + fprintf(stderr, "squid_ldap_auth: ERROR: Unknown alias dereference method '%s'\n", value); + exit(1); + } + break; case 'D': - binddn = value; - break; + binddn = value; + break; case 'w': - bindpasswd = value; - break; + bindpasswd = value; + break; case 'p': - persistent = !persistent; - break; + persistent = !persistent; + break; case 'R': - noreferrals = !noreferrals; - break; + noreferrals = !noreferrals; + break; default: - fprintf(stderr, "squid_ldap_auth: ERROR: Unknown command line option '%c'\n", option); - exit(1); + fprintf(stderr, "squid_ldap_auth: ERROR: Unknown command line option '%c'\n", option); + exit(1); } } @@ -212,7 +219,7 @@ main(int argc, char **argv) } *passwd++ = '\0'; /* Cut in username,password */ tryagain = 1; -recover: + recover: if (ld == NULL) { if ((ld = ldap_init(ldapServer, LDAP_PORT)) == NULL) { fprintf(stderr, "\nUnable to connect to LDAP server:%s port:%d\n", @@ -258,7 +265,8 @@ checkLDAP(LDAP * ld, char *userid, char *password) char filter[256]; LDAPMessage *res = NULL; LDAPMessage *entry; - char *searchattr[] = {NULL}; + char *searchattr[] = + {NULL}; char *userdn; int rc; @@ -300,6 +308,6 @@ checkLDAP(LDAP * ld, char *userid, char *password) if (ldap_simple_bind_s(ld, dn, password) != LDAP_SUCCESS) return 1; - + return 0; } diff --git a/helpers/ntlm_auth/SMB/ntlm.h b/helpers/ntlm_auth/SMB/ntlm.h index 6964367503..3230e579dd 100644 --- a/helpers/ntlm_auth/SMB/ntlm.h +++ b/helpers/ntlm_auth/SMB/ntlm.h @@ -57,7 +57,7 @@ static char *__foo; #define debug(X...) /* */ #endif /* DEBUG */ #else /* __GNUC__ */ -static void +static void debug(char *format,...) { } diff --git a/src/HttpReply.cc b/src/HttpReply.cc index bdfbafff47..b8e6405a9c 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.47 2001/07/28 09:21:31 hno Exp $ + * $Id: HttpReply.cc,v 1.48 2001/08/16 00:16:15 hno Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -469,7 +469,7 @@ httpReplyBodySize(method_t method, HttpReply * reply) * Calculates the maximum size allowed for an HTTP response */ void -httpReplyBodyBuildSize(request_t *request, HttpReply * reply, dlink_list *bodylist) +httpReplyBodyBuildSize(request_t * request, HttpReply * reply, dlink_list * bodylist) { body_size *bs; aclCheck_t *checklist; @@ -484,8 +484,8 @@ httpReplyBodyBuildSize(request_t *request, HttpReply * reply, dlink_list *bodyli /* Allow - use this entry */ reply->maxBodySize = bs->maxsize; bs = NULL; - debug (58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %d\n", reply->maxBodySize); + debug(58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %d\n", reply->maxBodySize); } - aclChecklistFree(checklist); + aclChecklistFree(checklist); } } diff --git a/src/cache_cf.cc b/src/cache_cf.cc index e379086db4..4f2ba2bb0a 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.387 2001/07/28 09:21:31 hno Exp $ + * $Id: cache_cf.cc,v 1.388 2001/08/16 00:16:15 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1870,15 +1870,15 @@ parse_b_size_t(size_t * var) parseBytesLine(var, B_BYTES_STR); } -CBDATA_TYPE (body_size); +CBDATA_TYPE(body_size); static void -parse_body_size_t(dlink_list *bodylist) +parse_body_size_t(dlink_list * bodylist) { body_size *bs; - CBDATA_INIT_TYPE (body_size); + CBDATA_INIT_TYPE(body_size); bs = cbdataAlloc(body_size); - parse_size_t (&bs->maxsize); + parse_size_t(&bs->maxsize); aclParseAccessLine(&bs->access_list); dlinkAddTail(bs, &bs->node, bodylist); @@ -1890,34 +1890,34 @@ dump_body_size_t(StoreEntry * entry, const char *name, dlink_list bodylist) body_size *bs; bs = (body_size *) bodylist.head; while (bs) { - acl_list *l; + acl_list *l; acl_access *head = bs->access_list; while (head != NULL) { - storeAppendPrintf(entry, "%s %d %s", name, bs->maxsize, + storeAppendPrintf(entry, "%s %d %s", name, bs->maxsize, head->allow ? "Allow" : "Deny"); for (l = head->acl_list; l != NULL; l = l->next) { - storeAppendPrintf(entry, " %s%s", + storeAppendPrintf(entry, " %s%s", l->op ? null_string : "!", l->acl->name); } storeAppendPrintf(entry, "\n"); head = head->next; - } + } bs = (body_size *) bs->node.next; } } static void -free_body_size_t(dlink_list * bodylist) //acl_access ** head) -{ +free_body_size_t(dlink_list * bodylist) //acl_access ** head) + { body_size *bs, *tempnode; bs = (body_size *) bodylist->head; while (bs) { - bs->maxsize = 0; + bs->maxsize = 0; aclDestroyAccessList(&bs->access_list); tempnode = (body_size *) bs->node.next; - dlinkDelete (&bs->node, bodylist); - cbdataFree (bs); + dlinkDelete(&bs->node, bodylist); + cbdataFree(bs); bs = tempnode; } } diff --git a/src/comm.cc b/src/comm.cc index fd8f1cf28f..0f53210da5 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.318 2001/04/14 00:03:22 hno Exp $ + * $Id: comm.cc,v 1.319 2001/08/16 00:16:16 hno Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -35,6 +35,9 @@ #include "squid.h" +#if defined(_SQUID_CYGWIN_) +#include +#endif #ifdef HAVE_NETINET_TCP_H #include #endif diff --git a/src/defines.h b/src/defines.h index 808e3c72f8..1f710d0e2c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.93 2001/05/05 17:49:54 hno Exp $ + * $Id: defines.h,v 1.94 2001/08/16 00:16:16 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -301,5 +301,5 @@ #define _WIN_OS_WIN98 3 #define _WIN_OS_WINNT 4 #define _WIN_OS_WIN2K 5 -#define _WIN_OS_STRING_SZ 80 +#define _WIN_OS_WINXP 6 #endif diff --git a/src/disk.cc b/src/disk.cc index d71919f120..4421e2ab5f 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,6 +1,6 @@ /* - * $Id: disk.cc,v 1.156 2001/07/28 22:43:24 hno Exp $ + * $Id: disk.cc,v 1.157 2001/08/16 00:16:16 hno Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -295,7 +295,7 @@ file_write(int fd, off_t file_offset, void *ptr_to_buf, int len, - DWCB *handle, + DWCB * handle, void *handle_data, FREE * free_func) { diff --git a/src/dns_internal.cc b/src/dns_internal.cc index f577dd5d24..f04e461a4f 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.cc,v 1.39 2001/05/05 17:49:54 hno Exp $ + * $Id: dns_internal.cc,v 1.40 2001/08/16 00:16:16 hno Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -159,7 +159,7 @@ idnsParseResolvConf(void) debug(78, 1) ("%s: %s\n", _PATH_RESOLV_CONF, xstrerror()); return; } -#if defined(_SQUID_CYGWIN_) +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_TEXT); #endif while (fgets(buf, 512, fp)) { @@ -227,6 +227,7 @@ idnsParseWIN32Registry(void) } break; case _WIN_OS_WIN2K: + case _WIN_OS_WINXP: /* get nameservers from the Windows 2000 registry */ /* search all interfaces for DNS server addresses */ if (RegOpenKey(HKEY_LOCAL_MACHINE, diff --git a/src/fs/coss/async_io.cc b/src/fs/coss/async_io.cc index 1e4f0513f0..b3676ea98c 100644 --- a/src/fs/coss/async_io.cc +++ b/src/fs/coss/async_io.cc @@ -11,7 +11,7 @@ * supports are read/write, and since COSS works on a single file * per storedir it should work just fine. * - * $Id: async_io.cc,v 1.5 2001/08/12 22:23:22 adrian Exp $ + * $Id: async_io.cc,v 1.6 2001/08/16 00:16:20 hno Exp $ */ #include "squid.h" @@ -34,18 +34,18 @@ * Return the index, or -1 if we can't find one. */ static int -a_file_findslot(async_queue_t *q) +a_file_findslot(async_queue_t * q) { - int i; - - /* Later we should use something a little more .. efficient :) */ - for (i = 0; i < MAX_ASYNCOP; i++) { - if (q->aq_queue[i].aq_e_state == AQ_ENTRY_FREE) - /* Found! */ - return i; - } - /* found nothing */ - return -1; + int i; + + /* Later we should use something a little more .. efficient :) */ + for (i = 0; i < MAX_ASYNCOP; i++) { + if (q->aq_queue[i].aq_e_state == AQ_ENTRY_FREE) + /* Found! */ + return i; + } + /* found nothing */ + return -1; } @@ -54,98 +54,96 @@ a_file_findslot(async_queue_t *q) /* Exported routines */ void -a_file_read(async_queue_t *q, int fd, void *buf, int req_len, off_t offset, - DRCB *callback, void *data) +a_file_read(async_queue_t * q, int fd, void *buf, int req_len, off_t offset, + DRCB * callback, void *data) { - int slot; - async_queue_entry_t *qe; + int slot; + async_queue_entry_t *qe; - assert(q->aq_state == AQ_STATE_SETUP); + assert(q->aq_state == AQ_STATE_SETUP); #if 0 - file_read(fd, buf, req_len, offset, callback, data); + file_read(fd, buf, req_len, offset, callback, data); #endif - /* Find a free slot */ - slot = a_file_findslot(q); - if (slot < 0) { - /* No free slot? Callback error, and return */ - fatal("Aiee! out of aiocb slots!\n"); - } - - /* Mark slot as ours */ - qe = &q->aq_queue[slot]; - qe->aq_e_state = AQ_ENTRY_USED; - qe->aq_e_callback.read = callback; - qe->aq_e_callback_data = data; - qe->aq_e_type = AQ_ENTRY_READ; - qe->aq_e_free = NULL; - qe->aq_e_buf = buf; - qe->aq_e_fd = fd; - - qe->aq_e_aiocb.aio_fildes = fd; - qe->aq_e_aiocb.aio_nbytes = req_len; - qe->aq_e_aiocb.aio_offset = offset; - qe->aq_e_aiocb.aio_buf = buf; - - /* Account */ - q->aq_numpending++; - - /* Lock */ - cbdataLock(data); - - /* Initiate aio */ - if (aio_read(&qe->aq_e_aiocb) < 0) { - debug(1, 1)("Aiee! aio_read() returned error (%d)!\n", errno); - assert(1==0); - } + /* Find a free slot */ + slot = a_file_findslot(q); + if (slot < 0) { + /* No free slot? Callback error, and return */ + fatal("Aiee! out of aiocb slots!\n"); + } + /* Mark slot as ours */ + qe = &q->aq_queue[slot]; + qe->aq_e_state = AQ_ENTRY_USED; + qe->aq_e_callback.read = callback; + qe->aq_e_callback_data = data; + qe->aq_e_type = AQ_ENTRY_READ; + qe->aq_e_free = NULL; + qe->aq_e_buf = buf; + qe->aq_e_fd = fd; + + qe->aq_e_aiocb.aio_fildes = fd; + qe->aq_e_aiocb.aio_nbytes = req_len; + qe->aq_e_aiocb.aio_offset = offset; + qe->aq_e_aiocb.aio_buf = buf; + + /* Account */ + q->aq_numpending++; + + /* Lock */ + cbdataLock(data); + + /* Initiate aio */ + if (aio_read(&qe->aq_e_aiocb) < 0) { + debug(1, 1) ("Aiee! aio_read() returned error (%d)!\n", errno); + assert(1 == 0); + } } void -a_file_write(async_queue_t *q, int fd, off_t offset, void *buf, int len, - DWCB *callback, void *data, FREE *freefunc) +a_file_write(async_queue_t * q, int fd, off_t offset, void *buf, int len, + DWCB * callback, void *data, FREE * freefunc) { - int slot; - async_queue_entry_t *qe; + int slot; + async_queue_entry_t *qe; - assert(q->aq_state == AQ_STATE_SETUP); + assert(q->aq_state == AQ_STATE_SETUP); #if 0 - file_write(fd, offset, buf, len, callback, data, freefunc); + file_write(fd, offset, buf, len, callback, data, freefunc); #endif - /* Find a free slot */ - slot = a_file_findslot(q); - if (slot < 0) { - /* No free slot? Callback error, and return */ - fatal("Aiee! out of aiocb slots!\n"); - } - - /* Mark slot as ours */ - qe = &q->aq_queue[slot]; - qe->aq_e_state = AQ_ENTRY_USED; - qe->aq_e_callback.write = callback; - qe->aq_e_callback_data = data; - qe->aq_e_type = AQ_ENTRY_WRITE; - qe->aq_e_free = freefunc; - qe->aq_e_buf = buf; - qe->aq_e_fd = fd; - - qe->aq_e_aiocb.aio_fildes = fd; - qe->aq_e_aiocb.aio_nbytes = len; - qe->aq_e_aiocb.aio_offset = offset; - qe->aq_e_aiocb.aio_buf = buf; - - /* Account */ - q->aq_numpending++; - - /* Lock */ - cbdataLock(data); - - /* Initiate aio */ - if (aio_write(&qe->aq_e_aiocb) < 0) { - debug(1, 1)("Aiee! aio_read() returned error (%d)!\n", errno); - assert(1==0); - } + /* Find a free slot */ + slot = a_file_findslot(q); + if (slot < 0) { + /* No free slot? Callback error, and return */ + fatal("Aiee! out of aiocb slots!\n"); + } + /* Mark slot as ours */ + qe = &q->aq_queue[slot]; + qe->aq_e_state = AQ_ENTRY_USED; + qe->aq_e_callback.write = callback; + qe->aq_e_callback_data = data; + qe->aq_e_type = AQ_ENTRY_WRITE; + qe->aq_e_free = freefunc; + qe->aq_e_buf = buf; + qe->aq_e_fd = fd; + + qe->aq_e_aiocb.aio_fildes = fd; + qe->aq_e_aiocb.aio_nbytes = len; + qe->aq_e_aiocb.aio_offset = offset; + qe->aq_e_aiocb.aio_buf = buf; + + /* Account */ + q->aq_numpending++; + + /* Lock */ + cbdataLock(data); + + /* Initiate aio */ + if (aio_write(&qe->aq_e_aiocb) < 0) { + debug(1, 1) ("Aiee! aio_read() returned error (%d)!\n", errno); + assert(1 == 0); + } } @@ -158,104 +156,102 @@ a_file_write(async_queue_t *q, int fd, off_t offset, void *buf, int len, * I'll make it much more optimal later. */ int -a_file_callback(async_queue_t *q) +a_file_callback(async_queue_t * q) { - int i; - int completed = 0; - int retval, reterr; - DRCB *rc; - DWCB *wc; - FREE *freefunc; - void *callback_data; - void *buf; - int fd; - async_queue_entry_t *aqe; - async_queue_entry_type_t type; - - assert(q->aq_state == AQ_STATE_SETUP); - - /* Loop through all slots */ - for (i = 0; i < MAX_ASYNCOP; i++) { - if (q->aq_queue[i].aq_e_state == AQ_ENTRY_USED) { - aqe = &q->aq_queue[i]; - /* Active, get status */ - reterr = aio_error(&aqe->aq_e_aiocb); - if (reterr < 0) { - fatal("aio_error returned an error!\n"); - } - if (reterr != EINPROGRESS) { - /* Get the return code */ - retval = aio_return(&aqe->aq_e_aiocb); - - /* Get the callback parameters */ - callback_data = aqe->aq_e_callback_data; - freefunc = aqe->aq_e_free; - rc = aqe->aq_e_callback.read; - wc = aqe->aq_e_callback.write; - buf = aqe->aq_e_buf; - fd = aqe->aq_e_fd; - type = aqe->aq_e_type; - - /* Free slot */ - bzero(aqe, sizeof(async_queue_entry_t)); - aqe->aq_e_state = AQ_ENTRY_FREE; - q->aq_numpending--; - - /* Callback */ - if (cbdataValid(callback_data)) { - if (type == AQ_ENTRY_READ) - rc(fd, buf, retval, reterr, callback_data); - if (type == AQ_ENTRY_WRITE) - wc(fd, reterr, retval, callback_data); - } - cbdataUnlock(callback_data); - if (type == AQ_ENTRY_WRITE && freefunc) - freefunc(buf); - } + int i; + int completed = 0; + int retval, reterr; + DRCB *rc; + DWCB *wc; + FREE *freefunc; + void *callback_data; + void *buf; + int fd; + async_queue_entry_t *aqe; + async_queue_entry_type_t type; + + assert(q->aq_state == AQ_STATE_SETUP); + + /* Loop through all slots */ + for (i = 0; i < MAX_ASYNCOP; i++) { + if (q->aq_queue[i].aq_e_state == AQ_ENTRY_USED) { + aqe = &q->aq_queue[i]; + /* Active, get status */ + reterr = aio_error(&aqe->aq_e_aiocb); + if (reterr < 0) { + fatal("aio_error returned an error!\n"); + } + if (reterr != EINPROGRESS) { + /* Get the return code */ + retval = aio_return(&aqe->aq_e_aiocb); + + /* Get the callback parameters */ + callback_data = aqe->aq_e_callback_data; + freefunc = aqe->aq_e_free; + rc = aqe->aq_e_callback.read; + wc = aqe->aq_e_callback.write; + buf = aqe->aq_e_buf; + fd = aqe->aq_e_fd; + type = aqe->aq_e_type; + + /* Free slot */ + bzero(aqe, sizeof(async_queue_entry_t)); + aqe->aq_e_state = AQ_ENTRY_FREE; + q->aq_numpending--; + + /* Callback */ + if (cbdataValid(callback_data)) { + if (type == AQ_ENTRY_READ) + rc(fd, buf, retval, reterr, callback_data); + if (type == AQ_ENTRY_WRITE) + wc(fd, reterr, retval, callback_data); } - + cbdataUnlock(callback_data); + if (type == AQ_ENTRY_WRITE && freefunc) + freefunc(buf); + } } - return completed; + } + return completed; } void -a_file_setupqueue(async_queue_t *q) +a_file_setupqueue(async_queue_t * q) { - int i; + int i; - /* Make sure the queue isn't setup */ - assert(q->aq_state == AQ_STATE_NONE); + /* Make sure the queue isn't setup */ + assert(q->aq_state == AQ_STATE_NONE); - /* Loop through, blanking the queue entries */ + /* Loop through, blanking the queue entries */ - /* Done */ - q->aq_state = AQ_STATE_SETUP; + /* Done */ + q->aq_state = AQ_STATE_SETUP; } void -a_file_syncqueue(async_queue_t *q) +a_file_syncqueue(async_queue_t * q) { - assert(q->aq_state == AQ_STATE_SETUP); - - /* - * Keep calling callback to complete ops until the queue is empty - * We can't quit when callback returns 0 - some calls may not - * return any completed pending events, but they're still pending! - */ - while (q->aq_numpending) - a_file_callback(q); + assert(q->aq_state == AQ_STATE_SETUP); + + /* + * Keep calling callback to complete ops until the queue is empty + * We can't quit when callback returns 0 - some calls may not + * return any completed pending events, but they're still pending! + */ + while (q->aq_numpending) + a_file_callback(q); } void -a_file_closequeue(async_queue_t *q) +a_file_closequeue(async_queue_t * q) { - assert(q->aq_state == AQ_STATE_SETUP); + assert(q->aq_state == AQ_STATE_SETUP); - a_file_syncqueue(q); - q->aq_state = AQ_STATE_NONE; + a_file_syncqueue(q); + q->aq_state = AQ_STATE_NONE; } - diff --git a/src/fs/coss/async_io.h b/src/fs/coss/async_io.h index 71f8d4a0e9..6ad7b2e5ca 100644 --- a/src/fs/coss/async_io.h +++ b/src/fs/coss/async_io.h @@ -4,19 +4,19 @@ #define MAX_ASYNCOP 128 typedef enum { - AQ_STATE_NONE, /* Not active/uninitialised */ - AQ_STATE_SETUP /* Initialised */ + AQ_STATE_NONE, /* Not active/uninitialised */ + AQ_STATE_SETUP /* Initialised */ } async_queue_state_t; typedef enum { - AQ_ENTRY_FREE, - AQ_ENTRY_USED + AQ_ENTRY_FREE, + AQ_ENTRY_USED } async_queue_entry_state_t; typedef enum { - AQ_ENTRY_NONE, - AQ_ENTRY_READ, - AQ_ENTRY_WRITE + AQ_ENTRY_NONE, + AQ_ENTRY_READ, + AQ_ENTRY_WRITE } async_queue_entry_type_t; @@ -25,35 +25,35 @@ typedef struct _async_queue async_queue_t; /* An async queue entry */ struct _async_queue_entry { - async_queue_entry_state_t aq_e_state; - async_queue_entry_type_t aq_e_type; - struct aiocb aq_e_aiocb; - union { - DRCB *read; - DWCB *write; - } aq_e_callback; - void *aq_e_callback_data; - FREE *aq_e_free; - int aq_e_fd; - void *aq_e_buf; + async_queue_entry_state_t aq_e_state; + async_queue_entry_type_t aq_e_type; + struct aiocb aq_e_aiocb; + union { + DRCB *read; + DWCB *write; + } aq_e_callback; + void *aq_e_callback_data; + FREE *aq_e_free; + int aq_e_fd; + void *aq_e_buf; }; /* An async queue */ struct _async_queue { - async_queue_state_t aq_state; - async_queue_entry_t aq_queue[MAX_ASYNCOP]; /* queued ops */ - int aq_numpending; /* Num of pending ops */ + async_queue_state_t aq_state; + async_queue_entry_t aq_queue[MAX_ASYNCOP]; /* queued ops */ + int aq_numpending; /* Num of pending ops */ }; /* Functions */ -extern void a_file_read(async_queue_t *q, int fd, void *buf, int req_len, - off_t offset, DRCB *callback, void *data); -extern void a_file_write(async_queue_t *q, int fd, off_t offset, void *buf, - int len, DWCB *callback, void *data, FREE *freefunc); -extern int a_file_callback(async_queue_t *q); -extern void a_file_setupqueue(async_queue_t *q); -extern void a_file_syncqueue(async_queue_t *q); -extern void a_file_closequeue(async_queue_t *q); +extern void a_file_read(async_queue_t * q, int fd, void *buf, int req_len, + off_t offset, DRCB * callback, void *data); +extern void a_file_write(async_queue_t * q, int fd, off_t offset, void *buf, + int len, DWCB * callback, void *data, FREE * freefunc); +extern int a_file_callback(async_queue_t * q); +extern void a_file_setupqueue(async_queue_t * q); +extern void a_file_syncqueue(async_queue_t * q); +extern void a_file_closequeue(async_queue_t * q); #endif diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 2647e090b9..7a5f390c9b 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.28 2001/08/12 22:18:35 adrian Exp $ + * $Id: store_dir_coss.cc,v 1.29 2001/08/16 00:16:20 hno Exp $ * * DEBUG: section 81 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -160,8 +160,8 @@ storeCossDirInit(SwapDir * sd) storeCossDirRebuild(sd); cs->fd = file_open(sd->path, O_RDWR | O_CREAT); if (cs->fd < 0) { - debug(81, 1) ("%s: %s\n", sd->path, xstrerror()); - fatal("storeCossDirInit: Failed to open a COSS directory."); + debug(81, 1) ("%s: %s\n", sd->path, xstrerror()); + fatal("storeCossDirInit: Failed to open a COSS directory."); } n_coss_dirs++; (void) storeDirGetBlkSize(sd->path, &sd->fs.blksize); @@ -657,7 +657,7 @@ storeCossDirShutdown(SwapDir * SD) { CossInfo *cs = (CossInfo *) SD->fsdata; - storeCossSync(SD); /* This'll call a_file_syncqueue() */ + storeCossSync(SD); /* This'll call a_file_syncqueue() */ a_file_closequeue(&cs->aq); file_close(cs->fd); cs->fd = -1; @@ -698,7 +698,7 @@ storeCossDirCheckObj(SwapDir * SD, const StoreEntry * e) * storeCossDirCallback - do the IO completions */ static int -storeCossDirCallback(SwapDir *SD) +storeCossDirCallback(SwapDir * SD) { CossInfo *cs = (CossInfo *) SD->fsdata; diff --git a/src/globals.h b/src/globals.h index d1a7b24d39..74124c3ffd 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.104 2001/05/05 17:49:55 hno Exp $ + * $Id: globals.h,v 1.105 2001/08/16 00:16:16 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -156,5 +156,5 @@ extern hash_table *proxy_auth_username_cache; /* NULL */ extern int incoming_sockets_accepted; #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) extern unsigned int WIN32_OS_version; /* 0 */ -extern char WIN32_OS_string[_WIN_OS_STRING_SZ]; +extern char *WIN32_OS_string; #endif diff --git a/src/main.cc b/src/main.cc index 5c3ec5b109..dbbe9b4015 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.339 2001/05/20 00:09:25 hno Exp $ + * $Id: main.cc,v 1.340 2001/08/16 00:16:16 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -998,9 +998,5 @@ SquidShutdown(void *unused) version_string); if (debug_log) fclose(debug_log); -#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) - WIN32_Exit(0); -#else exit(0); -#endif } diff --git a/src/protos.h b/src/protos.h index 07521d7549..f130b92365 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.409 2001/08/03 15:13:04 adrian Exp $ + * $Id: protos.h,v 1.410 2001/08/16 00:16:17 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1313,6 +1313,6 @@ int varyEvaluateMatch(StoreEntry * entry, request_t * req); /* CygWin & Windows NT Port */ /* win32.c */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) -extern int WIN32_Subsystem_Init(); -extern void WIN32_Exit(int); +extern int WIN32_Subsystem_Init(void); +extern void WIN32_Exit(void); #endif diff --git a/src/repl/lru/store_repl_lru.cc b/src/repl/lru/store_repl_lru.cc index 7fd4d82fbd..93eb4f6c17 100644 --- a/src/repl/lru/store_repl_lru.cc +++ b/src/repl/lru/store_repl_lru.cc @@ -1,6 +1,6 @@ /* - * $Id: store_repl_lru.cc,v 1.9 2001/07/04 00:12:06 hno Exp $ + * $Id: store_repl_lru.cc,v 1.10 2001/08/16 00:16:22 hno Exp $ * * DEBUG: section ? LRU Removal policy * AUTHOR: Henrik Nordstrom @@ -246,13 +246,13 @@ static void lru_stats(RemovalPolicy * policy, StoreEntry * sentry) { LruPolicyData *lru = policy->_data; - LruNode *lru_node = (LruNode *)lru->list.head; + LruNode *lru_node = (LruNode *) lru->list.head; -again: + again: if (lru_node) { - StoreEntry * entry = (StoreEntry *) lru_node->node.data; + StoreEntry *entry = (StoreEntry *) lru_node->node.data; if (storeEntryLocked(entry)) { - lru_node = (LruNode *)lru_node->node.next; + lru_node = (LruNode *) lru_node->node.next; goto again; } storeAppendPrintf(sentry, "LRU reference age: %.2f days\n", (double) (squid_curtime - entry->lastref) / (double) (24 * 60 * 60)); diff --git a/src/stat.cc b/src/stat.cc index 067dd6aa7e..edb099c2b5 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.347 2001/07/17 10:35:46 hno Exp $ + * $Id: stat.cc,v 1.348 2001/08/16 00:16:18 hno Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -986,7 +986,7 @@ statCountersInitSpecial(StatCounters * C) statHistEnumInit(&C->comm_icp_incoming, INCOMING_ICP_MAX); statHistEnumInit(&C->comm_dns_incoming, INCOMING_DNS_MAX); statHistEnumInit(&C->comm_http_incoming, INCOMING_HTTP_MAX); - statHistIntInit(&C->select_fds_hist, 256); /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */ + statHistIntInit(&C->select_fds_hist, 256); /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */ } /* add special cases here as they arrive */ diff --git a/src/store_dir.cc b/src/store_dir.cc index b37fd61cd7..e645347812 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir.cc,v 1.133 2001/08/11 19:09:21 adrian Exp $ + * $Id: store_dir.cc,v 1.134 2001/08/16 00:16:18 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -118,8 +118,8 @@ storeDirValidSwapDirSize(int swapdir, ssize_t objsize) * can't store it */ if ((objsize == -1) && - (Config.cacheSwap.swapDirs[swapdir].max_objsize != -1)) - return 0; + (Config.cacheSwap.swapDirs[swapdir].max_objsize != -1)) + return 0; /* * Else, make sure that the max object size is larger than objsize @@ -225,7 +225,7 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e) dirn = i; } if (dirn >= 0) - Config.cacheSwap.swapDirs[dirn].flags.selected = 1; + Config.cacheSwap.swapDirs[dirn].flags.selected = 1; return dirn; } diff --git a/src/tools.cc b/src/tools.cc index 91eb9d6834..3d009a3d77 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.208 2001/08/11 18:27:20 adrian Exp $ + * $Id: tools.cc,v 1.209 2001/08/16 00:16:19 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -968,6 +968,9 @@ parseEtcHosts(void) char *lt = buf; char *addr = buf; char *host = NULL; +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) + char *systemroot = NULL; +#endif if (NULL == Config.etcHostsPath) return; if (0 == strcmp(Config.etcHostsPath, "none")) @@ -978,7 +981,7 @@ parseEtcHosts(void) Config.etcHostsPath, xstrerror()); return; } -#if defined(_SQUID_CYGWIN_) +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_TEXT); #endif while (fgets(buf, 1024, fp)) { /* for each line */ diff --git a/src/win32.cc b/src/win32.cc index b173141e6a..1d3e8f2779 100644 --- a/src/win32.cc +++ b/src/win32.cc @@ -1,5 +1,5 @@ /* - * $Id: win32.cc,v 1.1 2001/05/06 14:25:21 hno Exp $ + * $Id: win32.cc,v 1.2 2001/08/16 00:16:19 hno Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -28,7 +28,6 @@ #include static unsigned int GetOSVersion(); -void WIN32_svcstatusupdate(DWORD); /* ====================================================================== */ /* LOCAL FUNCTIONS */ @@ -39,37 +38,40 @@ GetOSVersion() { OSVERSIONINFO osvi; + safe_free(WIN32_OS_string); memset(&osvi, '\0', sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx((OSVERSIONINFO *) & osvi); switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if (osvi.dwMajorVersion <= 4) { - strcpy(WIN32_OS_string, "Windows NT"); + WIN32_OS_string = xstrdup("Windows NT"); return _WIN_OS_WINNT; } - if (osvi.dwMajorVersion == 5) { - strcpy(WIN32_OS_string, "Windows 2000"); - return _WIN_OS_WIN2K; + if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1)) { + WIN32_OS_string = xstrdup("Windows XP"); + return _WIN_OS_WINXP; } + WIN32_OS_string = xstrdup("Windows 2000"); + return _WIN_OS_WIN2K; break; case VER_PLATFORM_WIN32_WINDOWS: if ((osvi.dwMajorVersion > 4) || ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0))) { - strcpy(WIN32_OS_string, "Windows 98"); + WIN32_OS_string = xstrdup("Windows 98"); return _WIN_OS_WIN98; } - strcpy(WIN32_OS_string, "Windows 95"); + WIN32_OS_string = xstrdup("Windows 95"); return _WIN_OS_WIN95; break; case VER_PLATFORM_WIN32s: - strcpy(WIN32_OS_string, "Windows 3.1 with WIN32S"); + WIN32_OS_string = xstrdup("Windows 3.1 with WIN32S"); return _WIN_OS_WIN32S; break; default: return _WIN_OS_UNKNOWN; } - strcpy(WIN32_OS_string, "Unknown"); + WIN32_OS_string = xstrdup("Unknown"); return _WIN_OS_UNKNOWN; } @@ -77,16 +79,20 @@ GetOSVersion() /* PUBLIC FUNCTIONS */ /* ====================================================================== */ -VOID -WIN32_Exit(int ExitStatus) +void +WIN32_Exit() { - exit(0); + _exit(0); } int WIN32_Subsystem_Init() { WIN32_OS_version = GetOSVersion(); + if ((WIN32_OS_version == _WIN_OS_UNKNOWN) || (WIN32_OS_version == _WIN_OS_WIN32S)) + return 1; + if (atexit(WIN32_Exit) != 0) + return 1; return 0; } #endif -- 2.47.3