⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htinet.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 2 页
字号:
		    }		}	    }	    fclose(fp);	}    }#endif /* RESOLV_CONF */#ifdef HAVE_GETDOMAINNAME    /* If everything else has failed then try getdomainname */    if (fqdn==1) {	if (getdomainname(name, MAXHOSTNAMELEN)) {	    HTTRACE(CORE_TRACE, "HostName.... Can't get domain name\n");	    StrAllocCopy(hostname, "");	    return NULL;	}	/* If the host name and the first part of the domain name are different	   then use the former as it is more exact (I guess) */	if (strncmp(name, hostname, (int) strlen(hostname))) {	    char *domain = strchr(name, '.');	    if (!domain)		domain = name;	    StrAllocCat(hostname, domain);	}    }#endif /* HAVE_GETDOMAINNAME */    if (hostname) {	char *strptr = hostname;	while (*strptr) {	    	    *strptr = TOLOWER(*strptr);	    strptr++;	}	if (*(hostname+strlen(hostname)-1) == '.')    /* Remove trailing dot */	    *(hostname+strlen(hostname)-1) = '\0';	HTTRACE(CORE_TRACE, "HostName.... FQDN is `%s\'\n" _ hostname);    }    return hostname;}/*							       HTGetMailAddress****	Get the mail address of the current user on the current host. The**	domain name used is the one initialized in HTSetHostName or**	HTGetHostName. The login name is determined using (ordered):****		getlogin**		getpwuid(getuid())****	The weakness about the last attempt is if the user has multiple**	login names each with the same user ID. If this fails as well then:****		LOGNAME environment variable**		USER environment variable****	Returns NULL or string to be freed by caller*/PUBLIC char * HTGetMailAddress (void){#ifdef HT_REENTRANT  char name[HT_LOGNAME_MAX];    /* For getlogin_r or getUserName */  int result;#endif#ifdef WWW_MSWINDOWS/* what was the plan for this under windows? - EGP */  char name[256];    /* For getlogin_r or getUserName */  unsigned int bufSize = sizeof(name);#endif#ifdef HAVE_PWD_H    struct passwd * pw_info = NULL;#endif    char * login = NULL;#ifdef WWW_MSWINDOWS    if (!login && GetUserName(name, &bufSize) != TRUE)        HTTRACE(CORE_TRACE, "MailAddress. GetUsername returns NO\n");#endif /* WWW_MSWINDOWS */#ifdef HAVE_CUSERID    if (!login && (login = (char *) cuserid(NULL)) == NULL)        HTTRACE(CORE_TRACE, "MailAddress. cuserid returns NULL\n");#endif /* HAVE_CUSERID */#ifdef HAVE_GETLOGIN#ifdef GETLOGIN_R_RETURNS_POINTER    if (!login && (login = (char *) getlogin_r(name, HT_LOGNAME_MAX)) == NULL)#elif defined(GETLOGIN_R_RETURNS_INT)    if (!login && (result = getlogin_r(name, HT_LOGNAME_MAX)) == 0)    {	login = &name[0];    }    else#else    if (!login && (login = (char *) getlogin()) == NULL)#endif /* HT_REENTRANT */	HTTRACE(CORE_TRACE, "MailAddress. getlogin returns NULL\n");#endif /* HAVE_GETLOGIN */#ifdef HAVE_PWD_H    if (!login && (pw_info = getpwuid(getuid())) != NULL)	login = pw_info->pw_name;#endif /* HAVE_PWD_H */    if (!login && (login = getenv("LOGNAME")) == NULL)	HTTRACE(CORE_TRACE, "MailAddress. LOGNAME not found\n");    if (!login && (login = getenv("USER")) == NULL)	HTTRACE(CORE_TRACE, "MailAddress. USER not found\n");    if (!login) login = HT_DEFAULT_LOGIN;    if (login) {	char * domain = NULL;	char * mailaddress = NULL;	StrAllocCopy(mailaddress, login);	StrAllocCat(mailaddress, "@");	if ((domain = HTGetHostName()) != NULL) {	    StrAllocCat(mailaddress, domain);	    HT_FREE(domain);	}	return mailaddress;    }    return NULL;}/***	Except on the NeXT, we pick up the NewsHost name from****	1.	Environment variable NNTPSERVER**	2.	File SERVER_FILE**	3.	Compilation time macro DEFAULT_NEWS_HOST****	On the NeXT, we pick up the NewsHost name from, in order:****	1.	WorldWideWeb default "NewsHost"**	2.	News default "NewsHost"**	3.	Compilation time macro DEFAULT_NEWS_HOST****	Returns NULL or string to be freed by caller*/PUBLIC char * HTGetNewsServer (void){    char * newshost = NULL;    char buffer[80];#ifdef NeXTStep    if ((newshost = NXGetDefaultValue("WorldWideWeb","NewsHost")) == 0)	if ((newshost = NXGetDefaultValue("News","NewsHost")) == 0)	    newshost = DEFAULT_NEWS_HOST;#else    if ((newshost = (char *) getenv("NNTPSERVER")) == NULL) {	FILE *fp = fopen(SERVER_FILE, "r");	*(buffer+79) = '\0';	if (fp) {	    if (fgets(buffer, 79, fp)) {		char *end;		newshost = buffer;		while (*newshost == ' ' || *newshost == '\t')		    newshost++;		end = newshost;		while (*end && !isspace((int) *end))		    end++;		*end = '\0';	    }	    fclose(fp);	}    }#endif /* NestStep */    /* Last resort */    if (!newshost || !*newshost) newshost = DEFAULT_NEWS_HOST;    /* Canonicalize host name */    {	char * result = NULL;	StrAllocCopy(result, newshost);	{	    char * strptr = result;	    while (*strptr) {		*strptr = TOLOWER(*strptr);		strptr++;	    }	}	return result;    }}/*	Timezone Offset**	---------------**	Calculates the offset from GMT in seconds*/PUBLIC time_t HTGetTimeZoneOffset (void){    static time_t HTTimeZone = -1;		  /* Invalid timezone offset */    if (HTTimeZone != -1) return HTTimeZone;		     /* Already done */#ifdef HAVE_TIMEZONE    {	time_t cur_t = time(NULL);#ifdef HT_REENTRANT	struct tm loctime;	struct tm *local = (struct tm *) localtime_r(&cur_t, &loctime);#else	struct tm *local = localtime(&cur_t);#endif /* HT_REENTRANT */#ifdef HAVE_DAYLIGHT	if (daylight && local->tm_isdst>0) {		   /* daylight time? */#else	if (local->tm_isdst>0) {			   /* daylight time? */#endif /* HAVE_DAYLIGHT */#ifdef HAVE_ALTZONE	    HTTimeZone = altzone;#else 	    /* Assumes a fixed DST offset of 1 hour, which is probably wrong */#ifdef __CYGWIN__ 	    HTTimeZone = _timezone - 3600;#else 	    HTTimeZone = timezone - 3600;#endif#endif /* HAVE_ALTZONE */	} else {						       /* no */#ifdef __CYGWIN__	    HTTimeZone = _timezone;#else	    HTTimeZone = timezone;#endif	}	HTTimeZone = -HTTimeZone;	HTTRACE(CORE_TRACE, "TimeZone.... GMT + (%02d) hours (including DST)\n" _ 		    (int) HTTimeZone/3600);    }#else#ifdef HAVE_TM_GMTOFF    {	time_t cur_t = time(NULL);#ifdef HT_REENTRANT	struct tm loctime;	localtime_r(&cur_t, &loctime);#else	struct tm * local = localtime(&cur_t);#endif /* HT_REENTRANT */	HTTimeZone = local->tm_gmtoff;	HTTRACE(CORE_TRACE, "TimeZone.... GMT + (%02d) hours (including DST)\n" _ 		    (int)local->tm_gmtoff / 3600);    }#else    HTTRACE(CORE_TRACE, "TimeZone.... Not defined\n");#endif /* HAVE_TM_GMTOFF */#endif /* HAVE_TIMEZONE */    return HTTimeZone;}/***	Finds a temporary name in in the directory given. If the directory**	is NULL then don't prepend anything.**	If success, the result must be freed by caller, else we return NULL*/PUBLIC char * HTGetTmpFileName (const char * abs_dir){    char * result = NULL;#ifdef HAVE_TEMPNAM    static char * envtmpdir = NULL;    size_t len = 0;    if (abs_dir && *abs_dir) {      char * tmpdir = getenv("TMPDIR");      if (tmpdir)          len = strlen(tmpdir);      if (len) {          if (!(envtmpdir = (char *) HT_REALLOC(envtmpdir, len + 8)))              HT_OUTOFMEM("HTGetTmpFileName");          strcpy(envtmpdir, "TMPDIR=");          strcpy(envtmpdir + 7, tmpdir);          putenv("TMPDIR=");      }    }#ifdef __CYGWIN__    result = tempnam(abs_dir, "");#else    result = tempnam(abs_dir, NULL);#endif /* __CYGWIN__ */    if (len)      putenv(envtmpdir);#else    /*    **  This is only approx. as we don't know if this file exists or not.    **  Hopefully, tempnam() exists on enough platforms so that this is not    **  a problem.    */    char * offset = NULL;    if (!(result = (char *) HT_MALLOC((abs_dir ? strlen(abs_dir) : 0) +				      HT_MAX_TMPNAM + 2)))	HT_OUTOFMEM("HTGetTmpFileName");#ifdef WWW_MSWINDOWS    if (abs_dir) {#else    if (abs_dir && *abs_dir==DIR_SEPARATOR_CHAR) {#endif /* WWW_MSWINDOWS */	strcpy(result, abs_dir);	offset = result+strlen(result);	if (*(offset-1) != DIR_SEPARATOR_CHAR) *offset++ = DIR_SEPARATOR_CHAR;#ifdef HT_REENTRANT	tmpnam_r(offset);#else	tmpnam(offset);#endif	{	    char * orig = strrchr(offset, DIR_SEPARATOR_CHAR);	    char * dest = offset;	    if (orig++) while ((*dest++ = *orig++));	}    } else {	offset = result;#ifdef HT_REENTRANT	tmpnam_r(offset);#else	tmpnam(offset);#endif	offset = result;    }#endif /* HAVE_TEMPNAM */    return result;}/***  Copied from X utilities*/PUBLIC ms_t HTGetTimeInMillis (void){#ifdef WWW_MSWINDOWS    return GetTickCount();#else /* WWW_MSWINDOWS */#ifdef HAVE_GETTIMEOFDAY    struct timeval tp;    gettimeofday(&tp, NULL);    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);#else    return((ms_t) 0);#endif#endif /* !WWW_MSWINDOWS */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -