dav/webdav.c

changeset 24
a317202ae787
parent 22
e593f7e41be0
child 25
29f77f1fdbf3
equal deleted inserted replaced
23:2b0a7361f15c 24:a317202ae787
112 if(url.length == 0) { 112 if(url.length == 0) {
113 return NULL; 113 return NULL;
114 } 114 }
115 DavSession *sn = malloc(sizeof(DavSession)); 115 DavSession *sn = malloc(sizeof(DavSession));
116 sn->errorstr = NULL; 116 sn->errorstr = NULL;
117 sn->error = CURLE_OK; 117 sn->error = DAV_OK;
118 if(url.ptr[url.length - 1] == '/') { 118 if(url.ptr[url.length - 1] == '/') {
119 sn->base_url = strdup(base_url); 119 sn->base_url = strdup(base_url);
120 } else { 120 } else {
121 char *url_str = malloc(url.length + 2); 121 char *url_str = malloc(url.length + 2);
122 memcpy(url_str, base_url, url.length); 122 memcpy(url_str, base_url, url.length);
124 url_str[url.length + 1] = '\0'; 124 url_str[url.length + 1] = '\0';
125 sn->base_url = url_str; 125 sn->base_url = url_str;
126 } 126 }
127 sn->context = context; 127 sn->context = context;
128 sn->handle = curl_easy_init(); 128 sn->handle = curl_easy_init();
129 //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
130 //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
129 131
130 // set proxy 132 // set proxy
131 if(sstrprefix(url, S("https"))) { 133 if(sstrprefix(url, S("https"))) {
132 if(context->https_proxy) { 134 if(context->https_proxy) {
133 //printf("use https_proxy: %s\n", context->https_proxy); 135 //printf("use https_proxy: %s\n", context->https_proxy);
685 int r = dav_create(parent_res); 687 int r = dav_create(parent_res);
686 if(r) { 688 if(r) {
687 free(parent); 689 free(parent);
688 return r; 690 return r;
689 } 691 }
690 } else if(parent_res && !res->iscollection) { 692 } else if(parent_res && !parent_res->iscollection) {
691 sn->error = DAV_FORBIDDEN; 693 sn->error = DAV_FORBIDDEN;
692 return 1; 694 return 1;
693 } else if(sn->error != DAV_OK) { 695 } else if(sn->error != DAV_OK) {
694 return 1; 696 return 1;
695 } 697 }
697 CURL *handle = res->session->handle; 699 CURL *handle = res->session->handle;
698 curl_easy_setopt(handle, CURLOPT_URL, url); 700 curl_easy_setopt(handle, CURLOPT_URL, url);
699 free(url); 701 free(url);
700 free(parent); 702 free(parent);
701 703
702 // TODO: check iscollection and create empty resource or collection 704 // create new collection or do an empty put request
703 705 CURLcode ret;
704 CURLcode ret = do_mkcol_request(handle); 706 if(res->iscollection) {
707 ret = do_mkcol_request(handle);
708 } else {
709 ret = do_put_request(handle, "", NULL, 0);
710 }
705 int status = 0; 711 int status = 0;
706 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); 712 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
707 if(ret == CURLE_OK && (status >= 200 && status < 300)) { 713 if(ret == CURLE_OK && (status >= 200 && status < 300)) {
708 res->session->error = DAV_OK; 714 res->session->error = DAV_OK;
709 return 0; 715 return 0;

mercurial