]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/journal-importer.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / journal-importer.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2016 Zbigniew Jędrzejewski-Szmek
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #pragma once
22
23 #include <stddef.h>
24 #include <stdbool.h>
25 #include <sys/uio.h>
26
27 #include "time-util.h"
28
29 /* Make sure not to make this smaller than the maximum coredump size.
30 * See COREDUMP_MAX in coredump.c */
31 #define ENTRY_SIZE_MAX (1024*1024*770u)
32 #define DATA_SIZE_MAX (1024*1024*768u)
33 #define LINE_CHUNK 8*1024u
34
35 struct iovec_wrapper {
36 struct iovec *iovec;
37 size_t size_bytes;
38 size_t count;
39 };
40
41 size_t iovw_size(struct iovec_wrapper *iovw);
42
43 typedef struct JournalImporter {
44 int fd;
45 bool passive_fd;
46 char *name;
47
48 char *buf;
49 size_t size; /* total size of the buffer */
50 size_t offset; /* offset to the beginning of live data in the buffer */
51 size_t scanned; /* number of bytes since the beginning of data without a newline */
52 size_t filled; /* total number of bytes in the buffer */
53
54 size_t field_len; /* used for binary fields: the field name length */
55 size_t data_size; /* and the size of the binary data chunk being processed */
56
57 struct iovec_wrapper iovw;
58
59 int state;
60 dual_timestamp ts;
61 } JournalImporter;
62
63 void journal_importer_cleanup(JournalImporter *);
64 int journal_importer_process_data(JournalImporter *);
65 int journal_importer_push_data(JournalImporter *, const char *data, size_t size);
66 void journal_importer_drop_iovw(JournalImporter *);
67 bool journal_importer_eof(const JournalImporter *);
68
69 static inline size_t journal_importer_bytes_remaining(const JournalImporter *imp) {
70 return imp->filled;
71 }