From 756fee58cb050da56b8df868f71de28ee9ca73c0 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Wed, 18 Aug 2021 14:54:41 +0200 Subject: [PATCH] Rename ConfigItem_include to ConfigResource and also use it for non-includes such as other items in the configuration file that are URLs. --- include/h.h | 2 +- include/struct.h | 20 +++-- src/conf.c | 212 ++++++++++++++++++++++---------------------- src/modulemanager.c | 2 +- src/modules/staff.c | 86 +++++++++++------- src/serv.c | 10 +-- src/url.c | 3 + src/windows/gui.c | 16 ++-- 8 files changed, 189 insertions(+), 162 deletions(-) diff --git a/include/h.h b/include/h.h index 0df2e9230..0ac455e26 100644 --- a/include/h.h +++ b/include/h.h @@ -87,7 +87,7 @@ extern MODVAR ConfigItem_allow_channel *conf_allow_channel; extern MODVAR ConfigItem_deny_version *conf_deny_version; extern MODVAR ConfigItem_log *conf_log; extern MODVAR ConfigItem_alias *conf_alias; -extern MODVAR ConfigItem_include *conf_include; +extern MODVAR ConfigResource *downloads; extern MODVAR ConfigItem_help *conf_help; extern MODVAR ConfigItem_offchans *conf_offchans; extern MODVAR SecurityGroup *securitygroups; diff --git a/include/struct.h b/include/struct.h index e46982bc6..b0a733f87 100644 --- a/include/struct.h +++ b/include/struct.h @@ -113,7 +113,7 @@ typedef struct ConfigItem_unknown ConfigItem_unknown; typedef struct ConfigItem_unknown_ext ConfigItem_unknown_ext; typedef struct ConfigItem_alias ConfigItem_alias; typedef struct ConfigItem_alias_format ConfigItem_alias_format; -typedef struct ConfigItem_include ConfigItem_include; +typedef struct ConfigResource ConfigResource; typedef struct ConfigItem_blacklist_module ConfigItem_blacklist_module; typedef struct ConfigItem_help ConfigItem_help; typedef struct ConfigItem_offchans ConfigItem_offchans; @@ -139,7 +139,7 @@ typedef struct MessageTag MessageTag; typedef struct MOTDFile MOTDFile; /* represents a whole MOTD, including remote MOTD support info */ typedef struct MOTDLine MOTDLine; /* one line of a MOTD stored as a linked list */ #ifdef USE_LIBCURL -typedef struct MOTDDownload MOTDDownload; /* used to coordinate download of a remote MOTD */ +typedef struct MOTDConfigResource MOTDConfigResource; /* used to coordinate download of a remote MOTD */ #endif typedef struct RealCommand RealCommand; @@ -808,7 +808,7 @@ struct MultiLine { }; #ifdef USE_LIBCURL -struct MOTDDownload +struct MOTDConfigResource { MOTDFile *themotd; }; @@ -829,7 +829,7 @@ struct MOTDFile To prevent such a situation from leading to a segfault, we introduce this remote control pointer. It works like this: - 1. read_motd() is called with a URL. A new MOTDDownload is + 1. read_motd() is called with a URL. A new MOTDConfigResource is allocated and the pointer is placed here. This pointer is also passed to the asynchrnous download handler. 2.a. The download is completed and read_motd_async_downloaded() @@ -842,7 +842,7 @@ struct MOTDFile the download. read_motd_async_downloaded() is eventually called and frees motd_download. */ - struct MOTDDownload *motd_download; + struct MOTDConfigResource *motd_download; #endif /* USE_LIBCURL */ }; @@ -1889,12 +1889,14 @@ struct ConfigItem_alias_format { Match *expr; }; -#define INCLUDE_REMOTE 0x1 -#define INCLUDE_DLQUEUED 0x2 +#define RESOURCE_REMOTE 0x1 +#define RESOURCE_DLQUEUED 0x2 +#define RESOURCE_INCLUDE 0x4 -struct ConfigItem_include { - ConfigItem_include *prev, *next; +struct ConfigResource { + ConfigResource *prev, *next; ConfigFlag_ban flag; + ConfigEntry *ce; char *file; char *url; char *errorbuf; diff --git a/src/conf.c b/src/conf.c index fc4630aef..593643c4e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -230,7 +230,7 @@ ConfigItem_allow_channel *conf_allow_channel = NULL; ConfigItem_deny_link *conf_deny_link = NULL; ConfigItem_deny_version *conf_deny_version = NULL; ConfigItem_alias *conf_alias = NULL; -ConfigItem_include *conf_include = NULL; +ConfigResource *config_resources = NULL; ConfigItem_blacklist_module *conf_blacklist_module = NULL; ConfigItem_help *conf_help = NULL; ConfigItem_offchans *conf_offchans = NULL; @@ -254,11 +254,11 @@ char *port_6667_ip = NULL; void add_include(const char *filename, const char *included_from, int included_from_line); #ifdef USE_LIBCURL -ConfigItem_include *add_remote_include(const char *, const char *, int, const char *, const char *included_from, int included_from_line); -void update_remote_include(ConfigItem_include *inc, const char *file, int, const char *errorbuf); -int remote_include(ConfigEntry *ce); +ConfigResource *add_config_resource(const char *resource, int type, ConfigEntry *ce); +void update_config_resource(ConfigResource *inc, const char *file, int, const char *errorbuf); +void resource_download_complete(const char *url, const char *file, const char *errorbuf, int cached, void *inc_key); #endif -void free_all_includes(void); +void free_all_config_resources(void); int rehash_internal(Client *client); int is_blacklisted_module(char *name); @@ -2120,7 +2120,7 @@ void config_load_failed(void) { unreal_log(ULOG_ERROR, "config", "CONFIG_NOT_LOADED", NULL, "IRCd configuration failed to load"); Unload_all_testing_modules(); - free_all_includes(); + free_all_config_resources(); config_free(conf); conf = NULL; free_iConf(&tempiConf); @@ -2155,11 +2155,11 @@ int config_read_start(void) int is_config_read_finished(void) { - ConfigItem_include *inc; + ConfigResource *inc; - for (inc = conf_include; inc; inc = inc->next) + for (inc = config_resources; inc; inc = inc->next) { - if (inc->flag.type & INCLUDE_DLQUEUED) + if (inc->flag.type & RESOURCE_DLQUEUED) { //config_status("Waiting for %s...", inc->url); return 0; @@ -2231,8 +2231,6 @@ int config_test(void) } } - free_all_includes(); - Init_all_testing_modules(); if (config_run_blocks() < 0) @@ -2270,6 +2268,19 @@ int config_test(void) return 0; } +void config_parse_and_queue_urls(ConfigEntry *ce) +{ + for (; ce; ce = ce->next) + { + if (ce->name && !strcmp(ce->name, "include")) + continue; /* handled elsewhere (but maybe merge? TODO) */ + if (ce->value && url_is_valid(ce->value)) + add_config_resource(ce->value, 0, ce); + if (ce->items) + config_parse_and_queue_urls(ce->items); + } +} + /** * Processes filename as part of the IRCd's configuration. * @@ -2288,7 +2299,7 @@ int config_read_file(char *filename, const char *original_path) { ConfigFile *cfptr, *cfptr2, **cfptr3; ConfigEntry *ce; - ConfigItem_include *inc, *my_inc; + ConfigResource *inc, *my_inc; int ret; int counter; @@ -2304,20 +2315,17 @@ int config_read_file(char *filename, const char *original_path) * entry for our current file. */ counter = 0; - for (inc = conf_include; inc; inc = inc->next) + for (inc = config_resources; inc; inc = inc->next) { - if (!strcmp(filename, inc->file)) - { - counter ++; - continue; - } -#ifdef _WIN32 - if (!strcasecmp(filename, inc->file)) - { - counter ++; - continue; - } +#ifndef _WIN32 + if (inc->file && !strcmp(filename, inc->file)) +#else + if (inc->file && !strcasecmp(filename, inc->file)) #endif + { + counter ++; + continue; + } if (inc->url && !strcmp(original_path, inc->url)) { counter ++; @@ -2348,9 +2356,13 @@ int config_read_file(char *filename, const char *original_path) if (!strcmp(ce->name, "blacklist-module")) _test_blacklist_module(cfptr, ce); + /* Load urls */ + config_parse_and_queue_urls(cfptr->items); + /* Load includes */ if (config_verbose > 1) config_status("Searching through %s for include files..", filename); + for (ce = cfptr->items; ce; ce = ce->next) { if (!strcmp(ce->name, "include")) @@ -3324,7 +3336,7 @@ char *convert_to_absolute_path_duplicate(char *path, char *reldir) * Actual config parser funcs */ -int _conf_include(ConfigFile *conf, ConfigEntry *ce) +int _conf_include(ConfigFile *conf, ConfigEntry *ce) { int ret = 0; #ifdef GLOBH @@ -3350,7 +3362,10 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) #ifdef USE_LIBCURL if (url_is_valid(ce->value)) - return remote_include(ce); + { + add_config_resource(ce->value, RESOURCE_INCLUDE, ce); + return 0; + } #else if (strstr(ce->value, "://")) { @@ -9478,7 +9493,7 @@ void start_listeners(void) void config_run(void) { start_listeners(); - free_all_includes(); + free_all_config_resources(); } int _conf_offchans(ConfigFile *conf, ConfigEntry *ce) @@ -10649,22 +10664,22 @@ int _conf_secret(ConfigFile *conf, ConfigEntry *ce) } #ifdef USE_LIBCURL -static void conf_download_complete(const char *url, const char *file, const char *errorbuf, int cached, void *inc_key) +void resource_download_complete(const char *url, const char *file, const char *errorbuf, int cached, void *inc_key) { - ConfigItem_include *inc = (ConfigItem_include *)inc_key; + ConfigResource *rs = (ConfigResource *)inc_key; - inc->flag.type &= ~INCLUDE_DLQUEUED; + rs->flag.type &= ~RESOURCE_DLQUEUED; - config_status("conf_download_complete() for %s [%s]", url, errorbuf?errorbuf:"success"); + config_status("resource_download_complete() for %s [%s]", url, errorbuf?errorbuf:"success"); if (!file && !cached) { /* DOWNLOAD FAILED */ - update_remote_include(inc, file, 0, errorbuf); + update_config_resource(rs, file, 0, errorbuf); unreal_log(ULOG_ERROR, "config", "DOWNLOAD_FAILED", NULL, "$file:$line_number: Failed to download '$url': $error_message", - log_data_string("file", inc->included_from), - log_data_integer("line_number", inc->included_from_line), + log_data_string("file", rs->included_from), + log_data_integer("line_number", rs->included_from_line), log_data_string("url", displayurl(url)), log_data_string("error_message", errorbuf)); /* Set error condition, this so config_read_file() later will stop. */ @@ -10683,9 +10698,9 @@ static void conf_download_complete(const char *url, const char *file, const char if (cached) { - unreal_copyfileex(inc->file, tmp, 1); - unreal_copyfileex(inc->file, unreal_mkcache(url), 0); - update_remote_include(inc, tmp, 0, NULL); + unreal_copyfileex(rs->file, tmp, 1); + unreal_copyfileex(rs->file, unreal_mkcache(url), 0); + update_config_resource(rs, tmp, 0, NULL); } else { @@ -10694,10 +10709,16 @@ static void conf_download_complete(const char *url, const char *file, const char remove(file). */ unreal_copyfileex(file, tmp, 1); - update_remote_include(inc, tmp, 0, NULL); + update_config_resource(rs, tmp, 0, NULL); unreal_copyfileex(file, unreal_mkcache(url), 0); } - config_read_file(inc->file, inc->url); + + if (rs->flag.type & RESOURCE_INCLUDE) + { + config_read_file(rs->file, rs->url); + } else { + safe_strdup(rs->ce->value, rs->file); // now information of url is lost hm! + } } /* If rehashing, check if we are done. @@ -10719,7 +10740,7 @@ static void conf_download_complete(const char *url, const char *file, const char void request_rehash(Client *client) { #ifdef USE_LIBCURL - ConfigItem_include *inc; + ConfigResource *inc; char found_remote = 0; if (loop.rehashing) { @@ -10840,48 +10861,22 @@ void listen_cleanup() close_unbound_listeners(); } -#ifdef USE_LIBCURL -char *find_remote_include(char *url, char **errorbuf) +ConfigResource *find_config_resource(char *url) { - ConfigItem_include *inc; + ConfigResource *inc; - for (inc = conf_include; inc; inc = inc->next) + for (inc = config_resources; inc; inc = inc->next) { - if (!(inc->flag.type & INCLUDE_REMOTE)) + if (!(inc->flag.type & RESOURCE_REMOTE)) continue; - if (!strcasecmp(url, inc->url)) - { - *errorbuf = inc->errorbuf; - return inc->file; - } + if (inc->url && !strcasecmp(url, inc->url)) + return inc; } return NULL; } /** - * Non-asynchronous remote inclusion to give a user better feedback - * when first starting his IRCd. - * - * The asynchronous friend is rehash() which merely queues remote - * includes for download using download_file_async(). - */ -int remote_include(ConfigEntry *ce) -{ - char *errorbuf = NULL; - char *url = ce->value; - char *file = NULL; // ??? - ConfigItem_include *inc; - time_t modtime = 0; // ??? - - inc = add_remote_include(file, url, 0, NULL, ce->file->filename, ce->line_number); - inc->flag.type |= INCLUDE_DLQUEUED; // wait.. why doesn't add_remote_include() do this? - download_file_async(inc->url, modtime, conf_download_complete, (void *)inc); - return 0; -} -#endif - -/** - * Add an item to the conf_include list for the specified file. + * Add an item to the config_resources list for the specified file. * * Checks for whether or not we're performing recursive includes * belong in conf_load() because that function is able to return an @@ -10892,42 +10887,51 @@ int remote_include(ConfigEntry *ce) */ void add_include(const char *file, const char *included_from, int included_from_line) { - ConfigItem_include *inc; + ConfigResource *inc; - inc = safe_alloc(sizeof(ConfigItem_include)); + inc = safe_alloc(sizeof(ConfigResource)); safe_strdup(inc->file, file); safe_strdup(inc->included_from, included_from); inc->included_from_line = included_from_line; - AddListItem(inc, conf_include); + AddListItem(inc, config_resources); } #ifdef USE_LIBCURL -/** - * Adds a remote include entry to the config_include list. - * - * This is to be called whenever the included_from and - * included_from_line parameters are known. This means that during a - * rehash when downloads are done asynchronously, you call this with - * the inclued_from and included_from_line information. After the - * download is complete and you know there it is stored in the FS, - * call update_remote_include(). - */ -ConfigItem_include *add_remote_include(const char *file, const char *url, int flags, const char *errorbuf, const char *included_from, int included_from_line) + +ConfigResource *add_config_resource(const char *resource, int type, ConfigEntry *ce) { - ConfigItem_include *inc; + ConfigResource *rs = safe_alloc(sizeof(ConfigResource)); + int url = 0; - /* we rely on safe_alloc() zeroing the ConfigItem_include */ - inc = safe_alloc(sizeof(ConfigItem_include)); - if (included_from) + config_status("add_config_resource() for '%s", resource); + + if (url_is_valid(resource)) + url = 1; + + safe_strdup(rs->included_from, ce->file->filename); + rs->included_from_line = ce->line_number; + rs->ce = ce; + + if (!url) { - safe_strdup(inc->included_from, included_from); - inc->included_from_line = included_from_line; + safe_strdup(rs->file, resource); + AddListItem(rs, config_resources); + } else { + // FIXME: duplicate entries are fine, and we need to add them to the + // list due to 'ce' expansion and so on. + // However, we should not download the file multiple times, that is + // just a waste ;) + + // FIXME: we pass a NULL file pointer here, even though it may be cached + // FIXME: similarly, we pass 0 modification time to download_file_async() + // while it should be the mtime of the cached entry + safe_strdup(rs->url, resource); + update_config_resource(rs, NULL, type|RESOURCE_REMOTE, NULL); + rs->flag.type |= RESOURCE_DLQUEUED; + AddListItem(rs, config_resources); + download_file_async(rs->url, 0, resource_download_complete, (void *)rs); } - safe_strdup(inc->url, url); - - update_remote_include(inc, file, INCLUDE_REMOTE|flags, errorbuf); - AddListItem(inc, conf_include); - return inc; + return rs; } /** @@ -10940,7 +10944,7 @@ ConfigItem_include *add_remote_include(const char *file, const char *url, int fl * downloading. The error will be stored into the config_include * entry. */ -void update_remote_include(ConfigItem_include *inc, const char *file, int flags, const char *errorbuf) +void update_config_resource(ConfigResource *inc, const char *file, int flags, const char *errorbuf) { /* * file may be NULL when errorbuf is non-NULL and vice-versa. @@ -10954,15 +10958,15 @@ void update_remote_include(ConfigItem_include *inc, const char *file, int flags, } #endif -void free_all_includes(void) +void free_all_config_resources(void) { - ConfigItem_include *inc, *next; + ConfigResource *inc, *next; - for (inc = conf_include; inc; inc = next) + for (inc = config_resources; inc; inc = next) { next = inc->next; #ifdef USE_LIBCURL - if (inc->flag.type & INCLUDE_REMOTE) + if (inc->flag.type & RESOURCE_REMOTE) { /* Delete the file, but only if it's not a cached version */ if (inc->file && strncmp(inc->file, CACHEDIR, strlen(CACHEDIR))) @@ -10975,7 +10979,7 @@ void free_all_includes(void) #endif safe_free(inc->file); safe_free(inc->included_from); - DelListItem(inc, conf_include); + DelListItem(inc, config_resources); safe_free(inc); } } diff --git a/src/modulemanager.c b/src/modulemanager.c index 0701125e8..09e914e86 100644 --- a/src/modulemanager.c +++ b/src/modulemanager.c @@ -1222,7 +1222,7 @@ void mm_install_module(ManagedModule *m) basename = "mod.c"; tmpfile = unreal_mktemp(TMPDIR, basename); - printf("Downloading %s from %s...\n", m->name, m->source); + printf("ConfigResourceing %s from %s...\n", m->name, m->source); if (!mm_http_request(m->source, tmpfile, 1)) { fprintf(stderr, "Repository %s seems to list a module file that cannot be retrieved (%s).\n", m->repo_url, m->source); diff --git a/src/modules/staff.c b/src/modules/staff.c index ca52e3316..890eb88aa 100644 --- a/src/modules/staff.c +++ b/src/modules/staff.c @@ -29,12 +29,29 @@ ModuleHeader MOD_HEADER "unrealircd-6", }; +#if 1 + +MOD_INIT() +{ + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + return MOD_SUCCESS; +} +#else #define MSG_STAFF "STAFF" #define DEF_STAFF_FILE CONFDIR "/network.staff" #define CONF_STAFF_FILE (staff_file ? staff_file : DEF_STAFF_FILE) #ifdef USE_LIBCURL -#define STAFF_FILE (Download.path ? Download.path : CONF_STAFF_FILE) +#define STAFF_FILE (ConfigResource.path ? ConfigResource.path : CONF_STAFF_FILE) #else #define STAFF_FILE CONF_STAFF_FILE #endif @@ -70,7 +87,7 @@ struct { char *file; // File name char *path; // File path char *url; // Full URL address -} Download; +} ConfigResource; #endif MOD_TEST() @@ -83,7 +100,7 @@ MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); #ifdef USE_LIBCURL - memset(&Download, 0, sizeof(Download)); + memset(&ConfigResource, 0, sizeof(ConfigResource)); ModuleSetOptions(modinfo->handle, MOD_OPT_PERM, 1); #endif memset(&staff, 0, sizeof(staff)); @@ -109,9 +126,9 @@ MOD_UNLOAD() unload_motd_file(&staff); #ifdef USE_LIBCURL - safe_free(Download.path); - safe_free(Download.file); - safe_free(Download.url); + safe_free(ConfigResource.path); + safe_free(ConfigResource.file); + safe_free(ConfigResource.url); #endif return MOD_SUCCESS; @@ -138,16 +155,16 @@ static void FreeConf() #ifdef USE_LIBCURL static void remove_staff_file() { - if (Download.path) + if (ConfigResource.path) { - if (remove(Download.path) == -1) + if (remove(ConfigResource.path) == -1) { if (config_verbose > 0) config_status("Cannot remove file %s: %s", - Download.path, strerror(errno)); + ConfigResource.path, strerror(errno)); } - safe_free(Download.path); - Download.path = NULL; + safe_free(ConfigResource.path); + ConfigResource.path = NULL; } } @@ -157,24 +174,24 @@ static int download_staff_file(ConfigEntry *ce) struct stat sb; char *file, *filename; - if (Download.in_progress) + if (ConfigResource.in_progress) return 0; - Download.is_url = 1; - safe_strdup(Download.url, ce->value); + ConfigResource.is_url = 1; + safe_strdup(ConfigResource.url, ce->value); file = url_getfilename(ce->value); filename = unreal_getfilename(file); /* TODO: handle NULL returns */ - safe_strdup(Download.file, filename); + safe_strdup(ConfigResource.file, filename); safe_free(file); - if (!loop.rehashing && !Download.once_completed) + if (!loop.rehashing && !ConfigResource.once_completed) { char *error; if (config_verbose > 0) - config_status("Downloading %s", displayurl(Download.url)); + config_status("ConfigResourceing %s", displayurl(ConfigResource.url)); if (!(file = download_file(ce->value, &error))) { @@ -184,37 +201,37 @@ static int download_staff_file(ConfigEntry *ce) return -1; } - Download.once_completed = 1; - safe_strdup(Download.path, file); - read_motd(Download.path, &staff); + ConfigResource.once_completed = 1; + safe_strdup(ConfigResource.path, file); + read_motd(ConfigResource.path, &staff); safe_free(file); return 0; } - file = Download.path ? Download.path : Download.file; + file = ConfigResource.path ? ConfigResource.path : ConfigResource.file; if ((ret = stat(file, &sb)) && errno != ENOENT) { /* I know, stat shouldn't fail... */ config_error("%s:%i: could not get the creation time of %s: stat() returned %d: %s", ce->file->filename, ce->line_number, - Download.file, ret, strerror(errno)); + ConfigResource.file, ret, strerror(errno)); return -1; } if (config_verbose > 0) - config_status("Downloading %s", displayurl(Download.url)); + config_status("ConfigResourceing %s", displayurl(ConfigResource.url)); - Download.in_progress = 1; - download_file_async(Download.url, sb.st_ctime, download_staff_file_complete, NULL); + ConfigResource.in_progress = 1; + download_file_async(ConfigResource.url, sb.st_ctime, download_staff_file_complete, NULL); return 0; } static void download_staff_file_complete(char *url, char *file, char *errorbuf, int cached, void *dummy) { - Download.in_progress = 0; - Download.once_completed = 1; + ConfigResource.in_progress = 0; + ConfigResource.once_completed = 1; if (!cached) { @@ -226,17 +243,17 @@ static void download_staff_file_complete(char *url, char *file, char *errorbuf, } remove_staff_file(); - safe_strdup(Download.path, file); - read_motd(Download.path, &staff); + safe_strdup(ConfigResource.path, file); + read_motd(ConfigResource.path, &staff); } else { char *urlfile = url_getfilename(url); char *file = unreal_getfilename(urlfile); char *tmp = unreal_mktemp("tmp", file); /* TODO: handle null returns ? */ - unreal_copyfile(Download.path, tmp); + unreal_copyfile(ConfigResource.path, tmp); remove_staff_file(); - safe_strdup(Download.path, tmp); + safe_strdup(ConfigResource.path, tmp); safe_free(urlfile); } } @@ -303,7 +320,7 @@ static int cb_conf(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(ce->name, "staff-file")) { #ifdef USE_LIBCURL - if (!Download.in_progress) + if (!ConfigResource.in_progress) { safe_strdup(staff_file, ce->value); if (url_is_valid(ce->value)) @@ -350,8 +367,8 @@ static int cb_rehashflag(Client *client, char *flag) MyUser(client) ? "Remotely " : "", client->name); #ifdef USE_LIBCURL - if (Download.is_url) - read_motd(Download.path, &staff); + if (ConfigResource.is_url) + read_motd(ConfigResource.path, &staff); else #endif read_motd(CONF_STAFF_FILE, &staff); @@ -387,3 +404,4 @@ CMD_FUNC(cmd_staff) sendto_one(client, NULL, RPL_ENDOFSTAFF, me.name, client->name); } +#endif diff --git a/src/serv.c b/src/serv.c index 9af8d4a89..b3b2de35b 100644 --- a/src/serv.c +++ b/src/serv.c @@ -54,7 +54,7 @@ int MODVAR spamf_ugly_vchanoverride = 0; void read_motd(const char *filename, MOTDFile *motd); void do_read_motd(const char *filename, MOTDFile *themotd); #ifdef USE_LIBCURL -void read_motd_async_downloaded(const char *url, const char *filename, const char *errorbuf, int cached, MOTDDownload *motd_download); +void read_motd_async_downloaded(const char *url, const char *filename, const char *errorbuf, int cached, MOTDConfigResource *motd_download); #endif extern MOTDLine *find_file(char *, short); @@ -776,7 +776,7 @@ void read_motd(const char *filename, MOTDFile *themotd) { #ifdef USE_LIBCURL time_t modtime; - MOTDDownload *motd_download; + MOTDConfigResource *motd_download; #endif /* TODO: if themotd points to a tld's motd, @@ -797,7 +797,7 @@ void read_motd(const char *filename, MOTDFile *themotd) if (filename && url_is_valid(filename)) { /* prepare our payload for read_motd_async_downloaded() */ - motd_download = safe_alloc(sizeof(MOTDDownload)); + motd_download = safe_alloc(sizeof(MOTDConfigResource)); motd_download->themotd = themotd; themotd->motd_download = motd_download; @@ -820,14 +820,14 @@ void read_motd(const char *filename, MOTDFile *themotd) * @param errorbuf NULL or an errorstring if there was an error while downloading the MOTD. * @param cached 0 if the URL was downloaded freshly or 1 if the last download was canceled and the local copy should be used. */ -void read_motd_async_downloaded(const char *url, const char *filename, const char *errorbuf, int cached, MOTDDownload *motd_download) +void read_motd_async_downloaded(const char *url, const char *filename, const char *errorbuf, int cached, MOTDConfigResource *motd_download) { MOTDFile *themotd; themotd = motd_download->themotd; /* check if the download was soft-canceled. See struct.h's docs on - struct MOTDDownload for details. + struct MOTDConfigResource for details. */ if (!themotd) { diff --git a/src/url.c b/src/url.c index b1756a554..1242ec435 100644 --- a/src/url.c +++ b/src/url.c @@ -49,6 +49,9 @@ typedef struct */ int url_is_valid(const char *string) { + if (strstr(string, " ") || strstr(string, "\t")) + return 0; + if (strstr(string, "telnet://") == string || strstr(string, "ldap://") == string || strstr(string, "dict://") == string) diff --git a/src/windows/gui.c b/src/windows/gui.c index 0bcaf78b1..4a956aa3f 100644 --- a/src/windows/gui.c +++ b/src/windows/gui.c @@ -367,15 +367,15 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } } AppendMenu(hConfig, MF_SEPARATOR, 0, NULL); - if (conf_include) + if (config_resources) { - ConfigItem_include *inc; - for (inc = conf_include; inc; inc = inc->next) + ConfigResource *inc; + for (inc = config_resources; inc; inc = inc->next) { if (inc->flag.type & INCLUDE_NOTLOADED) continue; #ifdef USE_LIBCURL - if (inc->flag.type & INCLUDE_REMOTE) + if (inc->flag.type & RESOURCE_REMOTE) AppendMenu(hConfig, MF_STRING, i++, inc->url); else #endif @@ -476,13 +476,13 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } AppendMenu(hConfig, MF_SEPARATOR, 0, NULL); - if (conf_include) + if (config_resources) { - ConfigItem_include *inc; - for (inc = conf_include; inc; inc = inc->next) + ConfigResource *inc; + for (inc = config_resources; inc; inc = inc->next) { #ifdef USE_LIBCURL - if (inc->flag.type & INCLUDE_REMOTE) + if (inc->flag.type & RESOURCE_REMOTE) AppendMenu(hConfig, MF_STRING, i++, inc->url); else #endif