From 680a1c735bdea9c49a9d76186189d2b469b2538d Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 20:50:45 +0000 Subject: [PATCH 1/9] MIME: Re-arrange Let get_mime_handler_name return an option instead of a name, and rename it to get_mime_handler_option. --- src/mime/backend/default.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 466261da6..0715c32fc 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -168,8 +168,8 @@ get_mime_type_name(unsigned char *type) return NULL; } -static inline unsigned char * -get_mime_handler_name(unsigned char *type, int xwin) +static inline struct option * +get_mime_handler_option(unsigned char *type, int xwin) { struct option *opt; unsigned char *name = get_mime_type_name(type); @@ -180,20 +180,20 @@ get_mime_handler_name(unsigned char *type, int xwin) mem_free(name); if (!opt) return NULL; - return straconcat("mime.handler.", opt->value.string, + name = straconcat("mime.handler.", opt->value.string, ".", get_system_str(xwin), NULL); + if (!name) return NULL; + + opt = get_opt_rec_real(config_options, name); + mem_free(name); + + return opt; } static struct mime_handler * get_mime_handler_default(unsigned char *type, int have_x) { - struct option *opt_tree; - unsigned char *handler_name = get_mime_handler_name(type, have_x); - - if (!handler_name) return NULL; - - opt_tree = get_opt_rec_real(config_options, handler_name); - mem_free(handler_name); + struct option *opt_tree = get_mime_handler_option(type, have_x); if (opt_tree) { unsigned char *desc = ""; From 9bc5317b13713e60b0dbbc96e1af993f6a5f39c9 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 20:58:30 +0000 Subject: [PATCH 2/9] MIME: Re-arrange Let get_mime_type_name return an option instead of a name, and rename it to get_mime_type_option. --- src/mime/backend/default.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 0715c32fc..4e77e557b 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -143,8 +143,8 @@ get_content_type_default(unsigned char *extension) return NULL; } -static unsigned char * -get_mime_type_name(unsigned char *type) +static struct option * +get_mime_type_option(unsigned char *type) { struct string name; int oldlength; @@ -159,8 +159,13 @@ get_mime_type_name(unsigned char *type) /* Search for end of the base type. */ pos = strchr(pos, '/'); if (pos) { + struct option *opt; + *pos = '.'; - return name.source; + opt = get_opt_rec_real(config_options, name.source); + done_string(&name); + + return opt; } } @@ -171,13 +176,9 @@ get_mime_type_name(unsigned char *type) static inline struct option * get_mime_handler_option(unsigned char *type, int xwin) { - struct option *opt; - unsigned char *name = get_mime_type_name(type); + struct option *opt = get_mime_type_option(type); + unsigned char *name; - if (!name) return NULL; - - opt = get_opt_rec_real(config_options, name); - mem_free(name); if (!opt) return NULL; name = straconcat("mime.handler.", opt->value.string, @@ -197,17 +198,10 @@ get_mime_handler_default(unsigned char *type, int have_x) if (opt_tree) { unsigned char *desc = ""; - unsigned char *mt = get_mime_type_name(type); + struct option *opt = get_mime_type_option(type); /* Try to find some description to assing to @name */ - if (mt) { - struct option *opt; - - opt = get_opt_rec_real(config_options, mt); - mem_free(mt); - - if (opt) desc = opt->value.string; - } + if (opt) desc = opt->value.string; return init_mime_handler(get_opt_str_tree(opt_tree, "program"), desc, default_mime_module.name, From 386684fe50fa9697cb31b868d846aa0b2e1b63e3 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:09:21 +0000 Subject: [PATCH 3/9] MIME: get_mime_type_option: Re-arrange More option API usage, less string manipulation. --- src/mime/backend/default.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 4e77e557b..d09da8a6c 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -146,23 +146,21 @@ get_content_type_default(unsigned char *extension) static struct option * get_mime_type_option(unsigned char *type) { + struct option *opt; struct string name; - int oldlength; + + opt = get_opt_rec_real(config_options, "mime.type"); + if (!opt) 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))) { - unsigned char *pos = name.source + oldlength; - /* Search for end of the base type. */ - pos = strchr(pos, '/'); - if (pos) { - struct option *opt; + unsigned char *pos = strchr(name.source, '/'); + if (pos) { *pos = '.'; - opt = get_opt_rec_real(config_options, name.source); + opt = get_opt_rec_real(opt, name.source); done_string(&name); return opt; From 8f4b40d4a0fd02bc3639520b64634ff43e40f5a0 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:15:41 +0000 Subject: [PATCH 4/9] MIME: get_mime_handler_option: Rename local variable opt to type_opt --- src/mime/backend/default.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index d09da8a6c..8383a862a 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -174,19 +174,19 @@ get_mime_type_option(unsigned char *type) static inline struct option * get_mime_handler_option(unsigned char *type, int xwin) { - struct option *opt = get_mime_type_option(type); + struct option *type_opt = get_mime_type_option(type); unsigned char *name; - if (!opt) return NULL; + if (!type_opt) return NULL; - name = straconcat("mime.handler.", opt->value.string, + name = straconcat("mime.handler.", type_opt->value.string, ".", get_system_str(xwin), NULL); if (!name) return NULL; - opt = get_opt_rec_real(config_options, name); + type_opt = get_opt_rec_real(config_options, name); mem_free(name); - return opt; + return type_opt; } static struct mime_handler * From 06a541487e7be9d56ef3f0682a88d4fe86d5dab2 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:21:42 +0000 Subject: [PATCH 5/9] MIME: get_mime_handler_option: More option API usage, less string manipulation. --- src/mime/backend/default.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 8383a862a..ed90d81df 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -174,19 +174,18 @@ get_mime_type_option(unsigned char *type) static inline struct option * get_mime_handler_option(unsigned char *type, int xwin) { + struct option *handler_opt; struct option *type_opt = get_mime_type_option(type); - unsigned char *name; if (!type_opt) return NULL; - name = straconcat("mime.handler.", type_opt->value.string, - ".", get_system_str(xwin), NULL); - if (!name) return NULL; + handler_opt = get_opt_rec_real(config_options, "mime.handler"); + if (!handler_opt) return NULL; - type_opt = get_opt_rec_real(config_options, name); - mem_free(name); + handler_opt = get_opt_rec_real(handler_opt, type_opt->value.string); + if (!handler_opt) return NULL; - return type_opt; + return get_opt_rec_real(handler_opt, get_system_str(xwin)); } static struct mime_handler * From 9337a7993d93f0ec2464cb2ce3e9c3c2a8df2195 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:25:43 +0000 Subject: [PATCH 6/9] MIME: get_mime_handler_default: Reflow logic. --- src/mime/backend/default.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index ed90d81df..ed4aacbf4 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -191,22 +191,19 @@ get_mime_handler_option(unsigned char *type, int xwin) static struct mime_handler * get_mime_handler_default(unsigned char *type, int have_x) { + unsigned char *desc = ""; + struct option *opt = get_mime_type_option(type); struct option *opt_tree = get_mime_handler_option(type, have_x); - if (opt_tree) { - unsigned char *desc = ""; - struct option *opt = get_mime_type_option(type); + if (!opt_tree) return NULL; - /* Try to find some description to assing to @name */ - if (opt) desc = opt->value.string; + /* Try to find some description to assing to @name */ + 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; + 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")); } From e6d35d8f3119bbc9089f2a1da8f153bbabd8b484 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:28:05 +0000 Subject: [PATCH 7/9] MIME: get_mime_handler_default: Rename stuff. Rename local variables opt to type_opt and opt_tree to handler_opt. --- src/mime/backend/default.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index ed4aacbf4..8586c2f19 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -192,18 +192,18 @@ static struct mime_handler * get_mime_handler_default(unsigned char *type, int have_x) { unsigned char *desc = ""; - struct option *opt = get_mime_type_option(type); - struct option *opt_tree = get_mime_handler_option(type, have_x); + struct option *type_opt = get_mime_type_option(type); + struct option *handler_opt = get_mime_handler_option(type, have_x); - if (!opt_tree) return NULL; + if (!handler_opt) return NULL; /* Try to find some description to assing to @name */ - if (opt) desc = opt->value.string; + if (type_opt) desc = type_opt->value.string; - return init_mime_handler(get_opt_str_tree(opt_tree, "program"), + return init_mime_handler(get_opt_str_tree(handler_opt, "program"), desc, default_mime_module.name, - get_opt_bool_tree(opt_tree, "ask"), - get_opt_bool_tree(opt_tree, "block")); + get_opt_bool_tree(handler_opt, "ask"), + get_opt_bool_tree(handler_opt, "block")); } From 675fc46987c7f5003947a9f641d6a6384b0c38d5 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:32:04 +0000 Subject: [PATCH 8/9] MIME: Let get_mime_handler_option take the MIME type's option instead of its name. --- src/mime/backend/default.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 8586c2f19..01a136c03 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -172,12 +172,11 @@ get_mime_type_option(unsigned char *type) } static inline struct option * -get_mime_handler_option(unsigned char *type, int xwin) +get_mime_handler_option(struct option *type_opt, int xwin) { struct option *handler_opt; - struct option *type_opt = get_mime_type_option(type); - if (!type_opt) return NULL; + assert(type_opt); handler_opt = get_opt_rec_real(config_options, "mime.handler"); if (!handler_opt) return NULL; @@ -193,8 +192,11 @@ get_mime_handler_default(unsigned char *type, int have_x) { unsigned char *desc = ""; struct option *type_opt = get_mime_type_option(type); - struct option *handler_opt = get_mime_handler_option(type, have_x); + struct option *handler_opt; + if (!type_opt) return NULL; + + handler_opt = get_mime_handler_option(type_opt, have_x); if (!handler_opt) return NULL; /* Try to find some description to assing to @name */ From 8147b0f14950239263a44dbc704f113241ed81a3 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 5 May 2006 21:35:02 +0000 Subject: [PATCH 9/9] MIME: get_mime_handler_option: Eliminate an unnecessary check. --- src/mime/backend/default.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/mime/backend/default.c b/src/mime/backend/default.c index 01a136c03..3cbc7852c 100644 --- a/src/mime/backend/default.c +++ b/src/mime/backend/default.c @@ -190,7 +190,6 @@ get_mime_handler_option(struct option *type_opt, int xwin) static struct mime_handler * get_mime_handler_default(unsigned char *type, int have_x) { - unsigned char *desc = ""; struct option *type_opt = get_mime_type_option(type); struct option *handler_opt; @@ -199,11 +198,9 @@ get_mime_handler_default(unsigned char *type, int have_x) handler_opt = get_mime_handler_option(type_opt, have_x); if (!handler_opt) return NULL; - /* Try to find some description to assing to @name */ - if (type_opt) desc = type_opt->value.string; - return init_mime_handler(get_opt_str_tree(handler_opt, "program"), - desc, default_mime_module.name, + type_opt->value.string, + default_mime_module.name, get_opt_bool_tree(handler_opt, "ask"), get_opt_bool_tree(handler_opt, "block")); }