97 lines
2.1 KiB
C
97 lines
2.1 KiB
C
#ifndef LANDERCTL
|
|
#define LANDERCTL
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Convenience wrapper around a CURL object
|
|
*/
|
|
typedef struct landerctl_curl {
|
|
CURL *curl;
|
|
struct curl_slist *headers;
|
|
char err_msg[CURL_ERROR_SIZE];
|
|
} landerctl_curl;
|
|
|
|
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);
|
|
|
|
/**
|
|
* Initialize a CURL object
|
|
*/
|
|
int landerctl_curl_init(landerctl_curl *out);
|
|
|
|
/**
|
|
* Set common configurations for the CURL shared across all commands
|
|
*/
|
|
int landerctl_curl_set_common(landerctl_curl *curl, landerctl_args *args,
|
|
const char *key);
|
|
|
|
/**
|
|
* Execute the HTTP request configured in the CURL object
|
|
*/
|
|
int landerctl_curl_perform(landerctl_curl *curl);
|
|
|
|
/**
|
|
* Inspect the response code and Location header of a successful HTTP request
|
|
*/
|
|
int landerctl_curl_inspect(landerctl_curl *curl, landerctl_args *args);
|
|
|
|
/**
|
|
* Deallocate the CURL object
|
|
*/
|
|
void landerctl_curl_cleanup(landerctl_curl *curl);
|
|
|
|
#endif
|