aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/response.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/response.c')
-rw-r--r--src/daemon/response.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/daemon/response.c b/src/daemon/response.c
index f52bb2df..3adb6bc9 100644
--- a/src/daemon/response.c
+++ b/src/daemon/response.c
@@ -148,6 +148,11 @@ MHD_get_response_header (struct MHD_Response *response, const char *key)
148 * header information and then be used any number of times. 148 * header information and then be used any number of times.
149 * 149 *
150 * @param size size of the data portion of the response, -1 for unknown 150 * @param size size of the data portion of the response, -1 for unknown
151 * @param block_size preferred block size for querying crc (advisory only,
152 * MHD may still call crc using smaller chunks); this
153 * is essentially the buffer size used for IO, clients
154 * should pick a value that is appropriate for IO and
155 * memory performance requirements
151 * @param crc callback to use to obtain response data 156 * @param crc callback to use to obtain response data
152 * @param crc_cls extra argument to crc 157 * @param crc_cls extra argument to crc
153 * @param crfc callback to call to free crc_cls resources 158 * @param crfc callback to call to free crc_cls resources
@@ -155,26 +160,24 @@ MHD_get_response_header (struct MHD_Response *response, const char *key)
155 */ 160 */
156struct MHD_Response * 161struct MHD_Response *
157MHD_create_response_from_callback (size_t size, 162MHD_create_response_from_callback (size_t size,
163 unsigned int block_size,
158 MHD_ContentReaderCallback crc, 164 MHD_ContentReaderCallback crc,
159 void *crc_cls, 165 void *crc_cls,
160 MHD_ContentReaderFreeCallback crfc) 166 MHD_ContentReaderFreeCallback crfc)
161{ 167{
162 struct MHD_Response *retVal; 168 struct MHD_Response *retVal;
163 169
164 if (crc == NULL) 170 if ( (crc == NULL) ||
171 (block_size == 0) )
172 return NULL;
173 retVal = malloc (sizeof (struct MHD_Response) + block_size);
174 if (retVal == NULL)
165 return NULL; 175 return NULL;
166 retVal = malloc (sizeof (struct MHD_Response));
167 memset (retVal, 0, sizeof (struct MHD_Response)); 176 memset (retVal, 0, sizeof (struct MHD_Response));
168 retVal->data = malloc (MHD_BUF_INC_SIZE); 177 retVal->data = (void*) &retVal[1];
169 if (retVal->data == NULL)
170 {
171 free (retVal);
172 return NULL;
173 }
174 retVal->data_buffer_size = MHD_BUF_INC_SIZE; 178 retVal->data_buffer_size = MHD_BUF_INC_SIZE;
175 if (pthread_mutex_init (&retVal->mutex, NULL) != 0) 179 if (pthread_mutex_init (&retVal->mutex, NULL) != 0)
176 { 180 {
177 free (retVal->data);
178 free (retVal); 181 free (retVal);
179 return NULL; 182 return NULL;
180 } 183 }
@@ -262,8 +265,6 @@ MHD_destroy_response (struct MHD_Response *response)
262 free (pos->value); 265 free (pos->value);
263 free (pos); 266 free (pos);
264 } 267 }
265 if (response->crc != NULL)
266 free (response->data);
267 free (response); 268 free (response);
268} 269}
269 270