16 #define AFW_IMPLEMENTATION_ID "afw_command_local"
33 impl_compiled_afw_version =
40 " \"type\" : \"requestHandler\",\n"
41 " \"uriPrefix\" : \"/\",\n"
42 " \"requestHandlerType\" : \"adaptor\"\n"
65 apr_array_clear(self->input_buffer);
73 c = fgetc(self->fd_input);
75 if (self->input_buffer->nelts != 0) {
80 if (c < '0' || c >
'9') {
83 rv = ungetc(c, self->fd_input);
89 rv = fscanf(self->fd_input,
"%lld", &len);
90 if (rv < 0 || rv != 1) {
93 c = fgetc(self->fd_input);
102 for (; len > 0; len--) {
103 c = fgetc(self->fd_input);
104 if (c < 0 || c > 255) {
107 APR_ARRAY_PUSH(self->input_buffer,
unsigned char) = c;
113 result->ptr = (
const afw_byte_t *)self->input_buffer->elts;
114 result->size = self->input_buffer->nelts;
118 self->fatal_error =
true;
124 impl_get_directive_input(
133 if (string->len == directive_len) {
137 if (string->s[directive_len] !=
':') {
141 s.s =
string->s + directive_len + 1;
142 s.len =
string->len - directive_len - 1;
152 impl_process_directive(
170 &afw_command_s_a_local_mode_evaluate_direct))
172 self->mode = afw_command_local_server_mode_evaluate_direct;
173 if (self->multi_request_mode_properties) {
177 self->multi_request_mode_properties = impl_get_directive_input(
self,
178 string, afw_command_s_a_local_mode_evaluate_direct.len, xctx);
184 &afw_command_s_a_local_mode_evaluate))
186 self->mode = afw_command_local_server_mode_evaluate;
187 if (self->multi_request_mode_properties) {
191 self->multi_request_mode_properties = impl_get_directive_input(
self,
192 string, afw_command_s_a_local_mode_evaluate.len, xctx);
198 &afw_command_s_a_local_mode_action_direct))
200 self->mode = afw_command_local_server_mode_action_direct;
201 if (self->multi_request_mode_properties) {
205 self->multi_request_mode_properties = impl_get_directive_input(
self,
206 string, afw_command_s_a_local_mode_action_direct.len, xctx);
212 &afw_command_s_a_local_mode_action))
214 self->mode = afw_command_local_server_mode_action;
215 if (self->multi_request_mode_properties) {
219 self->multi_request_mode_properties = impl_get_directive_input(
self,
220 string, afw_command_s_a_local_mode_action.len, xctx);
226 &afw_command_s_a_local_mode_http_like))
228 self->mode = afw_command_local_server_mode_http_like;
229 if (self->multi_request_mode_properties) {
233 self->multi_request_mode_properties = impl_get_directive_input(
self,
234 string, afw_command_s_a_local_mode_http_like.len, xctx);
240 &afw_command_s_a_local_request_properties))
242 if (self->multi_request_properties) {
245 self->multi_request_properties = impl_get_directive_input(
self,
246 string, afw_command_s_a_local_request_properties.len, xctx);
252 if (string->len <= 30) {
258 partial.s =
string->s;
270 impl_read_and_process_request(
284 0, self->command_self->xctx);
286 error_occurred =
false;
298 input = impl_local_get_input(
self, xctx);
301 if (self->fatal_error) {
322 &afw_command_s_a_local_directive_starts_with))
324 impl_process_directive(
self, input, xctx);
332 self->pub.request_count++;
334 switch (self->mode) {
336 case afw_command_local_server_mode_action:
337 xctx->request = afw_command_local_request_create(
self,
338 input, self->request_properties, xctx);
340 xctx->request, xctx);
343 case afw_command_local_server_mode_action_direct:
349 action_object, self->content_type, NULL, p, xctx);
352 afw_command_local_server_write_result(
self,
356 case afw_command_local_server_mode_evaluate:
369 xctx->request = afw_command_local_request_create(
self,
373 xctx->request, xctx);
376 case afw_command_local_server_mode_evaluate_direct:
382 &afw_s_function, &afw_s_evaluate_expression, xctx);
384 &afw_s_source,
string, xctx);
386 action_object, self->content_type, NULL, p, xctx);
389 afw_command_local_server_write_result(
self,
393 case afw_command_local_server_mode_http_like:
394 body = afw_command_local_parse_request(
self, &input, xctx);
395 xctx->request = afw_command_local_request_create(
396 self, body, self->request_properties, xctx);
398 xctx->request, xctx);
410 error_occurred =
true;
414 xctx->request = NULL;
418 afw_command_local_server_write_end(
self);
421 return keep_going && !
self->fatal_error;
458 afw_command_local_server_write_result(
self,
459 "afw " AFW_VERSION_STRING
"\n\n" "Local mode.\n");
460 afw_command_local_server_write_end(
self);
462 while (impl_read_and_process_request(
self));
476 xctx = command_self->xctx;
480 self->pub.inf = &impl_afw_server_inf;
481 self->pub.xctx = xctx;
483 self->pub.afw_compiled_version = &impl_compiled_afw_version;
485 self->pub.concurrent = 1;
486 self->pub.max_concurrent = 1;
487 self->pub.server_type = &afw_command_s_afw_command_local_mode;
488 self->pub.server_version = &impl_compiled_afw_version;
490 self->pub.thread_count = 1;
491 self->pub.server_version = &impl_compiled_afw_version;
493 self->command_self = command_self;
495 self->fd_input = command_self->fd_input;
496 self->fd_output = command_self->fd_output;
498 self->mode = afw_command_local_server_mode_evaluate_direct;
501 self->evaluate_function_id = &afw_s_evaluate_expression;
502 self->content_type = command_self->content_type_in;
506 &afw_s__AdaptiveServer_,
507 &afw_s_current,
self,
true, xctx);
510 if (!self->command_self->conf_z) {
511 self->command_self->conf_z =
"internal";
512 self->command_self->conf.len = strlen(
"internal");
516 &self->command_self->conf,
523 &self->command_self->conf, xctx);
529 self->command_self->conf_z,
534 self->mode = afw_command_local_server_mode_evaluate_direct;
535 if (self->multi_request_mode_properties) {
539 self->multi_request_mode_properties =
542 &self->properties_array[0], p, xctx);
544 &afw_s_afw, &afw_s__AdaptiveRequestProperties_, &afw_s_current, xctx);
554 afw_command_local_server_write_result(
556 const char *format, ...)
566 va_start (ap, format);
567 len = vsnprintf(NULL, 0, format, ap);
569 if (len < 0) exit(EXIT_FAILURE);
571 rv = fprintf(self->fd_output,
"%d\n", len);
572 if (rv < 0) exit(EXIT_FAILURE);
573 rv = fflush(self->fd_output);
574 if (rv < 0) exit(EXIT_FAILURE);
576 va_start (ap, format);
577 rv = vfprintf(self->fd_output, format, ap);
579 if (rv < 0) exit(EXIT_FAILURE);
581 rv = fflush(self->fd_output);
582 if (rv < 0) exit(EXIT_FAILURE);
589 afw_command_local_server_write_error(
602 status = (
self->fatal_error) ? &afw_s_fatal : &afw_s_error;
604 &afw_s_status, status, xctx);
608 &afw_s_error, error_object, xctx);
611 rv = fprintf(self->fd_output,
"%" AFW_SIZE_T_FMT "\n", string->len);
612 if (rv < 0) exit(EXIT_FAILURE);
615 if (rv < 0) exit(EXIT_FAILURE);
616 rv = fflush(self->fd_output);
617 if (rv < 0) exit(EXIT_FAILURE);
623 afw_command_local_server_write_end(
629 rv = fprintf(self->fd_output,
"0\n");
630 if (rv < 0) exit(EXIT_FAILURE);
631 rv = fflush(self->fd_output);
632 if (rv < 0) exit(EXIT_FAILURE);
Adaptive Framework Core API.
#define AFW_COMMAND_DEFINE_INTERNAL(type)
Define an internal function for /src/afw_command/ source*.c files.
Adaptive Framework afw command internal header.
Parse function to support afw command local server.
Implementation for interface afw_command_local.
Implementation for interface afw_command_local.
Interface afw_interface implementation declares.
afw_action_perform(const afw_object_t *request, const afw_content_type_t *response_content_type, const afw_object_t *response, const afw_pool_t *p, afw_xctx_t *xctx)
Perform actions(s) specified in AdaptiveActions object.
afw_adaptor_session_commit_and_release_cache(afw_boolean_t abort, afw_xctx_t *xctx)
Commit/Abort changes and release cached sessions and objects.
#define afw_value_is_list(A_VALUE)
Macro to determine if value is evaluated list.
afw_object_set_property_as_object(const afw_object_t *object, const afw_utf8_t *property_name, const afw_object_t *internal, afw_xctx_t *xctx)
Set property function for data type object values.
afw_data_type_object
Data type struct for object.
afw_data_type_object_to_utf8(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Convert data type object internal representation to utf-8.
afw_data_type_string
Data type struct for string.
afw_object_set_property_as_string(const afw_object_t *object, const afw_utf8_t *property_name, const afw_utf8_t *internal, afw_xctx_t *xctx)
Set property function for data type string values.
afw_command_local_server_create(afw_command_self_t *command_self)
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
unsigned char afw_byte_t
A byte of memory (unsigned).
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
#define AFW_SIZE_T_FMT
Format string specifier used for afw_size_t.
#define afw_content_type_raw_to_value(instance, raw, source_location, p, xctx)
Call method raw_to_value of interface afw_content_type.
#define afw_data_type_convert_internal(instance, to_internal, from_internal, to_data_type, p, xctx)
Call method convert_internal of interface afw_data_type.
void afw_environment_configure_with_object_list(const afw_list_t *entry_list, const afw_utf8_t *source_location, afw_xctx_t *xctx)
Configure environment with list of configuration entries.
#define AFW_FINALLY
Always executed regardless of error.
#define AFW_CATCH_UNHANDLED
Catch an unhandled error that occurs in a AFW_TRY block.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
const afw_object_t * afw_error_to_object(const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
Create an object with error info in specified pool.
#define AFW_ERROR_THROWN
Access the thrown error. See AFW_TRY.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
afw_json_utf8_string_create(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Create a json encoded quoted string.
#define afw_json_to_object(string, cede_p, p, xctx)
Compile json string to adaptive object.
afw_json_content_type_get()
Get the content type instance for json.
#define afw_object_release(instance, xctx)
Call method release of interface afw_object.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
const afw_object_t * afw_object_aggregate_external_create(const afw_object_t *const *object_list, const afw_pool_t *p, afw_xctx_t *xctx)
Create an aggregate object with an external object list.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
#define afw_request_handler_process(instance, request, xctx)
Call method process of interface afw_request_handler.
const afw_request_handler_t * afw_request_handler_director_create(const afw_server_t *server, const afw_utf8_z_t *config_file, const afw_pool_t *p, afw_xctx_t *xctx)
Create a request handler for director.
afw_runtime_env_create_and_set_indirect_object(const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, void *internal, afw_boolean_t overwrite, afw_xctx_t *xctx)
Create and set an indirect runtime object.
afw_runtime_env_set_object(const afw_object_t *object, afw_boolean_t overwrite, afw_xctx_t *xctx)
Set an object pointer in the environment's runtime objects.
impl_afw_server_release(const afw_server_t *instance, afw_xctx_t *xctx)
impl_afw_server_run(const afw_server_t *instance, const afw_request_handler_t *handler, afw_xctx_t *xctx)
afw_dateTime_now_local(const afw_pool_t *p, afw_xctx_t *xctx)
Get now local time as dateTime in specified pool.
afw_boolean_t afw_utf8_equal_utf8_z(const afw_utf8_t *s1, const afw_utf8_z_t *s2_z)
Check to see if a string equals a utf8_z string.
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.
afw_boolean_t afw_utf8_starts_with(const afw_utf8_t *string, const afw_utf8_t *starts_with)
Check to see if a string starts with another string.
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
const afw_utf8_t * afw_version_string()
#define afw_xctx_release(instance, xctx)
Call method release of interface afw_xctx.
#define afw_xctx_malloc_type(type, xctx)
Macro to allocate uncleared memory to hold type in xctx's pool.
afw_xctx_create(const afw_utf8_t *name, afw_integer_t number, afw_xctx_t *xctx)
Create an Adaptive Framework xctx.
Self typedef for afw_command_local implementation of afw_server.
Self typedef for afw_command self.
Adaptive Framework Error.
Struct for memory pointer and size.
Interface afw_object public struct.
Interface afw_pool public struct.
Interface afw_request_handler public struct.
Interface afw_server public struct.
NFC normalized UTF-8 string.
struct for data type list values.
Interface afw_value public struct.
Interface afw_xctx public struct.