]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-upload.h
Merge pull request #31648 from neighbourhoodie/review-content
[thirdparty/systemd.git] / src / journal-remote / journal-upload.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #pragma once
4
5 #include <inttypes.h>
6
7 #include "sd-event.h"
8 #include "sd-journal.h"
9
10 #include "time-util.h"
11
12 typedef enum {
13 ENTRY_CURSOR = 0, /* Nothing actually written yet. */
14 ENTRY_REALTIME,
15 ENTRY_MONOTONIC,
16 ENTRY_BOOT_ID,
17 ENTRY_NEW_FIELD, /* In between fields. */
18 ENTRY_TEXT_FIELD, /* In the middle of a text field. */
19 ENTRY_BINARY_FIELD_START, /* Writing the name of a binary field. */
20 ENTRY_BINARY_FIELD_SIZE, /* Writing the size of a binary field. */
21 ENTRY_BINARY_FIELD, /* In the middle of a binary field. */
22 ENTRY_OUTRO, /* Writing '\n' */
23 ENTRY_DONE, /* Need to move to a new field. */
24 } entry_state;
25
26 typedef struct Uploader {
27 sd_event *event;
28
29 char *url;
30 CURL *easy;
31 bool uploading;
32 char error[CURL_ERROR_SIZE];
33 struct curl_slist *header;
34 char *answer;
35
36 sd_event_source *input_event;
37 uint64_t timeout;
38
39 /* fd stuff */
40 int input;
41
42 /* journal stuff */
43 sd_journal* journal;
44
45 entry_state entry_state;
46 const void *field_data;
47 size_t field_pos, field_length;
48
49 /* general metrics */
50 const char *state_file;
51
52 size_t entries_sent;
53 char *last_cursor, *current_cursor;
54 usec_t watchdog_timestamp;
55 usec_t watchdog_usec;
56 } Uploader;
57
58 #define JOURNAL_UPLOAD_POLL_TIMEOUT (10 * USEC_PER_SEC)
59
60 int start_upload(Uploader *u,
61 size_t (*input_callback)(void *ptr,
62 size_t size,
63 size_t nmemb,
64 void *userdata),
65 void *data);
66
67 int open_journal_for_upload(Uploader *u,
68 sd_journal *j,
69 const char *cursor,
70 bool after_cursor,
71 bool follow);
72 void close_journal_input(Uploader *u);
73 int check_journal_input(Uploader *u);