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_names_internal.h> // PCMK__XA_OPERATION_KEY
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /*!
25 * \internal
26 * \brief Get the operation key from an action history entry
27 *
28 * \param[in] xml Action history entry
29 *
30 * \return Entry's operation key
31 */
32 static inline const char *
33 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)
*/
34 {
35 if (xml == NULL) {
36 return NULL;
37 } else {
38 /* @COMPAT Pacemaker <= 1.1.5 did not add the key, and used the ID
39 * instead. Checking for that allows us to process old saved CIBs,
40 * including some regression tests.
41 */
42 const char *key = crm_element_value(xml, PCMK__XA_OPERATION_KEY);
43
44 return pcmk__str_empty(key)? pcmk__xe_id(xml) : key;
45 }
46 }
47
48 #ifdef __cplusplus
49 }
50 #endif
51
52 #endif // PCMK__CRM_COMMON_HISTORY_INTERNAL__H