csync_owncloud.h

Go to the documentation of this file.
00001 /*
00002  * libcsync -- a library to sync a directory with another
00003  *
00004  * Copyright (c) 2011      by Andreas Schneider <asn@cryptomilk.org>
00005  * Copyright (c) 2012      by Klaas Freitag <freitag@owncloud.com>
00006  *
00007  * This program is free software = NULL, you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation = NULL, either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY = NULL, without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program = NULL, if not, write to the Free Software Foundation,
00019  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  */
00021 #ifndef CSYNC_OWNCLOUD_H
00022 #define CSYNC_OWNCLOUD_H
00023 
00024 #include <errno.h>
00025 #include <stdio.h>
00026 #include <time.h>
00027 #include <limits.h>
00028 #include <stdlib.h>
00029 
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <fcntl.h>
00033 
00034 #include "config.h"
00035 #ifdef NEON_WITH_LFS /* Switch on LFS in libneon. Never remove the NE_LFS! */
00036 #define NE_LFS
00037 #endif
00038 
00039 #include <neon/ne_basic.h>
00040 #include <neon/ne_socket.h>
00041 #include <neon/ne_session.h>
00042 #include <neon/ne_request.h>
00043 #include <neon/ne_props.h>
00044 #include <neon/ne_auth.h>
00045 #include <neon/ne_dates.h>
00046 #include <neon/ne_compress.h>
00047 #include <neon/ne_redirect.h>
00048 
00049 
00050 #include "c_rbtree.h"
00051 
00052 #include "c_lib.h"
00053 #include "csync.h"
00054 #include "csync_misc.h"
00055 #include "csync_macros.h"
00056 #include "c_private.h"
00057 #include "httpbf.h"
00058 
00059 #include "vio/csync_vio_module.h"
00060 #include "vio/csync_vio_file_stat.h"
00061 #include "vio/csync_vio.h"
00062 
00063 #include "csync_log.h"
00064 
00065 
00066 #define DEBUG_WEBDAV(...) csync_log( dav_session.csync_ctx, 9, "oc_module", __VA_ARGS__);
00067 
00068 enum resource_type {
00069     resr_normal = 0,
00070     resr_collection,
00071     resr_reference,
00072     resr_error
00073 };
00074 
00075 #define DAV_STRTOL strtoll
00076 
00077 /* Struct to store data for each resource found during an opendir operation.
00078  * It represents a single file entry.
00079  */
00080 
00081 typedef struct resource {
00082     char *uri;           /* The complete uri */
00083     char *name;          /* The filename only */
00084 
00085     enum resource_type type;
00086     int64_t              size;
00087     time_t             modtime;
00088     char*              md5;
00089 
00090     struct resource    *next;
00091 } resource;
00092 
00093 /* Struct to hold the context of a WebDAV PropFind operation to fetch
00094  * a directory listing from the server.
00095  */
00096 struct listdir_context {
00097     struct resource *list;           /* The list of result resources */
00098     struct resource *currResource;   /* A pointer to the current resource */
00099     char            *target;        /* Request-URI of the PROPFIND */
00100     unsigned int     result_count;   /* number of elements stored in list */
00101     int ref; /* reference count, only destroy when it reaches 0 */
00102 };
00103 
00104 
00105 /* Our cache, key is a char* */
00106 extern c_rbtree_t *propfind_recursive_cache;
00107 /* Values are propfind_recursive_element: */
00108 struct propfind_recursive_element {
00109     struct resource *self;
00110     struct resource *children;
00111 };
00112 typedef struct propfind_recursive_element propfind_recursive_element_t;
00113 void clear_propfind_recursive_cache(void);
00114 struct listdir_context *get_listdir_context_from_cache(const char *curi);
00115 struct listdir_context *fetch_resource_list_recursive(const char *uri, const char *curi);
00116 
00117 
00118 /*
00119  * context to store info about a temp file for GET and PUT requests
00120  * which store the data in a local file to save memory and secure the
00121  * transmission.
00122  */
00123 struct transfer_context {
00124     ne_request *req;            /* the neon request */
00125     int         fd;             /* file descriptor of the file to read or write from */
00126     const char  *method;        /* the HTTP method, either PUT or GET  */
00127     ne_decompress *decompress;  /* the decompress context */
00128     char        *url;
00129 
00130     /* Used for limiting the bandwidth */
00131     struct timeval last_time;
00132     ne_off_t last_progress;
00133     int64_t get_size;
00134 };
00135 
00136 typedef int (*csync_owncloud_redirect_callback_t)(CSYNC* ctx, const char* uri);
00137 
00138 /* Struct with the WebDAV session */
00139 struct dav_session_s {
00140     ne_session *ctx;
00141     char *user;
00142     char *pwd;
00143 
00144     char *proxy_type;
00145     char *proxy_host;
00146     int   proxy_port;
00147     char *proxy_user;
00148     char *proxy_pwd;
00149 
00150     char *session_key;
00151 
00152     char *error_string;
00153 
00154     int read_timeout;
00155 
00156     CSYNC *csync_ctx;
00157 
00158     csync_hbf_info_t *chunk_info;
00159 
00160     bool no_recursive_propfind;
00161     int64_t hbf_block_size;
00162     int64_t hbf_threshold;
00163 
00164     /* If 0, it is disabled.   If >0,  in Byte/seconds. If < 0,  in % of the available bandwidth*/
00165     int bandwidth_limit_upload;
00166     int bandwidth_limit_download;
00167 
00168     csync_overall_progress_t *overall_progress_data;
00169     csync_owncloud_redirect_callback_t redir_callback;
00170 };
00171 extern struct dav_session_s dav_session;
00172 
00173 /* The list of properties that is fetched in PropFind on a collection */
00174 static const ne_propname ls_props[] = {
00175     { "DAV:", "getlastmodified" },
00176     { "DAV:", "getcontentlength" },
00177     { "DAV:", "resourcetype" },
00178     { "DAV:", "getetag"},
00179     { NULL, NULL }
00180 };
00181 
00182 void set_errno_from_http_errcode( int err );
00183 void set_error_message( const char *msg );
00184 void set_errno_from_neon_errcode( int neon_code );
00185 int http_result_code_from_session(void);
00186 void set_errno_from_session(void);
00187 
00188 time_t oc_httpdate_parse( const char *date );
00189 
00190 char *_cleanPath( const char* uri );
00191 
00192 int _stat_perms( int type );
00193 csync_vio_file_stat_t *resourceToFileStat( struct resource *res );
00194 
00195 void oc_notify_progress(const char *file, enum csync_notify_type_e kind, int64_t current_size, int64_t full_size);
00196 
00197 #endif /* CSYNC_OWNCLOUD_H */

Generated on Mon Oct 21 19:24:18 2013 for doc by  doxygen 1.5.6