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