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

📄 htwwwstr.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 2 页
字号:
	    tm.tm_hour = strtol(s, &s, 10);	    tm.tm_min = strtol(++s, &s, 10);	    tm.tm_sec = strtol(++s, &s, 10);	} else {					    /* Second format */	    HTTRACE(CORE_TRACE, "Format...... Wkd, 00 Mon 0000 00:00:00 GMT\n");	    if ((int)strlen(s) < 20) {		HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format \"%s\"\n" _ s);		return 0;	    }	    tm.tm_mday = strtol(s, &s, 10);	    tm.tm_mon = make_month(s, &s);	    tm.tm_year = strtol(s, &s, 10) - 1900;	    tm.tm_hour = strtol(s, &s, 10);	    tm.tm_min = strtol(++s, &s, 10);	    tm.tm_sec = strtol(++s, &s, 10);	}    } else if (isdigit((int) *str)) {	if (strchr(str, 'T')) {		        /* ISO (limited format) date string */	    HTTRACE(CORE_TRACE, "Format...... YYYY.MM.DDThh:mmStzWkd\n");	    s = (char *) str;	    while (*s && *s==' ') s++;	    if ((int)strlen(s) < 21) {		HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format `%s\'\n" _ s);		return 0;	    }	    tm.tm_year = strtol(s, &s, 10) - 1900;	    tm.tm_mon  = strtol(++s, &s, 10);	    tm.tm_mday = strtol(++s, &s, 10);	    tm.tm_hour = strtol(++s, &s, 10);	    tm.tm_min  = strtol(++s, &s, 10);	    tm.tm_sec  = strtol(++s, &s, 10);	} else {					    /* delta seconds */	    t = expand ? time(NULL) + atol(str) : atol(str);#ifdef HTDEBUG	    if (CORE_TRACE) {		if (expand) {#if defined (HAVE_CTIME_R_2)		    char buffer[CTIME_MAX];		    HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _			    str _ (long) t _ (char *) ctime_r(&t, buffer));#elif defined(HAVE_CTIME_R_3)		    char buffer[CTIME_MAX];		    HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _			    str _ (long) t _ (char *) ctime_r(&t, buffer, CTIME_MAX));#else		    HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _			    str _ (long) t _ ctime(&t));#endif /* HT_REENTRANT */		} else {		    HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds\n" _ str _ (long) t);		}	    }#endif /* HT_DEBUG */	    return t;	}    } else {	      /* Try the other format:  Wed Jun  9 01:29:59 1993 GMT */	HTTRACE(CORE_TRACE, "Format...... Wkd Mon 00 00:00:00 0000 GMT\n");	s = (char *) str;	while (*s && *s==' ') s++;	HTTRACE(CORE_TRACE, "Trying...... The Wrong time format: %s\n" _ s);	if ((int)strlen(s) < 24) {	    HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format \"%s\"\n" _ s);	    return 0;	}	tm.tm_mon = make_month(s, &s);	tm.tm_mday = strtol(s, &s, 10);	tm.tm_hour = strtol(s, &s, 10);	tm.tm_min = strtol(++s, &s, 10);	tm.tm_sec = strtol(++s, &s, 10);	tm.tm_year = strtol(s, &s, 10) - 1900;    }    if (tm.tm_sec  < 0  ||  tm.tm_sec  > 59  ||	tm.tm_min  < 0  ||  tm.tm_min  > 59  ||	tm.tm_hour < 0  ||  tm.tm_hour > 23  ||	tm.tm_mday < 1  ||  tm.tm_mday > 31  ||	tm.tm_mon  < 0  ||  tm.tm_mon  > 11  ||	tm.tm_year <70  ||  tm.tm_year >120) {	HTTRACE(CORE_TRACE, "ERROR....... Parsed illegal time: %02d.%02d.%02d %02d:%02d:%02d\n" _ 	       tm.tm_mday _ tm.tm_mon+1 _ tm.tm_year _ 	       tm.tm_hour _ tm.tm_min _ tm.tm_sec);	return 0;    }#if 0#if defined(HAVE_TIMEZONE) && defined(HAVE_ALTZONE)    tm.tm_isdst = daylight;		       /* Already taken into account */    HTTRACE(CORE_TRACE, "Time string. Daylight is %s\n" _	    daylight>0 ? "on" : daylight==0 ? "off" : "unknown");#endif#else    /* Let mktime decide whether we have DST or not */    tm.tm_isdst = -1;#endif#ifdef HAVE_MKTIME    t = mktime(&tm);    t += (up ? HTUserProfile_timezone(up) : HTGetTimeZoneOffset());#else#ifdef HAVE_TIMEGM    t = timegm(&tm);#else#error "Neither mktime nor timegm defined"#endif /* HAVE_TIMEGM */#endif /* HAVE_MKTIME */    HTTRACE(CORE_TRACE, "Time string. %s parsed to %ld calendar time or `%s' in local time\n" _ 		str _ (long) t _ ctime(&t));    return t;}/***	Returns a string pointer to a static area of the current calendar**	time in RFC 1123 format, for example****		Sun, 06 Nov 1994 08:49:37 GMT****	The result can be given in both local and GMT dependent on the flag*/PUBLIC const char *HTDateTimeStr (time_t * calendar, BOOL local){    static char buf[40];#ifdef HAVE_STRFTIME    if (local) {	/*	** Solaris 2.3 has a bug so we _must_ use reentrant version	** Thomas Maslen <tmaslen@verity.com>	*/#if defined(HT_REENTRANT) || defined(SOLARIS)	struct tm loctime;	localtime_r(calendar, &loctime);	strftime(buf, 40, "%a, %d %b %Y %H:%M:%S", &loctime);#else	struct tm *loctime = localtime(calendar);	strftime(buf, 40, "%a, %d %b %Y %H:%M:%S", loctime);#endif /* SOLARIS || HT_REENTRANT */    } else {#if defined(HT_REENTRANT) || defined(SOLARIS)	struct tm gmt;	gmtime_r(calendar, &gmt);    	strftime(buf, 40, "%a, %d %b %Y %H:%M:%S GMT", &gmt);#else	struct tm *gmt = gmtime(calendar);    	strftime(buf, 40, "%a, %d %b %Y %H:%M:%S GMT", gmt);#endif /* SOLARIS || HT_REENTRANT */    }#else    if (local) {#if defined(HT_REENTRANT)	struct tm loctime;	localtime_r(calendar, &loctime);#else	struct tm *loctime = localtime(calendar);#endif /* HT_REENTRANT */	sprintf(buf,"%s, %02d %s %04d %02d:%02d:%02d",		wkdays[loctime->tm_wday],		loctime->tm_mday,		months[loctime->tm_mon],		loctime->tm_year + 1900,		loctime->tm_hour,		loctime->tm_min,		loctime->tm_sec);    } else {#if defined(HT_REENTRANT) || defined(SOLARIS)	struct tm gmt;	gmtime_r(calendar, &gmt);#else	struct tm *gmt = gmtime(calendar);#endif	sprintf(buf,"%s, %02d %s %04d %02d:%02d:%02d GMT",		wkdays[gmt->tm_wday],		gmt->tm_mday,		months[gmt->tm_mon],		gmt->tm_year + 1900,		gmt->tm_hour,		gmt->tm_min,		gmt->tm_sec);    }#endif    return buf;}/*	HTDateDirStr**	------------**	Generates a date string used in directory listings*/PUBLIC BOOL HTDateDirStr (time_t * time, char * str, int len){#ifdef HAVE_STRFTIME#if defined(HT_REENTRANT) || defined(SOLARIS)    struct tm loctime;    localtime_r(time, &loctime);    strftime(str, len, "%d-%b-%Y %H:%M", &loctime);    return YES;#else    strftime(str, len, "%d-%b-%Y %H:%M", localtime(time));    return YES;#endif /* HT_REENTRANT || SOLARIS */#else    if (len >= 16) {	struct tm *loctime = localtime(time);	sprintf(str,"%02d-%s-%02d %02d:%02d",		loctime->tm_mday,		months[loctime->tm_mon],		loctime->tm_year % 100,		loctime->tm_hour,		loctime->tm_min);	return YES;    }    return NO;#endif /* HAVE_STRFTIME */		}/* 							     	HTNumToStr**	Converts a long (byte count) to a string**	----------------------------------------**	This function was a PAIN!  In computer-world 1K is 1024 bytes**	and 1M is 1024K -- however, sprintf() still formats in base-10.**	Therefore I output only until 999, and then start using the**	next unit.  This doesn't work wrong, it's just a feature.**	The "str" must be large enough to contain the result.*/PUBLIC void HTNumToStr (unsigned long n, char * str, int len){    double size = n/1024.0;    if (len < 6) {	*str = '\0';	return;    }    if (n < 1000)	sprintf(str, "%dK", n>0 ? 1 : 0);    else if (size + 0.999 < 1000)	sprintf(str, "%dK", (int)(size + 0.5));    else if ((size /= 1024) < 9.9)	sprintf(str, "%.1fM", (size + 0.05));    else if (size < 1000)	sprintf(str, "%dM", (int)(size + 0.5));    else if ((size /= 1024) < 9.9)	sprintf(str, "%.1fG", (size + 0.05));    else	sprintf(str, "%dG", (int)(size + 0.5));}/***	Matches MIME constructions for content-types and others like**	them, for example "text/html", "text/plain". It can also match**	wild cards like "text/<star>" and "<star>/<star>. We use <star>**	instead of * in order note to make C like comments :-)*/PUBLIC BOOL HTMIMEMatch (HTAtom * tmplate, HTAtom * actual){    const char *t, *a;    char *st, *sa;    BOOL match = NO;    if (tmplate && actual && (t = HTAtom_name(tmplate))) {	if (!strcmp(t, "*"))	    return YES;	if (strchr(t, '*') &&	    (a = HTAtom_name(actual)) &&	    (st = strchr(t, '/')) && (sa = strchr(a,'/'))) {	    *sa = 0;	    *st = 0;	    if ((*(st-1)=='*' &&		 (*(st+1)=='*' || !strcasecomp(st+1, sa+1))) ||		(*(st+1)=='*' && !strcasecomp(t,a)))		match = YES;	    *sa = '/';	    *st = '/';	}        }    return match;}/*	Convert file URLs into a local representation**	---------------------------------------------**	The URL has already been translated through the rules in get_physical**	in HTAccess.c and all we need to do now is to map the path to a local**	representation, for example if must translate '/' to the ones that**	turn the wrong way ;-)**	Returns:**		OK:	local file (that must be freed by caller)**		Error:	NULL*/PUBLIC char * HTWWWToLocal (const char * url, const char * base,			    HTUserProfile * up){    if (url) {	char * access = HTParse(url, base, PARSE_ACCESS);	char * host = HTParse(url, base, PARSE_HOST);	char * path = HTParse(url, base, PARSE_PATH+PARSE_PUNCTUATION);	const char * myhost = HTUserProfile_fqdn(up);	/* Find out if this is a reference to the local file system */	if ((*access && strcmp(access, "file") && strcmp(access, "cache")) ||	     (*host && strcasecomp(host, "localhost") &&	      myhost && strcmp(host, myhost))) {	    HTTRACE(CORE_TRACE, "LocalName... Not on local file system\n");	    HT_FREE(access);	    HT_FREE(host);	    HT_FREE(path);	    return NULL;	} else {	    char *ptr;	    if ((ptr = strchr(path, ';')) || (ptr = strchr(path, '?')))		*ptr = '\0';		    /*	    ** Do whatever translation is required here in order to fit your	    ** platform _before_ the path is unescaped.	    */#ifdef VMS	    HTVMS_checkDecnet(path);#endif#ifdef WWW_MSWINDOWS	    /* An absolute pathname with logical drive */            if (*path == '/' && path[2] == ':') {		char *orig=path, *dest=path+1;		while((*orig++ = *dest++));	    /* A network host */            } else if (*host && strcasecomp(host, "localhost")) {		char * newpath = NULL;		StrAllocMCopy(&newpath, "//", host, path, NULL);		HT_FREE(path);		path = newpath;	    }	    /* Convert '/' to '\' */	    {		char *p = path;		while (*p) {		    if (*p=='/') *p='\\';		    p++;		}	    }#endif	    	    HTUnEscape(path);		  /* Take out the escaped characters */	    HTTRACE(CORE_TRACE, "Node........ `%s' means path `%s'\n" _ url _ path);	    HT_FREE(access);	    HT_FREE(host);	    return path;	}    }    return NULL;}/*	Convert a local file name into a URL**	------------------------------------**	Generates a WWW URL name from a local file name or NULL if error.**	Returns:**		OK:	local file (that must be freed by caller)**		Error:	NULL*/PUBLIC char * HTLocalToWWW (const char * local, const char * access){    char * escaped = NULL;    const char * scheme = (access && *access) ? access : "file:";     if (local && *local) {#ifdef VMS         char * unescaped = NULL;        if ((unescaped = (char *) HT_MALLOC(strlen(local) + 10)) == NULL)            HT_OUTOFMEM("HTLocalToWWW");        strcpy(unescaped, scheme);	     /* We get an absolute file name */	/* convert directory name to Unix-style syntax */	{	    char * disk = strchr (local, ':');	    char * dir = strchr (local, '[');	    if (disk) {		*disk = '\0';		strcat(unescaped, "/");		strcat(unescaped, local);	    }	    if (dir) {		char *p;		*dir = '/';	/* Convert leading '[' */		for (p = dir ; *p != ']'; ++p)		    if (*p == '.') *p = '/';		*p = '\0';	/* Cut on final ']' */		strcat(unescaped, dir);	    }	}        escaped = HTEscape(unescaped, URL_DOSFILE);        HT_FREE(unescaped);#else  /* not VMS */#ifdef WIN32        char * unescaped = NULL;        if ((unescaped = (char *) HT_MALLOC(strlen(local) + 10)) == NULL)            HT_OUTOFMEM("HTLocalToWWW");        strcpy(unescaped, scheme);	     /* We get an absolute file name */        if (strchr(local, ':')) strcat(unescaped, "/");        {            const char *p = local;            char *q = unescaped+strlen(unescaped);            while (*p) {                if (*p=='\\') {                    *q++='/';                } else                    *q++=*p;                p++;            }            *q = '\0';	}        escaped = HTEscape(unescaped, URL_DOSFILE);        HT_FREE(unescaped);#else  /* Unix */        char * escaped_path = HTEscape(local, URL_PATH);	escaped = StrAllocMCopy(&escaped, scheme, escaped_path, NULL);        HT_FREE(escaped_path);#endif /* not WIN32 */#endif /* not VMS */    }    return escaped;}

⌨️ 快捷键说明

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