This commit is contained in:
qorg11 2021-02-22 16:56:57 +01:00
parent 8c9529a7ba
commit 7f88127116
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 42 additions and 28 deletions

View File

@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <curl/curl.h>
#include <stdbool.h> #include <stdbool.h>
#include <errno.h>
#include <getopt.h>
#include <unistd.h>
#include <curl/curl.h>
#include "options.h" #include "options.h"
#include "clainsafecli.h" #include "clainsafecli.h"
@ -129,6 +129,11 @@ main(int argc, char **argv)
/* Form parameters */ /* Form parameters */
/* File name */ /* File name */
/* TODO: make it iterate on args so you can upload multiple files
* at once (clainsafecli file1 file2 ... filen)
*/
curl_formadd(&post,&last, curl_formadd(&post,&last,
CURLFORM_COPYNAME,"file", CURLFORM_COPYNAME,"file",
CURLFORM_FILE,argv[optind], CURLFORM_FILE,argv[optind],
@ -153,6 +158,7 @@ main(int argc, char **argv)
curl_easy_perform(easy_handle); curl_easy_perform(easy_handle);
if(!silent_flag) puts(""); if(!silent_flag) puts("");
puts(buffer); puts(buffer);
curl_formfree(post); curl_formfree(post);
@ -168,7 +174,8 @@ main(int argc, char **argv)
return 0; return 0;
} }
size_t static write_data(void *buffer, size_t size, size_t nmemb, static size_t
write_data(void *buffer, size_t size, size_t nmemb,
void *userp) void *userp)
{ {
memcpy(userp, buffer, nmemb*size); memcpy(userp, buffer, nmemb*size);
@ -178,7 +185,7 @@ size_t static write_data(void *buffer, size_t size, size_t nmemb,
void void
print_usage() print_usage()
{ {
printf("USAGE: clainsafecli [--tor|--i2p] [--server] file\n"); printf("USAGE: clainsafecli [--tor|--i2p] [-6|-4] [--server] file\n");
return; return;
} }
@ -199,9 +206,13 @@ store_link(const char *path, const char *buf)
void void
print_help() print_help()
{ {
printf("--server <server>: specifies the lainsafe server\n%s\n%s", printf("--server <server>: specifies the lainsafe server\n%s\n%s\n%s\n%s\n%s\%s",
"--tor: uses tor", "--tor: uses tor.",
"--help: print this message\n"); "--i2p: uses i2p.",
"-6|--ipv6: uses IPv6 only.",
"-4|--ipv6: uses IPv4 only.",
"--silent: doesn't print progress.",
"--help: print this message.\n");
return; return;
} }
@ -212,6 +223,9 @@ progress(void *clientp,
double ultotal, double ultotal,
double ulnow) double ulnow)
{ {
clientp = NULL;
dltotal = 0;
dlnow = 0;
printf("\r%0.f uploaded of %0.f (%0.f%%)",ulnow,ultotal, printf("\r%0.f uploaded of %0.f (%0.f%%)",ulnow,ultotal,
ulnow*100/ultotal); ulnow*100/ultotal);
fflush(stdout); fflush(stdout);