lander/landerctl/include/landerctl.h

97 lines
2.1 KiB
C
Raw Normal View History

#ifndef LANDERCTL
#define LANDERCTL
#include <stdbool.h>
#include <curl/curl.h>
2024-10-03 10:08:52 +02:00
/**
* Represents a parsed config file
*/
typedef struct landerctl_cfg {
const char *api_key;
const char *server_url;
const char *ca_certs_bundle;
} landerctl_cfg;
typedef enum landerctl_cfg_err {
landerctl_cfg_err_ok = 0,
landerctl_cfg_err_not_found,
landerctl_cfg_err_invalid,
landerctl_cfg_err_incomplete,
} landerctl_cfg_err;
/**
* Try to parse the required config arguments from the config file
*
* @param out config to write values to. Existing values are overwritten
* @param path path to config file
*/
landerctl_cfg_err landerctl_cfg_parse(landerctl_cfg *out, const char *path);
typedef enum landerctl_mode {
landerctl_mode_none = 0,
landerctl_mode_short,
landerctl_mode_paste,
landerctl_mode_file,
landerctl_mode_placeholder,
} landerctl_mode;
2024-10-03 10:08:52 +02:00
/**
* Represents parsed CLI arguments
*/
typedef struct landerctl_args {
bool secure;
bool verbose;
landerctl_cfg cfg;
struct {
char **arr;
int len;
} args;
landerctl_mode mode;
} landerctl_args;
2024-10-03 10:08:52 +02:00
/**
* Convenience wrapper around a CURL object
*/
typedef struct landerctl_curl {
CURL *curl;
struct curl_slist *headers;
char err_msg[CURL_ERROR_SIZE];
} landerctl_curl;
2024-10-03 10:00:44 +02:00
int landerctl_parse_args(landerctl_args *out, int argc, char **argv);
int landerctl_cmd_short(landerctl_args *args);
int landerctl_cmd_paste(landerctl_args *args);
int landerctl_cmd_file(landerctl_args *args);
int landerctl_cmd_placeholder(landerctl_args *args);
2024-10-03 10:00:44 +02:00
2024-10-03 10:08:52 +02:00
/**
* Initialize a CURL object
*/
2024-10-03 10:00:44 +02:00
int landerctl_curl_init(landerctl_curl *out);
2024-10-03 10:08:52 +02:00
/**
* Set common configurations for the CURL shared across all commands
*/
2024-10-03 10:00:44 +02:00
int landerctl_curl_set_common(landerctl_curl *curl, landerctl_args *args,
const char *key);
2024-10-03 10:08:52 +02:00
/**
* Execute the HTTP request configured in the CURL object
*/
2024-10-03 10:00:44 +02:00
int landerctl_curl_perform(landerctl_curl *curl);
2024-10-03 10:08:52 +02:00
/**
* Inspect the response code and Location header of a successful HTTP request
*/
2024-10-03 10:00:44 +02:00
int landerctl_curl_inspect(landerctl_curl *curl, landerctl_args *args);
2024-10-03 10:08:52 +02:00
/**
* Deallocate the CURL object
*/
2024-10-03 10:00:44 +02:00
void landerctl_curl_cleanup(landerctl_curl *curl);
#endif