This source file includes following definitions.
- pcmk__add_idref
- pcmk__free_idref
- pcmk__xe_resolve_idref
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <glib.h>
15 #include <libxml/tree.h>
16
17 #include <crm/crm.h>
18 #include <crm/common/xml.h>
19
20
21
22
23
24
25
26
27
28
29
30
31 void
32 pcmk__add_idref(GHashTable *table, const char *id, const char *referrer)
33 {
34 pcmk__idref_t *idref = NULL;
35
36 pcmk__assert((table != NULL) && (id != NULL) && (referrer != NULL));
37
38 idref = g_hash_table_lookup(table, id);
39 if (idref == NULL) {
40 idref = pcmk__assert_alloc(1, sizeof(pcmk__idref_t));
41 idref->id = pcmk__str_copy(id);
42 g_hash_table_insert(table, pcmk__str_copy(id), idref);
43 }
44 for (GList *iter = idref->refs; iter != NULL; iter = iter->next) {
45 if (pcmk__str_eq(referrer, (const char *) iter->data,
46 pcmk__str_none)) {
47 return;
48 }
49 }
50 idref->refs = g_list_append(idref->refs, pcmk__str_copy(referrer));
51 crm_trace("Added ID %s referrer %s", id, referrer);
52 }
53
54
55
56
57
58
59
60 void
61 pcmk__free_idref(gpointer data)
62 {
63 pcmk__idref_t *idref = data;
64
65 if (idref != NULL) {
66 free(idref->id);
67 g_list_free_full(idref->refs, free);
68 free(idref);
69 }
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84 xmlNode *
85 pcmk__xe_resolve_idref(xmlNode *xml, xmlNode *search)
86 {
87 char *xpath = NULL;
88 const char *ref = NULL;
89 xmlNode *result = NULL;
90
91 if (xml == NULL) {
92 return NULL;
93 }
94
95 ref = crm_element_value(xml, PCMK_XA_ID_REF);
96 if (ref == NULL) {
97 return xml;
98 }
99
100 if (search == NULL) {
101 search = xml;
102 }
103
104 xpath = crm_strdup_printf("//%s[@" PCMK_XA_ID "='%s']", xml->name, ref);
105 result = get_xpath_object(xpath, search, LOG_DEBUG);
106 if (result == NULL) {
107
108 pcmk__config_err("Ignoring invalid %s configuration: "
109 PCMK_XA_ID_REF " '%s' does not reference "
110 "a valid object " QB_XS " xpath=%s",
111 xml->name, ref, xpath);
112 }
113 free(xpath);
114 return result;
115 }