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

📄 lygetfile.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
						   WWW_Download_File) < 0) {				FREE(fname);				return(NOT_FOUND);			    }			    LYAddVisitedLink(doc);			    StrAllocCopy(doc->address, fname);			    FREE(fname);			    doc->internal_link = FALSE;			    WWWDoc.address = doc->address;			    FREE(doc->post_data);			    WWWDoc.post_data = NULL;			    FREE(doc->post_content_type);			    WWWDoc.post_content_type = NULL;			    WWWDoc.bookmark = doc->bookmark = FALSE;			    WWWDoc.isHEAD = doc->isHEAD = FALSE;			    WWWDoc.safe = doc->safe = FALSE;			    HTOutputFormat = WWW_PRESENT;			    if (!HTLoadAbsolute(&WWWDoc))				return(NOT_FOUND);			    else				return(NORMAL);			} else if (pound == NULL &&				   /*				    *  HTAnchor hash-table searches are now				    *  case-sensitive (hopefully, without				    *  anchor deletion problems), so this				    *  is too. - FM				    */				   (strcmp(doc->address,					   HTLoadedDocumentURL()) ||				   /*				    *  Also check the post_data elements. - FM				    */				   strcmp((doc->post_data ?					   doc->post_data : ""),					  HTLoadedDocumentPost_data()) ||				   /*				    *  Also check the isHEAD element. - FM				    */				   doc->isHEAD != HTLoadedDocumentIsHEAD())) {			    HTMLSetCharacterHandling(current_char_set);			    /*			     *	Nothing needed to be shown.			     */			    LYAddVisitedLink(doc);			    return(NULLFILE);			} else {			/*			 *  May set www_search_result.			 */			    if (pound != NULL)				HTFindPoundSelector(pound+1);			    HTMLSetCharacterHandling(current_char_set);			    return(NORMAL);			}		    }		}	  } else {	      if (TRACE && LYTraceLogFP == NULL)		  sleep(MessageSecs);	      _user_message(WWW_BAD_ADDR_MESSAGE, doc->address);	      if (TRACE)		  fprintf(stderr,"\n");	      sleep(MessageSecs);	      return(NULLFILE);	  }}/* *  The user wants to select a link or page by number. *  If follow_link_number returns DO_LINK_STUFF do_link *   will be run immediately following its execution. *  If follow_link_number returns DO_GOTOLINK_STUFF *   it has updated the passed in doc for positioning on a link. *  If follow_link_number returns DO_GOTOPAGE_STUFF *   it has set doc->line to the top line of the desired page *   for displaying that page. *  If follow_link_number returns PRINT_ERROR an error message *   will be given to the user. *  If follow_link_number returns DO_FORMS_STUFF some forms stuff *   will be done. (Not yet implemented.) *  If follow_link_number returns DO_NOTHING nothing special *   will run after it. */PUBLIC int follow_link_number ARGS4(	int,		c,	int,		cur,	document *,	doc,	int *,		num){    char temp[120];    int new_top, new_link;    BOOL want_go;    temp[0] = c;    temp[1] = '\0';    *num = -1;    _statusline(FOLLOW_LINK_NUMBER);    /*     *	Get the number, possibly with a letter suffix, from the user.     */    if (LYgetstr(temp, VISIBLE, sizeof(temp), NORECALL) < 0 || *temp == 0) {	_statusline(CANCELLED);	sleep(InfoSecs);	return(DO_NOTHING);    }    *num = atoi(temp);    /*     *	Check if we had a 'p' or 'P' following the number as     *	a flag for displaying the page with that number. - FM     */    if (strchr(temp, 'p') != NULL || strchr(temp, 'P') != NULL) {	int nlines = HText_getNumOfLines();	int npages = ((nlines + 1) > display_lines) ?		(((nlines + 1) + (display_lines - 1))/(display_lines))						    : 1;	if (*num < 1)	    *num = 1;	doc->line = (npages <= 1) ?				1 :		((*num <= npages) ? (((*num - 1) * display_lines) + 1)				  : (((npages - 1) * display_lines) + 1));	return(DO_GOTOPAGE_STUFF);    }    /*     *	Check if we want to make the link corresponding to the     *	number the current link, rather than ACTIVATE-ing it.     */    want_go = (strchr(temp, 'g') != NULL || strchr(temp, 'G') != NULL);   /*    *  If we have a valid number, act on it.    */   if (*num > 0) {	int info;	/*	 *  Get the lname, and hightext, directly from www	 *  structures and add it to the cur link so that	 *  we can pass it transparently on to getfile(),	 *  and load new_top and new_link if we instead want	 *  to make the link number current.  These things	 *  are done so that a link can be selected anywhere	 *  in the current document, whether it is displayed	 *  on the screen or not!	 */	if ((info = HTGetLinkInfo(*num,				  want_go,				  &new_top,				  &new_link,				  &links[cur].hightext,			  &links[cur].lname)) == WWW_INTERN_LINK_TYPE) {	    links[cur].type = WWW_INTERN_LINK_TYPE;	    return(DO_LINK_STUFF);	} else if (info == LINK_LINE_FOUND) {	    doc->line = new_top + 1;	    doc->link = new_link;	    return(DO_GOTOLINK_STUFF);	} else if (info) {	    links[cur].type = WWW_LINK_TYPE;	    return(DO_LINK_STUFF);	} else {	    return(PRINT_ERROR);	}    } else {	return(PRINT_ERROR);    }}#if defined(EXEC_LINKS) || defined(LYNXCGI_LINKS)struct trust {	char *src;	char *path;	int type;	struct trust *next;};static struct trust trusted_exec_default = {  "file://localhost/",	"",	EXEC_PATH,		NULL};static struct trust always_trusted_exec_default = {  "none",		"",	ALWAYS_EXEC_PATH,	NULL};static struct trust trusted_cgi_default = {  "",			"",	CGI_PATH,		NULL};static struct trust *trusted_exec = &trusted_exec_default;static struct trust *always_trusted_exec = &always_trusted_exec_default;static struct trust *trusted_cgi = &trusted_cgi_default;PRIVATE void LYTrusted_free NOARGS{    struct trust *cur;    struct trust *next;    if (trusted_exec != &trusted_exec_default) {	cur = trusted_exec;	while (cur) {	    FREE(cur->src);	    FREE(cur->path);	    next = cur->next;	    FREE(cur);	    cur = next;	}    }    if (always_trusted_exec != &always_trusted_exec_default) {	cur = always_trusted_exec;	while (cur) {	    FREE(cur->src);	    FREE(cur->path);	    next = cur->next;	    FREE(cur);	    cur = next;	}    }    if (trusted_cgi != &trusted_cgi_default) {	cur = trusted_cgi;	while (cur) {	    FREE(cur->src);	    FREE(cur->path);	    next = cur->next;	    FREE(cur);	    cur = next;	}    }    return;}PUBLIC void add_trusted ARGS2(	char *, 	str,	int,		type){    struct trust *tp;    char *path;    char *src = str;    int Type = type;    static BOOLEAN first = TRUE;    if (!src)	return;    if (first) {	atexit(LYTrusted_free);	first = FALSE;    }    path = strchr(src, '\t');    if (path)	*path++ = '\0';    else	path = "";    tp = (struct trust *)malloc(sizeof(*tp));    if (tp == NULL)	outofmem(__FILE__, "add_trusted");    tp->src = NULL;    tp->path = NULL;    tp->type = Type;    StrAllocCopy(tp->src, src);    StrAllocCopy(tp->path, path);    if (Type == EXEC_PATH) {	if (trusted_exec == &trusted_exec_default)	    tp->next = NULL;	else	    tp->next = trusted_exec;	trusted_exec = tp;    } else if (Type == ALWAYS_EXEC_PATH) {	if (always_trusted_exec == &always_trusted_exec_default)	    tp->next = NULL;	else	    tp->next = always_trusted_exec;	always_trusted_exec = tp;    } else if (Type == CGI_PATH) {	if (trusted_cgi == &trusted_cgi_default)	    tp->next = NULL;	else	    tp->next = trusted_cgi;	trusted_cgi = tp;    }}/* *  Check to see if the supplied paths is allowed to be executed. */PUBLIC BOOLEAN exec_ok ARGS3(	CONST char *,	source,	CONST char *,	link,	int,		type){    struct trust *tp;    CONST char *cp;    int Type = type;    /*     *	Always OK if it is a jump file shortcut.     */    if (LYJumpFileURL)	return TRUE;    /*     *	Choose the trust structure based on the type.     */    if (Type == EXEC_PATH) {	tp = trusted_exec;    } else if (Type == ALWAYS_EXEC_PATH) {	tp = always_trusted_exec;    } else if (Type == CGI_PATH) {	tp = trusted_cgi;    } else {	HTAlert(MALFORMED_EXEC_REQUEST);	return FALSE;    }#ifdef VMS    /*     *	Security: reject on relative path.     */    if ((cp = strchr(link, '[')) != NULL) {	char *cp1;	if (((cp1 = strchr(cp, '-')) != NULL) &&	    strchr(cp1, ']') != NULL) {	    while (cp1[1] == '-')		cp1++;	    if (cp1[1] == ']' ||		cp1[1] == '.') {		HTAlert(RELPATH_IN_EXEC_LINK);		return FALSE;	    }	}    }#else    /*     *	Security: reject on relative path.     */    if (strstr(link, "../") != NULL) {	HTAlert(RELPATH_IN_EXEC_LINK);	return FALSE;    }    /*     *	Security: reject on strange character.     */    for (cp = link; *cp != '\0'; cp++) {	if (!isalnum(*cp) &&	    *cp != '_' && *cp != '-' && *cp != ' ' &&	    *cp != ':' && *cp != '.' && *cp != '/' &&	    *cp != '@' && *cp != '~' && *cp != '$' &&	    *cp != '&' && *cp != '+' && *cp != '=' &&	    *cp != '\t') {	    char buf[128];	    sprintf(buf,		    BADCHAR_IN_EXEC_LINK,		    *cp);	    HTAlert(buf);	    return FALSE;	}    }#endif /* VMS */check_tp_for_entry:    while (tp) {	if (tp->type == Type) {	    char CONST *command = link;	    if (strstr(command,"//") == link) {		command += 2;	    }#ifdef VMS	    if (strncasecomp(source, tp->src, strlen(tp->src)) == 0 &&		strncasecomp(command, tp->path, strlen(tp->path)) == 0)#else	    if (strncmp(source, tp->src, strlen(tp->src)) == 0 &&		strncmp(command, tp->path, strlen(tp->path)) == 0)#endif /* VMS */		return TRUE;	}	tp = tp->next;    }    if (Type == EXEC_PATH &&	always_trusted_exec != &always_trusted_exec_default) {	Type = ALWAYS_EXEC_PATH;	tp = always_trusted_exec;	goto check_tp_for_entry;    }    if (!(no_exec && type == ALWAYS_EXEC_PATH))	HTAlert(BADLOCPATH_IN_EXEC_LINK);    return FALSE;}#endif /* EXEC_LINKS || LYNXCGI_LINKS */PRIVATE int fix_http_urls ARGS1(	document *,	doc){    char *slash;    /*     *	If it's an ftp URL with a trailing slash, trim it off.     */    if (!strncmp(doc->address, "ftp", 3) &&	doc->address[strlen(doc->address)-1] == '/') {	char * proxy;	char *path = HTParse(doc->address, "", PARSE_PATH|PARSE_PUNCTUATION);	/*	 *  If the path is a lone slash, we're done. - FM	 */	if (path) {	    if (path[0] == '/' && path[1] == '\0') {		FREE(path);		return 0;	    }	    FREE(path);	}	/*	 *  If we're proxying ftp, don't trim anything. - KW	 */	if (((proxy = (char *)getenv("ftp_proxy")) != NULL) &&	    *proxy != '\0' && !override_proxy(doc->address))	    return 0;	/*	 *  If we get to here, trim the trailing slash. - FM	 */	if (TRACE)	    fprintf(stderr, "fix_http_urls: URL '%s'\n", doc->address);	doc->address[strlen(doc->address)-1] = '\0';	if (TRACE) {	    fprintf(stderr, "        changed to '%s'\n", doc->address);	    if (!LYTraceLogFP)		sleep(MessageSecs);	}    }    /*     *	If there isn't a slash besides the two at the beginning, append one.     */    if ((slash = strrchr(doc->address, '/')) != NULL) {	if (*(slash-1) != '/' || *(slash-2) != ':') {	    return(0);	}    }    if (TRACE)	fprintf(stderr, "fix_http_urls: URL '%s'\n", doc->address);    StrAllocCat(doc->address, "/");    if (TRACE) {	fprintf(stderr, "        changed to '%s'\n",doc->address);	if (!LYTraceLogFP)	    sleep(MessageSecs);    }    return(1);}

⌨️ 快捷键说明

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