diff options
Diffstat (limited to 'src/microhttpd/response.c')
-rw-r--r-- | src/microhttpd/response.c | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index d352a804..b29f48f3 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -145,6 +145,51 @@ | |||
145 | } while (0) | 145 | } while (0) |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Add preallocated strings a header or footer line to the response without | ||
149 | * checking. | ||
150 | * | ||
151 | * Header/footer strings are not checked and assumed to be correct. | ||
152 | * | ||
153 | * The string must not be statically allocated! | ||
154 | * The strings must be malloc()'ed and zero terminated. The strings will | ||
155 | * be free()'ed when the response is destroyed. | ||
156 | * | ||
157 | * @param response response to add a header to | ||
158 | * @param kind header or footer | ||
159 | * @param header the header string to add, must be malloc()'ed and | ||
160 | * zero-terminated | ||
161 | * @param header_len the length of the @a header | ||
162 | * @param content the value string to add, must be malloc()'ed and | ||
163 | * zero-terminated | ||
164 | * @param content_len the length of the @a content | ||
165 | */ | ||
166 | bool | ||
167 | MHD_add_response_entry_no_alloc_ (struct MHD_Response *response, | ||
168 | enum MHD_ValueKind kind, | ||
169 | char *header, | ||
170 | size_t header_len, | ||
171 | char *content, | ||
172 | size_t content_len) | ||
173 | { | ||
174 | struct MHD_HTTP_Res_Header *hdr; | ||
175 | |||
176 | mhd_assert (0 != header_len); | ||
177 | mhd_assert (0 != content_len); | ||
178 | if (NULL == (hdr = MHD_calloc_ (1, sizeof (struct MHD_HTTP_Res_Header)))) | ||
179 | return false; | ||
180 | |||
181 | hdr->header = header; | ||
182 | hdr->header_size = header_len; | ||
183 | hdr->value = content; | ||
184 | hdr->value_size = content_len; | ||
185 | hdr->kind = kind; | ||
186 | _MHD_insert_header_last (response, hdr); | ||
187 | |||
188 | return true; /* Success exit point */ | ||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
148 | * Add a header or footer line to the response without checking. | 193 | * Add a header or footer line to the response without checking. |
149 | * | 194 | * |
150 | * It is assumed that parameters are correct. | 195 | * It is assumed that parameters are correct. |
@@ -166,34 +211,32 @@ MHD_add_response_entry_no_check_ (struct MHD_Response *response, | |||
166 | const char *content, | 211 | const char *content, |
167 | size_t content_len) | 212 | size_t content_len) |
168 | { | 213 | { |
169 | struct MHD_HTTP_Res_Header *hdr; | 214 | char *header_malloced; |
215 | char *value_malloced; | ||
170 | 216 | ||
171 | mhd_assert (0 != header_len); | 217 | mhd_assert (0 != header_len); |
172 | mhd_assert (0 != content_len); | 218 | mhd_assert (0 != content_len); |
173 | if (NULL == (hdr = MHD_calloc_ (1, sizeof (struct MHD_HTTP_Res_Header)))) | 219 | header_malloced = malloc (header_len + 1); |
220 | if (NULL == header_malloced) | ||
174 | return false; | 221 | return false; |
175 | hdr->header = malloc (header_len + 1); | ||
176 | if (NULL != hdr->header) | ||
177 | { | ||
178 | memcpy (hdr->header, header, header_len); | ||
179 | hdr->header[header_len] = 0; | ||
180 | hdr->header_size = header_len; | ||
181 | 222 | ||
182 | hdr->value = malloc (content_len + 1); | 223 | memcpy (header_malloced, header, header_len); |
183 | if (NULL != hdr->value) | 224 | header_malloced[header_len] = 0; |
184 | { | ||
185 | memcpy (hdr->value, content, content_len); | ||
186 | hdr->value[content_len] = 0; | ||
187 | hdr->value_size = content_len; | ||
188 | 225 | ||
189 | hdr->kind = kind; | 226 | value_malloced = malloc (content_len + 1); |
190 | _MHD_insert_header_last (response, hdr); | 227 | if (NULL != value_malloced) |
228 | { | ||
229 | memcpy (value_malloced, content, content_len); | ||
230 | value_malloced[content_len] = 0; | ||
191 | 231 | ||
232 | if (MHD_add_response_entry_no_alloc_ (response, kind, | ||
233 | header_malloced, header_len, | ||
234 | value_malloced, content_len)) | ||
192 | return true; /* Success exit point */ | 235 | return true; /* Success exit point */ |
193 | } | 236 | |
194 | free (hdr->header); | 237 | free (value_malloced); |
195 | } | 238 | } |
196 | free (hdr); | 239 | free (header_malloced); |
197 | 240 | ||
198 | return false; /* Failure exit point */ | 241 | return false; /* Failure exit point */ |
199 | } | 242 | } |