]> git.proxmox.com Git - systemd.git/blame - src/journal-remote/journal-remote-parse.h
Merge tag 'upstream/229'
[systemd.git] / src / journal-remote / journal-remote-parse.h
CommitLineData
60f067b4
JS
1/***
2 This file is part of systemd.
3
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
20#pragma once
21
22#include "sd-event.h"
4c89c718 23
60f067b4
JS
24#include "journal-remote-write.h"
25
26typedef enum {
27 STATE_LINE = 0, /* waiting to read, or reading line */
28 STATE_DATA_START, /* reading binary data header */
29 STATE_DATA, /* reading binary data */
30 STATE_DATA_FINISH, /* expecting newline */
31 STATE_EOF, /* done */
32} source_state;
33
34typedef struct RemoteSource {
5eef597e 35 char *name;
60f067b4 36 int fd;
5eef597e 37 bool passive_fd;
60f067b4
JS
38
39 char *buf;
5eef597e
MP
40 size_t size; /* total size of the buffer */
41 size_t offset; /* offset to the beginning of live data in the buffer */
42 size_t scanned; /* number of bytes since the beginning of data without a newline */
43 size_t filled; /* total number of bytes in the buffer */
e3bff60a
MP
44
45 size_t field_len; /* used for binary fields: the field name length */
46 size_t data_size; /* and the size of the binary data chunk being processed */
60f067b4
JS
47
48 struct iovec_wrapper iovw;
49
50 source_state state;
51 dual_timestamp ts;
52
5eef597e
MP
53 Writer *writer;
54
60f067b4 55 sd_event_source *event;
e3bff60a 56 sd_event_source *buffer_event;
60f067b4
JS
57} RemoteSource;
58
5eef597e
MP
59RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer);
60
61static inline size_t source_non_empty(RemoteSource *source) {
60f067b4
JS
62 assert(source);
63
5eef597e 64 return source->filled;
60f067b4
JS
65}
66
67void source_free(RemoteSource *source);
60f067b4 68int push_data(RemoteSource *source, const char *data, size_t size);
5eef597e 69int process_source(RemoteSource *source, bool compress, bool seal);