commit 72ea6579d15abdc5d9d0883a49880c0c51f3860c
parent b30aa0e5d7f0a81ddfa7c27a6e8536f9fea3321d
Author: ukai <ukai>
Date: Mon, 14 Jan 2002 15:59:17 +0000
[w3m-dev 02832] external URI loader support
From: Fumitoshi UKAI <ukai@debian.or.jp>
Diffstat:
10 files changed, 152 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,6 +1,7 @@
2002-01-15 Fumitoshi UKAI <ukai@debian.or.jp>
* [w3m-dev 02832] external URI loader support
+ * NEWS: support external URI loader
* config.h.dist (USE_EXTERNAL_URI_LOADER): added
* config.h.dist (USER_URIMETHODMAP): added
* config.h.dist (SYS_URIMETHODMAP): added
diff --git a/NEWS b/NEWS
@@ -1,5 +1,6 @@
w3m 0.3?
+* support external URI loader
* support -dump_extra ftp://
* new regex implementation
diff --git a/config.h.dist b/config.h.dist
@@ -117,6 +117,7 @@ MODEL=Linux.i686-monster-ja
#undef FTPPASS_HOSTNAMEGEN
#undef USE_NNTP
#undef USE_GOPHER
+#define USE_EXTERNAL_URI_LOADER
#undef USE_ALARM
#define USE_HELP_CGI
@@ -147,6 +148,8 @@ MODEL=Linux.i686-monster-ja
#define SYS_MAILCAP "/etc/mailcap"
#define USER_MIMETYPES "~/.mime.types"
#define SYS_MIMETYPES "/usr/local/lib/mime.types"
+#define USER_URIMETHODMAP RC_DIR "/urimethodmap"
+#define SYS_URIMETHODMAP ETC_DIR "/urimethodmap"
#define DEF_SAVE_FILE "index.html"
diff --git a/configure b/configure
@@ -698,6 +698,7 @@ else
fi
# protocols?
+ask_param "External URI loader support" use_external_uri_loader y
ask_param "NNTP support" use_nntp $include_opt
ask_param "Gopher support" use_gopher $include_opt
@@ -2044,6 +2045,7 @@ $def_use_cookie
$def_use_ssl
$def_use_ssl_verify
$def_ftppass_hostnamegen
+$def_use_external_uri_loader
$def_use_nntp
$def_use_gopher
$def_use_alarm
@@ -2076,6 +2078,8 @@ $def_use_help_cgi
#define SYS_MAILCAP "/etc/mailcap"
#define USER_MIMETYPES "~/.mime.types"
#define SYS_MIMETYPES "$MIME_TYPES"
+#define USER_URIMETHODMAP RC_DIR "/urimethodmap"
+#define SYS_URIMETHODMAP ETC_DIR "/urimethodmap"
#define DEF_SAVE_FILE "index.html"
diff --git a/file.c b/file.c
@@ -1069,14 +1069,27 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
else {
b = dirBuffer(pu.real_file);
if (b == NULL)
- return NULL;
+ return NO_BUFFER;
t = "text/html";
b->real_scheme = pu.scheme;
goto loaded;
}
}
}
+ break;
+#ifdef USE_EXTERNAL_URI_LOADER
+ case SCM_UNKNOWN:
+ tmp = searchURIMethods(&pu);
+ if (tmp != NULL) {
+ b = loadGeneralFile(tmp->ptr, NULL, NO_REFERER, 0, NULL);
+ if (b != NO_BUFFER)
+ return b;
+ }
+ break;
+#endif
}
+ disp_err_message(Sprintf("Unknown URI: %s",
+ parsedURL2Str(&pu)->ptr)->ptr, FALSE);
return NO_BUFFER;
}
diff --git a/fm.h b/fm.h
@@ -784,6 +784,9 @@ global struct cookie *First_cookie init(NULL);
global char *mailcap_files init(USER_MAILCAP ", " SYS_MAILCAP);
global char *mimetypes_files init(USER_MIMETYPES ", " SYS_MIMETYPES);
+#ifdef USE_EXTERNAL_URI_LOADER
+global char *urimethodmap_files init(USER_URIMETHODMAP ", " SYS_URIMETHODMAP);
+#endif
global TextList *fileToDelete;
diff --git a/menu.c b/menu.c
@@ -1281,7 +1281,7 @@ initSelectMenu(void)
conv_from_system(buf->currentURL.real_file));
}
break;
- case SCM_UNKNOWN:
+ // case SCM_UNKNOWN:
case SCM_MISSING:
break;
default:
diff --git a/proto.h b/proto.h
@@ -110,6 +110,10 @@ extern void setAlarmEvent(int sec, short status, int cmd, void *data);
extern int currentLn(Buffer *buf);
extern void tmpClearBuffer(Buffer *buf);
extern char *filename_extension(char *patch, int is_url);
+#ifdef USE_EXTERNAL_URI_LOADER
+extern void initURIMethods();
+extern Str searchURIMethods(ParsedURL *pu);
+#endif
extern void examineFile(char *path, URLFile *uf);
extern char *acceptableEncoding();
extern int dir_exist(char *path);
diff --git a/rc.c b/rc.c
@@ -110,6 +110,7 @@ static char *config_file = NULL;
#define CMT_SHOW_SRCH_STR "検索文字列を表示する"
#define CMT_MIMETYPES "利用するmime.types"
#define CMT_MAILCAP "利用するmailcap"
+#define CMT_URIMETHODMAP "利用するurimethodmap"
#define CMT_EDITOR "利用するエディタ"
#define CMT_MAILER "利用するメーラ"
#define CMT_EXTBRZ "外部ブラウザ"
@@ -227,6 +228,7 @@ static char *config_file = NULL;
#define CMT_SHOW_SRCH_STR "Show search strings"
#define CMT_MIMETYPES "mime.types files"
#define CMT_MAILCAP "mailcap files"
+#define CMT_URIMETHODMAP "urimethodmap files"
#define CMT_EDITOR "Editor"
#define CMT_MAILER "Mailer"
#define CMT_EXTBRZ "External Browser"
@@ -503,6 +505,10 @@ struct param_ptr params6[] = {
{"mime_types", P_STRING, PI_TEXT, (void *)&mimetypes_files, CMT_MIMETYPES,
NULL},
{"mailcap", P_STRING, PI_TEXT, (void *)&mailcap_files, CMT_MAILCAP, NULL},
+#ifdef USE_EXTERNAL_URI_LOADER
+ {"urimethodmap", P_STRING, PI_TEXT, (void *)&urimethodmap_files,
+ CMT_URIMETHODMAP, NULL},
+#endif
{"editor", P_STRING, PI_TEXT, (void *)&Editor, CMT_EDITOR, NULL},
{"mailer", P_STRING, PI_TEXT, (void *)&Mailer, CMT_MAILER, NULL},
{"extbrowser", P_STRING, PI_TEXT, (void *)&ExtBrowser, CMT_EXTBRZ, NULL},
@@ -1099,6 +1105,9 @@ sync_with_option(void)
#endif
initMailcap();
initMimeTypes();
+#ifdef USE_EXTERNAL_URI_LOADER
+ initURIMethods();
+#endif
if (AcceptLang == NULL || *AcceptLang == '\0') {
#if LANG == JA
diff --git a/url.c b/url.c
@@ -709,6 +709,10 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current)
goto analyze_file;
}
/* scheme part has been found */
+ if (p_url->scheme == SCM_UNKNOWN) {
+ p_url->file = allocStr(url, -1);
+ return;
+ }
/* get host and port */
if (p[0] != '/' || p[1] != '/') { /* scheme:foo or scheme:/foo */
p_url->host = NULL;
@@ -1083,9 +1087,12 @@ _parsedURL2Str(ParsedURL *pu, int pass)
#endif /* USE_SSL */
};
- if (pu->scheme == SCM_UNKNOWN || pu->scheme == SCM_MISSING) {
+ if (pu->scheme == SCM_MISSING) {
return Strnew_charp("???");
}
+ else if (pu->scheme == SCM_UNKNOWN) {
+ return Strnew_charp(pu->file);
+ }
if (pu->host == NULL && pu->file == NULL && pu->label != NULL) {
/* local label */
return Sprintf("#%s", pu->label);
@@ -1945,3 +1952,107 @@ filename_extension(char *path, int is_url)
else
return last_dot;
}
+
+#ifdef USE_EXTERNAL_URI_LOADER
+static struct table2 **urimethods;
+
+static struct table2 *
+loadURIMethods(char *filename)
+{
+ FILE *f;
+ int i, n;
+ Str tmp;
+ struct table2 *um;
+ char *up, *p;
+
+ f = fopen(expandName(filename), "r");
+ if (f == NULL)
+ return NULL;
+ i = 0;
+ while (tmp = Strfgets(f), tmp->length > 0) {
+ if (tmp->ptr[0] != '#')
+ i++;
+ }
+ fseek(f, 0, 0);
+ n = i;
+ um = New_N(struct table2, n + 1);
+ i = 0;
+ while (tmp = Strfgets(f), tmp->length > 0) {
+ if (tmp->ptr[0] == '#')
+ continue;
+ while (IS_SPACE(Strlastchar(tmp)))
+ Strshrink(tmp, 1);
+ for (up = p = tmp->ptr; *p != '\0'; p++) {
+ if (*p == ':') {
+ um[i].item1 = Strnew_charp_n(up, p - up)->ptr;
+ p++;
+ break;
+ }
+ }
+ if (*p == '\0')
+ continue;
+ while (*p != '\0' && IS_SPACE(*p))
+ p++;
+ um[i].item2 = Strnew_charp(p)->ptr;
+ i++;
+ }
+ um[i].item1 = NULL;
+ um[i].item2 = NULL;
+ fclose(f);
+ return um;
+}
+
+void
+initURIMethods()
+{
+ TextList *methodmap_list = NULL;
+ TextListItem *tl;
+ int i;
+
+ if (non_null(urimethodmap_files))
+ methodmap_list = make_domain_list(urimethodmap_files);
+ if (methodmap_list == NULL)
+ return;
+ urimethods = New_N(struct table2 *, (methodmap_list->nitem + 1));
+ for (i = 0, tl = methodmap_list->first; tl; tl = tl->next) {
+ urimethods[i] = loadURIMethods(tl->ptr);
+ if (urimethods[i])
+ i++;
+ }
+ urimethods[i] = NULL;
+}
+
+Str
+searchURIMethods(ParsedURL *pu)
+{
+ struct table2 *ump;
+ int i;
+ Str scheme = NULL;
+ Str url;
+ char *p;
+
+ if (pu->scheme != SCM_UNKNOWN)
+ return NULL; /* use internal */
+ if (urimethods == NULL)
+ return NULL;
+ url = parsedURL2Str(pu);
+ for (p = url->ptr; *p != '\0'; p++) {
+ if (*p == ':') {
+ scheme = Strnew_charp_n(url->ptr, p - url->ptr);
+ break;
+ }
+ }
+ if (scheme == NULL)
+ return NULL;
+
+ for (i = 0; (ump = urimethods[i]) != NULL; i++) {
+ while (ump->item1 != NULL) {
+ if (strcmp(ump->item1, scheme->ptr) == 0) {
+ return Sprintf(ump->item2, url_quote(url->ptr));
+ }
+ ump++;
+ }
+ }
+ return NULL;
+}
+#endif