allow regular resource url input in the path bar

Wed, 23 Oct 2024 21:46:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 23 Oct 2024 21:46:43 +0200
changeset 59
6bd37fe6d905
parent 58
0d25f15e2625
child 60
ee4e4742391e

allow regular resource url input in the path bar

application/window.c file | annotate | diff | comparison | revisions
libidav/utils.c file | annotate | diff | comparison | revisions
--- a/application/window.c	Wed Oct 23 18:25:43 2024 +0200
+++ b/application/window.c	Wed Oct 23 21:46:43 2024 +0200
@@ -295,6 +295,8 @@
     cxmutstr base = cx_strdup(cx_strn(full_path, end));
     cxmutstr base_path = cx_strcat(2, cx_strcast(base), CX_STR("/"));
     cxstring path = cx_strsubs(fpath, end + skip);
+    
+    cxstring trail = cx_str(len > 0 && full_path[len-1] == '/' ? "/" : "");
 
     cxstring *pathelms;
     size_t nelm = 0;
@@ -331,7 +333,7 @@
         elms[j].name_len = m.length;
 
         size_t elm_path_len = c.ptr + c.length - full_path;
-        cxmutstr elm_path = cx_strcat(2, cx_strn(full_path, elm_path_len), CX_STR("/"));
+        cxmutstr elm_path = cx_strcat(2, cx_strn(full_path, elm_path_len), i+1 < nelm ? CX_STR("/") : trail);
         elms[j].path = elm_path.ptr;
         elms[j].path_len = elm_path.length;
 
--- a/libidav/utils.c	Wed Oct 23 18:25:43 2024 +0200
+++ b/libidav/utils.c	Wed Oct 23 21:46:43 2024 +0200
@@ -731,6 +731,11 @@
 }
 
 char* util_path_to_url(DavSession *sn, const char *path) {
+    size_t pathlen = path ? strlen(path) : 0;
+    if(pathlen == 0) {
+        return strdup(sn->base_url);
+    }
+    
     CxBuffer url;
     cxBufferInit(&url, NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     
@@ -739,7 +744,7 @@
     // remove trailing slash
     cxBufferSeek(&url, -1, SEEK_CUR);
     
-    cxstring p = cx_str(path);
+    cxstring p = cx_strn(path, pathlen);
     
     CxStrtokCtx tkctx = cx_strtok(p, CX_STR("/"), INT_MAX);
     cxstring node;

mercurial