Debian Codegraph @

runtime/objomsr.c

raw
1 /* objomsr.c
2 * Implementation of the omsr (omodStringRequest) object.
3 *
4 * File begun on 2007-07-27 by RGerhards
5 *
6 * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH.
7 *
8 * This file is part of the rsyslog runtime library.
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 * -or-
16 * see COPYING.ASL20 in the source distribution
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <assert.h>
29 #include <string.h>
30
31 #include "rsyslog.h"
32 #include "objomsr.h"
33
34
35 /* destructor
36 */
37 rsRetVal OMSRdestruct(omodStringRequest_t *pThis) {
38 int i;
39
40 assert(pThis != NULL);
41 /* free the strings */
42 if (pThis->ppTplName != NULL) {
43 for (i = 0; i < pThis->iNumEntries; ++i) {
44 free(pThis->ppTplName[i]);
45 }
46 free(pThis->ppTplName);
47 }
48 if (pThis->piTplOpts != NULL) free(pThis->piTplOpts);
49 free(pThis);
50
51 return RS_RET_OK;
52 }
53
54
55 /* constructor
56 */
57 rsRetVal OMSRconstruct(omodStringRequest_t **ppThis, int iNumEntries) {
58 omodStringRequest_t *pThis = NULL;
59 DEFiRet;
60
61 assert(ppThis != NULL);
62 assert(iNumEntries >= 0);
63 if (iNumEntries > CONF_OMOD_NUMSTRINGS_MAXSIZE) {
64 ABORT_FINALIZE(RS_RET_MAX_OMSR_REACHED);
65 }
66 CHKmalloc(pThis = calloc(1, sizeof(omodStringRequest_t)));
67
68 /* got the structure, so fill it */
69 if (iNumEntries > 0) {
70 pThis->iNumEntries = iNumEntries;
71 /* allocate string for template name array. The individual strings will be
72 * allocated as the code progresses (we do not yet know the string sizes)
73 */
74 CHKmalloc(pThis->ppTplName = calloc(iNumEntries, sizeof(uchar *)));
75
76 /* allocate the template options array. */
77 CHKmalloc(pThis->piTplOpts = calloc(iNumEntries, sizeof(int)));
78 }
79
80 finalize_it:
81 if (iRet != RS_RET_OK) {
82 if (pThis != NULL) {
83 OMSRdestruct(pThis);
84 pThis = NULL;
85 }
86 }
87 *ppThis = pThis;
88 RETiRet;
89 }
90
91 /* set a template name and option to the object. Index must be given. The pTplName must be
92 * pointing to memory that can be freed. If in doubt, the caller must strdup() the value.
93 */
94 rsRetVal OMSRsetEntry(omodStringRequest_t *pThis, int iEntry, uchar *pTplName, int iTplOpts) {
95 assert(pThis != NULL);
96 assert(iEntry < pThis->iNumEntries);
97
98 if (pThis->ppTplName[iEntry] != NULL) free(pThis->ppTplName[iEntry]);
99 pThis->ppTplName[iEntry] = pTplName;
100 pThis->piTplOpts[iEntry] = iTplOpts;
101
102 return RS_RET_OK;
103 }
104
105
106 /* get number of entries for this object
107 */
108 int OMSRgetEntryCount(omodStringRequest_t *pThis) {
109 assert(pThis != NULL);
110 return pThis->iNumEntries;
111 }
112
113
114 /* return data for a specific entry. All data returned is
115 * read-only and lasts only as long as the object lives. If the caller
116 * needs it for an extended period of time, the caller must copy the
117 * strings. Please note that the string pointer may be NULL, which is the
118 * case when it was never set.
119 */
120 int OMSRgetEntry(omodStringRequest_t *pThis, int iEntry, uchar **ppTplName, int *piTplOpts) {
121 assert(pThis != NULL);
122 assert(ppTplName != NULL);
123 assert(piTplOpts != NULL);
124 assert(iEntry < pThis->iNumEntries);
125
126 *ppTplName = pThis->ppTplName[iEntry];
127 *piTplOpts = pThis->piTplOpts[iEntry];
128
129 return RS_RET_OK;
130 }
131
132
133 /* return the full set of template options that are supported by this version of
134 * OMSR. They are returned in an unsigned long value. The caller can mask that
135 * value to check on the option he is interested in.
136 * Note that this interface was added in 4.1.6, so a plugin must obtain a pointer
137 * to this interface via queryHostEtryPt().
138 * rgerhards, 2009-04-03
139 */
140 rsRetVal OMSRgetSupportedTplOpts(unsigned long *pOpts) {
141 DEFiRet;
142 assert(pOpts != NULL);
143 *pOpts = OMSR_RQD_TPL_OPT_SQL | OMSR_TPL_AS_ARRAY | OMSR_TPL_AS_MSG | OMSR_TPL_AS_JSON;
144 RETiRet;
145 }
146
147 /* vim:set ai:
148 */