summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fankhauser hiddenalpha.ch2023-09-28 21:42:24 +0200
committerAndreas Fankhauser hiddenalpha.ch2023-09-28 21:42:24 +0200
commit6e57027641296e679fa109a8edd3ff53c745a6de (patch)
tree702a8530fe63961ce386a74a781aab6c1ca825b3
parentfd21ccc591ba70c709ae00a909c92eae51afe1a0 (diff)
downloadgateleen-resclone-6e57027641296e679fa109a8edd3ff53c745a6de.zip
gateleen-resclone-6e57027641296e679fa109a8edd3ff53c745a6de.tar.gz
Bunch of formatting changes
-rw-r--r--src/gateleen_resclone/gateleen_resclone.c343
1 files changed, 166 insertions, 177 deletions
diff --git a/src/gateleen_resclone/gateleen_resclone.c b/src/gateleen_resclone/gateleen_resclone.c
index 4501125..f97373b 100644
--- a/src/gateleen_resclone/gateleen_resclone.c
+++ b/src/gateleen_resclone/gateleen_resclone.c
@@ -8,7 +8,6 @@
#include <errno.h>
#include <libgen.h>
#include <regex.h>
-#include <stdbool.h>
#include <string.h>
/* Libs */
@@ -30,128 +29,123 @@
/** Operation mode. */
-typedef enum opMode {
+typedef enum OpMode {
MODE_NULL =0,
MODE_FETCH=1,
MODE_PUSH =2
-} opMode_t;
+} OpMode;
/** Main module handle representing an instance. */
-typedef struct this {
- enum opMode mode;
+typedef struct Resclone {
+ enum OpMode mode;
/** Base URL where to upload to / download from. */
char *url;
/** Array of regex patterns to use per segment. */
regex_t *filter;
size_t filter_len;
/** Says if only start or whole path needs to match the pattern. */
- bool isFilterFull;
+ int isFilterFull;
/* Path to archive file to use. Using stdin/stdout if NULL. */
char *file;
-} this_t;
+} Resclone;
/** Closure for a download instructed by external caller. */
-typedef struct cls_dload {
- struct this *this;
+typedef struct ClsDload {
+ struct Resclone *resclone;
char *rootUrl;
struct archive *dstArchive;
struct archive_entry *tmpEntry;
char *archiveFile;
CURL *curl;
-} cls_dload_t;
+} ClsDload;
/** Closure for a collection (directory) download. */
-typedef struct cls_resourceDir {
- struct cls_dload *dload;
+typedef struct ResourceDir {
+ struct ClsDload *dload;
//yajl_handle yajl; <- TODO Obsolete
- struct cls_resourceDir *parentDir;
+ struct ResourceDir *parentDir;
char *rspBody;
size_t rspBody_len;
size_t rspBody_cap;
short rspCode;
char *name;
-} cls_resourceDir_t;
+} ResourceDir;
/** Closure for a file download. */
-typedef struct cls_resourceFile {
- struct cls_dload *dload;
+typedef struct ResourceFile {
+ struct ClsDload *dload;
size_t srcChunkIdx;
char *url;
char *buf;
int buf_len;
int buf_memSz;
-} cls_resourceFile_t;
+} ResourceFile;
/** Closure for an upload instructed by external caller. */
-typedef struct cls_upload {
- struct this *this;
+typedef struct Upload {
+ struct Resclone *resclone;
char *rootUrl;
char *archiveFile;
struct archive *srcArchive;
CURL *curl;
-} cls_upload_t;
+} Upload;
/** Closure for a PUT of a single resource. */
-typedef struct cls_put {
- struct cls_upload *upload;
+typedef struct Put {
+ struct Upload *upload;
/* Path (relative to rootUrl) of the resource to be uploaded. */
char *name;
-} cls_put_t;
+} Put;
/* Operations ****************************************************************/
-TPL_ARRAY( str, char*, 16 );
+TPL_ARRAY(str, char*, 16);
-static void
-printHelp( void )
-{
- char filename[sizeof(__FILE__)];
- strcpy( filename, __FILE__ );
+static void printHelp( void ){
printf("%s%s%s",
- "\n"
- " ", basename(filename), " - " STR_QUOT(PROJECT_VERSION) "\n"
- "\n"
- "Options:\n"
- "\n"
+ " \n"
+ " ", strrchr(filename,'/')+1, " - " STR_QUOT(PROJECT_VERSION) "\n"
+ " \n"
+ " Options:\n"
+ " \n"
" --pull|--push\n"
" Choose to download or upload.\n"
- "\n"
+ " \n"
" --url <url>\n"
- " Root node of remote tree.\n"
- "\n"
+ " Root node of remote tre\n"
" --filter-part <path-filter>\n"
- " Regex pattern applied as predicate to the path starting after the path\n"
- " specified in '--url'. Each path segment will be handled as its\n"
- " individual pattern. If there are longer paths to process, they will be\n"
- " accepted, as long they at least start-with specified filter.\n"
+ " Regex pattern applied as predicate to the path starting after\n"
+ " the path specified in '--url'. Each path segment will be\n"
+ " handled as its individual pattern. If there are longer paths to\n"
+ " process, they will be accepted, as long they at least\n"
+ " start-with specified filter.\n"
" Example: /foo/[0-9]+/bar\n"
- "\n"
+ " \n"
" --filter-full <path-filter>\n"
- " Nearly same as '--filter-part'. But paths with more segments than the\n"
- " pattern, will be rejected.\n"
- "\n"
+ " Nearly same as '--filter-part'. But paths with more segments\n"
+ " than the pattern, will be rejected.\n"
+ " \n"
" --file <path.tar>\n"
" (optional) Path to the archive file to read/write. Defaults to\n"
" stdin/stdout if ommitted.\n"
- "\n"
+ " \n"
+ " \n"
);
}
-static int
-parseArgs( int argc, char**argv, opMode_t*mode, char**url, regex_t**filter, size_t*filter_cnt,
- bool*isFilterFull, char**file ){
- ssize_t err, ret=0;
+static int parseArgs( int argc, char**argv, OpMode*mode, char**url, regex_t**filter, size_t*filter_cnt, int*isFilterFull, char**file ){
+ ssize_t err;
char *filterRaw = NULL;
if( argc == -1 ){ // -1 indicates the call to free our resources. So simply jump
goto fail; // to 'fail' because that has the same effect.
@@ -160,77 +154,77 @@ parseArgs( int argc, char**argv, opMode_t*mode, char**url, regex_t**filter, size
*url = NULL;
*filter = NULL;
*filter_cnt = 0;
- *isFilterFull = false;
+ *isFilterFull = 0;
*file = NULL;
for( int i=1 ; i<argc ; ++i ){
char *arg = argv[i];
if( !strcmp(arg,"--help") ){
printHelp();
- ret = -1; goto fail;
+ err = -1; goto fail;
}else if( !strcmp(arg,"--pull") ){
if( *mode ){
printf("%s\n","ERROR: Mode already specified. Won't set '--pull'.");
- ret = -1; goto fail;
+ err = -1; goto fail;
}
*mode = MODE_FETCH;
}else if( !strcmp(arg,"--push") ){
if( *mode ){
printf("%s\n","ERROR: Mode already specified. Won't set '--push'.");
- ret = -1; goto fail;
+ err = -1; goto fail;
}
*mode = MODE_PUSH;
}else if( !strcmp(arg,"--url") ){
if(!( arg=argv[++i]) ){
printf("%s\n","ERROR: Arg '--url' needs a value.");
- ret = -1; goto fail;
+ err = -1; goto fail;
}
*url = arg;
}else if( !strcmp(arg,"--filter-full") ){
if(!( arg=argv[++i] )){
printf("%s\n","ERROR: Arg '--filter-full' needs a value.");
- ret = -1; goto fail; }
+ err = -1; goto fail; }
if( filterRaw ){
printf("%s\n","ERROR: Cannot use '--filter-full' because a filter is already set.");
- ret=-1; goto fail; }
+ err=-1; goto fail; }
filterRaw = arg;
- *isFilterFull = true;
+ *isFilterFull = !0;
}else if( !strcmp(arg,"--filter-part") ){
if(!( arg=argv[++i] )){
printf("%s\n","ERROR: Arg '--filter-part' needs a value.");
- ret = -1; goto fail; }
+ err = -1; goto fail; }
if( filterRaw ){
printf("%s\n","ERROR: Cannot use '--filter-part' because a filter is already set.");
- ret=-1; goto fail; }
+ err = -1; goto fail; }
filterRaw = arg;
- *isFilterFull = false;
+ *isFilterFull = 0;
}else if( !strcmp(arg,"--file") ){
if(!( arg=argv[++i]) ){
printf("%s\n","ERROR: Arg '--file' needs a value.");
- ret = -1; goto fail;
+ err = -1; goto fail;
}
*file = arg;
}else{
printf("%s%s\n", "ERROR: Unknown arg ",arg);
- ret = -1; goto fail;
+ err = -1; goto fail;
}
}
- if( *mode==0 ){
- printf("%s\n", "ERROR: One of --push or --pull required.");
- ret = -1; goto fail;
+ if( *mode == 0 ){
+ printf("ERROR: One of --push or --pull required.\n");
+ err = -1; goto fail;
}
if( *url==NULL ){
- printf("%s\n", "ERROR: Arg --url missing.");
- ret = -1; goto fail;
+ printf("ERROR: Arg --url missing.\n");
+ err = -1; goto fail;
}
- uint_t urlFromArgs_len = strlen( *url );
+ uint_t urlFromArgs_len = strlen(*url);
if( ((*url)[urlFromArgs_len-1]) != '/' ){
char *urlFromArgs = *url;
uint_t url_len = urlFromArgs_len + 1;
*url = malloc(url_len+1); /* TODO: Should we free this? */
- memcpy( *url, urlFromArgs, urlFromArgs_len );
+ memcpy(*url, urlFromArgs, urlFromArgs_len);
(*url)[url_len-1] = '/';
(*url)[url_len] = '\0';
}else{
@@ -238,16 +232,16 @@ parseArgs( int argc, char**argv, opMode_t*mode, char**url, regex_t**filter, size
}
if( filterRaw ){
- uint_t buf_len = strlen( filterRaw );
- char *buf = malloc( 1+ buf_len +2 );
+ uint_t buf_len = strlen(filterRaw);
+ char *buf = malloc(1 + buf_len + 2);
buf[0] = '_'; // <- Match whole segment.
- memcpy( buf+1, filterRaw, buf_len+1 );
+ memcpy(buf+1, filterRaw, buf_len+1);
char *beg, *end;
size_t filter_cap = 0;
end = buf+1; // <- Initialize at begin for 1st iteration.
for( uint_t iSegm=0 ;; ++iSegm ){
- for( beg=end ; *beg=='/' ; ++beg ); // <- Search for begin and
- for( end=beg ; *end!='/' && *end!='\0' ; ++end ); // <- end of current segment.
+ for( beg=end ; *beg=='/' ; ++beg ); // <- Search for begin and ..
+ for( end=beg ; *end!='/' && *end!='\0' ; ++end ); // <- .. end of current segment.
char origBeg = beg[-1];
char origSep = *end;
char origNext = end[1];
@@ -261,21 +255,21 @@ parseArgs( int argc, char**argv, opMode_t*mode, char**url, regex_t**filter, size
// "[DEBUG] realloc(NULL, ", filter_cap*sizeof**filter," ) -> ", tmp);
if( tmp == NULL ){
fprintf(stderr, "%s%d%s\n", "[ERROR] realloc(", filter_cap*sizeof**filter, ")");
- ret = -ENOMEM; goto fail; }
+ err = -ENOMEM; goto fail; }
*filter = tmp;
}
//fprintf(stderr, "%s%d%s%s%s\n", "[DEBUG] filter[", iSegm, "] -> '", beg-1, "'");
- err = regcomp( (*filter)+iSegm, beg-1, REG_EXTENDED);
+ err = regcomp((*filter)+iSegm, beg-1, REG_EXTENDED);
if( err ){
fprintf(stderr, "%s%s%s%d\n", "[ERROR] regcomp(", beg, ") -> ", err);
- ret = -1; goto fail; }
- // Restore surrounding stuff.
+ err = -1; goto fail; }
+ /* Restore surrounding stuff. */
beg[-1] = origBeg;
- *end = origSep; // <- Restore tmp 'end-of-match' ($).
- end[1] = origNext; // <- Restore tmp termination.
- if( *end=='\0' ){ // EOF
+ *end = origSep; /* <- Restore tmp 'end-of-match' ($) */
+ end[1] = origNext; /* <- Restore tmp termination. */
+ if( *end == '\0' ){ /* EOF */
*filter_cnt = iSegm +1;
- *filter = realloc(*filter, *filter_cnt *sizeof(**filter)); // Trim result.
+ *filter = realloc(*filter, *filter_cnt *sizeof(**filter)); /* Trim result. */
assert(*filter != NULL);
free(buf); buf = NULL;
break;
@@ -285,27 +279,26 @@ parseArgs( int argc, char**argv, opMode_t*mode, char**url, regex_t**filter, size
if( *mode == MODE_PUSH && *filter ){
fprintf(stderr, "%s\n", "[ERROR] Filtering not supported for push mode.");
- ret = -1; goto fail;
+ err = -1; goto fail;
}
return 0;
fail:
free(*url); *url = NULL;
for( uint_t i=0 ; i<*filter_cnt ; ++i ){
- regfree( &(filter[0][i]) );
+ regfree(&(filter[0][i]));
}
*filter_cnt = 0;
free(*filter); *filter = NULL;
- return ret;
+ return err;
}
-static size_t
-onCurlDirRsp( char*buf, size_t size, size_t nmemb, void*cls_resourceDir_ ){
+static size_t onCurlDirRsp( char*buf, size_t size, size_t nmemb, void*ResourceDir_ ){
fprintf(stderr, "%s%s%s%p%s%ld%s%ld%s%p%s\n", "[TRACE] ", __func__, "( buf=", buf,
- ", size=", size, ", nmemb=", nmemb, ", cls=", cls_resourceDir_, " )");
- cls_resourceDir_t *resourceDir = cls_resourceDir_;
- cls_dload_t *dload = resourceDir->dload;
+ ", size=", size, ", nmemb=", nmemb, ", cls=", ResourceDir_, " )");
+ ResourceDir *resourceDir = ResourceDir_;
+ ClsDload *dload = resourceDir->dload;
CURL *curl = dload->curl;
const size_t buf_len = size * nmemb;
@@ -322,7 +315,7 @@ onCurlDirRsp( char*buf, size_t size, size_t nmemb, void*cls_resourceDir_ ){
resourceDir->rspBody_cap = resourceDir->rspBody_len + buf_len + 1024;
void *tmp = realloc(resourceDir->rspBody, resourceDir->rspBody_cap);
if( tmp == NULL ){
- err = size*nmemb/*TODO could we return anything better here?*/; goto endFn; }
+ err = size * nmemb/*TODO could we return anything better here?*/; goto endFn; }
resourceDir->rspBody = tmp;
}
memcpy(resourceDir->rspBody+resourceDir->rspBody_len, buf, buf_len);
@@ -331,16 +324,15 @@ onCurlDirRsp( char*buf, size_t size, size_t nmemb, void*cls_resourceDir_ ){
// Parsing occurs in the caller, as soon we processed whole response.
- err = size*nmemb;
+ err = size * nmemb;
endFn:
return err;
}
-static size_t
-onResourceChunk( char*buf, size_t size, size_t nmemb, void*cls_resourceFile_ ){
+static size_t onResourceChunk( char*buf, size_t size, size_t nmemb, void*ResourceFile_ ){
const int buf_len = size * nmemb;
- cls_resourceFile_t *resourceFile = cls_resourceFile_;
+ ResourceFile *resourceFile = ResourceFile_;
const int avail = resourceFile->buf_memSz - resourceFile->buf_len;
if( avail <= buf_len ){
@@ -358,10 +350,9 @@ onResourceChunk( char*buf, size_t size, size_t nmemb, void*cls_resourceFile_ ){
}
-static ssize_t
-collectResourceIntoMemory( cls_resourceFile_t*resourceFile, char*url ){
+static ssize_t collectResourceIntoMemory( ResourceFile*resourceFile, char*url ){
ssize_t err;
- cls_dload_t *dload = resourceFile->dload;
+ ClsDload *dload = resourceFile->dload;
CURL *curl = dload->curl;
err = CURLE_OK!= curl_easy_setopt(curl, CURLOPT_URL, url)
@@ -369,7 +360,7 @@ collectResourceIntoMemory( cls_resourceFile_t*resourceFile, char*url ){
|| CURLE_OK!= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, onResourceChunk)
|| CURLE_OK!= curl_easy_setopt(curl, CURLOPT_WRITEDATA, resourceFile)
;
- if( err ){ assert(!err); err=-1; goto endFn; }
+ if( err ){ assert(!err); err = -1; goto endFn; }
err = curl_easy_perform(curl);
if( err != CURLE_OK ){
@@ -384,14 +375,13 @@ endFn:
}
-static ssize_t
-copyBufToArchive( cls_resourceFile_t*resourceFile ){
+static ssize_t copyBufToArchive( ResourceFile*resourceFile ){
ssize_t err;
- cls_dload_t *dload = resourceFile->dload;
+ ClsDload *dload = resourceFile->dload;
char *fileName = resourceFile->url + strlen(resourceFile->dload->rootUrl);
if( ! dload->dstArchive ){
- // Setup archive if not setup yet.
+ /* Setup archive if not setup yet. */
dload->dstArchive = archive_write_new();
err = archive_write_set_format_pax_restricted(dload->dstArchive)
|| archive_write_open_filename(dload->dstArchive, dload->archiveFile)
@@ -403,7 +393,7 @@ copyBufToArchive( cls_resourceFile_t*resourceFile ){
}
}
- if( ! dload->tmpEntry ){
+ if( dload->tmpEntry == NULL ){
dload->tmpEntry = archive_entry_new();
}else{
dload->tmpEntry = archive_entry_clear(dload->tmpEntry);
@@ -413,8 +403,7 @@ copyBufToArchive( cls_resourceFile_t*resourceFile ){
archive_entry_set_size(dload->tmpEntry, resourceFile->buf_len);
archive_entry_set_perm(dload->tmpEntry, 0644);
err = archive_write_header(dload->dstArchive, dload->tmpEntry);
- if( err ){
- err=-1; goto endFn; }
+ if( err ){ err = -1; goto endFn; }
ssize_t written = archive_write_data(dload->dstArchive, resourceFile->buf, resourceFile->buf_len);
if( written < 0 ){
@@ -435,18 +424,18 @@ endFn:
/** @return 0:Reject, 1:Accept, <0:ERROR */
-static ssize_t pathFilterAcceptsEntry( cls_dload_t*dload, cls_resourceDir_t*resourceDir, const char*nameOrig ){
+static ssize_t pathFilterAcceptsEntry( ClsDload*dload, ResourceDir*resourceDir, const char*nameOrig ){
ssize_t err;
- char *name = strdup( nameOrig );
- uint_t name_len = strlen( name );
+ char *name = strdup(nameOrig);
+ uint_t name_len = strlen(name);
- if( dload->this->filter ){
+ if( dload->resclone->filter ){
// Count parents to find correct regex to apply.
uint_t idx = 0;
- for( cls_resourceDir_t*it=resourceDir->parentDir ; it ; it=it->parentDir ){ ++idx; }
+ for( ResourceDir*it=resourceDir->parentDir ; it ; it=it->parentDir ){ ++idx; }
// Check if we even have such a long filter at all.
- if( idx >= dload->this->filter_len ){
- if( dload->this->isFilterFull ){
+ if( idx >= dload->resclone->filter_len ){
+ if( dload->resclone->isFilterFull ){
//fprintf(stderr, "%s\n", "[DEBUG] Path longer than --filter-full -> reject.");
err = 0; goto endFn;
}else{
@@ -455,14 +444,14 @@ static ssize_t pathFilterAcceptsEntry( cls_dload_t*dload, cls_resourceDir_t*reso
}
}
// We have a regex. Setup the check.
- bool restoreEndSlash = false;
- if( name[name_len-1]=='/' ){
- restoreEndSlash = true;
+ int restoreEndSlash = 0;
+ if( name[name_len-1] == '/' ){
+ restoreEndSlash = !0;
name[name_len-1] = '\0';
}
//fprintf(stderr, "%s%u%s%s%s\n", "[DEBUG] idx=", idx," name='", name, "'");
- regex_t *filterArr = dload->this->filter;
- regex_t *r = filterArr + (idx);
+ regex_t *filterArr = dload->resclone->filter;
+ regex_t *r = filterArr + idx;
err = regexec(r, name, 0, 0, 0);
if( !err ){
//fprintf(stderr, "%s\n", "[DEBUG] Segment accepted by filter.");
@@ -489,14 +478,14 @@ endFn:
/** Gets called for every resource to scan/download.
* HINT: Gets called recursively. */
-static ssize_t gateleenResclone_download( cls_dload_t*dload , cls_resourceDir_t*parentResourceDir , char*entryName ){
+static ssize_t gateleenResclone_download( ClsDload*dload , ResourceDir*parentResourceDir , char*entryName ){
ssize_t err;
char *url = NULL;
int url_len = 0;
cJSON *jsonRoot = NULL;
int resUrl_len = 0;
- cls_resourceDir_t *resourceDir = NULL;
- cls_resourceFile_t *resourceFile = NULL;
+ ResourceDir *resourceDir = NULL;
+ ResourceFile *resourceFile = NULL;
if( entryName == NULL ){
/* Is the case when its the root call and not a recursive one */
@@ -504,7 +493,7 @@ static ssize_t gateleenResclone_download( cls_dload_t*dload , cls_resourceDir_t*
}
// Stack-Alloc resourceDir-closure.
- cls_resourceDir_t _1={0}; resourceDir =&_1;
+ ResourceDir _1 = {0}; resourceDir = &_1;
resourceDir->dload = dload;
resourceDir->parentDir = parentResourceDir;
resourceDir->name = strdup(entryName);
@@ -512,13 +501,13 @@ static ssize_t gateleenResclone_download( cls_dload_t*dload , cls_resourceDir_t*
// Configure client
{
url_len = 0;
- for( cls_resourceDir_t*d=resourceDir ; d ; d=d->parentDir ){
+ for( ResourceDir*d=resourceDir ; d ; d=d->parentDir ){
int len = strlen(d->name) - strspn(d->name, "/");
url_len += len;
}
url = malloc(url_len +1 /*MayPreventReallocLaterForName*/+24);
char *u = url + url_len;
- for( cls_resourceDir_t*d=resourceDir ; d ; d=d->parentDir ){
+ for( ResourceDir*d=resourceDir ; d ; d=d->parentDir ){
char *name = d->name + strspn(d->name, "/");
int name_len = strlen(name);
memcpy(u-name_len, name, name_len); u -= name_len;
@@ -574,7 +563,7 @@ static ssize_t gateleenResclone_download( cls_dload_t*dload , cls_resourceDir_t*
}
// Iterate all the entries we have to process.
- cls_resourceFile_t _2 = {0}; resourceFile =&_2;
+ ResourceFile _2 = {0}; resourceFile =&_2;
resourceFile->dload = dload;
uint_t iDirEntry = 0;
for( cJSON *arrEntry=data->child ; arrEntry!=NULL ; arrEntry=arrEntry->next ){
@@ -588,21 +577,21 @@ static ssize_t gateleenResclone_download( cls_dload_t*dload , cls_resourceDir_t*
int name_len = strlen(name);
err = pathFilterAcceptsEntry(dload, resourceDir, name);
- if( err < 0 ){ // ERROR
+ if( err < 0 ){ /* ERROR */
goto endFn;
- }else if( err == 0 ){ // REJECT
+ }else if( err == 0 ){ /* REJECT */
fprintf(stderr, "%s%s%s%s\n", "[INFO ] Skip '", url, name, "' (filtered)");
continue;
- }else{ // ACCEPT
- // Go ahead.
+ }else{ /* ACCEPT */
+ /* Go ahead */
}
- if( name[name_len-1] == '/' ){ // Gateleen reports a 'directory'
+ if( name[name_len-1] == '/' ){ /* Gateleen reports a 'directory' */
//fprintf(stderr, "%s%s%s%s\n", "[DEBUG] Scan '", url, name,"'");
err = gateleenResclone_download(dload, resourceDir, name);
if( err ){
goto endFn; }
- }else{ // Not a 'dir'? Then assume 'file'
+ }else{ /* Not a 'dir'? Then assume 'file' */
int requiredLen = url_len + 1/*slash*/ + name_len;
if( resUrl_len < requiredLen ){
void *tmp = realloc(resourceFile->url, requiredLen +1);
@@ -637,36 +626,36 @@ endFn:
}
-static void this_free( this_t*this ){
- if( this == NULL ) return;
+static void Resclone_free( Resclone*resclone ){
+ if( resclone == NULL ) return;
// TODO need free? -> char *url;
// TODO need free? -> regex_t *filter;
// TODO need free? -> char *file;
- free(this);
+ free(resclone);
}
-static this_t* this_alloc(){
+static Resclone* Resclone_alloc(){
ssize_t err;
- this_t *this = NULL;
+ Resclone *resclone = NULL;
err = curl_global_init(CURL_GLOBAL_ALL);
if( err ){
assert(!err); goto fail; }
- this = calloc(1, sizeof*this);
+ resclone = calloc(1, sizeof*resclone);
- return this;
+ return resclone;
fail:
- this_free(this);
+ Resclone_free(resclone);
return NULL;
}
-static size_t onUploadChunkRequested( char*buf, size_t size, size_t count, void*cls_put_ ){
+static size_t onUploadChunkRequested( char*buf, size_t size, size_t count, void*Put_ ){
int err;
- cls_put_t *put = cls_put_;
- cls_upload_t *upload = put->upload;
+ Put *put = Put_;
+ Upload *upload = put->upload;
const size_t buf_len = size * count;
ssize_t readLen = archive_read_data(upload->srcArchive, buf, buf_len);
@@ -691,10 +680,10 @@ endFn:
}
-static ssize_t addContentTypeHeader( cls_put_t*put, struct curl_slist *reqHdrs ){
+static ssize_t addContentTypeHeader( Put*put, struct curl_slist *reqHdrs ){
ssize_t err;
char *contentTypeHdr = NULL;
- cls_upload_t *upload = put->upload;
+ Upload *upload = put->upload;
const char *name = put->name;
uint_t name_len = strlen(put->name);
@@ -737,9 +726,9 @@ endFn:
}
-static ssize_t httpPutEntry( cls_put_t*put ){
+static ssize_t httpPutEntry( Put*put ){
ssize_t err;
- cls_upload_t *upload = put->upload;
+ Upload *upload = put->upload;
char *url = NULL;
struct curl_slist *reqHdrs = NULL;
@@ -782,9 +771,9 @@ endFn:
}
-static ssize_t readArchive( cls_upload_t*upload ){
+static ssize_t readArchive( Upload*upload ){
ssize_t err;
- cls_put_t *put = NULL;
+ Put *put = NULL;
upload->srcArchive = archive_read_new();
if( ! upload->srcArchive ){
@@ -816,7 +805,7 @@ static ssize_t readArchive( cls_upload_t*upload ){
continue;
}
//fprintf(stderr, "%s%s%s\n", "[DEBUG] Reading '",name,"'");
- cls_put_t _1 = {
+ Put _1 = {
.upload = upload,
.name = (char*)name
}; put = &_1;
@@ -833,22 +822,22 @@ endFn:
}
-static ssize_t pull( this_t*this ){
+static ssize_t pull( Resclone*resclone ){
ssize_t err;
- cls_dload_t *dload = NULL;
+ ClsDload *dload = NULL;
- if( this->file == NULL && isatty(1) ){
+ if( resclone->file == NULL && isatty(1) ){
fprintf(stderr, "%s\n",
"[ERROR] Are you sure you wanna write binary content to tty?");
err = -1; goto endFn;
}
- cls_dload_t _1 = {0}; dload =&_1;
- dload->this = this;
- dload->rootUrl = this->url;
- dload->archiveFile = this->file;
+ ClsDload _1 = {0}; dload =&_1;
+ dload->resclone = resclone;
+ dload->rootUrl = resclone->url;
+ dload->archiveFile = resclone->file;
dload->curl = curl_easy_init();
- if( ! dload->curl ){
+ if( dload->curl == NULL ){
fprintf(stderr, "%s\n", "[ERROR] curl_easy_init() -> NULL");
err = -1; goto endFn;
}
@@ -874,14 +863,14 @@ endFn:
}
-static ssize_t push( this_t*this ){
+static ssize_t push( Resclone*resclone ){
ssize_t err;
- cls_upload_t *upload = NULL;
+ Upload *upload = NULL;
- cls_upload_t _1={0}; upload =&_1;
- upload->this = this;
- upload->archiveFile = this->file;
- upload->rootUrl = this->url;
+ Upload _1={0}; upload =&_1;
+ upload->resclone = resclone;
+ upload->archiveFile = resclone->file;
+ upload->rootUrl = resclone->url;
upload->curl = curl_easy_init();
if( ! upload->curl ){
fprintf(stderr, "%s\n", "[ERROR] curl_easy_init() -> NULL");
@@ -904,31 +893,31 @@ endFn:
ssize_t gateleenResclone_run( int argc, char**argv ){
ssize_t err;
- this_t *this = NULL;
+ Resclone *resclone = NULL;
- this = this_alloc();
- if( this == NULL ){
+ resclone = Resclone_alloc();
+ if( resclone == NULL ){
err = -1; goto endFn; }
- err = parseArgs(argc, argv, &this->mode, &this->url, &this->filter,
- &this->filter_len, &this->isFilterFull, &this->file);
+ err = parseArgs(argc, argv, &resclone->mode, &resclone->url, &resclone->filter,
+ &resclone->filter_len, &resclone->isFilterFull, &resclone->file);
if( err ){
err = -1; goto endFn; }
- if( this->mode == MODE_FETCH ){
- err = pull(this); goto endFn;
- }else if( this->mode == MODE_PUSH ){
- err = push(this); goto endFn;
+ if( resclone->mode == MODE_FETCH ){
+ err = pull(resclone); goto endFn;
+ }else if( resclone->mode == MODE_PUSH ){
+ err = push(resclone); goto endFn;
}else{
err = -1; goto endFn;
}
assert(!"Unreachable");
endFn:
- parseArgs(-1, argv, &this->mode, &this->url, &this->filter, &this->filter_len,
- &this->isFilterFull, &this->file);
- this->mode = MODE_NULL; this->url = NULL; this->file = NULL;
- this_free(this);
+ parseArgs(-1, argv, &resclone->mode, &resclone->url, &resclone->filter, &resclone->filter_len,
+ &resclone->isFilterFull, &resclone->file);
+ resclone->mode = MODE_NULL; resclone->url = NULL; resclone->file = NULL;
+ Resclone_free(resclone);
return err;
}