summaryrefslogtreecommitdiff
path: root/sakisafecli/funcs.c
blob: d7782ff265c8206b7ef6f83c61bb703b5f70f486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <curl/system.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <libconfig.h>
#include <curl/curl.h>
#include <stdbool.h>
#include "sakisafecli.h"

size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
	memcpy(userp, buffer, nmemb * size);
	return 0;
}

void
print_usage()
{
	printf("USAGE: sakisafecli [-p socks proxy|-P http proxy] [-x] [-s] "
		  "[-6|-4] [--server] FILE\n");
	return;
}

void
print_help()
{
	printf("-s|--server: specifies the sakisafe "
		  "server\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
		  "-t|--token: Authentication token (https://u.kalli.st)",
		  "-P|--http-proxy: http proxy to use e.g. http://127.0.0.1:4444",
		  "-p|--socks-proxy: SOCK proxy to use e.g. 127.0.0.1:9050",
		  "-6|--ipv6: uses IPv6 only",
		  "-4|--ipv6: uses IPv4 only", 
		  "-S|--silent: doesn't print progress",
		  "-x|--paste: read file from stdin",
		  "-C: print current settings",
		  "-h|--help: print this message.\n");
	return;
}

size_t
progress(
	void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
	/* I don't know why the fuck I have to do this */
	if(ultotal == 0) {
		ultotal++;
	}
	printf("\r%li uploaded of %li (\033[32;1m%li%%\033[30;0m)",
		  ulnow,
		  ultotal,
		  ulnow * 100 / ultotal);
	fflush(stdout);
	return 0;
}