0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

Merge with git+ssh://pasky.or.cz/srv/git/elinks.git

This commit is contained in:
Witold Filipczyk 2006-05-06 08:10:57 +02:00 committed by Witold Filipczyk
commit 47062531ee

View File

@ -143,24 +143,27 @@ get_content_type_default(unsigned char *extension)
return NULL; return NULL;
} }
static unsigned char * static struct option *
get_mime_type_name(unsigned char *type) get_mime_type_option(unsigned char *type)
{ {
struct option *opt;
struct string name; struct string name;
int oldlength;
opt = get_opt_rec_real(config_options, "mime.type");
if (!opt) return NULL;
if (!init_string(&name)) return NULL; if (!init_string(&name)) return NULL;
add_to_string(&name, "mime.type.");
oldlength = name.length;
if (add_optname_to_string(&name, type, strlen(type))) { if (add_optname_to_string(&name, type, strlen(type))) {
unsigned char *pos = name.source + oldlength;
/* Search for end of the base type. */ /* Search for end of the base type. */
pos = strchr(pos, '/'); unsigned char *pos = strchr(name.source, '/');
if (pos) { if (pos) {
*pos = '.'; *pos = '.';
return name.source; opt = get_opt_rec_real(opt, name.source);
done_string(&name);
return opt;
} }
} }
@ -168,54 +171,38 @@ get_mime_type_name(unsigned char *type)
return NULL; return NULL;
} }
static inline unsigned char * static inline struct option *
get_mime_handler_name(unsigned char *type, int xwin) get_mime_handler_option(struct option *type_opt, int xwin)
{ {
struct option *opt; struct option *handler_opt;
unsigned char *name = get_mime_type_name(type);
if (!name) return NULL; assert(type_opt);
opt = get_opt_rec_real(config_options, name); handler_opt = get_opt_rec_real(config_options, "mime.handler");
mem_free(name); if (!handler_opt) return NULL;
if (!opt) return NULL;
return straconcat("mime.handler.", opt->value.string, handler_opt = get_opt_rec_real(handler_opt, type_opt->value.string);
".", get_system_str(xwin), NULL); if (!handler_opt) return NULL;
return get_opt_rec_real(handler_opt, get_system_str(xwin));
} }
static struct mime_handler * static struct mime_handler *
get_mime_handler_default(unsigned char *type, int have_x) get_mime_handler_default(unsigned char *type, int have_x)
{ {
struct option *opt_tree; struct option *type_opt = get_mime_type_option(type);
unsigned char *handler_name = get_mime_handler_name(type, have_x); struct option *handler_opt;
if (!handler_name) return NULL; if (!type_opt) return NULL;
opt_tree = get_opt_rec_real(config_options, handler_name); handler_opt = get_mime_handler_option(type_opt, have_x);
mem_free(handler_name); if (!handler_opt) return NULL;
if (opt_tree) { return init_mime_handler(get_opt_str_tree(handler_opt, "program"),
unsigned char *desc = ""; type_opt->value.string,
unsigned char *mt = get_mime_type_name(type); default_mime_module.name,
get_opt_bool_tree(handler_opt, "ask"),
/* Try to find some description to assing to @name */ get_opt_bool_tree(handler_opt, "block"));
if (mt) {
struct option *opt;
opt = get_opt_rec_real(config_options, mt);
mem_free(mt);
if (opt) desc = opt->value.string;
}
return init_mime_handler(get_opt_str_tree(opt_tree, "program"),
desc, default_mime_module.name,
get_opt_bool_tree(opt_tree, "ask"),
get_opt_bool_tree(opt_tree, "block"));
}
return NULL;
} }