dav/main.c

changeset 628
1f76d9624db8
parent 618
4b34d12cf211
child 651
6d1d569068bf
equal deleted inserted replaced
627:81e066c9ff87 628:1f76d9624db8
382 if(url[ulen-1] == '/') { 382 if(url[ulen-1] == '/') {
383 repo->url = strdup(url); 383 repo->url = strdup(url);
384 *path = strdup("/"); 384 *path = strdup("/");
385 } else if (strchr(url, '/')) { 385 } else if (strchr(url, '/')) {
386 repo->url = util_url_base(url); 386 repo->url = util_url_base(url);
387 *path = util_url_path(url); 387 *path = strdup(util_url_path(url));
388 } else { 388 } else {
389 repo->url = strdup(url); 389 repo->url = strdup(url);
390 *path = strdup("/"); 390 *path = strdup("/");
391 } 391 }
392 } 392 }
1553 static int dav_create_col(DavResource *res) { 1553 static int dav_create_col(DavResource *res) {
1554 res->iscollection = 1; 1554 res->iscollection = 1;
1555 return dav_create(res); 1555 return dav_create(res);
1556 } 1556 }
1557 1557
1558 static void print_cannoterr(DavSession *sn, const char *message) {
1559 switch(sn->error) {
1560 case DAV_UNSUPPORTED_PROTOCOL:
1561 case DAV_COULDNT_RESOLVE_PROXY:
1562 case DAV_COULDNT_RESOLVE_HOST:
1563 case DAV_COULDNT_CONNECT:
1564 case DAV_TIMEOUT:
1565 case DAV_SSL_ERROR: break;
1566 default: fprintf(stderr, "Cannot %s.\n", message);
1567 }
1568 }
1569
1558 static int cmd_operation_on_resources(CmdArgs* a, 1570 static int cmd_operation_on_resources(CmdArgs* a,
1559 int(*operation)(DavResource*), 1571 int(*operation)(DavResource*),
1560 const char* command, 1572 const char* command,
1561 const char* message) { 1573 const char* message) {
1562 if(a->argc < 1) { 1574 if(a->argc < 1) {
1587 assert(!!res); 1599 assert(!!res);
1588 res->iscollection = 1; 1600 res->iscollection = 1;
1589 1601
1590 if(a->argc == 1) { 1602 if(a->argc == 1) {
1591 if(operation(res)) { 1603 if(operation(res)) {
1592 fprintf(stderr, "Cannot %s.\n", message); 1604 print_cannoterr(sn, message);
1593 print_resource_error(sn, res->path); 1605 print_resource_error(sn, res->path);
1594 goto cmd_oponres_exit; 1606 goto cmd_oponres_exit;
1595 } 1607 }
1596 } else { 1608 } else {
1597 for(int i = 1 ; i < a->argc ;++i) { 1609 for(int i = 1 ; i < a->argc ;++i) {
1598 DavResource *child = dav_resource_new_child(sn, res, a->argv[i]); 1610 DavResource *child = dav_resource_new_child(sn, res, a->argv[i]);
1599 assert(!!child); 1611 assert(!!child);
1600 child->iscollection = 1; 1612 child->iscollection = 1;
1601 if(operation(child)) { 1613 if(operation(child)) {
1602 fprintf(stderr, "Cannot %s %s.\n", message, a->argv[i]); 1614 print_cannoterr(sn, message);
1603 print_resource_error(sn, child->path); 1615 print_resource_error(sn, child->path);
1604 goto cmd_oponres_exit; 1616 goto cmd_oponres_exit;
1605 } 1617 }
1606 } 1618 }
1607 } 1619 }

mercurial