| 1 |
/* modules.h |
| 2 |
* |
| 3 |
* Definition for build-in and plug-ins module handler. This file is the base |
| 4 |
* for all dynamically loadable module support. In theory, in v3 all modules |
| 5 |
* are dynamically loaded, in practice we currently do have a few build-in |
| 6 |
* once. This may become removed. |
| 7 |
* |
| 8 |
* The loader keeps track of what is loaded. For library modules, it is also |
| 9 |
* used to find objects (libraries) and to obtain the queryInterface function |
| 10 |
* for them. A reference count is maintened for libraries, so that they are |
| 11 |
* unloaded only when nobody still accesses them. |
| 12 |
* |
| 13 |
* File begun on 2007-07-22 by RGerhards |
| 14 |
* |
| 15 |
* Copyright 2007-2026 Rainer Gerhards and Adiscon GmbH. |
| 16 |
* |
| 17 |
* This file is part of the rsyslog runtime library. |
| 18 |
* |
| 19 |
* The rsyslog runtime library is free software: you can redistribute it and/or modify |
| 20 |
* it under the terms of the GNU Lesser General Public License as published by |
| 21 |
* the Free Software Foundation, either version 3 of the License, or |
| 22 |
* (at your option) any later version. |
| 23 |
* |
| 24 |
* The rsyslog runtime library is distributed in the hope that it will be useful, |
| 25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
* GNU Lesser General Public License for more details. |
| 28 |
* |
| 29 |
* You should have received a copy of the GNU Lesser General Public License |
| 30 |
* along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. |
| 31 |
* |
| 32 |
* A copy of the GPL can be found in the file "COPYING" in this distribution. |
| 33 |
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. |
| 34 |
*/ |
| 35 |
#ifndef MODULES_H_INCLUDED |
| 36 |
#define MODULES_H_INCLUDED 1 |
| 37 |
|
| 38 |
#include "objomsr.h" |
| 39 |
#include "rainerscript.h" |
| 40 |
|
| 41 |
typedef struct action_s action_t; |
| 42 |
|
| 43 |
|
| 44 |
/* the following define defines the current version of the module interface. |
| 45 |
* It can be used by any module which want's to simply prevent version conflicts |
| 46 |
* and does not intend to do specific old-version emulations. |
| 47 |
* rgerhards, 2008-03-04 |
| 48 |
* version 3 adds modInfo_t ptr to call of modInit -- rgerhards, 2008-03-10 |
| 49 |
* version 4 removes needUDPSocket OM callback -- rgerhards, 2008-03-22 |
| 50 |
* version 5 changes the way parsing works for input modules. This is |
| 51 |
* an important change, parseAndSubmitMessage() goes away. Other |
| 52 |
* module types are not affected. -- rgerhards, 2008-10-09 |
| 53 |
* version 6 introduces scoping support (starting with the output |
| 54 |
* modules) -- rgerhards, 2010-07-27 |
| 55 |
*/ |
| 56 |
#define CURR_MOD_IF_VERSION 6 |
| 57 |
|
| 58 |
typedef enum eModType_ { |
| 59 |
eMOD_IN = 0, /* input module */ |
| 60 |
eMOD_OUT = 1, /* output module */ |
| 61 |
eMOD_LIB = 2, /* library module */ |
| 62 |
eMOD_PARSER = 3, /* parser module */ |
| 63 |
eMOD_STRGEN = 4, /* strgen module */ |
| 64 |
eMOD_FUNCTION = 5, /*rscript function module*/ |
| 65 |
eMOD_ANY = 6 /* meta-name for "any type of module" -- to be used in function calls */ |
| 66 |
} eModType_t; |
| 67 |
|
| 68 |
|
| 69 |
#ifdef DEBUG |
| 70 |
typedef struct modUsr_s { |
| 71 |
struct modUsr_s *pNext; |
| 72 |
char *pszFile; |
| 73 |
} modUsr_t; |
| 74 |
#endif |
| 75 |
|
| 76 |
|
| 77 |
/* how is this module linked? */ |
| 78 |
typedef enum eModLinkType_ { |
| 79 |
eMOD_LINK_STATIC, |
| 80 |
eMOD_LINK_DYNAMIC_UNLOADED, /* dynalink module, currently not loaded */ |
| 81 |
eMOD_LINK_DYNAMIC_LOADED, /* dynalink module, currently loaded */ |
| 82 |
eMOD_LINK_ALL /* special: all linkage types, e.g. for unload */ |
| 83 |
} eModLinkType_t; |
| 84 |
|
| 85 |
/* remember which shared libs we dlopen()-ed */ |
| 86 |
struct dlhandle_s { |
| 87 |
uchar *pszName; |
| 88 |
void *pModHdlr; |
| 89 |
struct dlhandle_s *next; |
| 90 |
}; |
| 91 |
|
| 92 |
/* should this module be kept linked? */ |
| 93 |
typedef enum eModKeepType_ { eMOD_NOKEEP, eMOD_KEEP } eModKeepType_t; |
| 94 |
|
| 95 |
struct modInfo_s { |
| 96 |
struct modInfo_s *pPrev; /* support for creating a double linked module list */ |
| 97 |
struct modInfo_s *pNext; /* support for creating a linked module list */ |
| 98 |
int iIFVers; /* Interface version of module */ |
| 99 |
eModType_t eType; /* type of this module */ |
| 100 |
eModLinkType_t eLinkType; |
| 101 |
eModKeepType_t eKeepType; /* keep the module dynamically linked on unload */ |
| 102 |
uchar *pszName; /* printable module name, e.g. for dbgprintf */ |
| 103 |
uchar *cnfName; /* name to be used in config statements (e.g. 'name="omusrmsg"') */ |
| 104 |
unsigned uRefCnt; /* reference count for this module; 0 -> may be unloaded */ |
| 105 |
sbool bSetModCnfCalled; /* is setModCnf already called? Needed for built-in modules */ |
| 106 |
/* functions supported by all types of modules */ |
| 107 |
rsRetVal (*modInit)(int, int *, rsRetVal (**)(void *)); /* initialize the module */ |
| 108 |
/* be sure to support version handshake! */ |
| 109 |
rsRetVal (*modQueryEtryPt)(uchar *name, rsRetVal (**EtryPoint)()); /* query entry point addresses */ |
| 110 |
rsRetVal (*isCompatibleWithFeature)(syslogFeature); |
| 111 |
rsRetVal (*freeInstance)(void *); /* called before termination or module unload */ |
| 112 |
rsRetVal (*dbgPrintInstInfo)(void *); /* called before termination or module unload */ |
| 113 |
rsRetVal (*tryResume)(void *); /* called to see if module actin can be resumed now */ |
| 114 |
rsRetVal (*modExit)(void); /* called before termination or module unload */ |
| 115 |
rsRetVal (*modGetID)(void **); /* get its unique ID from module */ |
| 116 |
rsRetVal (*doHUP)(void *); /* HUP handler, action level */ |
| 117 |
rsRetVal (*doHUPWrkr)(void *); /* HUP handler, wrkr instance level */ |
| 118 |
/* v2 config system specific */ |
| 119 |
rsRetVal (*beginCnfLoad)(void *newCnf, rsconf_t *pConf); |
| 120 |
rsRetVal (*setModCnf)(struct nvlst *lst); |
| 121 |
rsRetVal (*endCnfLoad)(void *Cnf); |
| 122 |
rsRetVal (*checkCnf)(void *Cnf); |
| 123 |
rsRetVal (*activateCnfPrePrivDrop)(void *Cnf); |
| 124 |
rsRetVal (*activateCnf)(void *Cnf); /* make provided config the running conf */ |
| 125 |
rsRetVal (*freeCnf)(void *Cnf); |
| 126 |
/* end v2 config system specific */ |
| 127 |
union { |
| 128 |
struct { /* data for input modules */ |
| 129 |
/* TODO: remove? */ rsRetVal (*willRun)(void); /* check if the current config will be able to run*/ |
| 130 |
rsRetVal (*runInput)(thrdInfo_t *); /* function to gather input and submit to queue */ |
| 131 |
rsRetVal (*afterRun)(thrdInfo_t *); /* function to gather input and submit to queue */ |
| 132 |
rsRetVal (*newInpInst)(struct nvlst *lst); |
| 133 |
int bCanRun; /* cached value of whether willRun() succeeded */ |
| 134 |
} im; |
| 135 |
struct { /* data for output modules */ |
| 136 |
/* below: perform the configured action |
| 137 |
*/ |
| 138 |
rsRetVal (*beginTransaction)(void *); |
| 139 |
rsRetVal (*commitTransaction)(void *const, actWrkrIParams_t *const, const unsigned); |
| 140 |
rsRetVal (*doAction)(void **params, void *pWrkrData); |
| 141 |
rsRetVal (*endTransaction)(void *); |
| 142 |
rsRetVal (*parseSelectorAct)(uchar **, void **, omodStringRequest_t **); |
| 143 |
rsRetVal (*newActInst)(uchar *modName, struct nvlst *lst, void **, omodStringRequest_t **); |
| 144 |
rsRetVal (*SetShutdownImmdtPtr)(void *pData, void *pPtr); |
| 145 |
rsRetVal (*createWrkrInstance)(void *ppWrkrData, void *pData); |
| 146 |
rsRetVal (*freeWrkrInstance)(void *pWrkrData); |
| 147 |
rsRetVal (*setActionInfo)(void *pData, action_t *pAction); |
| 148 |
sbool supportsTX; /* set if the module supports transactions */ |
| 149 |
} om; |
| 150 |
struct { /* data for library modules */ |
| 151 |
char dummy; |
| 152 |
} lm; |
| 153 |
struct { /* data for parser modules */ |
| 154 |
rsRetVal (*newParserInst)(struct nvlst *lst, void *pinst); |
| 155 |
rsRetVal (*checkParserInst)(void *pinst); |
| 156 |
rsRetVal (*freeParserInst)(void *pinst); |
| 157 |
rsRetVal (*parse2)(instanceConf_t *const, smsg_t *); |
| 158 |
rsRetVal (*parse)(smsg_t *); |
| 159 |
} pm; |
| 160 |
struct { /* data for strgen modules */ |
| 161 |
rsRetVal (*strgen)(const smsg_t *const, actWrkrIParams_t *const iparam); |
| 162 |
} sm; |
| 163 |
struct { /* data for rscript modules */ |
| 164 |
rsRetVal (*getFunctArray)(int *const, struct scriptFunct **); |
| 165 |
} fm; |
| 166 |
} mod; |
| 167 |
void *pModHdlr; /* handler to the dynamic library holding the module */ |
| 168 |
#ifdef DEBUG |
| 169 |
/* we add some home-grown support to track our users (and detect who does not free us). */ |
| 170 |
modUsr_t *pModUsrRoot; |
| 171 |
#endif |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
/* interfaces */ |
| 176 |
BEGINinterface(module) /* name must also be changed in ENDinterface macro! */ |
| 177 |
modInfo_t *(*GetNxt)(modInfo_t *pThis); |
| 178 |
cfgmodules_etry_t *(*GetNxtCnfType)(rsconf_t *cnf, cfgmodules_etry_t *pThis, eModType_t rqtdType); |
| 179 |
uchar *(*GetName)(modInfo_t *pThis); |
| 180 |
uchar *(*GetStateName)(modInfo_t *pThis); |
| 181 |
rsRetVal (*Use)(const char *srcFile, modInfo_t *pThis); |
| 182 |
/**< must be called before a module is used (ref counting) */ |
| 183 |
rsRetVal (*Release)(const char *srcFile, modInfo_t **ppThis); /**< release a module (ref counting) */ |
| 184 |
void (*PrintList)(void); |
| 185 |
rsRetVal (*UnloadAndDestructAll)(eModLinkType_t modLinkTypesToUnload); |
| 186 |
rsRetVal (*doModInit)(rsRetVal (*modInit)(), uchar *name, void *pModHdlr, modInfo_t **pNew); |
| 187 |
rsRetVal (*Load)(uchar *name, sbool bConfLoad, struct nvlst *lst); |
| 188 |
rsRetVal (*SetModDir)(uchar *name); |
| 189 |
modInfo_t *(*FindWithCnfName)(rsconf_t *cnf, uchar *name, eModType_t rqtdType); /* added v3, 2011-07-19 */ |
| 190 |
ENDinterface(module) |
| 191 |
#define moduleCURR_IF_VERSION 5 /* increment whenever you change the interface structure! */ |
| 192 |
/* Changes: |
| 193 |
* v2 |
| 194 |
* - added param bCondLoad to Load call - 2011-04-27 |
| 195 |
* - removed GetNxtType, added GetNxtCnfType - 2011-04-27 |
| 196 |
* v3 (see above) |
| 197 |
* v4 |
| 198 |
* - added third parameter to Load() - 2012-06-20 |
| 199 |
*/ |
| 200 |
|
| 201 |
/* prototypes */ |
| 202 |
PROTOTYPEObj(module); |
| 203 |
/* in v6, we go back to in-core static link for core objects, at least those |
| 204 |
* that are not called from plugins. |
| 205 |
* ... and we need to know that none of the module functions are called from plugins! |
| 206 |
* rgerhards, 2012-09-24 |
| 207 |
*/ |
| 208 |
rsRetVal modulesProcessCnf(struct cnfobj *o); |
| 209 |
uchar *modGetName(modInfo_t *pThis); |
| 210 |
rsRetVal ATTR_NONNULL(1) addModToCnfList(cfgmodules_etry_t **pNew, cfgmodules_etry_t *pLast); |
| 211 |
rsRetVal readyModForCnf(modInfo_t *pThis, cfgmodules_etry_t **ppNew, cfgmodules_etry_t **ppLast); |
| 212 |
void modDoHUP(void); |
| 213 |
|
| 214 |
#endif /* #ifndef MODULES_H_INCLUDED */ |