summaryrefslogtreecommitdiffstats
path: root/include/crm/common/history_internal.h
blob: c74ef296c858fae7ef052adb97d684cb4c66eb97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2004-2024 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU Lesser General Public License
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
 */

#ifndef PCMK__CRM_COMMON_HISTORY_INTERNAL__H
#define PCMK__CRM_COMMON_HISTORY_INTERNAL__H

#include <stdio.h>                  // NULL
#include <libxml/tree.h>            // xmlNode

#include <crm/common/xml.h>         // crm_element_value()
#include <crm/common/internal.h>    // pcmk__str_empty()
#include <crm/common/xml_names_internal.h>  // PCMK__XA_OPERATION_KEY

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * \internal
 * \brief Get the operation key from an action history entry
 *
 * \param[in] xml  Action history entry
 *
 * \return Entry's operation key
 */
static inline const char *
pcmk__xe_history_key(const xmlNode *xml)
{
    if (xml == NULL) {
        return NULL;
    } else {
        /* @COMPAT Pacemaker <= 1.1.5 did not add the key, and used the ID
         * instead. Checking for that allows us to process old saved CIBs,
         * including some regression tests.
         */
        const char *key = crm_element_value(xml, PCMK__XA_OPERATION_KEY);

        return pcmk__str_empty(key)? pcmk__xe_id(xml) : key;
    }
}

#ifdef __cplusplus
}
#endif

#endif // PCMK__CRM_COMMON_HISTORY_INTERNAL__H