Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
qorg11 committed Jul 9, 2022
1 parent 957b871 commit 9c8749e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions sakisafecli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion sakisafecli/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ print_usage()
return;
}


void
print_help()
{
Expand Down
2 changes: 1 addition & 1 deletion sakisafecli/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
16 changes: 12 additions & 4 deletions sakisafecli/sakisafecli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9c8749e

Please sign in to comment.