Better documentation in the code

New flag: -C, which prints the current settings (Still have to add it to the manpage and help message)
master
qorg11 2022-06-23 16:45:46 +02:00
parent a4db8e35e3
commit 1d71334340
6 changed files with 71 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
sakisafecli
*.o
*.d
obj/

View File

@ -1,6 +1,34 @@
#include <libconfig.h>
#include <stdbool.h>
#include <stdio.h>
#include "options.h"
#include "config.h"
void
print_config()
{
puts("Current configuration:");
printf("Server: %s\n",server);
if(socks_proxy_flag)
printf("Socks proxy url: %s",socks_proxy_url);
if(http_proxy_flag)
printf("HTTP proxy url: %s",http_proxy_url);
if(silent_flag)
puts("Silent: true");
else
puts("Silent: false");
if(ipv6_flag)
printf("Force IPv6: true\n");
else
printf("Force IPv6: false\n");
if(ipv4_flag)
printf("Force IPv4: true\n");
else
printf("Force IPv4: false\n");
return;
}
void
parse_config_file(FILE *config)
{

9
sakisafecli/config.h Normal file
View File

@ -0,0 +1,9 @@
#include <libconfig.h>
/* Parse the config file */
void
parse_config_file(FILE *config);
/* Print the current settings */
void
print_config();

View File

@ -50,3 +50,4 @@ progress(void *clientp,
fflush(stdout);
}

24
sakisafecli/funcs.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <stdlib.h>
/* Function used from curl to write data to a buffer */
size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp);
/* Print usage message (when nothing is given to sakisafecli) */
void
print_usage();
/* Print help message (-h) */
void
print_help();
/* Function used to display progress when uploading a file */
void
progress(
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
/* Print config */
void
print_config();

View File

@ -9,6 +9,8 @@
#include <curl/curl.h>
#include "options.h"
#include "config.h"
#include "funcs.h"
#include "sakisafecli.h"
/* Config variables */
@ -99,7 +101,7 @@ main(int argc, char **argv)
int c = 0;
while((c = getopt_long(
argc, argv, "46hT:p:P:Ss:x", long_options, &option_index)) !=
argc, argv, "46hT:p:P:Ss:xC", long_options, &option_index)) !=
-1) {
switch(c) {
case 's':
@ -137,6 +139,9 @@ main(int argc, char **argv)
print_usage();
return 0;
break;
case 'C':
print_config();
return 0;
default:
print_usage();
return 0;
@ -187,8 +192,8 @@ main(int argc, char **argv)
*/
curl_mimepart *file_data;
file_data = curl_mime_addpart(mime);
char *filename = argv[argc];
char *filename = argv[optind];
if(paste_flag)
filename = "/dev/stdin";