diff options
Diffstat (limited to 'template.h')
-rw-r--r-- | template.h | 56 |
1 files changed, 34 insertions, 22 deletions
@@ -1,7 +1,7 @@ /* This is the header for template processing code of rsyslog. * begun 2004-11-17 rgerhards * - * Copyright 2004-2012 Rainer Gerhards and Adiscon + * Copyright (C) 2004-2012 by Rainer Gerhards and Adiscon GmbH * * This file is part of rsyslog. * @@ -30,6 +30,8 @@ #ifndef TEMPLATE_H_INCLUDED #define TEMPLATE_H_INCLUDED 1 +#include <json/json.h> +#include <libestr.h> #include "regexp.h" #include "stringbuf.h" @@ -37,15 +39,16 @@ struct template { struct template *pNext; char *pszName; int iLenName; - rsRetVal (*pStrgen)(msg_t*, uchar**, size_t *); /* name of strgen to use (bound if non-NULL!) */ + rsRetVal (*pStrgen)(msg_t*, uchar**, size_t *); + es_str_t *subtree; /* subtree name for subtree-type templates */ int tpenElements; /* number of elements in templateEntry list */ struct templateEntry *pEntryRoot; struct templateEntry *pEntryLast; - char optFormatEscape; /* in text fields, 0 - do not escape, - * 1 - escape "the MySQL way" - * 2 - escape quotes by double quotes, - * 3 - escape double quotes for JSON. - */ + char optFormatEscape; /* in text fields, */ +# define NO_ESCAPE 0 /* 0 - do not escape, */ +# define SQL_ESCAPE 1 /* 1 - escape "the MySQL way" */ +# define STDSQL_ESCAPE 2 /* 2 - escape quotes by double quotes, */ +# define JSON_ESCAPE 3 /* 3 - escape double quotes for JSON. */ /* following are options. All are 0/1 defined (either on or off). * we use chars because they are faster than bit fields and smaller * than short... @@ -55,8 +58,11 @@ struct template { enum EntryTypes { UNDEFINED = 0, CONSTANT = 1, FIELD = 2 }; enum tplFormatTypes { tplFmtDefault = 0, tplFmtMySQLDate = 1, tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4, - tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6}; + tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6, tplFmtUnixDate}; enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseConvLower = 2 }; +enum tplRegexType { TPL_REGEX_BRE = 0, /* posix BRE */ + TPL_REGEX_ERE = 1 /* posix ERE */ + }; #include "msg.h" @@ -64,6 +70,8 @@ enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseCo struct templateEntry { struct templateEntry *pNext; enum EntryTypes eEntryType; + uchar *fieldName; /**< field name to be used for structured output */ + int lenFieldName; union { struct { uchar *pConstant; /* pointer to constant value */ @@ -79,11 +87,8 @@ struct templateEntry { short has_regex; short iMatchToUse;/* which match should be obtained (10 max) */ short iSubMatchToUse;/* which submatch should be obtained (10 max) */ - enum { - TPL_REGEX_BRE = 0, /* posix BRE */ - TPL_REGEX_ERE = 1 /* posix ERE */ - } typeRegex; - enum { + enum tplRegexType typeRegex; + enum tlpRegexNoMatchType { TPL_REGEX_NOMATCH_USE_DFLTSTR = 0, /* use the (old style) default "**NO MATCH**" string */ TPL_REGEX_NOMATCH_USE_BLANK = 1, /* use a blank string */ TPL_REGEX_NOMATCH_USE_WHOLE_FIELD = 2, /* use the full field contents that we were searching in*/ @@ -97,6 +102,8 @@ struct templateEntry { int field_expand; /* use multiple instances of the field delimiter as a single one? */ #endif + es_str_t *propName; /**< property name (currently being used for CEE only) */ + enum tplFormatTypes eDateFormat; enum tplFormatCaseConvTypes eCaseConv; struct { /* bit fields! */ @@ -106,8 +113,11 @@ struct templateEntry { unsigned bDropLastLF: 1; /* drop last LF char in msg (PIX!) */ unsigned bSecPathDrop: 1; /* drop slashes, replace dots, empty string */ unsigned bSecPathReplace: 1; /* replace slashes, replace dots, empty string */ - unsigned bSPIffNo1stSP: 1; /* replace slashes, replace dots, empty string */ + unsigned bSPIffNo1stSP: 1; /* be a space if 1st pos if field is no space*/ unsigned bCSV: 1; /* format field in CSV (RFC 4180) format */ + unsigned bJSON: 1; /* format field JSON escaped */ + unsigned bJSONf: 1; /* format field JSON *field* (n/v pair) */ + unsigned bMandatory: 1; /* mandatory field - emit even if empty */ } options; /* options as bit fields */ } field; } data; @@ -123,14 +133,14 @@ ENDinterface(tpl) PROTOTYPEObj(tpl); -struct template* tplConstruct(void); -struct template *tplAddLine(char* pName, unsigned char** pRestOfConfLine); -struct template *tplFind(char *pName, int iLenName); +//struct template* tplConstruct(void); +struct template *tplAddLine(rsconf_t *conf, char* pName, unsigned char** pRestOfConfLine); +struct template *tplFind(rsconf_t *conf, char *pName, int iLenName); int tplGetEntryCount(struct template *pTpl); -void tplDeleteAll(void); -void tplDeleteNew(void); -void tplPrintList(void); -void tplLastStaticInit(struct template *tpl); +void tplDeleteAll(rsconf_t *conf); +void tplDeleteNew(rsconf_t *conf); +void tplPrintList(rsconf_t *conf); +void tplLastStaticInit(rsconf_t *conf, struct template *tpl); rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize); /* note: if a compiler warning for undefined type tells you to look at this * code line below, the actual cause is that you currently MUST include template.h @@ -139,9 +149,11 @@ rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize); */ rsRetVal tplToArray(struct template *pTpl, msg_t *pMsg, uchar*** ppArr); rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar** ppSz, size_t *); -rsRetVal doEscape(uchar **pp, size_t *pLen, unsigned short *pbMustBeFreed, int escapeMode); +rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **); +rsRetVal doEscape(uchar **pp, rs_size_t *pLen, unsigned short *pbMustBeFreed, int escapeMode); rsRetVal templateInit(); +rsRetVal tplProcessCnf(struct cnfobj *o); #endif /* #ifndef TEMPLATE_H_INCLUDED */ /* vim:set ai: |