This source file includes following definitions.
- crm_itoa
- crm_ftoa
- crm_ttoa
- crm_str_table_new
- crm_strcase_table_new
- pcmk_any_flags_set
- pcmk_all_flags_set
- crm_hash_table_size
- is_not_set
- is_set
- is_set_any
1
2
3
4
5
6
7
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
19
20
21
22
23 # include <sys/types.h>
24 # include <stdlib.h>
25 # include <stdbool.h>
26 # include <stdint.h>
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/results.h>
36
37 # define ONLINESTATUS "online"
38 # define OFFLINESTATUS "offline"
39
40
41 int pcmk_scan_nvpair(const char *input, char **name, char **value);
42 char *pcmk_format_nvpair(const char *name, const char *value, const char *units);
43 char *pcmk_format_named_time(const char *name, time_t epoch_time);
44
45
46 int crm_default_remote_port(void);
47
48
49 char *crm_itoa_stack(int an_int, char *buf, size_t len);
50 gboolean crm_is_true(const char *s);
51 int crm_str_to_boolean(const char *s, int *ret);
52 long long crm_parse_ll(const char *text, const char *default_text);
53 int crm_parse_int(const char *text, const char *default_text);
54 long long crm_get_msec(const char *input);
55 char * crm_strip_trailing_newline(char *str);
56 gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
57 guint crm_strcase_hash(gconstpointer v);
58 guint g_str_hash_traditional(gconstpointer v);
59 char *crm_strdup_printf(char const *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
60 int pcmk_numeric_strcasecmp(const char *s1, const char *s2);
61
62 # define crm_str_hash g_str_hash_traditional
63
64 static inline char *
65 crm_itoa(int an_int)
66 {
67 return crm_strdup_printf("%d", an_int);
68 }
69
70 static inline char *
71 crm_ftoa(double a_float)
72 {
73 return crm_strdup_printf("%f", a_float);
74 }
75
76 static inline char *
77 crm_ttoa(time_t epoch_time)
78 {
79 return crm_strdup_printf("%lld", (long long) epoch_time);
80 }
81
82
83
84
85
86
87
88
89 static inline GHashTable *
90 crm_str_table_new(void)
91 {
92 return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
93 }
94
95
96
97
98
99
100
101
102 static inline GHashTable *
103 crm_strcase_table_new(void)
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
113 void crm_build_path(const char *path_c, mode_t mode);
114
115 guint crm_parse_interval_spec(const char *input);
116 int char2score(const char *score);
117 char *score2char(int score);
118 char *score2char_stack(int score, char *buf, size_t len);
119
120
121 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
122 guint *interval_ms);
123 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
124 int *action_id, int *target_rc);
125 gboolean decode_transition_magic(const char *magic, char **uuid,
126 int *transition_id, int *action_id,
127 int *op_status, int *op_rc, int *target_rc);
128 int rsc_op_expected_rc(lrmd_event_data_t *event);
129 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
130 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
131 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
132 const char *task, const char *interval_spec,
133 const char *timeout);
134 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
135
136
137
138
139 enum pcmk_ra_caps {
140 pcmk_ra_cap_none = 0,
141 pcmk_ra_cap_provider = (1 << 0),
142 pcmk_ra_cap_status = (1 << 1),
143 pcmk_ra_cap_params = (1 << 2),
144 pcmk_ra_cap_unique = (1 << 3),
145 pcmk_ra_cap_promotable = (1 << 4),
146 pcmk_ra_cap_stdin = (1 << 5),
147 pcmk_ra_cap_fence_params = (1 << 6),
148 };
149
150 uint32_t pcmk_get_ra_caps(const char *standard);
151 char *crm_generate_ra_key(const char *standard, const char *provider,
152 const char *type);
153 int crm_parse_agent_spec(const char *spec, char **standard, char **provider,
154 char **type);
155
156
157 int compare_version(const char *version1, const char *version2);
158
159
160 void crm_abort(const char *file, const char *function, int line,
161 const char *condition, gboolean do_core, gboolean do_fork);
162
163
164
165
166
167
168
169
170
171
172 static inline bool
173 pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
174 {
175 return (flag_group & flags_to_check) != 0;
176 }
177
178
179
180
181
182
183
184
185
186
187 static inline bool
188 pcmk_all_flags_set(uint64_t flag_group, uint64_t flags_to_check)
189 {
190 return (flag_group & flags_to_check) == flags_to_check;
191 }
192
193
194
195
196 #define pcmk_is_set(g, f) pcmk_all_flags_set((g), (f))
197
198 static inline guint
199 crm_hash_table_size(GHashTable * hashtable)
200 {
201 if (hashtable == NULL) {
202 return 0;
203 }
204 return g_hash_table_size(hashtable);
205 }
206
207 char *crm_meta_name(const char *field);
208 const char *crm_meta_value(GHashTable * hash, const char *field);
209
210 char *crm_md5sum(const char *buffer);
211
212 char *crm_generate_uuid(void);
213
214
215 bool crm_is_daemon_name(const char *name);
216
217 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
218 int pcmk_daemon_user(uid_t *uid, gid_t *gid);
219
220 #ifdef HAVE_GNUTLS_GNUTLS_H
221 void crm_gnutls_global_init(void);
222 #endif
223
224 char *pcmk_hostname(void);
225
226 bool pcmk_str_is_infinity(const char *s);
227 bool pcmk_str_is_minus_infinity(const char *s);
228
229 #ifndef PCMK__NO_COMPAT
230
231
232
233
234
235 #define crm_get_interval crm_parse_interval_spec
236
237
238 static inline gboolean
239 is_not_set(long long word, long long bit)
240 {
241 return ((word & bit) == 0);
242 }
243
244
245 static inline gboolean
246 is_set(long long word, long long bit)
247 {
248 return ((word & bit) == bit);
249 }
250
251
252 static inline gboolean
253 is_set_any(long long word, long long bit)
254 {
255 return ((word & bit) != 0);
256 }
257
258
259 bool crm_provider_required(const char *standard);
260
261
262 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
263
264
265 gboolean safe_str_neq(const char *a, const char *b);
266
267
268 #define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
269
270 #endif
271
272 #ifdef __cplusplus
273 }
274 #endif
275
276 #endif