Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_request.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Helpers for interfaces afw_request*
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_REQUEST_H__
10 #define __AFW_REQUEST_H__
11 
12 #include "afw_interface.h"
13 
29 
34 #define AFW_REQUEST_Q_PN_CONTENT_TYPE AFW_Q_CONTENT_TYPE
35 
40 #define AFW_REQUEST_s_PN_CONTENT_TYPE afw_s_CONTENT_TYPE
41 
46 #define AFW_REQUEST_Q_PN_CONTENT_LENGTH AFW_Q_CONTENT_LENGTH
47 
52 #define AFW_REQUEST_s_PN_CONTENT_LENGTH afw_s_CONTENT_LENGTH
53 
57 #define AFW_REQUEST_Q_PN_HTTP_ACCEPT AFW_Q_HTTP_ACCEPT
58 
62 #define AFW_REQUEST_s_PN_HTTP_ACCEPT afw_s_HTTP_ACCEPT
63 
69 #define AFW_REQUEST_Q_PN_PATH_INFO AFW_Q_PATH_INFO
70 
76 #define AFW_REQUEST_s_PN_PATH_INFO afw_s_PATH_INFO
77 
83 #define AFW_REQUEST_Q_PN_QUERY_STRING AFW_Q_QUERY_STRING
84 
90 #define AFW_REQUEST_s_PN_QUERY_STRING afw_s_QUERY_STRING
91 
98 #define AFW_REQUEST_Q_PN_REQUEST_METHOD AFW_Q_REQUEST_METHOD
99 
106 #define AFW_REQUEST_s_PN_REQUEST_METHOD afw_s_REQUEST_METHOD
107 
113 #define AFW_REQUEST_Q_PN_REQUEST_URI AFW_Q_REQUEST_URI
114 
120 #define AFW_REQUEST_s_PN_REQUEST_URI afw_s_REQUEST_URI
121 
123 #define AFW_REQUEST_Q_METHOD_GET AFW_Q_GET
124 
126 #define AFW_REQUEST_s_METHOD_GET afw_s_GET
127 
129 #define AFW_REQUEST_Q_METHOD_POST AFW_Q_POST
130 
132 #define AFW_REQUEST_s_METHOD_POST afw_s_POST
133 
135 #define AFW_REQUEST_Q_METHOD_PUT AFW_Q_PUT
136 
138 #define AFW_REQUEST_s_METHOD_PUT afw_s_PUT
139 
141 #define AFW_REQUEST_Q_METHOD_PATCH AFW_Q_PATCH
142 
144 #define AFW_REQUEST_s_METHOD_PATCH afw_s_PATCH
145 
147 #define AFW_REQUEST_Q_METHOD_DELETE AFW_Q_DELETE
148 
150 #define AFW_REQUEST_s_METHOD_DELETE afw_s_DELETE
151 
152 
154 typedef enum afw_request_state_e {
155  afw_request_state_initial,
156  afw_request_state_content_read,
157  afw_request_state_status_set,
158  afw_request_state_header_written,
159  afw_request_state_response_written,
160  afw_request_state_response_finished
162 
170 AFW_DECLARE(const afw_utf8_t *)
172  const afw_request_t * instance,
173  const afw_pool_t *p,
174  afw_xctx_t *xctx);
175 
176 
177 
187 AFW_DECLARE(const afw_value_t *)
189  const afw_request_t * instance,
190  const afw_pool_t *p,
191  afw_xctx_t *xctx);
192 
193 
194 
195 /*
196  * @brief Get response content type.
197  * @param request instance.
198  * @param response_content_type return address.
199  * @param type return address.
200  * @param type_parameter return address.
201  * @param xctx of caller.
202  */
203 AFW_DEFINE(void)
204 afw_request_get_response_content_type(
205  const afw_request_t *instance,
206  const afw_content_type_t **response_content_type,
207  const afw_utf8_t **type,
208  const afw_utf8_t **type_parameter,
209  afw_xctx_t *xctx);
210 
211 
212 /*
213  * @brief Get response content type and set header first time called.
214  * @param request instance
215  * @param xctx of caller.
216  * @return content type instance
217  */
219 afw_request_prepare_response_content_type(
220  const afw_request_t * instance, afw_xctx_t *xctx);
221 
222 
223 /*
224  * @brief Create writer for response body.
225  * @param request instance
226  * @param xctx of caller.
227  * @return afw_writer instance
228  */
229 AFW_DEFINE(const afw_stream_t *)
230 afw_request_response_body_raw_writer_create(
231  const afw_request_t *request,
232  afw_xctx_t *xctx);
233 
234 
235 
246 AFW_DECLARE(void)
248  const afw_request_t * instance,
249  const afw_value_t *value,
250  const afw_object_options_t *options,
251  afw_xctx_t *xctx);
252 
253 
254 
264 AFW_DECLARE(void)
266  const afw_request_t * instance,
267  const afw_utf8_t *code,
268  const afw_error_t *error,
269  afw_xctx_t *xctx);
270 
271 
272 
279 AFW_DECLARE(void)
281  const afw_request_t * instance,
282  const afw_object_t * response,
283  afw_xctx_t *xctx);
284 
285 
286 AFW_END_DECLARES
287 
290 #endif /* __AFW_REQUEST_H__ */
AFW_DEFINE(const afw_object_t *)
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
enum afw_request_state_e afw_request_state_t
const afw_value_t * afw_request_body_to_value(const afw_request_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
Read a request body to value in a specifed pool.
Definition: afw_request.c:149
afw_request_state_e
Definition: afw_request.h:154
void afw_request_write_value_to_response_body(const afw_request_t *instance, const afw_value_t *value, const afw_object_options_t *options, afw_xctx_t *xctx)
Write value to response body.
Definition: afw_request.c:187
const afw_utf8_t * afw_request_body_to_utf8(const afw_request_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
Read a request body into a utf-8 string in a specifed pool.
Definition: afw_request.c:120
void afw_request_write_error_to_response_body(const afw_request_t *instance, const afw_utf8_t *code, const afw_error_t *error, afw_xctx_t *xctx)
Write xctx error to response body.
Definition: afw_request.c:216
void afw_request_write_success_response(const afw_request_t *instance, const afw_object_t *response, afw_xctx_t *xctx)
Write simple success to response body.
Definition: afw_request.c:248
Interface afw_content_type public struct.
Adaptive Framework Error.
Definition: afw_error.h:65
Struct for object processing options.
Interface afw_object public struct.
Interface afw_pool public struct.
Interface afw_request public struct.
Interface afw_stream public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.