From 9a7fbd4f71a9cabbdee86c68d954fe811a347484 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 4 Jun 2014 12:04:36 +0200 Subject: [PATCH] csync_owncloud: Parse properties in one function --- csync/src/csync_owncloud.c | 49 +----------------- csync/src/csync_owncloud_private.h | 2 + csync/src/csync_owncloud_recursive_propfind.c | 48 ++---------------- csync/src/csync_owncloud_util.c | 50 +++++++++++++++++++ 4 files changed, 56 insertions(+), 93 deletions(-) diff --git a/csync/src/csync_owncloud.c b/csync/src/csync_owncloud.c index 29e0b21d2..5aa01f92b 100644 --- a/csync/src/csync_owncloud.c +++ b/csync/src/csync_owncloud.c @@ -486,20 +486,10 @@ static void propfind_results_callback(void *userdata, { struct listdir_context *fetchCtx = userdata; struct resource *newres = 0; - const char *clength, *modtime = NULL; - const char *resourcetype = NULL; - const char *md5sum = NULL; - const char *file_id = NULL; - const char *directDownloadUrl = NULL; - const char *directDownloadCookies = NULL; const ne_status *status = NULL; char *path = ne_path_unescape( uri->path ); (void) status; - if( ! fetchCtx ) { - DEBUG_WEBDAV("No valid fetchContext"); - return; - } if( ! fetchCtx->target ) { DEBUG_WEBDAV("error: target must not be zero!" ); @@ -508,46 +498,9 @@ static void propfind_results_callback(void *userdata, /* Fill the resource structure with the data about the file */ newres = c_malloc(sizeof(struct resource)); - ZERO_STRUCTP(newres); newres->uri = path; /* no need to strdup because ne_path_unescape already allocates */ newres->name = c_basename( path ); - - modtime = ne_propset_value( set, &ls_props[0] ); - clength = ne_propset_value( set, &ls_props[1] ); - resourcetype = ne_propset_value( set, &ls_props[2] ); - md5sum = ne_propset_value( set, &ls_props[3] ); - file_id = ne_propset_value( set, &ls_props[4] ); - directDownloadUrl = ne_propset_value( set, &ls_props[5] ); - directDownloadCookies = ne_propset_value( set, &ls_props[6] ); - - newres->type = resr_normal; - if( clength == NULL && resourcetype && strncmp( resourcetype, "", 16 ) == 0) { - newres->type = resr_collection; - } - - if (modtime) { - newres->modtime = oc_httpdate_parse(modtime); - } - - /* DEBUG_WEBDAV("Parsing Modtime: %s -> %llu", modtime, (unsigned long long) newres->modtime ); */ - newres->size = 0; - if (clength) { - newres->size = atoll(clength); - /* DEBUG_WEBDAV("Parsed File size for %s from %s: %lld", newres->name, clength, (long long)newres->size ); */ - } - - if( md5sum ) { - newres->md5 = csync_normalize_etag(md5sum); - } - - csync_vio_set_file_id(newres->file_id, file_id); - - if (directDownloadUrl) { - newres->directDownloadUrl = c_strdup(directDownloadUrl); - } - if (directDownloadCookies) { - newres->directDownloadCookies = c_strdup(directDownloadCookies); - } + fill_webdav_properties_into_resource(newres, set); /* prepend the new resource to the result list */ newres->next = fetchCtx->list; diff --git a/csync/src/csync_owncloud_private.h b/csync/src/csync_owncloud_private.h index 9e262be5c..67eedc415 100644 --- a/csync/src/csync_owncloud_private.h +++ b/csync/src/csync_owncloud_private.h @@ -187,6 +187,8 @@ time_t oc_httpdate_parse( const char *date ); char *_cleanPath( const char* uri ); int _stat_perms( int type ); +void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop_result_set *set); + void resourceToFileStat( csync_vio_file_stat_t *lfs, struct resource *res ); void resource_free(struct resource* o); struct resource* resource_dup(struct resource* o); diff --git a/csync/src/csync_owncloud_recursive_propfind.c b/csync/src/csync_owncloud_recursive_propfind.c index af06d38a5..fb0dbdb57 100644 --- a/csync/src/csync_owncloud_recursive_propfind.c +++ b/csync/src/csync_owncloud_recursive_propfind.c @@ -98,11 +98,7 @@ static void propfind_results_recursive_callback(void *userdata, const ne_prop_result_set *set) { struct resource *newres = 0; - const char *clength, *modtime, *file_id = NULL; - const char *directDownloadUrl = NULL; - const char *directDownloadCookies = NULL; - const char *resourcetype = NULL; - const char *md5sum = NULL; + const ne_status *status = NULL; char *path = ne_path_unescape( uri->path ); char *parentPath; @@ -120,55 +116,17 @@ static void propfind_results_recursive_callback(void *userdata, /* Fill the resource structure with the data about the file */ newres = c_malloc(sizeof(struct resource)); - ZERO_STRUCTP(newres); newres->uri = path; /* no need to strdup because ne_path_unescape already allocates */ newres->name = c_basename( path ); + fill_webdav_properties_into_resource(newres, set); - modtime = ne_propset_value( set, &ls_props[0] ); - clength = ne_propset_value( set, &ls_props[1] ); - resourcetype = ne_propset_value( set, &ls_props[2] ); - md5sum = ne_propset_value( set, &ls_props[3] ); - file_id = ne_propset_value( set, &ls_props[4] ); - directDownloadUrl = ne_propset_value( set, &ls_props[5] ); - directDownloadCookies = ne_propset_value( set, &ls_props[6] ); - - newres->type = resr_normal; - if( resourcetype && strncmp( resourcetype, "", 16 ) == 0) { - newres->type = resr_collection; + if( newres->type == resr_collection) { ctx->propfind_recursive_cache_folder_count++; } else { - /* DEBUG_WEBDAV("propfind_results_recursive %s [%d]", newres->uri, newres->type); */ ctx->propfind_recursive_cache_file_count++; } - if (modtime) { - newres->modtime = oc_httpdate_parse(modtime); - } - - /* DEBUG_WEBDAV("Parsing Modtime: %s -> %llu", modtime, (unsigned long long) newres->modtime ); */ - newres->size = 0; - if (clength) { - newres->size = atoll(clength); - /* DEBUG_WEBDAV("Parsed File size for %s from %s: %lld", newres->name, clength, (long long)newres->size ); */ - } - - if( md5sum ) { - newres->md5 = csync_normalize_etag(md5sum); - } - - csync_vio_set_file_id(newres->file_id, file_id); - /* - DEBUG_WEBDAV("propfind_results_recursive %s [%s] %s", newres->uri, newres->type == resr_collection ? "collection" : "file", newres->md5); - */ - - if (directDownloadUrl) { - newres->directDownloadUrl = c_strdup(directDownloadUrl); - } - if (directDownloadCookies) { - newres->directDownloadCookies = c_strdup(directDownloadCookies); - } - /* Create new item in rb tree */ if (newres->type == resr_collection) { DEBUG_WEBDAV("propfind_results_recursive %s is a folder", newres->uri); diff --git a/csync/src/csync_owncloud_util.c b/csync/src/csync_owncloud_util.c index 3dbd75efe..7840cd089 100644 --- a/csync/src/csync_owncloud_util.c +++ b/csync/src/csync_owncloud_util.c @@ -343,6 +343,56 @@ int _stat_perms( int type ) { return ret; } +void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop_result_set *set) +{ + const char *clength, *modtime, *file_id = NULL; + const char *directDownloadUrl = NULL; + const char *directDownloadCookies = NULL; + const char *resourcetype = NULL; + const char *etag = NULL; + + modtime = ne_propset_value( set, &ls_props[0] ); + clength = ne_propset_value( set, &ls_props[1] ); + resourcetype = ne_propset_value( set, &ls_props[2] ); + etag = ne_propset_value( set, &ls_props[3] ); + file_id = ne_propset_value( set, &ls_props[4] ); + directDownloadUrl = ne_propset_value( set, &ls_props[5] ); + directDownloadCookies = ne_propset_value( set, &ls_props[6] ); + + if( resourcetype && strncmp( resourcetype, "", 16 ) == 0) { + newres->type = resr_collection; + } else { + newres->type = resr_normal; + } + + if (modtime) { + newres->modtime = oc_httpdate_parse(modtime); + } + + /* DEBUG_WEBDAV("Parsing Modtime: %s -> %llu", modtime, (unsigned long long) newres->modtime ); */ + newres->size = 0; + if (clength) { + newres->size = atoll(clength); + /* DEBUG_WEBDAV("Parsed File size for %s from %s: %lld", newres->name, clength, (long long)newres->size ); */ + } + + if( etag ) { + newres->md5 = csync_normalize_etag(etag); + } + + csync_vio_set_file_id(newres->file_id, file_id); + /* + DEBUG_WEBDAV("propfind_results_recursive %s [%s] %s", newres->uri, newres->type == resr_collection ? "collection" : "file", newres->md5); + */ + + if (directDownloadUrl) { + newres->directDownloadUrl = c_strdup(directDownloadUrl); + } + if (directDownloadCookies) { + newres->directDownloadCookies = c_strdup(directDownloadCookies); + } +} + struct resource* resource_dup(struct resource* o) { struct resource *r = c_malloc (sizeof( struct resource )); ZERO_STRUCTP(r);