📄 htaccess.c
字号:
status < 0 ? "FAIL" : "GET", full_address)); } /* ** Check out what we received from the net. */ if (status == HT_REDIRECTING) { /* Exported from HTMIME.c, of all places. *//** NO!! - FM **/ /* ** Doing this via HTMIME.c meant that the redirection cover ** page was already loaded before we learned that we want a ** different URL. Also, changing anchor->address, as Lynx ** was doing, meant we could never again access its hash ** table entry, creating an insolvable memory leak. Instead, ** if we had a 301 status and set permanent_redirection, ** we'll load the new URL in anchor->physical, preceded by a ** token, which we can check to make replacements on subsequent ** access attempts. We'll check recursively, and retrieve the ** final URL if we had multiple redirections to it. If we just ** went to HTLoad now, as Lou originally had this, we couldn't do ** Lynx's security checks and alternate handling of some URL types. ** So, instead, we'll go all the way back to the top of getfile ** in LYGetFile.c when the status is HT_REDIRECTING. This may ** seem bizarre, but it works like a charm! - FM ** ** Actually, the location header for redirections is now again ** picked up in HTMIME.c. But that's an internal matter between ** HTTP.c and HTMIME.c, is still under control of HTLoadHTTP for ** http URLs, is done in a way that doesn't load the redirection ** response's body (except when wanted as an error fallback), and ** thus need not concern us here. - kw 1999-12-02 */ CTRACE((tfp, "HTAccess: '%s' is a redirection URL.\n", address_to_load)); CTRACE((tfp, "HTAccess: Redirecting to '%s'\n", redirecting_url)); /* ** Prevent circular references. */ if (strcmp(address_to_load, redirecting_url)) { /* if different */ /* ** Load token and redirecting url into anchor->physical ** if we had 301 Permanent redirection. HTTP.c does not ** allow this if we have POST content. - FM */ if (permanent_redirection) { StrAllocCopy(anchor->physical, "Location="); StrAllocCat(anchor->physical, redirecting_url); } /* ** Set up flags before return to getfile. - FM */ StrAllocCopy(use_this_url_instead, redirecting_url); if (ForcingNoCache) LYforce_no_cache = YES; ++redirection_attempts; FREE(redirecting_url); permanent_redirection = FALSE; return(NO); } ++redirection_attempts; FREE(redirecting_url); permanent_redirection = FALSE; return(YES); } /* ** We did not receive a redirecting URL. - FM */ redirection_attempts = 0; FREE(redirecting_url); permanent_redirection = FALSE; if (status == HT_LOADED) { CTRACE((tfp, "HTAccess: `%s' has been accessed.\n", full_address)); return YES; } if (status == HT_PARTIAL_CONTENT) { HTAlert(gettext("Loading incomplete.")); CTRACE((tfp, "HTAccess: `%s' has been accessed, partial content.\n", full_address)); return YES; } if (status == HT_NO_DATA) { CTRACE((tfp, "HTAccess: `%s' has been accessed, No data left.\n", full_address)); return NO; } if (status == HT_NOT_LOADED) { CTRACE((tfp, "HTAccess: `%s' has been accessed, No data loaded.\n", full_address)); return NO; } if (status == HT_INTERRUPTED) { CTRACE((tfp, "HTAccess: `%s' has been accessed, transfer interrupted.\n", full_address)); return NO; } if (status > 0) { /* ** If you get this, then please find which routine is returning ** a positive unrecognized error code! */ fprintf(stderr, gettext("**** HTAccess: socket or file number returned by obsolete load routine!\n")); fprintf(stderr, gettext("**** HTAccess: Internal software error. Please mail lynx-dev@sig.net!\n")); fprintf(stderr, gettext("**** HTAccess: Status returned was: %d\n"),status); exit(EXIT_FAILURE); } /* Failure in accessing a document */ cp = NULL; StrAllocCopy(cp, gettext("Can't Access")); StrAllocCat(cp, " `"); StrAllocCat(cp, full_address); StrAllocCat(cp, "'"); _HTProgress(cp); FREE(cp); CTRACE((tfp, "HTAccess: Can't access `%s'\n", full_address)); HTLoadError(sink, 500, gettext("Unable to access document.")); return NO;} /* HTLoadDocument *//* Load a document from absolute name. HTLoadAbsolute()** -----------------------------------**** On Entry,** addr The absolute address of the document to be accessed.** filter if YES, treat document as HTML**** On Exit,** returns YES Success in opening document** NO Failure*/PUBLIC BOOL HTLoadAbsolute ARGS1( CONST DocAddress *, docaddr){ return HTLoadDocument(docaddr->address, HTAnchor_parent(HTAnchor_findAddress(docaddr)), (HTOutputFormat ? HTOutputFormat : WWW_PRESENT), HTOutputStream);}#ifdef NOT_USED_CODE/* Load a document from absolute name to stream. HTLoadToStream()** ---------------------------------------------**** On Entry,** addr The absolute address of the document to be accessed.** sink if non-NULL, send data down this stream**** On Exit,** returns YES Success in opening document** NO Failure*/PUBLIC BOOL HTLoadToStream ARGS3( CONST char *, addr, BOOL, filter, HTStream *, sink){ return HTLoadDocument(addr, HTAnchor_parent(HTAnchor_findAddress(addr)), (HTOutputFormat ? HTOutputFormat : WWW_PRESENT), sink);}#endif /* NOT_USED_CODE *//* Load a document from relative name. HTLoadRelative()** -----------------------------------**** On Entry,** relative_name The relative address of the document** to be accessed.**** On Exit,** returns YES Success in opening document** NO Failure*/PUBLIC BOOL HTLoadRelative ARGS2( CONST char *, relative_name, HTParentAnchor *, here){ DocAddress full_address; BOOL result; char * mycopy = NULL; char * stripped = NULL; char * current_address = HTAnchor_address((HTAnchor*)here); full_address.address = NULL; full_address.post_data = NULL; full_address.post_content_type = NULL; full_address.bookmark = NULL; full_address.isHEAD = FALSE; full_address.safe = FALSE; StrAllocCopy(mycopy, relative_name); stripped = HTStrip(mycopy); full_address.address = HTParse(stripped, current_address, PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); result = HTLoadAbsolute(&full_address); /* ** If we got redirection, result will be NO, but use_this_url_instead ** will be set. The calling routine should check both and do whatever ** is appropriate. - FM */ FREE(full_address.address); FREE(current_address); FREE(mycopy); /* Memory leak fixed 10/7/92 -- JFG */ return result;}/* Load if necessary, and select an anchor. HTLoadAnchor()** ----------------------------------------**** On Entry,** destination The child or parent anchor to be loaded.**** On Exit,** returns YES Success** NO Failure*/PUBLIC BOOL HTLoadAnchor ARGS1( HTAnchor *, destination){ HTParentAnchor * parent; BOOL loaded = NO; if (!destination) return NO; /* No link */ parent = HTAnchor_parent(destination); if (HTAnchor_document(parent) == NULL) { /* If not already loaded */ /* TBL 921202 */ BOOL result; char * address = HTAnchor_address((HTAnchor*) parent); result = HTLoadDocument(address, parent, HTOutputFormat ? HTOutputFormat : WWW_PRESENT, HTOutputStream); FREE(address); if (!result) return NO; loaded = YES; } { HText *text = (HText*)HTAnchor_document(parent); if (destination != (HTAnchor *)parent) { /* If child anchor */ HText_selectAnchor(text, /* Double display? @@ */ (HTChildAnchor*)destination); } else { if (!loaded) HText_select(text); } } return YES;} /* HTLoadAnchor *//* Search. HTSearch()** -------**** Performs a keyword search on word given by the user. Adds the** keyword to the end of the current address and attempts to open** the new address.**** On Entry,** *keywords space-separated keyword list or similar search list** here is anchor search is to be done on.*/PRIVATE char hex ARGS1( int, i){ char * hexchars = "0123456789ABCDEF"; return hexchars[i];}PUBLIC BOOL HTSearch ARGS2( CONST char *, keywords, HTParentAnchor *, here){#define acceptable \"1234567890abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_" char *q, *u; CONST char * p, *s, *e; /* Pointers into keywords */ char * address = NULL; BOOL result; char * escaped = typecallocn(char, (strlen(keywords)*3) + 1); static CONST BOOL isAcceptable[96] = /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ { 0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0, /* 2x !"#$%&'()*+,-./ */ 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4x @ABCDEFGHIJKLMNO */ 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* 5X PQRSTUVWXYZ[\]^_ */ 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6x `abcdefghijklmno */ 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 }; /* 7X pqrstuvwxyz{\}~ DEL */ if (escaped == NULL) outofmem(__FILE__, "HTSearch"); StrAllocCopy(address, here->isIndexAction); /* ** Convert spaces to + and hex escape unacceptable characters. */ for (s = keywords; *s && WHITE(*s); s++) /* Scan */ ; /* Skip white space */ for (e = s + strlen(s); e > s && WHITE(*(e-1)); e--) /* Scan */ ; /* Skip trailers */ for (q = escaped, p = s; p < e; p++) { /* Scan stripped field */ unsigned char c = UCH(TOASCII(*p)); if (WHITE(*p)) { *q++ = '+'; } else if (HTCJK != NOCJK) { *q++ = *p; } else if (c>=32 && c<=UCH(127) && isAcceptable[c-32]) { *q++ = *p; /* 930706 TBL for MVS bug */ } else { *q++ = '%'; *q++ = hex((int)(c >> 4)); *q++ = hex((int)(c & 15)); } } /* Loop over string */ *q = '\0'; /* Terminate escaped string */ u = strchr(address, '?'); /* Find old search string */ if (u != NULL) *u = '\0'; /* Chop old search off */ StrAllocCat(address, "?"); StrAllocCat(address, escaped); FREE(escaped); result = HTLoadRelative(address, here); FREE(address); /* ** If we got redirection, result will be NO, but use_this_url_instead ** will be set. The calling routine should check both and do whatever ** is appropriate. Only an http server (not a gopher or wais server) ** could return redirection. Lynx will go all the way back to its ** mainloop() and subject a redirecting URL to all of its security and ** restrictions checks. - FM */ return result;}/* Search Given Indexname. HTSearchAbsolute()** -----------------------**** Performs a keyword search on word given by the user. Adds the** keyword to the end of the current address and attempts to open** the new address.**** On Entry,** *keywords space-separated keyword list or similar search list** *indexname is name of object search is to be done on.*/PUBLIC BOOL HTSearchAbsolute ARGS2( CONST char *, keywords, char *, indexname){ DocAddress abs_doc; HTParentAnchor * anchor; abs_doc.address = indexname; abs_doc.post_data = NULL; abs_doc.post_content_type = NULL; abs_doc.bookmark = NULL; abs_doc.isHEAD = FALSE; abs_doc.safe = FALSE; anchor = (HTParentAnchor*)HTAnchor_findAddress(&abs_doc); return HTSearch(keywords, anchor);}#ifdef NOT_USED_CODE/* Generate the anchor for the home page. HTHomeAnchor()** --------------------------------------**** As it involves file access, this should only be done once** when the program first runs.** This is a default algorithm -- browser don't HAVE to use this.** But consistency between browsers is STRONGLY recommended!**** Priority order is:** 1 WWW_HOME environment variable (logical name, etc)** 2 ~/WWW/default.html** 3 /usr/local/bin/default.html** 4 http://www.w3.org/default.html*/PUBLIC HTParentAnchor * HTHomeAnchor NOARGS{ char * my_home_document = NULL; char * home = (char *)getenv(LOGICAL_DEFAULT); char * ref; HTParentAnchor * anchor; if (home) { StrAllocCopy(my_home_document, home);#define MAX_FILE_NAME 1024 /* @@@ */ } else if (HTClientHost) { /* Telnet server */ /* ** Someone telnets in, they get a special home. */ FILE * fp = fopen(REMOTE_POINTER, "r"); char * status; if (fp) { my_home_document = typecallocn(char, MAX_FILE_NAME); if (my_home_document == NULL) outofmem(__FILE__, "HTHomeAnchor"); status = fgets(my_home_document, MAX_FILE_NAME, fp); if (!status) { FREE(my_home_document); } fclose(fp); } if (my_home_document == NULL) StrAllocCopy(my_home_document, REMOTE_ADDRESS); }#ifdef UNIX if (my_home_document == NULL) { FILE * fp = NULL; CONST char * home = (CONST char*)getenv("HOME"); if (home != null) { HTSprintf0(&my_home_document, "%s/%s", home, PERSONAL_DEFAULT); fp = fopen(my_home_document, "r"); } if (!fp) { StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE); fp = fopen(my_home_document, "r"); } if (fp) { fclose(fp); } else { CTRACE((tfp, "HTBrowse: No local home document ~/%s or %s\n", PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE)); FREE(my_home_document); } }#endif /* UNIX */ ref = HTParse((my_home_document ? my_home_document : (HTClientHost ? REMOTE_ADDRESS : LAST_RESORT)), "file:", PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION); if (my_home_document) { CTRACE((tfp, "HTAccess: Using custom home page %s i.e., address %s\n", my_home_document, ref)); FREE(my_home_document); } anchor = (HTParentAnchor*)HTAnchor_findAddress(ref); FREE(ref); return anchor;}#endif /* NOT_USED_CODE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -