root/include/crm/common/util.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pcmk_any_flags_set
  2. pcmk_all_flags_set

   1 /*
   2  * Copyright 2004-2021 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 CRM_COMMON_UTIL__H
  11 #  define CRM_COMMON_UTIL__H
  12 
  13 #ifdef __cplusplus
  14 extern "C" {
  15 #endif
  16 
  17 /**
  18  * \file
  19  * \brief Utility functions
  20  * \ingroup core
  21  */
  22 
  23 #  include <sys/types.h>    // gid_t, mode_t, size_t, time_t, uid_t
  24 #  include <stdlib.h>
  25 #  include <stdbool.h>
  26 #  include <stdint.h>       // uint32_t
  27 #  include <limits.h>
  28 #  include <signal.h>
  29 #  include <glib.h>
  30 
  31 #  include <libxml/tree.h>
  32 
  33 #  include <crm/lrmd.h>
  34 #  include <crm/common/acl.h>
  35 #  include <crm/common/agents.h>
  36 #  include <crm/common/results.h>
  37 
  38 #  define ONLINESTATUS  "online"  // Status of an online client
  39 #  define OFFLINESTATUS "offline" // Status of an offline client
  40 
  41 /* public node attribute functions (from attrd_client.c) */
  42 char *pcmk_promotion_score_name(const char *rsc_id);
  43 
  44 /* public Pacemaker Remote functions (from remote.c) */
  45 int crm_default_remote_port(void);
  46 
  47 /* public string functions (from strings.c) */
  48 gboolean crm_is_true(const char *s);
  49 int crm_str_to_boolean(const char *s, int *ret);
  50 long long crm_get_msec(const char *input);
  51 char * crm_strip_trailing_newline(char *str);
  52 char *crm_strdup_printf(char const *format, ...) G_GNUC_PRINTF(1, 2);
  53 
  54 guint crm_parse_interval_spec(const char *input);
  55 int char2score(const char *score);
  56 char *score2char(int score);
  57 char *score2char_stack(int score, char *buf, size_t len);
  58 
  59 /* public operation functions (from operations.c) */
  60 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
  61                       guint *interval_ms);
  62 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
  63                                int *action_id, int *target_rc);
  64 gboolean decode_transition_magic(const char *magic, char **uuid,
  65                                  int *transition_id, int *action_id,
  66                                  int *op_status, int *op_rc, int *target_rc);
  67 int rsc_op_expected_rc(lrmd_event_data_t *event);
  68 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
  69 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
  70 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
  71                            const char *task, const char *interval_spec,
  72                            const char *timeout);
  73 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
  74 
  75 int compare_version(const char *version1, const char *version2);
  76 
  77 /* coverity[+kill] */
  78 void crm_abort(const char *file, const char *function, int line,
  79                const char *condition, gboolean do_core, gboolean do_fork);
  80 
  81 /*!
  82  * \brief Check whether any of specified flags are set in a flag group
  83  *
  84  * \param[in] flag_group        The flag group being examined
  85  * \param[in] flags_to_check    Which flags in flag_group should be checked
  86  *
  87  * \return true if \p flags_to_check is nonzero and any of its flags are set in
  88  *         \p flag_group, or false otherwise
  89  */
  90 static inline bool
  91 pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93     return (flag_group & flags_to_check) != 0;
  94 }
  95 
  96 /*!
  97  * \brief Check whether all of specified flags are set in a flag group
  98  *
  99  * \param[in] flag_group        The flag group being examined
 100  * \param[in] flags_to_check    Which flags in flag_group should be checked
 101  *
 102  * \return true if \p flags_to_check is zero or all of its flags are set in
 103  *         \p flag_group, or false otherwise
 104  */
 105 static inline bool
 106 pcmk_all_flags_set(uint64_t flag_group, uint64_t flags_to_check)
     /* [previous][next][first][last][top][bottom][index][help] */
 107 {
 108     return (flag_group & flags_to_check) == flags_to_check;
 109 }
 110 
 111 /*!
 112  * \brief Convenience alias for pcmk_all_flags_set(), to check single flag
 113  */
 114 #define pcmk_is_set(g, f)   pcmk_all_flags_set((g), (f))
 115 
 116 char *crm_meta_name(const char *field);
 117 const char *crm_meta_value(GHashTable * hash, const char *field);
 118 
 119 char *crm_md5sum(const char *buffer);
 120 
 121 char *crm_generate_uuid(void);
 122 
 123 // This belongs in ipc.h but is here for backward compatibility
 124 bool crm_is_daemon_name(const char *name);
 125 
 126 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
 127 int pcmk_daemon_user(uid_t *uid, gid_t *gid);
 128 
 129 #ifdef HAVE_GNUTLS_GNUTLS_H
 130 void crm_gnutls_global_init(void);
 131 #endif
 132 
 133 char *pcmk_hostname(void);
 134 
 135 bool pcmk_str_is_infinity(const char *s);
 136 bool pcmk_str_is_minus_infinity(const char *s);
 137 
 138 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
 139 #include <crm/common/util_compat.h>
 140 #endif
 141 
 142 #ifdef __cplusplus
 143 }
 144 #endif
 145 
 146 #endif

/* [previous][next][first][last][top][bottom][index][help] */