77 |
77 |
78 return res; |
78 return res; |
79 } |
79 } |
80 |
80 |
81 DavResource* dav_resource_new_full(DavSession *sn, char *parent_path, char *name, char *href) { |
81 DavResource* dav_resource_new_full(DavSession *sn, char *parent_path, char *name, char *href) { |
|
82 sstr_t n = sstr(name); |
|
83 // the name must not contain path separators |
|
84 for(int i=0;i<n.length-1;i++) { |
|
85 char c = n.ptr[i]; |
|
86 if(c == '/' || c == '\\') { |
|
87 n = sstr(util_resource_name(href)); |
|
88 break; |
|
89 } |
|
90 } |
|
91 // remove trailing '/' |
|
92 if(n.length > 0 && n.ptr[n.length-1] == '/') { |
|
93 n.length--; |
|
94 } |
|
95 |
82 DavResource *res = ucx_mempool_calloc(sn->mp, 1, sizeof(DavResource)); |
96 DavResource *res = ucx_mempool_calloc(sn->mp, 1, sizeof(DavResource)); |
83 res->session = sn; |
97 res->session = sn; |
84 |
98 |
85 // set name, path and href |
99 // set name, path and href |
86 sstr_t n = sstr(name); |
|
87 res->name = sstrdup_a(sn->mp->allocator, n).ptr; |
100 res->name = sstrdup_a(sn->mp->allocator, n).ptr; |
88 if(n.length > 0 && n.ptr[n.length-1] == '/') { |
|
89 res->name[n.length-1] = '\0'; |
|
90 } |
|
91 |
101 |
92 char *path = util_concat_path(parent_path, name); |
102 char *path = util_concat_path(parent_path, name); |
93 res->path = dav_session_strdup(sn, path); |
103 res->path = dav_session_strdup(sn, path); |
94 |
104 |
95 res->href = href; |
105 res->href = href; |