99 ret = cmd_date(args); |
99 ret = cmd_date(args); |
100 } else if(!strcasecmp(cmd, "set-property")) { |
100 } else if(!strcasecmp(cmd, "set-property")) { |
101 ret = cmd_set_property(args); |
101 ret = cmd_set_property(args); |
102 } else if(!strcasecmp(cmd, "get-property")) { |
102 } else if(!strcasecmp(cmd, "get-property")) { |
103 ret = cmd_get_property(args); |
103 ret = cmd_get_property(args); |
|
104 } else if(!strcasecmp(cmd, "info")) { |
|
105 ret = cmd_info(args); |
104 } else { |
106 } else { |
105 print_usage(argv[0]); |
107 print_usage(argv[0]); |
106 } |
108 } |
107 |
109 |
108 dav_context_destroy(ctx); |
110 dav_context_destroy(ctx); |
990 |
992 |
991 free(path); |
993 free(path); |
992 return 0; |
994 return 0; |
993 } |
995 } |
994 |
996 |
|
997 static int count_children(DavResource *res) { |
|
998 DavResource *child = res->children; |
|
999 int count = 0; |
|
1000 while(child) { |
|
1001 count++; |
|
1002 child = child->next; |
|
1003 } |
|
1004 return count; |
|
1005 } |
|
1006 |
|
1007 int cmd_info(CmdArgs *a) { |
|
1008 if(a->argc < 1) { |
|
1009 fprintf(stderr, "Too few arguments\n"); |
|
1010 return -1; |
|
1011 } |
|
1012 |
|
1013 char *url = a->argv[0]; |
|
1014 char *path = NULL; |
|
1015 DavSession *sn = connect_to_repo(url2repo(url, &path)); |
|
1016 |
|
1017 if(set_session_config(sn, a)) { |
|
1018 return -1; |
|
1019 } |
|
1020 |
|
1021 DavResource *res = dav_resource_new(sn, path); |
|
1022 if(!dav_load(res)) { |
|
1023 printf("name: %s\n", res->name); |
|
1024 printf("path: %s\n", res->path); |
|
1025 |
|
1026 char *url = util_path_to_url(sn, res->path); |
|
1027 printf("url: %s\n", url); |
|
1028 free(url); |
|
1029 |
|
1030 if(res->iscollection) { |
|
1031 printf("type: collection\n"); |
|
1032 printf("size: %d\n", count_children(res)); |
|
1033 } else { |
|
1034 printf("type: resource\n"); |
|
1035 char *len = ls_size_str(res); |
|
1036 printf("size: %s\n", len); |
|
1037 free(len); |
|
1038 } |
|
1039 |
|
1040 size_t count = 0; |
|
1041 DavPropName *properties = dav_get_property_names(res, &count); |
|
1042 |
|
1043 char *last_ns = NULL; |
|
1044 for(int i=0;i<count;i++) { |
|
1045 DavPropName p = properties[i]; |
|
1046 if(!last_ns || strcmp(last_ns, p.ns)) { |
|
1047 printf("\nnamespace: %s\n", p.ns); |
|
1048 last_ns = p.ns; |
|
1049 } |
|
1050 |
|
1051 sstr_t value = sstr(dav_get_property_ns(res, p.ns, p.name)); |
|
1052 value = sstrtrim(value); |
|
1053 printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr); |
|
1054 } |
|
1055 |
|
1056 dav_session_free(sn, properties); |
|
1057 } else { |
|
1058 print_resource_error(sn, res->path); |
|
1059 return -1; |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 |
995 char* stdin2str() { |
1064 char* stdin2str() { |
996 UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
1065 UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
997 size_t size = ucx_stream_hcopy(stdin, buf, fread, ucx_buffer_write); |
1066 size_t size = ucx_stream_hcopy(stdin, buf, fread, ucx_buffer_write); |
998 if(size == 0) { |
1067 if(size == 0) { |
999 ucx_buffer_free(buf); |
1068 ucx_buffer_free(buf); |