move dispatch cbs and data to one place
authorFelix Fietkau <nbd@openwrt.org>
Mon, 31 Dec 2012 18:29:44 +0000 (19:29 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 31 Dec 2012 18:29:44 +0000 (19:29 +0100)
client.c
file.c
uhttpd.h

index a28067e193b87d1bf41028f4587a6f249cd201b1..6d24ce5c80bd07eb3da9455bd4ba2798f9c3d65a 100644 (file)
--- a/client.c
+++ b/client.c
@@ -60,10 +60,8 @@ static void uh_connection_close(struct client *cl)
 
 static void uh_dispatch_done(struct client *cl)
 {
-       if (cl->dispatch_free)
-               cl->dispatch_free(cl);
-       cl->dispatch_free = NULL;
-       cl->dispatch_close_fds = NULL;
+       if (cl->dispatch.free)
+               cl->dispatch.free(cl);
 }
 
 void uh_request_done(struct client *cl)
@@ -71,7 +69,7 @@ void uh_request_done(struct client *cl)
        uh_chunk_eof(cl);
        uh_dispatch_done(cl);
        cl->us->notify_write = NULL;
-       memset(&cl->data, 0, sizeof(cl->data));
+       memset(&cl->dispatch, 0, sizeof(cl->dispatch));
 
        if (cl->request.version != UH_HTTP_VER_1_1 || !conf.http_keepalive) {
                uh_connection_close(cl);
@@ -281,8 +279,8 @@ static void client_ustream_write_cb(struct ustream *s, int bytes)
 {
        struct client *cl = container_of(s, struct client, sfd);
 
-       if (cl->dispatch_write_cb)
-               cl->dispatch_write_cb(cl);
+       if (cl->dispatch.write_cb)
+               cl->dispatch.write_cb(cl);
 }
 
 static void client_notify_state(struct ustream *s)
@@ -339,7 +337,7 @@ void uh_close_fds(void)
        uh_close_listen_fds();
        list_for_each_entry(cl, &clients, list) {
                close(cl->sfd.fd.fd);
-               if (cl->dispatch_close_fds)
-                       cl->dispatch_close_fds(cl);
+               if (cl->dispatch.close_fds)
+                       cl->dispatch.close_fds(cl);
        }
 }
diff --git a/file.c b/file.c
index 23222b9b15e07c5fe578e9968d3bc69b952db1f1..ae4517cfd3e472be430640bb22fa7ea5eddd5b93 100644 (file)
--- a/file.c
+++ b/file.c
@@ -315,10 +315,10 @@ static char * uh_file_unix2date(time_t ts)
 
 static char *uh_file_header(struct client *cl, int idx)
 {
-       if (!cl->data.file.hdr[idx])
+       if (!cl->dispatch.file.hdr[idx])
                return NULL;
 
-       return (char *) blobmsg_data(cl->data.file.hdr[idx]);
+       return (char *) blobmsg_data(cl->dispatch.file.hdr[idx]);
 }
 
 static void uh_file_response_ok_hdrs(struct client *cl, struct stat *s)
@@ -529,7 +529,7 @@ static void uh_file_dirlist(struct client *cl, struct path_info *pi)
 static void file_write_cb(struct client *cl)
 {
        char buf[512];
-       int fd = cl->data.file.fd;
+       int fd = cl->dispatch.file.fd;
        int r;
 
        while (cl->us->w.data_bytes < 256) {
@@ -550,7 +550,7 @@ static void file_write_cb(struct client *cl)
 
 static void uh_file_free(struct client *cl)
 {
-       close(cl->data.file.fd);
+       close(cl->dispatch.file.fd);
 }
 
 static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
@@ -583,10 +583,10 @@ static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
                return;
        }
 
-       cl->data.file.fd = fd;
-       cl->dispatch_write_cb = file_write_cb;
-       cl->dispatch_free = uh_file_free;
-       cl->dispatch_close_fds = uh_file_free;
+       cl->dispatch.file.fd = fd;
+       cl->dispatch.write_cb = file_write_cb;
+       cl->dispatch.free = uh_file_free;
+       cl->dispatch.close_fds = uh_file_free;
        file_write_cb(cl);
 }
 
@@ -604,7 +604,7 @@ static void uh_file_request(struct client *cl, struct path_info *pi, const char
 
        blobmsg_parse(hdr_policy, __HDR_MAX, tb, blob_data(cl->hdr.head), blob_len(cl->hdr.head));
 
-       cl->data.file.hdr = tb;
+       cl->dispatch.file.hdr = tb;
 
        if (!(pi->stat.st_mode & S_IROTH))
                goto error;
@@ -642,7 +642,7 @@ static bool __handle_file_request(struct client *cl, const char *url)
 
        if (!pi->redirected) {
                uh_file_request(cl, pi, url);
-               cl->data.file.hdr = NULL;
+               cl->dispatch.file.hdr = NULL;
        }
 
        return true;
index 02d270508d80f21b31919dcf7ef4a2d0d3c88469..a465a3dbf2c5d2cb0d27e92de59f2d47ab683df7 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -118,16 +118,17 @@ struct client {
 
        struct blob_buf hdr;
 
-       void (*dispatch_write_cb)(struct client *cl);
-       void (*dispatch_close_fds)(struct client *cl);
-       void (*dispatch_free)(struct client *cl);
-
-       union {
-               struct {
-                       struct blob_attr **hdr;
-                       int fd;
-               } file;
-       } data;
+       struct {
+               void (*write_cb)(struct client *cl);
+               void (*close_fds)(struct client *cl);
+               void (*free)(struct client *cl);
+               union {
+                       struct {
+                               struct blob_attr **hdr;
+                               int fd;
+                       } file;
+               };
+       } dispatch;
 };
 
 extern int n_clients;