journal-remote-parse.h revision 09d801a82a46df518dd752e40bf13ac404daa2ce
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/***
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2014 Zbigniew Jędrzejewski-Szmek
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering***/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#pragma once
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "sd-event.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "journal-remote-write.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringtypedef enum {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering STATE_LINE = 0, /* waiting to read, or reading line */
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering STATE_DATA_START, /* reading binary data header */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering STATE_DATA, /* reading binary data */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering STATE_DATA_FINISH, /* expecting newline */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering STATE_EOF, /* done */
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering} source_state;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringtypedef struct RemoteSource {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering char *name;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int fd;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering bool passive_fd;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char *buf;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering size_t size; /* total size of the buffer */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering size_t offset; /* offset to the beginning of live data in the buffer */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering size_t scanned; /* number of bytes since the beginning of data without a newline */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering size_t filled; /* total number of bytes in the buffer */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering size_t field_len; /* used for binary fields: the field name length */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering size_t data_size; /* and the size of the binary data chunk being processed */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
d3e84ddb885e9d5f0ae9930eb905910e3a81f157Lennart Poettering struct iovec_wrapper iovw;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
d3e84ddb885e9d5f0ae9930eb905910e3a81f157Lennart Poettering source_state state;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering dual_timestamp ts;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Writer *writer;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
afc6adb5ec7e73bc13156c43f52fb015cd80cc68Lennart Poettering sd_event_source *event;
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering} RemoteSource;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart PoetteringRemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic inline size_t source_non_empty(RemoteSource *source) {
cde93897cdefdd7c7f66c400a61e42ceee5f6a46Lennart Poettering assert(source);
cde93897cdefdd7c7f66c400a61e42ceee5f6a46Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return source->filled;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringvoid source_free(RemoteSource *source);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint process_data(RemoteSource *source);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint push_data(RemoteSource *source, const char *data, size_t size);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint process_source(RemoteSource *source, bool compress, bool seal);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering