Commit 1d238aa55d48674707773d95b848a2bca5693749
1 parent
a0ec357e
as i have a lot of static string initialization with the length of that sting a …
…created and used a macro to prevent errors
Showing
14 changed files
with
60 additions
and
167 deletions
@@ -23,8 +23,12 @@ | @@ -23,8 +23,12 @@ | ||
23 | #ifndef __UTILS_MEMORY_H__ | 23 | #ifndef __UTILS_MEMORY_H__ |
24 | #define __UTILS_MEMORY_H__ | 24 | #define __UTILS_MEMORY_H__ |
25 | 25 | ||
26 | +#define CSTRA(val) val, sizeof(val)-1 //!< Const STRing Argument | ||
27 | + | ||
26 | #define FREE(val) (ffree((void**)&(val))) | 28 | #define FREE(val) (ffree((void**)&(val))) |
27 | 29 | ||
28 | void ffree(void **); | 30 | void ffree(void **); |
29 | 31 | ||
30 | #endif // __UTILS_MEMORY_H__ | 32 | #endif // __UTILS_MEMORY_H__ |
33 | + | ||
34 | +// vim: set ts=4 sw=4: |
@@ -28,6 +28,8 @@ | @@ -28,6 +28,8 @@ | ||
28 | #include "http/request.h" | 28 | #include "http/request.h" |
29 | #include "http/header.h" | 29 | #include "http/header.h" |
30 | 30 | ||
31 | +#include "utils/memory.h" | ||
32 | + | ||
31 | #ifndef TRUE | 33 | #ifndef TRUE |
32 | #define TRUE 1 | 34 | #define TRUE 1 |
33 | #endif | 35 | #endif |
@@ -43,10 +45,7 @@ httpMessageHasKeepAlive(HttpMessage message) | @@ -43,10 +45,7 @@ httpMessageHasKeepAlive(HttpMessage message) | ||
43 | size_t size; | 45 | size_t size; |
44 | char * value; | 46 | char * value; |
45 | 47 | ||
46 | - header = httpHeaderGet( | ||
47 | - &(message->header), | ||
48 | - "connection", | ||
49 | - sizeof("connection")-1); | 48 | + header = httpHeaderGet(&(message->header), CSTRA("connection")); |
50 | 49 | ||
51 | if (NULL == header) { | 50 | if (NULL == header) { |
52 | return 0; | 51 | return 0; |
@@ -29,6 +29,7 @@ | @@ -29,6 +29,7 @@ | ||
29 | #include "http/message.h" | 29 | #include "http/message.h" |
30 | #include "http/header.h" | 30 | #include "http/header.h" |
31 | 31 | ||
32 | +#include "utils/memory.h" | ||
32 | 33 | ||
33 | HttpResponse | 34 | HttpResponse |
34 | httpResponse304( | 35 | httpResponse304( |
@@ -47,23 +48,11 @@ httpResponse304( | @@ -47,23 +48,11 @@ httpResponse304( | ||
47 | message->body = NULL; | 48 | message->body = NULL; |
48 | 49 | ||
49 | httpHeaderAdd(&(message->header), | 50 | httpHeaderAdd(&(message->header), |
50 | - new(HttpHeader, | ||
51 | - "Content-Type", | ||
52 | - sizeof("Content-Type")-1, | ||
53 | - mime, | ||
54 | - nmime)); | 51 | + new(HttpHeader, CSTRA("Content-Type"), mime, nmime)); |
55 | httpHeaderAdd(&(message->header), | 52 | httpHeaderAdd(&(message->header), |
56 | - new(HttpHeader, | ||
57 | - "ETag", | ||
58 | - sizeof("ETag")-1, | ||
59 | - etag, | ||
60 | - netag)); | 53 | + new(HttpHeader, CSTRA("ETag"), etag, netag)); |
61 | httpHeaderAdd(&(message->header), | 54 | httpHeaderAdd(&(message->header), |
62 | - new(HttpHeader, | ||
63 | - "Last-Modified", | ||
64 | - sizeof("Last-Modified")-1, | ||
65 | - mtime, | ||
66 | - nmtime)); | 55 | + new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime)); |
67 | 56 | ||
68 | return response; | 57 | return response; |
69 | } | 58 | } |
@@ -38,8 +38,6 @@ httpResponse403() | @@ -38,8 +38,6 @@ httpResponse403() | ||
38 | { | 38 | { |
39 | HttpResponse response; | 39 | HttpResponse response; |
40 | HttpMessage message; | 40 | HttpMessage message; |
41 | - char buffer[200]; | ||
42 | - size_t nbuf; | ||
43 | 41 | ||
44 | response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); | 42 | response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); |
45 | message = (HttpMessage)response; | 43 | message = (HttpMessage)response; |
@@ -48,15 +46,6 @@ httpResponse403() | @@ -48,15 +46,6 @@ httpResponse403() | ||
48 | message->nbody = 0; | 46 | message->nbody = 0; |
49 | message->body = NULL; | 47 | message->body = NULL; |
50 | 48 | ||
51 | - nbuf = sprintf(buffer, "%d", message->nbody); | ||
52 | - | ||
53 | - httpHeaderAdd(&(message->header), | ||
54 | - new(HttpHeader, | ||
55 | - "Content-Length", | ||
56 | - sizeof("Content-Length")-1, | ||
57 | - buffer, | ||
58 | - nbuf)); | ||
59 | - | ||
60 | return response; | 49 | return response; |
61 | } | 50 | } |
62 | 51 |
@@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
32 | #include "http/message.h" | 32 | #include "http/message.h" |
33 | #include "http/header.h" | 33 | #include "http/header.h" |
34 | 34 | ||
35 | +#include "utils/memory.h" | ||
35 | 36 | ||
36 | #define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ | 37 | #define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ |
37 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ | 38 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ |
@@ -45,35 +46,20 @@ | @@ -45,35 +46,20 @@ | ||
45 | HttpResponse | 46 | HttpResponse |
46 | httpResponse404() | 47 | httpResponse404() |
47 | { | 48 | { |
48 | - char buffer[200]; | ||
49 | HttpResponse response; | 49 | HttpResponse response; |
50 | HttpMessage message; | 50 | HttpMessage message; |
51 | - size_t nbuf; | ||
52 | 51 | ||
53 | response = new(HttpResponse, "HTTP/1.1", 404, "Not Found"); | 52 | response = new(HttpResponse, "HTTP/1.1", 404, "Not Found"); |
54 | message = (HttpMessage)response; | 53 | message = (HttpMessage)response; |
55 | 54 | ||
56 | httpHeaderAdd(&(message->header), | 55 | httpHeaderAdd(&(message->header), |
57 | - new(HttpHeader, | ||
58 | - "Content-Type", | ||
59 | - sizeof("Content-Type")-1, | ||
60 | - "text/html", | ||
61 | - sizeof("text/html")-1)); | 56 | + new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); |
62 | 57 | ||
63 | message->type = HTTP_MESSAGE_BUFFERED; | 58 | message->type = HTTP_MESSAGE_BUFFERED; |
64 | message->nbody = sizeof(RESP_DATA) - 1; | 59 | message->nbody = sizeof(RESP_DATA) - 1; |
65 | message->body = malloc(sizeof(RESP_DATA)); | 60 | message->body = malloc(sizeof(RESP_DATA)); |
66 | memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); | 61 | memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); |
67 | 62 | ||
68 | - nbuf = sprintf(buffer, "%d", message->nbody); | ||
69 | - | ||
70 | - httpHeaderAdd(&(message->header), | ||
71 | - new(HttpHeader, | ||
72 | - "Content-Length", | ||
73 | - sizeof("Content-Length")-1, | ||
74 | - buffer, | ||
75 | - nbuf)); | ||
76 | - | ||
77 | return response; | 63 | return response; |
78 | } | 64 | } |
79 | 65 |
@@ -33,6 +33,8 @@ | @@ -33,6 +33,8 @@ | ||
33 | #include "http/message.h" | 33 | #include "http/message.h" |
34 | #include "http/header.h" | 34 | #include "http/header.h" |
35 | 35 | ||
36 | +#include "utils/memory.h" | ||
37 | + | ||
36 | 38 | ||
37 | HttpResponse | 39 | HttpResponse |
38 | httpResponseAsset( | 40 | httpResponseAsset( |
@@ -47,8 +49,6 @@ httpResponseAsset( | @@ -47,8 +49,6 @@ httpResponseAsset( | ||
47 | size_t netag; | 49 | size_t netag; |
48 | char mtime[200]; | 50 | char mtime[200]; |
49 | size_t nmtime; | 51 | size_t nmtime; |
50 | - char clen[200]; | ||
51 | - size_t nclen; | ||
52 | struct stat st; | 52 | struct stat st; |
53 | HttpResponse response; | 53 | HttpResponse response; |
54 | HttpMessage message; | 54 | HttpMessage message; |
@@ -72,32 +72,12 @@ httpResponseAsset( | @@ -72,32 +72,12 @@ httpResponseAsset( | ||
72 | message->handle = handle; | 72 | message->handle = handle; |
73 | message->nbody = st.st_size; | 73 | message->nbody = st.st_size; |
74 | 74 | ||
75 | - nclen = sprintf(clen, "%d", message->nbody); | ||
76 | - | ||
77 | - httpHeaderAdd(&(message->header), | ||
78 | - new(HttpHeader, | ||
79 | - "Content-Type", | ||
80 | - sizeof("Content-Type")-1, | ||
81 | - mime, | ||
82 | - nmime)); | ||
83 | httpHeaderAdd(&(message->header), | 75 | httpHeaderAdd(&(message->header), |
84 | - new(HttpHeader, | ||
85 | - "Content-Length", | ||
86 | - sizeof("Content-Length")-1, | ||
87 | - clen, | ||
88 | - nclen)); | 76 | + new(HttpHeader, CSTRA("Content-Type"), mime, nmime)); |
89 | httpHeaderAdd(&(message->header), | 77 | httpHeaderAdd(&(message->header), |
90 | - new(HttpHeader, | ||
91 | - "ETag", | ||
92 | - sizeof("ETag")-1, | ||
93 | - etag, | ||
94 | - netag)); | 78 | + new(HttpHeader, CSTRA("ETag"), etag, netag)); |
95 | httpHeaderAdd(&(message->header), | 79 | httpHeaderAdd(&(message->header), |
96 | - new(HttpHeader, | ||
97 | - "Last-Modified", | ||
98 | - sizeof("Last-Modified")-1, | ||
99 | - mtime, | ||
100 | - nmtime)); | 80 | + new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime)); |
101 | 81 | ||
102 | return response; | 82 | return response; |
103 | } | 83 | } |
@@ -33,6 +33,8 @@ | @@ -33,6 +33,8 @@ | ||
33 | #include "http/message.h" | 33 | #include "http/message.h" |
34 | #include "http/header.h" | 34 | #include "http/header.h" |
35 | 35 | ||
36 | +#include "utils/memory.h" | ||
37 | + | ||
36 | #define RESP_DATA "<form action=\"/me/\" method=\"POST\">" \ | 38 | #define RESP_DATA "<form action=\"/me/\" method=\"POST\">" \ |
37 | "<input name=\"username\" type=\"text\" />" \ | 39 | "<input name=\"username\" type=\"text\" />" \ |
38 | "<input type=\"submit\">" \ | 40 | "<input type=\"submit\">" \ |
@@ -41,20 +43,14 @@ | @@ -41,20 +43,14 @@ | ||
41 | HttpResponse | 43 | HttpResponse |
42 | httpResponseLoginForm() | 44 | httpResponseLoginForm() |
43 | { | 45 | { |
44 | - char buffer[200]; | ||
45 | HttpResponse response; | 46 | HttpResponse response; |
46 | HttpMessage message; | 47 | HttpMessage message; |
47 | - size_t nbuf; | ||
48 | 48 | ||
49 | response = new(HttpResponse, "HTTP/1.1", 200, "OK"); | 49 | response = new(HttpResponse, "HTTP/1.1", 200, "OK"); |
50 | message = (HttpMessage)response; | 50 | message = (HttpMessage)response; |
51 | 51 | ||
52 | httpHeaderAdd(&(message->header), | 52 | httpHeaderAdd(&(message->header), |
53 | - new(HttpHeader, | ||
54 | - "Content-Type", | ||
55 | - sizeof("Content-Type")-1, | ||
56 | - "text/html", | ||
57 | - sizeof("text/html")-1)); | 53 | + new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); |
58 | 54 | ||
59 | message->type = HTTP_MESSAGE_BUFFERED; | 55 | message->type = HTTP_MESSAGE_BUFFERED; |
60 | 56 | ||
@@ -62,15 +58,6 @@ httpResponseLoginForm() | @@ -62,15 +58,6 @@ httpResponseLoginForm() | ||
62 | message->body = malloc(message->nbody); | 58 | message->body = malloc(message->nbody); |
63 | memcpy(message->body, RESP_DATA, message->nbody); | 59 | memcpy(message->body, RESP_DATA, message->nbody); |
64 | 60 | ||
65 | - nbuf = sprintf(buffer, "%d", message->nbody); | ||
66 | - | ||
67 | - httpHeaderAdd(&(message->header), | ||
68 | - new(HttpHeader, | ||
69 | - "Content-Length", | ||
70 | - sizeof("Content-Length")-1, | ||
71 | - buffer, | ||
72 | - nbuf)); | ||
73 | - | ||
74 | return response; | 61 | return response; |
75 | } | 62 | } |
76 | 63 |
@@ -33,6 +33,8 @@ | @@ -33,6 +33,8 @@ | ||
33 | #include "http/message.h" | 33 | #include "http/message.h" |
34 | #include "http/header.h" | 34 | #include "http/header.h" |
35 | 35 | ||
36 | +#include "utils/memory.h" | ||
37 | + | ||
36 | 38 | ||
37 | #define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ | 39 | #define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ |
38 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ | 40 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ |
@@ -124,32 +126,18 @@ | @@ -124,32 +126,18 @@ | ||
124 | HttpResponse | 126 | HttpResponse |
125 | httpResponseMe(char * uname) | 127 | httpResponseMe(char * uname) |
126 | { | 128 | { |
127 | - char buffer[200]; | ||
128 | HttpResponse response; | 129 | HttpResponse response; |
129 | HttpMessage message; | 130 | HttpMessage message; |
130 | - size_t nbuf; | ||
131 | 131 | ||
132 | response = new(HttpResponse, "HTTP/1.1", 200, "OK"); | 132 | response = new(HttpResponse, "HTTP/1.1", 200, "OK"); |
133 | message = (HttpMessage)response; | 133 | message = (HttpMessage)response; |
134 | 134 | ||
135 | httpHeaderAdd(&(message->header), | 135 | httpHeaderAdd(&(message->header), |
136 | - new(HttpHeader, | ||
137 | - "Content-Type", | ||
138 | - sizeof("Content-Type")-1, | ||
139 | - "text/html", | ||
140 | - sizeof("text/html")-1)); | 136 | + new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); |
141 | httpHeaderAdd(&(message->header), | 137 | httpHeaderAdd(&(message->header), |
142 | - new(HttpHeader, | ||
143 | - "Set-Cookie", | ||
144 | - sizeof("Set-Cookie")-1, | ||
145 | - "name=\"Georg Hopp\"", | ||
146 | - sizeof("name=\"Georg Hopp\"")-1)); | 138 | + new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("name=Georg+Hopp"))); |
147 | httpHeaderAdd(&(message->header), | 139 | httpHeaderAdd(&(message->header), |
148 | - new(HttpHeader, | ||
149 | - "Set-Cookie", | ||
150 | - sizeof("Set-Cookie")-1, | ||
151 | - "profession=\"coder\"", | ||
152 | - sizeof("profession=\"coder\"")-1)); | 140 | + new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("profession=coder"))); |
153 | 141 | ||
154 | message->type = HTTP_MESSAGE_BUFFERED; | 142 | message->type = HTTP_MESSAGE_BUFFERED; |
155 | message->nbody = sizeof(RESP_DATA)-1-2+strlen(uname); //!< the two are the %s | 143 | message->nbody = sizeof(RESP_DATA)-1-2+strlen(uname); //!< the two are the %s |
@@ -157,15 +145,6 @@ httpResponseMe(char * uname) | @@ -157,15 +145,6 @@ httpResponseMe(char * uname) | ||
157 | sprintf(message->body, RESP_DATA, uname); | 145 | sprintf(message->body, RESP_DATA, uname); |
158 | //memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1); | 146 | //memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1); |
159 | 147 | ||
160 | - nbuf = sprintf(buffer, "%d", message->nbody); | ||
161 | - | ||
162 | - httpHeaderAdd(&(message->header), | ||
163 | - new(HttpHeader, | ||
164 | - "Content-Length", | ||
165 | - sizeof("Content-Length")-1, | ||
166 | - buffer, | ||
167 | - nbuf)); | ||
168 | - | ||
169 | return response; | 148 | return response; |
170 | } | 149 | } |
171 | 150 |
@@ -33,6 +33,8 @@ | @@ -33,6 +33,8 @@ | ||
33 | #include "http/message.h" | 33 | #include "http/message.h" |
34 | #include "http/header.h" | 34 | #include "http/header.h" |
35 | 35 | ||
36 | +#include "utils/memory.h" | ||
37 | + | ||
36 | #define RESP_DATA "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}" | 38 | #define RESP_DATA "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}" |
37 | 39 | ||
38 | HttpResponse | 40 | HttpResponse |
@@ -48,11 +50,7 @@ httpResponseRandval(time_t ctime, int value) | @@ -48,11 +50,7 @@ httpResponseRandval(time_t ctime, int value) | ||
48 | message = (HttpMessage)response; | 50 | message = (HttpMessage)response; |
49 | 51 | ||
50 | httpHeaderAdd(&(message->header), | 52 | httpHeaderAdd(&(message->header), |
51 | - new(HttpHeader, | ||
52 | - "Content-Type", | ||
53 | - sizeof("Content-Type")-1, | ||
54 | - "application/json", | ||
55 | - sizeof("application/json")-1)); | 53 | + new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json"))); |
56 | 54 | ||
57 | message->type = HTTP_MESSAGE_BUFFERED; | 55 | message->type = HTTP_MESSAGE_BUFFERED; |
58 | 56 | ||
@@ -64,15 +62,6 @@ httpResponseRandval(time_t ctime, int value) | @@ -64,15 +62,6 @@ httpResponseRandval(time_t ctime, int value) | ||
64 | message->body = malloc(nbuf); | 62 | message->body = malloc(nbuf); |
65 | memcpy(message->body, buffer, nbuf); | 63 | memcpy(message->body, buffer, nbuf); |
66 | 64 | ||
67 | - nbuf = sprintf(buffer, "%d", message->nbody); | ||
68 | - | ||
69 | - httpHeaderAdd(&(message->header), | ||
70 | - new(HttpHeader, | ||
71 | - "Content-Length", | ||
72 | - sizeof("Content-Length")-1, | ||
73 | - buffer, | ||
74 | - nbuf)); | ||
75 | - | ||
76 | return response; | 65 | return response; |
77 | } | 66 | } |
78 | 67 |
@@ -7,49 +7,45 @@ | @@ -7,49 +7,45 @@ | ||
7 | #include "http/message.h" | 7 | #include "http/message.h" |
8 | #include "http/response.h" | 8 | #include "http/response.h" |
9 | 9 | ||
10 | +#include "utils/memory.h" | ||
11 | + | ||
10 | void | 12 | void |
11 | httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) | 13 | httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) |
12 | { | 14 | { |
13 | time_t t; | 15 | time_t t; |
14 | struct tm * tmp; | 16 | struct tm * tmp; |
15 | char buffer[200]; | 17 | char buffer[200]; |
16 | - size_t ndate; | 18 | + size_t nbuf; |
17 | 19 | ||
18 | if (httpMessageHasKeepAlive(request)) { | 20 | if (httpMessageHasKeepAlive(request)) { |
19 | httpHeaderAdd( | 21 | httpHeaderAdd( |
20 | &(response->header), | 22 | &(response->header), |
21 | - new(HttpHeader, | ||
22 | - "Connection", | ||
23 | - sizeof("Connection")-1, | ||
24 | - "Keep-Alive", | ||
25 | - sizeof("Keep-Alive")-1)); | 23 | + new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive"))); |
26 | } | 24 | } |
27 | else { | 25 | else { |
28 | httpHeaderAdd( | 26 | httpHeaderAdd( |
29 | &(response->header), | 27 | &(response->header), |
30 | - new(HttpHeader, | ||
31 | - "Connection", | ||
32 | - sizeof("Connection")-1, | ||
33 | - "Close", | ||
34 | - sizeof("Close")-1)); | 28 | + new(HttpHeader, CSTRA("Connection"), CSTRA("Close"))); |
35 | } | 29 | } |
36 | 30 | ||
37 | httpHeaderAdd(&(response->header), | 31 | httpHeaderAdd(&(response->header), |
38 | - new(HttpHeader, | ||
39 | - "Server", | ||
40 | - sizeof("Server")-1, | ||
41 | - "testserver", | ||
42 | - sizeof("testserver")-1)); | ||
43 | - | ||
44 | - t = time(NULL); | ||
45 | - tmp = localtime(&t); | ||
46 | - ndate = strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); | 32 | + new(HttpHeader, CSTRA("Server"), CSTRA("testserver"))); |
33 | + | ||
34 | + switch(((HttpResponse)response)->status) { | ||
35 | + case 304: | ||
36 | + break; | ||
37 | + | ||
38 | + default: | ||
39 | + nbuf = sprintf(buffer, "%d", response->nbody); | ||
40 | + httpHeaderAdd(&(response->header), | ||
41 | + new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); | ||
42 | + } | ||
43 | + | ||
44 | + t = time(NULL); | ||
45 | + tmp = localtime(&t); | ||
46 | + nbuf = strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); | ||
47 | httpHeaderAdd(&(response->header), | 47 | httpHeaderAdd(&(response->header), |
48 | - new(HttpHeader, | ||
49 | - "Date", | ||
50 | - sizeof("Date")-1, | ||
51 | - buffer, | ||
52 | - ndate)); | 48 | + new(HttpHeader, CSTRA("Date"), buffer, nbuf)); |
53 | } | 49 | } |
54 | 50 | ||
55 | // vim: set ts=4 sw=4: | 51 | // vim: set ts=4 sw=4: |
@@ -5,6 +5,8 @@ | @@ -5,6 +5,8 @@ | ||
5 | #include "http/request.h" | 5 | #include "http/request.h" |
6 | #include "http/response.h" | 6 | #include "http/response.h" |
7 | 7 | ||
8 | +#include "utils/memory.h" | ||
9 | + | ||
8 | HttpMessage | 10 | HttpMessage |
9 | httpWorkerGetAsset( | 11 | httpWorkerGetAsset( |
10 | HttpRequest request, | 12 | HttpRequest request, |
@@ -18,8 +20,7 @@ httpWorkerGetAsset( | @@ -18,8 +20,7 @@ httpWorkerGetAsset( | ||
18 | 20 | ||
19 | header = httpHeaderGet( | 21 | header = httpHeaderGet( |
20 | &(((HttpMessage)request)->header), | 22 | &(((HttpMessage)request)->header), |
21 | - "If-None-Match", | ||
22 | - sizeof("If-None-Match")-1); | 23 | + CSTRA("If-None-Match")); |
23 | 24 | ||
24 | if (NULL == header) { | 25 | if (NULL == header) { |
25 | match = ""; | 26 | match = ""; |
@@ -36,6 +36,8 @@ | @@ -36,6 +36,8 @@ | ||
36 | #include "http/parser.h" | 36 | #include "http/parser.h" |
37 | #include "session.h" | 37 | #include "session.h" |
38 | 38 | ||
39 | +#include "utils/memory.h" | ||
40 | + | ||
39 | HttpMessage httpWorkerGetAsset(HttpRequest, const char *, const char *, size_t); | 41 | HttpMessage httpWorkerGetAsset(HttpRequest, const char *, const char *, size_t); |
40 | void httpWorkerAddCommonHeader(HttpMessage, HttpMessage); | 42 | void httpWorkerAddCommonHeader(HttpMessage, HttpMessage); |
41 | 43 | ||
@@ -58,8 +60,7 @@ httpWorkerProcess(HttpWorker this, int fd) | @@ -58,8 +60,7 @@ httpWorkerProcess(HttpWorker this, int fd) | ||
58 | HttpMessage response = NULL; | 60 | HttpMessage response = NULL; |
59 | HttpHeader cookie = httpHeaderGet( | 61 | HttpHeader cookie = httpHeaderGet( |
60 | &(rmessage->header), | 62 | &(rmessage->header), |
61 | - "cookie", | ||
62 | - sizeof("Cookie")-1); | 63 | + CSTRA("cookie")); |
63 | 64 | ||
64 | if (NULL == this->session && NULL != cookie) { | 65 | if (NULL == this->session && NULL != cookie) { |
65 | int i; | 66 | int i; |
@@ -111,11 +112,7 @@ httpWorkerProcess(HttpWorker this, int fd) | @@ -111,11 +112,7 @@ httpWorkerProcess(HttpWorker this, int fd) | ||
111 | 112 | ||
112 | httpHeaderAdd( | 113 | httpHeaderAdd( |
113 | &(response->header), | 114 | &(response->header), |
114 | - new(HttpHeader, | ||
115 | - "Set-Cookie", | ||
116 | - sizeof("Set-Cookie")-1, | ||
117 | - buffer, | ||
118 | - nbuf)); | 115 | + new(HttpHeader, CSTRA("Set-Cookie"), buffer, nbuf)); |
119 | } | 116 | } |
120 | } | 117 | } |
121 | 118 | ||
@@ -144,16 +141,14 @@ httpWorkerProcess(HttpWorker this, int fd) | @@ -144,16 +141,14 @@ httpWorkerProcess(HttpWorker this, int fd) | ||
144 | response = httpWorkerGetAsset( | 141 | response = httpWorkerGetAsset( |
145 | request, | 142 | request, |
146 | "./assets/waldschrat.jpg", | 143 | "./assets/waldschrat.jpg", |
147 | - "image/jpeg", | ||
148 | - sizeof("image/jpeg")-1); | 144 | + CSTRA("image/jpeg")); |
149 | } | 145 | } |
150 | 146 | ||
151 | if (0 == strcmp("/jquery/", request->uri)) { | 147 | if (0 == strcmp("/jquery/", request->uri)) { |
152 | response = httpWorkerGetAsset( | 148 | response = httpWorkerGetAsset( |
153 | request, | 149 | request, |
154 | "./assets/jquery-1.7.1.min.js", | 150 | "./assets/jquery-1.7.1.min.js", |
155 | - "text/javascript", | ||
156 | - sizeof("text/javascript")-1); | 151 | + CSTRA("text/javascript")); |
157 | } | 152 | } |
158 | } | 153 | } |
159 | 154 |
@@ -51,7 +51,6 @@ serverPoll(Server this) { | @@ -51,7 +51,6 @@ serverPoll(Server this) { | ||
51 | 51 | ||
52 | if (fda < fdb) { | 52 | if (fda < fdb) { |
53 | memcpy(fda, fdb, sizeof(struct pollfd)); | 53 | memcpy(fda, fdb, sizeof(struct pollfd)); |
54 | - //memset(fdb, 0, sizeof(struct pollfd)); // this might be unneccessary | ||
55 | fdb--; | 54 | fdb--; |
56 | this->nfds--; | 55 | this->nfds--; |
57 | } | 56 | } |
@@ -56,7 +56,7 @@ socketCtor(void * _this, va_list * params) | @@ -56,7 +56,7 @@ socketCtor(void * _this, va_list * params) | ||
56 | } | 56 | } |
57 | 57 | ||
58 | //! Make the socket REUSE a TIME_WAIT socket | 58 | //! Make the socket REUSE a TIME_WAIT socket |
59 | - setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof (reUse)); | 59 | + setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse)); |
60 | 60 | ||
61 | return 0; | 61 | return 0; |
62 | } | 62 | } |
Please
register
or
login
to post a comment