src/server/safs/service.c

changeset 44
3da1f7b6847f
parent 21
627b09ee74e4
child 47
ce9790523346
--- a/src/server/safs/service.c	Tue Jan 01 14:02:25 2013 +0100
+++ b/src/server/safs/service.c	Tue Jan 01 19:22:56 2013 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2011 Olaf Wintermann. All rights reserved.
+ * Copyright 2013 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -27,7 +27,6 @@
  */
 
 #include <stdio.h>
-#include <errno.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 
@@ -39,6 +38,8 @@
 #include <sys/sendfile.h>
 #include "../util/strbuf.h"
 
+#include <errno.h>
+
 // TODO: system sendfile Abstraktionen in neue Datei auslagern
 /*
 ssize_t sys_sendfile(int out_fd, int in_fd, off_t *off, size_t len) {
@@ -53,7 +54,7 @@
  *
  * adds content-length header and starts the response
  *
- * return the file descriptor or an error code
+ * return the file descriptor or -1
  */
 int prepare_service_file(Session *sn, Request *rq) {
     char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
@@ -64,7 +65,8 @@
         perror("prepare_service_file: open");
 
         int status = 500;
-        switch(errno) {
+        int en = errno;
+        switch(en) {
             case EACCES: {
                 status = 403;
                 break;
@@ -103,9 +105,9 @@
 int send_file(pblock *pb, Session *sn, Request *rq) {
     int fd = prepare_service_file(sn, rq);
     if(fd < 0) {
-        /* TODO: service error */
-        http_start_response(sn, rq);
-        return REQ_PROCEED;
+        // if an error occurs, prepare_service_file sets the http status code
+        // we can just return REQ_ABORTED
+        return REQ_ABORTED;
     }
 
     /* send file*/

mercurial