2020-11-09 13:23:58 +09:00
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2020-10-27 18:18:20 +01:00
2014-03-17 22:54:28 -04:00
# pragma once
# include <inttypes.h>
# include "sd-event.h"
2015-11-18 22:46:33 +01:00
# include "sd-journal.h"
2019-11-28 09:14:22 +01:00
2016-04-05 20:27:48 -04:00
# include "time-util.h"
2014-03-17 22:54:28 -04:00
2014-03-29 00:37:25 -04:00
typedef enum {
ENTRY_CURSOR = 0 , /* Nothing actually written yet. */
ENTRY_REALTIME ,
ENTRY_MONOTONIC ,
ENTRY_BOOT_ID ,
ENTRY_NEW_FIELD , /* In between fields. */
ENTRY_TEXT_FIELD , /* In the middle of a text field. */
ENTRY_BINARY_FIELD_START , /* Writing the name of a binary field. */
ENTRY_BINARY_FIELD_SIZE , /* Writing the size of a binary field. */
ENTRY_BINARY_FIELD , /* In the middle of a binary field. */
ENTRY_OUTRO , /* Writing '\n' */
ENTRY_DONE , /* Need to move to a new field. */
} entry_state ;
2014-03-17 22:54:28 -04:00
typedef struct Uploader {
sd_event * events ;
2014-04-01 20:30:13 -04:00
sd_event_source * sigint_event , * sigterm_event ;
2014-03-17 22:54:28 -04:00
2014-07-10 01:39:49 -04:00
char * url ;
2014-03-17 22:54:28 -04:00
CURL * easy ;
bool uploading ;
2014-03-29 00:37:25 -04:00
char error [ CURL_ERROR_SIZE ] ;
2014-03-17 22:54:28 -04:00
struct curl_slist * header ;
2014-03-29 00:37:25 -04:00
char * answer ;
sd_event_source * input_event ;
uint64_t timeout ;
2014-03-17 22:54:28 -04:00
2014-03-29 00:37:25 -04:00
/* fd stuff */
2014-03-17 22:54:28 -04:00
int input ;
2014-03-29 00:37:25 -04:00
/* journal stuff */
sd_journal * journal ;
entry_state entry_state ;
const void * field_data ;
size_t field_pos , field_length ;
/* general metrics */
2014-04-01 09:09:35 -04:00
const char * state_file ;
2014-03-29 00:37:25 -04:00
size_t entries_sent ;
2014-04-01 09:09:35 -04:00
char * last_cursor , * current_cursor ;
2016-04-05 20:27:48 -04:00
usec_t watchdog_timestamp ;
usec_t watchdog_usec ;
2014-03-17 22:54:28 -04:00
} Uploader ;
2014-03-29 00:37:25 -04:00
# define JOURNAL_UPLOAD_POLL_TIMEOUT (10 * USEC_PER_SEC)
2014-03-17 22:54:28 -04:00
int start_upload ( Uploader * u ,
size_t ( * input_callback ) ( void * ptr ,
size_t size ,
size_t nmemb ,
void * userdata ) ,
void * data ) ;
2014-03-29 00:37:25 -04:00
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 ) ;