1    	/*
2    	 * Copyright 2024-2026 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)
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)
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)
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)
77   	{
CID (unavailable; MK=f0955d1cbc55815c537df35de54eb639) (#1 of 1): Inconsistent C union access (INCONSISTENT_UNION_ACCESS):
(1) Event assign_union_field: The union field "in" of "_pp" is written.
(2) Event inconsistent_union_field_access: In "_pp.out", the union field used: "out" is inconsistent with the field most recently stored: "in".
78   	    g_clear_pointer(&node_xml_ids, g_hash_table_destroy);
79   	}
80