~ubuntu-branches/ubuntu/lucid/rsyslog/lucid

« back to all changes in this revision

Viewing changes to module-template.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2007-10-19 17:21:49 UTC
  • Revision ID: james.westby@ubuntu.com-20071019172149-ie6ej2xve33mxiu7
Tags: upstream-1.19.10
ImportĀ upstreamĀ versionĀ 1.19.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 Rainer Gerhards and Adiscon GmbH.
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU General Public License
 
11
 * as published by the Free Software Foundation; either version 2
 
12
 * of the License, or (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
 *
 
23
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 
24
 */
 
25
#ifndef MODULE_TEMPLATE_H_INCLUDED
 
26
#define MODULE_TEMPLATE_H_INCLUDED 1
 
27
 
 
28
#include "objomsr.h"
 
29
 
 
30
/* macro to define standard output-module static data members
 
31
 */
 
32
#define DEF_OMOD_STATIC_DATA \
 
33
        static rsRetVal (*omsdRegCFSLineHdlr)();
 
34
 
 
35
/* to following macros are used to generate function headers and standard
 
36
 * functionality. It works as follows (described on the sample case of
 
37
 * createInstance()):
 
38
 *
 
39
 * BEGINcreateInstance
 
40
 * ... custom variable definitions (on stack) ... (if any)
 
41
 * CODESTARTcreateInstance
 
42
 * ... custom code ... (if any)
 
43
 * ENDcreateInstance
 
44
 */
 
45
 
 
46
/* createInstance()
 
47
 */
 
48
#define BEGINcreateInstance \
 
49
static rsRetVal createInstance(instanceData **ppData)\
 
50
        {\
 
51
        DEFiRet; /* store error code here */\
 
52
        instanceData *pData; /* use this to point to data elements */
 
53
 
 
54
#define CODESTARTcreateInstance \
 
55
        if((pData = calloc(1, sizeof(instanceData))) == NULL) {\
 
56
                *ppData = NULL;\
 
57
                return RS_RET_OUT_OF_MEMORY;\
 
58
        }
 
59
 
 
60
#define ENDcreateInstance \
 
61
        *ppData = pData;\
 
62
        return iRet;\
 
63
}
 
64
 
 
65
/* freeInstance()
 
66
 */
 
67
#define BEGINfreeInstance \
 
68
static rsRetVal freeInstance(void* pModData)\
 
69
{\
 
70
        DEFiRet;\
 
71
        instanceData *pData;
 
72
 
 
73
#define CODESTARTfreeInstance \
 
74
        pData = (instanceData*) pModData;
 
75
 
 
76
#define ENDfreeInstance \
 
77
        if(pData != NULL)\
 
78
                free(pData); /* we need to free this in any case */\
 
79
        return iRet;\
 
80
}
 
81
 
 
82
/* isCompatibleWithFeature()
 
83
 */
 
84
#define BEGINisCompatibleWithFeature \
 
85
static rsRetVal isCompatibleWithFeature(syslogFeature __attribute__((unused)) eFeat)\
 
86
{\
 
87
        rsRetVal iRet = RS_RET_INCOMPATIBLE;
 
88
 
 
89
#define CODESTARTisCompatibleWithFeature
 
90
 
 
91
#define ENDisCompatibleWithFeature \
 
92
        return iRet;\
 
93
}
 
94
 
 
95
/* doAction()
 
96
 */
 
97
#define BEGINdoAction \
 
98
static rsRetVal doAction(uchar __attribute__((unused)) **ppString, unsigned __attribute__((unused)) iMsgOpts, instanceData __attribute__((unused)) *pData)\
 
99
{\
 
100
        DEFiRet;
 
101
 
 
102
#define CODESTARTdoAction \
 
103
        /* ppString may be NULL if the output module requested no strings */
 
104
 
 
105
#define ENDdoAction \
 
106
        return iRet;\
 
107
}
 
108
 
 
109
 
 
110
/* dbgPrintInstInfo()
 
111
 * Extra comments:
 
112
 * Print debug information about this instance.
 
113
 */
 
114
#define BEGINdbgPrintInstInfo \
 
115
static rsRetVal dbgPrintInstInfo(void *pModData)\
 
116
{\
 
117
        DEFiRet;\
 
118
        instanceData *pData = NULL;
 
119
 
 
120
#define CODESTARTdbgPrintInstInfo \
 
121
        pData = (instanceData*) pModData;
 
122
 
 
123
#define ENDdbgPrintInstInfo \
 
124
        return iRet;\
 
125
}
 
126
 
 
127
 
 
128
/* needUDPSocket()
 
129
 * Talks back to syslogd if the global UDP syslog socket is needed for
 
130
 * sending. Returns 0 if not, 1 if needed. This interface hopefully goes
 
131
 * away at some time, because it is kind of a hack. However, currently
 
132
 * there is no way around it, so we need to support it.
 
133
 * rgerhards, 2007-07-26
 
134
 */
 
135
#define BEGINneedUDPSocket \
 
136
static rsRetVal needUDPSocket(void *pModData)\
 
137
{\
 
138
        rsRetVal iRet = RS_RET_FALSE;\
 
139
        instanceData *pData = NULL;
 
140
 
 
141
#define CODESTARTneedUDPSocket \
 
142
        pData = (instanceData*) pModData;
 
143
 
 
144
#define ENDneedUDPSocket \
 
145
        return iRet;\
 
146
}
 
147
 
 
148
 
 
149
/* onSelectReadyWrite()
 
150
 * Extra comments:
 
151
 * This is called when select() returned with a writable file descriptor
 
152
 * for this module. The fd was most probably obtained by getWriteFDForSelect()
 
153
 * before.
 
154
 */
 
155
#define BEGINonSelectReadyWrite \
 
156
static rsRetVal onSelectReadyWrite(void *pModData)\
 
157
{\
 
158
        rsRetVal iRet = RS_RET_NONE;\
 
159
        instanceData *pData = NULL;
 
160
 
 
161
#define CODESTARTonSelectReadyWrite \
 
162
        pData = (instanceData*) pModData;
 
163
 
 
164
#define ENDonSelectReadyWrite \
 
165
        return iRet;\
 
166
}
 
167
 
 
168
 
 
169
/* getWriteFDForSelect()
 
170
 * Extra comments:
 
171
 * Gets writefd for select call. Must only be returned when the selector must
 
172
 * be written to. If the module has no such fds, it must return RS_RET_NONE.
 
173
 * In this case, the default implementation is sufficient.
 
174
 * This interface will probably go away over time, but we need it now to
 
175
 * continue modularization.
 
176
 */
 
177
#define BEGINgetWriteFDForSelect \
 
178
static rsRetVal getWriteFDForSelect(void *pModData, short  __attribute__((unused)) *fd)\
 
179
{\
 
180
        rsRetVal iRet = RS_RET_NONE;\
 
181
        instanceData *pData = NULL;
 
182
 
 
183
#define CODESTARTgetWriteFDForSelect \
 
184
        assert(fd != NULL);\
 
185
        pData = (instanceData*) pModData;
 
186
 
 
187
#define ENDgetWriteFDForSelect \
 
188
        return iRet;\
 
189
}
 
190
 
 
191
 
 
192
/* parseSelectorAct()
 
193
 * Extra comments:
 
194
 * try to process a selector action line. Checks if the action
 
195
 * applies to this module and, if so, processed it. If not, it
 
196
 * is left untouched. The driver will then call another module.
 
197
 * On exit, ppModData must point to instance data. Also, a string
 
198
 * request object must be created and filled. A macro is defined
 
199
 * for that.
 
200
 * For the most usual case, we have defined a macro below.
 
201
 * If more than one string is requested, the macro can be used together
 
202
 * with own code that overwrites the entry count. In this case, the
 
203
 * macro must come before the own code. It is recommended to be
 
204
 * placed right after CODESTARTparseSelectorAct.
 
205
 */
 
206
#define BEGINparseSelectorAct \
 
207
static rsRetVal parseSelectorAct(uchar **pp, void **ppModData, omodStringRequest_t **ppOMSR)\
 
208
{\
 
209
        DEFiRet;\
 
210
        uchar *p;\
 
211
        instanceData *pData = NULL;
 
212
 
 
213
#define CODESTARTparseSelectorAct \
 
214
        assert(pp != NULL);\
 
215
        assert(ppModData != NULL);\
 
216
        assert(ppOMSR != NULL);\
 
217
        p = *pp;
 
218
 
 
219
#define CODE_STD_STRING_REQUESTparseSelectorAct(NumStrReqEntries) \
 
220
        CHKiRet(OMSRconstruct(ppOMSR, NumStrReqEntries));
 
221
 
 
222
#define CODE_STD_FINALIZERparseSelectorAct \
 
223
finalize_it:\
 
224
        if(iRet == RS_RET_OK || iRet == RS_RET_SUSPENDED) {\
 
225
                *ppModData = pData;\
 
226
                *pp = p;\
 
227
        } else {\
 
228
                /* cleanup, we failed */\
 
229
                if(*ppOMSR != NULL) {\
 
230
                        OMSRdestruct(*ppOMSR);\
 
231
                        *ppOMSR = NULL;\
 
232
                }\
 
233
                if(pData != NULL)\
 
234
                        freeInstance(&pData);\
 
235
        }
 
236
 
 
237
#define ENDparseSelectorAct \
 
238
        return iRet;\
 
239
}
 
240
 
 
241
 
 
242
/* tryResume()
 
243
 * This entry point is called to check if a module can resume operations. This
 
244
 * happens when a module requested that it be suspended. In suspended state,
 
245
 * the engine periodically tries to resume the module. If that succeeds, normal
 
246
 * processing continues. If not, the module will not be called unless a
 
247
 * tryResume() call succeeds.
 
248
 * Returns RS_RET_OK, if resumption succeeded, RS_RET_SUSPENDED otherwise
 
249
 * rgerhard, 2007-08-02
 
250
 */
 
251
#define BEGINtryResume \
 
252
static rsRetVal tryResume(instanceData __attribute__((unused)) *pData)\
 
253
{\
 
254
        DEFiRet;
 
255
 
 
256
#define CODESTARTtryResume \
 
257
        assert(pData != NULL);
 
258
 
 
259
#define ENDtryResume \
 
260
        return iRet;\
 
261
}
 
262
 
 
263
 
 
264
 
 
265
/* queryEtryPt()
 
266
 */
 
267
#define BEGINqueryEtryPt \
 
268
static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\
 
269
{\
 
270
        DEFiRet;
 
271
 
 
272
#define CODESTARTqueryEtryPt \
 
273
        if((name == NULL) || (pEtryPoint == NULL))\
 
274
                return RS_RET_PARAM_ERROR;\
 
275
        *pEtryPoint = NULL;
 
276
 
 
277
#define ENDqueryEtryPt \
 
278
        if(iRet == RS_RET_OK)\
 
279
                iRet = (*pEtryPoint == NULL) ? RS_RET_NOT_FOUND : RS_RET_OK;\
 
280
        return iRet;\
 
281
}
 
282
 
 
283
/* the following definition is the standard block for queryEtryPt for output
 
284
 * modules. This can be used if no specific handling (e.g. to cover version
 
285
 * differences) is needed.
 
286
 */
 
287
#define CODEqueryEtryPt_STD_OMOD_QUERIES\
 
288
        if(!strcmp((char*) name, "doAction")) {\
 
289
                *pEtryPoint = doAction;\
 
290
        } else if(!strcmp((char*) name, "parseSelectorAct")) {\
 
291
                *pEtryPoint = parseSelectorAct;\
 
292
        } else if(!strcmp((char*) name, "isCompatibleWithFeature")) {\
 
293
                *pEtryPoint = isCompatibleWithFeature;\
 
294
        } else if(!strcmp((char*) name, "dbgPrintInstInfo")) {\
 
295
                *pEtryPoint = dbgPrintInstInfo;\
 
296
        } else if(!strcmp((char*) name, "freeInstance")) {\
 
297
                *pEtryPoint = freeInstance;\
 
298
        } else if(!strcmp((char*) name, "getWriteFDForSelect")) {\
 
299
                *pEtryPoint = getWriteFDForSelect;\
 
300
        } else if(!strcmp((char*) name, "onSelectReadyWrite")) {\
 
301
                *pEtryPoint = onSelectReadyWrite;\
 
302
        } else if(!strcmp((char*) name, "needUDPSocket")) {\
 
303
                *pEtryPoint = needUDPSocket;\
 
304
        } else if(!strcmp((char*) name, "tryResume")) {\
 
305
                *pEtryPoint = tryResume;\
 
306
        }
 
307
 
 
308
/* modInit()
 
309
 * This has an extra parameter, which is the specific name of the modInit
 
310
 * function. That is needed for built-in modules, which must have unique
 
311
 * names in order to link statically.
 
312
 *
 
313
 * Extra Comments:
 
314
 * initialize the module
 
315
 *
 
316
 * Later, much more must be done. So far, we only return a pointer
 
317
 * to the queryEtryPt() function
 
318
 * TODO: do interface version checking & handshaking
 
319
 * iIfVersRequeted is the version of the interface specification that the
 
320
 * caller would like to see being used. ipIFVersProvided is what we
 
321
 * decide to provide.
 
322
 */
 
323
#define BEGINmodInit(uniqName) \
 
324
rsRetVal modInit##uniqName(int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), rsRetVal (*pHostQueryEtryPt)(uchar*, rsRetVal (**)()))\
 
325
{\
 
326
        DEFiRet;
 
327
 
 
328
#define CODESTARTmodInit \
 
329
        assert(pHostQueryEtryPt != NULL);\
 
330
        if((pQueryEtryPt == NULL) || (ipIFVersProvided == NULL))\
 
331
                return RS_RET_PARAM_ERROR;
 
332
 
 
333
#define ENDmodInit \
 
334
finalize_it:\
 
335
        *pQueryEtryPt = queryEtryPt;\
 
336
        return iRet;\
 
337
}
 
338
 
 
339
 
 
340
/* definitions for host API queries */
 
341
#define CODEmodInit_QueryRegCFSLineHdlr \
 
342
        CHKiRet(pHostQueryEtryPt((uchar*)"regCfSysLineHdlr", &omsdRegCFSLineHdlr));
 
343
 
 
344
#endif /* #ifndef MODULE_TEMPLATE_H_INCLUDED */
 
345
/*
 
346
 * vi:set ai:
 
347
 */