📄 htnews.c
字号:
LYstrncpy(buffer, "Status:", sizeof(buffer) - 1); else sprintf(buffer, "Status (ARTICLE %d):", art); PUTS(buffer); END(HTML_I); PUTC(' '); PUTS(response_text); MAYBE_END(HTML_LI); } /* Handle response to HEAD request */ } /* Loop over article */ } /* If read headers */ PUTC('\n'); if (LYListNewsNumbers) END(HTML_OL); else END(HTML_UL); PUTC('\n'); /* ** Link to later articles. */ if (last_required < last) { int after; /* End of article after */ after = last_required+HTNewsChunkSize; if (after == last) HTSprintf0(&dbuf, "%s%s", NewsHREF, groupName); /* original group */ else HTSprintf0(&dbuf, "%s%s/%d-%d", NewsHREF, groupName, last_required+1, after); CTRACE((tfp, " Block after is %s\n", dbuf)); PUTC('('); start_anchor(dbuf); PUTS(gettext("Later articles")); END(HTML_A); PUTS("...)\n"); }add_post: if (HTCanPost) { /* ** We have permission to POST to this host, ** so add a link for posting messages to ** this newsgroup. - FM */ char *href = NULL; START(HTML_HR); PUTC('\n'); if (!strncasecomp(NewsHREF, "snews:", 6)) StrAllocCopy(href,"snewspost://"); else StrAllocCopy(href,"newspost://"); StrAllocCat(href, NewsHost); StrAllocCat(href, "/"); StrAllocCat(href,groupName); start_anchor(href); PUTS(gettext("Post to ")); PUTS(groupName); END(HTML_A); FREE(href); } else { START(HTML_HR); } PUTC('\n'); return(HT_LOADED);}/* Load by name. HTLoadNews** =============*/PRIVATE int HTLoadNews ARGS4( CONST char *, arg, HTParentAnchor *, anAnchor, HTFormat, format_out, HTStream*, stream){ char command[262]; /* The whole command */ char proxycmd[260]; /* The proxy command */ char groupName[GROUP_NAME_LENGTH]; /* Just the group name */ int status; /* tcp return */ int retries; /* A count of how hard we have tried */ BOOL normal_url; /* Flag: "news:" or "nntp:" (physical) URL */ BOOL group_wanted; /* Flag: group was asked for, not article */ BOOL list_wanted; /* Flag: list was asked for, not article */ BOOL post_wanted; /* Flag: new post to group was asked for */ BOOL reply_wanted; /* Flag: followup post was asked for */ BOOL spost_wanted; /* Flag: new SSL post to group was asked for */ BOOL sreply_wanted; /* Flag: followup SSL post was asked for */ BOOL head_wanted = NO; /* Flag: want HEAD of single article */ int first, last; /* First and last articles asked for */ char *cp = 0; char *ListArg = NULL; char *ProxyHost = NULL; char *ProxyHREF = NULL; char *postfile = NULL;#ifdef USE_SSL char SSLprogress[256];#endif /* USE_SSL */ diagnostic = (format_out == WWW_SOURCE || /* set global flag */ format_out == HTAtom_for("www/download") || format_out == HTAtom_for("www/dump")); rawtext = NO; CTRACE((tfp, "HTNews: Looking for %s\n", arg)); if (!initialized) initialized = initialize(); if (!initialized) return -1; /* FAIL */ FREE(NewsHREF); command[0] = '\0'; command[sizeof(command)-1] = '\0'; proxycmd[0] = '\0'; proxycmd[sizeof(proxycmd)-1] = '\0'; { CONST char * p1 = arg; /* ** We will ask for the document, omitting the host name & anchor. ** ** Syntax of address is ** xxx@yyy Article ** <xxx@yyy> Same article ** xxxxx News group (no "@") ** group/n1-n2 Articles n1 to n2 in group */ normal_url = (BOOL) (!strncmp(arg, "news:", 5) || !strncmp(arg, "nntp:", 5)); spost_wanted = (BOOL) (!normal_url && strstr(arg, "snewspost:") != NULL); sreply_wanted = (BOOL) (!(normal_url || spost_wanted) && strstr(arg, "snewsreply:") != NULL); post_wanted = (BOOL) (!(normal_url || spost_wanted || sreply_wanted) && strstr(arg, "newspost:") != NULL); reply_wanted = (BOOL) (!(normal_url || spost_wanted || sreply_wanted || post_wanted) && strstr(arg, "newsreply:") != NULL); group_wanted = (BOOL) ((!(spost_wanted || sreply_wanted || post_wanted || reply_wanted) && strchr(arg, '@') == NULL) && (strchr(arg, '*') == NULL)); list_wanted = (BOOL) ((!(spost_wanted || sreply_wanted || post_wanted || reply_wanted || group_wanted) && strchr(arg, '@') == NULL) && (strchr(arg, '*') != NULL));#ifndef USE_SSL if (!strncasecomp(arg, "snewspost:", 10) || !strncasecomp(arg, "snewsreply:", 11)) { HTAlert(FAILED_CANNOT_POST_SSL); return HT_NOT_LOADED; }#endif /* !USE_SSL */ if (post_wanted || reply_wanted || spost_wanted || sreply_wanted) { /* ** Make sure we have a non-zero path for the newsgroup(s). - FM */ if ((p1 = strrchr(arg, '/')) != NULL) { p1++; } else if ((p1 = strrchr(arg, ':')) != NULL) { p1++; } if (!(p1 && *p1)) { HTAlert(WWW_ILLEGAL_URL_MESSAGE); return(HT_NO_DATA); } if (!(cp = HTParse(arg, "", PARSE_HOST)) || *cp == '\0') { if (s >= 0 && NewsHost && strcasecomp(NewsHost, HTNewsHost)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, HTNewsHost); } else { if (s >= 0 && NewsHost && strcasecomp(NewsHost, cp)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, cp); } FREE(cp); HTSprintf0(&NewsHREF, "%s://%.*s/", (post_wanted ? "newspost" : (reply_wanted ? "newreply" : (spost_wanted ? "snewspost" : "snewsreply"))), (int) sizeof(command) - 15, NewsHost); /* ** If the SSL daemon is being used as a proxy, ** reset p1 to the start of the proxied URL ** rather than to the start of the newsgroup(s). - FM */ if (spost_wanted && strncasecomp(arg, "snewspost:", 10)) p1 = strstr(arg, "snewspost:"); if (sreply_wanted && strncasecomp(arg, "snewsreply:", 11)) p1 = strstr(arg, "snewsreply:"); /* p1 = HTParse(arg, "", PARSE_PATH | PARSE_PUNCTUATION); */ /* ** Don't use HTParse because news: access doesn't follow traditional ** rules. For instance, if the article reference contains a '#', ** the rest of it is lost -- JFG 10/7/92, from a bug report */ } else if (!strncasecomp (arg, "nntp:", 5)) { if (((*(arg + 5) == '\0') || (!strcmp((arg + 5), "/") || !strcmp((arg + 5), "//") || !strcmp((arg + 5), "///"))) || ((!strncmp((arg + 5), "//", 2)) && (!(cp = strchr((arg + 7), '/')) || *(cp + 1) == '\0'))) { p1 = "*"; group_wanted = FALSE; list_wanted = TRUE; } else if (*(arg + 5) != '/') { p1 = (arg + 5); } else if (*(arg + 5) == '/' && *(arg + 6) != '/') { p1 = (arg + 6); } else { p1 = (cp + 1); } if (!(cp = HTParse(arg, "", PARSE_HOST)) || *cp == '\0') { if (s >= 0 && NewsHost && strcasecomp(NewsHost, HTNewsHost)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, HTNewsHost); } else { if (s >= 0 && NewsHost && strcasecomp(NewsHost, cp)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, cp); } FREE(cp); SnipIn(command, "nntp://%.*s/", 9, NewsHost); StrAllocCopy(NewsHREF, command); } else if (!strncasecomp(arg, "snews:", 6)) {#ifdef USE_SSL if (((*(arg + 6) == '\0') || (!strcmp((arg + 6), "/") || !strcmp((arg + 6), "//") || !strcmp((arg + 6), "///"))) || ((!strncmp((arg + 6), "//", 2)) && (!(cp = strchr((arg + 8), '/')) || *(cp + 1) == '\0'))) { p1 = "*"; group_wanted = FALSE; list_wanted = TRUE; } else if (*(arg + 6) != '/') { p1 = (arg + 6); } else if (*(arg + 6) == '/' && *(arg + 7) != '/') { p1 = (arg + 7); } else { p1 = (cp + 1); } if (!(cp = HTParse(arg, "", PARSE_HOST)) || *cp == '\0') { if (s >= 0 && NewsHost && strcasecomp(NewsHost, HTNewsHost)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, HTNewsHost); } else { if (s >= 0 && NewsHost && strcasecomp(NewsHost, cp)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, cp); } FREE(cp); sprintf(command, "snews://%.250s/", NewsHost); StrAllocCopy(NewsHREF, command);#else HTAlert(gettext("This client does not contain support for SNEWS URLs.")); return HT_NOT_LOADED;#endif /* USE_SSL */ } else if (!strncasecomp (arg, "news:/", 6)) { if (((*(arg + 6) == '\0') || !strcmp((arg + 6), "/") || !strcmp((arg + 6), "//")) || ((*(arg + 6) == '/') && (!(cp = strchr((arg + 7), '/')) || *(cp + 1) == '\0'))) { p1 = "*"; group_wanted = FALSE; list_wanted = TRUE; } else if (*(arg + 6) != '/') { p1 = (arg + 6); } else { p1 = (cp + 1); } if (!(cp = HTParse(arg, "", PARSE_HOST)) || *cp == '\0') { if (s >= 0 && NewsHost && strcasecomp(NewsHost, HTNewsHost)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, HTNewsHost); } else { if (s >= 0 && NewsHost && strcasecomp(NewsHost, cp)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, cp); } FREE(cp); SnipIn(command, "news://%.*s/", 9, NewsHost); StrAllocCopy(NewsHREF, command); } else { p1 = (arg + 5); /* Skip "news:" prefix */ if (*p1 == '\0') { p1 = "*"; group_wanted = FALSE; list_wanted = TRUE; } if (s >= 0 && NewsHost && strcasecomp(NewsHost, HTNewsHost)) { NEWS_NETCLOSE(s); s = -1; } StrAllocCopy(NewsHost, HTNewsHost); StrAllocCopy(NewsHREF, "news:"); } /* ** Set up any proxy for snews URLs that returns NNTP ** responses for Lynx to convert to HTML, instead of ** doing the conversion itself, and for handling posts ** or followups. - TZ & FM */ if (!strncasecomp(p1, "snews:", 6) || !strncasecomp(p1, "snewspost:", 10) || !strncasecomp(p1, "snewsreply:", 11)) { StrAllocCopy(ProxyHost, NewsHost); if ((cp = HTParse(p1, "", PARSE_HOST)) != NULL && *cp != '\0') { SnipIn(command, "snews://%.*s", 10, cp); StrAllocCopy(NewsHost, cp); } else { SnipIn(command, "snews://%.*s", 10, NewsHost); } command[sizeof(command)-2] = '\0'; FREE(cp); sprintf(proxycmd, "GET %.*s%c%c%c%c", (int) sizeof(proxycmd)-9, command, CR, LF, CR, LF); CTRACE((tfp, "HTNews: Proxy command is '%.*s'\n", (int)(strlen(proxycmd) - 4), proxycmd)); strcat(command, "/"); StrAllocCopy(ProxyHREF, NewsHREF); StrAllocCopy(NewsHREF, command); if (spost_wanted || sreply_wanted) { /* ** Reset p1 so that it points to the newsgroup(s). */ if ((p1 = strrchr(arg, '/')) != NULL) { p1++; } else { p1 = (strrchr(arg, ':') + 1); } } else { /* ** Reset p1 so that it points to the newsgroup ** (or a wildcard), or the article. */ if (!(cp = strrchr((p1 + 6), '/')) || *(cp + 1) == '\0') { p1 = "*"; group_wanted = FALSE; list_wanted = TRUE; } else { p1 = (cp + 1); } } } /* ** Set up command for a post, listing, or article request. - FM */ if (post_wanted || reply_wanted || spost_wanted || sreply_wanted) { strcpy(command, "POST"); } else if (list_wanted) { if (strlen(p1) > 249) { FREE(ProxyHost); FREE(ProxyHREF); HTAlert(URL_TOO_LONG); return -400; } SnipIn(command, "XGTITLE %.*s", 11, p1); } else if (group_wanted) { char * slash = strchr(p1, '/'); first = 0; last = 0; if (slash) { *slash = '\0'; if (strlen(p1) >= sizeof(groupName)) { FREE(ProxyHost); FREE(ProxyHREF); HTAlert(URL_TOO_LONG); return -400; } LYstrncpy(groupName, p1, sizeof(groupName) - 1); *slash = '/'; (void)sscanf(slash+1, "%d-%d", &first, &last); if ((first > 0) && (isdigit(UCH(*(slash+1)))) && (strchr(slash+1, '-') == NULL || first == last)) { /* ** We got a number greater than 0, which will be ** loaded as first, and either no range or the ** range computes to zero, so make last negative, ** as a flag to select the group and then fetch ** an article by number (first) instead of by ** messageID. - FM */ last = -1; } } else { if (strlen(p1) >= sizeof(groupName)) { FREE(ProxyHost); FREE(ProxyHREF); HTAlert(URL_TOO_LONG); return -400; } LYstrncpy(groupName, p1, sizeof(groupName) - 1); } SnipIn(command, "GROUP %.*s", 9, groupName); } else { int add_open=(strchr(p1, '<') == 0); int add_close=(strchr(p1, '>') == 0); if (strlen(p1) + add_open + add_close >= 252) { FREE(ProxyHost); FREE(ProxyHREF); HTAlert(URL_TOO_LONG); return -400; } sprintf(command, "ARTICLE %s%.*s%s", add_open ? "<" : "", (int) (sizeof(command) - (11 + add_open + add_close)), p1, add_close ? ">" : ""); } { char * p = command + strlen(command); /* ** Terminate command with CRLF, as in RFC 977. */ *p++ = CR; /* Macros to be correct on Mac */ *p++ = LF; *p++ = 0; } StrAllocCopy(ListArg, p1); } /* scope of p1 */ if (!*arg) { FREE(NewsHREF); FREE(ProxyHost); FREE(ProxyHREF); FREE(ListArg); return NO; /* Ignore if no name */ } if (!(post_wanted || reply_wanted || spost_wanted || sreply_wanted || (group_wanted && last != -1) || list_wanted)) { head_wanted = anAnchor->isHEAD; if (head_wanted && !strncmp(command, "ARTICLE ", 8)) { /* overwrite "ARTICLE" - hack... */ strcpy(command, "HEAD "); for (cp = command + 5; ; cp++) if ((*cp = *(cp + 3)) == '\0') break; } rawtext = (BOOL) (head_wanted || keep_mime_headers); } if (rawtext) { node_anchor = anAnchor; rawtarget = HTStreamStack(WWW_PLAINTEXT, format_out, stream, anAnchor); if (!rawtarget) { FREE(NewsHost); FREE(NewsHREF); FREE(ProxyHost); FREE(ProxyHREF); FREE(ListArg); HTAlert(gettext("No target for raw text!")); return(HT_NOT_LOADED); } /* Copy routine entry points */ rawtargetClass = *rawtarget->isa; } else /* ** Make a hypertext object with an anchor list. */ if (!(post_wanted || reply_wanted || spost_wanted || sreply_wanted)) { node_anchor = anAnchor; target = HTML_new(anAnchor, format_out, stream); targetClass = *target->isa; /* Copy routine entry points */ } /* ** Now, let's get a stream setup up from the NewsHost. */ for (retries = 0; retries < 2; retries++) { if (s < 0) { /* CONNECTING to news host */ char url[260]; if (!strcmp(NewsHREF, "news:")) { SnipIn (url, "lose://%.*s/", 9, NewsHost); } else if (ProxyHREF) { SnipIn (url, "%.*s", 1, ProxyHREF); } else { SnipIn (url, "%.*s", 1, Ne
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -