feat(landerctl): implement placeholder requests

feature/50-one-time-keys
Jef Roosens 2024-10-03 10:18:57 +02:00
parent b833d0ed74
commit bdbc750f7f
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
5 changed files with 39 additions and 1 deletions

View File

@ -34,6 +34,7 @@ typedef enum landerctl_mode {
landerctl_mode_short,
landerctl_mode_paste,
landerctl_mode_file,
landerctl_mode_placeholder,
} landerctl_mode;
/**
@ -64,6 +65,7 @@ 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

View File

@ -55,7 +55,7 @@ int landerctl_parse_args(landerctl_args *args, int argc, char **argv) {
const char *cfg_path = NULL;
while ((c = getopt(argc, argv, "SPFsvc:")) != -1) {
while ((c = getopt(argc, argv, "SPFHsvc:")) != -1) {
switch (c) {
case 'S':
args->mode = landerctl_mode_short;
@ -66,6 +66,9 @@ int landerctl_parse_args(landerctl_args *args, int argc, char **argv) {
case 'F':
args->mode = landerctl_mode_file;
break;
case 'H':
args->mode = landerctl_mode_placeholder;
break;
case 's':
args->secure = true;
break;

View File

@ -145,3 +145,30 @@ int landerctl_cmd_file(landerctl_args *args) {
return res;
}
int landerctl_cmd_placeholder(landerctl_args *args) {
// TODO argument count check
int res;
landerctl_curl curl;
if ((res = landerctl_curl_init(&curl))) {
return res;
}
const char *key = args->args.arr[0];
if ((res = landerctl_curl_set_common(&curl, args, key))) {
return res;
}
curl_easy_setopt(curl.curl, CURLOPT_POST, 1L);
res = landerctl_curl_perform(&curl);
if (res == 0) {
landerctl_curl_inspect(&curl, args);
}
landerctl_curl_cleanup(&curl);
return res;
}

View File

@ -43,6 +43,9 @@ int landerctl_curl_set_common(landerctl_curl *curl, landerctl_args *args,
case landerctl_mode_file:
mode_char = 'f';
break;
case landerctl_mode_placeholder:
mode_char = 'h';
break;
// Shouldn't be able to happen
default:
return 10;

View File

@ -25,6 +25,9 @@ int main(int argc, char **argv) {
case landerctl_mode_file:
res = landerctl_cmd_file(&args);
break;
case landerctl_mode_placeholder:
res = landerctl_cmd_placeholder(&args);
break;
default:
res = 7;
break;