balabit/syslog-ng-3.4 — pull request #19 by algernon (2012-10-13 17:05:40+00:00)
Title: json-format: Unbreak $(format-json)

The $(format-json) template function was misbehaving under certain
conditions, namely where we had a sub-object, a simple value, and
another object starting right after: in this case, no comma was placed
between the simple value and the name of the new sub-object.

The fix changes how comma placement is done completely: it is no
longer a mix of prefix_data & user_data magic, but all state is kept
in the user data, with the _obj_start(), _obj_end() and _value()
functions setting it as appropriate:

- When starting a new object, if we need a comma, we'll put one, and
turn the comma flag off (the first item within an object won't need
a comma).
- When ending an object, we never add a comma, but the next item will
need the comma flag set.
- When adding a value, if the comma flag is set, we add one, and in
the end, set the flag ourselves, as the next one will need a comma
too.

This is much simpler than the previous hackery, and also results in
correct JSON in every situation.

Signed-off-by: Gergely Nagy