GNU libmicrohttpd  0.9.72
response_from_callback.c
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
25 #include "internal.h"
26 
27 
45 struct MHD_Response *
46 MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
47  uint64_t size,
48  size_t block_size,
50  void *crc_cls,
52 {
53  struct MHD_Response *response;
54 
55  mhd_assert (NULL != crc);
56  mhd_assert (0 != block_size);
57  if (NULL ==
58  (response = MHD_calloc_ (1,
59  sizeof (struct MHD_Response)
60  + block_size)))
61  return NULL;
62  response->fd = -1;
63  response->status_code = sc;
64  response->data = (void *) &response[1];
65  response->data_buffer_size = block_size;
66  if (! MHD_mutex_init_ (&response->mutex))
67  {
68  free (response);
69  return NULL;
70  }
71  response->crc = crc;
72  response->crfc = crfc;
73  response->crc_cls = crc_cls;
74  response->reference_count = 1;
75  response->total_size = size;
76  return response;
77 }
78 
79 
80 /* end of response_from_callback.c */
struct MHD_Response * MHD_response_from_callback(enum MHD_HTTP_StatusCode sc, uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
void(* MHD_ContentReaderFreeCallback)(void *cls)
Definition: microhttpd.h:2355
#define mhd_assert(CHK)
Definition: mhd_assert.h:39
void * MHD_calloc_(size_t nelem, size_t elsize)
Definition: mhd_compat.c:98
#define NULL
Definition: reason_phrase.c:30
internal shared structures
#define MHD_mutex_init_(ignore)
Definition: mhd_locks.h:189
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
Definition: microhttpd.h:2339
MHD_ContentReaderFreeCallback crfc
Definition: internal.h:1606
void * crc_cls
Definition: internal.h:1594
size_t data_buffer_size
Definition: internal.h:1664
enum MHD_HTTP_StatusCode status_code
Definition: internal.h:1669
MHD_ContentReaderCallback crc
Definition: internal.h:1600
unsigned int reference_count
Definition: internal.h:1675
char * data
Definition: internal.h:1588
MHD_mutex_ mutex
Definition: internal.h:1637
uint64_t total_size
Definition: internal.h:1642