From 3b99450757a9e8747ab72e756c99762c01b2b30d Mon Sep 17 00:00:00 2001 From: Valerie Pond <79415174+ValwareIRC@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:11:58 +0100 Subject: [PATCH 1/5] Add `draft/FILEHOST` This module implements a configurable local filehost URI. https://github.com/progval/ircv3-specifications/blob/filehost/extensions/filehost.md --- files/filehost.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 files/filehost.c diff --git a/files/filehost.c b/files/filehost.c new file mode 100644 index 0000000..32c1a49 --- /dev/null +++ b/files/filehost.c @@ -0,0 +1,173 @@ +/** === Module Information === + * + * NAME: draft/FILEHOST + * LICENCE: GPLv3 or later + * COPYRIGHT: Ⓒ 2023 Valerie Pond, 2022 Val Lorentz + * DOCS: https://github.com/progval/ircv3-specifications/blob/filehost/extensions/filehost.md + * +*/ +/*** <<>> +module +{ + documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/filehost/README.md"; + troubleshooting "In case of problems, documentation or e-mail me at v.a.pond@outlook.com"; + min-unrealircd-version "6.*"; + max-unrealircd-version "6.*"; + post-install-text { + "The module is installed. Now all you need to do is add a loadmodule line:"; + "loadmodule \"third/filehost\";"; + "And /REHASH the IRCd."; + "The module does not need any other configuration."; + } +} +*** <<>> +*/ +#include "unrealircd.h" + +#define CONF_FILEHOST "filehosts" + +/* FILEHOST config struct */ +struct +{ + char *isupport_line; + MultiLine *hosts; + unsigned short int has_hosts; +} cfg; + + + +int filehost_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); +int filehost_configrun(ConfigFile *cf, ConfigEntry *ce, int type); +void setconf(void); +void freeconf(void); + +ModuleHeader MOD_HEADER + = { + "third/filehost", + "1.0", + "draft/FILEHOST support", + "Valware", + "unrealircd-6", +}; + +MOD_TEST() +{ + setconf(); + HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, filehost_configtest); + return MOD_SUCCESS; +} + +MOD_INIT() +{ + HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, filehost_configrun); + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + ISupport *is; + if (!(is = ISupportAdd(modinfo->handle, "draft/FILEHOST", cfg.isupport_line))) + return MOD_FAILED; + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + freeconf(); + return MOD_SUCCESS; +} + +void setconf(void) +{ + memset(&cfg, 0, sizeof(cfg)); + cfg.has_hosts = 0; + safe_strdup(cfg.isupport_line,""); +} + +void freeconf(void) +{ + freemultiline(cfg.hosts); + cfg.has_hosts = 0; + safe_free(cfg.isupport_line); + memset(&cfg, 0, sizeof(cfg)); +} + + +int filehost_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) +{ + int errors = 0; + ConfigEntry *cep; + freeconf(); + setconf(); + if (type != CONFIG_MAIN) + return 0; + + if (!ce || !ce->name) + return 0; + + if (strcmp(ce->name, CONF_FILEHOST)) + return 0; + + for (cep = ce->items; cep; cep = cep->next) + { + if (!cep->name) + { + config_error("%s:%i: blank %s item", cep->file->filename, cep->line_number, CONF_FILEHOST); + ++errors; + continue; + } + if (!strcasecmp(cep->name, "host")) + { + if (!BadPtr(cep->value)) + cfg.has_hosts = 1; + + else + config_error("%s:%i: Empty host at %s::%s", cep->file->filename, cep->line_number, CONF_FILEHOST, cep->name); + + continue; + } + + // Anything else is unknown to us =] + config_warn("%s:%i: unknown item %s::%s", cep->file->filename, cep->line_number, CONF_FILEHOST, cep->name); // So display just a warning + } + + *errs = errors; + return errors ? -1 : 1; +} + +int filehost_configrun(ConfigFile *cf, ConfigEntry *ce, int type) +{ + ConfigEntry *cep; + char buf[BUFSIZE] = "\0"; + + if (type != CONFIG_MAIN) + return 0; + + if (!ce || !ce->name) + return 0; + + if (strcmp(ce->name, "filehosts")) + return 0; + + for (cep = ce->items; cep; cep = cep->next) + { + if (!cep->name) + continue; + + if (!strcmp(cep->name, "host")) + addmultiline(&cfg.hosts, cep->value); + + } + + for (MultiLine *m = cfg.hosts; m; m = m->next) + { + strlcat(buf,m->line, sizeof(buf)); + if (m->next) + strlcat(buf,"\\x20",sizeof(buf)); + } + if (strlen(buf)) + safe_strdup(cfg.isupport_line, buf); + + + return 1; // We good +} From db38642d7ccfdf78bd9ea4a30f6e3a00d365ee65 Mon Sep 17 00:00:00 2001 From: Valerie Liu <79415174+ValwareIRC@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:28:37 +0100 Subject: [PATCH 2/5] Provide a better module description --- files/filehost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/filehost.c b/files/filehost.c index 32c1a49..59f90ce 100644 --- a/files/filehost.c +++ b/files/filehost.c @@ -45,7 +45,7 @@ ModuleHeader MOD_HEADER = { "third/filehost", "1.0", - "draft/FILEHOST support", + "IRCv3 draft/FILEHOST - Provides users with an ISUPPORT token about your file upload service", "Valware", "unrealircd-6", }; From e337238c4763501c97af70c970616a680bc1c737 Mon Sep 17 00:00:00 2001 From: Valerie Liu <79415174+ValwareIRC@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:32:56 +0100 Subject: [PATCH 3/5] Be clear about the URL --- files/filehost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/filehost.c b/files/filehost.c index 59f90ce..545e055 100644 --- a/files/filehost.c +++ b/files/filehost.c @@ -45,7 +45,7 @@ ModuleHeader MOD_HEADER = { "third/filehost", "1.0", - "IRCv3 draft/FILEHOST - Provides users with an ISUPPORT token about your file upload service", + "IRCv3 draft/FILEHOST - Provides users with an ISUPPORT token with a URL to your file upload service", "Valware", "unrealircd-6", }; From 3a7350942df54ccce14facc1efde2e3189331cc2 Mon Sep 17 00:00:00 2001 From: Valerie Liu <79415174+ValwareIRC@users.noreply.github.com> Date: Fri, 3 Jan 2025 04:14:05 +0000 Subject: [PATCH 4/5] Changes requested --- files/filehost.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/files/filehost.c b/files/filehost.c index 545e055..79dc696 100644 --- a/files/filehost.c +++ b/files/filehost.c @@ -59,6 +59,7 @@ MOD_TEST() MOD_INIT() { + setconf() HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, filehost_configrun); return MOD_SUCCESS; } @@ -66,7 +67,7 @@ MOD_INIT() MOD_LOAD() { ISupport *is; - if (!(is = ISupportAdd(modinfo->handle, "draft/FILEHOST", cfg.isupport_line))) + if (!(is = ISupportAdd(modinfo->handle, "draft/FILEHOST", cfg.isupport_line))) return MOD_FAILED; return MOD_SUCCESS; } @@ -97,15 +98,14 @@ int filehost_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { int errors = 0; ConfigEntry *cep; - freeconf(); - setconf(); + if (type != CONFIG_MAIN) return 0; if (!ce || !ce->name) - return 0; + return 0; - if (strcmp(ce->name, CONF_FILEHOST)) + if (strcmp(ce->name, CONF_FILEHOST)) return 0; for (cep = ce->items; cep; cep = cep->next) @@ -158,7 +158,7 @@ int filehost_configrun(ConfigFile *cf, ConfigEntry *ce, int type) addmultiline(&cfg.hosts, cep->value); } - + for (MultiLine *m = cfg.hosts; m; m = m->next) { strlcat(buf,m->line, sizeof(buf)); From 70037a37c0b1d98206c4e9f408eb5abb8892ba14 Mon Sep 17 00:00:00 2001 From: Valerie Liu <79415174+ValwareIRC@users.noreply.github.com> Date: Fri, 3 Jan 2025 04:14:32 +0000 Subject: [PATCH 5/5] Update the year lmao --- files/filehost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/filehost.c b/files/filehost.c index 79dc696..6eee28d 100644 --- a/files/filehost.c +++ b/files/filehost.c @@ -2,7 +2,7 @@ * * NAME: draft/FILEHOST * LICENCE: GPLv3 or later - * COPYRIGHT: Ⓒ 2023 Valerie Pond, 2022 Val Lorentz + * COPYRIGHT: Ⓒ 20253 Valerie Pond, 2022 Val Lorentz * DOCS: https://github.com/progval/ircv3-specifications/blob/filehost/extensions/filehost.md * */