libidav/resource.c

changeset 103
6606616eca9f
parent 102
64ded9f6a6c6
child 108
77254bd6dccb
equal deleted inserted replaced
102:64ded9f6a6c6 103:6606616eca9f
821 } 821 }
822 822
823 static size_t dav_read_h(void *buf, size_t size, size_t nelm, void *stream) { 823 static size_t dav_read_h(void *buf, size_t size, size_t nelm, void *stream) {
824 HashStream *s = stream; 824 HashStream *s = stream;
825 if(!s->sha) { 825 if(!s->sha) {
826 s->sha = dav_hash_init(); 826 s->sha = dav_sha256_create();
827 } 827 }
828 828
829 size_t r = s->read(buf, size, nelm, s->stream); 829 size_t r = s->read(buf, size, nelm, s->stream);
830 dav_hash_update(s->sha, buf, r); 830 dav_sha256_update(s->sha, buf, r);
831 return r; 831 return r;
832 } 832 }
833 833
834 static int dav_seek_h(void *stream, long offset, int whence) { 834 static int dav_seek_h(void *stream, long offset, int whence) {
835 HashStream *s = stream; 835 HashStream *s = stream;
836 if(offset == 0 && whence == SEEK_SET) { 836 if(offset == 0 && whence == SEEK_SET) {
837 unsigned char buf[DAV_SHA256_DIGEST_LENGTH]; 837 unsigned char buf[DAV_SHA256_DIGEST_LENGTH];
838 dav_hash_final(s->sha, buf); 838 dav_sha256_final(s->sha, buf);
839 s->sha = NULL; 839 s->sha = NULL;
840 } else { 840 } else {
841 s->error = 1; 841 s->error = 1;
842 } 842 }
843 return s->seek(s->stream, offset, whence); 843 return s->seek(s->stream, offset, whence);
936 dav_read_h, 936 dav_read_h,
937 (dav_seek_func)dav_seek_h, 937 (dav_seek_func)dav_seek_h,
938 data->length); 938 data->length);
939 939
940 if(hstr.sha) { 940 if(hstr.sha) {
941 dav_hash_final(hstr.sha, (unsigned char*)data->hash); 941 dav_sha256_final(hstr.sha, (unsigned char*)data->hash);
942 char *hash = util_hexstr((unsigned char*)data->hash, 32); 942 char *hash = util_hexstr((unsigned char*)data->hash, 32);
943 dav_set_string_property_ns(res, DAV_NS, "content-hash", hash); 943 dav_set_string_property_ns(res, DAV_NS, "content-hash", hash);
944 free(hash); 944 free(hash);
945 } 945 }
946 } else { 946 } else {
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL); 1116 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
1117 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); 1117 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
1118 curl_easy_setopt(handle, CURLOPT_PUT, 0L);
1119 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); 1118 curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
1120 1119
1121 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc); 1120 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_fnc);
1122 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream); 1121 curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
1123 1122
1660 1659
1661 in->m = curl_multi_init(); 1660 in->m = curl_multi_init();
1662 1661
1663 curl_easy_setopt(in->c, CURLOPT_HTTPHEADER, NULL); 1662 curl_easy_setopt(in->c, CURLOPT_HTTPHEADER, NULL);
1664 curl_easy_setopt(in->c, CURLOPT_CUSTOMREQUEST, NULL); 1663 curl_easy_setopt(in->c, CURLOPT_CUSTOMREQUEST, NULL);
1665 curl_easy_setopt(in->c, CURLOPT_PUT, 0L);
1666 curl_easy_setopt(in->c, CURLOPT_UPLOAD, 0L); 1664 curl_easy_setopt(in->c, CURLOPT_UPLOAD, 0L);
1667 1665
1668 curl_multi_add_handle(in->m, in->c); 1666 curl_multi_add_handle(in->m, in->c);
1669 1667
1670 dav_write_func write_fnc = (dav_write_func)in_write; 1668 dav_write_func write_fnc = (dav_write_func)in_write;
1798 } 1796 }
1799 1797
1800 curl_easy_setopt(out->c, CURLOPT_HEADERFUNCTION, NULL); 1798 curl_easy_setopt(out->c, CURLOPT_HEADERFUNCTION, NULL);
1801 curl_easy_setopt(out->c, CURLOPT_HTTPHEADER, NULL); 1799 curl_easy_setopt(out->c, CURLOPT_HTTPHEADER, NULL);
1802 curl_easy_setopt(out->c, CURLOPT_CUSTOMREQUEST, NULL); 1800 curl_easy_setopt(out->c, CURLOPT_CUSTOMREQUEST, NULL);
1803 curl_easy_setopt(out->c, CURLOPT_PUT, 1L);
1804 curl_easy_setopt(out->c, CURLOPT_UPLOAD, 1L); 1801 curl_easy_setopt(out->c, CURLOPT_UPLOAD, 1L);
1805 curl_easy_setopt(out->c, CURLOPT_READFUNCTION, read_fnc); 1802 curl_easy_setopt(out->c, CURLOPT_READFUNCTION, read_fnc);
1806 curl_easy_setopt(out->c, CURLOPT_READDATA, stream); 1803 curl_easy_setopt(out->c, CURLOPT_READDATA, stream);
1807 curl_easy_setopt(out->c, CURLOPT_SEEKFUNCTION, NULL); 1804 curl_easy_setopt(out->c, CURLOPT_SEEKFUNCTION, NULL);
1808 curl_easy_setopt(out->c, CURLOPT_INFILESIZE, -1); 1805 curl_easy_setopt(out->c, CURLOPT_INFILESIZE, -1);

mercurial