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); |
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; |