corosync  3.0.3
icmap.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Jan Friesse (jfriesse@redhat.com)
7  *
8  * This software licensed under BSD license, the text of which follows:
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * - Neither the name of the Red Hat, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <config.h>
36 
37 #include <string.h>
38 #include <stdio.h>
39 
40 #include <corosync/corotypes.h>
41 
42 #include <qb/qbdefs.h>
43 #include <qb/qblist.h>
44 #include <corosync/icmap.h>
45 
46 #define ICMAP_MAX_VALUE_LEN (16*1024)
47 
48 struct icmap_item {
49  char *key_name;
51  size_t value_len;
52  char value[];
53 };
54 
55 struct icmap_map {
56  qb_map_t *qb_map;
57 };
58 
59 static icmap_map_t icmap_global_map;
60 
61 struct icmap_track {
62  char *key_name;
63  int32_t track_type;
65  void *user_data;
66  struct qb_list_head list;
67 };
68 
70  char *key_name;
71  int prefix;
72  struct qb_list_head list;
73 };
74 
75 QB_LIST_DECLARE (icmap_ro_access_item_list_head);
76 QB_LIST_DECLARE (icmap_track_list_head);
77 
78 /*
79  * Static functions declarations
80  */
81 
82 /*
83  * Check if key_name is valid icmap key name. Returns 0 on success, and -1 on fail
84  */
85 static int icmap_check_key_name(const char *key_name);
86 
87 /*
88  * Check that value with given type has correct length value_len. Returns 0 on success,
89  * and -1 on fail
90  */
91 static int icmap_check_value_len(const void *value, size_t value_len, icmap_value_types_t type);
92 
93 /*
94  * Checks if item has same value as value with value_len and given type. Returns 0 if not, otherwise !0.
95  */
96 static int icmap_item_eq(const struct icmap_item *item, const void *value, size_t value_len, icmap_value_types_t type);
97 
98 /*
99  * Checks if given character is valid in key name. Returns 0 if not, otherwise !0.
100  */
101 static int icmap_is_valid_name_char(char c);
102 
103 /*
104  * Helper for getting integer and float value with given type for key key_name and store it in value.
105  */
106 static cs_error_t icmap_get_int_r(
107  const icmap_map_t map,
108  const char *key_name,
109  void *value,
111 
112 /*
113  * Return raw item value data. Internal function used by icmap_get_r which does most
114  * of arguments validity checks but doesn't copy data (it returns raw item data
115  * pointer). It's not very safe tho it's static.
116  */
117 static cs_error_t icmap_get_ref_r(
118  const icmap_map_t map,
119  const char *key_name,
120  void **value,
121  size_t *value_len,
123 
124 /*
125  * Function implementation
126  */
127 int32_t icmap_tt_to_qbtt(int32_t track_type)
128 {
129  int32_t res = 0;
130 
131  if (track_type & ICMAP_TRACK_DELETE) {
132  res |= QB_MAP_NOTIFY_DELETED;
133  }
134 
135  if (track_type & ICMAP_TRACK_MODIFY) {
136  res |= QB_MAP_NOTIFY_REPLACED;
137  }
138 
139  if (track_type & ICMAP_TRACK_ADD) {
140  res |= QB_MAP_NOTIFY_INSERTED;
141  }
142 
143  if (track_type & ICMAP_TRACK_PREFIX) {
144  res |= QB_MAP_NOTIFY_RECURSIVE;
145  }
146 
147  return (res);
148 }
149 
150 int32_t icmap_qbtt_to_tt(int32_t track_type)
151 {
152  int32_t res = 0;
153 
154  if (track_type & QB_MAP_NOTIFY_DELETED) {
155  res |= ICMAP_TRACK_DELETE;
156  }
157 
158  if (track_type & QB_MAP_NOTIFY_REPLACED) {
159  res |= ICMAP_TRACK_MODIFY;
160  }
161 
162  if (track_type & QB_MAP_NOTIFY_INSERTED) {
163  res |= ICMAP_TRACK_ADD;
164  }
165 
166  if (track_type & QB_MAP_NOTIFY_RECURSIVE) {
167  res |= ICMAP_TRACK_PREFIX;
168  }
169 
170  return (res);
171 }
172 
173 static void icmap_map_free_cb(uint32_t event,
174  char* key, void* old_value,
175  void* value, void* user_data)
176 {
177  struct icmap_item *item = (struct icmap_item *)old_value;
178 
179  /*
180  * value == old_value -> fast_adjust_int was used, don't free data
181  */
182  if (item != NULL && value != old_value) {
183  free(item->key_name);
184  free(item);
185  }
186 }
187 
189 {
190  int32_t err;
191 
192  *result = malloc(sizeof(struct icmap_map));
193  if (*result == NULL) {
194  return (CS_ERR_NO_MEMORY);
195  }
196 
197  (*result)->qb_map = qb_trie_create();
198  if ((*result)->qb_map == NULL)
199  return (CS_ERR_INIT);
200 
201  err = qb_map_notify_add((*result)->qb_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
202 
203  return (qb_to_cs_error(err));
204 }
205 
207 {
208  return (icmap_init_r(&icmap_global_map));
209 }
210 
211 static void icmap_set_ro_access_free(void)
212 {
213  struct qb_list_head *iter, *tmp_iter;
214  struct icmap_ro_access_item *icmap_ro_ai;
215 
216  qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
217  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
218  qb_list_del(&icmap_ro_ai->list);
219  free(icmap_ro_ai->key_name);
220  free(icmap_ro_ai);
221  }
222 }
223 
224 static void icmap_del_all_track(void)
225 {
226  struct qb_list_head *iter, *tmp_iter;
227  struct icmap_track *icmap_track;
228 
229  qb_list_for_each_safe(iter, tmp_iter, &icmap_track_list_head) {
230  icmap_track = qb_list_entry(iter, struct icmap_track, list);
231 
233  }
234 }
235 
236 void icmap_fini_r(const icmap_map_t map)
237 {
238 
239  qb_map_destroy(map->qb_map);
240  free(map);
241 
242  return;
243 }
244 
245 void icmap_fini(void)
246 {
247 
248  icmap_del_all_track();
249  /*
250  * catch 22 warning:
251  * We need to drop this notify but we can't because it calls icmap_map_free_cb
252  * while destroying the tree to free icmap_item(s).
253  * -> qb_map_notify_del_2(icmap_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
254  * and we cannot call it after map_destroy. joy! :)
255  */
256  icmap_fini_r(icmap_global_map);
257  icmap_set_ro_access_free();
258 
259  return ;
260 }
261 
263 {
264 
265  return (icmap_global_map);
266 }
267 
268 static int icmap_is_valid_name_char(char c)
269 {
270  return ((c >= 'a' && c <= 'z') ||
271  (c >= 'A' && c <= 'Z') ||
272  (c >= '0' && c <= '9') ||
273  c == '.' || c == '_' || c == '-' || c == '/' || c == ':');
274 }
275 
277 {
278  int i;
279 
280  for (i = 0; i < strlen(key_name); i++) {
281  if (!icmap_is_valid_name_char(key_name[i])) {
282  key_name[i] = '_';
283  }
284  }
285 }
286 
287 static int icmap_check_key_name(const char *key_name)
288 {
289  int i;
290 
291  if ((strlen(key_name) < ICMAP_KEYNAME_MINLEN) || strlen(key_name) > ICMAP_KEYNAME_MAXLEN) {
292  return (-1);
293  }
294 
295  for (i = 0; i < strlen(key_name); i++) {
296  if (!icmap_is_valid_name_char(key_name[i])) {
297  return (-1);
298  }
299  }
300 
301  return (0);
302 }
303 
305 {
306  size_t res = 0;
307 
308  switch (type) {
309  case ICMAP_VALUETYPE_INT8: res = sizeof(int8_t); break;
310  case ICMAP_VALUETYPE_UINT8: res = sizeof(uint8_t); break;
311  case ICMAP_VALUETYPE_INT16: res = sizeof(int16_t); break;
312  case ICMAP_VALUETYPE_UINT16: res = sizeof(uint16_t); break;
313  case ICMAP_VALUETYPE_INT32: res = sizeof(int32_t); break;
314  case ICMAP_VALUETYPE_UINT32: res = sizeof(uint32_t); break;
315  case ICMAP_VALUETYPE_INT64: res = sizeof(int64_t); break;
316  case ICMAP_VALUETYPE_UINT64: res = sizeof(uint64_t); break;
317  case ICMAP_VALUETYPE_FLOAT: res = sizeof(float); break;
318  case ICMAP_VALUETYPE_DOUBLE: res = sizeof(double); break;
321  res = 0;
322  break;
323  }
324 
325  return (res);
326 }
327 
328 static int icmap_check_value_len(const void *value, size_t value_len, icmap_value_types_t type)
329 {
330 
331  if (value_len > ICMAP_MAX_VALUE_LEN) {
332  return (-1);
333  }
334 
336  if (icmap_get_valuetype_len(type) == value_len) {
337  return (0);
338  } else {
339  return (-1);
340  }
341  }
342 
343  if (type == ICMAP_VALUETYPE_STRING) {
344  /*
345  * value_len can be shorter then real string length, but never
346  * longer (+ 1 is because of 0 at the end of string)
347  */
348  if (value_len > strlen((const char *)value) + 1) {
349  return (-1);
350  } else {
351  return (0);
352  }
353  }
354 
355  return (0);
356 }
357 
358 static int icmap_item_eq(const struct icmap_item *item, const void *value, size_t value_len, icmap_value_types_t type)
359 {
360  size_t ptr_len;
361 
362  if (item->type != type) {
363  return (0);
364  }
365 
366  if (item->type == ICMAP_VALUETYPE_STRING) {
367  ptr_len = strlen((const char *)value);
368  if (ptr_len > value_len) {
369  ptr_len = value_len;
370  }
371  ptr_len++;
372  } else {
373  ptr_len = value_len;
374  }
375 
376  if (item->value_len == ptr_len) {
377  return (memcmp(item->value, value, value_len) == 0);
378  };
379 
380  return (0);
381 }
382 
384  const icmap_map_t map1,
385  const char *key_name1,
386  const icmap_map_t map2,
387  const char *key_name2)
388 {
389  struct icmap_item *item1, *item2;
390 
391  if (map1 == NULL || key_name1 == NULL || map2 == NULL || key_name2 == NULL) {
392  return (0);
393  }
394 
395  item1 = qb_map_get(map1->qb_map, key_name1);
396  item2 = qb_map_get(map2->qb_map, key_name2);
397 
398  if (item1 == NULL || item2 == NULL) {
399  return (0);
400  }
401 
402  return (icmap_item_eq(item1, item2->value, item2->value_len, item2->type));
403 }
404 
406  const icmap_map_t map,
407  const char *key_name,
408  const void *value,
409  size_t value_len,
411 {
412  struct icmap_item *item;
413  struct icmap_item *new_item;
414  size_t new_value_len;
415  size_t new_item_size;
416 
417  if (value == NULL || key_name == NULL) {
418  return (CS_ERR_INVALID_PARAM);
419  }
420 
421  if (icmap_check_value_len(value, value_len, type) != 0) {
422  return (CS_ERR_INVALID_PARAM);
423  }
424 
425  item = qb_map_get(map->qb_map, key_name);
426  if (item != NULL) {
427  /*
428  * Check that key is really changed
429  */
430  if (icmap_item_eq(item, value, value_len, type)) {
431  return (CS_OK);
432  }
433  } else {
434  if (icmap_check_key_name(key_name) != 0) {
435  return (CS_ERR_NAME_TOO_LONG);
436  }
437  }
438 
440  if (type == ICMAP_VALUETYPE_STRING) {
441  new_value_len = strlen((const char *)value);
442  if (new_value_len > value_len) {
443  new_value_len = value_len;
444  }
445  new_value_len++;
446  } else {
447  new_value_len = value_len;
448  }
449  } else {
450  new_value_len = icmap_get_valuetype_len(type);
451  }
452 
453  new_item_size = sizeof(struct icmap_item) + new_value_len;
454  new_item = malloc(new_item_size);
455  if (new_item == NULL) {
456  return (CS_ERR_NO_MEMORY);
457  }
458  memset(new_item, 0, new_item_size);
459 
460  if (item == NULL) {
461  new_item->key_name = strdup(key_name);
462  if (new_item->key_name == NULL) {
463  free(new_item);
464  return (CS_ERR_NO_MEMORY);
465  }
466  } else {
467  new_item->key_name = item->key_name;
468  item->key_name = NULL;
469  }
470 
471  new_item->type = type;
472  new_item->value_len = new_value_len;
473 
474  memcpy(new_item->value, value, new_value_len);
475 
476  if (new_item->type == ICMAP_VALUETYPE_STRING) {
477  ((char *)new_item->value)[new_value_len - 1] = 0;
478  }
479 
480  qb_map_put(map->qb_map, new_item->key_name, new_item);
481 
482  return (CS_OK);
483 }
484 
486  const char *key_name,
487  const void *value,
488  size_t value_len,
490 {
491 
492  return (icmap_set_r(icmap_global_map, key_name, value, value_len, type));
493 }
494 
495 cs_error_t icmap_set_int8_r(const icmap_map_t map, const char *key_name, int8_t value)
496 {
497 
498  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT8));
499 }
500 
501 cs_error_t icmap_set_uint8_r(const icmap_map_t map, const char *key_name, uint8_t value)
502 {
503 
504  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT8));
505 }
506 
507 cs_error_t icmap_set_int16_r(const icmap_map_t map, const char *key_name, int16_t value)
508 {
509 
510  return (icmap_set_r(map,key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT16));
511 }
512 
513 cs_error_t icmap_set_uint16_r(const icmap_map_t map, const char *key_name, uint16_t value)
514 {
515 
516  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT16));
517 }
518 
519 cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
520 {
521 
522  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT32));
523 }
524 
525 cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
526 {
527 
528  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT32));
529 }
530 
531 cs_error_t icmap_set_int64_r(const icmap_map_t map, const char *key_name, int64_t value)
532 {
533 
534  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT64));
535 }
536 
537 cs_error_t icmap_set_uint64_r(const icmap_map_t map, const char *key_name, uint64_t value)
538 {
539 
540  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT64));
541 }
542 
543 cs_error_t icmap_set_float_r(const icmap_map_t map, const char *key_name, float value)
544 {
545 
546  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_FLOAT));
547 }
548 
549 cs_error_t icmap_set_double_r(const icmap_map_t map, const char *key_name, double value)
550 {
551 
552  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_DOUBLE));
553 }
554 
555 cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
556 {
557 
558  if (value == NULL) {
559  return (CS_ERR_INVALID_PARAM);
560  }
561 
562  return (icmap_set_r(map, key_name, value, strlen(value), ICMAP_VALUETYPE_STRING));
563 }
564 
566 {
567 
568  return (icmap_set_int8_r(icmap_global_map, key_name, value));
569 }
570 
572 {
573 
574  return (icmap_set_uint8_r(icmap_global_map, key_name, value));
575 }
576 
578 {
579 
580  return (icmap_set_int16_r(icmap_global_map, key_name, value));
581 }
582 
584 {
585 
586  return (icmap_set_uint16_r(icmap_global_map, key_name, value));
587 }
588 
590 {
591 
592  return (icmap_set_int32_r(icmap_global_map, key_name, value));
593 }
594 
596 {
597 
598  return (icmap_set_uint32_r(icmap_global_map, key_name, value));
599 }
600 
602 {
603 
604  return (icmap_set_int64_r(icmap_global_map, key_name, value));
605 }
606 
608 {
609 
610  return (icmap_set_uint64_r(icmap_global_map, key_name, value));
611 }
612 
614 {
615 
616  return (icmap_set_float_r(icmap_global_map, key_name, value));
617 }
618 
620 {
621 
622  return (icmap_set_double_r(icmap_global_map, key_name, value));
623 }
624 
625 cs_error_t icmap_set_string(const char *key_name, const char *value)
626 {
627 
628  return (icmap_set_string_r(icmap_global_map, key_name, value));
629 }
630 
632 {
633  struct icmap_item *item;
634 
635  if (key_name == NULL) {
636  return (CS_ERR_INVALID_PARAM);
637  }
638 
639  item = qb_map_get(map->qb_map, key_name);
640  if (item == NULL) {
641  return (CS_ERR_NOT_EXIST);
642  }
643 
644  if (qb_map_rm(map->qb_map, item->key_name) != QB_TRUE) {
645  return (CS_ERR_NOT_EXIST);
646  }
647 
648  return (CS_OK);
649 }
650 
652 {
653 
654  return (icmap_delete_r(icmap_global_map, key_name));
655 }
656 
657 static cs_error_t icmap_get_ref_r(
658  const icmap_map_t map,
659  const char *key_name,
660  void **value,
661  size_t *value_len,
663 {
664  struct icmap_item *item;
665 
666  if (key_name == NULL) {
667  return (CS_ERR_INVALID_PARAM);
668  }
669 
670  item = qb_map_get(map->qb_map, key_name);
671  if (item == NULL) {
672  return (CS_ERR_NOT_EXIST);
673  }
674 
675  if (type != NULL) {
676  *type = item->type;
677  }
678 
679  if (value_len != NULL) {
680  *value_len = item->value_len;
681  }
682 
683  if (value != NULL) {
684  *value = item->value;
685  }
686 
687  return (CS_OK);
688 }
689 
691  const icmap_map_t map,
692  const char *key_name,
693  void *value,
694  size_t *value_len,
696 {
697  cs_error_t res;
698  void *tmp_value;
699  size_t tmp_value_len;
700 
701  res = icmap_get_ref_r(map, key_name, &tmp_value, &tmp_value_len, type);
702  if (res != CS_OK) {
703  return (res);
704  }
705 
706  if (value == NULL) {
707  if (value_len != NULL) {
708  *value_len = tmp_value_len;
709  }
710  } else {
711  if (value_len == NULL || *value_len < tmp_value_len) {
712  return (CS_ERR_INVALID_PARAM);
713  }
714 
715  *value_len = tmp_value_len;
716 
717  memcpy(value, tmp_value, tmp_value_len);
718  }
719 
720  return (CS_OK);
721 }
722 
724  const char *key_name,
725  void *value,
726  size_t *value_len,
728 {
729 
730  return (icmap_get_r(icmap_global_map, key_name, value, value_len, type));
731 }
732 
733 cs_error_t icmap_get_string_r(icmap_map_t map, const char *key_name, char **str)
734 {
735  cs_error_t res;
736  size_t str_len;
738 
739  res = icmap_get_r(map, key_name, NULL, &str_len, &type);
740  if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) {
741  if (res == CS_OK) {
742  res = CS_ERR_INVALID_PARAM;
743  }
744 
745  goto return_error;
746  }
747 
748  *str = malloc(str_len);
749  if (*str == NULL) {
750  res = CS_ERR_NO_MEMORY;
751 
752  goto return_error;
753  }
754 
755  res = icmap_get_r(map, key_name, *str, &str_len, &type);
756  if (res != CS_OK) {
757  free(*str);
758  goto return_error;
759  }
760 
761  return (CS_OK);
762 
763 return_error:
764  return (res);
765 }
766 
767 static cs_error_t icmap_get_int_r(
768  const icmap_map_t map,
769  const char *key_name,
770  void *value,
772 {
773  char key_value[16];
774  size_t key_size;
775  cs_error_t err;
776  icmap_value_types_t key_type;
777 
778  key_size = sizeof(key_value);
779  memset(key_value, 0, key_size);
780 
781  err = icmap_get_r(map, key_name, key_value, &key_size, &key_type);
782  if (err != CS_OK)
783  return (err);
784 
785  if (key_type != type) {
786  return (CS_ERR_INVALID_PARAM);
787  }
788 
789  memcpy(value, key_value, icmap_get_valuetype_len(key_type));
790 
791  return (CS_OK);
792 }
793 
794 cs_error_t icmap_get_int8_r(const icmap_map_t map, const char *key_name, int8_t *i8)
795 {
796 
797  return (icmap_get_int_r(map, key_name, i8, ICMAP_VALUETYPE_INT8));
798 }
799 
800 cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
801 {
802 
803  return (icmap_get_int_r(map, key_name, u8, ICMAP_VALUETYPE_UINT8));
804 }
805 
806 cs_error_t icmap_get_int16_r(const icmap_map_t map, const char *key_name, int16_t *i16)
807 {
808 
809  return (icmap_get_int_r(map, key_name, i16, ICMAP_VALUETYPE_INT16));
810 }
811 
812 cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
813 {
814 
815  return (icmap_get_int_r(map, key_name, u16, ICMAP_VALUETYPE_UINT16));
816 }
817 
818 cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
819 {
820 
821  return (icmap_get_int_r(map, key_name, i32, ICMAP_VALUETYPE_INT32));
822 }
823 
824 cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
825 {
826 
827  return (icmap_get_int_r(map, key_name, u32, ICMAP_VALUETYPE_UINT32));
828 }
829 
830 cs_error_t icmap_get_int64_r(const icmap_map_t map, const char *key_name, int64_t *i64)
831 {
832 
833  return(icmap_get_int_r(map, key_name, i64, ICMAP_VALUETYPE_INT64));
834 }
835 
836 cs_error_t icmap_get_uint64_r(const icmap_map_t map, const char *key_name, uint64_t *u64)
837 {
838 
839  return (icmap_get_int_r(map, key_name, u64, ICMAP_VALUETYPE_UINT64));
840 }
841 
842 cs_error_t icmap_get_float_r(const icmap_map_t map, const char *key_name, float *flt)
843 {
844 
845  return (icmap_get_int_r(map, key_name, flt, ICMAP_VALUETYPE_FLOAT));
846 }
847 
848 cs_error_t icmap_get_double_r(const icmap_map_t map, const char *key_name, double *dbl)
849 {
850 
851  return (icmap_get_int_r(map, key_name, dbl, ICMAP_VALUETYPE_DOUBLE));
852 }
853 
854 cs_error_t icmap_get_string(const char *key_name, char **str)
855 {
856 
857  return (icmap_get_string_r(icmap_global_map, key_name, str));
858 }
859 
860 cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
861 {
862 
863  return (icmap_get_int8_r(icmap_global_map, key_name, i8));
864 }
865 
866 cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
867 {
868 
869  return (icmap_get_uint8_r(icmap_global_map, key_name, u8));
870 }
871 
872 cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
873 {
874 
875  return (icmap_get_int16_r(icmap_global_map, key_name, i16));
876 }
877 
878 cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
879 {
880 
881  return (icmap_get_uint16_r(icmap_global_map, key_name, u16));
882 }
883 
884 cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
885 {
886 
887  return (icmap_get_int32_r(icmap_global_map, key_name, i32));
888 }
889 
890 cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
891 {
892 
893  return (icmap_get_uint32_r(icmap_global_map, key_name, u32));
894 }
895 
896 cs_error_t icmap_get_int64(const char *key_name, int64_t *i64)
897 {
898 
899  return(icmap_get_int64_r(icmap_global_map, key_name, i64));
900 }
901 
902 cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
903 {
904 
905  return (icmap_get_uint64_r(icmap_global_map, key_name, u64));
906 }
907 
908 cs_error_t icmap_get_float(const char *key_name, float *flt)
909 {
910 
911  return (icmap_get_float_r(icmap_global_map, key_name, flt));
912 }
913 
914 cs_error_t icmap_get_double(const char *key_name, double *dbl)
915 {
916 
917  return (icmap_get_double_r(icmap_global_map, key_name, dbl));
918 }
919 
921  const icmap_map_t map,
922  const char *key_name,
923  int32_t step)
924 {
925  struct icmap_item *item;
926  uint8_t u8;
927  uint16_t u16;
928  uint32_t u32;
929  uint64_t u64;
930  cs_error_t err = CS_OK;
931 
932  if (key_name == NULL) {
933  return (CS_ERR_INVALID_PARAM);
934  }
935 
936  item = qb_map_get(map->qb_map, key_name);
937  if (item == NULL) {
938  return (CS_ERR_NOT_EXIST);
939  }
940 
941  switch (item->type) {
944  memcpy(&u8, item->value, sizeof(u8));
945  u8 += step;
946  err = icmap_set(key_name, &u8, sizeof(u8), item->type);
947  break;
950  memcpy(&u16, item->value, sizeof(u16));
951  u16 += step;
952  err = icmap_set(key_name, &u16, sizeof(u16), item->type);
953  break;
956  memcpy(&u32, item->value, sizeof(u32));
957  u32 += step;
958  err = icmap_set(key_name, &u32, sizeof(u32), item->type);
959  break;
962  memcpy(&u64, item->value, sizeof(u64));
963  u64 += step;
964  err = icmap_set(key_name, &u64, sizeof(u64), item->type);
965  break;
970  err = CS_ERR_INVALID_PARAM;
971  break;
972  }
973 
974  return (err);
975 }
976 
978  const char *key_name,
979  int32_t step)
980 {
981 
982  return (icmap_adjust_int_r(icmap_global_map, key_name, step));
983 }
984 
986  const icmap_map_t map,
987  const char *key_name,
988  int32_t step)
989 {
990  struct icmap_item *item;
991  cs_error_t err = CS_OK;
992 
993  if (key_name == NULL) {
994  return (CS_ERR_INVALID_PARAM);
995  }
996 
997  item = qb_map_get(map->qb_map, key_name);
998  if (item == NULL) {
999  return (CS_ERR_NOT_EXIST);
1000  }
1001 
1002  switch (item->type) {
1003  case ICMAP_VALUETYPE_INT8:
1004  case ICMAP_VALUETYPE_UINT8:
1005  *(uint8_t *)item->value += step;
1006  break;
1007  case ICMAP_VALUETYPE_INT16:
1009  *(uint16_t *)item->value += step;
1010  break;
1011  case ICMAP_VALUETYPE_INT32:
1013  *(uint32_t *)item->value += step;
1014  break;
1015  case ICMAP_VALUETYPE_INT64:
1017  *(uint64_t *)item->value += step;
1018  break;
1019  case ICMAP_VALUETYPE_FLOAT:
1023  err = CS_ERR_INVALID_PARAM;
1024  break;
1025  }
1026 
1027  if (err == CS_OK) {
1028  qb_map_put(map->qb_map, item->key_name, item);
1029  }
1030 
1031  return (err);
1032 }
1033 
1035  const char *key_name,
1036  int32_t step)
1037 {
1038 
1039  return (icmap_fast_adjust_int_r(icmap_global_map, key_name, step));
1040 }
1041 
1043 {
1044  return (icmap_adjust_int_r(map, key_name, 1));
1045 }
1046 
1048 {
1049  return (icmap_inc_r(icmap_global_map, key_name));
1050 }
1051 
1053 {
1054  return (icmap_adjust_int_r(map, key_name, -1));
1055 }
1056 
1058 {
1059  return (icmap_dec_r(icmap_global_map, key_name));
1060 }
1061 
1063 {
1064  return (icmap_fast_adjust_int_r(map, key_name, 1));
1065 }
1066 
1068 {
1069  return (icmap_fast_inc_r(icmap_global_map, key_name));
1070 }
1071 
1073 {
1074  return (icmap_fast_adjust_int_r(map, key_name, -1));
1075 }
1076 
1078 {
1079  return (icmap_fast_dec_r(icmap_global_map, key_name));
1080 }
1081 
1082 icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
1083 {
1084  return (qb_map_pref_iter_create(map->qb_map, prefix));
1085 }
1086 
1087 icmap_iter_t icmap_iter_init(const char *prefix)
1088 {
1089  return (icmap_iter_init_r(icmap_global_map, prefix));
1090 }
1091 
1092 
1094 {
1095  struct icmap_item *item;
1096  const char *res;
1097 
1098  res = qb_map_iter_next(iter, (void **)&item);
1099  if (res == NULL) {
1100  return (res);
1101  }
1102 
1103  if (value_len != NULL) {
1104  *value_len = item->value_len;
1105  }
1106 
1107  if (type != NULL) {
1108  *type = item->type;
1109  }
1110 
1111  return (res);
1112 }
1113 
1115 {
1116  qb_map_iter_free(iter);
1117 }
1118 
1119 static void icmap_notify_fn(uint32_t event, char *key, void *old_value, void *value, void *user_data)
1120 {
1122  struct icmap_item *new_item = (struct icmap_item *)value;
1123  struct icmap_item *old_item = (struct icmap_item *)old_value;
1124  struct icmap_notify_value new_val;
1125  struct icmap_notify_value old_val;
1126 
1127  if (value == NULL && old_value == NULL) {
1128  return ;
1129  }
1130 
1131  if (new_item != NULL) {
1132  new_val.type = new_item->type;
1133  new_val.len = new_item->value_len;
1134  new_val.data = new_item->value;
1135  } else {
1136  memset(&new_val, 0, sizeof(new_val));
1137  }
1138 
1139  /*
1140  * old_item == new_item if fast functions are used -> don't fill old value
1141  */
1142  if (old_item != NULL && old_item != new_item) {
1143  old_val.type = old_item->type;
1144  old_val.len = old_item->value_len;
1145  old_val.data = old_item->value;
1146  } else {
1147  memset(&old_val, 0, sizeof(old_val));
1148  }
1149 
1151  key,
1152  new_val,
1153  old_val,
1155 }
1156 
1158  const char *key_name,
1159  int32_t track_type,
1160  icmap_notify_fn_t notify_fn,
1161  void *user_data,
1163 {
1164  int32_t err;
1165 
1166  if (notify_fn == NULL || icmap_track == NULL) {
1167  return (CS_ERR_INVALID_PARAM);
1168  }
1169 
1170  if ((track_type & ~(ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX)) != 0) {
1171  return (CS_ERR_INVALID_PARAM);
1172  }
1173 
1174  *icmap_track = malloc(sizeof(**icmap_track));
1175  if (*icmap_track == NULL) {
1176  return (CS_ERR_NO_MEMORY);
1177  }
1178  memset(*icmap_track, 0, sizeof(**icmap_track));
1179 
1180  if (key_name != NULL) {
1181  (*icmap_track)->key_name = strdup(key_name);
1182  };
1183 
1184  (*icmap_track)->track_type = track_type;
1185  (*icmap_track)->notify_fn = notify_fn;
1186  (*icmap_track)->user_data = user_data;
1187 
1188  if ((err = qb_map_notify_add(icmap_global_map->qb_map, (*icmap_track)->key_name, icmap_notify_fn,
1189  icmap_tt_to_qbtt(track_type), *icmap_track)) != 0) {
1190  free((*icmap_track)->key_name);
1191  free(*icmap_track);
1192 
1193  return (qb_to_cs_error(err));
1194  }
1195 
1196  qb_list_init(&(*icmap_track)->list);
1197  qb_list_add (&(*icmap_track)->list, &icmap_track_list_head);
1198 
1199  return (CS_OK);
1200 }
1201 
1203 {
1204  int32_t err;
1205 
1206  if ((err = qb_map_notify_del_2(icmap_global_map->qb_map, icmap_track->key_name,
1207  icmap_notify_fn, icmap_tt_to_qbtt(icmap_track->track_type), icmap_track)) != 0) {
1208  return (qb_to_cs_error(err));
1209  }
1210 
1211  qb_list_del(&icmap_track->list);
1212  free(icmap_track->key_name);
1213  free(icmap_track);
1214 
1215  return (CS_OK);
1216 }
1217 
1219 {
1220  return (icmap_track->user_data);
1221 }
1222 
1223 cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
1224 {
1225  struct qb_list_head *iter, *tmp_iter;
1226  struct icmap_ro_access_item *icmap_ro_ai;
1227 
1228  qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
1229  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1230 
1231  if (icmap_ro_ai->prefix == prefix && strcmp(key_name, icmap_ro_ai->key_name) == 0) {
1232  /*
1233  * We found item
1234  */
1235  if (ro_access) {
1236  return (CS_ERR_EXIST);
1237  } else {
1238  qb_list_del(&icmap_ro_ai->list);
1239  free(icmap_ro_ai->key_name);
1240  free(icmap_ro_ai);
1241 
1242  return (CS_OK);
1243  }
1244  }
1245  }
1246 
1247  if (!ro_access) {
1248  return (CS_ERR_NOT_EXIST);
1249  }
1250 
1251  icmap_ro_ai = malloc(sizeof(*icmap_ro_ai));
1252  if (icmap_ro_ai == NULL) {
1253  return (CS_ERR_NO_MEMORY);
1254  }
1255 
1256  memset(icmap_ro_ai, 0, sizeof(*icmap_ro_ai));
1257  icmap_ro_ai->key_name = strdup(key_name);
1258  if (icmap_ro_ai->key_name == NULL) {
1259  free(icmap_ro_ai);
1260  return (CS_ERR_NO_MEMORY);
1261  }
1262 
1263  icmap_ro_ai->prefix = prefix;
1264  qb_list_init(&icmap_ro_ai->list);
1265  qb_list_add (&icmap_ro_ai->list, &icmap_ro_access_item_list_head);
1266 
1267  return (CS_OK);
1268 }
1269 
1270 int icmap_is_key_ro(const char *key_name)
1271 {
1272  struct qb_list_head *iter;
1273  struct icmap_ro_access_item *icmap_ro_ai;
1274 
1275  qb_list_for_each(iter, &icmap_ro_access_item_list_head) {
1276  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1277 
1278  if (icmap_ro_ai->prefix) {
1279  if (strlen(icmap_ro_ai->key_name) > strlen(key_name))
1280  continue;
1281 
1282  if (strncmp(icmap_ro_ai->key_name, key_name, strlen(icmap_ro_ai->key_name)) == 0) {
1283  return (CS_TRUE);
1284  }
1285  } else {
1286  if (strcmp(icmap_ro_ai->key_name, key_name) == 0) {
1287  return (CS_TRUE);
1288  }
1289  }
1290  }
1291 
1292  return (CS_FALSE);
1293 
1294 }
1295 
1297 {
1298  icmap_iter_t iter;
1299  size_t value_len;
1300  icmap_value_types_t value_type;
1301  const char *key_name;
1302  cs_error_t err;
1303  void *value;
1304 
1305  iter = icmap_iter_init_r(src_map, NULL);
1306  if (iter == NULL) {
1307  return (CS_ERR_NO_MEMORY);
1308  }
1309 
1310  err = CS_OK;
1311 
1312  while ((key_name = icmap_iter_next(iter, &value_len, &value_type)) != NULL) {
1313  err = icmap_get_ref_r(src_map, key_name, &value, &value_len, &value_type);
1314  if (err != CS_OK) {
1315  goto exit_iter_finalize;
1316  }
1317 
1318  err = icmap_set_r(dst_map, key_name, value, value_len, value_type);
1319  if (err != CS_OK) {
1320  goto exit_iter_finalize;
1321  }
1322  }
1323 
1324 exit_iter_finalize:
1325  icmap_iter_finalize(iter);
1326 
1327  return (err);
1328 }
icmap_tt_to_qbtt
int32_t icmap_tt_to_qbtt(int32_t track_type)
Definition: icmap.c:127
icmap_get_float_r
cs_error_t icmap_get_float_r(const icmap_map_t map, const char *key_name, float *flt)
Definition: icmap.c:842
ICMAP_VALUETYPE_FLOAT
Definition: icmap.h:67
icmap_set_int32
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
Definition: icmap.c:589
icmap_set_int64
cs_error_t icmap_set_int64(const char *key_name, int64_t value)
Definition: icmap.c:601
CS_ERR_NAME_TOO_LONG
Definition: corotypes.h:110
icmap_set_uint32_r
cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
Definition: icmap.c:525
value
uint32_t value
Definition: exec/votequorum.c:100
icmap_ro_access_item::prefix
int prefix
Definition: icmap.c:71
icmap_item::type
icmap_value_types_t type
Definition: icmap.c:50
icmap_set_double_r
cs_error_t icmap_set_double_r(const icmap_map_t map, const char *key_name, double value)
Definition: icmap.c:549
icmap_item
Definition: icmap.c:48
ICMAP_VALUETYPE_UINT32
Definition: icmap.h:64
icmap_qbtt_to_tt
int32_t icmap_qbtt_to_tt(int32_t track_type)
Definition: icmap.c:150
icmap_set_uint64
cs_error_t icmap_set_uint64(const char *key_name, uint64_t value)
Definition: icmap.c:607
icmap_fast_dec_r
cs_error_t icmap_fast_dec_r(const icmap_map_t map, const char *key_name)
icmap_fast_dec_r
Definition: icmap.c:1072
icmap_set_uint32
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:595
icmap_item::key_name
char * key_name
Definition: icmap.c:49
ICMAP_VALUETYPE_INT32
Definition: icmap.h:63
icmap_iter_init_r
icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
Definition: icmap.c:1082
icmap_fini_r
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
Definition: icmap.c:236
icmap_set_r
cs_error_t icmap_set_r(const icmap_map_t map, const char *key_name, const void *value, size_t value_len, icmap_value_types_t type)
Reentrant version of icmap_set.
Definition: icmap.c:405
icmap_get_uint8_r
cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
Definition: icmap.c:800
icmap_get_int16_r
cs_error_t icmap_get_int16_r(const icmap_map_t map, const char *key_name, int16_t *i16)
Definition: icmap.c:806
icmap_set
cs_error_t icmap_set(const char *key_name, const void *value, size_t value_len, icmap_value_types_t type)
Store value with value_len length and type as key_name name in global icmap.
Definition: icmap.c:485
ICMAP_VALUETYPE_INT64
Definition: icmap.h:65
icmap_get_uint64
cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
Definition: icmap.c:902
icmap_track::notify_fn
icmap_notify_fn_t notify_fn
Definition: icmap.c:64
type
char type
Definition: totem.h:55
icmap_get_uint16
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:878
icmap_set_ro_access
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Set read-only access for given key (key_name) or prefix, If prefix is set.
Definition: icmap.c:1223
icmap_fast_adjust_int_r
cs_error_t icmap_fast_adjust_int_r(const icmap_map_t map, const char *key_name, int32_t step)
icmap_fast_adjust_int_r
Definition: icmap.c:985
CS_ERR_NOT_EXIST
Definition: corotypes.h:109
icmap_fast_inc
cs_error_t icmap_fast_inc(const char *key_name)
Increase stored value by one.
Definition: icmap.c:1067
icmap_fast_inc_r
cs_error_t icmap_fast_inc_r(const icmap_map_t map, const char *key_name)
icmap_fast_inc_r
Definition: icmap.c:1062
icmap_track::track_type
int32_t track_type
Definition: icmap.c:63
icmap_track::list
struct qb_list_head list
Definition: icmap.c:66
ICMAP_VALUETYPE_DOUBLE
Definition: icmap.h:68
icmap_set_float_r
cs_error_t icmap_set_float_r(const icmap_map_t map, const char *key_name, float value)
Definition: icmap.c:543
icmap_get_valuetype_len
size_t icmap_get_valuetype_len(icmap_value_types_t type)
Definition: icmap.c:304
ICMAP_TRACK_PREFIX
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
Definition: icmap.h:85
icmap_get_int64
cs_error_t icmap_get_int64(const char *key_name, int64_t *i64)
Definition: icmap.c:896
icmap_set_int32_r
cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
Definition: icmap.c:519
icmap_set_float
cs_error_t icmap_set_float(const char *key_name, float value)
Definition: icmap.c:613
icmap_convert_name_to_valid_name
void icmap_convert_name_to_valid_name(char *key_name)
Converts given key_name to valid key name (replacing all prohibited characters by _)
Definition: icmap.c:276
icmap_set_uint8_r
cs_error_t icmap_set_uint8_r(const icmap_map_t map, const char *key_name, uint8_t value)
Definition: icmap.c:501
icmap_get_uint32
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:890
icmap_ro_access_item
Definition: icmap.c:69
icmap_get_global_map
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:262
icmap_get_uint64_r
cs_error_t icmap_get_uint64_r(const icmap_map_t map, const char *key_name, uint64_t *u64)
Definition: icmap.c:836
ICMAP_MAX_VALUE_LEN
#define ICMAP_MAX_VALUE_LEN
Definition: icmap.c:46
CS_TRUE
#define CS_TRUE
Definition: corotypes.h:54
icmap_iter_init
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1087
icmap_set_uint16
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:583
ICMAP_VALUETYPE_BINARY
Definition: icmap.h:70
ICMAP_TRACK_ADD
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
icmap_set_int16
cs_error_t icmap_set_int16(const char *key_name, int16_t value)
Definition: icmap.c:577
icmap_item::value
char value[]
Definition: icmap.c:52
icmap.h
ICMAP_VALUETYPE_UINT16
Definition: icmap.h:62
icmap_get_float
cs_error_t icmap_get_float(const char *key_name, float *flt)
Definition: icmap.c:908
icmap_ro_access_item::list
struct qb_list_head list
Definition: icmap.c:72
CS_ERR_INIT
Definition: corotypes.h:101
icmap_track_t
struct icmap_track * icmap_track_t
Track type.
Definition: icmap.h:128
icmap_map
Definition: icmap.c:55
icmap_get
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Retrieve value of key key_name and store it in user preallocated value pointer.
Definition: icmap.c:723
CS_OK
Definition: corotypes.h:98
icmap_notify_value::type
icmap_value_types_t type
Definition: icmap.h:92
icmap_init_r
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
Definition: icmap.c:188
icmap_get_int8
cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
Definition: icmap.c:860
icmap_delete
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
Definition: icmap.c:651
icmap_set_uint64_r
cs_error_t icmap_set_uint64_r(const icmap_map_t map, const char *key_name, uint64_t value)
Definition: icmap.c:537
icmap_set_int8_r
cs_error_t icmap_set_int8_r(const icmap_map_t map, const char *key_name, int8_t value)
Definition: icmap.c:495
icmap_fini
void icmap_fini(void)
Finalize global icmap.
Definition: icmap.c:245
icmap_get_double_r
cs_error_t icmap_get_double_r(const icmap_map_t map, const char *key_name, double *dbl)
Definition: icmap.c:848
ICMAP_KEYNAME_MAXLEN
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
ICMAP_VALUETYPE_INT8
Definition: icmap.h:59
cs_error_t
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
icmap_get_int8_r
cs_error_t icmap_get_int8_r(const icmap_map_t map, const char *key_name, int8_t *i8)
Definition: icmap.c:794
icmap_map::qb_map
qb_map_t * qb_map
Definition: icmap.c:56
icmap_item::value_len
size_t value_len
Definition: icmap.c:51
icmap_iter_next
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
Definition: icmap.c:1093
icmap_key_value_eq
int icmap_key_value_eq(const icmap_map_t map1, const char *key_name1, const icmap_map_t map2, const char *key_name2)
Compare value of key with name key_name1 in map1 with key with name key_name2 in map2.
Definition: icmap.c:383
icmap_copy_map
cs_error_t icmap_copy_map(icmap_map_t dst_map, const icmap_map_t src_map)
Copy content of src_map icmap to dst_map icmap.
Definition: icmap.c:1296
qb_to_cs_error
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
icmap_ro_access_item::key_name
char * key_name
Definition: icmap.c:70
icmap_is_key_ro
int icmap_is_key_ro(const char *key_name)
Check in given key is read only.
Definition: icmap.c:1270
icmap_track::user_data
void * user_data
Definition: icmap.c:65
icmap_dec_r
cs_error_t icmap_dec_r(const icmap_map_t map, const char *key_name)
icmap_dec_r
Definition: icmap.c:1052
icmap_notify_fn_t
void(* icmap_notify_fn_t)(int32_t event, const char *key_name, struct icmap_notify_value new_value, struct icmap_notify_value old_value, void *user_data)
Prototype for notify callback function.
Definition: icmap.h:103
CS_ERR_EXIST
Definition: corotypes.h:111
icmap_get_uint8
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:866
icmap_get_int32
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
Definition: icmap.c:884
icmap_adjust_int
cs_error_t icmap_adjust_int(const char *key_name, int32_t step)
icmap_adjust_int
Definition: icmap.c:977
icmap_get_double
cs_error_t icmap_get_double(const char *key_name, double *dbl)
Definition: icmap.c:914
icmap_value_types_t
icmap_value_types_t
Possible types of value.
Definition: icmap.h:58
icmap_track_add
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
Definition: icmap.c:1157
icmap_set_uint16_r
cs_error_t icmap_set_uint16_r(const icmap_map_t map, const char *key_name, uint16_t value)
Definition: icmap.c:513
icmap_inc
cs_error_t icmap_inc(const char *key_name)
Increase stored value by one.
Definition: icmap.c:1047
icmap_delete_r
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:631
icmap_iter_finalize
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1114
icmap_track::key_name
char * key_name
Definition: icmap.c:62
ICMAP_TRACK_DELETE
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
user_data
void * user_data
Definition: sam.c:127
icmap_get_int64_r
cs_error_t icmap_get_int64_r(const icmap_map_t map, const char *key_name, int64_t *i64)
Definition: icmap.c:830
ICMAP_TRACK_MODIFY
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
icmap_set_int16_r
cs_error_t icmap_set_int16_r(const icmap_map_t map, const char *key_name, int16_t value)
Definition: icmap.c:507
QB_LIST_DECLARE
QB_LIST_DECLARE(icmap_ro_access_item_list_head)
icmap_set_int64_r
cs_error_t icmap_set_int64_r(const icmap_map_t map, const char *key_name, int64_t value)
Definition: icmap.c:531
icmap_get_string
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition: icmap.c:854
CS_FALSE
#define CS_FALSE
Definition: corotypes.h:53
icmap_init
cs_error_t icmap_init(void)
Initialize global icmap.
Definition: icmap.c:206
icmap_get_r
cs_error_t icmap_get_r(const icmap_map_t map, const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Same as icmap_get but it's reentrant and operates on given icmap_map.
Definition: icmap.c:690
ICMAP_VALUETYPE_UINT64
Definition: icmap.h:66
config.h
ICMAP_VALUETYPE_INT16
Definition: icmap.h:61
CS_ERR_INVALID_PARAM
Definition: corotypes.h:104
icmap_set_double
cs_error_t icmap_set_double(const char *key_name, double value)
Definition: icmap.c:619
ICMAP_VALUETYPE_STRING
Definition: icmap.h:69
icmap_fast_dec
cs_error_t icmap_fast_dec(const char *key_name)
Decrease stored value by one.
Definition: icmap.c:1077
icmap_adjust_int_r
cs_error_t icmap_adjust_int_r(const icmap_map_t map, const char *key_name, int32_t step)
icmap_adjust_int_r
Definition: icmap.c:920
icmap_set_string_r
cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
Definition: icmap.c:555
ICMAP_VALUETYPE_UINT8
Definition: icmap.h:60
corotypes.h
icmap_get_int32_r
cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
Definition: icmap.c:818
icmap_inc_r
cs_error_t icmap_inc_r(const icmap_map_t map, const char *key_name)
icmap_inc_r
Definition: icmap.c:1042
icmap_track
Definition: icmap.c:61
icmap_set_string
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:625
icmap_get_string_r
cs_error_t icmap_get_string_r(icmap_map_t map, const char *key_name, char **str)
Definition: icmap.c:733
icmap_get_uint16_r
cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
Definition: icmap.c:812
icmap_fast_adjust_int
cs_error_t icmap_fast_adjust_int(const char *key_name, int32_t step)
icmap_fast_adjust_int
Definition: icmap.c:1034
icmap_set_uint8
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:571
icmap_track_get_user_data
void * icmap_track_get_user_data(icmap_track_t icmap_track)
Return user data associated with given track.
Definition: icmap.c:1218
icmap_notify_value
Structure passed as new_value and old_value in change callback.
Definition: icmap.h:91
icmap_set_int8
cs_error_t icmap_set_int8(const char *key_name, int8_t value)
Definition: icmap.c:565
CS_ERR_NO_MEMORY
Definition: corotypes.h:105
ICMAP_KEYNAME_MINLEN
#define ICMAP_KEYNAME_MINLEN
Minimum lenght of key in icmap.
Definition: icmap.h:53
icmap_iter_t
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
icmap_get_uint32_r
cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
Definition: icmap.c:824
icmap_track_delete
cs_error_t icmap_track_delete(icmap_track_t icmap_track)
Remove previously added track.
Definition: icmap.c:1202
icmap_get_int16
cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
Definition: icmap.c:872
icmap_dec
cs_error_t icmap_dec(const char *key_name)
Decrease stored value by one.
Definition: icmap.c:1057