diff options
Diffstat (limited to 'src/daemon/internal.h')
-rw-r--r-- | src/daemon/internal.h | 171 |
1 files changed, 169 insertions, 2 deletions
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 2f7fd194..61653d8e 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h | |||
@@ -35,7 +35,8 @@ | |||
35 | #include <netdb.h> | 35 | #include <netdb.h> |
36 | #include <string.h> | 36 | #include <string.h> |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #include <stdarg> | 38 | #include <stdarg.h> |
39 | #include <errno.h> | ||
39 | #include <fcntl.h> | 40 | #include <fcntl.h> |
40 | #include <pthread.h> | 41 | #include <pthread.h> |
41 | #include <netinet/in.h> | 42 | #include <netinet/in.h> |
@@ -45,7 +46,7 @@ | |||
45 | 46 | ||
46 | #define MHD_MAX_BUF_SIZE 2048 | 47 | #define MHD_MAX_BUF_SIZE 2048 |
47 | 48 | ||
48 | 49 | #define MAX(a,b) ((a)<(b)) ? (b) : (a) | |
49 | 50 | ||
50 | /** | 51 | /** |
51 | * Header or cookie in HTTP request or response. | 52 | * Header or cookie in HTTP request or response. |
@@ -72,6 +73,172 @@ struct MHD_Access_Handler { | |||
72 | }; | 73 | }; |
73 | 74 | ||
74 | 75 | ||
76 | /** | ||
77 | * Representation of a response. | ||
78 | */ | ||
79 | struct MHD_Response { | ||
80 | |||
81 | /** | ||
82 | * Headers to send for the response. Initially | ||
83 | * the linked list is created in inverse order; | ||
84 | * the order should be inverted before sending! | ||
85 | */ | ||
86 | struct MHD_HTTP_Header * first_header; | ||
87 | |||
88 | /** | ||
89 | * Buffer pointing to data that we are supposed | ||
90 | * to send as a response. | ||
91 | */ | ||
92 | char * data; | ||
93 | |||
94 | /** | ||
95 | * Closure to give to the content reader | ||
96 | * free callback. | ||
97 | */ | ||
98 | void * crc_cls; | ||
99 | |||
100 | /** | ||
101 | * How do we get more data? NULL if we are | ||
102 | * given all of the data up front. | ||
103 | */ | ||
104 | MHD_ContentReaderCallback crc; | ||
105 | |||
106 | /** | ||
107 | * NULL if data must not be freed, otherwise | ||
108 | * either user-specified callback or "&free". | ||
109 | */ | ||
110 | MHD_ContentReaderFreeCallback crfc; | ||
111 | |||
112 | /** | ||
113 | * Mutex to synchronize access to data/size and | ||
114 | * reference counts. | ||
115 | */ | ||
116 | pthread_mutex_t mutex; | ||
117 | |||
118 | /** | ||
119 | * Reference count for this response. Free | ||
120 | * once the counter hits zero. | ||
121 | */ | ||
122 | unsigned int reference_count; | ||
123 | |||
124 | /** | ||
125 | * Set to -1 if size is not known. | ||
126 | */ | ||
127 | size_t total_size; | ||
128 | |||
129 | /** | ||
130 | * Size of data. | ||
131 | */ | ||
132 | size_t data_size; | ||
133 | |||
134 | /** | ||
135 | * At what offset in the stream is the | ||
136 | * beginning of data located? | ||
137 | */ | ||
138 | size_t data_start; | ||
139 | |||
140 | }; | ||
141 | |||
142 | |||
143 | |||
144 | struct MHD_Session { | ||
145 | struct MHD_Session * next; | ||
146 | |||
147 | struct MHD_Daemon * daemon; | ||
148 | |||
149 | struct MHD_HTTP_Header * headers_received; | ||
150 | |||
151 | struct MHD_Response * response; | ||
152 | |||
153 | char * method; | ||
154 | |||
155 | char * url; | ||
156 | |||
157 | /** | ||
158 | * Buffer for reading requests. | ||
159 | */ | ||
160 | char * read_buffer; | ||
161 | |||
162 | /** | ||
163 | * Buffer for writing response. | ||
164 | */ | ||
165 | char * write_buffer; | ||
166 | |||
167 | /** | ||
168 | * Foreign address (of length addr_len). | ||
169 | */ | ||
170 | struct sockaddr_in * addr; | ||
171 | |||
172 | /** | ||
173 | * Thread for this session (if we are using | ||
174 | * one thread per connection). | ||
175 | */ | ||
176 | pthread_t pid; | ||
177 | |||
178 | size_t read_buffer_size; | ||
179 | |||
180 | size_t readLoc; | ||
181 | |||
182 | size_t write_buffer_size; | ||
183 | |||
184 | size_t writeLoc; | ||
185 | |||
186 | /** | ||
187 | * Current write position in the actual response | ||
188 | * (excluding headers, content only; should be 0 | ||
189 | * while sending headers). | ||
190 | */ | ||
191 | size_t messagePos; | ||
192 | |||
193 | /** | ||
194 | * Remaining (!) number of bytes in the upload. | ||
195 | * Set to -1 for unknown (connection will close | ||
196 | * to indicate end of upload). | ||
197 | */ | ||
198 | size_t uploadSize; | ||
199 | |||
200 | /** | ||
201 | * Length of the foreign address. | ||
202 | */ | ||
203 | socklen_t addr_len; | ||
204 | |||
205 | /** | ||
206 | * Socket for this connection. Set to -1 if | ||
207 | * this connection has died (daemon should clean | ||
208 | * up in that case). | ||
209 | */ | ||
210 | int socket_fd; | ||
211 | |||
212 | /** | ||
213 | * Have we finished receiving all of the headers yet? | ||
214 | * Set to 1 once we are done processing all of the | ||
215 | * headers. Note that due to pipelining, it is | ||
216 | * possible that the NEXT request is already | ||
217 | * (partially) waiting in the read buffer. | ||
218 | */ | ||
219 | int headersReceived; | ||
220 | |||
221 | /** | ||
222 | * Have we finished receiving the data from a | ||
223 | * potential file-upload? | ||
224 | */ | ||
225 | int bodyReceived; | ||
226 | |||
227 | /** | ||
228 | * Have we finished sending all of the headers yet? | ||
229 | */ | ||
230 | int headersSent; | ||
231 | |||
232 | /** | ||
233 | * HTTP response code. Only valid if response object | ||
234 | * is already set. | ||
235 | */ | ||
236 | unsigned int responseCode; | ||
237 | |||
238 | }; | ||
239 | |||
240 | |||
241 | |||
75 | struct MHD_Daemon { | 242 | struct MHD_Daemon { |
76 | 243 | ||
77 | struct MHD_Access_Handler * handlers; | 244 | struct MHD_Access_Handler * handlers; |