src/server/safs/service.c

changeset 116
d7a186cf87f6
parent 104
a8acbb12f27c
child 127
84e206063b64
equal deleted inserted replaced
115:51d9a15eac98 116:d7a186cf87f6
51 * adds content-length header 51 * adds content-length header
52 * 52 *
53 * return the opened file 53 * return the opened file
54 */ 54 */
55 SYS_FILE prepare_service_file(Session *sn, Request *rq, VFSContext *vfs, struct stat *s) { 55 SYS_FILE prepare_service_file(Session *sn, Request *rq, VFSContext *vfs, struct stat *s) {
56 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); 56 char *path = pblock_findkeyval(pb_key_path, rq->vars);
57 57
58 // open the file 58 // open the file
59 SYS_FILE fd = vfs_open(vfs, ppath, O_RDONLY); 59 SYS_FILE fd = vfs_open(vfs, path, O_RDONLY);
60 if(!fd) { 60 if(!fd) {
61 // vfs_open sets http status code 61 // vfs_open sets http status code
62 return NULL; 62 return NULL;
63 } 63 }
64 64
347 rangeelm = rangeelm->next; 347 rangeelm = rangeelm->next;
348 i++; 348 i++;
349 } 349 }
350 net_printf(sn->csd, "%s--\r\n", sep); 350 net_printf(sn->csd, "%s--\r\n", sep);
351 351
352 free(r);
352 return 0; 353 return 0;
353 } 354 }
354 355
355 int send_file(pblock *pb, Session *sn, Request *rq) { 356 int send_file(pblock *pb, Session *sn, Request *rq) {
356 struct stat s; 357 struct stat s;
449 } 450 }
450 451
451 int service_index(pblock *pb, Session *sn, Request *rq) { 452 int service_index(pblock *pb, Session *sn, Request *rq) {
452 //printf("service_index\n"); 453 //printf("service_index\n");
453 454
454 char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars); 455 char *path = pblock_findkeyval(pb_key_path, rq->vars);
455 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); 456 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
456 457
457 sstr_t r_uri = sstr(uri); 458 sstr_t r_uri = sstr(uri);
458 459
459 // open the file 460 // open the file
460 VFSContext *vfs = vfs_request_context(sn, rq); 461 VFSContext *vfs = vfs_request_context(sn, rq);
461 VFS_DIR dir = vfs_opendir(vfs, ppath); 462 VFS_DIR dir = vfs_opendir(vfs, path);
462 if(!dir) { 463 if(!dir) {
463 return REQ_ABORTED; 464 return REQ_ABORTED;
464 } 465 }
465 466
466 sbuf_t *out = sbuf_new(1024); // output buffer 467 sbuf_t *out = sbuf_new(1024); // output buffer

mercurial