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

📄 lygetfile.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTTP.h"#include "HTAnchor.h"	    /* Anchor class */#include "HTAccess.h"#include "HTParse.h"#include "LYCurses.h"#include "GridText.h"#include "LYGlobalDefs.h"#include "LYUtils.h"#include "LYCharSets.h"#include "LYCharUtils.h"#include "HTAlert.h"#include "LYSignal.h"#include "LYGetFile.h"#include "LYPrint.h"#include "LYHistory.h"#include "LYStrings.h"#include "LYClean.h"#include "LYDownload.h"#include "LYNews.h"#include "LYMail.h"#include "LYSystem.h"#include "LYKeymap.h"#include "LYBookmark.h"#include "LYMap.h"#include "LYList.h"#ifdef VMS#include "HTVMSUtils.h"#endif /* VMS */#ifdef DOSPATH#include "HTDOS.h"#endif#ifdef DIRED_SUPPORT#include "LYLocal.h"#endif /* DIRED_SUPPORT */#include "LYexit.h"#include "LYLeaks.h"#ifndef VMS#ifdef SYSLOG_REQUESTED_URLS#include <syslog.h>#endif /* SYSLOG_REQUESTED_URLS */#endif /* !VMS */#define FREE(x) if (x) {free(x); x = NULL;}PRIVATE int fix_http_urls PARAMS((document *doc));extern char * WWW_Download_File;#ifdef VMSextern BOOLEAN LYDidRename;#endif /* VMS */#if 0 /* UNUSED */#ifdef DIRED_SUPPORTPRIVATE char * LYSanctify ARGS1(	char *, 	href){    int i;    char *p, *cp, *tp;    char address_buffer[1024];    i = (strlen(href) - 1);    while (i && href[i] == '/') href[i--] = '\0';    if ((cp = (char *)strchr(href,'~')) != NULL) {       if (!strncmp(href, "file://localhost/", 17))	 tp = (href + 17);       else	 tp = (href + 5);       if ((cp - tp) && *(cp-1) != '/')	 return href;       LYstrncpy(address_buffer, href, (cp - href));       if (address_buffer[(strlen(address_buffer) - 1)] == '/')	 address_buffer[(strlen(address_buffer) - 1)] = '\0';       p = (char *)Home_Dir();       strcat(address_buffer, p);       if (strlen(++cp))	 strcat(address_buffer, cp);       if (strcmp(href, address_buffer))	 StrAllocCopy(href, address_buffer);    }    return href;}#endif /* DIRED_SUPPORT */#endifPUBLIC BOOLEAN getfile ARGS1(	document *,	doc){	int url_type = 0;	char *cp = NULL;	char *temp = NULL;	DocAddress WWWDoc;  /* a WWW absolute doc address struct */	/*	 *  Reset LYCancelDownload to prevent unwanted delayed effect. - KW	 */	if (LYCancelDownload) {	    if (TRACE)		fprintf(stderr,			"getfile:    resetting LYCancelDownload to FALSE\n");	    LYCancelDownload = FALSE;	}	/*	 *  Reset fake 'Z' to prevent unwanted delayed effect. - kw	 */	LYFakeZap(NO);Try_Redirected_URL:	/*	 *  Load the WWWDoc struct in case we need to use it.	 */	WWWDoc.address = doc->address;	WWWDoc.post_data = doc->post_data;	WWWDoc.post_content_type = doc->post_content_type;	WWWDoc.bookmark = doc->bookmark;	WWWDoc.isHEAD = doc->isHEAD;	WWWDoc.safe = doc->safe;	/*	 *  Reset WWW_Download_File just in case.	 */	FREE(WWW_Download_File);	/*	 *  Reset redirect_post_content just in case.	 */	redirect_post_content = FALSE;	if (TRACE) {	    fprintf(stderr,"getfile: getting %s\n\n",doc->address);	}	/*	 *  Protect against denial of service attacks	 *  via the port 19 CHARGEN service, and block	 *  connections to the port 25 ESMTP service.	 *  Also reject any likely spoof attempts via	 *  wrap arounds at 65536. - FM	 */	if ((temp = HTParse(doc->address, "", PARSE_HOST)) != NULL &&	    strlen(temp) > 3) {	    char *cp1;	    if ((cp1 = strchr(temp, '@')) == NULL)		cp1 = temp;	    if ((cp = strrchr(cp1, ':')) != NULL) {		long int value;		cp++;		if (sscanf(cp, "%ld", &value) == 1) {		    if (value == 19 || value == 65555) {			HTAlert(PORT_NINETEEN_INVALID);			FREE(temp);			return(NULLFILE);		    }		    if (value == 25 || value == 65561) {			HTAlert(PORT_TWENTYFIVE_INVALID);			FREE(temp);			return(NULLFILE);		    }		    if (value > 65535 || value < 0) {			char msg[265];			sprintf(msg, PORT_INVALID, (unsigned long)value);			HTAlert(msg);			FREE(temp);			return(NULLFILE);		    }		} else if (isdigit((unsigned char)*cp)) {		    HTAlert(URL_PORT_BAD);		    FREE(temp);		    return(NULLFILE);		}	    }	}	cp = NULL;	FREE(temp);	/*	 *  Check to see if this is a universal document ID	 *  that lib WWW wants to handle.	 *	 *  Some special URL's we handle ourselves. :)	 */	if ((url_type = is_url(doc->address)) != 0) {		if (LYValidate && !LYPermitURL) {		    if (!(url_type == HTTP_URL_TYPE ||			  url_type == HTTPS_URL_TYPE ||			  url_type == LYNXHIST_URL_TYPE ||			  url_type == LYNXKEYMAP_URL_TYPE ||			  url_type == LYNXIMGMAP_URL_TYPE ||			  url_type == LYNXCOOKIE_URL_TYPE ||			  0==strncasecomp(WWWDoc.address, helpfilepath,					  strlen(helpfilepath)) ||			  (lynxlistfile != NULL &&			   0==strncasecomp(WWWDoc.address, lynxlistfile,					  strlen(lynxlistfile))) ||			  (lynxlinksfile != NULL &&			   0==strncasecomp(WWWDoc.address, lynxlinksfile,					  strlen(lynxlinksfile))) ||			  (lynxjumpfile != NULL &&			   0==strncasecomp(WWWDoc.address, lynxjumpfile,					  strlen(lynxjumpfile))))) {			_statusline(NOT_HTTP_URL_OR_ACTION);			sleep(MessageSecs);			return(NULLFILE);		    }		}		if (traversal) {		    /*		     *	Only traverse http URLs.		     */		    if (url_type != HTTP_URL_TYPE &&			url_type != LYNXIMGMAP_URL_TYPE)			return(NULLFILE);		} else if (check_realm && !LYPermitURL && !LYJumpFileURL) {		    if (!(0==strncmp(startrealm, WWWDoc.address,				     strlen(startrealm)) ||			  url_type == LYNXHIST_URL_TYPE ||			  url_type == LYNXKEYMAP_URL_TYPE ||			  url_type == LYNXIMGMAP_URL_TYPE ||			  url_type == LYNXCOOKIE_URL_TYPE ||			  url_type == LYNXPRINT_URL_TYPE ||			  url_type == LYNXDOWNLOAD_URL_TYPE ||			  url_type == MAILTO_URL_TYPE ||			  url_type == NEWSPOST_URL_TYPE ||			  url_type == NEWSREPLY_URL_TYPE ||			  url_type == SNEWSPOST_URL_TYPE ||			  url_type == SNEWSREPLY_URL_TYPE ||			  (!LYUserSpecifiedURL &&			   (url_type == LYNXEXEC_URL_TYPE ||			    url_type == LYNXPROG_URL_TYPE ||			    url_type == LYNXCGI_URL_TYPE)) ||			  (WWWDoc.bookmark != NULL &&			   *WWWDoc.bookmark != '\0') ||			  0==strncasecomp(WWWDoc.address, helpfilepath,					  strlen(helpfilepath)) ||			  (lynxlistfile != NULL &&			   0==strncasecomp(WWWDoc.address, lynxlistfile,					  strlen(lynxlistfile))) ||			  (lynxjumpfile != NULL &&			   0==strncasecomp(WWWDoc.address, lynxjumpfile,					  strlen(lynxjumpfile))))) {			_statusline(NOT_IN_STARTING_REALM);			sleep(MessageSecs);			return(NULLFILE);		    }		}		if (WWWDoc.post_data &&		    url_type != HTTP_URL_TYPE &&		    url_type != HTTPS_URL_TYPE &&		    url_type != LYNXCGI_URL_TYPE &&		    url_type != LYNXIMGMAP_URL_TYPE &&		    url_type != GOPHER_URL_TYPE &&		    url_type != CSO_URL_TYPE &&		    url_type != PROXY_URL_TYPE &&		    !(url_type == FILE_URL_TYPE &&		      *(LYlist_temp_url()) &&		      !strncmp(WWWDoc.address, LYlist_temp_url(),			       strlen(LYlist_temp_url())))) {		    if (TRACE)			fprintf(stderr,				"getfile: dropping post_data!\n");		    HTAlert("POST not supported for this URL - ignoring POST data!");		    FREE(doc->post_data);		    FREE(doc->post_content_type);		    WWWDoc.post_data = NULL;		    WWWDoc.post_content_type = NULL;		}#ifndef VMS#ifdef SYSLOG_REQUESTED_URLS		syslog(LOG_INFO|LOG_LOCAL5, "%s", doc->address);#endif /* SYSLOG_REQUESTED_URLS */#endif /* !VMS */		if (url_type == UNKNOWN_URL_TYPE ||		    url_type == AFS_URL_TYPE ||		    url_type == PROSPERO_URL_TYPE) {		    HTAlert(UNSUPPORTED_URL_SCHEME);		    return(NULLFILE);		} else if (url_type == DATA_URL_TYPE) {		    HTAlert(UNSUPPORTED_DATA_URL);		    return(NULLFILE);		} else if (url_type == LYNXPRINT_URL_TYPE) {		    return(printfile(doc));		} else if (url_type == NEWSPOST_URL_TYPE ||			   url_type == NEWSREPLY_URL_TYPE ||			   url_type == SNEWSPOST_URL_TYPE ||			   url_type == SNEWSREPLY_URL_TYPE) {		    if (no_newspost) {			_statusline(NEWSPOSTING_DISABLED);			sleep(MessageSecs);			return(NULLFILE);		    } else {			HTLoadAbsolute(&WWWDoc);			return(NULLFILE);		    }		} else if (url_type == LYNXDOWNLOAD_URL_TYPE) {		    LYDownload(doc->address);#ifdef VMS		    if (LYDidRename) {			/*			 *  The temporary file was saved to disk via a			 *  rename(), so we can't access the temporary			 *  file again via the download menu.  Clear the			 *  flag, and return NULLFILE to pop. - FM			 */			LYDidRename = FALSE;			return(NULLFILE);		    } else {			return(NORMAL);		    }#else		    return(NORMAL);#endif /* VMS */		} else if (url_type == LYNXDIRED_URL_TYPE) {#ifdef DIRED_SUPPORT		    if (no_dired_support) {		       _statusline(DIRED_DISABLED);		       sleep(MessageSecs);		       return(NULLFILE);		    } else {		       local_dired(doc);		       WWWDoc.address = doc->address;		       WWWDoc.post_data = doc->post_data;		       WWWDoc.post_content_type = doc->post_content_type;		       WWWDoc.bookmark = doc->bookmark;		       WWWDoc.isHEAD = doc->isHEAD;		       WWWDoc.safe = doc->safe;		       if (!HTLoadAbsolute(&WWWDoc))			   return(NOT_FOUND);		       return(NORMAL);		    }#else		    _statusline(DIRED_DISABLED);		    sleep(MessageSecs);		    return(NULLFILE);#endif /* DIRED_SUPPORT */		} else if (url_type == LYNXHIST_URL_TYPE) {		    /*		     *	'doc' will change to the new file		     *	if we had a successful LYpop_num(),		     *	and the return value will be FALSE		     *	if we had a cancel. - FM		     */		    if ((historytarget(doc) == FALSE) ||			!doc || !doc->address) {			HTMLSetCharacterHandling(current_char_set);			return(NOT_FOUND);		    }		    /*		     *	We changed it so reload.		     */		    WWWDoc.address = doc->address;		    WWWDoc.post_data = doc->post_data;		    WWWDoc.post_content_type = doc->post_content_type;		    WWWDoc.bookmark = doc->bookmark;		    WWWDoc.isHEAD = doc->isHEAD;		    WWWDoc.safe = doc->safe;#ifndef DONT_TRACK_INTERNAL_LINKS		    if (doc->internal_link && !reloading) {			LYinternal_flag = TRUE;		    }#endif		    if (!HTLoadAbsolute(&WWWDoc)) {			HTMLSetCharacterHandling(current_char_set);			return(NOT_FOUND);		    }		    HTMLSetCharacterHandling(current_char_set);		    return(NORMAL);		} else if (url_type == LYNXEXEC_URL_TYPE ||			   url_type == LYNXPROG_URL_TYPE) {#ifdef EXEC_LINKS		    if (no_exec &&			!exec_ok(HTLoadedDocumentURL(),				 doc->address+9, ALWAYS_EXEC_PATH)) {			statusline(EXECUTION_DISABLED);			sleep(MessageSecs);		    } else if (no_bookmark_exec &&			       HTLoadedDocumentBookmark()) {			statusline(BOOKMARK_EXEC_DISABLED);			sleep(MessageSecs);		    } else if (local_exec || (local_exec_on_local_files &&			       exec_ok(HTLoadedDocumentURL(),				       doc->address+9, EXEC_PATH))) {			char *p, addressbuf[1024];			/*			 *  Bug puts slash on end if none is in the string.			 */			char *last_slash = strrchr(doc->address,'/');			if (last_slash-doc->address==strlen(doc->address)-1)			    doc->address[strlen(doc->address)-1] = '\0';			p = doc->address;			/*			 *  Convert '~' to $HOME.			 */			if ((cp = strchr(doc->address, '~'))) {			    strncpy(addressbuf, doc->address, cp-doc->address);			    addressbuf[cp - doc->address] = '\0';#ifdef DOSPATH			    p = HTDOS_wwwName((char *)Home_Dir());#else#ifdef VMS			    p = HTVMS_wwwName((char *)Home_Dir());#else			    p = (char *)Home_Dir();#endif /* VMS */#endif /* DOSPATH */			    strcat(addressbuf, p);			    strcat(addressbuf, cp+1);			    p = addressbuf;			}			/*			 *  Show URL before executing it.			 */			statusline(doc->address);			sleep(InfoSecs);			stop_curses();			/*			 *  Run the command.			 */			if (strstr(p,"//") == p+9)			    system(p+11);			else			    system(p+9);			if (url_type != LYNXPROG_URL_TYPE) {			    /*			     *	Make sure user gets to see screen output.			     */#ifndef VMS			    signal(SIGINT, SIG_IGN);#endif /* !VMS */			    printf("\n%s", RETURN_TO_LYNX);			    fflush(stdout);			    LYgetch();#ifdef VMS			    {			      extern BOOLEAN HadVMSInterrupt;			      HadVMSInterrupt = FALSE;			    }#endif /* VMS */			}			start_curses();			LYAddVisitedLink(doc);		     } else {			char buf[512];

⌨️ 快捷键说明

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