--- a/libidav/utils.c Sun Sep 17 13:51:01 2023 +0200 +++ b/libidav/utils.c Sat Sep 30 16:33:47 2023 +0200 @@ -281,7 +281,7 @@ } } -char* util_url_base_s(cxstring url) { +cxstring util_url_base_s(cxstring url) { size_t i = 0; if(url.length > 0) { int slmax; @@ -303,12 +303,11 @@ } } } - cxstring server = cx_strsubsl(url, 0, i); - return cx_strdup(server).ptr; + return cx_strsubsl(url, 0, i); } -char* util_url_base(char *url) { - return util_url_base_s(cx_str(url)); +char* util_url_base(const char *url) { + return cx_strdup(util_url_base_s(cx_str(url))).ptr; } #ifdef _WIN32 @@ -316,30 +315,30 @@ #endif const char* util_url_path(const char *url) { - const char *path = NULL; - size_t len = strlen(url); + return util_url_path_s(cx_str(url)).ptr; +} + +cxstring util_url_path_s(cxstring url) { + cxstring path = { "", 0 }; int slashcount = 0; int slmax; - if(len > 7 && !strncasecmp(url, "http://", 7)) { + if(url.length > 7 && !strncasecmp(url.ptr, "http://", 7)) { slmax = 3; - } else if(len > 8 && !strncasecmp(url, "https://", 8)) { + } else if(url.length > 8 && !strncasecmp(url.ptr, "https://", 8)) { slmax = 3; } else { slmax = 1; } char c; - for(int i=0;i<len;i++) { - c = url[i]; + for(int i=0;i<url.length;i++) { + c = url.ptr[i]; if(c == '/') { slashcount++; if(slashcount == slmax) { - path = url + i; + path = cx_strsubs(url, i); break; } } - } - if(!path) { - path = url + len; // empty string } return path; } @@ -617,7 +616,7 @@ } char* util_concat_path(const char *url_base, const char *p) { - cxstring base = cx_str((char*)url_base); + cxstring base = cx_str(url_base); cxstring path; if(p) { path = cx_str((char*)p); @@ -625,6 +624,14 @@ path = CX_STR(""); } + return util_concat_path_s(base, path).ptr; +} + +cxmutstr util_concat_path_s(cxstring base, cxstring path) { + if(!path.ptr) { + path = CX_STR(""); + } + int add_separator = 0; if(base.length != 0 && base.ptr[base.length-1] == '/') { if(path.ptr[0] == '/') { @@ -643,7 +650,7 @@ url = cx_strcat(2, base, path); } - return url.ptr; + return url; } char* util_get_url(DavSession *sn, const char *href) {