Added config file support
This commit is contained in:
parent
0d1e07fe51
commit
efc3ac374d
11 changed files with 79 additions and 83 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
sakisafecli
|
||||
*.o
|
||||
*.d
|
|
@ -3,9 +3,10 @@
|
|||
TARGET = sakisafecli
|
||||
OBJS = sakisafecli.o funcs.o
|
||||
CC = cc
|
||||
CFLAGSDEF = -MD -std=c11 -Wall -Wextra -lcurl
|
||||
CFLAGS = -O2 -march=native
|
||||
CFLAGSDEF += -MD -std=c11 -Wall -Wextra -lcurl -lconfig
|
||||
CFLAGS += -O2 -ggdb
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(CFLAGSDEF) $(OBJS) -o $(TARGET)
|
||||
|
@ -15,6 +16,9 @@ $(TARGET): $(OBJS)
|
|||
|
||||
-include *.d
|
||||
|
||||
.PHONY: clean
|
||||
install: all
|
||||
@cp sakisafecli /usr/local/bin/
|
||||
|
||||
.PHONY: clean install
|
||||
clean:
|
||||
rm -f *.d *.o sakisafecli
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <libconfig.h>
|
||||
#include "sakisafecli.h"
|
||||
|
||||
size_t
|
||||
|
@ -62,4 +63,3 @@ progress(void *clientp,
|
|||
fflush(stdout);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
funcs.o: funcs.c /usr/include/stdio.h \
|
||||
/usr/include/bits/libc-header-start.h /usr/include/features.h \
|
||||
/usr/include/stdc-predef.h /usr/include/sys/cdefs.h \
|
||||
/usr/include/bits/wordsize.h /usr/include/bits/long-double.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/clang/12.0.1/include/stddef.h \
|
||||
/usr/lib/clang/12.0.1/include/stdarg.h /usr/include/bits/types.h \
|
||||
/usr/include/bits/timesize.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/bits/time64.h /usr/include/bits/types/__fpos_t.h \
|
||||
/usr/include/bits/types/__mbstate_t.h \
|
||||
/usr/include/bits/types/__fpos64_t.h /usr/include/bits/types/__FILE.h \
|
||||
/usr/include/bits/types/FILE.h /usr/include/bits/types/struct_FILE.h \
|
||||
/usr/include/bits/stdio_lim.h /usr/include/bits/floatn.h \
|
||||
/usr/include/bits/floatn-common.h /usr/include/bits/stdio.h \
|
||||
/usr/include/string.h /usr/include/errno.h /usr/include/bits/errno.h \
|
||||
/usr/include/linux/errno.h /usr/include/asm/errno.h \
|
||||
/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \
|
||||
sakisafecli.h /usr/include/stdlib.h /usr/include/bits/stdlib-bsearch.h \
|
||||
/usr/include/bits/stdlib-float.h
|
Binary file not shown.
|
@ -9,9 +9,6 @@ char *server = "https://lainsafe.kalli.st";
|
|||
* socks/http proxy, you can set it here.
|
||||
*/
|
||||
|
||||
int socks_proxy_port = 9050; /* Tor */
|
||||
int http_proxy_port = 4444; /* I2P */
|
||||
|
||||
/* Enable "history" files and where to store that file */
|
||||
|
||||
char history_file_path[256];
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,4 @@
|
|||
#include <libconfig.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -10,26 +11,42 @@
|
|||
#include "options.h"
|
||||
#include "sakisafecli.h"
|
||||
|
||||
/* Config variables */
|
||||
char *socks_proxy_url, *http_proxy_url;
|
||||
|
||||
bool socks_proxy_flag = false, http_proxy_flag = false;
|
||||
bool ipv6_flag = false, ipv4_flag = false;
|
||||
bool silent_flag = false;
|
||||
config_t runtime_config;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct curl_httppost *post = NULL;
|
||||
struct curl_httppost *last = NULL;
|
||||
|
||||
bool socks_proxy_flag, http_proxy_flag;
|
||||
socks_proxy_flag = http_proxy_flag = false;
|
||||
bool ipv6_flag, ipv4_flag;
|
||||
ipv6_flag = ipv4_flag = false;
|
||||
char *token = NULL;
|
||||
long silent_flag = 0L;
|
||||
char *buffer = (char *)calloc(1024, sizeof(char));
|
||||
|
||||
char *socks_proxy_url, *http_proxy_url;
|
||||
char *buffer = (char *)calloc(1024, sizeof(char));
|
||||
|
||||
if(buffer == NULL) {
|
||||
fprintf(stderr, "Error allocating memory!\n");
|
||||
return -1;
|
||||
}
|
||||
char config_location[512];
|
||||
char *sakisafeclirc_env = getenv("SAKISAFECLIRC");
|
||||
|
||||
if(sakisafeclirc_env == NULL) {
|
||||
snprintf(config_location, 512, "%s/.sakisafeclirc", getenv("HOME"));
|
||||
FILE *fp = fopen(config_location, "r");
|
||||
if(fp != NULL)
|
||||
parse_config_file(fp);
|
||||
} else {
|
||||
strncpy(config_location, sakisafeclirc_env, 512);
|
||||
FILE *fp = fopen(config_location, "r");
|
||||
if(fp != NULL)
|
||||
parse_config_file(fp);
|
||||
}
|
||||
|
||||
CURL *easy_handle = curl_easy_init();
|
||||
|
||||
|
@ -50,12 +67,11 @@ main(int argc, char **argv)
|
|||
{ "help", no_argument, 0, 'h' },
|
||||
{ "socks-proxy", required_argument, 0, 'p' },
|
||||
{ "token", required_argument, 0, 'T' },
|
||||
{ "http-proxy", no_argument, 0, 'P' },
|
||||
{ "http-proxy", required_argument, 0, 'P' },
|
||||
{ "silent", no_argument, 0, 'S' },
|
||||
{ "ipv4", no_argument, 0, '4' },
|
||||
{ "ipv6", no_argument, 0, '6' },
|
||||
{ 0, 0, 0, 0 }
|
||||
|
||||
};
|
||||
|
||||
int c = 0;
|
||||
|
@ -191,5 +207,42 @@ main(int argc, char **argv)
|
|||
store_link(history_file_path, buffer);
|
||||
}
|
||||
free(buffer);
|
||||
config_destroy(&runtime_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
parse_config_file(FILE *config)
|
||||
{
|
||||
config_init(&runtime_config);
|
||||
config_read(&runtime_config, config);
|
||||
config_setting_t *cur;
|
||||
cur = config_lookup(&runtime_config, "server");
|
||||
if(config != NULL) {
|
||||
if(cur != NULL)
|
||||
server = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "socks_proxy");
|
||||
if(cur != NULL)
|
||||
socks_proxy_url = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "http_proxy");
|
||||
if(cur != NULL)
|
||||
http_proxy_url = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "use_socks_proxy");
|
||||
if(cur != NULL)
|
||||
socks_proxy_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "use_http_proxy");
|
||||
|
||||
if(cur != NULL)
|
||||
http_proxy_flag = config_setting_get_bool(cur);
|
||||
|
||||
cur = config_lookup(&runtime_config, "silent");
|
||||
if(cur != NULL)
|
||||
silent_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "force_ipv6");
|
||||
if(cur != NULL)
|
||||
ipv6_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "force_ipv4");
|
||||
if(cur != NULL)
|
||||
ipv4_flag = config_setting_get_bool(cur);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
sakisafecli.o: sakisafecli.c /usr/include/stdio.h \
|
||||
/usr/include/bits/libc-header-start.h /usr/include/features.h \
|
||||
/usr/include/stdc-predef.h /usr/include/sys/cdefs.h \
|
||||
/usr/include/bits/wordsize.h /usr/include/bits/long-double.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/clang/12.0.1/include/stddef.h \
|
||||
/usr/lib/clang/12.0.1/include/stdarg.h /usr/include/bits/types.h \
|
||||
/usr/include/bits/timesize.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/bits/time64.h /usr/include/bits/types/__fpos_t.h \
|
||||
/usr/include/bits/types/__mbstate_t.h \
|
||||
/usr/include/bits/types/__fpos64_t.h /usr/include/bits/types/__FILE.h \
|
||||
/usr/include/bits/types/FILE.h /usr/include/bits/types/struct_FILE.h \
|
||||
/usr/include/bits/stdio_lim.h /usr/include/bits/floatn.h \
|
||||
/usr/include/bits/floatn-common.h /usr/include/bits/stdio.h \
|
||||
/usr/include/string.h /usr/include/stdlib.h \
|
||||
/usr/include/bits/stdlib-bsearch.h /usr/include/bits/stdlib-float.h \
|
||||
/usr/lib/clang/12.0.1/include/stdbool.h /usr/include/errno.h \
|
||||
/usr/include/bits/errno.h /usr/include/linux/errno.h \
|
||||
/usr/include/asm/errno.h /usr/include/asm-generic/errno.h \
|
||||
/usr/include/asm-generic/errno-base.h /usr/include/getopt.h \
|
||||
/usr/include/bits/getopt_core.h /usr/include/bits/getopt_ext.h \
|
||||
/usr/include/unistd.h /usr/include/bits/posix_opt.h \
|
||||
/usr/include/bits/confname.h /usr/include/bits/unistd_ext.h \
|
||||
/usr/include/curl/curl.h /usr/include/curl/curlver.h \
|
||||
/usr/include/curl/system.h /usr/include/sys/types.h \
|
||||
/usr/include/bits/types/clockid_t.h /usr/include/bits/types/time_t.h \
|
||||
/usr/include/bits/types/timer_t.h /usr/include/bits/stdint-intn.h \
|
||||
/usr/include/sys/socket.h /usr/include/bits/types/struct_iovec.h \
|
||||
/usr/include/bits/socket.h /usr/include/bits/socket_type.h \
|
||||
/usr/include/bits/sockaddr.h /usr/include/bits/socket-constants.h \
|
||||
/usr/lib/clang/12.0.1/include/limits.h /usr/include/limits.h \
|
||||
/usr/include/time.h /usr/include/bits/time.h \
|
||||
/usr/include/bits/types/clock_t.h /usr/include/bits/types/struct_tm.h \
|
||||
/usr/include/bits/types/struct_timespec.h /usr/include/bits/endian.h \
|
||||
/usr/include/bits/endianness.h /usr/include/sys/time.h \
|
||||
/usr/include/bits/types/struct_timeval.h /usr/include/sys/select.h \
|
||||
/usr/include/bits/select.h /usr/include/bits/types/sigset_t.h \
|
||||
/usr/include/bits/types/__sigset_t.h /usr/include/curl/easy.h \
|
||||
/usr/include/curl/multi.h /usr/include/curl/urlapi.h \
|
||||
/usr/include/curl/options.h /usr/include/curl/header.h options.h \
|
||||
sakisafecli.h
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
size_t
|
||||
write_data(void *buffer, size_t size, size_t nmemb,
|
||||
void *userp);
|
||||
write_data(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
|
||||
void
|
||||
print_usage();
|
||||
|
@ -15,9 +15,8 @@ void
|
|||
print_help();
|
||||
|
||||
void
|
||||
progress(void *clientp,
|
||||
double dltotal,
|
||||
double dlnow,
|
||||
double ultotal,
|
||||
double ulnow);
|
||||
progress(
|
||||
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
|
||||
|
||||
void
|
||||
parse_config_file(FILE *config);
|
||||
|
|
Binary file not shown.
Loading…
Add table
Reference in a new issue