Added a header for clainsafecli which contains the functions. Also

added the default curl progress bar.

Added deprecation note for lainsafecli.
This commit is contained in:
qorg11 2021-02-09 18:23:43 +01:00
parent e87c6c9b1c
commit acb47dd5bb
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
3 changed files with 98 additions and 78 deletions

View File

@ -5,47 +5,10 @@
#include <getopt.h>
#include <errno.h>
#include <curl/curl.h>
#include <math.h>
#include "options.h"
size_t static write_data(void *buffer, size_t size, size_t nmemb,
void *userp)
{
memcpy(userp, buffer, nmemb*size);
return 0;
}
void
print_usage()
{
printf("USAGE: clainsafecli [--tor|--i2p] [--server] file\n");
return;
}
int
store_link(const char *path, const char *buf)
{
FILE *fp = fopen(path,"a+");
if(fp == NULL) {
fprintf(stderr,"Error opening file %i: %s\n",errno,
strerror(errno));
return -1;
}
fwrite(buf,strlen(buf),1,fp);
fputc('\n',fp);
return 0;
}
void
print_help()
{
printf("--server <server>: specifies the lainsafe server\n%s\n%s\n%s",
"--tor: uses tor",
"--help: print this message\n",
"--i2p: uses i2p HTTP proxy"
);
return;
}
#include "clainsafecli.h"
int
main(int argc, char **argv)
@ -59,6 +22,7 @@ main(int argc, char **argv)
char *buffer = (char *)calloc(1024,sizeof(char));
if(buffer == NULL) {
fprintf(stderr,"Error allocating memory!\n");
return -1;
}
CURL *easy_handle = curl_easy_init();
@ -147,6 +111,14 @@ main(int argc, char **argv)
CURLFORM_COPYCONTENTS,argv[optind],
CURLFORM_END);
/* Progress bar
*
* TODO: Use a custom progress bar rather than
* default curl progress bar
*
*/
curl_easy_setopt(easy_handle,CURLOPT_NOPROGRESS,0L);
curl_easy_setopt(easy_handle,CURLOPT_HTTPPOST,post);
curl_easy_perform(easy_handle);
@ -165,3 +137,31 @@ main(int argc, char **argv)
free(buffer);
return 0;
}
size_t static write_data(void *buffer, size_t size, size_t nmemb,
void *userp)
{
memcpy(userp, buffer, nmemb*size);
return 0;
}
void
print_usage()
{
printf("USAGE: clainsafecli [--tor|--i2p] [--server] file\n");
return;
}
int
store_link(const char *path, const char *buf)
{
FILE *fp = fopen(path,"a+");
if(fp == NULL) {
fprintf(stderr,"Error opening file %i: %s\n",errno,
strerror(errno));
return -1;
}
fwrite(buf,strlen(buf),1,fp);
fputc('\n',fp);
return 0;
}

View File

@ -0,0 +1,17 @@
#include <stdlib.h>
size_t
static write_data(void *buffer, size_t size, size_t nmemb,
void *userp);
void
print_usage();
int progress_func(void* ptr, double TotalToDownload, double NowDownloaded,
double TotalToUpload, double NowUploaded);
int
store_link(const char *path, const char *buf);
void
print_help();

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with lainsafe. If not, see <https://www.gnu.org/licenses/>.
# This script is kind of deprecated. Use clainsafecli instead.
use Getopt::Long;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
@ -148,3 +150,4 @@ if ($STORE_LINKS) {
print FILE $req->{_content} . " $file" ."\n";
close FILE;
}