dav/sync.c

changeset 347
b6ff6be7aa91
parent 331
9ca1e4706acc
child 361
b6f2462ee055
equal deleted inserted replaced
346:3e20fd78e555 347:b6ff6be7aa91
256 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); 256 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0);
257 } 257 }
258 return sn; 258 return sn;
259 } 259 }
260 260
261 static void print_allowed_cmds(SyncDirectory *dir) {
262 fprintf(stderr, "Allowed commands: ");
263 char *sep = "";
264 if((dir->allow_cmd & SYNC_CMD_PULL) == SYNC_CMD_PULL) {
265 fprintf(stderr, "pull");
266 sep = ", ";
267 }
268 if((dir->allow_cmd & SYNC_CMD_PUSH) == SYNC_CMD_PUSH) {
269 fprintf(stderr, "%spush", sep);
270 sep = ", ";
271 }
272 if((dir->allow_cmd & SYNC_CMD_ARCHIVE) == SYNC_CMD_ARCHIVE) {
273 fprintf(stderr, "%sarchive", sep);
274 }
275 fprintf(stderr, "\n");
276 }
277
261 int cmd_pull(CmdArgs *a) { 278 int cmd_pull(CmdArgs *a) {
262 if(a->argc != 1) { 279 if(a->argc != 1) {
263 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); 280 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
264 return -1; 281 return -1;
265 } 282 }
268 if(!dir) { 285 if(!dir) {
269 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); 286 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
270 return -1; 287 return -1;
271 } 288 }
272 if(scfg_check_dir(dir)) { 289 if(scfg_check_dir(dir)) {
290 return -1;
291 }
292
293 if((dir->allow_cmd & SYNC_CMD_PULL) != SYNC_CMD_PULL) {
294 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n");
295 print_allowed_cmds(dir);
273 return -1; 296 return -1;
274 } 297 }
275 298
276 Repository *repo = get_repository(sstr(dir->repository)); 299 Repository *repo = get_repository(sstr(dir->repository));
277 if(!repo) { 300 if(!repo) {
801 if(!dir) { 824 if(!dir) {
802 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); 825 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
803 return -1; 826 return -1;
804 } 827 }
805 if(scfg_check_dir(dir)) { 828 if(scfg_check_dir(dir)) {
829 return -1;
830 }
831
832 int cmd = archive ? SYNC_CMD_ARCHIVE : SYNC_CMD_PUSH;
833 if((dir->allow_cmd & cmd) != cmd) {
834 fprintf(stderr, "Command '%s' is not allowed for this sync dir\n", archive ? "archive" : "push");
835 print_allowed_cmds(dir);
806 return -1; 836 return -1;
807 } 837 }
808 838
809 Repository *repo = get_repository(sstr(dir->repository)); 839 Repository *repo = get_repository(sstr(dir->repository));
810 if(!repo) { 840 if(!repo) {

mercurial