68 dav_context_destroy(context); |
68 dav_context_destroy(context); |
69 return NULL; |
69 return NULL; |
70 } |
70 } |
71 |
71 |
72 // add DAV: namespace |
72 // add DAV: namespace |
73 DavNamespace *davns = malloc(sizeof(DavNamespace)); |
73 if(dav_add_namespace(context, "D", "DAV:")) { |
74 if(!davns) { |
74 dav_context_destroy(context); |
75 free(davns); |
75 return NULL; |
76 dav_context_destroy(context); |
76 } |
77 return NULL; |
77 |
78 } |
|
79 davns->prefix = strdup("D"); |
|
80 if(!davns->prefix) { |
|
81 free(davns); |
|
82 dav_context_destroy(context); |
|
83 return NULL; |
|
84 } |
|
85 davns->name = strdup("DAV:"); |
|
86 if(!davns->name) { |
|
87 free(davns->prefix); |
|
88 free(davns); |
|
89 dav_context_destroy(context); |
|
90 return NULL; |
|
91 } |
|
92 if(ucx_map_cstr_put(context->namespaces, "D", davns)) { |
|
93 free(davns->prefix); |
|
94 free(davns->name); |
|
95 free(davns); |
|
96 dav_context_destroy(context); |
|
97 return NULL; |
|
98 } |
|
99 |
78 |
100 // add idav namespace |
79 // add idav namespace |
101 DavNamespace *idavns = malloc(sizeof(DavNamespace)); |
80 if(dav_add_namespace(context, "idav", DAV_NS)) { |
102 if(!idavns) { |
81 dav_context_destroy(context); |
103 free(idavns); |
82 return NULL; |
104 dav_context_destroy(context); |
83 } |
105 return NULL; |
84 |
106 } |
85 // add idavprops namespace |
107 idavns->prefix = strdup("idav"); |
86 if(dav_add_namespace(context, "idavprops", DAV_PROPS_NS)) { |
108 if(!idavns->prefix) { |
87 dav_context_destroy(context); |
109 free(idavns); |
88 return NULL; |
110 dav_context_destroy(context); |
89 } |
111 return NULL; |
90 |
112 } |
|
113 idavns->name = strdup(DAV_NS); |
|
114 if(!idavns->name) { |
|
115 free(idavns->prefix); |
|
116 free(idavns); |
|
117 dav_context_destroy(context); |
|
118 return NULL; |
|
119 } |
|
120 if(ucx_map_cstr_put(context->namespaces, "idav", idavns)) { |
|
121 free(idavns->prefix); |
|
122 free(idavns->name); |
|
123 free(idavns); |
|
124 dav_context_destroy(context); |
|
125 return NULL; |
|
126 } |
|
127 |
|
128 return context; |
91 return context; |
129 } |
92 } |
130 |
93 |
131 void dav_context_destroy(DavContext *ctx) { |
94 void dav_context_destroy(DavContext *ctx) { |
132 // destroy all sessions assoziated with this context |
95 // destroy all sessions assoziated with this context |
193 int dav_add_namespace(DavContext *context, const char *prefix, const char *name) { |
156 int dav_add_namespace(DavContext *context, const char *prefix, const char *name) { |
194 DavNamespace *namespace = malloc(sizeof(DavNamespace)); |
157 DavNamespace *namespace = malloc(sizeof(DavNamespace)); |
195 if(!namespace) { |
158 if(!namespace) { |
196 return 1; |
159 return 1; |
197 } |
160 } |
198 namespace->prefix = strdup(prefix); |
161 |
199 namespace->name = strdup(name); |
162 char *p = strdup(prefix); |
200 return ucx_map_cstr_put(context->namespaces, prefix, namespace); |
163 char *n = strdup(name); |
|
164 |
|
165 int err = 0; |
|
166 if(p && n) { |
|
167 namespace->prefix = p; |
|
168 namespace->name = n; |
|
169 err = ucx_map_cstr_put(context->namespaces, prefix, namespace); |
|
170 } |
|
171 |
|
172 if(err) { |
|
173 free(namespace); |
|
174 if(p) free(p); |
|
175 if(n) free(n); |
|
176 } |
|
177 |
|
178 return err; |
201 } |
179 } |
202 |
180 |
203 DavNamespace* dav_get_namespace(DavContext *context, const char *prefix) { |
181 DavNamespace* dav_get_namespace(DavContext *context, const char *prefix) { |
204 return ucx_map_cstr_get(context->namespaces, prefix); |
182 return ucx_map_cstr_get(context->namespaces, prefix); |
205 } |
183 } |