summaryrefslogtreecommitdiffstats
path: root/msg.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-03-07 16:10:58 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-03-07 16:10:58 +0000
commit549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec (patch)
treeed166a3d83210c30502825d644f5be40a9624b08 /msg.c
parent1888852c9a59631771efb5975aa51ddb0305ceb2 (diff)
downloadrsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.tar.gz
rsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.tar.xz
rsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.zip
extracted regexp functionality to its own dynamically loadable module
Diffstat (limited to 'msg.c')
-rw-r--r--msg.c69
1 files changed, 43 insertions, 26 deletions
diff --git a/msg.c b/msg.c
index 8e235919..1076feae 100644
--- a/msg.c
+++ b/msg.c
@@ -42,11 +42,13 @@
#include "msg.h"
#include "var.h"
#include "datetime.h"
+#include "regexp.h"
/* static data */
DEFobjStaticHelpers
DEFobjCurrIf(var)
DEFobjCurrIf(datetime)
+DEFobjCurrIf(regexp)
static syslogCODE rs_prioritynames[] =
{
@@ -1765,40 +1767,55 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
if (pTpe->data.field.has_regex != 0) {
if (pTpe->data.field.has_regex == 2)
/* Could not compile regex before! */
- return
- "**NO MATCH** **BAD REGULAR EXPRESSION**";
+ return "**NO MATCH** **BAD REGULAR EXPRESSION**";
- dbgprintf("debug: String to match for regex is: %s\n",
- pRes);
+ dbgprintf("debug: String to match for regex is: %s\n", pRes);
- if (0 != regexec(&pTpe->data.field.re, pRes, nmatch,
- pmatch, 0)) {
- /* we got no match! */
- return "**NO MATCH**";
- } else {
- /* Match! */
- /* I need to malloc pB */
- int iLenBuf;
- char *pB;
+ if(objUse(regexp, "regexp") == RS_RET_OK) {
+ if (0 != regexp.regexec(&pTpe->data.field.re, pRes, nmatch,
+ pmatch, 0)) {
+ /* we got no match! */
+ if (*pbMustBeFreed == 1) {
+ free(pRes);
+ *pbMustBeFreed = 0;
+ }
+ return "**NO MATCH**";
+ } else {
+ /* Match! */
+ /* I need to malloc pB */
+ int iLenBuf;
+ char *pB;
+
+ iLenBuf = pmatch[1].rm_eo - pmatch[1].rm_so;
+ pB = (char *) malloc((iLenBuf + 1) * sizeof(char));
+
+ if (pB == NULL) {
+ if (*pbMustBeFreed == 1)
+ free(pRes);
+ *pbMustBeFreed = 0;
+ return "**OUT OF MEMORY ALLOCATING pBuf**";
+ }
- iLenBuf = pmatch[1].rm_eo - pmatch[1].rm_so;
- pB = (char *) malloc((iLenBuf + 1) * sizeof(char));
+ /* Lets copy the matched substring to the buffer */
+ memcpy(pB, pRes + pmatch[1].rm_so, iLenBuf);
+ pB[iLenBuf] = '\0';/* terminate string, did not happen before */
- if (pB == NULL) {
if (*pbMustBeFreed == 1)
free(pRes);
- *pbMustBeFreed = 0;
- return "**OUT OF MEMORY ALLOCATING pBuf**";
+ pRes = pB;
+ *pbMustBeFreed = 1;
}
-
- /* Lets copy the matched substring to the buffer */
- memcpy(pB, pRes + pmatch[1].rm_so, iLenBuf);
- pB[iLenBuf] = '\0';/* terminate string, did not happen before */
-
- if (*pbMustBeFreed == 1)
+ } else {
+ /* we could not load regular expression support. This is quite unexpected at
+ * this stage of processing (after all, the config parser found it), but so
+ * it is. We return an error in that case. -- rgerhards, 2008-03-07
+ */
+ dbgprintf("could not get regexp object pointer, so regexp can not be evaluated\n");
+ if (*pbMustBeFreed == 1) {
free(pRes);
- pRes = pB;
- *pbMustBeFreed = 1;
+ *pbMustBeFreed = 0;
+ }
+ return "***REGEXP NOT AVAILABLE***";
}
}
#endif /* #ifdef FEATURE_REGEXP */