GNU libmicrohttpd  0.9.72
request.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 */
27 #include "internal.h"
28 
29 
41 unsigned int
43  enum MHD_ValueKind kind,
44  MHD_KeyValueIterator iterator,
45  void *iterator_cls)
46 {
47  int ret;
48  struct MHD_HTTP_Header *pos;
49 
50  ret = 0;
51  for (pos = request->headers_received;
52  NULL != pos;
53  pos = pos->next)
54  {
55  if (0 != (pos->kind & kind))
56  {
57  ret++;
58  if ( (NULL != iterator) &&
59  (MHD_YES != iterator (iterator_cls,
60  pos->kind,
61  pos->header,
62  pos->value)) )
63  return ret;
64  }
65  }
66  return ret;
67 }
68 
69 
95 enum MHD_Bool
96 MHD_request_set_value (struct MHD_Request *request,
97  enum MHD_ValueKind kind,
98  const char *key,
99  const char *value)
100 {
101  struct MHD_HTTP_Header *pos;
102 
103  pos = MHD_pool_allocate (request->connection->pool,
104  sizeof (struct MHD_HTTP_Header),
105  MHD_YES);
106  if (NULL == pos)
107  return MHD_NO;
108  pos->header = (char *) key;
109  pos->value = (char *) value;
110  pos->kind = kind;
111  pos->next = NULL;
112  /* append 'pos' to the linked list of headers */
113  if (NULL == request->headers_received_tail)
114  {
115  request->headers_received = pos;
116  request->headers_received_tail = pos;
117  }
118  else
119  {
120  request->headers_received_tail->next = pos;
121  request->headers_received_tail = pos;
122  }
123  return MHD_YES;
124 }
125 
126 
137 const char *
139  enum MHD_ValueKind kind,
140  const char *key)
141 {
142  struct MHD_HTTP_Header *pos;
143 
144  for (pos = request->headers_received;
145  NULL != pos;
146  pos = pos->next)
147  {
148  if ((0 != (pos->kind & kind)) &&
149  ( (key == pos->header) ||
150  ( (NULL != pos->header) &&
151  (NULL != key) &&
153  pos->header)))))
154  return pos->value;
155  }
156  return NULL;
157 }
158 
159 
160 /* end of request.c */
enum MHD_Result(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
Definition: microhttpd.h:2261
enum MHD_Bool MHD_request_set_value(struct MHD_Request *request, enum MHD_ValueKind kind, const char *key, const char *value)
Definition: request.c:96
const char * MHD_request_lookup_value(struct MHD_Request *request, enum MHD_ValueKind kind, const char *key)
Definition: request.c:138
unsigned int MHD_request_get_values(struct MHD_Request *request, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
Definition: request.c:42
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
Definition: memorypool.c:203
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Definition: mhd_str.c:346
#define NULL
Definition: reason_phrase.c:30
internal shared structures
@ MHD_YES
Definition: microhttpd.h:151
@ MHD_NO
Definition: microhttpd.h:146
MHD_ValueKind
Definition: microhttpd.h:1781
struct MemoryPool * pool
Definition: internal.h:685
char * header
Definition: internal.h:347
enum MHD_ValueKind kind
Definition: internal.h:358
struct MHD_HTTP_Header * next
Definition: internal.h:342
char * value
Definition: internal.h:352
struct MHD_HTTP_Header * headers_received
Definition: internal.h:388
struct MHD_HTTP_Header * headers_received_tail
Definition: internal.h:393
struct MHD_Connection * connection
Definition: internal.h:377