From 12366d132df6e0be00fc06514fecae5a92e891c0 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 13 Jul 2022 18:19:21 -0500 Subject: [PATCH] Update: Strip out NULL characters after applying delimits. Once a rule is read and the IKI data is parsed, apply the IKI delimits. NULL characters replace the delimits. Strip out all NULL characters from the string after the delimits are applied. --- level_3/controller/c/rule/private-rule.c | 62 +++++++++++++++++++++++++------- level_3/controller/c/rule/private-rule.h | 28 +++++++++++++++ 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/level_3/controller/c/rule/private-rule.c b/level_3/controller/c/rule/private-rule.c index 1b48e9d..001668f 100644 --- a/level_3/controller/c/rule/private-rule.c +++ b/level_3/controller/c/rule/private-rule.c @@ -163,10 +163,14 @@ extern "C" { return status; } - // Apply the IKI delimits to the buffer. - for (f_array_length_t j = 0; j < action->ikis.array[action->ikis.used].delimits.used; ++j) { - action->parameters.array[action->parameters.used].string[action->ikis.array[action->ikis.used].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0]; - } // for + // Apply the IKI delimits to the buffer, stripping out the NULL characters. + status = controller_rule_action_read_delimit_apply(global, &global.thread->cache, &action->ikis.array[action->ikis.used], &action->parameters.array[action->parameters.used]); + + if (F_status_is_error(status)) { + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true); + + return status; + } } ++action->parameters.used; @@ -317,10 +321,14 @@ extern "C" { return status; } - // Apply the IKI delimits to the buffer. - for (f_array_length_t j = 0; j < actions->array[actions->used].ikis.array[0].delimits.used; ++j) { - actions->array[actions->used].parameters.array[0].string[actions->array[actions->used].ikis.array[0].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0]; - } // for + // Apply the IKI delimits to the buffer, stripping out the NULL characters. + status = controller_rule_action_read_delimit_apply(global, cache, &actions->array[actions->used].ikis.array[0], &actions->array[actions->used].parameters.array[0]); + + if (F_status_is_error(status)) { + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true); + + return status; + } } actions->array[actions->used].ikis.used = 1; @@ -632,10 +640,14 @@ extern "C" { return status; } - // Apply the IKI delimits to the buffer. - for (f_array_length_t j = 0; j < actions->array[actions->used].ikis.array[0].delimits.used; ++j) { - actions->array[actions->used].parameters.array[0].string[actions->array[actions->used].ikis.array[0].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0]; - } // for + // Apply the IKI delimits to the buffer, stripping out the NULL characters. + status = controller_rule_action_read_delimit_apply(global, cache, &actions->array[actions->used].ikis.array[0], &actions->array[actions->used].parameters.array[0]); + + if (F_status_is_error(status)) { + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true); + + return status; + } } actions->array[actions->used].ikis.used = 1; @@ -686,6 +698,32 @@ extern "C" { } #endif // _di_controller_rule_action_read_ +#ifndef _di_controller_rule_action_read_delimit_apply_ + f_status_t controller_rule_action_read_delimit_apply(const controller_global_t global, controller_cache_t * const cache, f_iki_data_t * const iki_data, f_string_dynamic_t * const destination) { + + if (!iki_data->delimits.used) return F_none; + + cache->expanded.used = 0; + + f_status_t status = f_string_dynamics_increase(F_memory_default_allocation_small_d, &cache->expanded); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_append(*destination, &cache->expanded.array[0]); + if (F_status_is_error(status)) return status; + + for (f_array_length_t j = 0; j < iki_data->delimits.used; ++j) { + cache->expanded.array[0].string[iki_data->delimits.array[j]] = f_iki_syntax_placeholder_s.string[0]; + } // for + + destination->used = 0; + + status = f_string_dynamic_append_nulless(cache->expanded.array[0], destination); + if (F_status_is_error(status)) return status; + + return F_none; + } +#endif // _di_controller_rule_action_read_delimit_apply_ + #ifndef _di_controller_rule_action_read_rerun_number_ f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t * const index, f_number_unsigned_t * const number) { diff --git a/level_3/controller/c/rule/private-rule.h b/level_3/controller/c/rule/private-rule.h index 6af5665..b9f6af7 100644 --- a/level_3/controller/c/rule/private-rule.h +++ b/level_3/controller/c/rule/private-rule.h @@ -159,6 +159,34 @@ extern "C" { #endif // _di_controller_rule_action_read_ /** + * Apply delimits and remove resulting NULL characters. + * + * @param global + * The global data. + * @param cache + * A structure for containing and caching relevant data. + * This uses cache->expanded. + * @param iki_data + * The IKI data to process. + * @param destination + * The string to save the expanded data to. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_string_dynamic_append(). + * Errors (with error bit) from: f_string_dynamic_append_nulless(). + * Errors (with error bit) from: f_string_dynamics_increase(). + * + * @see f_string_dynamic_append() + * @see f_string_dynamic_append_nulless() + * @see f_string_dynamics_increase() + */ +#ifndef _di_controller_rule_action_read_delimit_apply_ + extern f_status_t controller_rule_action_read_delimit_apply(const controller_global_t global, controller_cache_t * const cache, f_iki_data_t * const iki_data, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; +#endif // _di_controller_rule_action_read_delimit_apply_ + +/** * Copy a rule, allocating new space as necessary. * * This does not do any locking or unlocking for the rule data, be sure to lock appropriately before and after calling this. -- 1.8.3.1