1 /*
2 * Copyright 2024-2025 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10 #include <crm_internal.h>
11
12 #include <stdio.h> // NULL
13 #include <glib.h> // GHashTable, etc.
14
15 #include "pacemaker-attrd.h"
16
17 // Track the last known node XML ID for each node name
18 static GHashTable *node_xml_ids = NULL;
19
20 /*!
21 * \internal
22 * \brief Get last known XML ID for a given node
23 *
24 * \param[in] node_name Name of node to check
25 *
26 * \return Last known XML ID for node (or NULL if none known)
27 *
28 * \note The return value may become invalid if attrd_set_node_xml_id() or
29 * attrd_forget_node_xml_id() is later called for \p node_name.
30 */
31 const char *
32 attrd_get_node_xml_id(const char *node_name)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
33 {
34 if (node_xml_ids == NULL) {
35 return NULL;
36 }
37 return g_hash_table_lookup(node_xml_ids, node_name);
38 }
39
40 /*!
41 * \internal
42 * \brief Set last known XML ID for a given node
43 *
44 * \param[in] node_name Name of node to set
45 * \param[in] node_xml_id New XML ID to set for node
46 */
47 void
48 attrd_set_node_xml_id(const char *node_name, const char *node_xml_id)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
49 {
50 if (node_xml_ids == NULL) {
51 node_xml_ids = pcmk__strikey_table(free, free);
52 }
53 pcmk__insert_dup(node_xml_ids, node_name, node_xml_id);
54 }
55
56 /*!
57 * \internal
58 * \brief Forget last known XML ID for a given node
59 *
60 * \param[in] node_name Name of node to forget
61 */
62 void
63 attrd_forget_node_xml_id(const char *node_name)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
64 {
65 if (node_xml_ids == NULL) {
66 return;
67 }
68 g_hash_table_remove(node_xml_ids, node_name);
69 }
70
71 /*!
72 * \internal
73 * \brief Free the node XML ID cache
74 */
75 void
76 attrd_cleanup_xml_ids(void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
77 {
78 if (node_xml_ids != NULL) {
79 g_hash_table_destroy(node_xml_ids);
80 node_xml_ids = NULL;
81 }
82 }