doc
csync_owncloud.h
Go to the documentation of this file.
1 /*
2  * libcsync -- a library to sync a directory with another
3  *
4  * Copyright (c) 2011 by Andreas Schneider <asn@cryptomilk.org>
5  * Copyright (c) 2012 by Klaas Freitag <freitag@owncloud.com>
6  *
7  * This program is free software = NULL, you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation = NULL, either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY = NULL, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program = NULL, if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 #ifndef CSYNC_OWNCLOUD_H
22 #define CSYNC_OWNCLOUD_H
23 
24 #include <errno.h>
25 #include <stdio.h>
26 #include <time.h>
27 #include <limits.h>
28 #include <stdlib.h>
29 
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 
34 #include "config.h"
35 #ifdef NEON_WITH_LFS /* Switch on LFS in libneon. Never remove the NE_LFS! */
36 #define NE_LFS
37 #endif
38 
39 #include <neon/ne_basic.h>
40 #include <neon/ne_socket.h>
41 #include <neon/ne_session.h>
42 #include <neon/ne_request.h>
43 #include <neon/ne_props.h>
44 #include <neon/ne_auth.h>
45 #include <neon/ne_dates.h>
46 #include <neon/ne_compress.h>
47 #include <neon/ne_redirect.h>
48 
49 
50 #include "c_rbtree.h"
51 
52 #include "c_lib.h"
53 #include "csync.h"
54 #include "csync_misc.h"
55 #include "csync_macros.h"
56 #include "c_private.h"
57 #include "httpbf.h"
58 
59 #include "vio/csync_vio_module.h"
61 #include "vio/csync_vio.h"
62 
63 #include "csync_log.h"
64 
65 
66 #define DEBUG_WEBDAV(...) csync_log( dav_session.csync_ctx, 9, "oc_module", __VA_ARGS__);
67 
73 };
74 
75 #define DAV_STRTOL strtoll
76 
77 /* Struct to store data for each resource found during an opendir operation.
78  * It represents a single file entry.
79  */
80 
81 typedef struct resource {
82  char *uri; /* The complete uri */
83  char *name; /* The filename only */
84 
86  int64_t size;
87  time_t modtime;
88  char* md5;
89 
90  struct resource *next;
91 } resource;
92 
93 /* Struct to hold the context of a WebDAV PropFind operation to fetch
94  * a directory listing from the server.
95  */
97  struct resource *list; /* The list of result resources */
98  struct resource *currResource; /* A pointer to the current resource */
99  char *target; /* Request-URI of the PROPFIND */
100  unsigned int result_count; /* number of elements stored in list */
101  int ref; /* reference count, only destroy when it reaches 0 */
102 };
103 
104 
105 /* Our cache, key is a char* */
107 /* Values are propfind_recursive_element: */
109  struct resource *self;
111 };
114 struct listdir_context *get_listdir_context_from_cache(const char *curi);
115 struct listdir_context *fetch_resource_list_recursive(const char *uri, const char *curi);
116 
117 
118 /*
119  * context to store info about a temp file for GET and PUT requests
120  * which store the data in a local file to save memory and secure the
121  * transmission.
122  */
124  ne_request *req; /* the neon request */
125  int fd; /* file descriptor of the file to read or write from */
126  const char *method; /* the HTTP method, either PUT or GET */
127  ne_decompress *decompress; /* the decompress context */
128  char *url;
129 
130  /* Used for limiting the bandwidth */
131  struct timeval last_time;
132  ne_off_t last_progress;
133  int64_t get_size;
134 };
135 
136 typedef int (*csync_owncloud_redirect_callback_t)(CSYNC* ctx, const char* uri);
137 
138 /* Struct with the WebDAV session */
140  ne_session *ctx;
141  char *user;
142  char *pwd;
143 
144  char *proxy_type;
145  char *proxy_host;
147  char *proxy_user;
148  char *proxy_pwd;
149 
150  char *session_key;
151 
153 
155 
157 
159 
161  int64_t hbf_block_size;
162  int64_t hbf_threshold;
163 
164  /* If 0, it is disabled. If >0, in Byte/seconds. If < 0, in % of the available bandwidth*/
167 
170 };
171 extern struct dav_session_s dav_session;
172 
173 /* The list of properties that is fetched in PropFind on a collection */
174 static const ne_propname ls_props[] = {
175  { "DAV:", "getlastmodified" },
176  { "DAV:", "getcontentlength" },
177  { "DAV:", "resourcetype" },
178  { "DAV:", "getetag"},
179  { NULL, NULL }
180 };
181 
182 void set_errno_from_http_errcode( int err );
183 void set_error_message( const char *msg );
184 void set_errno_from_neon_errcode( int neon_code );
186 void set_errno_from_session(void);
187 
188 time_t oc_httpdate_parse( const char *date );
189 
190 char *_cleanPath( const char* uri );
191 
192 int _stat_perms( int type );
194 
195 void oc_notify_progress(const char *file, enum csync_notify_type_e kind, int64_t current_size, int64_t full_size);
196 
197 #endif /* CSYNC_OWNCLOUD_H */
char * _cleanPath(const char *uri)
struct timeval last_time
time_t modtime
Application developer interface for csync.
csync_overall_progress_t * overall_progress_data
ne_off_t last_progress
char * md5
int type
Definition: csync_private.h:72
time_t oc_httpdate_parse(const char *date)
ne_request * req
csync_notify_type_e
Definition: csync.h:120
void oc_notify_progress(const char *file, enum csync_notify_type_e kind, int64_t current_size, int64_t full_size)
int(* csync_owncloud_redirect_callback_t)(CSYNC *ctx, const char *uri)
ne_decompress * decompress
struct resource * currResource
int bandwidth_limit_download
void set_errno_from_session(void)
int _stat_perms(int type)
int64_t size
resource_type
void set_errno_from_neon_errcode(int neon_code)
struct dav_session_s dav_session
Structure that represents a red-black tree.
Definition: c_rbtree.h:111
Interface of the cynapses libc red-black tree implementation.
struct resource * list
csync_vio_file_stat_t * resourceToFileStat(struct resource *res)
struct resource * next
csync public structure
Definition: csync_private.h:88
int bandwidth_limit_upload
struct resource resource
csync_owncloud_redirect_callback_t redir_callback
void set_errno_from_http_errcode(int err)
struct resource * children
int64_t hbf_block_size
char * name
unsigned int result_count
void clear_propfind_recursive_cache(void)
c_rbtree_t * propfind_recursive_cache
const char * method
int64_t hbf_threshold
static const ne_propname ls_props[]
struct listdir_context * fetch_resource_list_recursive(const char *uri, const char *curi)
ne_session * ctx
bool no_recursive_propfind
char * uri
Logging interface of csync.
csync_hbf_info_t * chunk_info
enum resource_type type
int http_result_code_from_session(void)
void set_error_message(const char *msg)
struct listdir_context * get_listdir_context_from_cache(const char *curi)