jsonparser: Throw an error when the JSON input is not an object

syslog-ng assumes that the JSON input the parser receives will be an
object, if it is not, we should throw an error. The most likely case is
a miss-parse, we should not try to be clever there, but fail instead
with a sensible message.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
json-parser: When parsing fails, tag the error with the input

When JSON parsing fails with returning a NULL object, add the original
input to the emitted error message, for easier debugging.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
afprog: Fix the grammar so that program() source works again

The grammar of the afprog module was a bit flaky, which resulted in
program() sources not being recognised, because the grammar couldn't
properly terminate the sentence, and skipped it instead. By refactoring
the grammar into the same style the program() destination uses, the
problem went away. This closes #34.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
misc: fixed truncated IP addresses set in $HOST

In case getnameinfo() fails to resolve an address, it automatically returns
the numeric IP address without setting an error condition, which messes up
the logic in resolve_sockaddr() and causes the IP address to be truncated if
use_fqdn() is set to no.  This patch instructs getnameinfo() to return
failure instead by passing NI_NAMEREQD in flags.

References: bugzilla #240
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogPipe: remove "sender" argument from log_pipe_notify()

This argument was unused anyway and restricted notify invocations from LogPipe
instances.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogReader: removed LogReaderWatch typedef and unused member

This was dead code is the remnants of the change to a multithreaded
architecture, not used anymore.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logreader: remove unneeded log_proto_server_prepare() call from log_reader_init_watches

The results of this call were not needed at all.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogReader: whitespace fix

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logreader: don't rely on the fact that iv_fd was registered to decide polling strategy

I'm trying to set the logic straight that tries to detect how we are polling
the source. Instead of checking iv_fd_registered() on iv_fd, use
pollable_state for that.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logreader: separate log_reader_update_fd_callbacks

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logreader: factor out log_reader_update_follow_timer()

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logreader: added idempotency to _start_watches() and stop_watches()

Logreader now tracks if its I/O watches are running using a boolean
variable.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogReader: introduce the LogReaderPollEvents interface

This is an intermediate step that introduces a LogReader specific private
class to perform I/O polling.  In the subsequent patches this will become
more general so it can be applied by LogWriter instances as well.  This
patch changes the LogReader logic to instantiate the appropriate class at a
single location and rely on LogReaderPollEvents descendants to perform the
work it needs but with a uniform interface.

This patch introduces the abstract base class (LogReaderPollEvents) and two
descendants factored out of LogReader, LogReaderPollFileChanges and
LogReaderPollFd.  The first performing the follow-freq() style time based
polling, the second merely polling the specified fd using poll(2).

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
PollEvents: implement PollEvents abstract class

The new PollEvents class is factored out from LogReader as a generic
interface to implement event polling both in LogReader and LogWriter.

The plan is to have a generic PollFdEvents class to poll for fd I/O events,
and a separate class for file-change polling when using follow-freq().

Other polling methods may become available in the future.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
PollFileChanges: new class, factored out from LogReader

This class factors out PollFileChanges from the logreader module, making it
less tightly coupled with LogReader and indicating this also in the name.
This is right now affile specific as only regular files are polled using a
timer.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
PollFdEvents: factor out from LogReader

This patch factors out LogReaderPollFd as a LogReader independent class into
its separate module as a derived class of PollEvents.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogReader: drop log_reader_start_watches()

Instead of having a separate start_watches() method, make update_watches()
aware if watches are running and react accordingly. Previously both
functions were invoked anyway.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogReader: drop constructor arguments in favour of log_reader_reopen

Instead of passing the LogProtoServer and PollEvents instance in the
constructor, pass those using log_reader_reopen() once the constructor
has finished. This makes LogWriter and LogReader a bit more similar and
provides a single path for passing this data.

This patch also cleans up the previously unused log_reader_reopen()
interface and removes most of the arguments, which should've been
passed to more specialized methods.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
affile: make follow freq completely file source specific

Instead of stuffing the follow-freq parameter to LogReaderOptions, move it
to AFFileSourceDriver where it is actually relevant. This patch also
removes GlobalConfig->follow_freq, which was never set anywhere in the
code.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoServer: remove unused fd argument from prepare

With the recent LogReader/PollEvents split, it is now possible to remove
the fd return argument from LogProtoServer->prepare. This patch
does exactly that.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>