application/davcontroller.c

changeset 77
5de33c2d94c6
parent 68
79a9aadf1c70
child 78
ad7ced6cf00b
equal deleted inserted replaced
76:641dcc79e0ef 77:5de33c2d94c6
880 DDFile *file = data; 880 DDFile *file = data;
881 881
882 file->download->current_file_downloaded = 0; 882 file->download->current_file_downloaded = 0;
883 file->download->current_file_size = file->size; 883 file->download->current_file_size = file->size;
884 884
885 FILE *f = fopen(file->to, "wb"); 885 FILE *f = sys_fopen(file->to, "wb");
886 if (!f) { 886 if (!f) {
887 return 0; 887 return 0;
888 } 888 }
889 file->fd = f; 889 file->fd = f;
890 890
1297 1297
1298 unsigned char rd[8]; 1298 unsigned char rd[8];
1299 memset(rd, 0, 8); 1299 memset(rd, 0, 8);
1300 dav_rand_bytes(rd, 8); 1300 dav_rand_bytes(rd, 8);
1301 char *hex = util_hexstr(rd, 8); 1301 char *hex = util_hexstr(rd, 8);
1302 cxmutstr tmp = cx_asprintf("%sdownload-%s-%s", dir, name, hex); 1302 cxmutstr tmp = cx_asprintf("%sdownload-%s-%s", dir, hex, name);
1303 return tmp.ptr; 1303 return tmp.ptr;
1304 } 1304 }
1305 1305
1306 static int jobthr_resourceviewer_load(void *data) { 1306 static int jobthr_resourceviewer_load(void *data) {
1307 DavResourceViewer *doc = data; 1307 DavResourceViewer *doc = data;
1320 doc->error = err; 1320 doc->error = err;
1321 doc->message_str = "Cannot load content"; // TODO: better message 1321 doc->message_str = "Cannot load content"; // TODO: better message
1322 } 1322 }
1323 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { 1323 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) {
1324 char *tmp = gen_tmp_download_filename(res->name); 1324 char *tmp = gen_tmp_download_filename(res->name);
1325 FILE *f = fopen(tmp, "w"); 1325 FILE *f = sys_fopen(tmp, "wb");
1326 if(f) { 1326 if(f) {
1327 int err = dav_get_content(res, f, (dav_write_func)fwrite); 1327 int err = dav_get_content(res, f, (dav_write_func)fwrite);
1328 if(!err) { 1328 if(!err) {
1329 doc->tmp_file = tmp; 1329 doc->tmp_file = tmp;
1330 } else { 1330 } else {
1445 1445
1446 if(doc->type == DAV_RESOURCE_VIEW_TEXT) { 1446 if(doc->type == DAV_RESOURCE_VIEW_TEXT) {
1447 ui_set(doc->text, doc->text_content->space); 1447 ui_set(doc->text, doc->text_content->space);
1448 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) { 1448 } else if(doc->type == DAV_RESOURCE_VIEW_IMAGE) {
1449 ui_image_load_file(doc->image, doc->tmp_file); 1449 ui_image_load_file(doc->image, doc->tmp_file);
1450 unlink(doc->tmp_file);
1451 } 1450 }
1452 1451
1453 ui_set(doc->tabview, 1); 1452 ui_set(doc->tabview, 1);
1454 } 1453 }
1455 1454

mercurial