#pragma once
#include <inttypes.h>
#include "sd-journal.h"
#include "sd-event.h"
typedef enum {
ENTRY_CURSOR = 0,
ENTRY_REALTIME,
ENTRY_MONOTONIC,
ENTRY_BOOT_ID,
ENTRY_NEW_FIELD,
ENTRY_TEXT_FIELD,
ENTRY_BINARY_FIELD_START,
ENTRY_BINARY_FIELD_SIZE,
ENTRY_BINARY_FIELD,
ENTRY_OUTRO,
ENTRY_DONE,
} entry_state;
typedef struct Uploader {
sd_event *events;
sd_event_source *sigint_event, *sigterm_event;
char *url;
CURL *easy;
bool uploading;
char error[CURL_ERROR_SIZE];
struct curl_slist *header;
char *answer;
sd_event_source *input_event;
uint64_t timeout;
int input;
sd_journal* journal;
entry_state entry_state;
const void *field_data;
size_t field_pos, field_length;
const char *state_file;
size_t entries_sent;
char *last_cursor, *current_cursor;
} Uploader;
#define JOURNAL_UPLOAD_POLL_TIMEOUT (10 * USEC_PER_SEC)
int start_upload(Uploader *u,
size_t (*input_callback)(void *ptr,
size_t size,
size_t nmemb,
void *userdata),
void *data);
int open_journal_for_upload(Uploader *u,
sd_journal *j,
const char *cursor,
bool after_cursor,
bool follow);
void close_journal_input(Uploader *u);
int check_journal_input(Uploader *u);