dav/main.c

branch
ucx-3.1
changeset 816
839fefbdedc7
parent 811
9385330bdd38
equal deleted inserted replaced
815:1f40ca07ae1b 816:839fefbdedc7
701 return -1; 701 return -1;
702 } 702 }
703 703
704 // get list of resources 704 // get list of resources
705 CxList *reslist = cxLinkedListCreateSimple(CX_STORE_POINTERS); 705 CxList *reslist = cxLinkedListCreateSimple(CX_STORE_POINTERS);
706 reslist->simple_destructor = (cx_destructor_func)free_getres; 706 cxDefineDestructor(reslist, free_getres);
707 uint64_t totalsize = 0; 707 uint64_t totalsize = 0;
708 uint64_t rescount = 0; 708 uint64_t rescount = 0;
709 709
710 GetResource *getres = malloc(sizeof(GetResource)); 710 GetResource *getres = malloc(sizeof(GetResource));
711 getres->res = res; 711 getres->res = res;
714 char *structure = cmd_getoption(a, "structure"); 714 char *structure = cmd_getoption(a, "structure");
715 715
716 // iterate over resource tree 716 // iterate over resource tree
717 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); 717 CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS);
718 cxListInsert(stack, 0, getres); 718 cxListInsert(stack, 0, getres);
719 while(stack->size > 0) { 719 while(cxListSize(stack) > 0) {
720 GetResource *g = cxListAt(stack, 0); 720 GetResource *g = cxListAt(stack, 0);
721 cxListRemove(stack, 0); 721 cxListRemove(stack, 0);
722 722
723 if(g->res->iscollection) { 723 if(g->res->iscollection) {
724 DavResource *child = g->res->children; 724 DavResource *child = g->res->children;
767 } 767 }
768 tout = tar_open(tarfile); 768 tout = tar_open(tarfile);
769 } else { 769 } else {
770 get = get_resource; 770 get = get_resource;
771 } 771 }
772 CxIterator i = cxListIterator(reslist); 772 CxIterator iter = cxListIterator(reslist);
773 cx_foreach(GetResource *, getres, i) { 773 cx_foreach(GetResource *, res_item, iter) {
774 ret = get(repo, getres, a, tout); 774 ret = get(repo, res_item, a, tout);
775 if(ret) { 775 if(ret) {
776 break; 776 break;
777 } 777 }
778 } 778 }
779 if(export) { 779 if(export) {
1596 if(set_session_config(destsn, a)) { 1596 if(set_session_config(destsn, a)) {
1597 return -1; 1597 return -1;
1598 } 1598 }
1599 DavResource *dest = dav_resource_new(destsn, destpath); 1599 DavResource *dest = dav_resource_new(destsn, destpath);
1600 char *desthref = dav_resource_get_href(dest); 1600 char *desthref = dav_resource_get_href(dest);
1601 char *desturl = util_get_url(destsn, desthref); 1601 desturl = util_get_url(destsn, desthref);
1602 1602
1603 DavResource *res = dav_resource_new(srcsn, srcpath); 1603 DavResource *res = dav_resource_new(srcsn, srcpath);
1604 int err = cp ? dav_copyto(res, desturl, override) 1604 int err = cp ? dav_copyto(res, desturl, override)
1605 : dav_moveto(res, desturl, override); 1605 : dav_moveto(res, desturl, override);
1606 1606
2100 if(!dav_load(res)) { 2100 if(!dav_load(res)) {
2101 printf("name: %s\n", res->name); 2101 printf("name: %s\n", res->name);
2102 printf("path: %s\n", res->path); 2102 printf("path: %s\n", res->path);
2103 2103
2104 char *server = util_url_base(sn->base_url); 2104 char *server = util_url_base(sn->base_url);
2105 char *url = util_concat_path(server, res->href); 2105 url = util_concat_path(server, res->href);
2106 printf("url: %s\n", url); 2106 printf("url: %s\n", url);
2107 free(url); 2107 free(url);
2108 free(server); 2108 free(server);
2109 2109
2110 if(res->iscollection) { 2110 if(res->iscollection) {
2134 printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr); 2134 printf(" %s: %.*s\n", p.name, (int)value.length, value.ptr);
2135 } else { 2135 } else {
2136 // find some xml elements 2136 // find some xml elements
2137 printf(" %s: ", p.name); 2137 printf(" %s: ", p.name);
2138 DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval); 2138 DavXmlNode *x = xval->type == DAV_XML_ELEMENT ? xval : dav_xml_nextelm(xval);
2139 for(int i=0;i<3;i++) { 2139 for(int j=0;j<3;j++) {
2140 if(x) { 2140 if(x) {
2141 if(i == 2) { 2141 if(j == 2) {
2142 printf(" ..."); 2142 printf(" ...");
2143 break; 2143 break;
2144 } else { 2144 } else {
2145 print_xml_infostr(x); 2145 print_xml_infostr(x);
2146 } 2146 }
2148 break; 2148 break;
2149 } 2149 }
2150 x = dav_xml_nextelm(x); 2150 x = dav_xml_nextelm(x);
2151 } 2151 }
2152 printf("\n"); 2152 printf("\n");
2153
2154
2155 } 2153 }
2156 } 2154 }
2157 2155
2158 dav_session_free(sn, properties); 2156 dav_session_free(sn, properties);
2159 return 0; 2157 return 0;
2395 return buf.space; 2393 return buf.space;
2396 } 2394 }
2397 2395
2398 void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content) { 2396 void printxmldoc(FILE *out, char *root, char *rootns, DavXmlNode *content) {
2399 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); 2397 CxMap *nsmap = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
2400 nsmap->simple_destructor = free; 2398 cxDefineDestructor(nsmap, free);
2401 2399
2402 cxMapPut(nsmap, cx_hash_key_str(rootns), "x0"); 2400 cxMapPut(nsmap, cx_hash_key_str(rootns), "x0");
2403 fprintf(out, "%s", "<?xml version=\"1.0\"?>\n"); 2401 fprintf(out, "%s", "<?xml version=\"1.0\"?>\n");
2404 fprintf(out, "<x0:%s xmlns:x0=\"%s\">", root, rootns); 2402 fprintf(out, "<x0:%s xmlns:x0=\"%s\">", root, rootns);
2405 2403
2654 char *password = util_password_input("Password: "); 2652 char *password = util_password_input("Password: ");
2655 2653
2656 // optionally, get one or more locations 2654 // optionally, get one or more locations
2657 char *location = NULL; 2655 char *location = NULL;
2658 CxList *locations = cxLinkedListCreateSimple(CX_STORE_POINTERS); 2656 CxList *locations = cxLinkedListCreateSimple(CX_STORE_POINTERS);
2659 locations->simple_destructor = free; 2657 cxDefineDestructor(locations, free);
2660 while((location = assistant_getoptcfg("Location"))) { 2658 while((location = assistant_getoptcfg("Location"))) {
2661 cxListAdd(locations, location); 2659 cxListAdd(locations, location);
2662 } 2660 }
2663 2661
2664 int ret = 1; 2662 int ret = 1;
2686 2684
2687 /* 2685 /*
2688 * called before the secret store is decrypted 2686 * called before the secret store is decrypted
2689 */ 2687 */
2690 static int cmd_ss_list_users_bc(CmdArgs *Args, PwdStore *secrets, int *ret) { 2688 static int cmd_ss_list_users_bc(CmdArgs *Args, PwdStore *secrets, int *ret) {
2691 if(secrets->index->size == 0) { 2689 if(cxMapSize(secrets->index) == 0) {
2692 return 1; // abort, because the secret store is empty 2690 return 1; // abort, because the secret store is empty
2693 } 2691 }
2694 // set ret to 1, because decrypt could fail and this should be an error 2692 // set ret to 1, because decrypt could fail and this should be an error
2695 *ret = 1; 2693 *ret = 1;
2696 return 0; 2694 return 0;
2703 *ret = 0; 2701 *ret = 0;
2704 2702
2705 CxList *list = secrets->locations; 2703 CxList *list = secrets->locations;
2706 for(int i=0;i<2;i++) { 2704 for(int i=0;i<2;i++) {
2707 if(list) { 2705 if(list) {
2708 CxIterator i = cxListIterator(list); 2706 CxIterator iter = cxListIterator(list);
2709 cx_foreach(PwdIndexEntry*, index, i) { 2707 cx_foreach(PwdIndexEntry*, index, iter) {
2710 PwdEntry *e = cxMapGet(secrets->ids, cx_hash_key_str(index->id)); 2708 PwdEntry *e = cxMapGet(secrets->ids, cx_hash_key_str(index->id));
2711 if(e) { 2709 if(e) {
2712 printf("Id: %s\n", e->id); 2710 printf("Id: %s\n", e->id);
2713 printf("User: %s\n", e->user); 2711 printf("User: %s\n", e->user);
2714 if(index->locations) { 2712 if(index->locations) {
2786 } 2784 }
2787 } 2785 }
2788 } 2786 }
2789 2787
2790 static void secrets_remove_location(PwdIndexEntry *index) { 2788 static void secrets_remove_location(PwdIndexEntry *index) {
2791 if(!index->locations || index->locations->size == 0) { 2789 if(!index->locations || cxListSize(index->locations) == 0) {
2792 printf("no locations\n"); 2790 printf("no locations\n");
2793 return; 2791 return;
2794 } 2792 }
2795 2793
2796 printf("0: abort\n"); 2794 printf("0: abort\n");
2893 secrets_remove_location(index); 2891 secrets_remove_location(index);
2894 break; 2892 break;
2895 } 2893 }
2896 case 4: { 2894 case 4: {
2897 // list locations 2895 // list locations
2898 if(!index->locations || index->locations->size == 0) { 2896 if(!index->locations || cxListSize(index->locations)) {
2899 printf("no locations\n"); 2897 printf("no locations\n");
2900 } else { 2898 } else {
2901 CxIterator i = cxListIterator(index->locations); 2899 CxIterator i = cxListIterator(index->locations);
2902 cx_foreach(char *, location, i) { 2900 cx_foreach(char *, location, i) {
2903 printf("Location: %s\n", location); 2901 printf("Location: %s\n", location);

mercurial