|
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 NODE_H |
|
30 #define NODE_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 DavNodeData DavNodeData; |
|
50 typedef struct DavProperty DavProperty; |
|
51 |
|
52 typedef size_t(*dav_read_func)(void*, size_t, size_t, void*); |
|
53 typedef size_t(*dav_write_func)(const void*, size_t, size_t, void*); |
|
54 |
|
55 struct DavNamespace { |
|
56 char *prefix; |
|
57 char *name; |
|
58 }; |
|
59 |
|
60 struct DavResource { |
|
61 DavSession *session; |
|
62 DavResource *prev; |
|
63 DavResource *next; |
|
64 DavResource *parent; |
|
65 DavResource *children; |
|
66 char *name; |
|
67 char *path; |
|
68 char *href; |
|
69 uint64_t contentlength; |
|
70 char *contenttype; |
|
71 time_t creationdate; |
|
72 time_t lastmodified; |
|
73 DavNodeData *data; |
|
74 int iscollection; |
|
75 }; |
|
76 |
|
77 struct DavSession { |
|
78 DavContext *context; |
|
79 CURL *handle; |
|
80 char *base_url; |
|
81 UcxMempool *mp; |
|
82 UcxAllocator *allocator; |
|
83 int error; |
|
84 }; |
|
85 |
|
86 struct DavContext { |
|
87 UcxMap *namespaces; |
|
88 }; |
|
89 |
|
90 struct dav_content_data { |
|
91 char *data; |
|
92 size_t length; |
|
93 }; |
|
94 |
|
95 struct dav_content_stream { |
|
96 void *stream; |
|
97 read_func read; |
|
98 }; |
|
99 |
|
100 struct DavNodeData { |
|
101 UcxMap *properties; |
|
102 UcxList *set; |
|
103 UcxList *remove; |
|
104 |
|
105 /* |
|
106 * char* or stream |
|
107 */ |
|
108 void *content; |
|
109 /* |
|
110 * if NULL, content is a char* |
|
111 */ |
|
112 read_func read; |
|
113 /* |
|
114 * content length |
|
115 */ |
|
116 size_t length; |
|
117 }; |
|
118 |
|
119 struct DavProperty { |
|
120 DavNamespace *ns; |
|
121 char *name; |
|
122 char *value; |
|
123 }; |
|
124 |
|
125 DavContext* dav_context_new(); |
|
126 int dav_add_namespace(DavContext *context, char *prefix, char *ns); |
|
127 DavNamespace* dav_get_namespace(DavContext *context, char *prefix); |
|
128 |
|
129 DavSession* dav_session_new(DavContext *context, char *base_url); |
|
130 DavSession* dav_session_new_auth(DavContext *context, char *base_url, char *user, char *password); |
|
131 void dav_session_set_auth(DavSession *sn, char *user, char *password); |
|
132 |
|
133 DavResource* dav_get(DavSession *sn, char *path, char *properties); |
|
134 |
|
135 UcxList* parse_properties_string(DavContext *context, sstr_t str); |
|
136 |
|
137 |
|
138 DavResource* dav_resource_new(DavSession *sn, char *path); |
|
139 DavResource* resource_new_href(DavSession *sn, char *href); |
|
140 |
|
141 void resource_add_property(DavResource *res, char *ns, char *name, char *value); |
|
142 void resource_add_child(DavResource *parent, DavResource *child); |
|
143 UcxKey dav_property_key(char *ns, char *name); |
|
144 void resource_set_info(DavResource *res, char *href); |
|
145 DavNodeData* node_data_new(DavSession *sn); |
|
146 |
|
147 int dav_load(DavResource *res); |
|
148 int dav_store(DavResource *res); |
|
149 |
|
150 char* dav_get_property_ns(DavResource *res, char *ns, char *name); |
|
151 void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value); |
|
152 void dav_remove_property_ns(DavResource *res, char *ns, char *name, char *value); |
|
153 |
|
154 |
|
155 |
|
156 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func); |
|
157 void dav_set_content_data(DavResource *res, char *content, size_t length); |
|
158 |
|
159 int dav_get_content(DavResource *res, void *stream, dav_write_func write_func); |
|
160 |
|
161 #ifdef __cplusplus |
|
162 } |
|
163 #endif |
|
164 |
|
165 #endif /* NODE_H */ |
|
166 |