From 9c8749e664e75c6f924e8b62d2f70e1aabc5b295 Mon Sep 17 00:00:00 2001
From: qorg11 <teru-sama@riseup.net>
Date: Sat, 9 Jul 2022 16:40:25 +0200
Subject: [PATCH] Clean code

---
 sakisafecli/Makefile      |  2 ++
 sakisafecli/funcs.c       |  1 -
 sakisafecli/options.h     |  2 +-
 sakisafecli/sakisafecli.c | 16 ++++++++++++----
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/sakisafecli/Makefile b/sakisafecli/Makefile
index 6a2de40..28dacd0 100644
--- a/sakisafecli/Makefile
+++ b/sakisafecli/Makefile
@@ -3,6 +3,8 @@ SRCS  += funcs.c sakisafecli.c config.c
 MAN    = sakisafecli.1 sakisafeclirc.5
 LDADD  = -lssl -lz -lpthread -lnghttp2 -lcurl -lconfig -lcrypto -L/usr/local/lib
 PREFIX = /usr/local
+
 BINDIR = $(PREFIX)/bin
 MANDIR = $(PREFIX)/man/man
+
 .include <bsd.prog.mk>
diff --git a/sakisafecli/funcs.c b/sakisafecli/funcs.c
index 8f9ecc8..ea75d79 100644
--- a/sakisafecli/funcs.c
+++ b/sakisafecli/funcs.c
@@ -19,7 +19,6 @@ print_usage()
 	return;
 }
 
-
 void
 print_help()
 {
diff --git a/sakisafecli/options.h b/sakisafecli/options.h
index 77b563c..d92a575 100644
--- a/sakisafecli/options.h
+++ b/sakisafecli/options.h
@@ -26,6 +26,6 @@ extern bool http_proxy_flag;
 extern bool ipv6_flag;
 extern bool ipv4_flag;
 extern bool silent_flag;
-extern config_t runtime_config;
 extern char *ssh_key_path;
+extern config_t runtime_config;
 #endif  /* OPTIONS_H */
diff --git a/sakisafecli/sakisafecli.c b/sakisafecli/sakisafecli.c
index 28c5ae0..47887c0 100644
--- a/sakisafecli/sakisafecli.c
+++ b/sakisafecli/sakisafecli.c
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <curl/curl.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include "curl/easy.h"
 #include "options.h"
@@ -151,7 +152,9 @@ main(int argc, char **argv)
 	}
 
 	if(access(argv[optind], F_OK) && !paste_flag) {
-		fprintf(stderr, "Error opening file\n");
+		fprintf(stderr, "Error opening file: %s\n",
+			strerror(errno)
+			);
 		return -1;
 	}
 
@@ -178,8 +181,7 @@ main(int argc, char **argv)
 		curl_easy_setopt(easy_handle, CURLOPT_PROXY, socks_proxy_url);
 		curl_easy_setopt(
 			easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
-	} else if(http_proxy_flag && ((protocol == CURLPROTO_HTTP) ||
-							(protocol == CURLPROTO_HTTPS))) {
+	} else if(http_proxy_flag && protocol == CURLPROTO_HTTP) {
 		curl_easy_setopt(easy_handle, CURLOPT_PROXY, http_proxy_url);
 		curl_easy_setopt(easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
 	}
@@ -209,9 +211,10 @@ main(int argc, char **argv)
 
 	/* Process HTTP uploads */
 
-	if(protocol == CURLPROTO_HTTP || protocol == CURLPROTO_HTTPS) {
+	if(protocol == CURLPROTO_HTTP) {
 		curl_mime *mime;
 		mime = curl_mime_init(easy_handle);
+		
 		curl_easy_setopt(easy_handle, CURLOPT_MIMEPOST, mime);
 		if(!mime) {
 			fprintf(stderr, "Error initializing curl_mime\n");
@@ -240,16 +243,21 @@ main(int argc, char **argv)
 	else if(protocol == CURLPROTO_SCP) {
 		char path[256];
 		char *filename = argv[optind];
+		
 		curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, true);
 		FILE *fp = fopen(filename, "r");
+		
 		struct stat st;
 		stat(argv[optind], &st);
 		snprintf(path, 256, "%s/%s", server, filename);
+		
 		curl_easy_setopt(easy_handle, CURLOPT_READDATA, fp);
 		curl_easy_setopt(
 			easy_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)st.st_size);
+		
 		curl_easy_setopt(easy_handle, CURLOPT_URL, path);
 		curl_easy_perform(easy_handle);
+		putchar('\n');
 	} else {
 		puts("Unsupported protocol");
 		return -1;