| 1 |
/* module-template.h |
| 2 |
* This header contains macros that can be used to implement the |
| 3 |
* plumbing of modules. |
| 4 |
* |
| 5 |
* File begun on 2007-07-25 by RGerhards |
| 6 |
* |
| 7 |
* Copyright 2007-2026 Adiscon GmbH. |
| 8 |
* |
| 9 |
* This file is part of the rsyslog runtime library. |
| 10 |
* |
| 11 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 |
* you may not use this file except in compliance with the License. |
| 13 |
* You may obtain a copy of the License at |
| 14 |
* |
| 15 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 16 |
* -or- |
| 17 |
* see COPYING.ASL20 in the source distribution |
| 18 |
* |
| 19 |
* Unless required by applicable law or agreed to in writing, software |
| 20 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 21 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 |
* See the License for the specific language governing permissions and |
| 23 |
* limitations under the License. |
| 24 |
*/ |
| 25 |
#ifndef MODULE_TEMPLATE_H_INCLUDED |
| 26 |
#define MODULE_TEMPLATE_H_INCLUDED 1 |
| 27 |
|
| 28 |
#include "modules.h" |
| 29 |
#include "obj.h" |
| 30 |
#include "objomsr.h" |
| 31 |
#include "threads.h" |
| 32 |
|
| 33 |
/* macro to define standard output-module static data members |
| 34 |
*/ |
| 35 |
#define DEF_MOD_STATIC_DATA \ |
| 36 |
static __attribute__((unused)) rsRetVal (*omsdRegCFSLineHdlr)(uchar * pCmdName, int bChainingPermitted, \ |
| 37 |
ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), \ |
| 38 |
void *pData, void *pOwnerCookie) |
| 39 |
|
| 40 |
#define DEF_OMOD_STATIC_DATA \ |
| 41 |
DEF_MOD_STATIC_DATA; \ |
| 42 |
DEFobjCurrIf(obj) static __attribute__((unused)) int bCoreSupportsBatching; |
| 43 |
#define DEF_IMOD_STATIC_DATA \ |
| 44 |
DEF_MOD_STATIC_DATA; \ |
| 45 |
DEFobjCurrIf(obj) |
| 46 |
#define DEF_LMOD_STATIC_DATA DEF_MOD_STATIC_DATA |
| 47 |
#define DEF_PMOD_STATIC_DATA \ |
| 48 |
DEFobjCurrIf(obj); \ |
| 49 |
DEF_MOD_STATIC_DATA |
| 50 |
#define DEF_SMOD_STATIC_DATA \ |
| 51 |
DEFobjCurrIf(obj); \ |
| 52 |
DEF_MOD_STATIC_DATA |
| 53 |
#define DEF_FMOD_STATIC_DATA \ |
| 54 |
DEFobjCurrIf(obj); \ |
| 55 |
DEF_MOD_STATIC_DATA |
| 56 |
|
| 57 |
|
| 58 |
/* Macro to define the module type. Each module can only have a single type. If |
| 59 |
* a module provides multiple types, several separate modules must be created which |
| 60 |
* then should share a single library containing the majority of code. This macro |
| 61 |
* must be present in each module. -- rgerhards, 2007-12-14 |
| 62 |
* Note that MODULE_TYPE_TESTBENCH is reserved for testbenches, but |
| 63 |
* declared in their own header files (because the rest does not need these |
| 64 |
* defines). -- rgerhards, 2008-06-13 |
| 65 |
*/ |
| 66 |
#define MODULE_TYPE(x) \ |
| 67 |
static rsRetVal modGetType(eModType_t *modType) { \ |
| 68 |
*modType = x; \ |
| 69 |
return RS_RET_OK; \ |
| 70 |
} |
| 71 |
|
| 72 |
#define MODULE_TYPE_INPUT MODULE_TYPE(eMOD_IN) |
| 73 |
#define MODULE_TYPE_OUTPUT MODULE_TYPE(eMOD_OUT) |
| 74 |
#define MODULE_TYPE_PARSER MODULE_TYPE(eMOD_PARSER) |
| 75 |
#define MODULE_TYPE_STRGEN MODULE_TYPE(eMOD_STRGEN) |
| 76 |
#define MODULE_TYPE_FUNCTION MODULE_TYPE(eMOD_FUNCTION) |
| 77 |
#define MODULE_TYPE_LIB \ |
| 78 |
DEF_LMOD_STATIC_DATA; \ |
| 79 |
MODULE_TYPE(eMOD_LIB) |
| 80 |
|
| 81 |
/* Macro to define whether the module should be kept dynamically linked. |
| 82 |
*/ |
| 83 |
#define MODULE_KEEP_TYPE(x) \ |
| 84 |
static rsRetVal modGetKeepType(eModKeepType_t *modKeepType) { \ |
| 85 |
*modKeepType = x; \ |
| 86 |
return RS_RET_OK; \ |
| 87 |
} |
| 88 |
#define MODULE_TYPE_NOKEEP MODULE_KEEP_TYPE(eMOD_NOKEEP) |
| 89 |
#define MODULE_TYPE_KEEP MODULE_KEEP_TYPE(eMOD_KEEP) |
| 90 |
|
| 91 |
/* macro to define a unique module id. This must be able to fit in a void*. The |
| 92 |
* module id must be unique inside a running rsyslogd application. It is used to |
| 93 |
* track ownership of several objects. Most importantly, when the module is |
| 94 |
* unloaded the module id value is used to find what needs to be destroyed. |
| 95 |
* We currently use a pointer to modExit() as the module id. This sounds to be |
| 96 |
* reasonable save, as each module must have this entry point AND there is no valid |
| 97 |
* reason for twice this entry point being in memory. |
| 98 |
* rgerhards, 2007-11-21 |
| 99 |
*/ |
| 100 |
#define STD_LOADABLE_MODULE_ID ((void *)modExit) |
| 101 |
|
| 102 |
|
| 103 |
/* macro to implement the "modGetID()" interface function |
| 104 |
* rgerhards 2007-11-21 |
| 105 |
*/ |
| 106 |
#define DEFmodGetID \ |
| 107 |
static rsRetVal modGetID(void **pID) { \ |
| 108 |
*pID = STD_LOADABLE_MODULE_ID; \ |
| 109 |
return RS_RET_OK; \ |
| 110 |
} |
| 111 |
|
| 112 |
/* macro to provide the v6 config system module name |
| 113 |
*/ |
| 114 |
#define MODULE_CNFNAME(name) \ |
| 115 |
static rsRetVal modGetCnfName(uchar **cnfName) { \ |
| 116 |
*cnfName = (uchar *)name; \ |
| 117 |
return RS_RET_OK; \ |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/* to following macros are used to generate function headers and standard |
| 122 |
* functionality. It works as follows (described on the sample case of |
| 123 |
* createInstance()): |
| 124 |
* |
| 125 |
* BEGINcreateInstance |
| 126 |
* ... custom variable definitions (on stack) ... (if any) |
| 127 |
* CODESTARTcreateInstance |
| 128 |
* ... custom code ... (if any) |
| 129 |
* ENDcreateInstance |
| 130 |
*/ |
| 131 |
|
| 132 |
/* createInstance() |
| 133 |
*/ |
| 134 |
#define BEGINcreateInstance \ |
| 135 |
static rsRetVal createInstance(instanceData **ppData) { \ |
| 136 |
DEFiRet; /* store error code here */ \ |
| 137 |
instanceData *pData; /* use this to point to data elements */ |
| 138 |
|
| 139 |
#define CODESTARTcreateInstance \ |
| 140 |
if ((pData = calloc(1, sizeof(instanceData))) == NULL) { \ |
| 141 |
*ppData = NULL; \ |
| 142 |
return RS_RET_OUT_OF_MEMORY; \ |
| 143 |
} |
| 144 |
|
| 145 |
#define ENDcreateInstance \ |
| 146 |
*ppData = pData; \ |
| 147 |
RETiRet; \ |
| 148 |
} |
| 149 |
|
| 150 |
/* freeInstance() |
| 151 |
* This is the cleanup function for the module instance. It is called immediately before |
| 152 |
* the module instance is destroyed (unloaded). The module should do any cleanup |
| 153 |
* here, e.g. close file, free instantance heap memory and the like. Control will |
| 154 |
* not be passed back to the module once this function is finished. Keep in mind, |
| 155 |
* however, that other instances may still be loaded and used. So do not destroy |
| 156 |
* anything that may be used by another instance. If you have such a ressource, you |
| 157 |
* currently need to do the instance counting yourself. |
| 158 |
*/ |
| 159 |
#define BEGINfreeInstance \ |
| 160 |
static rsRetVal freeInstance(void *pModData) { \ |
| 161 |
DEFiRet; \ |
| 162 |
instanceData *pData; |
| 163 |
|
| 164 |
#define CODESTARTfreeInstance pData = (instanceData *)pModData; |
| 165 |
|
| 166 |
#define ENDfreeInstance \ |
| 167 |
if (pData != NULL) free(pData); /* we need to free this in any case */ \ |
| 168 |
RETiRet; \ |
| 169 |
} |
| 170 |
|
| 171 |
/* createWrkrInstance() |
| 172 |
*/ |
| 173 |
#define BEGINcreateWrkrInstance \ |
| 174 |
static rsRetVal createWrkrInstance(wrkrInstanceData_t **ppWrkrData, instanceData *pData) { \ |
| 175 |
DEFiRet; /* store error code here */ \ |
| 176 |
wrkrInstanceData_t *pWrkrData; /* use this to point to data elements */ |
| 177 |
|
| 178 |
#define CODESTARTcreateWrkrInstance \ |
| 179 |
if ((pWrkrData = calloc(1, sizeof(wrkrInstanceData_t))) == NULL) { \ |
| 180 |
*ppWrkrData = NULL; \ |
| 181 |
return RS_RET_OUT_OF_MEMORY; \ |
| 182 |
} \ |
| 183 |
pWrkrData->pData = pData; |
| 184 |
|
| 185 |
#define ENDcreateWrkrInstance \ |
| 186 |
*ppWrkrData = pWrkrData; \ |
| 187 |
RETiRet; \ |
| 188 |
} |
| 189 |
|
| 190 |
/* freeWrkrInstance */ |
| 191 |
#define BEGINfreeWrkrInstance \ |
| 192 |
static rsRetVal freeWrkrInstance(void *pd) { \ |
| 193 |
DEFiRet; \ |
| 194 |
wrkrInstanceData_t *pWrkrData; |
| 195 |
|
| 196 |
#define CODESTARTfreeWrkrInstance pWrkrData = (wrkrInstanceData_t *)pd; |
| 197 |
|
| 198 |
#define ENDfreeWrkrInstance \ |
| 199 |
if (pWrkrData != NULL) free(pWrkrData); /* we need to free this in any case */ \ |
| 200 |
RETiRet; \ |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
/* isCompatibleWithFeature() |
| 205 |
*/ |
| 206 |
#define BEGINisCompatibleWithFeature \ |
| 207 |
static rsRetVal isCompatibleWithFeature(syslogFeature __attribute__((unused)) eFeat) { \ |
| 208 |
rsRetVal iRet = RS_RET_INCOMPATIBLE; |
| 209 |
|
| 210 |
#define CODESTARTisCompatibleWithFeature |
| 211 |
|
| 212 |
#define ENDisCompatibleWithFeature \ |
| 213 |
RETiRet; \ |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
/* beginTransaction() |
| 218 |
* introduced in v4.3.3 -- rgerhards, 2009-04-27 |
| 219 |
*/ |
| 220 |
#define BEGINbeginTransaction \ |
| 221 |
static rsRetVal beginTransaction(wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 222 |
DEFiRet; |
| 223 |
|
| 224 |
#define CODESTARTbeginTransaction /* currently empty, but may be extended */ |
| 225 |
|
| 226 |
#define ENDbeginTransaction \ |
| 227 |
RETiRet; \ |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/* commitTransaction() |
| 232 |
* Commits a transaction. Note that beginTransaction() must have been |
| 233 |
* called before this entry point. It receives the full batch of messages |
| 234 |
* to be processed in pParam parameter. |
| 235 |
* introduced in v8.1.3 -- rgerhards, 2013-12-04 |
| 236 |
*/ |
| 237 |
#define BEGINcommitTransaction \ |
| 238 |
static rsRetVal commitTransaction(wrkrInstanceData_t __attribute__((unused)) *const pWrkrData, \ |
| 239 |
actWrkrIParams_t *const pParams, const unsigned nParams) { \ |
| 240 |
DEFiRet; |
| 241 |
|
| 242 |
#define CODESTARTcommitTransaction /* currently empty, but may be extended */ |
| 243 |
|
| 244 |
#define ENDcommitTransaction \ |
| 245 |
RETiRet; \ |
| 246 |
} |
| 247 |
|
| 248 |
/* endTransaction() |
| 249 |
* introduced in v4.3.3 -- rgerhards, 2009-04-27 |
| 250 |
*/ |
| 251 |
#define BEGINendTransaction \ |
| 252 |
static rsRetVal endTransaction(wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 253 |
DEFiRet; |
| 254 |
|
| 255 |
#define CODESTARTendTransaction /* currently empty, but may be extended */ |
| 256 |
|
| 257 |
#define ENDendTransaction \ |
| 258 |
RETiRet; \ |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
/* doAction() |
| 263 |
*/ |
| 264 |
#define BEGINdoAction \ |
| 265 |
static rsRetVal doAction(void *pMsgData, wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 266 |
uchar **ppString = (uchar **)pMsgData; \ |
| 267 |
DEFiRet; |
| 268 |
|
| 269 |
#define CODESTARTdoAction /* ppString may be NULL if the output module requested no strings */ |
| 270 |
|
| 271 |
#define ENDdoAction \ |
| 272 |
RETiRet; \ |
| 273 |
} |
| 274 |
|
| 275 |
/* setActionInfo() |
| 276 |
* Optional callback to provide the action object after creation. |
| 277 |
*/ |
| 278 |
#define BEGINsetActionInfo \ |
| 279 |
static rsRetVal setActionInfo(void *const pModData, action_t *const pAction) { \ |
| 280 |
DEFiRet; \ |
| 281 |
instanceData *pData; |
| 282 |
|
| 283 |
#define CODESTARTsetActionInfo \ |
| 284 |
pData = (instanceData *)pModData; \ |
| 285 |
(void)pAction; \ |
| 286 |
(void)pData; |
| 287 |
|
| 288 |
#define ENDsetActionInfo \ |
| 289 |
RETiRet; \ |
| 290 |
} |
| 291 |
|
| 292 |
/* below is a variant of doAction where the passed-in data is not the common |
| 293 |
* case of string. |
| 294 |
*/ |
| 295 |
#define BEGINdoAction_NoStrings \ |
| 296 |
static rsRetVal doAction(void *pMsgData, wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 297 |
DEFiRet; |
| 298 |
|
| 299 |
|
| 300 |
/* dbgPrintInstInfo() |
| 301 |
* Extra comments: |
| 302 |
* Print debug information about this instance. |
| 303 |
*/ |
| 304 |
#define BEGINdbgPrintInstInfo \ |
| 305 |
static rsRetVal dbgPrintInstInfo(void *pModData) { \ |
| 306 |
DEFiRet; \ |
| 307 |
instanceData *pData = NULL; |
| 308 |
|
| 309 |
#define CODESTARTdbgPrintInstInfo \ |
| 310 |
pData = (instanceData *)pModData; \ |
| 311 |
(void)pData; /* prevent compiler warning if unused! */ |
| 312 |
|
| 313 |
#define ENDdbgPrintInstInfo \ |
| 314 |
RETiRet; \ |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
/* parseSelectorAct() |
| 319 |
* Extra comments: |
| 320 |
* try to process a selector action line. Checks if the action |
| 321 |
* applies to this module and, if so, processed it. If not, it |
| 322 |
* is left untouched. The driver will then call another module. |
| 323 |
* On exit, ppModData must point to instance data. Also, a string |
| 324 |
* request object must be created and filled. A macro is defined |
| 325 |
* for that. |
| 326 |
* For the most usual case, we have defined a macro below. |
| 327 |
* If more than one string is requested, the macro can be used together |
| 328 |
* with own code that overwrites the entry count. In this case, the |
| 329 |
* macro must come before the own code. It is recommended to be |
| 330 |
* placed right after CODESTARTparseSelectorAct. |
| 331 |
*/ |
| 332 |
#define BEGINparseSelectorAct \ |
| 333 |
static rsRetVal parseSelectorAct(uchar **pp, void **ppModData, omodStringRequest_t **ppOMSR) { \ |
| 334 |
DEFiRet; \ |
| 335 |
uchar *p; \ |
| 336 |
instanceData *pData = NULL; |
| 337 |
|
| 338 |
#define CODESTARTparseSelectorAct \ |
| 339 |
assert(pp != NULL); \ |
| 340 |
assert(ppModData != NULL); \ |
| 341 |
assert(ppOMSR != NULL); \ |
| 342 |
p = *pp; |
| 343 |
|
| 344 |
#define CODE_STD_STRING_REQUESTparseSelectorAct(NumStrReqEntries) CHKiRet(OMSRconstruct(ppOMSR, NumStrReqEntries)); |
| 345 |
|
| 346 |
#define CODE_STD_FINALIZERparseSelectorAct \ |
| 347 |
finalize_it : ATTR_UNUSED; /* semi-colon needed according to gcc doc! */ \ |
| 348 |
if (iRet == RS_RET_OK || iRet == RS_RET_OK_WARN || iRet == RS_RET_SUSPENDED) { \ |
| 349 |
*ppModData = pData; \ |
| 350 |
*pp = p; \ |
| 351 |
} else { \ |
| 352 |
/* cleanup, we failed */ \ |
| 353 |
if (*ppOMSR != NULL) { \ |
| 354 |
OMSRdestruct(*ppOMSR); \ |
| 355 |
*ppOMSR = NULL; \ |
| 356 |
} \ |
| 357 |
if (pData != NULL) { \ |
| 358 |
freeInstance(pData); \ |
| 359 |
} \ |
| 360 |
} |
| 361 |
|
| 362 |
#define ENDparseSelectorAct \ |
| 363 |
RETiRet; \ |
| 364 |
} |
| 365 |
|
| 366 |
/* a special replacement macro for modules that do not support legacy config at all */ |
| 367 |
#define NO_LEGACY_CONF_parseSelectorAct \ |
| 368 |
static rsRetVal parseSelectorAct(uchar **pp ATTR_UNUSED, void **ppModData ATTR_UNUSED, \ |
| 369 |
omodStringRequest_t **ppOMSR ATTR_UNUSED) { \ |
| 370 |
return RS_RET_LEGA_ACT_NOT_SUPPORTED; \ |
| 371 |
} |
| 372 |
|
| 373 |
/* newActInst() |
| 374 |
* Extra comments: |
| 375 |
* This creates a new instance of a the action that implements the call. |
| 376 |
* This is part of the conf2 (rsyslog v6) config system. It is called by |
| 377 |
* the core when an action object has been obtained. The output module |
| 378 |
* must then verify parameters and create a new action instance (if |
| 379 |
* parameters are acceptable) or return an error code. |
| 380 |
* On exit, ppModData must point to instance data. Also, a string |
| 381 |
* request object must be created and filled. A macro is defined |
| 382 |
* for that. |
| 383 |
* For the most usual case, we have defined a macro below. |
| 384 |
* If more than one string is requested, the macro can be used together |
| 385 |
* with own code that overwrites the entry count. In this case, the |
| 386 |
* macro must come before the own code. It is recommended to be |
| 387 |
* placed right after CODESTARTnewActInst. |
| 388 |
*/ |
| 389 |
#define BEGINnewActInst \ |
| 390 |
static rsRetVal newActInst(uchar __attribute__((unused)) * modName, struct nvlst __attribute__((unused)) * lst, \ |
| 391 |
void **ppModData, omodStringRequest_t **ppOMSR) { \ |
| 392 |
DEFiRet; \ |
| 393 |
instanceData *pData = NULL; \ |
| 394 |
*ppOMSR = NULL; |
| 395 |
|
| 396 |
#define CODESTARTnewActInst |
| 397 |
|
| 398 |
#define CODE_STD_STRING_REQUESTnewActInst(NumStrReqEntries) CHKiRet(OMSRconstruct(ppOMSR, NumStrReqEntries)) |
| 399 |
|
| 400 |
#define CODE_STD_FINALIZERnewActInst \ |
| 401 |
finalize_it : if (iRet == RS_RET_OK || iRet == RS_RET_SUSPENDED) { \ |
| 402 |
*ppModData = pData; \ |
| 403 |
} else { \ |
| 404 |
/* cleanup, we failed */ \ |
| 405 |
if (*ppOMSR != NULL) { \ |
| 406 |
OMSRdestruct(*ppOMSR); \ |
| 407 |
*ppOMSR = NULL; \ |
| 408 |
} \ |
| 409 |
if (pData != NULL) { \ |
| 410 |
freeInstance(pData); \ |
| 411 |
} \ |
| 412 |
} |
| 413 |
|
| 414 |
#define ENDnewActInst \ |
| 415 |
RETiRet; \ |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
/* newInpInst() |
| 420 |
* This is basically the equivalent to newActInst() for creating input |
| 421 |
* module (listener) instances. |
| 422 |
*/ |
| 423 |
#define BEGINnewInpInst \ |
| 424 |
static rsRetVal newInpInst(struct nvlst *lst) { \ |
| 425 |
DEFiRet; |
| 426 |
|
| 427 |
#define CODESTARTnewInpInst |
| 428 |
|
| 429 |
#define CODE_STD_FINALIZERnewInpInst |
| 430 |
|
| 431 |
#define ENDnewInpInst \ |
| 432 |
RETiRet; \ |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
/* newParserInst() |
| 437 |
* This is basically the equivalent to newActInst() for creating parser |
| 438 |
* module (listener) instances. |
| 439 |
*/ |
| 440 |
#define BEGINnewParserInst \ |
| 441 |
static rsRetVal newParserInst(struct nvlst *lst, void *pinst) { \ |
| 442 |
instanceConf_t *inst; \ |
| 443 |
DEFiRet; |
| 444 |
|
| 445 |
#define CODESTARTnewParserInst |
| 446 |
|
| 447 |
#define CODE_STD_FINALIZERnewParserInst |
| 448 |
|
| 449 |
#define ENDnewParserInst \ |
| 450 |
if (iRet == RS_RET_OK) *((instanceConf_t **)pinst) = inst; \ |
| 451 |
RETiRet; \ |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
/* freeParserInst */ |
| 456 |
#define BEGINfreeParserInst \ |
| 457 |
static rsRetVal freeParserInst(void *pi) { \ |
| 458 |
DEFiRet; \ |
| 459 |
instanceConf_t *pInst; |
| 460 |
|
| 461 |
#define CODESTARTfreeParserInst pInst = (instanceConf_t *)pi; |
| 462 |
|
| 463 |
#define ENDfreeParserInst \ |
| 464 |
if (pInst != NULL) free(pInst); \ |
| 465 |
RETiRet; \ |
| 466 |
} |
| 467 |
|
| 468 |
/* tryResume() |
| 469 |
* This entry point is called to check if a module can resume operations. This |
| 470 |
* happens when a module requested that it be suspended. In suspended state, |
| 471 |
* the engine periodically tries to resume the module. If that succeeds, normal |
| 472 |
* processing continues. If not, the module will not be called unless a |
| 473 |
* tryResume() call succeeds. |
| 474 |
* Returns RS_RET_OK, if resumption succeeded, RS_RET_SUSPENDED otherwise |
| 475 |
* rgerhard, 2007-08-02 |
| 476 |
*/ |
| 477 |
#define BEGINtryResume \ |
| 478 |
static rsRetVal tryResume(wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 479 |
DEFiRet; |
| 480 |
|
| 481 |
#define CODESTARTtryResume assert(pWrkrData != NULL); |
| 482 |
|
| 483 |
#define ENDtryResume \ |
| 484 |
RETiRet; \ |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
/* initConfVars() - initialize pre-v6.3-config variables |
| 489 |
*/ |
| 490 |
#define BEGINinitConfVars \ |
| 491 |
static rsRetVal initConfVars(void) { \ |
| 492 |
DEFiRet; |
| 493 |
|
| 494 |
#define CODESTARTinitConfVars |
| 495 |
|
| 496 |
#define ENDinitConfVars \ |
| 497 |
RETiRet; \ |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
/* queryEtryPt() |
| 502 |
*/ |
| 503 |
#define BEGINqueryEtryPt \ |
| 504 |
DEFmodGetID static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)()) { \ |
| 505 |
DEFiRet; |
| 506 |
|
| 507 |
#define CODESTARTqueryEtryPt \ |
| 508 |
if ((name == NULL) || (pEtryPoint == NULL)) { \ |
| 509 |
return RS_RET_PARAM_ERROR; \ |
| 510 |
} \ |
| 511 |
*pEtryPoint = NULL; |
| 512 |
|
| 513 |
#define ENDqueryEtryPt \ |
| 514 |
if (iRet == RS_RET_OK) \ |
| 515 |
if (*pEtryPoint == NULL) { \ |
| 516 |
dbgprintf("entry point '%s' not present in module\n", name); \ |
| 517 |
iRet = RS_RET_MODULE_ENTRY_POINT_NOT_FOUND; \ |
| 518 |
} \ |
| 519 |
RETiRet; \ |
| 520 |
} |
| 521 |
|
| 522 |
/** \addtogroup module_entrypoint_blocks |
| 523 |
* \{ |
| 524 |
* \brief Standard queryEtryPt block for all module types. |
| 525 |
* |
| 526 |
* Must be included in every module. This defines default queries |
| 527 |
* like `modExit`, `modGetID`, etc. |
| 528 |
*/ |
| 529 |
#define CODEqueryEtryPt_STD_MOD_QUERIES \ |
| 530 |
if (!strcmp((char *)name, "modExit")) { \ |
| 531 |
*pEtryPoint = modExit; \ |
| 532 |
} \ |
| 533 |
if (!strcmp((char *)name, "modGetID")) { \ |
| 534 |
*pEtryPoint = modGetID; \ |
| 535 |
} \ |
| 536 |
if (!strcmp((char *)name, "getType")) { \ |
| 537 |
*pEtryPoint = modGetType; \ |
| 538 |
} \ |
| 539 |
if (!strcmp((char *)name, "getKeepType")) { \ |
| 540 |
*pEtryPoint = modGetKeepType; \ |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* \brief Standard block for output modules without transaction support. |
| 545 |
*/ |
| 546 |
#define CODEqueryEtryPt_STD_OMOD_QUERIES \ |
| 547 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "doAction")) { \ |
| 548 |
*pEtryPoint = doAction; \ |
| 549 |
} \ |
| 550 |
if (!strcmp((char *)name, "dbgPrintInstInfo")) { \ |
| 551 |
*pEtryPoint = dbgPrintInstInfo; \ |
| 552 |
} \ |
| 553 |
if (!strcmp((char *)name, "freeInstance")) { \ |
| 554 |
*pEtryPoint = freeInstance; \ |
| 555 |
} \ |
| 556 |
if (!strcmp((char *)name, "parseSelectorAct")) { \ |
| 557 |
*pEtryPoint = parseSelectorAct; \ |
| 558 |
} \ |
| 559 |
if (!strcmp((char *)name, "isCompatibleWithFeature")) { \ |
| 560 |
*pEtryPoint = isCompatibleWithFeature; \ |
| 561 |
} \ |
| 562 |
if (!strcmp((char *)name, "tryResume")) { \ |
| 563 |
*pEtryPoint = tryResume; \ |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* \brief Standard block for output modules using the transaction interface. |
| 568 |
*/ |
| 569 |
#define CODEqueryEtryPt_STD_OMODTX_QUERIES \ |
| 570 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "beginTransaction")) { \ |
| 571 |
*pEtryPoint = beginTransaction; \ |
| 572 |
} \ |
| 573 |
if (!strcmp((char *)name, "commitTransaction")) { \ |
| 574 |
*pEtryPoint = commitTransaction; \ |
| 575 |
} \ |
| 576 |
if (!strcmp((char *)name, "dbgPrintInstInfo")) { \ |
| 577 |
*pEtryPoint = dbgPrintInstInfo; \ |
| 578 |
} \ |
| 579 |
if (!strcmp((char *)name, "freeInstance")) { \ |
| 580 |
*pEtryPoint = freeInstance; \ |
| 581 |
} \ |
| 582 |
if (!strcmp((char *)name, "parseSelectorAct")) { \ |
| 583 |
*pEtryPoint = parseSelectorAct; \ |
| 584 |
} \ |
| 585 |
if (!strcmp((char *)name, "isCompatibleWithFeature")) { \ |
| 586 |
*pEtryPoint = isCompatibleWithFeature; \ |
| 587 |
} \ |
| 588 |
if (!strcmp((char *)name, "tryResume")) { \ |
| 589 |
*pEtryPoint = tryResume; \ |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* \brief Additional methods for output module v8+ support. |
| 594 |
*/ |
| 595 |
#define CODEqueryEtryPt_STD_OMOD8_QUERIES \ |
| 596 |
if (!strcmp((char *)name, "createWrkrInstance")) { \ |
| 597 |
*pEtryPoint = createWrkrInstance; \ |
| 598 |
} \ |
| 599 |
if (!strcmp((char *)name, "freeWrkrInstance")) { \ |
| 600 |
*pEtryPoint = freeWrkrInstance; \ |
| 601 |
} |
| 602 |
|
| 603 |
/** |
| 604 |
* \brief For output modules with transaction interface extension. |
| 605 |
*/ |
| 606 |
#define CODEqueryEtryPt_TXIF_OMOD_QUERIES \ |
| 607 |
if (!strcmp((char *)name, "beginTransaction")) { \ |
| 608 |
*pEtryPoint = beginTransaction; \ |
| 609 |
} \ |
| 610 |
if (!strcmp((char *)name, "endTransaction")) { \ |
| 611 |
*pEtryPoint = endTransaction; \ |
| 612 |
} |
| 613 |
|
| 614 |
/** |
| 615 |
* \brief Optional support for feature compatibility query. |
| 616 |
*/ |
| 617 |
#define CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES \ |
| 618 |
if (!strcmp((char *)name, "isCompatibleWithFeature")) { \ |
| 619 |
*pEtryPoint = isCompatibleWithFeature; \ |
| 620 |
} |
| 621 |
|
| 622 |
#define CODEqueryEtryPt_SetActionInfo_IF_OMOD_QUERIES \ |
| 623 |
if (!strcmp((char *)name, "setActionInfo")) { \ |
| 624 |
*pEtryPoint = setActionInfo; \ |
| 625 |
} |
| 626 |
|
| 627 |
/** |
| 628 |
* \brief Standard block for input modules. |
| 629 |
*/ |
| 630 |
#define CODEqueryEtryPt_STD_IMOD_QUERIES \ |
| 631 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "runInput")) { \ |
| 632 |
*pEtryPoint = runInput; \ |
| 633 |
} \ |
| 634 |
if (!strcmp((char *)name, "willRun")) { \ |
| 635 |
*pEtryPoint = willRun; \ |
| 636 |
} \ |
| 637 |
if (!strcmp((char *)name, "afterRun")) { \ |
| 638 |
*pEtryPoint = afterRun; \ |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* \brief For modules using the config interface v2. |
| 643 |
*/ |
| 644 |
#define CODEqueryEtryPt_STD_CONF2_QUERIES \ |
| 645 |
if (!strcmp((char *)name, "beginCnfLoad")) { \ |
| 646 |
*pEtryPoint = beginCnfLoad; \ |
| 647 |
} \ |
| 648 |
if (!strcmp((char *)name, "endCnfLoad")) { \ |
| 649 |
*pEtryPoint = endCnfLoad; \ |
| 650 |
} \ |
| 651 |
if (!strcmp((char *)name, "checkCnf")) { \ |
| 652 |
*pEtryPoint = checkCnf; \ |
| 653 |
} \ |
| 654 |
if (!strcmp((char *)name, "activateCnf")) { \ |
| 655 |
*pEtryPoint = activateCnf; \ |
| 656 |
} \ |
| 657 |
if (!strcmp((char *)name, "freeCnf")) { \ |
| 658 |
*pEtryPoint = freeCnf; \ |
| 659 |
} \ |
| 660 |
CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES |
| 661 |
|
| 662 |
#define CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES \ |
| 663 |
if (!strcmp((char *)name, "setModCnf")) { \ |
| 664 |
*pEtryPoint = setModCnf; \ |
| 665 |
} |
| 666 |
|
| 667 |
#define CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES \ |
| 668 |
if (!strcmp((char *)name, "newActInst")) { \ |
| 669 |
*pEtryPoint = newActInst; \ |
| 670 |
} \ |
| 671 |
CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES |
| 672 |
|
| 673 |
#define CODEqueryEtryPt_STD_CONF2_IMOD_QUERIES \ |
| 674 |
if (!strcmp((char *)name, "newInpInst")) { \ |
| 675 |
*pEtryPoint = newInpInst; \ |
| 676 |
} \ |
| 677 |
CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES |
| 678 |
|
| 679 |
#define CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES \ |
| 680 |
if (!strcmp((char *)name, "activateCnfPrePrivDrop")) { \ |
| 681 |
*pEtryPoint = activateCnfPrePrivDrop; \ |
| 682 |
} |
| 683 |
|
| 684 |
/** |
| 685 |
* \brief Config interface v6 module name support. |
| 686 |
*/ |
| 687 |
#define CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES \ |
| 688 |
if (!strcmp((char *)name, "getModCnfName")) { \ |
| 689 |
*pEtryPoint = modGetCnfName; \ |
| 690 |
} |
| 691 |
|
| 692 |
/** |
| 693 |
* \brief Standard block for library modules. |
| 694 |
*/ |
| 695 |
#define CODEqueryEtryPt_STD_LIB_QUERIES CODEqueryEtryPt_STD_MOD_QUERIES |
| 696 |
|
| 697 |
/** |
| 698 |
* \brief Standard block for parser modules. |
| 699 |
*/ |
| 700 |
#define CODEqueryEtryPt_STD_PMOD_QUERIES \ |
| 701 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "parse")) { \ |
| 702 |
*pEtryPoint = parse; \ |
| 703 |
} \ |
| 704 |
if (!strcmp((char *)name, "GetParserName")) { \ |
| 705 |
*pEtryPoint = GetParserName; \ |
| 706 |
} |
| 707 |
|
| 708 |
/** |
| 709 |
* \brief Standard block for parser modules using config v2. |
| 710 |
*/ |
| 711 |
#define CODEqueryEtryPt_STD_PMOD2_QUERIES \ |
| 712 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "parse2")) { \ |
| 713 |
*pEtryPoint = parse2; \ |
| 714 |
} \ |
| 715 |
if (!strcmp((char *)name, "GetParserName")) { \ |
| 716 |
*pEtryPoint = GetParserName; \ |
| 717 |
} \ |
| 718 |
if (!strcmp((char *)name, "newParserInst")) { \ |
| 719 |
*pEtryPoint = newParserInst; \ |
| 720 |
} \ |
| 721 |
if (!strcmp((char *)name, "checkParserInst")) { \ |
| 722 |
*pEtryPoint = checkParserInst; \ |
| 723 |
} \ |
| 724 |
if (!strcmp((char *)name, "freeParserInst")) { \ |
| 725 |
*pEtryPoint = freeParserInst; \ |
| 726 |
} \ |
| 727 |
CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES |
| 728 |
|
| 729 |
/** |
| 730 |
* \brief Standard block for rscript function modules. |
| 731 |
*/ |
| 732 |
#define CODEqueryEtryPt_STD_FMOD_QUERIES \ |
| 733 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "getFunctArray")) { \ |
| 734 |
*pEtryPoint = getFunctArray; \ |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* \brief Standard block for strgen modules. |
| 739 |
*/ |
| 740 |
#define CODEqueryEtryPt_STD_SMOD_QUERIES \ |
| 741 |
CODEqueryEtryPt_STD_MOD_QUERIES if (!strcmp((char *)name, "strgen")) { \ |
| 742 |
*pEtryPoint = strgen; \ |
| 743 |
} \ |
| 744 |
if (!strcmp((char *)name, "GetName")) { \ |
| 745 |
*pEtryPoint = GetStrgenName; \ |
| 746 |
} |
| 747 |
/** \} */ // end of module_entrypoint_blocks |
| 748 |
|
| 749 |
|
| 750 |
/* modInit() |
| 751 |
* This has an extra parameter, which is the specific name of the modInit |
| 752 |
* function. That is needed for built-in modules, which must have unique |
| 753 |
* names in order to link statically. Please note that this is always only |
| 754 |
* the case with modInit() and NO other entry point. The reason is that only |
| 755 |
* modInit() is visible form a linker/loader point of view. All other entry |
| 756 |
* points are passed via rsyslog-internal query functions and are defined |
| 757 |
* static inside the modules source. This is an important concept, as it allows |
| 758 |
* us to support different interface versions within a single module. (Granted, |
| 759 |
* we do not currently have different interface versions, so we can not put |
| 760 |
* it to a test - but our firm believe is that we can do all abstraction needed...) |
| 761 |
* |
| 762 |
* Extra Comments: |
| 763 |
* initialize the module |
| 764 |
* |
| 765 |
* Later, much more must be done. So far, we only return a pointer |
| 766 |
* to the queryEtryPt() function |
| 767 |
* TODO: do interface version checking & handshaking |
| 768 |
* iIfVersRequetsed is the version of the interface specification that the |
| 769 |
* caller would like to see being used. ipIFVersProvided is what we |
| 770 |
* decide to provide. |
| 771 |
* rgerhards, 2007-11-21: see modExit() comment below for important information |
| 772 |
* on the need to initialize static data with code. modInit() may be called on a |
| 773 |
* cached, left-in-memory copy of a previous incarnation. |
| 774 |
*/ |
| 775 |
#define BEGINmodInit(uniqName) \ |
| 776 |
rsRetVal __attribute__((unused)) modInit##uniqName( \ |
| 777 |
int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), \ |
| 778 |
rsRetVal (*pHostQueryEtryPt)(uchar *, rsRetVal(**)()), modInfo_t __attribute__((unused)) * pModInfo); \ |
| 779 |
rsRetVal __attribute__((unused)) modInit##uniqName( \ |
| 780 |
int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), \ |
| 781 |
rsRetVal (*pHostQueryEtryPt)(uchar *, rsRetVal(**)()), modInfo_t __attribute__((unused)) * pModInfo) { \ |
| 782 |
DEFiRet; \ |
| 783 |
rsRetVal (*pObjGetObjInterface)(obj_if_t * pIf); |
| 784 |
|
| 785 |
/* |
| 786 |
* Variant for modules that already publish modInit prototypes in headers. |
| 787 |
* This avoids duplicate declarations while preserving missing-prototype |
| 788 |
* coverage for modules that still rely on BEGINmodInit's local predecl. |
| 789 |
*/ |
| 790 |
#define BEGINmodInitNoPredecl(uniqName) \ |
| 791 |
rsRetVal __attribute__((unused)) modInit##uniqName( \ |
| 792 |
int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), \ |
| 793 |
rsRetVal (*pHostQueryEtryPt)(uchar *, rsRetVal(**)()), modInfo_t __attribute__((unused)) * pModInfo) { \ |
| 794 |
DEFiRet; \ |
| 795 |
rsRetVal (*pObjGetObjInterface)(obj_if_t * pIf); |
| 796 |
|
| 797 |
#define CODESTARTmodInit \ |
| 798 |
assert(pHostQueryEtryPt != NULL); \ |
| 799 |
iRet = pHostQueryEtryPt((uchar *)"objGetObjInterface", &pObjGetObjInterface); \ |
| 800 |
if ((iRet != RS_RET_OK) || (pQueryEtryPt == NULL) || (ipIFVersProvided == NULL) || \ |
| 801 |
(pObjGetObjInterface == NULL)) { \ |
| 802 |
return (iRet == RS_RET_OK) ? RS_RET_PARAM_ERROR : iRet; \ |
| 803 |
} \ |
| 804 |
/* now get the obj interface so that we can access other objects */ \ |
| 805 |
CHKiRet(pObjGetObjInterface(&obj)) |
| 806 |
|
| 807 |
/* do those initializations necessary for legacy config variables */ |
| 808 |
#define INITLegCnfVars initConfVars() |
| 809 |
|
| 810 |
#define ENDmodInit \ |
| 811 |
finalize_it : *pQueryEtryPt = queryEtryPt; \ |
| 812 |
RETiRet; \ |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
/* now come some check functions, which enable a standard way of obtaining feature |
| 817 |
* information from the core. feat is the to-be-tested feature and featVar is a |
| 818 |
* variable that receives the result (0-not support, 1-supported). |
| 819 |
* This must be a macro, so that it is put into the output's code. Otherwise, we |
| 820 |
* would need to rely on a library entry point, which is what we intend to avoid ;) |
| 821 |
* rgerhards, 2009-04-27 |
| 822 |
*/ |
| 823 |
#define INITChkCoreFeature(featVar, feat) \ |
| 824 |
{ \ |
| 825 |
rsRetVal MACRO_Ret; \ |
| 826 |
rsRetVal (*pQueryCoreFeatureSupport)(int *, unsigned); \ |
| 827 |
int bSupportsIt; \ |
| 828 |
featVar = 0; \ |
| 829 |
MACRO_Ret = pHostQueryEtryPt((uchar *)"queryCoreFeatureSupport", &pQueryCoreFeatureSupport); \ |
| 830 |
if (MACRO_Ret == RS_RET_OK) { \ |
| 831 |
/* found entry point, so let's see if core supports it */ \ |
| 832 |
CHKiRet((*pQueryCoreFeatureSupport)(&bSupportsIt, feat)); \ |
| 833 |
if (bSupportsIt) featVar = 1; \ |
| 834 |
} else if (MACRO_Ret != RS_RET_ENTRY_POINT_NOT_FOUND) { \ |
| 835 |
ABORT_FINALIZE(MACRO_Ret); /* Something else went wrong, what is not acceptable */ \ |
| 836 |
} \ |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
/* definitions for host API queries */ |
| 841 |
#define CODEmodInit_QueryRegCFSLineHdlr CHKiRet(pHostQueryEtryPt((uchar *)"regCfSysLineHdlr", &omsdRegCFSLineHdlr)); |
| 842 |
|
| 843 |
|
| 844 |
/* modExit() |
| 845 |
* This is the counterpart to modInit(). It destroys a module and makes it ready for |
| 846 |
* unloading. It is similiar to freeInstance() for the instance data. Please note that |
| 847 |
* this entry point needs to free any module-global data structures and registrations. |
| 848 |
* For example, the CfSysLineHandlers a module has registered need to be unregistered |
| 849 |
* here. This entry point is only called immediately before unloading of the module. So |
| 850 |
* it is likely to be destroyed. HOWEVER, the caller may decide to keep the module cached. |
| 851 |
* So a module must never assume that it is actually destroyed. A call to modInit() may |
| 852 |
* happen immediately after modExit(). So a module can NOT assume that static data elements |
| 853 |
* are being re-initialized by the loader - this must always be done by module code itself. |
| 854 |
* It is suggested to do this in modInit(). - rgerhards, 2007-11-21 |
| 855 |
*/ |
| 856 |
#define BEGINmodExit \ |
| 857 |
static rsRetVal modExit(void) { \ |
| 858 |
DEFiRet; |
| 859 |
|
| 860 |
#define CODESTARTmodExit |
| 861 |
|
| 862 |
#define ENDmodExit \ |
| 863 |
RETiRet; \ |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
/* beginCnfLoad() |
| 868 |
* This is a function tells an input module that a new config load begins. |
| 869 |
* The core passes in a handle to the new module-specific module conf to |
| 870 |
* the module. -- rgerards, 2011-05-03 |
| 871 |
*/ |
| 872 |
#define BEGINbeginCnfLoad \ |
| 873 |
static rsRetVal beginCnfLoad(modConfData_t **ptr, __attribute__((unused)) rsconf_t *pConf) { \ |
| 874 |
modConfData_t *pModConf; \ |
| 875 |
DEFiRet; |
| 876 |
|
| 877 |
#define CODESTARTbeginCnfLoad \ |
| 878 |
if ((pModConf = calloc(1, sizeof(modConfData_t))) == NULL) { \ |
| 879 |
*ptr = NULL; \ |
| 880 |
return RS_RET_OUT_OF_MEMORY; \ |
| 881 |
} |
| 882 |
|
| 883 |
#define ENDbeginCnfLoad \ |
| 884 |
*ptr = pModConf; \ |
| 885 |
RETiRet; \ |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
/* setModCnf() |
| 890 |
* This function permits to set module global parameters via the v2 config |
| 891 |
* interface. It may be called multiple times, but parameters must not be |
| 892 |
* set in a conflicting way. The module must use its current config load |
| 893 |
* context when processing the directives. |
| 894 |
* Note that lst may be NULL, especially if the module is loaded via the |
| 895 |
* legacy config system. The module must check for this. |
| 896 |
* NOTE: This entry point must only be implemented if module global |
| 897 |
* parameters are actually required. |
| 898 |
*/ |
| 899 |
#define BEGINsetModCnf \ |
| 900 |
static rsRetVal setModCnf(struct nvlst *lst) { \ |
| 901 |
DEFiRet; |
| 902 |
|
| 903 |
#define CODESTARTsetModCnf |
| 904 |
|
| 905 |
#define ENDsetModCnf \ |
| 906 |
RETiRet; \ |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
/* endCnfLoad() |
| 911 |
* This is a function tells an input module that the current config load ended. |
| 912 |
* It gets a last chance to make changes to its in-memory config object. After |
| 913 |
* this call, the config object must no longer be changed. |
| 914 |
* The pModConf pointer passed into the module must no longer be used. |
| 915 |
* rgerards, 2011-05-03 |
| 916 |
*/ |
| 917 |
#define BEGINendCnfLoad \ |
| 918 |
static rsRetVal endCnfLoad(modConfData_t *ptr) { \ |
| 919 |
modConfData_t __attribute__((unused)) *pModConf = (modConfData_t *)ptr; \ |
| 920 |
DEFiRet; |
| 921 |
|
| 922 |
#define CODESTARTendCnfLoad |
| 923 |
|
| 924 |
#define ENDendCnfLoad \ |
| 925 |
RETiRet; \ |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
/* checkCnf() |
| 930 |
* Check the provided config object for errors, inconsistencies and other things |
| 931 |
* that do not work out. |
| 932 |
* NOTE: no part of the config must be activated, so some checks that require |
| 933 |
* activation can not be done in this entry point. They must be done in the |
| 934 |
* activateConf() stage, where the caller must also be prepared for error |
| 935 |
* returns. |
| 936 |
* rgerhards, 2011-05-03 |
| 937 |
*/ |
| 938 |
#define BEGINcheckCnf \ |
| 939 |
static rsRetVal checkCnf(modConfData_t *ptr) { \ |
| 940 |
modConfData_t __attribute__((unused)) *pModConf = (modConfData_t *)ptr; \ |
| 941 |
DEFiRet; |
| 942 |
|
| 943 |
#define CODESTARTcheckCnf |
| 944 |
|
| 945 |
#define ENDcheckCnf \ |
| 946 |
RETiRet; \ |
| 947 |
} |
| 948 |
|
| 949 |
/* checkParserInst() - verifies a parser instance configuration */ |
| 950 |
#define BEGINcheckParserInst \ |
| 951 |
static rsRetVal checkParserInst(void *const ptr) { \ |
| 952 |
instanceConf_t __attribute__((unused)) *pInst = (instanceConf_t *)ptr; \ |
| 953 |
DEFiRet; |
| 954 |
|
| 955 |
#define CODESTARTcheckParserInst |
| 956 |
|
| 957 |
#define ENDcheckParserInst \ |
| 958 |
RETiRet; \ |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
/* activateCnfPrePrivDrop() |
| 963 |
* Initial config activation, before dropping privileges. This is an optional |
| 964 |
* entry points that should only be implemented by those module that really need |
| 965 |
* it. Processing should be limited to the minimum possible. Main activation |
| 966 |
* should happen in the normal activateCnf() call. |
| 967 |
* rgerhards, 2011-05-06 |
| 968 |
*/ |
| 969 |
#define BEGINactivateCnfPrePrivDrop \ |
| 970 |
static rsRetVal activateCnfPrePrivDrop(modConfData_t *ptr) { \ |
| 971 |
modConfData_t *pModConf = (modConfData_t *)ptr; \ |
| 972 |
DEFiRet; |
| 973 |
|
| 974 |
#define CODESTARTactivateCnfPrePrivDrop |
| 975 |
|
| 976 |
#define ENDactivateCnfPrePrivDrop \ |
| 977 |
RETiRet; \ |
| 978 |
} |
| 979 |
|
| 980 |
|
| 981 |
/* activateCnf() |
| 982 |
* This activates the provided config, and may report errors if they are detected |
| 983 |
* during activation. |
| 984 |
* rgerhards, 2011-05-03 |
| 985 |
*/ |
| 986 |
#define BEGINactivateCnf \ |
| 987 |
static rsRetVal activateCnf(modConfData_t *ptr) { \ |
| 988 |
modConfData_t __attribute__((unused)) *pModConf = (modConfData_t *)ptr; \ |
| 989 |
DEFiRet; |
| 990 |
|
| 991 |
#define CODESTARTactivateCnf |
| 992 |
|
| 993 |
#define ENDactivateCnf \ |
| 994 |
RETiRet; \ |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
/* freeCnf() |
| 999 |
* This is a function tells an input module that it must free all data |
| 1000 |
* associated with the passed-in module config. |
| 1001 |
* rgerhards, 2011-05-03 |
| 1002 |
*/ |
| 1003 |
#define BEGINfreeCnf \ |
| 1004 |
static rsRetVal freeCnf(void *ptr) { \ |
| 1005 |
modConfData_t *pModConf = (modConfData_t *)ptr; \ |
| 1006 |
DEFiRet; |
| 1007 |
|
| 1008 |
#define CODESTARTfreeCnf |
| 1009 |
|
| 1010 |
#define ENDfreeCnf \ |
| 1011 |
if (pModConf != NULL) free(pModConf); /* we need to free this in any case */ \ |
| 1012 |
RETiRet; \ |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
/* runInput() |
| 1017 |
* This is the main function for input modules. It is used to gather data from the |
| 1018 |
* input source and submit it to the message queue. Each runInput() instance has its own |
| 1019 |
* thread. This is handled by the rsyslog engine. It needs to spawn off new threads only |
| 1020 |
* if there is a module-internal need to do so. |
| 1021 |
*/ |
| 1022 |
#define BEGINrunInput \ |
| 1023 |
static rsRetVal runInput(thrdInfo_t __attribute__((unused)) * pThrd) { \ |
| 1024 |
DEFiRet; |
| 1025 |
|
| 1026 |
#define CODESTARTrunInput dbgSetThrdName((uchar *)__FILE__); /* we need to provide something better later */ |
| 1027 |
|
| 1028 |
#define ENDrunInput \ |
| 1029 |
RETiRet; \ |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
/* willRun() |
| 1034 |
* This is a function that will be replaced in the longer term. It is used so |
| 1035 |
* that a module can tell the caller if it will run or not. This is to be replaced |
| 1036 |
* when we introduce input module instances. However, these require config syntax |
| 1037 |
* changes and I may (or may not... ;)) hold that until another config file |
| 1038 |
* format is available. -- rgerhards, 2007-12-17 |
| 1039 |
* returns RS_RET_NO_RUN if it will not run (RS_RET_OK or error otherwise) |
| 1040 |
*/ |
| 1041 |
#define BEGINwillRun \ |
| 1042 |
static rsRetVal willRun(void) { \ |
| 1043 |
DEFiRet; |
| 1044 |
|
| 1045 |
#define CODESTARTwillRun |
| 1046 |
|
| 1047 |
#define ENDwillRun \ |
| 1048 |
RETiRet; \ |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
/* afterRun() |
| 1053 |
* This function is called after an input module has been run and its thread has |
| 1054 |
* been terminated. It shall do any necessary cleanup. |
| 1055 |
* This is expected to evolve into a freeInstance type of call once the input module |
| 1056 |
* interface evolves to support multiple instances. |
| 1057 |
* rgerhards, 2007-12-17 |
| 1058 |
*/ |
| 1059 |
#define BEGINafterRun \ |
| 1060 |
static rsRetVal afterRun(void) { \ |
| 1061 |
DEFiRet; |
| 1062 |
|
| 1063 |
#define CODESTARTafterRun |
| 1064 |
|
| 1065 |
#define ENDafterRun \ |
| 1066 |
RETiRet; \ |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
/* doHUP() |
| 1071 |
* This function is optional. Currently, it is available to output plugins |
| 1072 |
* only, but may be made available to other types of plugins in the future. |
| 1073 |
* A plugin does not need to define this entry point. If if does, it gets |
| 1074 |
* called when a HUP at the action level is to be done. A plugin should register |
| 1075 |
* this function so that it can close files, connection or other resources |
| 1076 |
* on HUP - if it can be assume the user wanted to do this as a part of HUP |
| 1077 |
* processing. Note that the name "HUP" has historical reasons, it stems back |
| 1078 |
* to the infamous SIGHUP which was sent to restart a syslogd. We still retain |
| 1079 |
* that legacy, but may move this to a different signal. |
| 1080 |
* rgerhards, 2008-10-22 |
| 1081 |
*/ |
| 1082 |
#define CODEqueryEtryPt_doHUP \ |
| 1083 |
if (!strcmp((char *)name, "doHUP")) { \ |
| 1084 |
*pEtryPoint = doHUP; \ |
| 1085 |
} |
| 1086 |
#define BEGINdoHUP \ |
| 1087 |
static rsRetVal doHUP(instanceData __attribute__((unused)) * pData) { \ |
| 1088 |
DEFiRet; |
| 1089 |
|
| 1090 |
#define CODESTARTdoHUP |
| 1091 |
|
| 1092 |
#define ENDdoHUP \ |
| 1093 |
RETiRet; \ |
| 1094 |
} |
| 1095 |
|
| 1096 |
/* doHUPParser() |
| 1097 |
*/ |
| 1098 |
#define CODEqueryEtryPt_doHUPParser \ |
| 1099 |
if (!strcmp((char *)name, "doHUP")) { \ |
| 1100 |
*pEtryPoint = doHUP; \ |
| 1101 |
} |
| 1102 |
#define BEGINdoHUPParser \ |
| 1103 |
static rsRetVal doHUP(instanceConf_t __attribute__((unused)) * pData) { \ |
| 1104 |
DEFiRet; |
| 1105 |
|
| 1106 |
#define CODESTARTdoHUPParser |
| 1107 |
|
| 1108 |
#define ENDdoHUPParser \ |
| 1109 |
RETiRet; \ |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
/* doHUPWrkr() |
| 1114 |
* This is like doHUP(), but on an action worker level. |
| 1115 |
* rgerhards, 2015-03-25 |
| 1116 |
*/ |
| 1117 |
#define CODEqueryEtryPt_doHUPWrkr \ |
| 1118 |
if (!strcmp((char *)name, "doHUPWrkr")) { \ |
| 1119 |
*pEtryPoint = doHUPWrkr; \ |
| 1120 |
} |
| 1121 |
#define BEGINdoHUPWrkr \ |
| 1122 |
static rsRetVal doHUPWrkr(wrkrInstanceData_t __attribute__((unused)) * pWrkrData) { \ |
| 1123 |
DEFiRet; |
| 1124 |
|
| 1125 |
#define CODESTARTdoHUPWrkr |
| 1126 |
|
| 1127 |
#define ENDdoHUPWrkr \ |
| 1128 |
RETiRet; \ |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
/* SetShutdownImmdtPtr() |
| 1133 |
* This function is optional. If defined by an output plugin, it is called |
| 1134 |
* each time the action is invoked to set the "ShutdownImmediate" pointer, |
| 1135 |
* which is used during termination to indicate the action should shutdown |
| 1136 |
* as quickly as possible. |
| 1137 |
*/ |
| 1138 |
#define CODEqueryEtryPt_SetShutdownImmdtPtr \ |
| 1139 |
else if (!strcmp((char *)name, "SetShutdownImmdtPtr")) { \ |
| 1140 |
*pEtryPoint = SetShutdownImmdtPtr; \ |
| 1141 |
} |
| 1142 |
#define BEGINSetShutdownImmdtPtr \ |
| 1143 |
static rsRetVal SetShutdownImmdtPtr(instanceData __attribute__((unused)) * pData, int *pPtr) { \ |
| 1144 |
DEFiRet; |
| 1145 |
|
| 1146 |
#define CODESTARTSetShutdownImmdtPtr |
| 1147 |
|
| 1148 |
#define ENDSetShutdownImmdtPtr \ |
| 1149 |
RETiRet; \ |
| 1150 |
} |
| 1151 |
|
| 1152 |
|
| 1153 |
/* parse() - main entry point of parser modules (v1 config interface) |
| 1154 |
*/ |
| 1155 |
#define BEGINparse \ |
| 1156 |
static rsRetVal parse(smsg_t *pMsg) { \ |
| 1157 |
DEFiRet; |
| 1158 |
|
| 1159 |
#define CODESTARTparse assert(pMsg != NULL); |
| 1160 |
|
| 1161 |
#define ENDparse \ |
| 1162 |
RETiRet; \ |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
/* parse2() - main entry point of parser modules (v2+ config interface) |
| 1167 |
*/ |
| 1168 |
#define BEGINparse2 \ |
| 1169 |
static rsRetVal parse2(instanceConf_t *const pInst, smsg_t *pMsg) { \ |
| 1170 |
DEFiRet; |
| 1171 |
|
| 1172 |
#define CODESTARTparse2 \ |
| 1173 |
assert(pInst != NULL); \ |
| 1174 |
assert(pMsg != NULL); |
| 1175 |
|
| 1176 |
#define ENDparse2 \ |
| 1177 |
RETiRet; \ |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
/* strgen() - main entry point of parser modules |
| 1182 |
* Note that we do NOT use size_t as this permits us to store the |
| 1183 |
* values directly into optimized heap structures. |
| 1184 |
* ppBuf is the buffer pointer |
| 1185 |
* pLenBuf is the current max size of this buffer |
| 1186 |
* pStrLen is an output parameter that MUST hold the length |
| 1187 |
* of the generated string on exit (this is cached) |
| 1188 |
*/ |
| 1189 |
#define BEGINstrgen \ |
| 1190 |
static rsRetVal strgen(smsg_t *const pMsg, actWrkrIParams_t *const iparam) { \ |
| 1191 |
DEFiRet; |
| 1192 |
|
| 1193 |
#define CODESTARTstrgen assert(pMsg != NULL); |
| 1194 |
|
| 1195 |
#define ENDstrgen \ |
| 1196 |
RETiRet; \ |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
/* getFunctArray() - main entry point of parser modules |
| 1201 |
* Note that we do NOT use size_t as this permits us to store the |
| 1202 |
* values directly into optimized heap structures. |
| 1203 |
* ppBuf is the buffer pointer |
| 1204 |
* pLenBuf is the current max size of this buffer |
| 1205 |
* pStrLen is an output parameter that MUST hold the length |
| 1206 |
* of the generated string on exit (this is cached) |
| 1207 |
*/ |
| 1208 |
#define BEGINgetFunctArray \ |
| 1209 |
static rsRetVal getFunctArray(int *const version, const struct scriptFunct **const functArray) { \ |
| 1210 |
DEFiRet; |
| 1211 |
|
| 1212 |
#define CODESTARTgetFunctArray |
| 1213 |
|
| 1214 |
#define ENDgetFunctArray \ |
| 1215 |
RETiRet; \ |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
/* function to specify the parser name. This is done via a single command which |
| 1220 |
* receives a ANSI string as parameter. |
| 1221 |
*/ |
| 1222 |
#define PARSER_NAME(x) \ |
| 1223 |
static rsRetVal GetParserName(uchar **ppSz) { \ |
| 1224 |
*ppSz = UCHAR_CONSTANT(x); \ |
| 1225 |
return RS_RET_OK; \ |
| 1226 |
} |
| 1227 |
|
| 1228 |
|
| 1229 |
/* function to specify the strgen name. This is done via a single command which |
| 1230 |
* receives a ANSI string as parameter. |
| 1231 |
*/ |
| 1232 |
#define STRGEN_NAME(x) \ |
| 1233 |
static rsRetVal GetStrgenName(uchar **ppSz) { \ |
| 1234 |
*ppSz = UCHAR_CONSTANT(x); \ |
| 1235 |
return RS_RET_OK; \ |
| 1236 |
} |
| 1237 |
|
| 1238 |
#endif /* #ifndef MODULE_TEMPLATE_H_INCLUDED */ |