]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-parse.h
Merge pull request #2495 from heftig/master
[thirdparty/systemd.git] / src / journal-remote / journal-remote-parse.h
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"
23
24 #include "journal-remote-write.h"
25
26 typedef 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
34 typedef struct RemoteSource {
35 char *name;
36 int fd;
37 bool passive_fd;
38
39 char *buf;
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 */
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 */
47
48 struct iovec_wrapper iovw;
49
50 source_state state;
51 dual_timestamp ts;
52
53 Writer *writer;
54
55 sd_event_source *event;
56 sd_event_source *buffer_event;
57 } RemoteSource;
58
59 RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer);
60
61 static inline size_t source_non_empty(RemoteSource *source) {
62 assert(source);
63
64 return source->filled;
65 }
66
67 void source_free(RemoteSource *source);
68 int push_data(RemoteSource *source, const char *data, size_t size);
69 int process_source(RemoteSource *source, bool compress, bool seal);