2
* send all output to stdout - this is primarily a test driver (but may
3
* be used for weired use cases). Not tested for robustness!
5
* NOTE: read comments in module-template.h for more specifics!
7
* File begun on 2009-03-19 by RGerhards
9
* Copyright 2009 Rainer Gerhards and Adiscon GmbH.
11
* This file is part of rsyslog.
13
* Rsyslog is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
18
* Rsyslog is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
26
* A copy of the GPL can be found in the file "COPYING" in this distribution.
39
#include "syslogd-types.h"
42
#include "module-template.h"
44
#include "cfsysline.h"
48
/* internal structures
52
/* config variables */
53
static int bUseArrayInterface; /* shall action use array instead of string template interface? */
56
typedef struct _instanceData {
57
int bUseArrayInterface; /* uses action use array instead of string template interface? */
61
CODESTARTcreateInstance
65
BEGINisCompatibleWithFeature
66
CODESTARTisCompatibleWithFeature
67
if(eFeat == sFEATURERepeatedMsgReduction)
69
ENDisCompatibleWithFeature
78
CODESTARTdbgPrintInstInfo
94
if(pData->bUseArrayInterface) {
95
/* if we use array passing, we need to put together a string
96
* ourselves. At this point, please keep in mind that omstdout is
97
* primarily a testing aid. Other modules may do different processing
98
* if they would like to support downlevel versions which do not support
99
* array-passing, but also use that interface on cores who do...
100
* So this code here is also more or less an example of how to do that.
101
* rgerhards, 2009-04-03
103
szParams = (char**) (ppString[0]);
104
/* In array-passing mode, ppString[] contains a NULL-terminated array
109
while(szParams[iParam] != NULL) {
111
szBuf[iBuf++] = ','; /* all but first need a delimiter */
113
while(szParams[iParam][iParamVal] != '\0' && iBuf < sizeof(szBuf)) {
114
szBuf[iBuf++] = szParams[iParam][iParamVal++];
121
toWrite = (char*) ppString[0];
123
write(1, toWrite, strlen(toWrite)); /* 1 is stdout! */
127
BEGINparseSelectorAct
129
CODESTARTparseSelectorAct
130
CODE_STD_STRING_REQUESTparseSelectorAct(1)
131
/* first check if this config line is actually for us */
132
if(strncmp((char*) p, ":omstdout:", sizeof(":omstdout:") - 1)) {
133
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
136
/* ok, if we reach this point, we have something for us */
137
p += sizeof(":omstdout:") - 1; /* eat indicator sequence (-1 because of '\0'!) */
138
CHKiRet(createInstance(&pData));
140
/* check if a non-standard template is to be applied */
143
iTplOpts = (bUseArrayInterface == 0) ? 0 : OMSR_TPL_AS_ARRAY;
144
CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, iTplOpts, (uchar*) "RSYSLOG_FileFormat"));
145
pData->bUseArrayInterface = bUseArrayInterface;
146
CODE_STD_FINALIZERparseSelectorAct
157
CODEqueryEtryPt_STD_OMOD_QUERIES
162
/* Reset config variables for this module to default values.
164
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
167
bUseArrayInterface = 0;
174
rsRetVal (*pomsrGetSupportedTplOpts)(unsigned long *pOpts);
176
int bArrayPassingSupported; /* does core support template passing as an array? */
178
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
179
CODEmodInit_QueryRegCFSLineHdlr
180
/* check if the rsyslog core supports parameter passing code */
181
bArrayPassingSupported = 0;
182
localRet = pHostQueryEtryPt((uchar*)"OMSRgetSupportedTplOpts", &pomsrGetSupportedTplOpts);
183
if(localRet == RS_RET_OK) {
184
/* found entry point, so let's see if core supports array passing */
185
CHKiRet((*pomsrGetSupportedTplOpts)(&opts));
186
if(opts & OMSR_TPL_AS_ARRAY)
187
bArrayPassingSupported = 1;
188
} else if(localRet != RS_RET_ENTRY_POINT_NOT_FOUND) {
189
ABORT_FINALIZE(localRet); /* Something else went wrong, what is not acceptable */
191
DBGPRINTF("omstdout: array-passing is %ssupported by rsyslog core.\n", bArrayPassingSupported ? "" : "not ");
193
if(bArrayPassingSupported) {
194
/* enable config comand only if core supports it */
195
CHKiRet(omsdRegCFSLineHdlr((uchar *)"actionomstdoutarrayinterface", 0, eCmdHdlrBinary, NULL,
196
&bUseArrayInterface, STD_LOADABLE_MODULE_ID));
198
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
199
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));