diff options
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | anchor.c | 65 | ||||
-rw-r--r-- | file.c | 15 | ||||
-rw-r--r-- | html.h | 11 | ||||
-rw-r--r-- | main.c | 9 | ||||
-rw-r--r-- | news.c | 179 | ||||
-rw-r--r-- | proto.h | 3 | ||||
-rw-r--r-- | url.c | 44 |
8 files changed, 251 insertions, 98 deletions
@@ -1,3 +1,24 @@ +2003-01-07 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + + * [w3m-dev 03610] Re: news:<newsgroup> + * anchor.c (_put_anchor_news): check '<' + (reAnchorNewsheader): added + * file.c (loadSomething): Subject: as buffername + (checkHeader): check buf->document_header + (loadGeneralFile): reAnchorNewsheader + * html.h (SCM_NNTP_GROUP): added + * main.c (main): delete USE_NNTP in switch (newbuf->real_scheme) + (chkNMIDBuffer): lowercase in url_like_pat + * news.c (add_news_message): add scheme, group as arg + (openNewsStream): check SCM_NNTP_GROUP + check current_news.host + (readNewsgroup): rewrite to support nntp:,news: extension + * proto.h (reAnchorNewsheader): added + * url.c (DefaultPort): add 119 for nntp group + (parseURL2): rewrite to support nntp:,news: extension + (_parsedURL2Str): add for SCM_NNTP_GROUP + (openURL): rewrite to support nntp:,news: extension + 2002-12-28 Fumitoshi UKAI <ukai@debian.or.jp> * fix build errors @@ -6157,4 +6178,4 @@ a * [w3m-dev 03276] compile error on EWS4800 * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.655 2002/12/27 16:46:13 ukai Exp $ +$Id: ChangeLog,v 1.656 2003/01/06 15:36:56 ukai Exp $ @@ -1,4 +1,4 @@ -/* $Id: anchor.c,v 1.17 2002/12/24 17:24:33 ukai Exp $ */ +/* $Id: anchor.c,v 1.18 2003/01/06 15:36:57 ukai Exp $ */ #include "fm.h" #include "myctype.h" #include "regex.h" @@ -193,9 +193,11 @@ _put_anchor_news(Buffer *buf, char *p1, char *p2, int line, int pos) { Str tmp; - p1++; - if (*(p2 - 1) == '>') - p2--; + if (*p1 == '<') { + p1++; + if (*(p2 - 1) == '>') + p2--; + } tmp = Strnew_charp_n(p1, p2 - p1); #ifdef JP_CHARSET tmp = conv_str(tmp, InnerCode, buf->document_code); @@ -366,6 +368,61 @@ reAnchorNews(Buffer *buf, char *re) { return reAnchorAny(buf, re, _put_anchor_news); } + +char * +reAnchorNewsheader(Buffer *buf) +{ + Line *l; + char *p, *p1, *p2; + static char *header_mid[] = { + "Message-Id:", "References:", "In-Reply-To:", NULL + }; + static char *header_group[] = { + "Newsgroups:", NULL + }; + char **header, **q; + int i, search = FALSE; + + if (!buf || !buf->firstLine) + return NULL; + for (i = 0; i <= 1; i++) { + if (i == 0) { + regexCompile("<[!-;=?-~]+@[a-zA-Z0-9\\.\\-_]+>", 1); + header = header_mid; + } + else { + regexCompile("[a-zA-Z0-9\\.\\-_]+", 1); + header = header_group; + } + for (l = buf->firstLine; l != NULL && l->real_linenumber == 0; + l = l->next) { + p = l->lineBuf; + if (!IS_SPACE(*p)) { + search = FALSE; + for (q = header; *q; q++) { + if (!strncasecmp(p, *q, sizeof(*q) - 1)) { + search = TRUE; + p = strchr(p, ':') + 1; + break; + } + } + } + if (!search) + continue; + for (;;) { + if (regexMatch(p, &l->lineBuf[l->len] - p, p == l->lineBuf) + == 1) { + matchedPosition(&p1, &p2); + p = reAnchorPos(buf, l, p1, p2, _put_anchor_news); + } + else + break; + } + } + } + reseq_anchor(buf); + return NULL; +} #endif /* USE_NNTP */ #define FIRST_MARKER_SIZE 30 @@ -1,4 +1,4 @@ -/* $Id: file.c,v 1.174 2002/12/27 16:30:54 ukai Exp $ */ +/* $Id: file.c,v 1.175 2003/01/06 15:36:58 ukai Exp $ */ #include "fm.h" #include <sys/types.h> #include "myctype.h" @@ -215,8 +215,11 @@ loadSomething(URLFile *f, return NULL; buf->filename = path; - if (buf->buffername == NULL || buf->buffername[0] == '\0') - buf->buffername = conv_from_system(lastFileName(path)); + if (buf->buffername == NULL || buf->buffername[0] == '\0') { + buf->buffername = checkHeader(buf, "Subject:"); + if (buf->buffername == NULL) + buf->buffername = conv_from_system(lastFileName(path)); + } if (buf->currentURL.scheme == SCM_UNKNOWN) buf->currentURL.scheme = f->scheme; buf->real_scheme = f->scheme; @@ -889,7 +892,7 @@ checkHeader(Buffer *buf, char *field) TextListItem *i; char *p; - if (buf == NULL || field == NULL) + if (buf == NULL || field == NULL || buf->document_header == NULL) return NULL; for (i = buf->document_header->first; i != NULL; i = i->next) { if (!strncasecmp(i->ptr, field, len)) { @@ -2089,6 +2092,10 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, } if (header_string) header_string = NULL; +#ifdef USE_NNTP + if (f.scheme == SCM_NNTP || f.scheme == SCM_NEWS) + reAnchorNewsheader(b); +#endif preFormUpdateBuffer(b); if (fmInitialized) term_raw(); @@ -1,4 +1,4 @@ -/* $Id: html.h,v 1.17 2002/12/27 16:07:44 ukai Exp $ */ +/* $Id: html.h,v 1.18 2003/01/06 15:36:59 ukai Exp $ */ #ifndef _HTML_H #define _HTML_H #ifdef USE_SSL @@ -361,11 +361,12 @@ struct environment { #define SCM_LOCAL_CGI 5 #define SCM_EXEC 6 #define SCM_NNTP 7 -#define SCM_NEWS 8 -#define SCM_NEWS_GROUP 9 -#define SCM_MAILTO 10 +#define SCM_NNTP_GROUP 8 +#define SCM_NEWS 9 +#define SCM_NEWS_GROUP 10 +#define SCM_MAILTO 11 #ifdef USE_SSL -#define SCM_HTTPS 11 +#define SCM_HTTPS 12 #endif /* USE_SSL */ #endif /* _HTML_H */ @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.183 2002/12/27 16:07:44 ukai Exp $ */ +/* $Id: main.c,v 1.184 2003/01/06 15:36:59 ukai Exp $ */ #define MAINPROGRAM #include "fm.h" #include <signal.h> @@ -874,11 +874,6 @@ main(int argc, char **argv, char **envp) else if (newbuf == NO_BUFFER) continue; switch (newbuf->real_scheme) { -#ifdef USE_NNTP - case SCM_NNTP: - case SCM_NEWS: - case SCM_NEWS_GROUP: -#endif /* USE_NNTP */ case SCM_MAILTO: break; case SCM_LOCAL: @@ -4636,7 +4631,7 @@ void chkNMIDBuffer(Buffer *buf) { static char *url_like_pat[] = { - "<[!-;=?-~]+@[A-z0-9\\.\\-_]+>", + "<[!-;=?-~]+@[a-zA-Z0-9\\.\\-_]+>", NULL, }; int i; @@ -1,4 +1,4 @@ -/* $Id: news.c,v 1.5 2002/12/27 16:46:13 ukai Exp $ */ +/* $Id: news.c,v 1.6 2003/01/06 15:36:59 ukai Exp $ */ #include "fm.h" #include "myctype.h" #include <stdio.h> @@ -181,7 +181,7 @@ html_quote_s(char *str) static void add_news_message(Str str, int index, char *date, char *name, char *subject, - char *mid) + char *mid, char *scheme, char *group) { time_t t; struct tm *tm; @@ -190,12 +190,40 @@ add_news_message(Str str, int index, char *date, char *name, char *subject, t = mymktime(date); tm = localtime(&t); Strcat(str, - Sprintf - ("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s<td><a href=\"news:%s\">%s</a>\n", - index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name), - html_quote(file_quote(mid)), html_quote(subject))); + Sprintf("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s", + index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name))); + if (group) + Strcat(str, Sprintf("<td><a href=\"%s%s/%d\">%s</a>\n", scheme, group, + index, html_quote(subject))); + else + Strcat(str, Sprintf("<td><a href=\"%s%s\">%s</a>\n", scheme, + html_quote(file_quote(mid)), html_quote(subject))); } +/* + * [News article] + * * RFC 1738 + * nntp://<host>:<port>/<newsgroup-name>/<article-number> + * news:<message-id> + * + * * Extension + * nntp://<host>:<port>/<newsgroup-name>/<message-id> + * nntp://<host>:<port>/<message-id> + * news:<newsgroup-name>/<article-number> + * news:<newsgroup-name>/<message-id> + * + * [News group] + * * RFC 1738 + * news:<newsgroup-name> + * + * * Extension + * nntp://<host>:<port>/<newsgroup-name> + * nntp://<host>:<port>/<newsgroup-name>/<start-number>-<end-number> + * news:<newsgroup-name>/<start-number>-<end-number> + * + * <message-id> = <unique>@<full_domain_name> + */ + InputStream openNewsStream(ParsedURL *pu) { @@ -205,13 +233,17 @@ openNewsStream(ParsedURL *pu) if (pu->file == NULL || *pu->file == '\0') return NULL; - if (pu->scheme == SCM_NNTP) + if (pu->scheme == SCM_NNTP || pu->scheme == SCM_NNTP_GROUP) host = pu->host; else host = NNTP_server; - if (!host || *host == '\0') + if (!host || *host == '\0') { + if (current_news.host) + news_quit(¤t_news); return NULL; - if (pu->scheme != SCM_NNTP && (p = strchr(host, ':'))) { + } + if (pu->scheme != SCM_NNTP && pu->scheme != SCM_NNTP_GROUP && + (p = strchr(host, ':'))) { host = allocStr(host, p - host); port = atoi(p + 1); } @@ -238,24 +270,33 @@ openNewsStream(ParsedURL *pu) if (!news_open(¤t_news)) return NULL; } - if (pu->scheme == SCM_NNTP) { - /* first char of pu->file is '/' */ - group = file_unquote(Strnew_charp(pu->file + 1)->ptr); + if (pu->scheme == SCM_NNTP || pu->scheme == SCM_NEWS) { + /* News article */ + group = allocStr(pu->file, -1); + if (pu->scheme == SCM_NNTP && *group == '/') { + /* first char of pu->file is '/' */ + group++; + } + group = file_unquote(group); p = strchr(group, '/'); - if (p == NULL) - return NULL; - *p++ = '\0'; - news_command(¤t_news, Sprintf("GROUP %s", group)->ptr, &status); - if (status != 211) - return NULL; - news_command(¤t_news, Sprintf("ARTICLE %s", p)->ptr, &status); - if (status != 220) - return NULL; - return current_news.rf; - } - else if (pu->scheme == SCM_NEWS) { - tmp = Sprintf("ARTICLE <%s>", url_unquote(pu->file)); - news_command(¤t_news, tmp->ptr, &status); + if (p == NULL) { /* <message-id> */ + if (!strchr(group, '@')) + return NULL; + p = group; + } + else { /* <newsgroup>/<message-id or article-number> */ + *p++ = '\0'; + news_command(¤t_news, Sprintf("GROUP %s", group)->ptr, + &status); + if (status != 211) + return NULL; + } + if (strchr(p, '@')) /* <message-id> */ + news_command(¤t_news, Sprintf("ARTICLE <%s>", p)->ptr, + &status); + else /* <article-number> */ + news_command(¤t_news, Sprintf("ARTICLE %s", p)->ptr, + &status); if (status != 220) return NULL; return current_news.rf; @@ -270,8 +311,7 @@ readNewsgroup(ParsedURL *pu) Str tmp; URLFile f; Buffer *buf; - char *group, *p, *q, *s, *t, *n; - char *volatile qgroup; + char *scheme, *group, *qgroup, *list, *p, *q, *s, *t, *n; int status, i, first, last; volatile int flag = 0, start = 0, end = 0; char code = '\0'; @@ -279,14 +319,28 @@ readNewsgroup(ParsedURL *pu) if (current_news.host == NULL || !pu->file || *pu->file == '\0') return NULL; - group = file_unquote(pu->file); - qgroup = html_quote(group); - page = Strnew(); - + group = allocStr(pu->file, -1); + if (pu->scheme == SCM_NNTP_GROUP) { + if (*group == '/') + group++; + scheme = "nntp:/"; + } + else + scheme = "news:"; + if ((list = strchr(group, '/'))) { + /* <newsgroup>/<start-number>-<end-number> */ + *list++ = '\0'; + } if (fmInitialized) { message(Sprintf("Reading newsgroup %s...", group)->ptr, 0, 0); refresh(); } + qgroup = html_quote(group); + group = file_unquote(group); + page = Sprintf("<title>Newsgroup: %s</title>\n\ +<h1>Newsgroup: %s</h1>\n<hr>\n", + qgroup, qgroup); + if (SETJMP(AbortLoading) != 0) { news_close(¤t_news); Strcat_charp(page, "</table><p>Transfer Interrupted!\n"); @@ -296,42 +350,44 @@ readNewsgroup(ParsedURL *pu) if (fmInitialized) term_cbreak(); - page = - Sprintf - ("<title>Newsgroup: %s</title>\n<h1>Newsgroup: %s</h1>\n<hr>\n", - qgroup, qgroup); - - qgroup = html_quote(file_quote(group)); /* URL */ tmp = news_command(¤t_news, Sprintf("GROUP %s", group)->ptr, &status); if (status != 211) goto news_list; if (sscanf(tmp->ptr, "%d %d %d %d", &status, &i, &first, &last) != 4) goto news_list; - if (pu->label) { - start = atoi(pu->label); + if (list && *list) { + if ((p = strchr(list, '-'))) { + *p++ = '\0'; + end = atoi(p); + } + start = atoi(list); if (start > 0) { if (start < first) start = first; - end = start + MaxNewsMessage; + if (end <= 0) + end = start + MaxNewsMessage - 1; } } if (start <= 0) { start = first; - end = last + 1; - if (end - start > MaxNewsMessage) - start = end - MaxNewsMessage; + end = last; + if (end - start > MaxNewsMessage - 1) + start = end - MaxNewsMessage + 1; } + page = Sprintf("<title>Newsgroup: %s %d-%d</title>\n\ +<h1>Newsgroup: %s %d-%d</h1>\n<hr>\n", + qgroup, start, end, qgroup, start, end); if (start > first) { i = start - MaxNewsMessage; if (i < first) i = first; - Strcat(page, Sprintf("<a href=\"news:%s#%d\">[%d-%d]</a>\n", - qgroup, i, i, start - 1)); + Strcat(page, Sprintf("<a href=\"%s%s/%d-%d\">[%d-%d]</a>\n", scheme, + qgroup, i, start - 1, i, start - 1)); } Strcat_charp(page, "<table>\n"); - news_command(¤t_news, Sprintf("XOVER %d-%d", start, end - 1)->ptr, + news_command(¤t_news, Sprintf("XOVER %d-%d", start, end)->ptr, &status); if (status == 224) { f.scheme = SCM_NEWS; @@ -360,13 +416,14 @@ readNewsgroup(ParsedURL *pu) *q = '\0'; s = convertLine(&f, decodeMIME(s), &code, HEADER_MODE)->ptr; n = convertLine(&f, decodeMIME(n), &code, HEADER_MODE)->ptr; - add_news_message(page, i, t, n, s, p); + add_news_message(page, i, t, n, s, p, scheme, + pu->scheme == SCM_NNTP_GROUP ? qgroup : NULL); } } else { init_stream(&f, SCM_NEWS, current_news.rf); buf = newBuffer(INIT_BUFFER_WIDTH); - for (i = start; i < end && i <= last; i++) { + for (i = start; i <= end && i <= last; i++) { news_command(¤t_news, Sprintf("HEAD %d", i)->ptr, &status); if (status != 221) continue; @@ -383,23 +440,26 @@ readNewsgroup(ParsedURL *pu) continue; if (!(t = checkHeader(buf, "Date:"))) continue; - add_news_message(page, i, t, n, s, p); + add_news_message(page, i, t, n, s, p, scheme, + pu->scheme == SCM_NNTP_GROUP ? qgroup : NULL); } } Strcat_charp(page, "</table>\n"); - if (end <= last) { - i = end + MaxNewsMessage - 1; + if (end < last) { + i = end + MaxNewsMessage; if (i > last) i = last; - Strcat(page, Sprintf("<a href=\"news:%s#%d\">[%d-%d]</a>\n", - qgroup, end, end, i)); + Strcat(page, Sprintf("<a href=\"%s%s/%d-%d\">[%d-%d]</a>\n", scheme, + qgroup, end + 1, i, end + 1, i)); } flag = 1; news_list: - news_command(¤t_news, Sprintf("LIST ACTIVE %s.*", group)->ptr, - &status); + tmp = Sprintf("LIST ACTIVE %s", group); + if (!strchr(group, '*')) + Strcat_charp(tmp, ".*"); + news_command(¤t_news, tmp->ptr, &status); if (status != 215) goto news_end; while (1) { @@ -415,13 +475,14 @@ readNewsgroup(ParsedURL *pu) p = tmp->ptr; for (q = p; *q && !IS_SPACE(*q); q++) ; *(q++) = '\0'; - i = 0; if (sscanf(q, "%d %d", &last, &first) == 2 && last >= first) i = last - first + 1; + else + i = 0; Strcat(page, Sprintf - ("<tr><td align=right>%d<td><a href=\"news:%s\">%s</a>\n", i, - html_quote(file_quote(p)), html_quote(p))); + ("<tr><td align=right>%d<td><a href=\"%s%s\">%s</a>\n", i, + scheme, html_quote(file_quote(p)), html_quote(p))); } if (flag == 2) Strcat_charp(page, "</table>\n"); @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.75 2002/12/27 16:07:44 ukai Exp $ */ +/* $Id: proto.h,v 1.76 2003/01/06 15:37:00 ukai Exp $ */ /* * This file was automatically generated by version 1.7 of cextract. * Manual editing not recommended. @@ -537,6 +537,7 @@ extern void reAnchorWord(Buffer *buf, Line *l, int spos, int epos); extern char *reAnchor(Buffer *buf, char *re); #ifdef USE_NNTP extern char *reAnchorNews(Buffer *buf, char *re); +extern char *reAnchorNewsheader(Buffer *buf); #endif /* USE_NNTP */ extern void addMultirowsForm(Buffer *buf, AnchorList *al); extern Anchor *closest_next_anchor(AnchorList *a, Anchor *an, int x, int y); @@ -1,4 +1,4 @@ -/* $Id: url.c,v 1.62 2002/12/27 16:30:54 ukai Exp $ */ +/* $Id: url.c,v 1.63 2003/01/06 15:37:00 ukai Exp $ */ #include "fm.h" #include <sys/types.h> #include <sys/socket.h> @@ -53,6 +53,7 @@ static int 0, /* local-CGI - not defined? */ 0, /* exec - not defined? */ 119, /* nntp */ + 119, /* nntp group */ 119, /* news */ 119, /* news group */ 0, /* mailto - not defined */ @@ -69,6 +70,7 @@ struct cmdtable schemetable[] = { {"file", SCM_LOCAL}, /* {"exec", SCM_EXEC}, */ {"nntp", SCM_NNTP}, + /* {"nntp", SCM_NNTP_GROUP}, */ {"news", SCM_NEWS}, /* {"news", SCM_NEWS_GROUP}, */ #ifndef USE_W3MMAILER @@ -972,10 +974,26 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) return; #endif if (pu->scheme == SCM_NEWS) { - if (pu->file && !strchr(pu->file, '@')) + if (pu->file && !strchr(pu->file, '@') && + (!(p = strchr(pu->file, '/')) || strchr(p + 1, '-') || + *(p + 1) == '\0')) pu->scheme = SCM_NEWS_GROUP; return; } + if (pu->scheme == SCM_NNTP) { + if (pu->file && !strchr(pu->file, '@') && + (!(p = strchr(pu->file + 1, '/')) || strchr(p + 1, '-') || + *(p + 1) == '\0')) + pu->scheme = SCM_NNTP_GROUP; + if (current && (current->scheme == SCM_NNTP || + current->scheme == SCM_NNTP_GROUP)) { + if (pu->host == NULL) + pu->host = current->host; + if (pu->port == NULL) + pu->port = current->port; + } + return; + } if (pu->scheme == SCM_LOCAL) pu->file = expandName(pu->file); @@ -995,9 +1013,6 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) #ifdef USE_GOPHER pu->scheme != SCM_GOPHER && #endif /* USE_GOPHER */ -#ifdef USE_NNTP - pu->scheme != SCM_NEWS && pu->scheme != SCM_NEWS_GROUP && -#endif /* USE_NNTP */ pu->file[0] != '/' #ifdef SUPPORT_DOS_DRIVE_PREFIX && !(pu->scheme == SCM_LOCAL && IS_ALPHA(pu->file[0]) @@ -1076,9 +1091,6 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) #ifdef USE_GOPHER pu->scheme != SCM_GOPHER && #endif /* USE_GOPHER */ -#ifdef USE_NNTP - pu->scheme != SCM_NEWS && pu->scheme != SCM_NEWS_GROUP && -#endif /* USE_NNTP */ pu->file[0] == '/') { /* * this happens on the following conditions: @@ -1108,8 +1120,8 @@ _parsedURL2Str(ParsedURL *pu, int pass) { Str tmp; static char *scheme_str[] = { - "http", "gopher", "ftp", "ftp", "file", "file", "exec", "nntp", "news", - "news", "mailto", + "http", "gopher", "ftp", "ftp", "file", "file", "exec", "nntp", "nntp", + "news", "news", "mailto", #ifdef USE_SSL "https", #endif /* USE_SSL */ @@ -1766,16 +1778,14 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, #endif /* USE_GOPHER */ #ifdef USE_NNTP case SCM_NNTP: - /* nntp://<host>:<port>/<newsgroup-name>/<article-number> */ + case SCM_NNTP_GROUP: case SCM_NEWS: - /* news:<unique>@<full_domain_name> */ case SCM_NEWS_GROUP: - /* news:<newsgroup-name> */ - uf.stream = openNewsStream(pu); - if (uf.stream) - uf.scheme = SCM_NEWS; /* XXX */ + if (pu->scheme == SCM_NNTP || pu->scheme == SCM_NEWS) + uf.scheme = SCM_NEWS; else - uf.scheme = pu->scheme; + uf.scheme = SCM_NEWS_GROUP; + uf.stream = openNewsStream(pu); return uf; #endif /* USE_NNTP */ case SCM_UNKNOWN: |