57 browser->resources->update(browser->resources, 0); |
57 browser->resources->update(browser->resources, 0); |
58 } |
58 } |
59 |
59 |
60 // ------------------------------ davbrowser_connect2repo ------------------------------ |
60 // ------------------------------ davbrowser_connect2repo ------------------------------ |
61 |
61 |
62 static int connect2repo(void *data) { |
62 void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo) { |
63 DavBrowser *browser = data; |
|
64 DavCfgRepository *repo = browser->repository; |
|
65 |
|
66 // TODO: cleanup current session |
|
67 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr); |
63 DavSession *sn = dav_session_new(application_dav_context(), repo->url.value.ptr); |
68 if (repo->user.value.ptr && repo->password.value.ptr) { |
64 if (repo->user.value.ptr && repo->password.value.ptr) { |
69 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
65 cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
70 dav_session_set_auth(sn, repo->user.value.ptr, decodedpw.ptr); |
66 dav_session_set_auth(sn, repo->user.value.ptr, decodedpw.ptr); |
71 free(decodedpw.ptr); |
67 free(decodedpw.ptr); |
72 } |
68 } |
73 browser->sn = sn; |
69 browser->sn = sn; |
|
70 browser->repo_base = cx_strdup(cx_strn(repo->name.value.ptr, repo->name.value.length)).ptr; |
74 |
71 |
75 return 0; |
72 ui_set(browser->path, repo->name.value.ptr); |
76 } |
|
77 |
73 |
78 static void repo_connected(UiEvent *event, void *data) { |
74 davbrowser_query_path(ui, browser, ""); |
79 DavBrowser *browser = event->document; |
|
80 ui_set(browser->path, browser->repository->name.value.ptr); |
|
81 |
|
82 davbrowser_query_path(event->obj, browser, "/"); |
|
83 } |
|
84 |
|
85 void davbrowser_connect2repo(UiObject *ui, DavBrowser *browser, DavCfgRepository *repo) { |
|
86 browser->repository = repo; |
|
87 ui_threadpool_job(browser->dav_queue, ui, connect2repo, browser, repo_connected, NULL); |
|
88 } |
75 } |
89 |
76 |
90 |
77 |
91 // ------------------------------ davbrowser_query_path ------------------------------ |
78 // ------------------------------ davbrowser_query_path ------------------------------ |
92 |
79 |
126 // for comparison, we need the current base_url/repo_name + path |
113 // for comparison, we need the current base_url/repo_name + path |
127 size_t len = path ? strlen(path) : 0; |
114 size_t len = path ? strlen(path) : 0; |
128 if (len == 1 && *path == '/') { |
115 if (len == 1 && *path == '/') { |
129 path = ""; |
116 path = ""; |
130 } |
117 } |
131 char *full_path = util_concat_path(browser->repository->name.value.ptr, path); |
118 char *full_path = util_concat_path(browser->repo_base, path); |
132 // compare new path with current path |
119 // compare new path with current path |
133 // in theory we could always set path, but maybe this is faster |
120 // in theory we could always set path, but maybe this is faster |
134 char *current_path = ui_get(browser->path); |
121 char *current_path = ui_get(browser->path); |
135 if (strcmp(full_path, current_path)) { |
122 if (strcmp(full_path, current_path)) { |
136 ui_set(browser->path, full_path); |
123 ui_set(browser->path, full_path); |