logthrdestdrv: make the thread ivykis based.

It is easier to add timer, task, event etc. to the threaded destination,
and this re-factorizing eliminates the locking and waiting for conditions.
And the throttle timeout handling is also added to logthreaded destination.

Make this code is more maintainable.

Signed-off-by: Juhász Viktor <viktor.juhasz@balabit.com>
logsource: log_msg_ack() refactored

it calls log_source_flow_control_adjust() which doing
  - flow control rate adjustment and
  - flow control window size adjustment

Signed-off-by: Budai Laszlo <Laszlo.Budai@balabit.com>
proto: implement reader-side late ack mechanism

late ack mechanism:
 - late ack is for position tracking
 - position should be saved only after the LogMessage (corresponding to the
   logline read from the position we want to save) has ACKed

in order to do that:
- proto queued() method removed [before the late-ack era queued() has called
  after the LogMessage forwarded to the LogWriter::queue and this method saved
  the position immediately -> this means that if the message ACK has aborted we
  lost that message]

- fetch() knows the position of the stream where logline read, we just set a
  bookmark for that position

- if the fetched data is a valid log message, a new LogMessage object is
created and the bookmark is bound to that object

- when a positive ACK is received for the LogMessage, bookmark is saved

Decoupling position save from queued() generates a new problem: it is not
guaranteed that the ACKs received in-order (eg.:
  msg1 -> unmatching filter -> the message is processed -> ACKed
  msg0 -> destination -> logqueue -> transport -> ACKed
).

For solving this problem we have to use a Ringbuffer storing AckRecords.
AckRecord = (Bookmark, ack status).
(Number of slots in Ringbuffer is proportional to window size; when window is
full, no new message is received, thus no new Bookmark is needed)

For every incoming message an AckRecord is bound when it is queued to
logsource(log_source_queue() called, this is the point when we know that
the fetched line is a valid logmessage, Bookmark is filled, it is ready for
forwarding to the consumer's queue).

When a continuous range of positive ACK is formed at the head of
the RingBuffer, Bookmark of the AckRecord with the highest position in the
range is saved and the range is dropped from the RingBuffer
(-> the ringbuffer head is reset by range length, window size also increased
by range-length).

Tracking ACKs: AckTracker

Using AckTracker for reliable cases is OK but what about "unreliable" cases
where no position tracking supported? There are two kind of AckTrackers:
a reliable and a non-reliable. Non-reliable AckTracker just not use a
RingBuffer, not saving a Bookmark, of course, and window size increased by 1.

Signed-off-by: Budai Laszlo <Laszlo.Budai@balabit.com>
logproto-text-server: set position tracking flag

Signed-off-by: Budai Laszlo <Laszlo.Budai@balabit.com>
afsocket: Memory leak fix

If the configuration stays the same during a reload, log_reader_set_peer_addr()
is already called and log_reader_set_peer_addr() doesn't unref its previous
peer_addr.

Signed-off-by: Tibor Benke <ihrwein@gmail.com>
logmsg: LMAck signature reduced by removing an uneccessary ack_userdata pointer

LogMsg held a reference to a LogSource instance.
This is not needed when AckTracker is used.

Signed-off-by: Budai Laszlo <Laszlo.Budai@balabit.com>
json: json-c 0.12+ compatibility

In order to be able to build with both json-c 0.9 and 0.12+, we need
some compatibility shims, to replace deprecated functions. This patch
adds just that, surrounded with appropriate ifdefs. Based on a patch by
Balazs Scheidler <bazsi@balabit.hu>; this fixes #153.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Merge branch 'h/json-c-0.12'
Merge pull request #160 from juhaszviktor/logthrdestrefact

logthrdestdrv: make the thread ivykis based.
Merge pull request #166 from ihrwein/f/afsocket-memory-leak-fix

afsocket: Memory leak fix
logwriter: still free the unconsumed item during reloading configuration

Otherwise we have no chance to free this stuff.

Reported-by: Xufeng Zhang <xufeng.zhang@windriver.com>
Signed-off-by: Tusa Viktor <tusavik@gmail.com>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
socket: Various leak fixes in afsocket module.

TransportMapper and SocketOptions structures are not embedded ones, so
they should be freed up, when freeing up drivers.

Reported-by: Xufeng Zhang <xufeng.zhang@windriver.com>
Signed-off-by: Viktor Tusa <tusavik@gmail.com>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Merge pull request #165 from lbudai/f/merge-proto

F/merge proto