9 #ifndef __AFW_COMMON_H__
10 #define __AFW_COMMON_H__
53 #include <apr_general.h>
54 #include <apr_tables.h>
55 #include <apr_strings.h>
58 #include <apr_buckets.h>
59 #include <apr_atomic.h>
60 #include <apr_thread_proc.h>
61 #include <apr_thread_rwlock.h>
96 #if defined(_WIN32) || defined(WIN32)
97 #define AFW_ATOMIC volatile
100 #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
101 #define AFW_HAS_ATOMIC
102 #include <stdatomic.h>
103 #define AFW_ATOMIC _Atomic
105 #error C11 or higher with atomic primitives and types is required to compile Adaptive Framework
125 #define AFW_POSSIBLY_UNUSED_VARIABLE __attribute__((unused))
127 #define AFW_POSSIBLY_UNUSED_VARIABLE
131 #define AFW_ASSERT(e) assert(e)
135 #define offsetof(type, member) __builtin_offsetof (type, member)
141 #define AFW_ADAPTOR_ID "afw"
144 #define AFW_STRINGIFY(x) AFW_STRINGIFY_x(x)
145 #define AFW_STRINGIFY_x(x) #x
148 #define AFW__FILE_LINE__ __FILE__ ":" AFW_STRINGIFY(__LINE__)
166 #define AFW_INT32_MIN -2147483647 - 1
169 #define AFW_INT32_MAX 2147483647
181 #define AFW_UINT16_MAX 65536
187 #define AFW_UINT32_MAX 4294967296
266 #define AFW_UTF8_Z_LEN -1
275 #define AFW_INTEGER_MAX_BUFFER 21
281 #define AFW_INTEGER_MAX APR_INT64_MAX
286 #define AFW_INTEGER_Q_MAX "9223372036854775807"
291 #define AFW_INTEGER_MIN APR_INT64_MIN
296 #define AFW_INTEGER_Q_MIN "-9223372036854775808"
301 #define AFW_INTEGER_MAX_SAFE_DOUBLE 9007199254740991
306 #define AFW_INTEGER_MIN_SAFE_DOUBLE -9007199254740991
313 #define AFW_INTEGER_IS_SAFE_DOUBLE(integer) \
314 ((integer) <= AFW_INTEGER_MAX_SAFE_DOUBLE && \
315 ((integer) >= AFW_INTEGER_MIN_SAFE_DOUBLE)
326 #define AFW_INTEGER_FMT APR_INT64_T_FMT
331 #define AFW_INTEGER_MAX_DIGITS 19
336 #define AFW_Q_INTEGER_MAX_DIGITS "19"
341 #define AFW_SIZE_T_FMT APR_SIZE_T_FMT
346 #define AFW_SIZE_T_MAX APR_SIZE_MAX
351 #define AFW_SIZE_T_MAX_DIGITS 19
356 #define AFW_Q_SIZE_T_MAX_DIGITS "19"
362 #define AFW_SIZE_T_MAX_BUFFER AFW_SIZE_T_MAX_DIGITS + 1
383 #define AFW_TRUE true
392 #define AFW_FALSE false
396 #define AFW_CRLF "\x0d\x0a"
400 #define AFW_CRLF_STRLEN 2
409 #define AFW_COMPILE_TYPE_MAP(XX) \
413 "This is an error") \
417 &afw_function_definition_compile_expression, \
418 "See production Expression in src/afw/doc/syntax/index.html or " \
419 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
421 XX(expression_tuple, \
423 &afw_function_definition_compile_expression_tuple, \
424 "See production ExpressionTuple in src/afw/doc/syntax/index.html or " \
425 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
429 &afw_function_definition_compile_hybrid, \
430 "See production Hybrid in src/afw/doc/syntax/index.html or " \
431 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
435 &afw_function_definition_compile_json, \
436 "Compile strict json") \
438 XX(parenthesized_expression, \
440 &afw_function_definition_compile_expression, \
441 "See production ParenthesizedExpression in " \
442 "src/afw/doc/syntax/index.html " \
443 "or src/afw/generated/ebnf/syntax.ebnf for syntax.") \
447 &afw_function_definition_compile_regexp, \
448 "Parses a regular expression conforming to XML Schemas Part 2 " \
449 "Datatype Appendix F and builds an automata suitable for testing " \
450 "strings against that regular expression ") \
454 &afw_function_definition_compile_relaxed_json, \
455 "1) Allows inline and block comments\n" \
456 "2) Allows property names to be unquoted if they start with '_',\n" \
457 " '$', 'a-z', 'A-Z', or char > 127 followed by any of those or\n" \
459 "3) Allows Infinity, -Infinity, NaN, and -NaN for number values.\n" \
460 "4) Allows a trailing comma in Object and List.") \
464 &afw_function_definition_compile_script, \
465 "See production Script in src/afw/doc/syntax/index.html or " \
466 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
470 &afw_function_definition_compile_template, \
471 "See production Template in src/afw/doc/syntax/index.html or " \
472 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
476 &afw_function_definition_compile_script, \
477 "See production TestScript in src/afw/doc/syntax/index.html or " \
478 "src/afw/generated/ebnf/syntax.ebnf for syntax.") \
480 XX(xpathExpression, \
482 &afw_function_definition_compile_xpathExpression, \
483 "XML Path Language (XPath) expression")
489 #define XX(name, data_type, compile_function, description) \
490 afw_compile_type_ ## name,
493 afw_compile_type_count
582 #define AFW_UTF8_LITERAL(A_STRING) {A_STRING, sizeof(A_STRING) - 1}
588 #define AFW_UTF8_FMT ".*s"
591 #define AFW_UTF8_CONTEXTUAL_LABEL_FMT_SEP "> "
595 #define AFW_UTF8_CONTEXTUAL_LABEL_FMT \
596 AFW_UTF8_FMT AFW_UTF8_CONTEXTUAL_LABEL_FMT_SEP
605 #define AFW_UTF8_FMT_ARG(A_STRING) \
606 (int)(A_STRING)->len, (const char *)(A_STRING)->s
616 #define AFW_UTF8_FMT_OPTIONAL_ARG(A_STRING) \
617 (A_STRING) ? (int)(A_STRING)->len : 0, \
618 (A_STRING) ? (const char *)(A_STRING)->s : ""
628 #define AFW_UTF8_FMT_OPTIONAL_UNDEFINED_ARG(A_STRING) \
629 (A_STRING) ? (int)(A_STRING)->len : 0, \
630 (A_STRING) ? (const char *)(A_STRING)->s : "<undefined>"
636 #define AFW_MESSAGE_PREFIX __FILE__ ":" AFW_STRINGIFY(__LINE__) " "
642 #define AFW_UTF8_ENCODING "UTF-8"
718 #define AFW_STACK_STRUCT(struct_name, entry_type) \
719 struct struct_name { \
723 const afw_pool_t *p; \
896 #define AFW_ERROR_CODE_MAP(XX) \
897 XX(none, true, 200, "OK" )\
898 XX(general, true, 500, "General Error" )\
899 XX(bad_request, true, 400, "Bad Request" )\
900 XX(query_too_complex, true, 400, "Query Too Complex" )\
901 XX(request_syntax, true, 400, "Request Syntax Error" )\
902 XX(objects_needed, true, 400, "Objects Needed To Complete Request")\
903 XX(authentication_required,true, 401, "Authentication Needed" )\
904 XX(denied, true, 403, "Forbidden - Access Denied" )\
905 XX(read_only, true, 403, "Forbidden - Read Only" )\
906 XX(not_found, true, 404, "Not Found" )\
907 XX(method_not_allowed, true, 405, "Method Not Allowed" )\
908 XX(unsupported_accept, false, 406, "Unsupported Content Type Requested")\
909 XX(client_time_out, true, 408, "Request Timeout" )\
910 XX(im_a_teapot, true, 418, "I'm a Teapot" )\
911 XX(conflict, true, 409, "Conflict" )\
912 XX(length_required, true, 411, "Content Length Required" )\
913 XX(payload_too_large, true, 413, "Payload too large" )\
914 XX(unsupported_content, true, 415, "Unsupported Content Type" )\
915 XX(memory, true, 500, "Memory Error" )\
916 XX(syntax, true, 500, "Server Side Syntax Error" )\
917 XX(method_not_supported, true, 501, "Method Not Supported" )\
918 XX(client_closed, false, 000, "Client Closed Connection" )\
919 XX(assertion_failed, true, 400, "Assertion failed" )\
920 XX(cast_error, true, 400, "Adaptive Type Cast Error" )\
921 XX(arg_error, true, 400, "Adaptive Function Arg Error" )\
922 XX(evaluate, true, 400, "Evaluation error" )\
923 XX(undefined, true, 400, "Undefined value" )\
924 XX(code, true, 500, "Clearly an internal coding error" )\
928 afw_error_code_is_not_specified = 0,
930 #define XX(id, error_allow_in_response, http_response_code, description) \
931 afw_error_code_ ## id,
969 (*afw_xctx_get_variable_t)(
978 afw_log_priority_invalid = -1,
1209 const void * buffer,
1228 const void * buffer,
1241 (*afw_runtime_value_accessor_t) (
1266 (*afw_function_thunk_execute_t) (
1289 (*afw_function_arg_check_t)(
1298 #define AFW_SERVICE_STARTUP_MAP(XX) \
1299 XX(disabled, "Service is disabled and cannot be started." )\
1300 XX(permanent, "Service is permanently started and can not be stopped." )\
1301 XX(manual, "Service is started and stopped manually." )\
1302 XX(immediate, "Service is started immediately and can be stopped and " \
1303 "started manually." )\
1313 #define XX(id, desc) afw_service_startup_ ## id,
1317 afw_service_startup_invalid
1321 #define AFW_SERVICE_STATUS_MAP(XX) \
1322 XX(error, "Service is not running because of an error." )\
1323 XX(disabled, "Service is disabled." )\
1324 XX(ready_to_start, "Service is ready to start." )\
1325 XX(starting, "Service is starting." )\
1326 XX(running, "Service is running." )\
1327 XX(stopping, "Service is finishing active work and releasing resources." )\
1328 XX(stopped, "Service is stopped and can be started manually." )\
1329 XX(restarting,"Service is restarting." )\
1339 #define XX(id, desc) afw_service_status_ ## id,
1343 afw_service_status_invalid
1348 #define afw_thread_mutex_t apr_thread_mutex_t
1351 #define afw_thread_mutex_create apr_thread_mutex_create
1354 #define afw_thread_mutex_lock apr_thread_mutex_lock
1357 #define afw_thread_mutex_trylock apr_thread_mutex_trylock
1360 #define afw_thread_mutex_unlock apr_thread_mutex_unlock
1363 #define afw_thread_mutex_destroy apr_thread_mutex_destroy
1366 #define AFW_THREAD_FUNCTION APR_THREAD_FUNC
1377 #define AFW_ENVIRONMENT_DEFAULT_EVALUATION_STACK_INITIAL_COUNT 100
1380 #define AFW_ENVIRONMENT_DEFAULT_EVALUATION_STACK_MAXIMUM_COUNT 200
(deprecated) Adaptive Framework associative array templates
Adaptive Framework Common Opaques Header.
Adaptive Framework declare helpers for afw_.
#define AFW_BEGIN_DECLARES
Adaptive Framework Base Package main Doxygen groups.
Interface afw_interface opaque typedefs.
struct afw_object_meta_s afw_object_meta_t
Typedef for meta variable in afw_object interface.
#define AFW_SERVICE_STARTUP_MAP(XX)
Map used for afw_service_startup_t enum.
void(* afw_service_wrapper_stop_cb)(void *data, afw_xctx_t *xctx)
Typedef for service wrapper stop call back.
#define AFW_STACK_STRUCT(struct_name, entry_type)
Define a struct for a stack with the specified entry type.
uint8_t afw_uint8_t
8-bit unsigned integer.
struct afw_name_value_s afw_name_value_t
Typedef for name/value pair.
apr_uint64_t afw_uint64_t
64-bit unsigned integer.
double afw_float64_t
64-bit float.
struct afw_dateTime_s afw_dateTime_t
date, time, and time zone.
afw_boolean_t(* afw_object_cb_t)(const afw_object_t *object, void *context, afw_xctx_t *xctx)
Typedef for afw_adaptor_session_object callback.
afw_log_priority_e
Log levels. See afw_log.h for more information.
struct afw_time_no_time_zone_s afw_time_no_time_zone_t
time with no time zone.
apr_uint16_t afw_uint16_t
16-bit unsigned integer.
void *(AFW_THREAD_FUNCTION * afw_thread_function_t)(const afw_thread_t *thread, void *arg)
Typedef for thread start function.
double afw_double_t
Normal AFW number is double.
apr_int32_t afw_int32_t
32-bit signed integer.
afw_service_status_e
Typedef for service status enum.
apr_int16_t afw_int16_t
16-bit signed integer.
apr_uint64_t afw_unsigned_integer_t
typedef for big unsigned int.
struct afw_time_s afw_time_t
time with time zone.
#define AFW_THREAD_FUNCTION
Uses APR_THREAD_FUNC as AFW_THREAD_FUNCTION.
double afw_float_t
Normal float.
afw_service_startup_e
Typedef for service startup type enum.
struct afw_yearMonthDuration_s afw_yearMonthDuration_t
yearMonth duration
int8_t afw_int8_t
8-bit signed integer.
enum afw_error_code_e afw_error_code_t
int afw_log_priority_mask_t
unsigned char afw_byte_t
A byte of memory (unsigned).
afw_boolean_t(* afw_value_cb_t)(const void *value, void *context, afw_xctx_t *xctx)
Typedef for value callback.
struct afw_key_z_string_z_s afw_key_z_string_z_t
Typedef for key/string pair that have both utf8 and utf8_z.
enum afw_service_status_e afw_service_status_t
Typedef for service status enum.
afw_int32_t afw_code_point_t
Unicode code point.
struct afw_time_zone_s afw_time_zone_t
time zone
enum afw_service_startup_e afw_service_startup_t
Typedef for service startup type enum.
struct afw_dayTimeDuration_s afw_dayTimeDuration_t
dayTime duration
#define AFW_SERVICE_STATUS_MAP(XX)
Map used for afw_service_status_t enum.
char * afw_uri_t
this implementation uses UTF-8.
#define AFW_COMPILE_TYPE_MAP(XX)
Compile Type Map.
int(* afw_utf8_octet_get_cb_t)(afw_utf8_octet_t *octet, void *data, afw_xctx_t *xctx)
Get an utf-8 octet (8 bits).
struct afw_memory_s afw_memory_t
Struct for memory pointer and size.
struct afw_utf8_array_s afw_utf8_array_t
Array of strings.
struct afw_date_s afw_date_t
date with time zone.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
apr_int64_t afw_int64_t
64-bit signed integer.
afw_size_t(* afw_read_cb_t)(void *context, const void *buffer, afw_size_t size, afw_boolean_t *more_to_read, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for read callback function.
apr_uint32_t afw_uint32_t
32-bit unsigned integer.
float afw_float32_t
32-bit float.
enum afw_compile_type_e afw_compile_type_t
Compile type enum.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
uint32_t afw_u_cp_t
A Unicode codepoint. Range is 0 to 0x10ffff. Other values are illegal Unicode codepoints.
apr_size_t afw_size_t
size_t.
afw_adaptor_journal_option_e
Typedef for afw_adaptor_journal get_entry options enum.
struct afw_time_with_offset_s afw_time_with_offset_t
Time with offset (old)
void(* afw_pool_cleanup_function_p_t)(void *data, void *data2, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for pool cleanup functions.
struct afw_time_duration_s afw_time_duration_t
Time duration.
struct afw_thread_attr_s afw_thread_attr_t
Typedef for afw_thread_attr.
afw_compile_type_e
Compile type enum.
unsigned char afw_octet_t
8 bits (unsigned).
enum afw_log_priority_e afw_log_priority_t
Log levels. See afw_log.h for more information.
struct afw_utf8_s afw_utf8_t
NFC normalized UTF-8 string.
struct afw_key_string_s afw_key_string_t
Typedef for key/string pair.
void(* afw_service_wrapper_start_cb)(void *data, afw_xctx_t *xctx)
Typedef for service wrapper start call back.
#define AFW_ERROR_CODE_MAP(XX)
Error code map. IMPORTANT>>> Do not change the order of these entries. The order must match the order...
afw_code_point_t(* afw_code_point_get_cb_t)(void *data, afw_xctx_t *xctx)
Get Unicode code point callback.
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
apr_int64_t afw_integer_t
typedef for big signed int.
union afw_c_types_u afw_c_types_t
Typedef for union of all cType.
enum afw_adaptor_journal_option_e afw_adaptor_journal_option_t
Typedef for afw_adaptor_journal get_entry options enum.
apr_off_t afw_off_t
off_t.
struct afw_date_no_time_zone_s afw_date_no_time_zone_t
date with no time zone.
union afw_utf8_utf8_z_s afw_utf8_utf8_z_t
NFC normalized UTF-8 string accessible as afw_utf8_t or afw_utf8_z_t.
@ afw_log_priority_trace3
@ afw_log_priority_trace8
@ afw_log_priority_trace4
@ afw_log_priority_notice
@ afw_log_priority_trace2
@ afw_log_priority_trace5
@ afw_log_priority_trace_min
@ afw_log_priority_trace7
@ afw_log_priority_trace6
@ afw_log_priority_trace_max
@ afw_log_priority_warning
@ afw_log_priority_trace1
@ afw_adaptor_journal_option_get_next_for_consumer_after_cursor
afw_adaptor_journal get_entry option get_next_for_consumer_after_cursor
@ afw_adaptor_journal_option_get_next_for_consumer
afw_adaptor_journal get_entry option get_next_for_consumer
@ afw_adaptor_journal_option_advance_cursor_for_consumer
afw_adaptor_journal get_entry option advance_cursor_for_consumer
@ afw_adaptor_journal_option_get_next_after_cursor
afw_adaptor_journal get_entry option get_next_after_cursor
@ afw_adaptor_journal_option_get_by_cursor
afw_adaptor_journal get_entry option get_by_cursor
@ afw_adaptor_journal_option_get_first
afw_adaptor_journal get_entry option get_first
@ afw_error_code_highest_afw
Interface afw_adaptor public struct.
afw_date_no_time_zone_t date
afw_time_zone_t time_zone
date, time, and time zone.
afw_time_no_time_zone_t time
afw_date_no_time_zone_t date
afw_time_zone_t time_zone
Struct for typedef afw_environment_t defined in afw_common.h.
AFW_ATOMIC const afw_boolean_t * default_flags
Default flags array indexed by flag_index.
AFW_ATOMIC afw_integer_t pool_number
Used to give unique number for pool.
FILE * stdout_fd
Open file descriptor used for writing standard output. Default stdout.
const afw_lock_t * multithreaded_pool_lock
Lock used internal to afw_pool.c.
afw_double_t minus_infinity
Double minus infinity.
afw_utf8_t application_id
The id of the application.
afw_size_t flag_index_trace_request_detail
Flag index of trace:request:detail.
AFW_ATOMIC afw_size_t flags_count_allocated
The number of flags allocated in global_flags.
afw_size_t flag_index_trace_authorization_check_detail
Flag index of trace:authorization:check:detail.
afw_size_t evaluation_stack_maximum_count
maximum_count used to create xctx's evaluation stack.
afw_size_t flag_index_debug_pool
Flag index of debug:pool.
const afw_adaptor_t * afw_adaptor
Adaptive framework core adaptor.
const afw_lock_t * active_log_list_lock
Lock for protecting changes to active log list.
afw_size_t flag_index_response_error_hasAdditionalDetail
Flag index of response:error:hasAdditionalDetail.
afw_double_t NaN
Double NaN.
afw_size_t flag_index_response_error_contextual
Flag index of response:error:contextual.
afw_size_t flag_index_debug_function_active_detail
Flag index of debug:function_active:detail.
const afw_object_t * application_qualified_variables
const afw_log_t * log
Director log. This log will direct to other logs.
const afw_object_t * initial_environment_variables
Environment variables at environment create.
afw_size_t flag_index_trace_evaluation_detail
Flag index of trace:evaluation:detail.
const afw_pool_t * p
Pool used to hold environment.
afw_size_t flag_index_response_error_backtraceEvaluation
Flag index of response:error:backtraceEvaluation.
const afw_value_t * NaN_value
Double NaN value.
afw_size_t flag_index_trace_authorization_check
Flag index of trace:authorization:check.
afw_size_t flag_index_debug_function_active
Flag index of debug:function_active.
const afw_lock_t * flags_lock
Lock for protecting changes to flags (internal to afw_flag.c).
const afw_lock_t * adaptor_id_anchor_lock
Lock for protecting changes to adaptor id anchors.
const afw_function_environment_t * function_environment
Used by function execution.
const afw_flag_t *AFW_ATOMIC const * flag_by_index
Flag struct indexed by flag_index.
afw_size_t flag_index_trace_authorization_decision_detail
Flag index of trace:authorization:decision:detail.
const afw_object_t * application_object
Application object - /afw/_AdaptiveApplication_/current.
afw_size_t flag_index_trace_authorization_decision
Flag index of trace:authorization:decision.
afw_size_t evaluation_stack_initial_count
initial_count used to create xctx's evaluation stack.
FILE * debug_fd
Open file descriptor used for debug writes. Default stderr.
const afw_lock_rw_t * authorization_handler_id_anchor_rw_lock
Lock for protecting changes to authorization handler id anchors.
afw_size_t flag_index_debug_pool_detail
Flag index of debug:pool:detail.
const afw_object_t * root_file_paths
rootFilePaths - /afw/_AdaptiveApplication_/current/rootFilePaths.
afw_boolean_t terminating
Indicates that environment is terminating.
const afw_lock_t * environment_lock
Lock for whole environment.
afw_size_t flag_index_trace_authorization_check_bypass
Flag index of trace:authorization:check:bypass.
afw_log_priority_mask_t log_mask
Copy of director log's mask for short circuit tests.
const afw_value_t * infinity_value
Double infinity value.
const afw_utf8_t * layout_adaptor_id
Custom layout adaptor or NULL.
const afw_authorization_control_t * authorization_control
Used by authorization.
afw_double_t infinity
Double infinity.
afw_size_t flag_index_response_error_backtrace
Flag index of response:error:backtrace.
FILE * stderr_fd
Open file descriptor used for writing error output. Default stderr.
AFW_ATOMIC afw_size_t flags_count_registered
The number of flags registered.
afw_size_t flag_index_trace_request
Flag index of trace:request.
const afw_adaptor_t * conf_adaptor
Adaptor for application.confAdaptorId or NULL.
const afw_value_t * minus_infinity_value
Double minus infinity value.
Struct used for a registered flag.
Function execute parameter.
Typedef for key/string pair.
Typedef for key/string pair that have both utf8 and utf8_z.
Interface afw_list public struct.
Interface afw_log public struct.
Struct for memory pointer and size.
Typedef for name/value pair.
Interface afw_object public struct.
Interface afw_pool public struct.
Struct for runtime object map property.
Struct for afw_stack_t typedef.
Struct for public part of afw_pool_t.
afw_time_no_time_zone_t time
afw_time_zone_t time_zone
NFC normalized UTF-8 string.
Struct for function thunk value.
Interface afw_value public struct.
Interface afw_xctx public struct.
Typedef for union of all cType.
NFC normalized UTF-8 string accessible as afw_utf8_t or afw_utf8_z_t.