diff --git a/include/crm/pengine/rules.h b/include/crm/pengine/rules.h index b0b733eb34..24892b78d7 100644 --- a/include/crm/pengine/rules.h +++ b/include/crm/pengine/rules.h @@ -1,36 +1,23 @@ /* * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__CRM_PENGINE_RULES__H # define PCMK__CRM_PENGINE_RULES__H # include # include # include # include # include -#ifdef __cplusplus -extern "C" { -#endif - -void pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, - const pe_rule_eval_data_t *rule_data, GHashTable *hash, - const char *always_first, gboolean overwrite, - crm_time_t *next_change); - -#ifdef __cplusplus -} -#endif - #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) #include #endif #endif diff --git a/include/crm/pengine/rules_compat.h b/include/crm/pengine/rules_compat.h index cfc619d8da..46644a2ee4 100644 --- a/include/crm/pengine/rules_compat.h +++ b/include/crm/pengine/rules_compat.h @@ -1,47 +1,54 @@ /* * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__CRM_PENGINE_RULES_COMPAT__H # define PCMK__CRM_PENGINE_RULES_COMPAT__H -#include -#include // xmlNode -#include // crm_time_t -#include +#include // gboolean, GHashTable +#include // xmlNode +#include // crm_time_t +#include // enum rsc_role_e +#include // pe_rule_eval_data_t #ifdef __cplusplus extern "C" { #endif /** * \file * \brief Deprecated Pacemaker rule API * \ingroup pengine * \deprecated Do not include this header directly. The rule APIs in this * header, and the header itself, will be removed in a future * release. */ // @COMPAT sbd's configure script checks for this (as of at least 1.5.2) //! \deprecated Use pcmk_evaluate_rule() instead gboolean test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now); //! \deprecated Use pcmk_unpack_nvpair_blocks() instead void pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now, crm_time_t *next_change); +//! \deprecated Use pcmk_unpack_nvpair_blocks() instead +void pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, + const pe_rule_eval_data_t *rule_data, GHashTable *hash, + const char *always_first, gboolean overwrite, + crm_time_t *next_change); + #ifdef __cplusplus } #endif #endif // PCMK__CRM_PENGINE_RULES_COMPAT__H diff --git a/lib/pengine/rules.c b/lib/pengine/rules.c index 86e12a27de..0eac8295af 100644 --- a/lib/pengine/rules.c +++ b/lib/pengine/rules.c @@ -1,137 +1,120 @@ /* * Copyright 2004-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include -#include +#include // NULL +#include // gboolean, GList, GHashTable +#include // xmlNode #include +#include // crm_time_t +#include // enum rsc_role_e + #include -#include +#include // pcmk_rule_input_t, etc. +#include // pcmk__nvpair_unpack_t, etc. -#include -#include -#include -#include -#include -#include +CRM_TRACE_INIT_DATA(pe_rules); -#include -#include +// Deprecated functions kept only for backward API compatibility +// LCOV_EXCL_START -CRM_TRACE_INIT_DATA(pe_rules); +#include + +gboolean +test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now) +{ + pcmk_rule_input_t rule_input = { + .node_attrs = node_hash, + .now = now, + }; + + return pcmk_evaluate_rule(rule, &rule_input, NULL) == pcmk_rc_ok; +} /*! * \internal * \brief Map pe_rule_eval_data_t to pcmk_rule_input_t * * \param[out] new New data struct * \param[in] old Old data struct */ static void map_rule_input(pcmk_rule_input_t *new, const pe_rule_eval_data_t *old) { if (old == NULL) { return; } new->now = old->now; new->node_attrs = old->node_hash; if (old->rsc_data != NULL) { new->rsc_standard = old->rsc_data->standard; new->rsc_provider = old->rsc_data->provider; new->rsc_agent = old->rsc_data->agent; } if (old->match_data != NULL) { new->rsc_params = old->match_data->params; new->rsc_meta = old->match_data->meta; if (old->match_data->re != NULL) { new->rsc_id = old->match_data->re->string; new->rsc_id_submatches = old->match_data->re->pmatch; new->rsc_id_nmatches = old->match_data->re->nregs; } } if (old->op_data != NULL) { new->op_name = old->op_data->op_name; new->op_interval_ms = old->op_data->interval; } } -/*! - * \brief Extract nvpair blocks contained by an XML element into a hash table - * - * \param[in,out] top Ignored - * \param[in] xml_obj XML element containing blocks of nvpair elements - * \param[in] set_name If not NULL, only use blocks of this element - * \param[in] rule_data Matching parameters to use when unpacking - * \param[out] hash Where to store extracted name/value pairs - * \param[in] always_first If not NULL, process block with this ID first - * \param[in] overwrite Whether to replace existing values with same - * name (all internal callers pass \c FALSE) - * \param[out] next_change If not NULL, set to when evaluation will change - */ void pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, const pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *next_change) { GList *pairs = pcmk__xe_dereference_children(xml_obj, set_name); if (pairs) { pcmk__nvpair_unpack_t data = { .values = hash, .first_id = always_first, .overwrite = overwrite, .next_change = next_change, }; map_rule_input(&(data.rule_input), rule_data); pairs = g_list_sort_with_data(pairs, pcmk__cmp_nvpair_blocks, &data); g_list_foreach(pairs, pcmk__unpack_nvpair_block, &data); g_list_free(pairs); } } -// Deprecated functions kept only for backward API compatibility -// LCOV_EXCL_START - -#include - -gboolean -test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now) -{ - pcmk_rule_input_t rule_input = { - .node_attrs = node_hash, - .now = now, - }; - - return pcmk_evaluate_rule(rule, &rule_input, NULL) == pcmk_rc_ok; -} - void pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now, crm_time_t *next_change) { pe_rule_eval_data_t rule_data = { .node_hash = node_hash, .now = now, .match_data = NULL, .rsc_data = NULL, .op_data = NULL }; pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash, always_first, overwrite, next_change); } // LCOV_EXCL_STOP // End deprecated API