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

📄 lyutils.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *  A file URL for a remote host is an obsolete ftp URL. *  Return YES only if we're certain it's a local file. - FM */PUBLIC BOOLEAN LYisLocalFile ARGS1(	char *, 	filename){    char *host = NULL;    char *acc_method = NULL;    char *cp;    if (!filename)	return NO;    if (!(host = HTParse(filename, "", PARSE_HOST)))	return NO;    if (!*host) {	FREE(host);	return NO;    }    if ((cp=strchr(host, ':')) != NULL)	*cp = '\0';    if ((acc_method = HTParse(filename, "", PARSE_ACCESS))) {	if (0==strcmp("file", acc_method) &&	    (0==strcmp(host, "localhost") ||#ifdef VMS	     0==strcasecomp(host, HTHostName())))#else	     0==strcmp(host, HTHostName())))#endif /* VMS */	{	    FREE(host);	    FREE(acc_method);	    return YES;	}    }    FREE(host);    FREE(acc_method);    return NO;}/* *  Utility for checking URLs with a host field. *  Return YES only if we're certain it's the local host. - FM */PUBLIC BOOLEAN LYisLocalHost ARGS1(	char *, 	filename){    char *host = NULL;    char *cp;    if (!filename)	return NO;    if (!(host = HTParse(filename, "", PARSE_HOST)))	return NO;    if (!*host) {	FREE(host);	return NO;    }    if ((cp = strchr(host, ':')) != NULL)	*cp = '\0';#ifdef VMS    if ((0==strcasecomp(host, "localhost") ||	 0==strcasecomp(host, LYHostName) ||	 0==strcasecomp(host, HTHostName()))) {#else    if ((0==strcmp(host, "localhost") ||	 0==strcmp(host, LYHostName) ||	 0==strcmp(host, HTHostName()))) {#endif /* VMS */	    FREE(host);	    return YES;    }    FREE(host);    return NO;}/* *  Utility for freeing the list of local host aliases. - FM */PUBLIC void LYLocalhostAliases_free NOARGS{    char *alias;    HTList *cur = localhost_aliases;    if (!cur)	return;    while (NULL != (alias = (char *)HTList_nextObject(cur))) {	FREE(alias);    }    HTList_delete(localhost_aliases);    localhost_aliases = NULL;    return;}/* *  Utility for listing hosts to be treated as local aliases. - FM */PUBLIC void LYAddLocalhostAlias ARGS1(	char *, 	alias){    char *LocalAlias;    if (!(alias && *alias))	return;    if (!localhost_aliases) {	localhost_aliases = HTList_new();	atexit(LYLocalhostAliases_free);    }    if ((LocalAlias = (char *)calloc(1, (strlen(alias) + 1))) == NULL)	outofmem(__FILE__, "HTAddLocalhosAlias");    strcpy(LocalAlias, alias);    HTList_addObject(localhost_aliases, LocalAlias);    return;}/* *  Utility for checking URLs with a host field. *  Return YES only if we've listed the host as a local alias. - FM */PUBLIC BOOLEAN LYisLocalAlias ARGS1(	char *, 	filename){    char *host = NULL;    char *alias;    char *cp;    HTList *cur = localhost_aliases;    if (!cur || !filename)	return NO;    if (!(host = HTParse(filename, "", PARSE_HOST)))	return NO;    if (!(*host)) {	FREE(host);	return NO;    }    if ((cp = strchr(host, ':')) != NULL)	*cp = '\0';    while (NULL != (alias = (char *)HTList_nextObject(cur))) {#ifdef VMS	if (0==strcasecomp(host, alias)) {#else	if (0==strcmp(host, alias)) {#endif /* VMS */	    FREE(host);	    return YES;	}    }    FREE(host);    return NO;}/***  This function checks for a URL with an unknown scheme,**  but for which proxying has been set up, and if so,**  returns PROXY_URL_TYPE. - FM****  If a colon is present but the string segment which**  precedes it is not being proxied, and we can rule**  out that what follows the colon is not a port field,**  it returns UNKNOWN_URL_TYPE.  Otherwise, it returns**  0 (not a URL). - FM*/PUBLIC int LYCheckForProxyURL ARGS1(	char *, 	filename){    char *cp = filename;    char *cp1;    char *cp2 = NULL;    /*     *	Don't crash on an empty argument.     */    if (cp == NULL || *cp == '\0')	return(0);    /* kill beginning spaces */    while (isspace((unsigned char)*cp))	cp++;    /*     * Check for a colon, and if present,     * see if we have proxying set up.     */    if ((cp1 = strchr((cp+1), ':')) != NULL) {	*cp1 = '\0';	StrAllocCopy(cp2, cp);	*cp1 = ':';	StrAllocCat(cp2, "_proxy");	if (getenv(cp2) != NULL) {	    FREE(cp2);	    return(PROXY_URL_TYPE);	}	FREE(cp2);	cp1++;	if (isdigit((unsigned char)*cp1)) {	    while (*cp1 && isdigit((unsigned char)*cp1))		cp1++;	    if (*cp1 && *cp1 != '/')		return(UNKNOWN_URL_TYPE);	}    }    return(0);}/***  Must recognize a URL and return the type.**  If recognized, based on a case-insensitive**  analyis of the scheme field, ensures that**  the scheme field has the expected case.****  Returns 0 (not a URL) for a NULL argument,**  one which lacks a colon.****  Chains to LYCheckForProxyURL() if a colon**  is present but the type is not recognized.*/PUBLIC int is_url ARGS1(	char *, 	filename){    char *cp = filename;    char *cp1;    int i;    /*     *	Don't crash on an empty argument.     */    if (cp == NULL || *cp == '\0')	return(0);    /*     *	Can't be a URL if it lacks a colon.     */    if (NULL == strchr(cp, ':'))	return(0);    /*     *	Kill beginning spaces.     */    while (isspace((unsigned char)*cp))	cp++;    /*     *	Can't be a URL if it starts with a slash.     *	So return immediately for this common case,     *	also to avoid false positives if there was     *	a colon later in the string. - KW     */    if (*cp == '/')	return(0);#ifdef DOSPATH /* sorry! */	if (strncmp(cp, "file:///", 8) && strlen(cp) == 19 &&	    cp[strlen(cp)-1] == ':')	    StrAllocCat(cp,"/");#endif    if (!strncasecomp(cp, "news:", 5)) {	if (strncmp(cp, "news", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NEWS_URL_TYPE);    } else if (!strncasecomp(cp, "nntp:", 5)) {	if (strncmp(cp, "nntp", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NNTP_URL_TYPE);    } else if (!strncasecomp(cp, "snews:", 6)) {	if (strncmp(cp, "snews", 5)) {	    for (i = 0; i < 5; i++)		cp[i] = TOLOWER(cp[i]);	}	return(SNEWS_URL_TYPE);    } else if (!strncasecomp(cp, "newspost:", 9)) {	/*	 *  Special Lynx type to handle news posts.	 */	if (strncmp(cp, "newspost", 8)) {	    for (i = 0; i < 8; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NEWSPOST_URL_TYPE);    } else if (!strncasecomp(cp, "newsreply:", 10)) {	/*	 *  Special Lynx type to handle news replies (followups).	 */	if (strncmp(cp, "newsreply", 9)) {	    for (i = 0; i < 9; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NEWSREPLY_URL_TYPE);    } else if (!strncasecomp(cp, "snewspost:", 10)) {	/*	 *  Special Lynx type to handle snews posts.	 */	if (strncmp(cp, "snewspost", 9)) {	    for (i = 0; i < 9; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NEWSPOST_URL_TYPE);    } else if (!strncasecomp(cp, "snewsreply:", 11)) {	/*	 *  Special Lynx type to handle snews replies (followups).	 */	if (strncmp(cp, "snewsreply", 10)) {	    for (i = 0; i < 10; i++)		cp[i] = TOLOWER(cp[i]);	}	return(NEWSREPLY_URL_TYPE);    } else if (!strncasecomp(cp, "mailto:", 7)) {	if (strncmp(cp, "mailto", 6)) {	    for (i = 0; i < 6; i++)		cp[i] = TOLOWER(cp[i]);	}	return(MAILTO_URL_TYPE);    } else if (!strncasecomp(cp, "file:", 5)) {	if (strncmp(cp, "file", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	if (LYisLocalFile(cp)) {	    return(FILE_URL_TYPE);	} else if (cp[5] == '/' && cp[6] == '/') {	    return(FTP_URL_TYPE);	} else {	    return(0);	}    } else if (!strncasecomp(cp, "data:", 5)) {	if (strncmp(cp, "data", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	return(DATA_URL_TYPE);    } else if (!strncasecomp(cp, "lynxexec:", 9)) {	/*	 *  Special External Lynx type to handle execution	 *  of commands or scripts which require a pause to	 *  read the screen upon completion.	 */	if (strncmp(cp, "lynxexec", 8)) {	    for (i = 0; i < 8; i++)		cp[i] = TOLOWER(cp[i]);	}	return(LYNXEXEC_URL_TYPE);    } else if (!strncasecomp(cp, "lynxprog:", 9)) {	/*	 *  Special External Lynx type to handle execution	 *  of commans, sriptis or programs with do not	 *  require a pause to read screen upon completion.	 */	if (strncmp(cp, "lynxprog", 8)) {	    for (i = 0; i < 8; i++)		cp[i] = TOLOWER(cp[i]);	}	return(LYNXPROG_URL_TYPE);    } else if (!strncasecomp(cp, "lynxcgi:", 8)) {	/*	 *  Special External Lynx type to handle cgi scripts.	 */	if (strncmp(cp, "lynxcgi", 7)) {	    for (i = 0; i < 7; i++)		cp[i] = TOLOWER(cp[i]);	}	return(LYNXCGI_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXPRINT:", 10)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXPRINT", 9)) {	    for (i = 0; i < 9; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXPRINT_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXDOWNLOAD:", 13)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYDOWNLOAD", 12)) {	    for (i = 0; i < 12; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXDOWNLOAD_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXDIRED:", 10)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXDIRED", 9)) {	    for (i = 0; i < 9; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXDIRED_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXHIST:", 9)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXHIST", 8)) {	    for (i = 0; i < 8; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXHIST_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXKEYMAP:", 11)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXKEYMAP", 10)) {	    for (i = 0; i < 10; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXKEYMAP_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXIMGMAP:", 11)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXIMGMAP", 10)) {	    for (i = 0; i < 10; i++)		cp[i] = TOUPPER(cp[i]);	}	(void)is_url(&cp[11]);	return(LYNXIMGMAP_URL_TYPE);    } else if (!strncasecomp(cp, "LYNXCOOKIE:", 11)) {	/*	 *  Special Internal Lynx type.	 */	if (strncmp(cp, "LYNXCOOKIE", 10)) {	    for (i = 0; i < 10; i++)		cp[i] = TOUPPER(cp[i]);	}	return(LYNXCOOKIE_URL_TYPE);    } else if (strstr((cp+3), "://") == NULL) {	/*	 *  If it doesn't contain "://", and it's not one of the	 *  the above, it can't be a URL with a scheme we know,	 *  so check if it's an unknown scheme for which proxying	 *  has been set up. - FM	 */	return(LYCheckForProxyURL(filename));    } else if (!strncasecomp(cp, "http:", 5)) {	if (strncmp(cp, "http", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	return(HTTP_URL_TYPE);    } else if (!strncasecomp(cp, "https:", 6)) {	if (strncmp(cp, "https", 5)) {	    for (i = 0; i < 5; i++)		cp[i] = TOLOWER(cp[i]);	}	return(HTTPS_URL_TYPE);    } else if (!strncasecomp(cp, "gopher:", 7)) {	if (strncmp(cp, "gopher", 6)) {	    for (i = 0; i < 6; i++)		cp[i] = TOLOWER(cp[i]);	}	if ((cp1 = strchr(cp+11,'/')) != NULL) {	    if (TOUPPER(*(cp1+1)) == 'H' || *(cp1+1) == 'w')		/* if this is a gopher html type */		return(HTML_GOPHER_URL_TYPE);	    else if (*(cp1+1) == 'T' || *(cp1+1) == '8')		return(TELNET_GOPHER_URL_TYPE);	    else if (*(cp1+1) == '7')		return(INDEX_GOPHER_URL_TYPE);	    else		return(GOPHER_URL_TYPE);	} else {	    return(GOPHER_URL_TYPE);	}    } else if (!strncasecomp(cp, "ftp:", 4)) {	if (strncmp(cp, "ftp", 3)) {	    for (i = 0; i < 3; i++)		cp[i] = TOLOWER(cp[i]);	}	return(FTP_URL_TYPE);    } else if (!strncasecomp(cp, "wais:", 5)) {	if (strncmp(cp, "wais", 4)) {	    for (i = 0; i < 4; i++)		cp[i] = TOLOWER(cp[i]);	}	return(WAIS_URL_TYPE);    } else if (!strncasecomp(cp, "telnet:", 7)) {	if (strncmp(cp, "telnet", 6)) {	    for (i = 0; i < 6; i++)		cp[i] = TOLOWER(cp[i]);	}	return(TELNET_URL_TYPE);    } else if (!strncasecomp(cp, "tn3270:", 7)) {	if (strncmp(cp, "tn", 2)) {	    for (i = 0; i < 2; i++)		cp[i] = TOLOWER(cp[i]);	}	return(TN3270_URL_TYPE);    } else if (!strncasecomp(cp, "rlogin:", 7)) {	if (strncmp(cp, "rlogin", 6)) {	    for (i = 0; i < 6; i++)		cp[i] = TOLOWER(cp[i]);	}	re

⌨️ 快捷键说明

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