version 2.33, 1994/12/02 19:25:17
|
version 2.33.2.4, 1995/03/09 18:28:09
|
Line 15
|
Line 15
|
** and HTDoAccept |
** and HTDoAccept |
*/ |
*/ |
|
|
#ifndef VMS |
/* Library include files */ |
#include <pwd.h> |
#include "tcp.h" |
#endif /* not VMS */ |
|
|
|
#include "tcp.h" /* Defines SHORT_NAMES if necessary */ |
|
|
|
#include "HTUtils.h" |
#include "HTUtils.h" |
|
#include "HTString.h" |
#include "HTAtom.h" |
#include "HTAtom.h" |
#include "HTList.h" |
#include "HTList.h" |
#include "HTParse.h" |
#include "HTParse.h" |
#include "HTAccess.h" |
#include "HTAccess.h" |
#include "HTError.h" |
#include "HTError.h" |
|
|
#ifdef EVENT_LOOP |
|
#include "HTThread.h" |
#include "HTThread.h" |
#endif /* EVENT_LOOP */ |
|
|
|
#include "HTTCP.h" /* Implemented here */ |
#include "HTTCP.h" /* Implemented here */ |
|
|
#ifdef VMS |
#ifdef VMS |
Line 95 PRIVATE HTList *hostcache = NULL; /* Li
|
Line 88 PRIVATE HTList *hostcache = NULL; /* Li
|
PRIVATE unsigned int HTCacheSize = 0; /* Current size of cache */ |
PRIVATE unsigned int HTCacheSize = 0; /* Current size of cache */ |
|
|
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
/* TEMPORARY STUFF */ |
|
#define IOCTL ioctl |
|
/* ------------------------------------------------------------------------- */ |
|
|
|
/* Encode INET status (as in sys/errno.h) inet_status() |
|
** ------------------ |
|
** |
|
** On entry, |
|
** where gives a description of what caused the error |
|
** global errno gives the error number in the unix way. |
|
** |
|
** On return, |
|
** returns a negative status in the unix way. |
|
*/ |
|
#ifndef PCNFS |
|
#ifdef VMS |
|
#ifndef __DECC |
|
extern int uerrno; /* Deposit of error info (as per errno.h) */ |
|
extern volatile noshare int socket_errno; /* socket VMS error info |
|
(used for translation of vmserrno) */ |
|
extern volatile noshare int vmserrno; /* Deposit of VMS error info */ |
|
extern volatile noshare int errno; /* noshare to avoid PSECT conflict */ |
|
#endif /* not DECC */ |
|
#endif /* VMS */ |
|
|
|
#ifndef errno |
|
extern int errno; |
|
#endif /* errno */ |
|
|
|
#ifndef VM |
|
#ifndef VMS |
|
#ifndef NeXT |
|
#ifndef THINK_C |
|
extern char *sys_errlist[]; /* see man perror on cernvax */ |
|
extern int sys_nerr; |
|
#endif /* think c */ |
|
#endif /* NeXT */ |
|
#endif /* VMS */ |
|
#endif /* VM */ |
|
|
|
#endif /* PCNFS */ |
|
|
|
|
|
/* |
/* |
* Returns the string equivalent of the current errno. |
** Returns the string equivalent to the errno passed in the argument. |
*/ |
** We can't use errno directly as we haev both errno and socerrno. The |
PUBLIC CONST char * HTErrnoString NOARGS |
** result is a static buffer. |
|
*/ |
|
PUBLIC CONST char * HTErrnoString ARGS1(int, errornumber) |
{ |
{ |
#ifndef VMS |
|
|
|
#ifdef VM |
|
return "(Error number not translated)"; /* What Is the VM equiv? */ |
|
#define ER_NO_TRANS_DONE |
|
#endif |
|
|
|
#if defined(NeXT) || defined(THINK_C) |
#if defined(NeXT) || defined(THINK_C) |
return strerror(errno); |
return strerror(errornumber); |
#define ER_NO_TRANS_DONE |
#else |
#endif |
#ifdef VMS |
|
|
#ifndef ER_NO_TRANS_DONE |
|
return (errno < sys_nerr ? sys_errlist[errno] : "Unknown error"); |
|
#endif |
|
|
|
#else /* VMS */ |
|
|
|
static char buf[60]; |
static char buf[60]; |
sprintf(buf,"Unix errno = %ld dec, VMS error = %lx hex",errno,vaxc$errno); |
sprintf(buf,"Unix errno = %ld dec, VMS error = %lx hex", errornumber, |
|
vaxc$errno); |
return buf; |
return buf; |
|
#else |
|
return (errornumber < sys_nerr ? sys_errlist[errornumber]:"Unknown error"); |
|
#endif |
#endif |
#endif |
} |
} |
|
|
|
|
/* Report Internet Error |
#ifdef OLD_CODE |
** --------------------- |
/* Debug error message |
*/ |
*/ |
PUBLIC int HTInetStatus ARGS1(char *, where) |
PUBLIC int HTInetStatus ARGS1(char *, where) |
{ |
{ |
#ifndef VMS |
#ifndef VMS |
|
|
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "TCP errno... %d after call to %s() failed.\n............ %s\n", errno, where, HTErrnoString()); |
fprintf(TDEST, "TCP errno... %d after call to %s() failed.\n............ %s\n", errno, where, HTErrnoString(errornumber)); |
|
|
#else /* VMS */ |
#else /* VMS */ |
|
|
if (PROT_TRACE) fprintf(stderr, " Unix error number = %ld dec\n", errno); |
if (PROT_TRACE) fprintf(TDEST, " Unix error number = %ld dec\n", errno); |
if (PROT_TRACE) fprintf(stderr, " VMS error = %lx hex\n", vaxc$errno); |
if (PROT_TRACE) fprintf(TDEST, " VMS error = %lx hex\n", vaxc$errno); |
|
|
#ifdef MULTINET |
#ifdef MULTINET |
if (PROT_TRACE) fprintf(stderr, " Multinet error = %lx hex\n", socket_errno); |
if (PROT_TRACE) fprintf(TDEST, " Multinet error = %lx hex\n", socket_errno); |
if (PROT_TRACE) fprintf(stderr, " Error String = %s\n", vms_errno_string()); |
if (PROT_TRACE) fprintf(TDEST, " Error String = %s\n", vms_errno_string()); |
#endif /* MULTINET */ |
#endif /* MULTINET */ |
|
|
#endif /* VMS */ |
#endif /* VMS */ |
Line 198 PUBLIC int HTInetStatus ARGS1(char *, wh
|
Line 140 PUBLIC int HTInetStatus ARGS1(char *, wh
|
return -errno; |
return -errno; |
#endif |
#endif |
} |
} |
|
#endif |
|
|
|
|
/* Parse a cardinal value parse_cardinal() |
/* Parse a cardinal value parse_cardinal() |
Line 219 PUBLIC unsigned int HTCardinal ARGS3
|
Line 162 PUBLIC unsigned int HTCardinal ARGS3
|
char **, pp, |
char **, pp, |
unsigned int, max_value) |
unsigned int, max_value) |
{ |
{ |
int n; |
unsigned int n=0; |
if ( (**pp<'0') || (**pp>'9')) { /* Null string is error */ |
if ( (**pp<'0') || (**pp>'9')) { /* Null string is error */ |
*pstatus = -3; /* No number where one expeceted */ |
*pstatus = -3; /* No number where one expeceted */ |
return 0; |
return 0; |
} |
} |
|
|
n=0; |
|
while ((**pp>='0') && (**pp<='9')) n = n*10 + *((*pp)++) - '0'; |
while ((**pp>='0') && (**pp<='9')) n = n*10 + *((*pp)++) - '0'; |
|
|
if (n>max_value) { |
if (n>max_value) { |
Line 253 PUBLIC void HTSetSignal NOARGS
|
Line 194 PUBLIC void HTSetSignal NOARGS
|
** get `connection refused' back |
** get `connection refused' back |
*/ |
*/ |
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { |
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { |
if (PROT_TRACE) fprintf(stderr, "HTSignal.... Can't catch SIGPIPE\n"); |
if (PROT_TRACE) fprintf(TDEST, "HTSignal.... Can't catch SIGPIPE\n"); |
} else { |
} else { |
if (PROT_TRACE) fprintf(stderr, "HTSignal.... Ignoring SIGPIPE\n"); |
if (PROT_TRACE) fprintf(TDEST, "HTSignal.... Ignoring SIGPIPE\n"); |
} |
} |
} |
} |
#endif /* WWWLIB_SIG */ |
#endif /* WWWLIB_SIG */ |
Line 272 PRIVATE void HTTCPCacheRemoveElement ARG
|
Line 213 PRIVATE void HTTCPCacheRemoveElement ARG
|
{ |
{ |
if (!hostcache) { |
if (!hostcache) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostCache... Remove not done, no cache\n"); |
fprintf(TDEST, "HostCache... Remove not done, no cache\n"); |
return; |
return; |
} |
} |
if (PROT_TRACE) fprintf(stderr, "HostCache... Remove `%s' from cache\n", |
if (PROT_TRACE) fprintf(TDEST, "HostCache... Remove `%s' from cache\n", |
HTAtom_name(element->hostname)); |
HTAtom_name(element->hostname)); |
HTList_removeObject(hostcache, (void *) element); |
HTList_removeObject(hostcache, (void *) element); |
if (*element->addrlist) |
if (*element->addrlist) |
Line 322 PRIVATE void HTTCPCacheRemoveHost ARGS1(
|
Line 263 PRIVATE void HTTCPCacheRemoveHost ARGS1(
|
HTList *cur = hostcache; |
HTList *cur = hostcache; |
host_info *pres = NULL; |
host_info *pres = NULL; |
if (!hostcache) { |
if (!hostcache) { |
fprintf(stderr, "HostCache... Remove host not done, no cache\n"); |
if (PROT_TRACE) |
|
fprintf(TDEST, "HostCache... Remove host not done, no cache\n"); |
return; |
return; |
} |
} |
while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) { |
while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) { |
Line 346 PRIVATE void HTTCPCacheGarbage NOARGS
|
Line 288 PRIVATE void HTTCPCacheGarbage NOARGS
|
unsigned int worst_hits = 30000; /* Should use UINT_MAX :-( */ |
unsigned int worst_hits = 30000; /* Should use UINT_MAX :-( */ |
if (!hostcache) { |
if (!hostcache) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostCache... Garbage collection not done, no cache\n"); |
fprintf(TDEST, "HostCache... Garbage collection not done, no cache\n"); |
return; |
return; |
} |
} |
|
|
Line 380 PRIVATE host_info *HTTCPCacheAddElement
|
Line 322 PRIVATE host_info *HTTCPCacheAddElement
|
int cnt = 1; |
int cnt = 1; |
if (!host || !element) { |
if (!host || !element) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostCache... Bad argument to add to cache\n"); |
fprintf(TDEST, "HostCache... Bad argument to add to cache\n"); |
return NULL; |
return NULL; |
} |
} |
while(*index++) |
while(*index++) |
Line 408 PRIVATE host_info *HTTCPCacheAddElement
|
Line 350 PRIVATE host_info *HTTCPCacheAddElement
|
|
|
if (PROT_TRACE) { |
if (PROT_TRACE) { |
if (newhost->homes == 1) |
if (newhost->homes == 1) |
fprintf(stderr, "HostCache... Adding single-homed host `%s'\n", |
fprintf(TDEST, "HostCache... Adding single-homed host `%s'\n", |
HTAtom_name(host)); |
HTAtom_name(host)); |
else |
else |
fprintf(stderr, "HostCache... Adding host `%s' with %d homes\n", |
fprintf(TDEST, "HostCache... Adding host `%s' with %d homes\n", |
HTAtom_name(host), newhost->homes); |
HTAtom_name(host), newhost->homes); |
} |
} |
HTList_addObject(hostcache, (void *) newhost); |
HTList_addObject(hostcache, (void *) newhost); |
Line 440 PUBLIC void HTTCPAddrWeights ARGS2(char
|
Line 382 PUBLIC void HTTCPAddrWeights ARGS2(char
|
HTList *cur = hostcache; |
HTList *cur = hostcache; |
host_info *pres = NULL; |
host_info *pres = NULL; |
if (!hostcache) { |
if (!hostcache) { |
fprintf(stderr, "HostCache... Weights not calculated, no cache\n"); |
fprintf(TDEST, "HostCache... Weights not calculated, no cache\n"); |
return; |
return; |
} |
} |
/* Skip any port number from host name */ |
/* Skip any port number from host name */ |
Line 476 PUBLIC void HTTCPAddrWeights ARGS2(char
|
Line 418 PUBLIC void HTTCPAddrWeights ARGS2(char
|
*(pres->weight+cnt) = *(pres->weight+cnt) * passive; |
*(pres->weight+cnt) = *(pres->weight+cnt) * passive; |
} |
} |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "AddrWeights. Home %d has weight %4.2f\n", cnt, |
fprintf(TDEST, "AddrWeights. Home %d has weight %4.2f\n", cnt, |
*(pres->weight+cnt)); |
*(pres->weight+cnt)); |
} |
} |
} else if (PROT_TRACE) { |
} else if (PROT_TRACE) { |
fprintf(stderr, "HostCache... Weights not calculated, host not found in cache: `%s\'\n", host); |
fprintf(TDEST, "HostCache... Weights not calculated, host not found in cache: `%s\'\n", host); |
} |
} |
} |
} |
|
|
Line 537 PUBLIC int HTGetHostByName ARGS3(char *,
|
Line 479 PUBLIC int HTGetHostByName ARGS3(char *,
|
while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) { |
while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) { |
if (pres->hostname == hostatom) { |
if (pres->hostname == hostatom) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostByName.. Host `%s\' found in cache.\n", host); |
fprintf(TDEST, "HostByName.. Host `%s\' found in cache.\n", host); |
break; |
break; |
} |
} |
} |
} |
Line 562 PUBLIC int HTGetHostByName ARGS3(char *,
|
Line 504 PUBLIC int HTGetHostByName ARGS3(char *,
|
struct hostent *hostelement; /* see netdb.h */ |
struct hostent *hostelement; /* see netdb.h */ |
#ifdef MVS /* Outstanding problem with crash in MVS gethostbyname */ |
#ifdef MVS /* Outstanding problem with crash in MVS gethostbyname */ |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTTCP on MVS gethostbyname(%s)\n", host); |
fprintf(TDEST, "HTTCP on MVS gethostbyname(%s)\n", host); |
#endif |
#endif |
if ((hostelement = gethostbyname(host)) == NULL) { |
if ((hostelement = gethostbyname(host)) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostByName.. Can't find internet node name `%s'.\n", host); |
fprintf(TDEST, "HostByName.. Can't find internet node name `%s'.\n", host); |
return -1; |
return -1; |
} |
} |
|
|
Line 609 PUBLIC char * HTGetHostBySock ARGS1(int,
|
Line 551 PUBLIC char * HTGetHostBySock ARGS1(int,
|
AF_INET); |
AF_INET); |
if (!phost) { |
if (!phost) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "TCP......... Can't find internet node name for peer!!\n"); |
fprintf(TDEST, "TCP......... Can't find internet node name for peer!!\n"); |
return NULL; |
return NULL; |
} |
} |
StrAllocCopy(name, phost->h_name); |
StrAllocCopy(name, phost->h_name); |
if (PROT_TRACE) fprintf(stderr, "TCP......... Peer name is `%s'\n", name); |
if (PROT_TRACE) fprintf(TDEST, "TCP......... Peer name is `%s'\n", name); |
|
|
return name; |
return name; |
|
|
Line 658 PUBLIC int HTParseInet ARGS3(SockA *, si
|
Line 600 PUBLIC int HTParseInet ARGS3(SockA *, si
|
#endif |
#endif |
} else { |
} else { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "ParseInet... No port indicated\n"); |
fprintf(TDEST, "ParseInet... No port indicated\n"); |
free(host); |
free(host); |
return -1; |
return -1; |
} |
} |
Line 673 PUBLIC int HTParseInet ARGS3(SockA *, si
|
Line 615 PUBLIC int HTParseInet ARGS3(SockA *, si
|
sin->sdn_nam.n_len = min(DN_MAXNAML, strlen(host)); /* <=6 in phase 4 */ |
sin->sdn_nam.n_len = min(DN_MAXNAML, strlen(host)); /* <=6 in phase 4 */ |
strncpy (sin->sdn_nam.n_name, host, sin->sdn_nam.n_len + 1); |
strncpy (sin->sdn_nam.n_name, host, sin->sdn_nam.n_len + 1); |
|
|
if (PROT_TRACE) fprintf(stderr, |
if (PROT_TRACE) fprintf(TDEST, |
"DECnet: Parsed address as object number %d on host %.6s...\n", |
"DECnet: Parsed address as object number %d on host %.6s...\n", |
sin->sdn_objnum, host); |
sin->sdn_objnum, host); |
|
|
Line 699 PUBLIC int HTParseInet ARGS3(SockA *, si
|
Line 641 PUBLIC int HTParseInet ARGS3(SockA *, si
|
} |
} |
} |
} |
if (PROT_TRACE) { |
if (PROT_TRACE) { |
fprintf(stderr, "ParseInet... Parsed address as port %d on %s\n", |
fprintf(TDEST, "ParseInet... Parsed address as port %d on %s\n", |
(int) ntohs(sin->sin_port), |
(int) ntohs(sin->sin_port), |
HTInetString(sin)); |
HTInetString(sin)); |
} |
} |
Line 728 PRIVATE void get_host_details NOARGS
|
Line 670 PRIVATE void get_host_details NOARGS
|
|
|
if (hostname) return; /* Already done */ |
if (hostname) return; /* Already done */ |
gethostname(name, namelength); /* Without domain */ |
gethostname(name, namelength); /* Without domain */ |
if (PROT_TRACE) fprintf(stderr, "TCP......... Local host name is %s\n", name); |
if (PROT_TRACE) fprintf(TDEST, "TCP......... Local host name is %s\n", name); |
StrAllocCopy(hostname, name); |
StrAllocCopy(hostname, name); |
|
|
#ifndef DECNET /* Decnet ain't got no damn name server 8#OO */ |
#ifndef DECNET /* Decnet ain't got no damn name server 8#OO */ |
phost=gethostbyname(name); /* See netdb.h */ |
phost=gethostbyname(name); /* See netdb.h */ |
if (!phost) { |
if (!phost) { |
if (PROT_TRACE) fprintf(stderr, |
if (PROT_TRACE) fprintf(TDEST, |
"TCP......... Can't find my own internet node address for `%s'!!\n", |
"TCP......... Can't find my own internet node address for `%s'!!\n", |
name); |
name); |
return; /* Fail! */ |
return; /* Fail! */ |
} |
} |
StrAllocCopy(hostname, phost->h_name); |
StrAllocCopy(hostname, phost->h_name); |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "TCP......... Full local host name is %s\n", hostname); |
fprintf(TDEST, "TCP......... Full local host name is %s\n", hostname); |
|
|
#ifdef NEED_HOST_ADDRESS /* no -- needs name server! */ |
#ifdef NEED_HOST_ADDRESS /* no -- needs name server! */ |
memcpy(&HTHostAddress, &phost->h_addr, phost->h_length); |
memcpy(&HTHostAddress, &phost->h_addr, phost->h_length); |
if (PROT_TRACE) fprintf(stderr, " Name server says that I am `%s' = %s\n", |
if (PROT_TRACE) fprintf(TDEST, " Name server says that I am `%s' = %s\n", |
hostname, HTInetString(&HTHostAddress)); |
hostname, HTInetString(&HTHostAddress)); |
#endif /* NEED_HOST_ADDRESS */ |
#endif /* NEED_HOST_ADDRESS */ |
|
|
Line 757 PRIVATE void get_host_details NOARGS
|
Line 699 PRIVATE void get_host_details NOARGS
|
/* HTGetDomainName |
/* HTGetDomainName |
** Returns the current domain name without the local host name. |
** Returns the current domain name without the local host name. |
** The response is pointing to a static area that might be changed |
** The response is pointing to a static area that might be changed |
** using HTSetHostName(). Returns NULL on error |
** using HTSetHostName(). |
|
** |
|
** Returns NULL on error, "" if domain name is not found |
*/ |
*/ |
PUBLIC CONST char *HTGetDomainName NOARGS |
PUBLIC CONST char *HTGetDomainName NOARGS |
{ |
{ |
Line 767 PUBLIC CONST char *HTGetDomainName NOARG
|
Line 711 PUBLIC CONST char *HTGetDomainName NOARG
|
if ((domain = strchr(host, '.')) != NULL) |
if ((domain = strchr(host, '.')) != NULL) |
return ++domain; |
return ++domain; |
else |
else |
return host; |
return ""; |
} else |
} else |
return NULL; |
return NULL; |
} |
} |
Line 792 PUBLIC void HTSetHostName ARGS1(char *,
|
Line 736 PUBLIC void HTSetHostName ARGS1(char *,
|
if (*(hostname+strlen(hostname)-1) == '.') /* Remove trailing dot */ |
if (*(hostname+strlen(hostname)-1) == '.') /* Remove trailing dot */ |
*(hostname+strlen(hostname)-1) = '\0'; |
*(hostname+strlen(hostname)-1) = '\0'; |
} else { |
} else { |
if (PROT_TRACE) fprintf(stderr, "SetHostName. Bad argument ignored\n"); |
if (PROT_TRACE) fprintf(TDEST, "SetHostName. Bad argument ignored\n"); |
} |
} |
} |
} |
|
|
Line 828 PUBLIC CONST char * HTGetHostName NOARGS
|
Line 772 PUBLIC CONST char * HTGetHostName NOARGS
|
*(name+MAXHOSTNAMELEN) = '\0'; |
*(name+MAXHOSTNAMELEN) = '\0'; |
if (gethostname(name, MAXHOSTNAMELEN)) { /* Maybe without domain */ |
if (gethostname(name, MAXHOSTNAMELEN)) { /* Maybe without domain */ |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostName.... Can't get host name\n"); |
fprintf(TDEST, "HostName.... Can't get host name\n"); |
return NULL; |
return NULL; |
} |
} |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostName.... Local host name is `%s\'\n", name); |
fprintf(TDEST, "HostName.... Local host name is `%s\'\n", name); |
StrAllocCopy(hostname, name); |
StrAllocCopy(hostname, name); |
{ |
{ |
char *strptr = strchr(hostname, '.'); |
char *strptr = strchr(hostname, '.'); |
Line 867 PUBLIC CONST char * HTGetHostName NOARGS
|
Line 811 PUBLIC CONST char * HTGetHostName NOARGS
|
} |
} |
|
|
/* If everything else has failed then try getdomainname */ |
/* If everything else has failed then try getdomainname */ |
#ifndef sco |
#ifndef NO_GETDOMAINNAME |
if (!got_it) { |
if (!got_it) { |
if (getdomainname(name, MAXHOSTNAMELEN)) { |
if (getdomainname(name, MAXHOSTNAMELEN)) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostName.... Can't get domain name\n"); |
fprintf(TDEST, "HostName.... Can't get domain name\n"); |
StrAllocCopy(hostname, ""); |
StrAllocCopy(hostname, ""); |
return NULL; |
return NULL; |
} |
} |
Line 880 PUBLIC CONST char * HTGetHostName NOARGS
|
Line 824 PUBLIC CONST char * HTGetHostName NOARGS
|
then use the former as it is more exact (I guess) */ |
then use the former as it is more exact (I guess) */ |
if (strncmp(name, hostname, (int) strlen(hostname))) { |
if (strncmp(name, hostname, (int) strlen(hostname))) { |
char *domain = strchr(name, '.'); |
char *domain = strchr(name, '.'); |
if (!domain) |
if (domain) |
domain = name; |
StrAllocCat(hostname, domain); |
StrAllocCat(hostname, "."); |
|
StrAllocCat(hostname, domain); |
|
} |
} |
} |
} |
#endif /* not sco */ |
#endif /* NO_GETDOMAINNAME */ |
#endif /* not VMS */ |
#endif /* not VMS */ |
|
|
{ |
{ |
Line 899 PUBLIC CONST char * HTGetHostName NOARGS
|
Line 841 PUBLIC CONST char * HTGetHostName NOARGS
|
*(hostname+strlen(hostname)-1) = '\0'; |
*(hostname+strlen(hostname)-1) = '\0'; |
} |
} |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostName.... Full host name is `%s\'\n", hostname); |
fprintf(TDEST, "HostName.... Full host name is `%s\'\n", hostname); |
return hostname; |
return hostname; |
|
|
#ifndef DECNET /* Decnet ain't got no damn name server 8#OO */ |
#ifndef DECNET /* Decnet ain't got no damn name server 8#OO */ |
Line 909 PUBLIC CONST char * HTGetHostName NOARGS
|
Line 851 PUBLIC CONST char * HTGetHostName NOARGS
|
struct hostent *hostelement; |
struct hostent *hostelement; |
if ((hostelement = gethostbyname(hostname)) == NULL) { |
if ((hostelement = gethostbyname(hostname)) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HostName.... Can't find host name on DNS\n"); |
fprintf(TDEST, "HostName.... Can't find host name on DNS\n"); |
FREE(hostname); |
FREE(hostname); |
return NULL; |
return NULL; |
} |
} |
Line 942 PUBLIC void HTSetMailAddress ARGS1(char
|
Line 884 PUBLIC void HTSetMailAddress ARGS1(char
|
else |
else |
StrAllocCopy(mailaddress, address); |
StrAllocCopy(mailaddress, address); |
if (TRACE) |
if (TRACE) |
fprintf(stderr, "SetMailAdr.. Set mail address to `%s\'\n", |
fprintf(TDEST, "SetMailAdr.. Set mail address to `%s\'\n", |
mailaddress); |
mailaddress); |
} |
} |
|
|
Line 978 PUBLIC CONST char * HTGetMailAddress NOA
|
Line 920 PUBLIC CONST char * HTGetMailAddress NOA
|
|
|
#ifdef VMS |
#ifdef VMS |
if ((login = (char *) cuserid(NULL)) == NULL) { |
if ((login = (char *) cuserid(NULL)) == NULL) { |
if (PROT_TRACE) fprintf(stderr, "MailAddress. cuserid returns NULL\n"); |
if (PROT_TRACE) fprintf(TDEST, "MailAddress. cuserid returns NULL\n"); |
} |
} |
|
|
#else /* not VMS */ |
#else |
|
#ifdef _WINDOWS |
|
login = "PCUSER"; /* @@@ COULD BE BETTER @@@ */ |
|
#else /* Unix like... */ |
if ((login = (char *) getlogin()) == NULL) { |
if ((login = (char *) getlogin()) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "MailAddress. getlogin returns NULL\n"); |
fprintf(TDEST, "MailAddress. getlogin returns NULL\n"); |
if ((pw_info = getpwuid(getuid())) == NULL) { |
if ((pw_info = getpwuid(getuid())) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "MailAddress. getpwid returns NULL\n"); |
fprintf(TDEST, "MailAddress. getpwid returns NULL\n"); |
if ((login = getenv("LOGNAME")) == NULL) { |
if ((login = getenv("LOGNAME")) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "MailAddress. LOGNAME not found\n"); |
fprintf(TDEST, "MailAddress. LOGNAME not found\n"); |
if ((login = getenv("USER")) == NULL) { |
if ((login = getenv("USER")) == NULL) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr,"MailAddress. USER not found\n"); |
fprintf(TDEST,"MailAddress. USER not found\n"); |
return NULL; /* I GIVE UP */ |
return NULL; /* I GIVE UP */ |
} |
} |
} |
} |
} else |
} else |
login = pw_info->pw_name; |
login = pw_info->pw_name; |
} |
} |
#endif /* not VMS */ |
#endif |
|
#endif |
|
|
if (login) { |
if (login) { |
StrAllocCopy(mailaddress, login); |
StrAllocCopy(mailaddress, login); |
Line 1058 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1004 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
return -1; |
return -1; |
} else { |
} else { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Looking up `%s\'\n", host); |
fprintf(TDEST, "HTDoConnect. Looking up `%s\'\n", host); |
} |
} |
|
|
/* Set up defaults */ |
/* Set up defaults */ |
if (net->sockfd < 0) { |
if (net->sockfd==INVSOC) { |
memset((void *) &net->sock_addr, '\0', sizeof(net->sock_addr)); |
memset((void *) &net->sock_addr, '\0', sizeof(net->sock_addr)); |
#ifdef DECNET |
#ifdef DECNET |
net->sock_addr.sdn_family = AF_DECnet;/* Family = DECnet, host order */ |
net->sock_addr.sdn_family = AF_DECnet;/* Family = DECnet, host order */ |
Line 1076 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1022 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
/* If we are trying to connect to a multi-homed host then loop here until |
/* If we are trying to connect to a multi-homed host then loop here until |
success or we have tried all IP-addresses */ |
success or we have tried all IP-addresses */ |
do { |
do { |
if (net->sockfd < 0) { |
if (net->sockfd==INVSOC) { |
int hosts; |
int hosts; |
if ((hosts = HTParseInet(&net->sock_addr, host, use_cur)) < 0) { |
if ((hosts = HTParseInet(&net->sock_addr, host, use_cur)) < 0) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Can't locate remote host `%s\'\n", host); |
fprintf(TDEST, "HTDoConnect. Can't locate remote host `%s\'\n", host); |
HTErrorAdd(net->request, ERR_FATAL, NO, HTERR_NO_REMOTE_HOST, |
HTErrorAdd(net->request, ERR_FATAL, NO, HTERR_NO_REMOTE_HOST, |
(void *) host, strlen(host), "HTDoConnect"); |
(void *) host, strlen(host), "HTDoConnect"); |
break; |
break; |
Line 1088 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1034 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
if (!net->addressCount && hosts > 1) |
if (!net->addressCount && hosts > 1) |
net->addressCount = hosts; |
net->addressCount = hosts; |
#ifdef DECNET |
#ifdef DECNET |
if ((net->sockfd = socket(AF_DECnet, SOCK_STREAM, 0)) < 0) |
if ((net->sockfd=socket(AF_DECnet, SOCK_STREAM, 0))==INVSOC) |
#else |
#else |
if ((net->sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
if ((net->sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==INVSOC) |
#endif |
#endif |
{ |
{ |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "socket"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno, NO, "socket"); |
break; |
break; |
} |
} |
if (addr) |
if (addr) |
*addr = ntohl(net->sock_addr.sin_addr.s_addr); |
*addr = ntohl(net->sock_addr.sin_addr.s_addr); |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Created socket number %d\n", |
fprintf(TDEST, "HTDoConnect. Created socket number %d\n", |
net->sockfd); |
net->sockfd); |
|
|
/* If non-blocking protocol then change socket status |
/* If non-blocking protocol then change socket status |
Line 1110 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1056 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
** does NOT work on SVR4 systems. O_NONBLOCK is POSIX. |
** does NOT work on SVR4 systems. O_NONBLOCK is POSIX. |
*/ |
*/ |
if (!HTProtocolBlocking(net->request)) { |
if (!HTProtocolBlocking(net->request)) { |
|
#if defined(_WINDOWS) || defined(VMS) |
|
{ |
|
int enable = 1; |
|
status = IOCTL(net->sockfd, FIONBIO, &enable); |
|
} |
|
#else |
if((status = FCNTL(net->sockfd, F_GETFL, 0)) != -1) { |
if((status = FCNTL(net->sockfd, F_GETFL, 0)) != -1) { |
status |= O_NONBLOCK; /* POSIX */ |
status |= O_NONBLOCK; /* POSIX */ |
status = FCNTL(net->sockfd, F_SETFL, status); |
status = FCNTL(net->sockfd, F_SETFL, status); |
} |
} |
|
#endif |
if (status == -1) { |
if (status == -1) { |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Can NOT make socket non-blocking\n"); |
fprintf(TDEST, "HTDoConnect. Can NOT make socket non-blocking\n"); |
} else if (PROT_TRACE) |
} else if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Using NON_BLOCKING I/O\n"); |
fprintf(TDEST, "HTDoConnect. Using NON_BLOCKING I/O\n"); |
} |
} |
|
|
/* If multi-homed host then start timer on connection */ |
/* If multi-homed host then start timer on connection */ |
Line 1129 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1082 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
/* Check for interrupt */ |
/* Check for interrupt */ |
if (HTThreadIntr(net->sockfd)) { |
if (HTThreadIntr(net->sockfd)) { |
if (NETCLOSE(net->sockfd) < 0) |
if (NETCLOSE(net->sockfd) < 0) |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "NETCLOSE"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno,NO,"NETCLOSE"); |
#ifdef EVENT_LOOP |
|
HTThreadState(net->sockfd, THD_CLOSE); |
HTThreadState(net->sockfd, THD_CLOSE); |
#endif /* EVENT_LOOP */ |
net->sockfd = INVSOC; |
net->sockfd = -1; |
|
free(p1); |
free(p1); |
return HT_INTERRUPTED; |
return HT_INTERRUPTED; |
} |
} |
Line 1160 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1111 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
* the normal case. |
* the normal case. |
*/ |
*/ |
#ifdef EAGAIN |
#ifdef EAGAIN |
if ((status < 0) && ((errno == EINPROGRESS) || (errno == EAGAIN))) |
if ((status < 0) && ((socerrno==EINPROGRESS) || (socerrno==EAGAIN))) |
#else |
#else |
if ((status < 0) && (errno == EINPROGRESS)) |
if ((status < 0) && (socerrno == EINPROGRESS)) |
#endif /* EAGAIN */ |
#endif /* EAGAIN */ |
{ |
{ |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. WOULD BLOCK `%s'\n", host); |
fprintf(TDEST, "HTDoConnect. WOULD BLOCK `%s'\n", host); |
#ifdef EVENT_LOOP |
|
HTThreadState(net->sockfd, THD_SET_WRITE); |
HTThreadState(net->sockfd, THD_SET_WRITE); |
#endif /* EVENT_LOOP */ |
|
free(p1); |
free(p1); |
return HT_WOULD_BLOCK; |
return HT_WOULD_BLOCK; |
} |
} |
if (net->addressCount >= 1) { |
if (net->addressCount >= 1) { |
net->connecttime = time(NULL) - net->connecttime; |
net->connecttime = time(NULL) - net->connecttime; |
if (status < 0) { |
if (status < 0) { |
if (errno == EISCONN) { /* connect multi after would block */ |
if (socerrno==EISCONN) { /* connect multi after would block */ |
#ifdef EVENT_LOOP |
|
HTThreadState(net->sockfd, THD_CLR_WRITE); |
HTThreadState(net->sockfd, THD_CLR_WRITE); |
#endif /* EVENT_LOOP */ |
|
HTTCPAddrWeights(host, net->connecttime); |
HTTCPAddrWeights(host, net->connecttime); |
free(p1); |
free(p1); |
net->addressCount = 0; |
net->addressCount = 0; |
return 0; |
return 0; |
} |
} |
HTErrorSysAdd(net->request, ERR_NON_FATAL, NO, "connect"); |
HTErrorSysAdd(net->request, ERR_NON_FATAL, socerrno, NO, |
|
"connect"); |
|
|
/* I have added EINVAL `invalid argument' as this is what I |
/* I have added EINVAL `invalid argument' as this is what I |
get back from a non-blocking connect where I should |
get back from a non-blocking connect where I should |
get `connection refused' */ |
get `connection refused' on SVR4 */ |
if (errno==ECONNREFUSED || errno==ETIMEDOUT || |
if (socerrno==ECONNREFUSED || socerrno==ETIMEDOUT || |
errno==ENETUNREACH || errno==EHOSTUNREACH || |
socerrno==ENETUNREACH || socerrno==EHOSTUNREACH || |
errno==EHOSTDOWN || errno==EINVAL) |
#ifdef __srv4__ |
|
socerrno==EHOSTDOWN || socerrno==EINVAL) |
|
#else |
|
socerrno==EHOSTDOWN) |
|
#endif |
net->connecttime += TCP_DELAY; |
net->connecttime += TCP_DELAY; |
else |
else |
net->connecttime += TCP_PENALTY; |
net->connecttime += TCP_PENALTY; |
if (NETCLOSE(net->sockfd) < 0) |
if (NETCLOSE(net->sockfd) < 0) |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "NETCLOSE"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno, NO, |
#ifdef EVENT_LOOP |
"NETCLOSE"); |
HTThreadState(net->sockfd, THD_CLOSE); |
HTThreadState(net->sockfd, THD_CLOSE); |
#endif /* EVENT_LOOP */ |
net->sockfd = INVSOC; |
net->sockfd = -1; |
|
HTTCPAddrWeights(host, net->connecttime); |
HTTCPAddrWeights(host, net->connecttime); |
} else { /* Connect on multi-homed */ |
} else { /* Connect on multi-homed */ |
HTTCPAddrWeights(host, net->connecttime); |
HTTCPAddrWeights(host, net->connecttime); |
Line 1210 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1161 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
return 0; |
return 0; |
} |
} |
} else if (status < 0) { |
} else if (status < 0) { |
if (errno == EISCONN) { /* Connect single after would block */ |
if (socerrno==EISCONN) { /* Connect single after would block */ |
#ifdef EVENT_LOOP |
|
HTThreadState(net->sockfd, THD_CLR_WRITE); |
HTThreadState(net->sockfd, THD_CLR_WRITE); |
#endif /* EVENT_LOOP */ |
|
net->addressCount = 0; |
net->addressCount = 0; |
free(p1); |
free(p1); |
return 0; |
return 0; |
} else { |
} else { |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "connect"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno, NO, |
|
"connect"); |
HTTCPCacheRemoveHost(host); |
HTTCPCacheRemoveHost(host); |
if (NETCLOSE(net->sockfd) < 0) |
if (NETCLOSE(net->sockfd) < 0) |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "NETCLOSE"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno, NO, |
#ifdef EVENT_LOOP |
"NETCLOSE"); |
HTThreadState(net->sockfd, THD_CLOSE); |
HTThreadState(net->sockfd, THD_CLOSE); |
#endif /* EVENT_LOOP */ |
|
break; |
break; |
} |
} |
} else { /* Connect on single homed */ |
} else { /* Connect on single homed */ |
Line 1235 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
Line 1184 PUBLIC int HTDoConnect ARGS5(HTNetInfo *
|
} while (--net->addressCount); |
} while (--net->addressCount); |
|
|
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoConnect. Connect failed\n"); |
fprintf(TDEST, "HTDoConnect. Connect failed\n"); |
free (p1); |
free (p1); |
net->addressCount = 0; |
net->addressCount = 0; |
net->sockfd = -1; |
net->sockfd = INVSOC; |
return -1; |
return -1; |
} |
} |
|
|
Line 1260 PUBLIC int HTDoAccept ARGS1(HTNetInfo *,
|
Line 1209 PUBLIC int HTDoAccept ARGS1(HTNetInfo *,
|
int status; |
int status; |
int cnt; |
int cnt; |
int soc_addrlen = sizeof(soc_address); |
int soc_addrlen = sizeof(soc_address); |
if (net->sockfd < 0) { |
if (net->sockfd==INVSOC) { |
if (PROT_TRACE) fprintf(stderr, "HTDoAccept.. Bad socket number\n"); |
if (PROT_TRACE) fprintf(TDEST, "HTDoAccept.. Bad socket number\n"); |
return -1; |
return -1; |
} |
} |
|
|
/* First make the socket non-blocking */ |
/* First make the socket non-blocking */ |
#ifdef VMS |
#if defined(_WINDOWS) || defined(VMS) |
#ifdef MULTINET |
|
{ |
{ |
int enable = 1; |
int enable = 1; /* Need the variable! */ |
status = socket_ioctl(net->sockfd, FIONBIO, &enable); |
status = IOCTL(net->sockfd, FIONBIO, enable); |
} |
} |
#endif /* MULTINET */ |
#else |
#else /* not VMS */ |
|
if((status = FCNTL(net->sockfd, F_GETFL, 0)) != -1) { |
if((status = FCNTL(net->sockfd, F_GETFL, 0)) != -1) { |
status |= FNDELAY; /* O_NDELAY; */ |
status |= O_NONBLOCK; /* POSIX */ |
status = FCNTL(net->sockfd, F_SETFL, status); |
status = FCNTL(net->sockfd, F_SETFL, status); |
} |
} |
#endif /* not VMS */ |
#endif |
if (status == -1) { |
if (status == -1) { |
HTErrorSysAdd(net->request, ERR_FATAL, NO, "fcntl"); |
HTErrorSysAdd(net->request, ERR_FATAL, socerrno, NO, "IOCTL"); |
return -1; |
return -1; |
} |
} |
|
|
/* Now poll every sekund */ |
/* Now poll every sekund */ |
for(cnt=0; cnt<MAX_ACCEPT_POLL; cnt++) { |
for(cnt=0; cnt<MAX_ACCEPT_POLL; cnt++) { |
if ((status = accept(net->sockfd, (struct sockaddr*) &soc_address, |
if ((status = accept(net->sockfd, (struct sockaddr*) &soc_address, |
&soc_addrlen)) >= 0) { |
&soc_addrlen)) != INVSOC) { |
if (PROT_TRACE) fprintf(stderr, |
if (PROT_TRACE) fprintf(TDEST, |
"HTDoAccept.. Accepted new socket %d\n", |
"HTDoAccept.. Accepted new socket %d\n", |
status); |
status); |
return status; |
return status; |
} else |
} else |
HTErrorSysAdd(net->request, ERR_WARNING, YES, "accept"); |
HTErrorSysAdd(net->request, ERR_WARN, socerrno, YES, "accept"); |
sleep(1); |
sleep(1); |
} |
} |
|
|
/* If nothing has happened */ |
/* If nothing has happened */ |
if (PROT_TRACE) |
if (PROT_TRACE) |
fprintf(stderr, "HTDoAccept.. Timed out, no connection!\n"); |
fprintf(TDEST, "HTDoAccept.. Timed out, no connection!\n"); |
HTErrorAdd(net->request, ERR_FATAL, NO, HTERR_TIME_OUT, NULL, 0, |
HTErrorAdd(net->request, ERR_FATAL, NO, HTERR_TIME_OUT, NULL, 0, |
"HTDoAccept"); |
"HTDoAccept"); |
return -1; |
return -1; |