301 break; |
301 break; |
302 } |
302 } |
303 } |
303 } |
304 } |
304 } |
305 } |
305 } |
306 cxstring server = cx_strsubsl(url, 0, i); |
306 return cx_strsubsl(url, 0, i); |
307 return cx_strdup(server).ptr; |
307 } |
308 } |
308 |
309 |
309 char* util_url_base(const char *url) { |
310 char* util_url_base(char *url) { |
310 return cx_strdup(util_url_base_s(cx_str(url))).ptr; |
311 return util_url_base_s(cx_str(url)); |
|
312 } |
311 } |
313 |
312 |
314 #ifdef _WIN32 |
313 #ifdef _WIN32 |
315 #define strncasecmp _strnicmp |
314 #define strncasecmp _strnicmp |
316 #endif |
315 #endif |
317 |
316 |
318 const char* util_url_path(const char *url) { |
317 const char* util_url_path(const char *url) { |
319 const char *path = NULL; |
318 return util_url_path_s(cx_str(url)).ptr; |
320 size_t len = strlen(url); |
319 } |
|
320 |
|
321 cxstring util_url_path_s(cxstring url) { |
|
322 cxstring path = { "", 0 }; |
321 int slashcount = 0; |
323 int slashcount = 0; |
322 int slmax; |
324 int slmax; |
323 if(len > 7 && !strncasecmp(url, "http://", 7)) { |
325 if(url.length > 7 && !strncasecmp(url.ptr, "http://", 7)) { |
324 slmax = 3; |
326 slmax = 3; |
325 } else if(len > 8 && !strncasecmp(url, "https://", 8)) { |
327 } else if(url.length > 8 && !strncasecmp(url.ptr, "https://", 8)) { |
326 slmax = 3; |
328 slmax = 3; |
327 } else { |
329 } else { |
328 slmax = 1; |
330 slmax = 1; |
329 } |
331 } |
330 char c; |
332 char c; |
331 for(int i=0;i<len;i++) { |
333 for(int i=0;i<url.length;i++) { |
332 c = url[i]; |
334 c = url.ptr[i]; |
333 if(c == '/') { |
335 if(c == '/') { |
334 slashcount++; |
336 slashcount++; |
335 if(slashcount == slmax) { |
337 if(slashcount == slmax) { |
336 path = url + i; |
338 path = cx_strsubs(url, i); |
337 break; |
339 break; |
338 } |
340 } |
339 } |
341 } |
340 } |
|
341 if(!path) { |
|
342 path = url + len; // empty string |
|
343 } |
342 } |
344 return path; |
343 return path; |
345 } |
344 } |
346 |
345 |
347 char* util_url_decode(DavSession *sn, const char *url) { |
346 char* util_url_decode(DavSession *sn, const char *url) { |
615 return mkdir(path, mode); |
614 return mkdir(path, mode); |
616 #endif |
615 #endif |
617 } |
616 } |
618 |
617 |
619 char* util_concat_path(const char *url_base, const char *p) { |
618 char* util_concat_path(const char *url_base, const char *p) { |
620 cxstring base = cx_str((char*)url_base); |
619 cxstring base = cx_str(url_base); |
621 cxstring path; |
620 cxstring path; |
622 if(p) { |
621 if(p) { |
623 path = cx_str((char*)p); |
622 path = cx_str((char*)p); |
624 } else { |
623 } else { |
|
624 path = CX_STR(""); |
|
625 } |
|
626 |
|
627 return util_concat_path_s(base, path).ptr; |
|
628 } |
|
629 |
|
630 cxmutstr util_concat_path_s(cxstring base, cxstring path) { |
|
631 if(!path.ptr) { |
625 path = CX_STR(""); |
632 path = CX_STR(""); |
626 } |
633 } |
627 |
634 |
628 int add_separator = 0; |
635 int add_separator = 0; |
629 if(base.length != 0 && base.ptr[base.length-1] == '/') { |
636 if(base.length != 0 && base.ptr[base.length-1] == '/') { |
641 url = cx_strcat(3, base, CX_STR("/"), path); |
648 url = cx_strcat(3, base, CX_STR("/"), path); |
642 } else { |
649 } else { |
643 url = cx_strcat(2, base, path); |
650 url = cx_strcat(2, base, path); |
644 } |
651 } |
645 |
652 |
646 return url.ptr; |
653 return url; |
647 } |
654 } |
648 |
655 |
649 char* util_get_url(DavSession *sn, const char *href) { |
656 char* util_get_url(DavSession *sn, const char *href) { |
650 cxstring base = cx_str(sn->base_url); |
657 cxstring base = cx_str(sn->base_url); |
651 cxstring href_str = cx_str(href); |
658 cxstring href_str = cx_str(href); |