1 /*
2 * Copyright 2004-2024 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 Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10 #ifndef PCMK__CRM_COMMON_HISTORY_INTERNAL__H
11 #define PCMK__CRM_COMMON_HISTORY_INTERNAL__H
12
13 #include <stdio.h> // NULL
14 #include <libxml/tree.h> // xmlNode
15
16 #include <crm/common/xml.h> // crm_element_value()
17 #include <crm/common/internal.h> // pcmk__str_empty()
18 #include <crm/common/xml_element_internal.h> // pcmk__xe_id()
19 #include <crm/common/xml_names_internal.h> // PCMK__XA_OPERATION_KEY
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*!
26 * \internal
27 * \brief Get the operation key from an action history entry
28 *
29 * \param[in] xml Action history entry
30 *
31 * \return Entry's operation key
32 */
33 static inline const char *
34 pcmk__xe_history_key(const xmlNode *xml)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
35 {
36 if (xml == NULL) {
37 return NULL;
38 } else {
39 /* @COMPAT Pacemaker <= 1.1.5 did not add the key, and used the ID
40 * instead. Checking for that allows us to process old saved CIBs,
41 * including some regression tests.
42 */
43 const char *key = crm_element_value(xml, PCMK__XA_OPERATION_KEY);
44
45 return pcmk__str_empty(key)? pcmk__xe_id(xml) : key;
46 }
47 }
48
49 #ifdef __cplusplus
50 }
51 #endif
52
53 #endif // PCMK__CRM_COMMON_HISTORY_INTERNAL__H