From b99e37d54f6e9dd53ebe50ed2781ef041c423343 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:41:45 +0100 Subject: [PATCH] Remove dependence of compress module on share module --- doc/MODULES | 8 ++++---- doc/modules/MODULES | 4 ++-- doc/sphinx_source/modules/included.rst | 6 +++--- doc/sphinx_source/modules/mod/compress.rst | 10 ++++------ eggdrop.conf | 8 ++++---- src/mod/compress.mod/compress.c | 23 ++++++++++++++-------- src/mod/compress.mod/compress.h | 11 ++++++----- src/mod/compress.mod/help/compress.help | 4 ++-- src/mod/compress.mod/modinfo | 8 ++++---- src/mod/share.mod/share.c | 14 +++++++++++-- 10 files changed, 56 insertions(+), 40 deletions(-) diff --git a/doc/MODULES b/doc/MODULES index 9e6aeba41..ef8f2c019 100644 --- a/doc/MODULES +++ b/doc/MODULES @@ -1,4 +1,4 @@ -Eggdrop Module Information Last revised: Jul 25, 2016 +Eggdrop Module Information Last revised: Nov 10, 2022 Eggdrop Module Information @@ -60,9 +60,9 @@ MODULES INCLUDED WITH EGGDROP compress - This module provides support for file compression. This allows the - bot to transfer compressed user files and, therefore, save a - significant amount of bandwidth. + This module provides support for file compression. With share module + loaded this allows the bot to transfer compressed user files and, + therefore, save a significant amount of bandwidth. console diff --git a/doc/modules/MODULES b/doc/modules/MODULES index 05b2a8fef..48e47a498 100644 --- a/doc/modules/MODULES +++ b/doc/modules/MODULES @@ -25,8 +25,8 @@ channels compress - This module provides support for file compression. This allows the - bot to transfer compressed user files and, therefore, save a + This module provides support for file compression. With share module loaded + this allows the bot to transfer compressed user files and, therefore, save a significant amount of bandwidth. console diff --git a/doc/sphinx_source/modules/included.rst b/doc/sphinx_source/modules/included.rst index 95f459942..625ad896e 100644 --- a/doc/sphinx_source/modules/included.rst +++ b/doc/sphinx_source/modules/included.rst @@ -40,9 +40,9 @@ Modules included with Eggdrop or save channel specific userfile information. :ref:`compress` - This module provides support for file compression. This - allows the bot to transfer compressed user files and, therefore, - save a significant amount of bandwidth. + This module provides support for file compression. With share module loaded + this allows the bot to transfer compressed user files and, therefore, save a + significant amount of bandwidth. :ref:`console` This module provides storage of console settings when you exit diff --git a/doc/sphinx_source/modules/mod/compress.rst b/doc/sphinx_source/modules/mod/compress.rst index ceb76c871..dc60d3d12 100644 --- a/doc/sphinx_source/modules/mod/compress.rst +++ b/doc/sphinx_source/modules/mod/compress.rst @@ -1,4 +1,4 @@ -Last revised: May 27, 2004 +Last revised: Nov 10, 2022 .. _compress: @@ -6,11 +6,9 @@ Last revised: May 27, 2004 Compress Module =============== -This module provides support for file compression. It can be used -to compress files via Tcl or to transfer the userfile compressed during the -share process, saving bandwidth. - -This module requires: share +This module provides support for file compression. It can be used to compress +files via Tcl or, with share module loaded, to transfer the userfile compressed +during the share process, saving bandwidth. Put this line into your Eggdrop configuration file to load the compress module:: diff --git a/eggdrop.conf b/eggdrop.conf index 81e35bfe9..8b57163ae 100755 --- a/eggdrop.conf +++ b/eggdrop.conf @@ -1510,10 +1510,10 @@ set xfer-timeout 30 #### COMPRESS MODULE #### -# This module provides support for file compression. This allows the -# bot to transfer compressed user files and therefore save a significant amount -# of bandwidth. The share module must be loaded to load this module. Un-comment -# the following line to the compress module. +# This module provides support for file compression. With share module loaded +# this allows the bot to transfer compressed user files and therefore save a +# significant amount of bandwidth. Un-comment the following line to the compress +# module. #loadmodule compress # Allow compressed sending of user files? The user files are compressed with diff --git a/src/mod/compress.mod/compress.c b/src/mod/compress.mod/compress.c index d4cd73154..ec615d857 100644 --- a/src/mod/compress.mod/compress.c +++ b/src/mod/compress.mod/compress.c @@ -412,7 +412,9 @@ static char *compress_close() rem_help_reference("compress.help"); rem_tcl_commands(my_tcl_cmds); rem_tcl_ints(my_tcl_ints); - uff_deltable(compress_uff_table); + + if (module_find("share", 2, 5)) + uff_deltable(compress_uff_table); module_undepend(MODULE_NAME); return NULL; @@ -420,6 +422,15 @@ static char *compress_close() EXPORT_SCOPE char *compress_start(); +static void compress_start_share() { + module_entry *me = module_find("share", 2, 5); + if (me) { + share_funcs = me->funcs; + uff_addtable(compress_uff_table); + } + debug0("added compression mod funcs to share mod"); +} + static Function compress_table[] = { /* 0 - 3 */ (Function) compress_start, @@ -433,6 +444,7 @@ static Function compress_table[] = { (Function) uncompress_file, /* 8 - 11 */ (Function) is_compressedfile, + (Function) compress_start_share, }; char *compress_start(Function *global_funcs) @@ -444,19 +456,14 @@ char *compress_start(Function *global_funcs) share_compressed = 0; compress_level = 9; - module_register(MODULE_NAME, compress_table, 1, 2); + module_register(MODULE_NAME, compress_table, 1, 3); if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) { module_undepend(MODULE_NAME); return "This module requires Eggdrop 1.8.0 or later."; } - share_funcs = module_depend(MODULE_NAME, "share", 2, 3); - if (!share_funcs) { - module_undepend(MODULE_NAME); - return "This module requires share module 2.3 or later."; - } + compress_start_share(); - uff_addtable(compress_uff_table); add_tcl_ints(my_tcl_ints); add_tcl_commands(my_tcl_cmds); add_help_reference("compress.help"); diff --git a/src/mod/compress.mod/compress.h b/src/mod/compress.mod/compress.h index 05467bc5b..da1c556a0 100644 --- a/src/mod/compress.mod/compress.h +++ b/src/mod/compress.mod/compress.h @@ -39,12 +39,13 @@ typedef enum { #ifndef MAKING_COMPRESS /* 4 - 7 */ -# define compress_to_file ((int (*)(char *, char *, int))(compress_funcs[4])) -# define compress_file ((int (*)(char *, int))(compress_funcs[5])) -# define uncompress_to_file ((int (*)(char *, char *))(uncompress_funcs[6])) -# define uncompress_file ((int (*)(char *))(uncompress_funcs[7])) +# define compress_to_file ((int (*)(char *, char *, int))(compress_funcs[4])) +# define compress_file ((int (*)(char *, int))(compress_funcs[5])) +# define uncompress_to_file ((int (*)(char *, char *))(uncompress_funcs[6])) +# define uncompress_file ((int (*)(char *))(uncompress_funcs[7])) /* 8 - 11 */ -# define is_compressedfile ((int (*)(char *))(uncompress_funcs[8])) +# define is_compressedfile ((int (*)(char *))(uncompress_funcs[8])) +# define compress_start_share ((void (*)(void))(compress_funcs[9])) #endif /* !MAKING_COMPRESS */ #endif /* !_EGG_MOD_COMPRESS_COMPRESS_H */ diff --git a/src/mod/compress.mod/help/compress.help b/src/mod/compress.mod/help/compress.help index 87683c56c..733ad4464 100644 --- a/src/mod/compress.mod/help/compress.help +++ b/src/mod/compress.mod/help/compress.help @@ -1,8 +1,8 @@ %{help=compress module}%{+n} ### %bcompress module%b This module provides support for file compression. It can be used - to compress files via Tcl or to transfer the userfile compressed during the - share process, saving bandwidth. + to compress files via Tcl or, with share module loaded, to transfer the + userfile compressed during the share process, saving bandwidth. Config file variables for configuring the compress module: %bcompress-level share-compressed%b diff --git a/src/mod/compress.mod/modinfo b/src/mod/compress.mod/modinfo index 454de6694..52c521795 100644 --- a/src/mod/compress.mod/modinfo +++ b/src/mod/compress.mod/modinfo @@ -1,7 +1,7 @@ -DESC:The compress module provides support for file compression. This -DESC:allows the bot to transfer compressed user files and therefore -DESC:saves a significant amount of bandwidth, especially on very active -DESC:hubs. The module depends on the zlib library. +DESC:The compress module provides support for file compression. With share +DESC:module loaded this allows the bot to transfer compressed user files and +DESC:therefore saves a significant amount of bandwidth, especially on very +DESC:active hubs. The module depends on the zlib library. DESC: DESC:You will want to ENABLE this module if you have enough CPU time DESC:to spare. diff --git a/src/mod/share.mod/share.c b/src/mod/share.mod/share.c index 57d4c3292..01ecf3385 100644 --- a/src/mod/share.mod/share.c +++ b/src/mod/share.mod/share.c @@ -34,6 +34,7 @@ #include "src/users.h" #include "transfer.mod/transfer.h" #include "channels.mod/channels.h" +#include "compress.mod/compress.h" /* Minimum version I will share with. */ static const int min_share = 1029900; @@ -44,7 +45,8 @@ static const int min_exemptinvite = 1032800; /* Minimum version that supports userfile features. */ static const int min_uffeature = 1050200; -static Function *global = NULL, *transfer_funcs = NULL, *channels_funcs = NULL; +static Function *global = NULL, *transfer_funcs = NULL, *channels_funcs = NULL, + *compress_funcs = NULL; static int private_global = 0; static int private_user = 0; @@ -2349,10 +2351,11 @@ static Function share_table[] = { char *share_start(Function *global_funcs) { + module_entry *me; global = global_funcs; - module_register(MODULE_NAME, share_table, 2, 4); + module_register(MODULE_NAME, share_table, 2, 5); if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) { module_undepend(MODULE_NAME); return "This module requires Eggdrop 1.8.0 or later."; @@ -2378,6 +2381,13 @@ char *share_start(Function *global_funcs) add_builtins(H_dcc, my_cmds); uff_init(); uff_addtable(internal_uff_table); + + me = module_find("compress", 1, 3); + if (me) { + compress_funcs = me->funcs; + compress_start_share(); + } + return NULL; }