|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2013 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef WEBDAV_H |
|
30 #define WEBDAV_H |
|
31 |
|
32 #include <inttypes.h> |
|
33 #include <ucx/map.h> |
|
34 #include <ucx/mempool.h> |
|
35 #include <ucx/list.h> |
|
36 #include <ucx/buffer.h> |
|
37 #include <curl/curl.h> |
|
38 #include <libxml/tree.h> |
|
39 |
|
40 #ifdef __cplusplus |
|
41 extern "C" { |
|
42 #endif |
|
43 |
|
44 typedef struct DavContext DavContext; |
|
45 typedef struct DavSession DavSession; |
|
46 typedef struct DavResource DavResource; |
|
47 typedef struct DavRequest DavRequest; |
|
48 typedef struct DavNamespace DavNamespace; |
|
49 typedef struct DavProperty DavProperty; |
|
50 |
|
51 #include "davql.h" |
|
52 |
|
53 typedef size_t(*dav_read_func)(void*, size_t, size_t, void*); |
|
54 typedef size_t(*dav_write_func)(const void*, size_t, size_t, void*); |
|
55 |
|
56 enum DavError { |
|
57 DAV_OK = 0, |
|
58 DAV_ERROR, |
|
59 DAV_NOT_FOUND, |
|
60 DAV_UNAUTHORIZED, |
|
61 DAV_FORBIDDEN, |
|
62 DAV_METHOD_NOT_ALLOWED, |
|
63 DAV_CONFLICT |
|
64 }; |
|
65 |
|
66 typedef enum DavError DavError; |
|
67 |
|
68 struct DavNamespace { |
|
69 char *prefix; |
|
70 char *name; |
|
71 }; |
|
72 |
|
73 struct DavResource { |
|
74 DavSession *session; |
|
75 DavResource *prev; |
|
76 DavResource *next; |
|
77 DavResource *parent; |
|
78 DavResource *children; |
|
79 char *name; |
|
80 char *path; |
|
81 char *href; |
|
82 uint64_t contentlength; |
|
83 char *contenttype; |
|
84 time_t creationdate; |
|
85 time_t lastmodified; |
|
86 void *data; |
|
87 int iscollection; |
|
88 }; |
|
89 |
|
90 struct DavSession { |
|
91 DavContext *context; |
|
92 CURL *handle; |
|
93 char *base_url; |
|
94 UcxMempool *mp; |
|
95 UcxAllocator *allocator; |
|
96 DavError error; |
|
97 const char *errorstr; |
|
98 }; |
|
99 |
|
100 struct DavContext { |
|
101 UcxMap *namespaces; |
|
102 UcxList *sessions; |
|
103 char *http_proxy; |
|
104 char *https_proxy; |
|
105 char *no_proxy; |
|
106 }; |
|
107 |
|
108 struct DavProperty { |
|
109 DavNamespace *ns; |
|
110 char *name; |
|
111 char *value; |
|
112 }; |
|
113 |
|
114 DavContext* dav_context_new(); |
|
115 void dav_context_destroy(DavContext *ctx); |
|
116 int dav_add_namespace(DavContext *context, char *prefix, char *ns); |
|
117 DavNamespace* dav_get_namespace(DavContext *context, char *prefix); |
|
118 |
|
119 DavSession* dav_session_new(DavContext *context, char *base_url); |
|
120 DavSession* dav_session_new_auth( |
|
121 DavContext *context, |
|
122 char *base_url, |
|
123 char *user, |
|
124 char *password); |
|
125 void dav_session_set_auth(DavSession *sn, char *user, char *password); |
|
126 |
|
127 void session_set_error(DavSession *sn, CURLcode c, int status); |
|
128 |
|
129 void dav_session_destroy(DavSession *sn); |
|
130 |
|
131 DavResource* dav_get(DavSession *sn, char *path, char *properties); |
|
132 DavResource* dav_get2(DavSession *sn, DavGetQuery *query); |
|
133 |
|
134 UcxList* parse_properties_string(DavContext *context, sstr_t str); |
|
135 |
|
136 DavResource* dav_query(DavSession *sn, char *query, ...); |
|
137 |
|
138 UcxKey dav_property_key(char *ns, char *name); |
|
139 void dav_get_property_namespace( |
|
140 DavContext *ctx, |
|
141 char *prefixed_name, |
|
142 char **ns, |
|
143 char **name); |
|
144 |
|
145 /* ------------------------ resource functions ------------------------ */ |
|
146 |
|
147 DavResource* dav_resource_new(DavSession *sn, char *path); |
|
148 DavResource* dav_resource_new_href(DavSession *sn, char *href); |
|
149 |
|
150 DavResource* dav_create_child(DavResource *parent, char *name); |
|
151 int dav_delete(DavResource *res); |
|
152 int dav_create(DavResource *res); |
|
153 int dav_exists(DavResource *res); |
|
154 |
|
155 char* dav_get_property(DavResource *res, char *name); |
|
156 char* dav_get_property_ns(DavResource *res, char *ns, char *name); |
|
157 void dav_set_property(DavResource *res, char *name, char *value); |
|
158 void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value); |
|
159 void dav_remove_property(DavResource *res, char *name); |
|
160 void dav_remove_property_ns(DavResource *res, char *ns, char *name); |
|
161 |
|
162 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func); |
|
163 void dav_set_content_data(DavResource *res, char *content, size_t length); |
|
164 |
|
165 int dav_load(DavResource *res); |
|
166 int dav_store(DavResource *res); |
|
167 int dav_get_content(DavResource *res, void *stream, dav_write_func write_func); |
|
168 |
|
169 #ifdef __cplusplus |
|
170 } |
|
171 #endif |
|
172 |
|
173 #endif /* WEBDAV_H */ |
|
174 |