From 5191ed82a17e9acfe91fa637b6132a1099a3719d Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Thu, 30 Aug 2007 22:03:14 +0000 Subject: [PATCH] Move domain-specific options code to config/domain For great modularity! --- src/config/Makefile | 2 +- src/config/conf.c | 1 + src/config/options.c | 100 +------------------------------------------ src/config/options.h | 13 ------ 4 files changed, 3 insertions(+), 113 deletions(-) diff --git a/src/config/Makefile b/src/config/Makefile index 2f86c3cc..0bb2ed5e 100644 --- a/src/config/Makefile +++ b/src/config/Makefile @@ -1,6 +1,6 @@ top_builddir=../.. include $(top_builddir)/Makefile.config -OBJS = cmdline.o conf.o dialogs.o home.o kbdbind.o options.o opttypes.o timer.o urlhist.o +OBJS = cmdline.o conf.o dialogs.o domain.o home.o kbdbind.o options.o opttypes.o timer.o urlhist.o include $(top_srcdir)/Makefile.lib diff --git a/src/config/conf.c b/src/config/conf.c index 3044cf54..4c9f3fa1 100644 --- a/src/config/conf.c +++ b/src/config/conf.c @@ -20,6 +20,7 @@ #include "config/conf.h" #include "config/dialogs.h" +#include "config/domain.h" #include "config/home.h" #include "config/kbdbind.h" #include "config/options.h" diff --git a/src/config/options.c b/src/config/options.c index ebfd4278..2240c735 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -13,6 +13,7 @@ #include "cache/cache.h" #include "config/conf.h" #include "config/dialogs.h" +#include "config/domain.h" #include "config/options.h" #include "config/opttypes.h" #include "dialogs/status.h" @@ -23,8 +24,6 @@ #include "main/main.h" /* shrink_memory() */ #include "main/select.h" #include "network/connection.h" -#include "protocol/uri.h" -#include "session/location.h" #include "session/session.h" #include "terminal/color.h" #include "terminal/screen.h" @@ -34,7 +33,6 @@ #include "util/memory.h" #include "util/string.h" #include "viewer/text/draw.h" -#include "viewer/text/vs.h" /* TODO? In the past, covered by shadow and legends, remembered only by the @@ -244,9 +242,6 @@ get_opt_rec_real(struct option *tree, const unsigned char *name) return opt; } -static struct option *get_domain_option_from_session(unsigned char *, - struct session *); - /* Fetch pointer to value of certain option. It is guaranteed to never return * NULL. Note that you are supposed to use wrapper get_opt(). */ union option_value * @@ -707,99 +702,6 @@ get_option_shadow(struct option *option, struct option *tree, return shadow_option; } -INIT_LIST_OF(struct domain_tree, domain_trees); - -/* Look for the option with the given name in all domain shadow-trees that - * match the given domain-name. Return the option from the the shadow tree - * that best matches the given domain name. */ -static struct option * -get_domain_option(unsigned char *domain_name, int domain_len, - unsigned char *name) -{ - struct option *opt, *longest_match_opt = NULL; - struct domain_tree *longest_match = NULL; - struct domain_tree *domain; - - assert(domain_name); - assert(*domain_name); - - foreach (domain, domain_trees) - if ((!longest_match || domain->len > longest_match->len) - && is_in_domain(domain->name, domain_name, domain_len) - && (opt = get_opt_rec_real(domain->tree, name))) { - longest_match = domain; - longest_match_opt = opt; - } - - return longest_match_opt; -} - -static struct option * -get_domain_option_from_session(unsigned char *name, struct session *ses) -{ - struct uri *uri; - - assert(ses); - assert(name); - - if (!have_location(ses)) - return NULL; - - uri = cur_loc(ses)->vs.uri; - if (!uri->host || !uri->hostlen) - return NULL; - - return get_domain_option(uri->host, uri->hostlen, name); -} - -/* Return the shadow shadow tree for the given domain name, and - * if the domain does not yet have a shadow tree, create it. */ -struct option * -get_domain_tree(unsigned char *domain_name) -{ - struct domain_tree *domain; - int domain_len; - - assert(domain_name); - assert(*domain_name); - - foreach (domain, domain_trees) - if (!strcasecmp(domain->name, domain_name)) - return domain->tree; - - domain_len = strlen(domain_name); - /* One byte is reserved for domain in struct domain_tree. */ - domain = mem_alloc(sizeof(*domain) + domain_len); - if (!domain) return NULL; - - domain->tree = copy_option(config_options, CO_SHALLOW - | CO_NO_LISTBOX_ITEM); - if (!domain->tree) { - mem_free(domain); - return NULL; - } - - memcpy(domain->name, domain_name, domain_len + 1); - domain->len = domain_len; - - add_to_list(domain_trees, domain); - - return domain->tree; -} - -void -done_domain_trees(void) -{ - struct domain_tree *domain, *next; - - foreachsafe (domain, next, domain_trees) { - delete_option(domain->tree); - domain->tree = NULL; - del_from_list(domain); - mem_free(domain); - } -} - LIST_OF(struct option) * init_options_tree(void) diff --git a/src/config/options.h b/src/config/options.h index 59ddc85b..27cab908 100644 --- a/src/config/options.h +++ b/src/config/options.h @@ -182,19 +182,6 @@ extern struct option *copy_option(struct option *, int); struct option *get_option_shadow(struct option *, struct option *, struct option *); -struct domain_tree { - LIST_HEAD(struct domain_tree); - - struct option *tree; - - int len; - - unsigned char name[1]; /* Must be at end of struct. */ -}; - -extern LIST_OF(struct domain_tree) domain_trees; -struct option *get_domain_tree(unsigned char *); - extern void delete_option(struct option *); void mark_option_as_deleted(struct option *);