[Pkg-owncloud-commits] [owncloud-client] 59/332: csync_owncloud: Parse properties in one function

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 9a7fbd4f71a9cabbdee86c68d954fe811a347484
Author: Markus Goetz <markus at woboq.com>
Date:   Wed Jun 4 12:04:36 2014 +0200

    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 29e0b21..5aa01f9 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, "<DAV:collection>", 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 9e262be..67eedc4 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 af06d38..fb0dbdb 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, "<DAV:collection>", 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 3dbd75e..7840cd0 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, "<DAV:collection>", 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list