Curl devs were very smart and decided to deprecated the

CURL_PROGRESSFUNCTION option that had 0 problems in my opinion and
decided to change it with CURL_XFERINFOFUNCTION thing which barely
works and had to do a very weird workaround so I don't get a floating
point exception just because. Well, it works and that's what matters.
master
Barrington 2023-03-09 15:39:38 +01:00
parent a804518ef6
commit 82422e6d37
Signed by: svragv
GPG Key ID: B39C0BCEE94A4A89
3 changed files with 27 additions and 10 deletions

View File

@ -1,8 +1,10 @@
#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
@ -37,16 +39,19 @@ print_help()
return;
}
void
size_t
progress(
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
/* So I don't get a warning */
dltotal += 1;
dlnow += 1;
printf("\r%0.f uploaded of %0.f (\033[32;1m%0.f%%\033[30;0m)",
/* I don't know why the fuck I have to do this */
if(ultotal == 0) {
ultotal++;
}
struct progress *memory = (struct progress *)clientp;
printf("\r%li uploaded of %li (\033[32;1m%li%%\033[30;0m)",
ulnow,
ultotal,
ulnow * 100 / ultotal);
fflush(stdout);
return 0;
}

View File

@ -194,7 +194,9 @@ main(int argc, char **argv)
/* Common options for both HTTP and SCP transfers */
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
struct progress mem;
curl_easy_setopt(easy_handle, CURLOPT_XFERINFODATA, &mem);
curl_easy_setopt(easy_handle, CURLOPT_XFERINFOFUNCTION, progress);
/* File name */

View File

@ -2,6 +2,13 @@
#define SAKISAFECLI_H
#include <stdlib.h>
#include <stdio.h>
#include <curl/curl.h>
struct progress
{
char *_private;
size_t size;
};
size_t
write_data(void *buffer, size_t size, size_t nmemb, void *userp);
@ -15,9 +22,12 @@ store_link(const char *path, const char *buf);
void
print_help();
void
progress(
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
size_t
progress(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow);
void
parse_config_file(FILE *config);