emit all protocol properties, not just non-defaults
Added missing error check too.
@@ -2069,20 +2069,10 @@ createProtocolEntryJson(config_t* cfg, protocol_def_t* prot)
if (!cJSON_AddStringToObjLN(root, NAME_NODE, prot->protname)) goto err;
if (!cJSON_AddStringToObjLN(root, REGEX_NODE, prot->regex)) goto err;
-
- // only emit non-defaults
- if (prot->binary) {
- if (!cJSON_AddStringToObjLN(root, BINARY_NODE, "true")) goto err;
- }
- if (prot->binary && prot->len) {
+ if (!cJSON_AddStringToObjLN(root, BINARY_NODE, valToStr(boolMap, prot->binary))) goto err;
if (!cJSON_AddNumberToObjLN(root, LEN_NODE, prot->len)) goto err;
- }
- if (!prot->detect) {
- if (!cJSON_AddStringToObjLN(root, DETECT_NODE, "false")) goto err;
- }
- if (prot->payload) {
- if (!cJSON_AddStringToObjLN(root, PAYLOAD_NODE, "true")) goto err;
- }
+ if (!cJSON_AddStringToObjLN(root, DETECT_NODE, valToStr(boolMap, prot->detect))) goto err;
+ if (!cJSON_AddStringToObjLN(root, PAYLOAD_NODE, valToStr(boolMap, prot->payload))) goto err;
return root;
err:
@@ -2101,6 +2091,7 @@ createProtocolJson(config_t* cfg)
protocol_def_t *prot = lstFind(g_protlist, key);
if (prot) {
cJSON *item = createProtocolEntryJson(cfg, prot);
+ if (!item) goto err;
cJSON_AddItemToArray(root, item);
}
}
