GNU libmicrohttpd  0.9.72
request_info.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 
43 enum MHD_Bool
45  enum MHD_RequestInformationType info_type,
46  union MHD_RequestInformation *return_value,
47  size_t return_value_size)
48 {
49 #define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \
50  return MHD_NO
51 
52  switch (info_type)
53  {
54  case MHD_REQUEST_INFORMATION_CONNECTION:
55  CHECK_SIZE (struct MHD_Connection *);
56  return_value->connection = request->connection;
57  return MHD_YES;
58  case MHD_REQUEST_INFORMATION_CLIENT_CONTEXT:
59  CHECK_SIZE (void **);
60  return_value->request_context = &request->client_context;
61  return MHD_YES;
62  case MHD_REQUEST_INFORMATION_HTTP_VERSION:
63  CHECK_SIZE (const char *);
64  return_value->http_version = request->version_s;
65  return MHD_YES;
66  case MHD_REQUEST_INFORMATION_HTTP_METHOD:
67  CHECK_SIZE (const char *);
68  return_value->http_method = request->method_s;
69  return MHD_YES;
70  case MHD_REQUEST_INFORMATION_HEADER_SIZE:
71  CHECK_SIZE (size_t);
72  if ( (MHD_REQUEST_HEADERS_RECEIVED > request->state) ||
73  (MHD_REQUEST_CLOSED == request->state) )
74  return MHD_NO; /* invalid, too early! */
75  return_value->header_size = request->header_size;
76  return MHD_YES;
77 
78  default:
79  return MHD_NO;
80  }
81 
82 #undef CHECK_SIZE
83 }
84 
85 
86 /* end of request_info.c */
enum MHD_Bool MHD_request_get_information_sz(struct MHD_Request *request, enum MHD_RequestInformationType info_type, union MHD_RequestInformation *return_value, size_t return_value_size)
Definition: request_info.c:44
@ MHD_REQUEST_CLOSED
Definition: internal.h:321
@ MHD_REQUEST_HEADERS_RECEIVED
Definition: internal.h:237
internal shared structures
@ MHD_YES
Definition: microhttpd.h:151
@ MHD_NO
Definition: microhttpd.h:146
#define CHECK_SIZE(type)
void * client_context
Definition: internal.h:401
struct MHD_Connection * connection
Definition: internal.h:377
size_t header_size
Definition: internal.h:502
char * version_s
Definition: internal.h:419
enum MHD_REQUEST_STATE state
Definition: internal.h:549
char * method_s
Definition: internal.h:407