diff options
| -rw-r--r-- | opentracker.c | 17 | ||||
| -rw-r--r-- | ot_http.c | 28 | ||||
| -rw-r--r-- | ot_http.h | 4 |
3 files changed, 27 insertions, 22 deletions
diff --git a/opentracker.c b/opentracker.c index 0ae98e6..354e837 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -163,7 +163,7 @@ static void handle_dead(const int64 sock) { | |||
| 163 | for (i = 0; i < cookie->batches; ++i) | 163 | for (i = 0; i < cookie->batches; ++i) |
| 164 | iob_reset(cookie->batch + i); | 164 | iob_reset(cookie->batch + i); |
| 165 | free(cookie->batch); | 165 | free(cookie->batch); |
| 166 | array_reset(&cookie->request); | 166 | buf_reset(&cookie->request); |
| 167 | if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) | 167 | if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) |
| 168 | mutex_workqueue_canceltask(sock); | 168 | mutex_workqueue_canceltask(sock); |
| 169 | free(cookie); | 169 | free(cookie); |
| @@ -189,25 +189,24 @@ static void handle_read(const int64 sock, struct ot_workstruct *ws) { | |||
| 189 | ws->keep_alive = 0; | 189 | ws->keep_alive = 0; |
| 190 | 190 | ||
| 191 | /* If we get the whole request in one packet, handle it without copying */ | 191 | /* If we get the whole request in one packet, handle it without copying */ |
| 192 | if (!array_start(&cookie->request)) { | 192 | if (!cookie->request.data) { |
| 193 | if ((ws->header_size = header_complete(ws->inbuf, byte_count))) { | 193 | if ((ws->header_size = header_complete(ws->inbuf, byte_count))) { |
| 194 | ws->request = ws->inbuf; | 194 | ws->request = ws->inbuf; |
| 195 | ws->request_size = byte_count; | 195 | ws->request_size = byte_count; |
| 196 | http_handle_request(sock, ws); | 196 | http_handle_request(sock, ws); |
| 197 | } else | 197 | } else if (buf_cat(&cookie->request, ws->inbuf, (size_t)byte_count)) |
| 198 | array_catb(&cookie->request, ws->inbuf, (size_t)byte_count); | 198 | handle_dead(sock); |
| 199 | return; | 199 | return; |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | array_catb(&cookie->request, ws->inbuf, byte_count); | 202 | if (buf_cat(&cookie->request, ws->inbuf, (size_t)byte_count) || cookie->request.size > G_INBUF_SIZE) { |
| 203 | if (array_failed(&cookie->request) || array_bytes(&cookie->request) > 8192) { | ||
| 204 | http_issue_error(sock, ws, CODE_HTTPERROR_500); | 203 | http_issue_error(sock, ws, CODE_HTTPERROR_500); |
| 205 | return; | 204 | return; |
| 206 | } | 205 | } |
| 207 | 206 | ||
| 208 | while ((ws->header_size = header_complete(array_start(&cookie->request), array_bytes(&cookie->request)))) { | 207 | while ((ws->header_size = header_complete(cookie->request.data, (ssize_t)cookie->request.size))) { |
| 209 | ws->request = array_start(&cookie->request); | 208 | ws->request = cookie->request.data; |
| 210 | ws->request_size = array_bytes(&cookie->request); | 209 | ws->request_size = (ssize_t)cookie->request.size; |
| 211 | http_handle_request(sock, ws); | 210 | http_handle_request(sock, ws); |
| 212 | #ifdef WANT_KEEPALIVE | 211 | #ifdef WANT_KEEPALIVE |
| 213 | if (!ws->keep_alive) | 212 | if (!ws->keep_alive) |
| @@ -15,7 +15,6 @@ | |||
| 15 | #include <unistd.h> | 15 | #include <unistd.h> |
| 16 | 16 | ||
| 17 | /* Libowfat */ | 17 | /* Libowfat */ |
| 18 | #include "array.h" | ||
| 19 | #include "iob.h" | 18 | #include "iob.h" |
| 20 | #include "ip6.h" | 19 | #include "ip6.h" |
| 21 | 20 | ||
| @@ -54,20 +53,25 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
| 54 | return; | 53 | return; |
| 55 | } | 54 | } |
| 56 | 55 | ||
| 57 | /* whoever sends data is not interested in its input-array */ | 56 | /* whoever sends data is not interested in its input buffer */ |
| 58 | if (ws->keep_alive && ws->header_size != ws->request_size) { | 57 | if (ws->keep_alive && ws->header_size != ws->request_size) { |
| 59 | size_t rest = ws->request_size - ws->header_size; | 58 | size_t rest = ws->request_size - ws->header_size; |
| 60 | if (array_start(&cookie->request)) { | 59 | if (cookie->request.data) { |
| 61 | memmove(array_start(&cookie->request), ws->request + ws->header_size, rest); | 60 | memmove(cookie->request.data, ws->request + ws->header_size, rest); |
| 62 | array_truncate(&cookie->request, 1, rest); | 61 | buf_truncate(&cookie->request, rest); |
| 63 | } else | 62 | } else if (buf_cat(&cookie->request, ws->request + ws->header_size, rest)) { |
| 64 | array_catb(&cookie->request, ws->request + ws->header_size, rest); | 63 | /* Without room for what the client pipelined behind this request, answer |
| 64 | this one and let the connection close, rather than keeping it open | ||
| 65 | around a request we have silently dropped */ | ||
| 66 | buf_reset(&cookie->request); | ||
| 67 | ws->keep_alive = 0; | ||
| 68 | } | ||
| 65 | } else | 69 | } else |
| 66 | array_reset(&cookie->request); | 70 | buf_reset(&cookie->request); |
| 67 | 71 | ||
| 68 | written_size = write(sock, ws->reply, ws->reply_size); | 72 | written_size = write(sock, ws->reply, ws->reply_size); |
| 69 | if ((written_size < 0) || ((written_size == ws->reply_size) && !ws->keep_alive)) { | 73 | if ((written_size < 0) || ((written_size == ws->reply_size) && !ws->keep_alive)) { |
| 70 | array_reset(&cookie->request); | 74 | buf_reset(&cookie->request); |
| 71 | free(cookie); | 75 | free(cookie); |
| 72 | io_close(sock); | 76 | io_close(sock); |
| 73 | return; | 77 | return; |
| @@ -78,7 +82,7 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
| 78 | tai6464 t; | 82 | tai6464 t; |
| 79 | 83 | ||
| 80 | if (!(outbuf = malloc(ws->reply_size - written_size))) { | 84 | if (!(outbuf = malloc(ws->reply_size - written_size))) { |
| 81 | array_reset(&cookie->request); | 85 | buf_reset(&cookie->request); |
| 82 | free(cookie); | 86 | free(cookie); |
| 83 | io_close(sock); | 87 | io_close(sock); |
| 84 | return; | 88 | return; |
| @@ -90,7 +94,7 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
| 90 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { | 94 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
| 91 | free(cookie->batch); | 95 | free(cookie->batch); |
| 92 | free(outbuf); | 96 | free(outbuf); |
| 93 | array_reset(&cookie->request); | 97 | buf_reset(&cookie->request); |
| 94 | free(cookie); | 98 | free(cookie); |
| 95 | io_close(sock); | 99 | io_close(sock); |
| 96 | return; | 100 | return; |
| @@ -155,7 +159,7 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, size_t io | |||
| 155 | } | 159 | } |
| 156 | 160 | ||
| 157 | /* If this socket collected request in a buffer, free it now */ | 161 | /* If this socket collected request in a buffer, free it now */ |
| 158 | array_reset(&cookie->request); | 162 | buf_reset(&cookie->request); |
| 159 | 163 | ||
| 160 | /* If we came here, wait for the answer is over */ | 164 | /* If we came here, wait for the answer is over */ |
| 161 | if (cookie->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK) { | 165 | if (cookie->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK) { |
| @@ -6,6 +6,8 @@ | |||
| 6 | #ifndef OT_HTTP_H__ | 6 | #ifndef OT_HTTP_H__ |
| 7 | #define OT_HTTP_H__ | 7 | #define OT_HTTP_H__ |
| 8 | 8 | ||
| 9 | #include "ot_buf.h" | ||
| 10 | |||
| 9 | typedef enum { | 11 | typedef enum { |
| 10 | STRUCT_HTTP_FLAG_WAITINGFORTASK = 1, | 12 | STRUCT_HTTP_FLAG_WAITINGFORTASK = 1, |
| 11 | STRUCT_HTTP_FLAG_GZIP = 2, | 13 | STRUCT_HTTP_FLAG_GZIP = 2, |
| @@ -16,7 +18,7 @@ typedef enum { | |||
| 16 | } STRUCT_HTTP_FLAG; | 18 | } STRUCT_HTTP_FLAG; |
| 17 | 19 | ||
| 18 | struct http_data { | 20 | struct http_data { |
| 19 | array request; | 21 | ot_buf request; |
| 20 | io_batch *batch; | 22 | io_batch *batch; |
| 21 | size_t batches; | 23 | size_t batches; |
| 22 | ot_ip6 ip; | 24 | ot_ip6 ip; |
