GNU libmicrohttpd
0.9.71
response_from_buffer.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
40
struct
MHD_Response
*
41
MHD_response_from_buffer
(
enum
MHD_HTTP_StatusCode sc,
42
size_t
size,
43
void
*buffer,
44
enum
MHD_ResponseMemoryMode
mode)
45
{
46
struct
MHD_Response
*response;
47
void
*tmp;
48
49
mhd_assert
( (
NULL
!= buffer) ||
50
(0 == size) );
51
if
(
NULL
==
52
(response =
MHD_calloc_
(1,
53
sizeof
(
struct
MHD_Response
))))
54
return
NULL
;
55
response->
fd
= -1;
56
if
(! MHD_mutex_init_ (&response->
mutex
))
57
{
58
free (response);
59
return
NULL
;
60
}
61
if
( (
MHD_RESPMEM_MUST_COPY
== mode) &&
62
(size > 0) )
63
{
64
if
(
NULL
== (tmp = malloc (size)))
65
{
66
MHD_mutex_destroy_chk_
(&response->
mutex
);
67
free (response);
68
return
NULL
;
69
}
70
memcpy (tmp,
71
buffer,
72
size);
73
buffer = tmp;
74
}
75
if
(
MHD_RESPMEM_PERSISTENT
!= mode)
76
{
77
response->
crfc
= &free;
78
response->
crc_cls
= buffer;
79
}
80
response->
status_code
= sc;
81
response->
reference_count
= 1;
82
response->
total_size
= size;
83
response->
data
= buffer;
84
response->
data_size
= size;
85
return
response;
86
}
87
88
89
/* end of response_from_buffer.c */
MHD_ResponseMemoryMode
MHD_ResponseMemoryMode
Definition:
microhttpd.h:3049
MHD_Response::crfc
MHD_ContentReaderFreeCallback crfc
Definition:
internal.h:1606
MHD_calloc_
void * MHD_calloc_(size_t nelem, size_t elsize)
Definition:
mhd_compat.c:98
MHD_Response::status_code
enum MHD_HTTP_StatusCode status_code
Definition:
internal.h:1669
MHD_Response::reference_count
unsigned int reference_count
Definition:
internal.h:1675
MHD_Response::total_size
uint64_t total_size
Definition:
internal.h:1642
MHD_Response::data_size
size_t data_size
Definition:
internal.h:1659
internal.h
internal shared structures
MHD_mutex_destroy_chk_
#define MHD_mutex_destroy_chk_(pmutex)
Definition:
mhd_locks.h:121
NULL
#define NULL
Definition:
reason_phrase.c:30
MHD_response_from_buffer
struct MHD_Response * MHD_response_from_buffer(enum MHD_HTTP_StatusCode sc, size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
Definition:
response_from_buffer.c:41
MHD_Response::fd
int fd
Definition:
internal.h:1680
MHD_Response::mutex
MHD_mutex_ mutex
Definition:
internal.h:1637
mhd_assert
#define mhd_assert(CHK)
Definition:
mhd_assert.h:39
MHD_RESPMEM_PERSISTENT
@ MHD_RESPMEM_PERSISTENT
Definition:
microhttpd.h:3057
MHD_RESPMEM_MUST_COPY
@ MHD_RESPMEM_MUST_COPY
Definition:
microhttpd.h:3074
MHD_Response
Definition:
internal.h:1568
MHD_Response::crc_cls
void * crc_cls
Definition:
internal.h:1594
MHD_Response::data
char * data
Definition:
internal.h:1588
src
lib
response_from_buffer.c
Generated by
1.8.18