Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_authorization_impl.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Authorization Implementation Support
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 static void
18 impl_set_trace_flag_fields(
20  afw_xctx_t *xctx)
21 {
22  const afw_pool_t *p = self->p;
23  const afw_pool_t *env_p = xctx->env->p;
24  const afw_utf8_t *flag_id;
25  const afw_utf8_t *brief;
26  const afw_utf8_t *description;
27  const afw_utf8_t *included_by_flag_id;
28  const afw_flag_t *flag;
29 
30  /* authorization_handler_id_trace_flag_id */
31  self->trace_flag_id =
32  afw_utf8_printf(p, xctx,
33  "trace:authorizationHandlerId:%" AFW_UTF8_FMT,
34  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
35 
36  /* authorization_handler_id_detail_flag_id */
37  self->detail_flag_id =
38  afw_utf8_printf(p, xctx,
39  "trace:authorizationHandlerId:%" AFW_UTF8_FMT ":detail",
40  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
41 
42  /* authorization_handler_id_detail_flag_index */
44  self ->detail_flag_id, xctx);
45  if (!flag) {
46  flag_id = afw_utf8_clone(
47  self ->detail_flag_id,
48  env_p, xctx);
49 
50  brief = afw_utf8_printf(env_p, xctx,
51  "Detail trace of authorizationHandlerId %" AFW_UTF8_FMT,
52  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
53 
54  description = afw_utf8_printf(env_p, xctx,
55  "This produces a basic plus detail trace "
56  "of authorizationHandlerId %" AFW_UTF8_FMT ".",
57  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
58 
59  included_by_flag_id = afw_utf8_printf(env_p, xctx,
60  "trace:authorizationHandlerType:%" AFW_UTF8_FMT ":detail",
61  AFW_UTF8_FMT_ARG(self->authorization_handler_type_id));
62 
63  afw_environment_register_flag(flag_id, brief, description,
64  included_by_flag_id, xctx);
65 
67  self->detail_flag_id, xctx);
68  }
69  self->detail_flag_index = flag->flag_index;
70 
71 
72  /* authorization_handler_id_trace_flag_index */
74  self->trace_flag_id, xctx);
75  if (!flag) {
76  flag_id = afw_utf8_clone(
77  self->trace_flag_id,
78  env_p, xctx);
79 
80  brief = afw_utf8_printf(env_p, xctx,
81  "Trace authorizationHandlerId %" AFW_UTF8_FMT,
82  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
83 
84  description = afw_utf8_printf(env_p, xctx,
85  "This produces a basic trace of authorizationHandlerId %" AFW_UTF8_FMT ".",
86  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
87 
88  included_by_flag_id = afw_utf8_printf(env_p, xctx,
89  "trace:authorizationHandlerType:%" AFW_UTF8_FMT,
90  AFW_UTF8_FMT_ARG(self->authorization_handler_type_id));
91 
92  afw_environment_register_flag(flag_id, brief, description,
93  included_by_flag_id, xctx);
94 
95  afw_flag_add_included_by(self->trace_flag_id,
96  self->detail_flag_id, xctx);
97 
99  self->trace_flag_id, xctx);
100  }
101  self->trace_flag_index = flag->flag_index;
102 }
103 
104 
105 
109  afw_size_t instance_size,
110  const afw_object_t *properties,
111  const afw_pool_t *p,
112  afw_xctx_t *xctx)
113 {
115  const afw_utf8_t *s;
116  afw_boolean_t found;
117 
119  (instance_size != 0)
120  ? instance_size
121  : sizeof(afw_authorization_handler_t),
122  xctx);
123  self->inf = inf;
124  self->p = p;
125 
126  /* Prepare properties. */
128  properties, xctx);
129 
130  /* Get authorizationHandlerType from properties. */
131  self->authorization_handler_type_id = afw_object_old_get_property_as_string(
132  properties, &afw_s_authorizationHandlerType, xctx);
133 
134  /* Get source location. Default it to authorization handler. */
135  self->source_location = afw_object_old_get_property_as_string(
136  properties, &afw_s_sourceLocation, xctx);
137  if (!self->source_location) {
138  self->source_location = &afw_s_authorization_handler;
139  }
140 
141  /* Get authorization_handler_id from parameters. */
143  &afw_s_authorizationHandlerId, p, xctx);
144  if (!s) {
145  AFW_THROW_ERROR_FZ(general, xctx,
146  "%" AFW_UTF8_FMT " requires id property.",
147  AFW_UTF8_FMT_ARG(self->source_location));
148  }
149  afw_memory_copy(&self->authorization_handler_id, s);
150 
151  /* Create lock. */
152  s = afw_utf8_printf(p, xctx,
153  "authorization_handler_id:%" AFW_UTF8_FMT,
154  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
155  if (!afw_environment_get_lock(s, xctx)) {
156  self->authorization_handler_lock_rw = afw_lock_create_rw_and_register(
157  afw_utf8_clone(s, xctx->env->p, xctx),
158  afw_utf8_printf(xctx->env->p, xctx,
159  "Authorization handler id %" AFW_UTF8_FMT " read/write lock",
160  AFW_UTF8_FMT_ARG(&self->authorization_handler_id)),
161  afw_utf8_printf(xctx->env->p, xctx,
162  "Read/write lock used internally by authorization_handler id %"
163  AFW_UTF8_FMT " implementation.",
164  AFW_UTF8_FMT_ARG(&self->authorization_handler_id)),
165  xctx);
166  }
167 
168  /* Service id. */
169  self->service_id = afw_utf8_printf(p, xctx,
170  "authorizationHandler-%" AFW_UTF8_FMT,
171  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
172 
173  /* priority default 9999 */
174  self->priority = afw_object_old_get_property_as_integer(properties,
175  &afw_s_priority, &found, xctx);
176  if (!found) {
177  self->priority = 9999;
178  }
179 
180  /* allow_* and required. */
181  self->allow_deny_override = afw_object_old_get_property_as_boolean(properties,
182  &afw_s_allowDenyOverride, &found, xctx);
183  self->allow_permit_override = afw_object_old_get_property_as_boolean(properties,
184  &afw_s_allowPermitOverride, &found, xctx);
185  self->required = afw_object_old_get_property_as_boolean(properties,
186  &afw_s_required, &found, xctx);
187 
188  /* Set trace fields */
189  impl_set_trace_flag_fields(self, xctx);
190 
191  /* Trace create */
192  afw_trace_fz(1, self->trace_flag_index, self, xctx,
193  "authorizationHandlerId %" AFW_UTF8_FMT " is being created",
194  AFW_UTF8_FMT_ARG(&self->authorization_handler_id));
195 
196  /* Return new instance. */
197  return self;
198 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
afw_authorization_handler_impl_create_cede_p(const afw_authorization_handler_inf_t *inf, afw_size_t instance_size, const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Developers should call this in all create functions for a afw_authorization_handler.
#define afw_object_old_get_property_as_boolean(object, property_name, found, xctx)
Get property function for data type boolean value.
#define afw_object_old_get_property_as_integer(object, property_name, found, xctx)
Get property function for data type integer value.
#define afw_object_old_get_property_as_string(object, property_name, xctx)
Get property function for data type string value.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
Definition: afw_common.h:605
_Bool afw_boolean_t
Definition: afw_common.h:373
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
const afw_object_t * afw_environment_prepare_conf_type_properties(const afw_object_t *properties, afw_xctx_t *xctx)
Prepare properties for a conf type.
#define afw_environment_register_flag(flag_id, brief, description, included_by_flag_id, xctx)
Register a flag.
const afw_lock_t * afw_environment_get_lock(const afw_utf8_t *log_type, afw_xctx_t *xctx)
Get the lock instance associated a lock id.
const afw_flag_t * afw_environment_get_flag(const afw_utf8_t *flag_id, afw_xctx_t *xctx)
Get the flag instance associated with flag_id.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:319
void afw_flag_add_included_by(const afw_utf8_t *flag_id, const afw_utf8_t *included_by_flag_id, afw_xctx_t *xctx)
Add another include_by flag to a registered flag.
Definition: afw_flag.c:688
afw_lock_create_rw_and_register(const afw_utf8_t *lock_id, const afw_utf8_t *brief, const afw_utf8_t *description, afw_xctx_t *xctx)
Create a read/write lock and register in environment.
Definition: afw_lock.c:175
#define afw_memory_copy(to, from)
Copy to preallocated memory of same type.
Definition: afw_memory.h:39
afw_object_old_get_property_as_utf8(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
Get an object's property value as a string in specified pool.
Definition: afw_object.c:531
#define afw_pool_calloc(instance, size, xctx)
Call method calloc of interface afw_pool.
#define afw_trace_fz(trace_level, flag_index, instance, xctx, format_z,...)
If applicable, write trace using a printf style format.
Definition: afw_trace.h:88
const afw_utf8_t * afw_utf8_clone(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Clone a utf-8 string into a specific pool.
Definition: afw_utf8.h:347
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
Definition: afw_utf8.c:459
Interface afw_authorization_handler_inf_s struct.
Interface afw_authorization_handler public struct.
const afw_pool_t * p
Pool used to hold environment.
Definition: afw_common.h:1386
Struct used for a registered flag.
Definition: afw_flag.h:32
afw_size_t flag_index
Index of this flag in flags array.
Definition: afw_flag.h:51
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.