diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-08-29 16:00:20 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-08-29 16:00:20 +0200 |
commit | d18a93e943b4552890a0e603b9fc7db5a6fd7761 (patch) | |
tree | cc52a522acb81040fcc121ba6c82a9aaa6ae34b0 | |
parent | a5e51ced933cb73bd3755bffb81aceceb3f0f953 (diff) | |
download | rsyslog-d18a93e943b4552890a0e603b9fc7db5a6fd7761.tar.gz rsyslog-d18a93e943b4552890a0e603b9fc7db5a6fd7761.tar.xz rsyslog-d18a93e943b4552890a0e603b9fc7db5a6fd7761.zip |
default outname for $!<property> is now without $! prefix
also some type cleanup and simplification
-rw-r--r-- | doc/property_replacer.html | 6 | ||||
-rw-r--r-- | runtime/msg.c | 4 | ||||
-rw-r--r-- | template.c | 60 | ||||
-rw-r--r-- | template.h | 3 |
4 files changed, 42 insertions, 31 deletions
diff --git a/doc/property_replacer.html b/doc/property_replacer.html index c6464a3b..943c4f73 100644 --- a/doc/property_replacer.html +++ b/doc/property_replacer.html @@ -345,7 +345,11 @@ Currently, the following options are defined: <tr> <td><b>Outname</b></td> <td>This field permits to specify a field name for structured-data emitting property replacer options. -If used for a constant a template with line style, unpredictable behaviour can occur.</td> +It is most useful to set, for example, the name for JSON-based fields (like used in ommngodb). For +text-based modules, it is simply ignored. +If not specified, the original property name is used, with the exception of properties starting with +"$!", where that prefix is removed. Note that unnamaned constants are NOT forwarded to output modules +that expect structure (like ommnogodb). To pass constants, an outname must be set. </tr> <tr> <td><b>CaseConversion</b></td> diff --git a/runtime/msg.c b/runtime/msg.c index 6725203c..187f0c22 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -2577,9 +2577,9 @@ jsonField(struct templateEntry *pTpe, uchar **ppRes, unsigned short *pbMustBeFre pSrc = *ppRes; buflen = (*pBufLen == -1) ? ustrlen(pSrc) : *pBufLen; /* we hope we have only few escapes... */ - dst = es_newStr(buflen+es_strlen(pTpe->fieldName)+15); + dst = es_newStr(buflen+pTpe->lenFieldName+15); es_addChar(&dst, '"'); - es_addStr(&dst, pTpe->fieldName); + es_addBuf(&dst, (char*)pTpe->fieldName, pTpe->lenFieldName); es_addBufConstcstr(&dst, "\":\""); CHKiRet(jsonAddVal(pSrc, buflen, &dst)); es_addChar(&dst, '"'); @@ -279,7 +279,6 @@ finalize_it: rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjson) { struct templateEntry *pTpe; - char *cstr; size_t propLen; unsigned short bMustBeFreed; uchar *pVal; @@ -304,10 +303,7 @@ rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjso free(pVal); } } - /* TODO: unify strings, handling currently quite inefficient! */ - cstr = es_str2cstr(pTpe->fieldName, NULL); - json_object_object_add(json, cstr, jsonf); - free(cstr); + json_object_object_add(json, (char*)pTpe->fieldName, jsonf); } *pjson = (iRet == RS_RET_OK) ? json : NULL; @@ -1022,17 +1018,21 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) /* save field name - if none was given, use the property name instead */ if(pStrField == NULL) { - if((pTpe->fieldName = - es_newStrFromCStr((char*)cstrGetSzStrNoNULL(pStrProp), cstrLen(pStrProp))) == NULL) { - return 1; + if(pTpe->data.field.propid == PROP_CEE) { + /* in CEE case, we remove "$!" from the fieldname - it's just our indicator */ + pTpe->fieldName = ustrdup(cstrGetSzStrNoNULL(pStrProp)+2); + pTpe->lenFieldName = cstrLen(pStrProp)-2; + } else { + pTpe->fieldName = ustrdup(cstrGetSzStrNoNULL(pStrProp)); + pTpe->lenFieldName = cstrLen(pStrProp); } } else { - if((pTpe->fieldName = - es_newStrFromCStr((char*)cstrGetSzStrNoNULL(pStrField), cstrLen(pStrField))) == NULL) { - return 1; - } + pTpe->fieldName = ustrdup(cstrGetSzStrNoNULL(pStrField)); + pTpe->lenFieldName = cstrLen(pStrProp); cstrDestruct(&pStrField); } + if(pTpe->fieldName == NULL) + return 1; cstrDestruct(&pStrProp); @@ -1235,7 +1235,7 @@ createConstantTpe(struct template *pTpl, struct cnfobj *o) es_str_t *value; int i; struct cnfparamvals *pvals; - es_str_t *outname = NULL; + uchar *outname = NULL; DEFiRet; /* pull params */ @@ -1248,7 +1248,7 @@ createConstantTpe(struct template *pTpl, struct cnfobj *o) if(!strcmp(pblkConstant.descr[i].name, "value")) { value = pvals[i].val.d.estr; } else if(!strcmp(pblkConstant.descr[i].name, "outname")) { - outname = es_strdup(pvals[i].val.d.estr); + outname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else { dbgprintf("template:constantTpe: program error, non-handled " "param '%s'\n", pblkConstant.descr[i].name); @@ -1262,6 +1262,8 @@ createConstantTpe(struct template *pTpl, struct cnfobj *o) es_unescapeStr(value); pTpe->eEntryType = CONSTANT; pTpe->fieldName = outname; + if(outname != NULL) + pTpe->lenFieldName = ustrlen(outname); pTpe->data.constant.iLenConstant = es_strlen(value); pTpe->data.constant.pConstant = (uchar*)es_str2cstr(value, NULL); @@ -1274,8 +1276,7 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o) { struct templateEntry *pTpe; cstr_t *name; - es_str_t *estrname; - es_str_t *outname = NULL; + uchar *outname = NULL; int i; int droplastlf = 0; int spifno1stsp = 0; @@ -1304,16 +1305,15 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o) if(!pvals[i].bUsed) continue; if(!strcmp(pblkProperty.descr[i].name, "name")) { - estrname = es_strdup(pvals[i].val.d.estr); - /* TODO: unify strings!!! */ rsCStrConstructFromszStr(&name, (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL)); + cstrFinalize(name); } else if(!strcmp(pblkProperty.descr[i].name, "droplastlf")) { droplastlf = pvals[i].val.d.n; } else if(!strcmp(pblkProperty.descr[i].name, "spifno1stsp")) { spifno1stsp = pvals[i].val.d.n; } else if(!strcmp(pblkProperty.descr[i].name, "outname")) { - outname = es_strdup(pvals[i].val.d.estr); + outname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else if(!strcmp(pblkProperty.descr[i].name, "position.from")) { frompos = pvals[i].val.d.n; } else if(!strcmp(pblkProperty.descr[i].name, "position.to")) { @@ -1435,8 +1435,14 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o) "param '%s'\n", pblkProperty.descr[i].name); } } - if(outname == NULL) - outname = es_strdup(estrname); + if(outname == NULL) { + uchar *psz = cstrGetSzStrNoNULL(name); + /* we need to drop "$!" prefix, if present */ + if(!strncmp((char*)psz, "$!", 2)) + outname = ustrdup(psz + 2); + else + outname = ustrdup(psz); + } /* sanity check */ if(topos == -1 && frompos != -1) @@ -1460,9 +1466,8 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o) CHKiRet(propNameToID(name, &pTpe->data.field.propid)); if(pTpe->data.field.propid == PROP_CEE) { /* in CEE case, we need to preserve the actual property name */ - pTpe->data.field.propName = estrname; - } else { - es_deleteStr(estrname); + pTpe->data.field.propName = es_newStrFromCStr((char*)cstrGetSzStrNoNULL(name)+2, + cstrLen(name)-2); } pTpe->data.field.options.bDropLastLF = droplastlf; pTpe->data.field.options.bSPIffNo1stSP = spifno1stsp; @@ -1506,7 +1511,9 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o) pTpe->data.field.options.bSecPathReplace = 1; break; } - pTpe->fieldName = outname; + pTpe->fieldName = ustrdup(outname); + if(outname != NULL) + pTpe->lenFieldName = ustrlen(outname); pTpe->data.field.eDateFormat = datefmt; if(fieldnum != -1) { pTpe->data.field.has_fields = 1; @@ -1807,11 +1814,10 @@ void tplDeleteAll(rsconf_t *conf) } if(pTpeDel->data.field.propName != NULL) es_deleteStr(pTpeDel->data.field.propName); - if(pTpeDel->fieldName != NULL) - es_deleteStr(pTpeDel->fieldName); #endif break; } + free(pTpeDel->fieldName); /*dbgprintf("\n");*/ free(pTpeDel); } @@ -68,7 +68,8 @@ enum tplRegexType { TPL_REGEX_BRE = 0, /* posix BRE */ struct templateEntry { struct templateEntry *pNext; enum EntryTypes eEntryType; - es_str_t *fieldName; /**< field name to be used for structured output */ + uchar *fieldName; /**< field name to be used for structured output */ + int lenFieldName; union { struct { uchar *pConstant; /* pointer to constant value */ |