Tue, 30 Jan 2024 16:58:03 +0100
switch DavSession in davbrowser_query_url when a different server is specified
--- a/application/application.c Tue Jan 30 16:01:44 2024 +0100 +++ b/application/application.c Tue Jan 30 16:58:03 2024 +0100 @@ -153,5 +153,5 @@ void action_repo_selected(UiEvent *event, void *data) { DavCfgRepository *repo = event->eventdata; DavBrowser *browser = event->document; - davbrowser_connect2repo(event->obj, browser, repo); + davbrowser_connect2repo(event->obj, browser, repo, ""); }
--- a/application/davcontroller.c Tue Jan 30 16:01:44 2024 +0100 +++ b/application/davcontroller.c Tue Jan 30 16:58:03 2024 +0100 @@ -31,6 +31,9 @@ #include <cx/printf.h> +#include "config.h" + +#include <libidav/config.h> #include <libidav/utils.h> DavBrowser* davbrowser_create(UiObject *toplevel) { @@ -67,7 +70,7 @@ // ------------------------------ davbrowser_connect2repo ------------------------------ -void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo) { +void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo, const char *path) { DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr); if (repo->user.value.ptr && repo->password.value.ptr) { cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); @@ -75,11 +78,17 @@ free(decodedpw.ptr); } browser->sn = sn; - browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr; + if (repo->name.value.length > 0) { + browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr; + } else { + browser->repo_base = cx_strdup(cx_strn(repo->url.value.ptr, repo->url.value.length)).ptr; + } - ui_set(browser->path, repo->name.value.ptr); + char *dav_path = util_concat_path(browser->repo_base, path); + ui_set(browser->path, dav_path); + free(dav_path); - davbrowser_query_path(ui, browser, ""); + davbrowser_query_path(ui, browser, path); } @@ -96,7 +105,7 @@ DavBrowserQueryPath *query = data; DavSession *sn = query->browser->sn; - DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,D:getcontenttype from %s with depth = 1 order by iscollection desc, name", query->path); + DavResource *res = dav_query(sn, "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery from %s with depth = 1 order by iscollection desc, name", query->path); query->result = res; return 0; @@ -169,7 +178,16 @@ } } - // TODO: + char *path = NULL; + DavCfgRepository *repo = dav_config_url2repo(get_config(), url, &path); + davbrowser_connect2repo(ui, browser, repo, path); + + if (path) { + free(path); + } + if (!repo->node) { + dav_repository_free(get_config(), repo); + } } void davbrowser_add2navstack(DavBrowser *browser, const char *base, const char *path) {
--- a/application/davcontroller.h Tue Jan 30 16:01:44 2024 +0100 +++ b/application/davcontroller.h Tue Jan 30 16:58:03 2024 +0100 @@ -45,7 +45,7 @@ void davbrowser_set_collection(UiObject *ui, DavBrowser *browser, DavResource *collection); -void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo); +void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo, const char *path); void davbrowser_query_path(UiObject *ui, DavBrowser *browser, const char *path);