root/include/crm/common/util.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. crm_strcase_equal
  2. crm_str_table_new
  3. crm_strcase_table_new
  4. is_not_set
  5. is_set
  6. is_set_any
  7. crm_hash_table_size

   1 /* 
   2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
   3  * 
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU Lesser General Public
   6  * License as published by the Free Software Foundation; either
   7  * version 2 of the License, or (at your option) any later version.
   8  * 
   9  * This software is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12  * General Public License for more details.
  13  * 
  14  * You should have received a copy of the GNU Lesser General Public
  15  * License along with this library; if not, write to the Free Software
  16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17  */
  18 #ifndef CRM_COMMON_UTIL__H
  19 #  define CRM_COMMON_UTIL__H
  20 
  21 /**
  22  * \file
  23  * \brief Utility functions
  24  * \ingroup core
  25  */
  26 
  27 #  include <sys/types.h>
  28 #  include <stdlib.h>
  29 #  include <stdbool.h>
  30 #  include <limits.h>
  31 #  include <signal.h>
  32 #  include <sysexits.h>
  33 #  include <glib.h>
  34 
  35 #  include <libxml/tree.h>
  36 
  37 #  include <crm/lrmd.h>
  38 
  39 #  if SUPPORT_HEARTBEAT
  40 #    include <heartbeat.h>
  41 #  else
  42 #    define     NORMALNODE      "normal"
  43 #    define     ACTIVESTATUS    "active"/* fully functional, and all links are up */
  44 #    define     DEADSTATUS      "dead"
  45                                 /* Status of non-working link or machine */
  46 #    define     PINGSTATUS      "ping"
  47                                 /* Status of a working ping node */
  48 #    define     JOINSTATUS      "join"
  49                                 /* Status when an api client joins */
  50 #    define     LEAVESTATUS     "leave"
  51                                 /* Status when an api client leaves */
  52 #    define     ONLINESTATUS    "online"/* Status of an online client */
  53 #    define     OFFLINESTATUS   "offline"
  54                                         /* Status of an offline client */
  55 #  endif
  56 
  57 /* public Pacemaker Remote functions (from remote.c) */
  58 int crm_default_remote_port(void);
  59 
  60 /* public string functions (from strings.c) */
  61 char *crm_itoa_stack(int an_int, char *buf, size_t len);
  62 char *crm_itoa(int an_int);
  63 gboolean crm_is_true(const char *s);
  64 int crm_str_to_boolean(const char *s, int *ret);
  65 int crm_parse_int(const char *text, const char *default_text);
  66 char * crm_strip_trailing_newline(char *str);
  67 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
  68 gboolean safe_str_neq(const char *a, const char *b);
  69 guint crm_strcase_hash(gconstpointer v);
  70 guint g_str_hash_traditional(gconstpointer v);
  71 
  72 #  define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
  73 #  define crm_str_hash g_str_hash_traditional
  74 
  75 /* used with hash tables where case does not matter */
  76 static inline gboolean
  77 crm_strcase_equal(gconstpointer a, gconstpointer b)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79     return crm_str_eq((const char *) a, (const char *) b, FALSE);
  80 }
  81 
  82 /*!
  83  * \brief Create hash table with dynamically allocated string keys/values
  84  *
  85  * \return Newly hash table
  86  * \note It is the caller's responsibility to free the result, using
  87  *       g_hash_table_destroy().
  88  */
  89 static inline GHashTable *
  90 crm_str_table_new()
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92     return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
  93 }
  94 
  95 /*!
  96  * \brief Create hash table with case-insensitive dynamically allocated string keys/values
  97  *
  98  * \return Newly hash table
  99  * \note It is the caller's responsibility to free the result, using
 100  *       g_hash_table_destroy().
 101  */
 102 static inline GHashTable *
 103 crm_strcase_table_new()
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105     return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal, free, free);
 106 }
 107 
 108 GHashTable *crm_str_table_dup(GHashTable *old_table);
 109 
 110 #  define crm_atoi(text, default_text) crm_parse_int(text, default_text)
 111 
 112 /* public I/O functions (from io.c) */
 113 void crm_build_path(const char *path_c, mode_t mode);
 114 
 115 long long crm_get_msec(const char *input);
 116 unsigned long long crm_get_interval(const char *input);
 117 int char2score(const char *score);
 118 char *score2char(int score);
 119 char *score2char_stack(int score, char *buf, size_t len);
 120 
 121 /* public operation functions (from operations.c) */
 122 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
 123                       int *interval);
 124 gboolean decode_transition_key(const char *key, char **uuid, int *action,
 125                                int *transition_id, int *target_rc);
 126 gboolean decode_transition_magic(const char *magic, char **uuid,
 127                                  int *transition_id, int *action_id,
 128                                  int *op_status, int *op_rc, int *target_rc);
 129 int rsc_op_expected_rc(lrmd_event_data_t *event);
 130 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
 131 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
 132 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
 133                            const char *task, const char *interval,
 134                            const char *timeout);
 135 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
 136 
 137 int compare_version(const char *version1, const char *version2);
 138 
 139 /* coverity[+kill] */
 140 void crm_abort(const char *file, const char *function, int line,
 141                const char *condition, gboolean do_core, gboolean do_fork);
 142 
 143 static inline gboolean
 144 is_not_set(long long word, long long bit)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146     return ((word & bit) == 0);
 147 }
 148 
 149 static inline gboolean
 150 is_set(long long word, long long bit)
     /* [previous][next][first][last][top][bottom][index][help] */
 151 {
 152     return ((word & bit) == bit);
 153 }
 154 
 155 static inline gboolean
 156 is_set_any(long long word, long long bit)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158     return ((word & bit) != 0);
 159 }
 160 
 161 static inline guint
 162 crm_hash_table_size(GHashTable * hashtable)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164     if (hashtable == NULL) {
 165         return 0;
 166     }
 167     return g_hash_table_size(hashtable);
 168 }
 169 
 170 char *crm_meta_name(const char *field);
 171 const char *crm_meta_value(GHashTable * hash, const char *field);
 172 
 173 char *crm_md5sum(const char *buffer);
 174 
 175 char *crm_generate_uuid(void);
 176 bool crm_is_daemon_name(const char *name);
 177 
 178 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
 179 
 180 #ifdef HAVE_GNUTLS_GNUTLS_H
 181 void crm_gnutls_global_init(void);
 182 #endif
 183 
 184 int crm_exit(int rc);
 185 bool pcmk_acl_required(const char *user);
 186 
 187 char *crm_generate_ra_key(const char *class, const char *provider, const char *type);
 188 bool crm_provider_required(const char *standard);
 189 int crm_parse_agent_spec(const char *spec, char **standard, char **provider,
 190                          char **type);
 191 
 192 #endif

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