39 #include <dirent.h> |
39 #include <dirent.h> |
40 |
40 |
41 |
41 |
42 #include <libidav/utils.h> |
42 #include <libidav/utils.h> |
43 #include <libidav/crypto.h> |
43 #include <libidav/crypto.h> |
|
44 #include <libidav/session.h> |
44 #include "config.h" |
45 #include "config.h" |
45 #include "main.h" |
46 #include "main.h" |
46 |
47 |
47 static DavContext *ctx; |
48 static DavContext *ctx; |
48 |
49 |
49 static void xmlerrorfnc(void * c, const char * msg, ... ) { |
50 static void xmlerrorfnc(void * c, const char * msg, ... ) { |
50 // nothing |
51 // nothing |
51 } |
52 } |
52 |
53 |
53 #include <libidav/session.h> |
|
54 void test() { |
54 void test() { |
55 |
55 |
56 } |
56 } |
57 |
57 |
58 int main(int argc, char **argv) { |
58 int main(int argc, char **argv) { |
141 " -u <date> " |
141 " -u <date> " |
142 "Get resources which are modified since the specified date\n"); |
142 "Get resources which are modified since the specified date\n"); |
143 fprintf(stderr, " -a show all files\n"); |
143 fprintf(stderr, " -a show all files\n"); |
144 fprintf(stderr, " -l print resources in long list format\n"); |
144 fprintf(stderr, " -l print resources in long list format\n"); |
145 fprintf(stderr, " -t print content type\n"); |
145 fprintf(stderr, " -t print content type\n"); |
146 fprintf(stderr, " -n <uri> specify namespace uri"); |
146 fprintf(stderr, " -n <uri> specify namespace uri\n"); |
|
147 fprintf(stderr, " -v verbose output\n"); |
147 fprintf(stderr, "\n"); |
148 fprintf(stderr, "\n"); |
148 fprintf(stderr, |
149 fprintf(stderr, |
149 "Instead of an url you can pass a repository name " |
150 "Instead of an url you can pass a repository name " |
150 "with an optional path:\n"); |
151 "with an optional path:\n"); |
151 fprintf(stderr, " <repository>/path/\n"); |
152 fprintf(stderr, " <repository>/path/\n"); |
268 if(plain && crypt) { |
269 if(plain && crypt) { |
269 fprintf(stderr, "Error: -p and -c option set\n"); |
270 fprintf(stderr, "Error: -p and -c option set\n"); |
270 return 1; |
271 return 1; |
271 } |
272 } |
272 |
273 |
273 if(plain) { |
274 if (plain) { |
274 int flags = sn->flags; |
275 sn->flags &= ~DAV_SESSION_FULL_ENCRYPTION; |
275 dav_session_set_flags(sn, 0); |
|
276 } else if(crypt) { |
276 } else if(crypt) { |
277 dav_session_set_flags(sn, DAV_SESSION_FULL_ENCRYPTION); |
277 sn->flags |= DAV_SESSION_FULL_ENCRYPTION; |
|
278 } |
|
279 |
|
280 if (cmd_getoption(a, "verbose")) { |
|
281 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
|
282 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
278 } |
283 } |
279 |
284 |
280 return 0; |
285 return 0; |
281 } |
286 } |
282 |
287 |
|
288 static DavSession* connect_to_repo(Repository *repo) { |
|
289 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
290 sn->flags = get_repository_flags(repo); |
|
291 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
292 |
|
293 return sn; |
|
294 } |
283 |
295 |
284 int cmd_list(CmdArgs *a) { |
296 int cmd_list(CmdArgs *a) { |
285 if(a->argc != 1) { |
297 if(a->argc != 1) { |
286 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
298 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
287 return -1; |
299 return -1; |
288 } |
300 } |
289 |
301 |
290 char *url = a->argv[0]; |
302 char *url = a->argv[0]; |
291 char *path = NULL; |
303 char *path = NULL; |
292 //char *base = NULL; |
|
293 Repository *repo = url2repo(url, &path); |
304 Repository *repo = url2repo(url, &path); |
294 //base = util_concat_path(repo->url, path); |
305 DavSession *sn = connect_to_repo(repo); |
295 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
296 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
297 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
298 |
306 |
299 if(set_session_config(sn, a)) { |
307 if(set_session_config(sn, a)) { |
300 return -1; |
308 return -1; |
301 } |
309 } |
302 |
310 |
513 } |
521 } |
514 |
522 |
515 char *url = a->argv[0]; |
523 char *url = a->argv[0]; |
516 char *path = NULL; |
524 char *path = NULL; |
517 Repository *repo = url2repo(url, &path); |
525 Repository *repo = url2repo(url, &path); |
518 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
526 DavSession *sn = connect_to_repo(repo); |
519 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
520 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
521 |
527 |
522 if(set_session_config(sn, a)) { |
528 if(set_session_config(sn, a)) { |
523 return -1; |
529 return -1; |
524 } |
530 } |
525 |
531 |
636 |
642 |
637 char *url = a->argv[0]; |
643 char *url = a->argv[0]; |
638 char *file = a->argv[1]; |
644 char *file = a->argv[1]; |
639 char *path = NULL; |
645 char *path = NULL; |
640 Repository *repo = url2repo(url, &path); |
646 Repository *repo = url2repo(url, &path); |
641 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
647 DavSession *sn = connect_to_repo(repo); |
642 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
643 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
644 |
648 |
645 if(set_session_config(sn, a)) { |
649 if(set_session_config(sn, a)) { |
646 return -1; |
650 return -1; |
647 } |
651 } |
648 |
652 |
775 return -1; |
779 return -1; |
776 } |
780 } |
777 |
781 |
778 char *url = a->argv[0]; |
782 char *url = a->argv[0]; |
779 char *path = NULL; |
783 char *path = NULL; |
780 Repository *repo = url2repo(url, &path); |
784 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
781 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
782 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
783 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
784 |
785 |
785 if(set_session_config(sn, a)) { |
786 if(set_session_config(sn, a)) { |
786 return -1; |
787 return -1; |
787 } |
788 } |
788 |
789 |
808 return -1; |
809 return -1; |
809 } |
810 } |
810 |
811 |
811 char *url = a->argv[0]; |
812 char *url = a->argv[0]; |
812 char *path = NULL; |
813 char *path = NULL; |
813 Repository *repo = url2repo(url, &path); |
814 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
814 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
815 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
816 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
817 |
815 |
818 if(set_session_config(sn, a)) { |
816 if(set_session_config(sn, a)) { |
819 return -1; |
817 return -1; |
820 } |
818 } |
821 |
819 |
871 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
869 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); |
872 fwrite(str, 1, len, stdout); |
870 fwrite(str, 1, len, stdout); |
873 } else if (a->argc == 1) { |
871 } else if (a->argc == 1) { |
874 char *url = a->argv[0]; |
872 char *url = a->argv[0]; |
875 char *path = NULL; |
873 char *path = NULL; |
876 Repository *repo = url2repo(url, &path); |
874 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
877 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
878 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
879 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
880 |
875 |
881 DavResource *res = dav_resource_new(sn, path); |
876 DavResource *res = dav_resource_new(sn, path); |
882 char *date = NULL; |
877 char *date = NULL; |
883 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
878 curl_easy_setopt(sn->handle, CURLOPT_HEADERFUNCTION, get_date_header_cb); |
884 curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
879 curl_easy_setopt(sn->handle, CURLOPT_WRITEHEADER, &date); |
901 return -1; |
896 return -1; |
902 } |
897 } |
903 |
898 |
904 char *url = a->argv[0]; |
899 char *url = a->argv[0]; |
905 char *path = NULL; |
900 char *path = NULL; |
906 Repository *repo = url2repo(url, &path); |
901 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
907 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
908 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
909 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
910 |
902 |
911 if(set_session_config(sn, a)) { |
903 if(set_session_config(sn, a)) { |
912 return -1; |
904 return -1; |
913 } |
905 } |
914 |
906 |
947 return -1; |
939 return -1; |
948 } |
940 } |
949 |
941 |
950 char *url = a->argv[0]; |
942 char *url = a->argv[0]; |
951 char *path = NULL; |
943 char *path = NULL; |
952 Repository *repo = url2repo(url, &path); |
944 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
953 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
|
954 dav_session_set_flags(sn, get_repository_flags(repo)); |
|
955 sn->key = dav_context_get_key(ctx, repo->default_key); |
|
956 |
945 |
957 if(set_session_config(sn, a)) { |
946 if(set_session_config(sn, a)) { |
958 return -1; |
947 return -1; |
959 } |
948 } |
960 |
949 |