117 ret = cmd_set_property(args); |
117 ret = cmd_set_property(args); |
118 } else if(!strcasecmp(cmd, "get-property")) { |
118 } else if(!strcasecmp(cmd, "get-property")) { |
119 ret = cmd_get_property(args); |
119 ret = cmd_get_property(args); |
120 } else if(!strcasecmp(cmd, "info")) { |
120 } else if(!strcasecmp(cmd, "info")) { |
121 ret = cmd_info(args); |
121 ret = cmd_info(args); |
122 } else if(!strcasecmp(cmd, "add-repository")) { |
|
123 ret = cmd_add_repository(args); |
|
124 } else { |
122 } else { |
125 print_usage(argv[0]); |
123 print_usage(argv[0]); |
126 } |
124 } |
127 |
125 |
128 dav_context_destroy(ctx); |
126 dav_context_destroy(ctx); |
959 print_resource_error(sn, res->path); |
957 print_resource_error(sn, res->path); |
960 fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move"); |
958 fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move"); |
961 return -1; |
959 return -1; |
962 } |
960 } |
963 } else { |
961 } else { |
964 fprintf(stderr, "Copy or Move not supported for different hosts.\n"); |
962 char *server1 = util_url_base(repo1->url); |
965 return -1; |
963 char *server2 = util_url_base(repo2->url); |
966 } |
964 if(!strcmp(server1, server2)) { |
|
965 DavSession *sn2 = connect_to_repo(repo2); |
|
966 if(set_session_config(sn2, a)) { |
|
967 return -1; |
|
968 } |
|
969 DavResource *dest = dav_resource_new(sn2, path2); |
|
970 char *desthref = dav_resource_get_href(dest); |
|
971 char *desturl = util_get_url(sn2, desthref); |
|
972 |
|
973 DavResource *res = dav_resource_new(sn, path1); |
|
974 int err = cp ? dav_copyto(res, desturl, override) |
|
975 : dav_moveto(res, desturl, override); |
|
976 |
|
977 free(desturl); |
|
978 dav_session_destroy(sn2); |
|
979 |
|
980 if(err) { |
|
981 print_resource_error(sn, res->path); |
|
982 fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move"); |
|
983 return -1; |
|
984 } |
|
985 } else { |
|
986 fprintf(stderr, "Copy or Move not supported for different hosts.\n"); |
|
987 return -1; |
|
988 } |
|
989 } |
|
990 |
|
991 dav_session_destroy(sn); |
967 |
992 |
968 return 0; |
993 return 0; |
969 } |
994 } |
970 |
995 |
971 |
996 |
1249 |
1274 |
1250 // TODO |
1275 // TODO |
1251 |
1276 |
1252 return; |
1277 return; |
1253 } |
1278 } |
1254 |
|
1255 int cmd_add_repository(CmdArgs *a) { |
|
1256 char *interactive = cmd_getoption(a, "interactive"); |
|
1257 |
|
1258 if(!interactive && a->argc < 2) { |
|
1259 fprintf(stderr, "Too few arguments\n"); |
|
1260 fprintf(stderr, "Alternatively, use the interactive mode"); |
|
1261 return -1; |
|
1262 } |
|
1263 |
|
1264 Repository *repo = repository_new(); |
|
1265 // create repo object and fill config with cmd args |
|
1266 for(int i=0;i<a->argc;i++) { |
|
1267 char *key; |
|
1268 char *value; |
|
1269 if(!getkeyvalue(a->argv[i], &key, &value)) { |
|
1270 if(!strcmp(key, "password")) { |
|
1271 // passwords from command line args are plain text |
|
1272 // but the repository needs a base64 encoded password |
|
1273 char *pw = util_base64encode(value, strlen(value)); |
|
1274 free(value); |
|
1275 value = pw; |
|
1276 } |
|
1277 |
|
1278 if(repo_add_config(repo, key, value)) { |
|
1279 fprintf( |
|
1280 stderr, |
|
1281 "Unkown repository config element: %s\n", |
|
1282 key); |
|
1283 } |
|
1284 |
|
1285 free(key); |
|
1286 free(value); |
|
1287 } else { |
|
1288 fprintf(stderr, "´%s´ not in key=value format\n", a->argv[i]); |
|
1289 // TODO: cleanup |
|
1290 return -1; |
|
1291 } |
|
1292 } |
|
1293 |
|
1294 if(interactive) { |
|
1295 // start interactive assistent to adjust config |
|
1296 repository_assistent(repo, 0); |
|
1297 } |
|
1298 |
|
1299 return 0; |
|
1300 } |
|