libidav/utils.c

changeset 69
0dbdd7e8c1fc
parent 66
f8c1f685e08e
child 70
88092b88ec00
equal deleted inserted replaced
68:f6d3db6113d3 69:0dbdd7e8c1fc
201 curl_easy_setopt(sn->handle, CURLOPT_URL, url); 201 curl_easy_setopt(sn->handle, CURLOPT_URL, url);
202 free(url.ptr); 202 free(url.ptr);
203 } 203 }
204 204
205 char* util_path_to_url(DavSession *sn, char *path) { 205 char* util_path_to_url(DavSession *sn, char *path) {
206 UcxBuffer *url = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND); 206 char *space = malloc(256);
207 UcxBuffer *url = ucx_buffer_new(space, 256, UCX_BUFFER_AUTOEXTEND);
207 208
208 // add base url 209 // add base url
209 ucx_buffer_write(sn->base_url, 1, strlen(sn->base_url), url); 210 ucx_buffer_write(sn->base_url, 1, strlen(sn->base_url), url);
210 // remove trailing slash 211 // remove trailing slash
211 ucx_buffer_seek(url, -1, SEEK_CUR); 212 ucx_buffer_seek(url, -1, SEEK_CUR);
228 if(path[p.length-1] == '/') { 229 if(path[p.length-1] == '/') {
229 ucx_buffer_putc(url, '/'); 230 ucx_buffer_putc(url, '/');
230 } 231 }
231 ucx_buffer_putc(url, 0); 232 ucx_buffer_putc(url, 0);
232 233
233 // only free the buffer struct and return the buffer space 234 space = url->space;
234 char *space = url->space; 235 ucx_buffer_free(url);
235 free(url); 236
236 return space; 237 return space;
237 } 238 }
238 239
239 char* util_parent_path(char *path) { 240 char* util_parent_path(char *path) {
240 char *name = util_resource_name(path); 241 char *name = util_resource_name(path);

mercurial