Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_server_fcgi_properties_object.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Implementation of afw_object interface for FCGI properties
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw.h"
17 #include "afw_object_impl.h"
18 
19 
20 /* Declares and rti/inf defines for interface afw_object */
21 #define AFW_IMPLEMENTATION_ID "fcgi"
23 
24 typedef struct impl_self_s {
25  afw_object_t pub;
27  const afw_object_t *properties;
28 } impl_self_t;
29 
30 
31 const afw_object_t *
34  afw_xctx_t *xctx)
35 {
36  impl_self_t *self;
37 
38  static const afw_utf8_t impl_path =
39  AFW_UTF8_LITERAL("/afw/_AdaptiveRequestProperties_/current");
40 
41  /* Allocate memory for self and initialize. */
42  self = afw_xctx_calloc_type(impl_self_t, request->pub.xctx);
43  self->pub.inf = &impl_afw_object_inf;
44  self->pub.meta.id = &afw_s_current;
45  self->pub.meta.object_type_uri = &afw_s__AdaptiveRequestProperties_;
46  self->pub.meta.object_uri = &impl_path;
47  self->pub.p = xctx->p;
48  self->request = request;
49 
50  /* Create request properties object. */
51  self->properties = afw_object_create(xctx->p, xctx);
52 
53  return (const afw_object_t *)self;
54 }
55 
56 
57 
58 /*
59  * Implementation of method release of interface afw_object.
60  */
61 void
63  const afw_object_t * instance,
64  afw_xctx_t *xctx)
65 {
66  /* Always releases with xctx. */
67 }
68 
69 
70 
71 /*
72  * Implementation of method add_reference of interface afw_object.
73  */
74 void
76  const afw_object_t * instance,
77  afw_xctx_t *xctx)
78 {
79  /* Always releases with xctx. */
80 }
81 
82 /*
83  * Implementation of method get_count for interface afw_object.
84  */
87  const afw_object_t * instance,
88  afw_xctx_t * xctx)
89 {
90 // <afwdev {prefixed_interface_name}>_self_t *self =
91 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
92 
94  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
95 
96 }
97 
98 /*
99  * Implementation of method get_meta for interface afw_object.
100  */
101 const afw_value_t *
103  const afw_object_t *instance,
104  const afw_pool_t *p,
105  afw_xctx_t *xctx)
106 {
108  instance, p, xctx);
109 }
110 
111 
112 
113 /*
114  * Implementation of method get_property of interface afw_object.
115  */
116 const afw_value_t *
118  const afw_object_t * instance,
119  const afw_utf8_t * property_name,
120  afw_xctx_t *xctx)
121 {
122  impl_self_t *self = (impl_self_t *)instance;
123  const void *s;
124  const afw_value_t *value;
125  const afw_utf8_z_t *property_name_z;
126 
127  /* Look for property in memory first. */
128  value = afw_object_get_property(self->properties, property_name,
129  xctx);
130  if (value) return value;
131 
132  /* If not in memory, try FCGX_GetParam(). */
133  value = NULL;
134  property_name_z = afw_utf8_z_create(property_name->s, property_name->len,
135  xctx->p, xctx);
136  s = FCGX_GetParam(property_name_z,
137  self->request->fcgx_request->envp);
138  if (s) {
139  value = afw_value_make_string_copy(s, AFW_UTF8_Z_LEN, xctx->p, xctx);
140  }
141 
142  return value;
143 }
144 
145 
146 
147 /*
148  * Implementation of method get_property_meta for interface afw_object.
149  */
150 const afw_value_t *
152  const afw_object_t *instance,
153  const afw_utf8_t *property_name,
154  const afw_pool_t *p,
155  afw_xctx_t *xctx)
156 {
158  instance, property_name, p, xctx);
159 }
160 
161 
162 
164  const afw_iterator_t *iterator;
165  char **envp;
167 
168 
169 
170 /*
171  * Implementation of method get_next_property of interface afw_object.
172  */
173 const afw_value_t *
175  const afw_object_t * instance,
176  const afw_iterator_t * * iterator,
177  const afw_utf8_t * * property_name,
178  afw_xctx_t *xctx)
179 {
180  impl_self_t *self = (impl_self_t *)instance;
182  const afw_value_t *value;
183  const afw_utf8_octet_t *s;
184  const afw_utf8_octet_t *c;
185  const afw_utf8_t *string;
186 
187  if (!*iterator) {
188  *iterator = (afw_iterator_t *)afw_xctx_calloc_type(
190 
191  }
192  it = (impl_request_properties_iterator_t *)*iterator;
193 
194  if (!it->envp) {
195  value = afw_object_get_next_property(self->properties,
196  &it->iterator, property_name, xctx);
197  if (value) {
198  return value;
199  }
200  it->envp = self->request->fcgx_request->envp;
201  }
202 
203  if (!it->envp || !*it->envp) {
204  *iterator = NULL;
205  return NULL;
206  }
207 
208  for (s = c = *it->envp; *c && *c != '='; c++);
209  if (property_name) {
210  *property_name = afw_utf8_create(s, c - s, xctx->p, xctx);
211  }
212 
213  if (!*c) {
214  string = &afw_s_a_empty_string;
215  }
216  else {
217  string = afw_utf8_create(c + 1, AFW_UTF8_Z_LEN, xctx->p, xctx);
218  }
219 
220  value = afw_value_create_string(string, xctx->p, xctx);
221  (it->envp)++;
222  return value;
223 }
224 
225 
226 
227 /*
228  * Implementation of method get_next_property_meta for interface afw_object.
229  */
230 const afw_value_t *
232  const afw_object_t *instance,
233  const afw_iterator_t **iterator,
234  const afw_utf8_t **property_name,
235  const afw_pool_t *p,
236  afw_xctx_t *xctx)
237 {
239  instance, iterator, property_name, p, xctx);
240 }
241 
242 
243 
244 /*
245  * Implementation of method has_property of interface afw_object.
246  */
249  const afw_object_t * instance,
250  const afw_utf8_t * property_name,
251  afw_xctx_t *xctx)
252 {
253  const afw_value_t *value;
254 
255  /* Call impl_get_own_property and throw away value. */
257  instance, property_name, xctx);
258 
259  return (value != NULL);
260 }
261 
262 
263 
264 /*
265  * Implementation of method get_setter of interface afw_object.
266  */
267 const afw_object_setter_t *
269  const afw_object_t * instance,
270  afw_xctx_t *xctx)
271 {
272  /* Assign instance pointer to self. */
273  impl_self_t * self = (impl_self_t *)instance;
274 
275  return afw_object_get_setter(self->properties, xctx);
276 }
Adaptive Framework Core API.
Helpers for object implementation development.
Interface afw_interface implementation declares.
Internal header file for AFW FCGI Server.
const afw_object_t * afw_server_fcgi_internal_create_properties_object(afw_server_fcgi_internal_request_t *request, afw_xctx_t *xctx)
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
Definition: afw_common.h:266
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
Definition: afw_common.h:582
struct afw_iterator_s afw_iterator_t
_Bool afw_boolean_t
Definition: afw_common.h:373
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
const afw_object_setter_t * impl_afw_object_get_setter(const afw_object_t *instance, afw_xctx_t *xctx)
void impl_afw_object_add_reference(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_next_property(const afw_object_t *instance, const afw_iterator_t **iterator, const afw_utf8_t **property_name, afw_xctx_t *xctx)
void impl_afw_object_release(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_meta(const afw_object_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_next_property_meta(const afw_object_t *instance, const afw_iterator_t **iterator, const afw_utf8_t **property_name, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
afw_boolean_t impl_afw_object_has_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_property_meta(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * afw_object_impl_get_property_meta(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
A general impl of method get_property_meta for interface afw_object that can be accessed externally.
const afw_value_t * afw_object_impl_get_meta(const afw_object_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
A general impl of method get_meta for interface afw_object that can be accessed externally.
const afw_value_t * afw_object_impl_get_next_property_meta(const afw_object_t *instance, const afw_iterator_t **iterator, const afw_utf8_t **property_name, const afw_pool_t *p, afw_xctx_t *xctx)
A general impl of method get_next_property_meta for interface afw_object that can be accessed externa...
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_get_setter(instance, xctx)
Call method get_setter of interface afw_object.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
Definition: afw_object.h:948
afw_utf8_z_create(const afw_utf8_octet_t *s, afw_size_t len, const afw_pool_t *p, afw_xctx_t *xctx)
Create a NFC Normalized zero terminated UTF-8 string in specified pool.
Definition: afw_utf8.c:366
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
Definition: afw_utf8.h:239
afw_value_make_string_copy(const afw_utf8_octet_t *s, afw_size_t len, const afw_pool_t *p, afw_xctx_t *xctx)
Definition: afw_value.c:496
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Definition: afw_xctx.h:199
Interface afw_object public struct.
Interface afw_object_setter public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.