modules: tag origin at load time.

This commit is contained in:
Elizabeth Myers 2016-03-06 18:56:45 -06:00
parent 7ee96784c2
commit 216d70e91d
7 changed files with 765 additions and 836 deletions

View file

@ -62,7 +62,7 @@ mapi_cap_list_av2 remove_cap_list[] = {
const char description[] = "Provides the REMOVE command, an alternative to KICK"; const char description[] = "Provides the REMOVE command, an alternative to KICK";
DECLARE_MODULE_AV2(remove, MAPI_ORIGIN_EXTENSION, NULL, NULL, remove_clist, NULL, remove_hfnlist, remove_cap_list, NULL, description); DECLARE_MODULE_AV2(remove, NULL, NULL, remove_clist, NULL, remove_hfnlist, remove_cap_list, NULL, description);
static int static int
m_remove(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) m_remove(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])

View file

@ -93,14 +93,12 @@ struct mapi_mheader_av1
}; };
#define MAPI_ORIGIN_UNKNOWN 0 /* Unknown provenance (AV1 etc.) */ #define MAPI_ORIGIN_UNKNOWN 0 /* Unknown provenance (AV1 etc.) */
#define MAPI_ORIGIN_EXTERNAL 1 /* Came from outside charybdis */ #define MAPI_ORIGIN_EXTENSION 1 /* Charybdis extension */
#define MAPI_ORIGIN_EXTENSION 2 /* Charybdis bundled extension */ #define MAPI_ORIGIN_CORE 2 /* Charybdis core module */
#define MAPI_ORIGIN_CORE 3 /* Charybdis core module */
struct mapi_mheader_av2 struct mapi_mheader_av2
{ {
int mapi_version; /* Module API version */ int mapi_version; /* Module API version */
int mapi_origin; /* Module provenance */
int (*mapi_register)(void); /* Register function; ret -1 = failure (unload) */ int (*mapi_register)(void); /* Register function; ret -1 = failure (unload) */
void (*mapi_unregister)(void); /* Unregister function. */ void (*mapi_unregister)(void); /* Unregister function. */
mapi_clist_av1 *mapi_command_list; /* List of commands to add. */ mapi_clist_av1 *mapi_command_list; /* List of commands to add. */
@ -114,8 +112,8 @@ struct mapi_mheader_av2
#define DECLARE_MODULE_AV1(name, reg, unreg, cl, hl, hfnlist, v) \ #define DECLARE_MODULE_AV1(name, reg, unreg, cl, hl, hfnlist, v) \
struct mapi_mheader_av1 _mheader = { MAPI_V1, reg, unreg, cl, hl, hfnlist, v} struct mapi_mheader_av1 _mheader = { MAPI_V1, reg, unreg, cl, hl, hfnlist, v}
#define DECLARE_MODULE_AV2(name, origin, reg, unreg, cl, hl, hfnlist, caplist, v, desc) \ #define DECLARE_MODULE_AV2(name, reg, unreg, cl, hl, hfnlist, caplist, v, desc) \
struct mapi_mheader_av2 _mheader = { MAPI_V2, origin, reg, unreg, cl, hl, hfnlist, caplist, v, desc} struct mapi_mheader_av2 _mheader = { MAPI_V2, reg, unreg, cl, hl, hfnlist, caplist, v, desc}
/* add a path */ /* add a path */
void mod_add_path(const char *path); void mod_add_path(const char *path);
@ -131,8 +129,8 @@ extern void load_all_modules(int warn);
extern void load_core_modules(int); extern void load_core_modules(int);
extern int unload_one_module(const char *, int); extern int unload_one_module(const char *, int);
extern int load_one_module(const char *, int); extern int load_one_module(const char *, int, int);
extern int load_a_module(const char *, int, int); extern int load_a_module(const char *, int, int, int);
extern int findmodule_byname(const char *); extern int findmodule_byname(const char *);
extern void modules_init(void); extern void modules_init(void);

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,13 @@
/* A Bison parser, made by GNU Bison 2.3. */ /* A Bison parser, made by GNU Bison 3.0.4. */
/* Skeleton interface for Bison's Yacc-like parsers in C /* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation, either version 3 of the License, or
any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -16,9 +15,7 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program. If not, see <http://www.gnu.org/licenses/>. */
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, you may create a larger work that contains /* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work part or all of the Bison parser skeleton and distribute that work
@ -33,18 +30,27 @@
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
/* Tokens. */ #ifndef YY_YY_IRCD_PARSER_H_INCLUDED
# define YY_YY_IRCD_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers enum yytokentype
know about them. */ {
enum yytokentype { LOADMODULE = 258,
LOADMODULE = 258, TWODOTS = 259,
TWODOTS = 259, QSTRING = 260,
QSTRING = 260, STRING = 261,
STRING = 261, NUMBER = 262
NUMBER = 262 };
};
#endif #endif
/* Tokens. */ /* Tokens. */
#define LOADMODULE 258 #define LOADMODULE 258
@ -53,24 +59,28 @@
#define STRING 261 #define STRING 261
#define NUMBER 262 #define NUMBER 262
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 165 "ircd_parser.y" union YYSTYPE
{ {
#line 164 "ircd_parser.y" /* yacc.c:1909 */
int number; int number;
char string[IRCD_BUFSIZE + 1]; char string[IRCD_BUFSIZE + 1];
conf_parm_t * conf_parm; conf_parm_t * conf_parm;
}
/* Line 1529 of yacc.c. */ #line 74 "ircd_parser.h" /* yacc.c:1909 */
#line 69 "ircd_parser.h" };
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif #endif
extern YYSTYPE yylval; extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_IRCD_PARSER_H_INCLUDED */

View file

@ -291,14 +291,15 @@ oneitem: qstring
loadmodule: loadmodule:
LOADMODULE QSTRING LOADMODULE QSTRING
{ {
char *m_bn; char *m_bn;
m_bn = rb_basename((char *) $2);
m_bn = rb_basename((char *) $2); if (findmodule_byname(m_bn) == -1)
{
load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
}
if (findmodule_byname(m_bn) == -1) rb_free(m_bn);
load_one_module($2, 0);
rb_free(m_bn);
} }
';' ';'
; ;

View file

@ -243,7 +243,7 @@ load_all_modules(int warn)
if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la")) if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la"))
{ {
(void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name); (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
(void) load_a_module(module_fq_name, warn, 0); (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0);
} }
} }
@ -268,7 +268,7 @@ load_core_modules(int warn)
snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH, snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
core_module_table[i], ".la"); core_module_table[i], ".la");
if(load_a_module(module_name, warn, 1) == -1) if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1)
{ {
ilog(L_MAIN, ilog(L_MAIN,
"Error loading core module %s%s: terminating ircd", "Error loading core module %s%s: terminating ircd",
@ -285,7 +285,7 @@ load_core_modules(int warn)
* side effects - * side effects -
*/ */
int int
load_one_module(const char *path, int coremodule) load_one_module(const char *path, int origin, int coremodule)
{ {
char modpath[PATH_MAX]; char modpath[PATH_MAX];
rb_dlink_node *pathst; rb_dlink_node *pathst;
@ -296,6 +296,12 @@ load_one_module(const char *path, int coremodule)
if (server_state_foreground == 1) if (server_state_foreground == 1)
inotice("loading module %s ...", path); inotice("loading module %s ...", path);
if(coremodule != 0)
{
coremodule = 1;
origin = MAPI_ORIGIN_CORE;
}
RB_DLINK_FOREACH(pathst, mod_paths.head) RB_DLINK_FOREACH(pathst, mod_paths.head)
{ {
mpath = pathst->data; mpath = pathst->data;
@ -308,10 +314,7 @@ load_one_module(const char *path, int coremodule)
if(S_ISREG(statbuf.st_mode)) if(S_ISREG(statbuf.st_mode))
{ {
/* Regular files only please */ /* Regular files only please */
if(coremodule) return load_a_module(modpath, 1, origin, coremodule);
return load_a_module(modpath, 1, 1);
else
return load_a_module(modpath, 1, 0);
} }
} }
@ -362,6 +365,7 @@ static int
do_modload(struct Client *source_p, const char *module) do_modload(struct Client *source_p, const char *module)
{ {
char *m_bn = rb_basename(module); char *m_bn = rb_basename(module);
int origin;
if(findmodule_byname(m_bn) != -1) if(findmodule_byname(m_bn) != -1)
{ {
@ -370,7 +374,8 @@ do_modload(struct Client *source_p, const char *module)
return 0; return 0;
} }
load_one_module(module, 0); origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION;
load_one_module(module, origin, 0);
rb_free(m_bn); rb_free(m_bn);
@ -500,7 +505,7 @@ do_modreload(struct Client *source_p, const char *module)
return 0; return 0;
} }
if((load_one_module(m_bn, check_core) == -1) && check_core) if((load_one_module(m_bn, modlist[modindex]->origin, check_core) == -1) && check_core)
{ {
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Error reloading core module: %s: terminating ircd", m_bn); "Error reloading core module: %s: terminating ircd", m_bn);
@ -781,17 +786,16 @@ unload_one_module(const char *name, int warn)
/* /*
* load_a_module() * load_a_module()
* *
* inputs - path name of module, int to notice, int of core * inputs - path name of module, int to notice, int of origin, int of core
* output - -1 if error 0 if success * output - -1 if error 0 if success
* side effects - loads a module if successful * side effects - loads a module if successful
*/ */
int int
load_a_module(const char *path, int warn, int core) load_a_module(const char *path, int warn, int origin, int core)
{ {
lt_dlhandle tmpptr; lt_dlhandle tmpptr;
char *mod_basename; char *mod_basename;
const char *ver, *description = NULL; const char *ver, *description = NULL;
int origin = 0;
int *mapi_version; int *mapi_version;
@ -911,7 +915,6 @@ load_a_module(const char *path, int warn, int core)
/* New in MAPI v2 - version replacement */ /* New in MAPI v2 - version replacement */
ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version; ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version;
description = mheader->mapi_module_description; description = mheader->mapi_module_description;
origin = mheader->mapi_origin;
if(mheader->mapi_cap_list) if(mheader->mapi_cap_list)
{ {
@ -983,9 +986,6 @@ load_a_module(const char *path, int warn, int core)
switch(origin) switch(origin)
{ {
case MAPI_ORIGIN_EXTERNAL:
o = "external";
break;
case MAPI_ORIGIN_EXTENSION: case MAPI_ORIGIN_EXTENSION:
o = "extension"; o = "extension";
break; break;

View file

@ -290,7 +290,7 @@ conf_set_modules_module(void *data)
m_bn = rb_basename((char *) data); m_bn = rb_basename((char *) data);
if(findmodule_byname(m_bn) == -1) if(findmodule_byname(m_bn) == -1)
load_one_module((char *) data, 0); load_one_module((char *) data, MAPI_ORIGIN_EXTENSION, 0);
rb_free(m_bn); rb_free(m_bn);
} }