Added token support

This commit is contained in:
qorg11 2021-04-04 14:50:24 +02:00
parent 89ad06ce23
commit c81acdd4fd
No account linked to committer's email address
2 changed files with 15 additions and 4 deletions

View File

@ -20,7 +20,7 @@ main(int argc, char **argv)
tor_flag = i2p_flag = false; tor_flag = i2p_flag = false;
bool ipv6_flag, ipv4_flag; bool ipv6_flag, ipv4_flag;
ipv6_flag = ipv4_flag = false; ipv6_flag = ipv4_flag = false;
char *token = NULL;
long silent_flag = 0L; long silent_flag = 0L;
char *buffer = (char *)calloc(1024,sizeof(char)); char *buffer = (char *)calloc(1024,sizeof(char));
if(buffer == NULL) { if(buffer == NULL) {
@ -44,6 +44,7 @@ main(int argc, char **argv)
{"server",required_argument,0,'s'}, {"server",required_argument,0,'s'},
{"help" ,no_argument ,0,'h'}, {"help" ,no_argument ,0,'h'},
{"tor" ,no_argument ,0,'t'}, {"tor" ,no_argument ,0,'t'},
{"token" ,required_argument,0,'T'},
{"i2p" ,no_argument ,0,'i'}, {"i2p" ,no_argument ,0,'i'},
{"silent",no_argument ,0,'S'}, {"silent",no_argument ,0,'S'},
{"ipv4" ,no_argument ,0,'4'}, {"ipv4" ,no_argument ,0,'4'},
@ -53,7 +54,7 @@ main(int argc, char **argv)
}; };
int c = 0; int c = 0;
while((c = getopt_long(argc,argv, "46htiSs:", while((c = getopt_long(argc,argv, "46hT:tiSs:",
long_options,&option_index)) != -1) { long_options,&option_index)) != -1) {
switch(c) { switch(c) {
case 's': case 's':
@ -72,6 +73,9 @@ main(int argc, char **argv)
case 'S': case 'S':
silent_flag = true; silent_flag = true;
break; break;
case 'T':
token = optarg;
break;
case '4': case '4':
ipv4_flag = true; ipv4_flag = true;
break; break;
@ -144,6 +148,11 @@ main(int argc, char **argv)
CURLFORM_COPYNAME,"file", CURLFORM_COPYNAME,"file",
CURLFORM_COPYCONTENTS,argv[i], CURLFORM_COPYCONTENTS,argv[i],
CURLFORM_END); CURLFORM_END);
if(token)
curl_formadd(&post,&last,
CURLFORM_COPYNAME,"token",
CURLFORM_COPYCONTENTS,token,
CURLFORM_END);
curl_easy_setopt(easy_handle,CURLOPT_NOPROGRESS,silent_flag); curl_easy_setopt(easy_handle,CURLOPT_NOPROGRESS,silent_flag);
curl_easy_setopt(easy_handle,CURLOPT_PROGRESSFUNCTION,progress); curl_easy_setopt(easy_handle,CURLOPT_PROGRESSFUNCTION,progress);

View File

@ -35,7 +35,8 @@ 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\n%s\n%s\n%s\n%s", printf("--server <server>: specifies the lainsafe server\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
"-t|--token: Authentication token (https://u.kalli.st)",
"--tor: uses tor.", "--tor: uses tor.",
"--i2p: uses i2p.", "--i2p: uses i2p.",
"-6|--ipv6: uses IPv6 only.", "-6|--ipv6: uses IPv6 only.",
@ -55,8 +56,9 @@ progress(void *clientp,
/* So I don't get a warning */ /* So I don't get a warning */
dltotal += 1; dltotal += 1;
dlnow += 1; dlnow += 1;
printf("\r%0.f uploaded of %0.f (%0.f%%)",ulnow,ultotal, printf("\r%0.f uploaded of %0.f (\E[32;1m%0.f%%\E[30;0m)",ulnow,ultotal,
ulnow*100/ultotal); ulnow*100/ultotal);
fflush(stdout); fflush(stdout);
} }