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  free(*result);
200  return (CS_ERR_INIT);
201  }
202 
203  err = qb_map_notify_add((*result)->qb_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
204 
205  return (qb_to_cs_error(err));
206 }
207 
209 {
210  return (icmap_init_r(&icmap_global_map));
211 }
212 
213 static void icmap_set_ro_access_free(void)
214 {
215  struct qb_list_head *iter, *tmp_iter;
216  struct icmap_ro_access_item *icmap_ro_ai;
217 
218  qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
219  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
220  qb_list_del(&icmap_ro_ai->list);
221  free(icmap_ro_ai->key_name);
222  free(icmap_ro_ai);
223  }
224 }
225 
226 static void icmap_del_all_track(void)
227 {
228  struct qb_list_head *iter, *tmp_iter;
229  struct icmap_track *icmap_track;
230 
231  qb_list_for_each_safe(iter, tmp_iter, &icmap_track_list_head) {
232  icmap_track = qb_list_entry(iter, struct icmap_track, list);
233 
235  }
236 }
237 
238 void icmap_fini_r(const icmap_map_t map)
239 {
240 
241  qb_map_destroy(map->qb_map);
242  free(map);
243 
244  return;
245 }
246 
247 void icmap_fini(void)
248 {
249 
250  icmap_del_all_track();
251  /*
252  * catch 22 warning:
253  * We need to drop this notify but we can't because it calls icmap_map_free_cb
254  * while destroying the tree to free icmap_item(s).
255  * -> qb_map_notify_del_2(icmap_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
256  * and we cannot call it after map_destroy. joy! :)
257  */
258  icmap_fini_r(icmap_global_map);
259  icmap_set_ro_access_free();
260 
261  return ;
262 }
263 
265 {
266 
267  return (icmap_global_map);
268 }
269 
270 static int icmap_is_valid_name_char(char c)
271 {
272  return ((c >= 'a' && c <= 'z') ||
273  (c >= 'A' && c <= 'Z') ||
274  (c >= '0' && c <= '9') ||
275  c == '.' || c == '_' || c == '-' || c == '/' || c == ':');
276 }
277 
279 {
280  int i;
281 
282  for (i = 0; i < strlen(key_name); i++) {
283  if (!icmap_is_valid_name_char(key_name[i])) {
284  key_name[i] = '_';
285  }
286  }
287 }
288 
289 static int icmap_check_key_name(const char *key_name)
290 {
291  int i;
292 
293  if ((strlen(key_name) < ICMAP_KEYNAME_MINLEN) || strlen(key_name) > ICMAP_KEYNAME_MAXLEN) {
294  return (-1);
295  }
296 
297  for (i = 0; i < strlen(key_name); i++) {
298  if (!icmap_is_valid_name_char(key_name[i])) {
299  return (-1);
300  }
301  }
302 
303  return (0);
304 }
305 
307 {
308  size_t res = 0;
309 
310  switch (type) {
311  case ICMAP_VALUETYPE_INT8: res = sizeof(int8_t); break;
312  case ICMAP_VALUETYPE_UINT8: res = sizeof(uint8_t); break;
313  case ICMAP_VALUETYPE_INT16: res = sizeof(int16_t); break;
314  case ICMAP_VALUETYPE_UINT16: res = sizeof(uint16_t); break;
315  case ICMAP_VALUETYPE_INT32: res = sizeof(int32_t); break;
316  case ICMAP_VALUETYPE_UINT32: res = sizeof(uint32_t); break;
317  case ICMAP_VALUETYPE_INT64: res = sizeof(int64_t); break;
318  case ICMAP_VALUETYPE_UINT64: res = sizeof(uint64_t); break;
319  case ICMAP_VALUETYPE_FLOAT: res = sizeof(float); break;
320  case ICMAP_VALUETYPE_DOUBLE: res = sizeof(double); break;
323  res = 0;
324  break;
325  }
326 
327  return (res);
328 }
329 
330 static int icmap_check_value_len(const void *value, size_t value_len, icmap_value_types_t type)
331 {
332 
333  if (value_len > ICMAP_MAX_VALUE_LEN) {
334  return (-1);
335  }
336 
338  if (icmap_get_valuetype_len(type) == value_len) {
339  return (0);
340  } else {
341  return (-1);
342  }
343  }
344 
345  if (type == ICMAP_VALUETYPE_STRING) {
346  /*
347  * value_len can be shorter then real string length, but never
348  * longer (+ 1 is because of 0 at the end of string)
349  */
350  if (value_len > strlen((const char *)value) + 1) {
351  return (-1);
352  } else {
353  return (0);
354  }
355  }
356 
357  return (0);
358 }
359 
360 static int icmap_item_eq(const struct icmap_item *item, const void *value, size_t value_len, icmap_value_types_t type)
361 {
362  size_t ptr_len;
363 
364  if (item->type != type) {
365  return (0);
366  }
367 
368  if (item->type == ICMAP_VALUETYPE_STRING) {
369  ptr_len = strlen((const char *)value);
370  if (ptr_len > value_len) {
371  ptr_len = value_len;
372  }
373  ptr_len++;
374  } else {
375  ptr_len = value_len;
376  }
377 
378  if (item->value_len == ptr_len) {
379  return (memcmp(item->value, value, value_len) == 0);
380  };
381 
382  return (0);
383 }
384 
386  const icmap_map_t map1,
387  const char *key_name1,
388  const icmap_map_t map2,
389  const char *key_name2)
390 {
391  struct icmap_item *item1, *item2;
392 
393  if (map1 == NULL || key_name1 == NULL || map2 == NULL || key_name2 == NULL) {
394  return (0);
395  }
396 
397  item1 = qb_map_get(map1->qb_map, key_name1);
398  item2 = qb_map_get(map2->qb_map, key_name2);
399 
400  if (item1 == NULL || item2 == NULL) {
401  return (0);
402  }
403 
404  return (icmap_item_eq(item1, item2->value, item2->value_len, item2->type));
405 }
406 
408  const icmap_map_t map,
409  const char *key_name,
410  const void *value,
411  size_t value_len,
413 {
414  struct icmap_item *item;
415  struct icmap_item *new_item;
416  size_t new_value_len;
417  size_t new_item_size;
418 
419  if (value == NULL || key_name == NULL) {
420  return (CS_ERR_INVALID_PARAM);
421  }
422 
423  if (icmap_check_value_len(value, value_len, type) != 0) {
424  return (CS_ERR_INVALID_PARAM);
425  }
426 
427  item = qb_map_get(map->qb_map, key_name);
428  if (item != NULL) {
429  /*
430  * Check that key is really changed
431  */
432  if (icmap_item_eq(item, value, value_len, type)) {
433  return (CS_OK);
434  }
435  } else {
436  if (icmap_check_key_name(key_name) != 0) {
437  return (CS_ERR_NAME_TOO_LONG);
438  }
439  }
440 
442  if (type == ICMAP_VALUETYPE_STRING) {
443  new_value_len = strlen((const char *)value);
444  if (new_value_len > value_len) {
445  new_value_len = value_len;
446  }
447  new_value_len++;
448  } else {
449  new_value_len = value_len;
450  }
451  } else {
452  new_value_len = icmap_get_valuetype_len(type);
453  }
454 
455  new_item_size = sizeof(struct icmap_item) + new_value_len;
456  new_item = malloc(new_item_size);
457  if (new_item == NULL) {
458  return (CS_ERR_NO_MEMORY);
459  }
460  memset(new_item, 0, new_item_size);
461 
462  if (item == NULL) {
463  new_item->key_name = strdup(key_name);
464  if (new_item->key_name == NULL) {
465  free(new_item);
466  return (CS_ERR_NO_MEMORY);
467  }
468  } else {
469  new_item->key_name = item->key_name;
470  item->key_name = NULL;
471  }
472 
473  new_item->type = type;
474  new_item->value_len = new_value_len;
475 
476  memcpy(new_item->value, value, new_value_len);
477 
478  if (new_item->type == ICMAP_VALUETYPE_STRING) {
479  ((char *)new_item->value)[new_value_len - 1] = 0;
480  }
481 
482  qb_map_put(map->qb_map, new_item->key_name, new_item);
483 
484  return (CS_OK);
485 }
486 
488  const char *key_name,
489  const void *value,
490  size_t value_len,
492 {
493 
494  return (icmap_set_r(icmap_global_map, key_name, value, value_len, type));
495 }
496 
497 cs_error_t icmap_set_int8_r(const icmap_map_t map, const char *key_name, int8_t value)
498 {
499 
500  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT8));
501 }
502 
503 cs_error_t icmap_set_uint8_r(const icmap_map_t map, const char *key_name, uint8_t value)
504 {
505 
506  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT8));
507 }
508 
509 cs_error_t icmap_set_int16_r(const icmap_map_t map, const char *key_name, int16_t value)
510 {
511 
512  return (icmap_set_r(map,key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT16));
513 }
514 
515 cs_error_t icmap_set_uint16_r(const icmap_map_t map, const char *key_name, uint16_t value)
516 {
517 
518  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT16));
519 }
520 
521 cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
522 {
523 
524  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT32));
525 }
526 
527 cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
528 {
529 
530  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT32));
531 }
532 
533 cs_error_t icmap_set_int64_r(const icmap_map_t map, const char *key_name, int64_t value)
534 {
535 
536  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_INT64));
537 }
538 
539 cs_error_t icmap_set_uint64_r(const icmap_map_t map, const char *key_name, uint64_t value)
540 {
541 
542  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_UINT64));
543 }
544 
545 cs_error_t icmap_set_float_r(const icmap_map_t map, const char *key_name, float value)
546 {
547 
548  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_FLOAT));
549 }
550 
551 cs_error_t icmap_set_double_r(const icmap_map_t map, const char *key_name, double value)
552 {
553 
554  return (icmap_set_r(map, key_name, &value, sizeof(value), ICMAP_VALUETYPE_DOUBLE));
555 }
556 
557 cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
558 {
559 
560  if (value == NULL) {
561  return (CS_ERR_INVALID_PARAM);
562  }
563 
564  return (icmap_set_r(map, key_name, value, strlen(value), ICMAP_VALUETYPE_STRING));
565 }
566 
568 {
569 
570  return (icmap_set_int8_r(icmap_global_map, key_name, value));
571 }
572 
574 {
575 
576  return (icmap_set_uint8_r(icmap_global_map, key_name, value));
577 }
578 
580 {
581 
582  return (icmap_set_int16_r(icmap_global_map, key_name, value));
583 }
584 
586 {
587 
588  return (icmap_set_uint16_r(icmap_global_map, key_name, value));
589 }
590 
592 {
593 
594  return (icmap_set_int32_r(icmap_global_map, key_name, value));
595 }
596 
598 {
599 
600  return (icmap_set_uint32_r(icmap_global_map, key_name, value));
601 }
602 
604 {
605 
606  return (icmap_set_int64_r(icmap_global_map, key_name, value));
607 }
608 
610 {
611 
612  return (icmap_set_uint64_r(icmap_global_map, key_name, value));
613 }
614 
616 {
617 
618  return (icmap_set_float_r(icmap_global_map, key_name, value));
619 }
620 
622 {
623 
624  return (icmap_set_double_r(icmap_global_map, key_name, value));
625 }
626 
627 cs_error_t icmap_set_string(const char *key_name, const char *value)
628 {
629 
630  return (icmap_set_string_r(icmap_global_map, key_name, value));
631 }
632 
634 {
635  struct icmap_item *item;
636 
637  if (key_name == NULL) {
638  return (CS_ERR_INVALID_PARAM);
639  }
640 
641  item = qb_map_get(map->qb_map, key_name);
642  if (item == NULL) {
643  return (CS_ERR_NOT_EXIST);
644  }
645 
646  if (qb_map_rm(map->qb_map, item->key_name) != QB_TRUE) {
647  return (CS_ERR_NOT_EXIST);
648  }
649 
650  return (CS_OK);
651 }
652 
654 {
655 
656  return (icmap_delete_r(icmap_global_map, key_name));
657 }
658 
659 static cs_error_t icmap_get_ref_r(
660  const icmap_map_t map,
661  const char *key_name,
662  void **value,
663  size_t *value_len,
665 {
666  struct icmap_item *item;
667 
668  if (key_name == NULL) {
669  return (CS_ERR_INVALID_PARAM);
670  }
671 
672  item = qb_map_get(map->qb_map, key_name);
673  if (item == NULL) {
674  return (CS_ERR_NOT_EXIST);
675  }
676 
677  if (type != NULL) {
678  *type = item->type;
679  }
680 
681  if (value_len != NULL) {
682  *value_len = item->value_len;
683  }
684 
685  if (value != NULL) {
686  *value = item->value;
687  }
688 
689  return (CS_OK);
690 }
691 
693  const icmap_map_t map,
694  const char *key_name,
695  void *value,
696  size_t *value_len,
698 {
699  cs_error_t res;
700  void *tmp_value;
701  size_t tmp_value_len;
702 
703  res = icmap_get_ref_r(map, key_name, &tmp_value, &tmp_value_len, type);
704  if (res != CS_OK) {
705  return (res);
706  }
707 
708  if (value == NULL) {
709  if (value_len != NULL) {
710  *value_len = tmp_value_len;
711  }
712  } else {
713  if (value_len == NULL || *value_len < tmp_value_len) {
714  return (CS_ERR_INVALID_PARAM);
715  }
716 
717  *value_len = tmp_value_len;
718 
719  memcpy(value, tmp_value, tmp_value_len);
720  }
721 
722  return (CS_OK);
723 }
724 
726  const char *key_name,
727  void *value,
728  size_t *value_len,
730 {
731 
732  return (icmap_get_r(icmap_global_map, key_name, value, value_len, type));
733 }
734 
735 cs_error_t icmap_get_string_r(icmap_map_t map, const char *key_name, char **str)
736 {
737  cs_error_t res;
738  size_t str_len;
740 
741  res = icmap_get_r(map, key_name, NULL, &str_len, &type);
742  if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) {
743  if (res == CS_OK) {
744  res = CS_ERR_INVALID_PARAM;
745  }
746 
747  goto return_error;
748  }
749 
750  *str = malloc(str_len);
751  if (*str == NULL) {
752  res = CS_ERR_NO_MEMORY;
753 
754  goto return_error;
755  }
756 
757  res = icmap_get_r(map, key_name, *str, &str_len, &type);
758  if (res != CS_OK) {
759  free(*str);
760  goto return_error;
761  }
762 
763  return (CS_OK);
764 
765 return_error:
766  return (res);
767 }
768 
769 static cs_error_t icmap_get_int_r(
770  const icmap_map_t map,
771  const char *key_name,
772  void *value,
774 {
775  char key_value[16];
776  size_t key_size;
777  cs_error_t err;
778  icmap_value_types_t key_type;
779 
780  key_size = sizeof(key_value);
781  memset(key_value, 0, key_size);
782 
783  err = icmap_get_r(map, key_name, key_value, &key_size, &key_type);
784  if (err != CS_OK)
785  return (err);
786 
787  if (key_type != type) {
788  return (CS_ERR_INVALID_PARAM);
789  }
790 
791  memcpy(value, key_value, icmap_get_valuetype_len(key_type));
792 
793  return (CS_OK);
794 }
795 
796 cs_error_t icmap_get_int8_r(const icmap_map_t map, const char *key_name, int8_t *i8)
797 {
798 
799  return (icmap_get_int_r(map, key_name, i8, ICMAP_VALUETYPE_INT8));
800 }
801 
802 cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
803 {
804 
805  return (icmap_get_int_r(map, key_name, u8, ICMAP_VALUETYPE_UINT8));
806 }
807 
808 cs_error_t icmap_get_int16_r(const icmap_map_t map, const char *key_name, int16_t *i16)
809 {
810 
811  return (icmap_get_int_r(map, key_name, i16, ICMAP_VALUETYPE_INT16));
812 }
813 
814 cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
815 {
816 
817  return (icmap_get_int_r(map, key_name, u16, ICMAP_VALUETYPE_UINT16));
818 }
819 
820 cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
821 {
822 
823  return (icmap_get_int_r(map, key_name, i32, ICMAP_VALUETYPE_INT32));
824 }
825 
826 cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
827 {
828 
829  return (icmap_get_int_r(map, key_name, u32, ICMAP_VALUETYPE_UINT32));
830 }
831 
832 cs_error_t icmap_get_int64_r(const icmap_map_t map, const char *key_name, int64_t *i64)
833 {
834 
835  return(icmap_get_int_r(map, key_name, i64, ICMAP_VALUETYPE_INT64));
836 }
837 
838 cs_error_t icmap_get_uint64_r(const icmap_map_t map, const char *key_name, uint64_t *u64)
839 {
840 
841  return (icmap_get_int_r(map, key_name, u64, ICMAP_VALUETYPE_UINT64));
842 }
843 
844 cs_error_t icmap_get_float_r(const icmap_map_t map, const char *key_name, float *flt)
845 {
846 
847  return (icmap_get_int_r(map, key_name, flt, ICMAP_VALUETYPE_FLOAT));
848 }
849 
850 cs_error_t icmap_get_double_r(const icmap_map_t map, const char *key_name, double *dbl)
851 {
852 
853  return (icmap_get_int_r(map, key_name, dbl, ICMAP_VALUETYPE_DOUBLE));
854 }
855 
856 cs_error_t icmap_get_string(const char *key_name, char **str)
857 {
858 
859  return (icmap_get_string_r(icmap_global_map, key_name, str));
860 }
861 
862 cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
863 {
864 
865  return (icmap_get_int8_r(icmap_global_map, key_name, i8));
866 }
867 
868 cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
869 {
870 
871  return (icmap_get_uint8_r(icmap_global_map, key_name, u8));
872 }
873 
874 cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
875 {
876 
877  return (icmap_get_int16_r(icmap_global_map, key_name, i16));
878 }
879 
880 cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
881 {
882 
883  return (icmap_get_uint16_r(icmap_global_map, key_name, u16));
884 }
885 
886 cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
887 {
888 
889  return (icmap_get_int32_r(icmap_global_map, key_name, i32));
890 }
891 
892 cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
893 {
894 
895  return (icmap_get_uint32_r(icmap_global_map, key_name, u32));
896 }
897 
898 cs_error_t icmap_get_int64(const char *key_name, int64_t *i64)
899 {
900 
901  return(icmap_get_int64_r(icmap_global_map, key_name, i64));
902 }
903 
904 cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
905 {
906 
907  return (icmap_get_uint64_r(icmap_global_map, key_name, u64));
908 }
909 
910 cs_error_t icmap_get_float(const char *key_name, float *flt)
911 {
912 
913  return (icmap_get_float_r(icmap_global_map, key_name, flt));
914 }
915 
916 cs_error_t icmap_get_double(const char *key_name, double *dbl)
917 {
918 
919  return (icmap_get_double_r(icmap_global_map, key_name, dbl));
920 }
921 
923  const icmap_map_t map,
924  const char *key_name,
925  int32_t step)
926 {
927  struct icmap_item *item;
928  uint8_t u8;
929  uint16_t u16;
930  uint32_t u32;
931  uint64_t u64;
932  cs_error_t err = CS_OK;
933 
934  if (key_name == NULL) {
935  return (CS_ERR_INVALID_PARAM);
936  }
937 
938  item = qb_map_get(map->qb_map, key_name);
939  if (item == NULL) {
940  return (CS_ERR_NOT_EXIST);
941  }
942 
943  switch (item->type) {
946  memcpy(&u8, item->value, sizeof(u8));
947  u8 += step;
948  err = icmap_set(key_name, &u8, sizeof(u8), item->type);
949  break;
952  memcpy(&u16, item->value, sizeof(u16));
953  u16 += step;
954  err = icmap_set(key_name, &u16, sizeof(u16), item->type);
955  break;
958  memcpy(&u32, item->value, sizeof(u32));
959  u32 += step;
960  err = icmap_set(key_name, &u32, sizeof(u32), item->type);
961  break;
964  memcpy(&u64, item->value, sizeof(u64));
965  u64 += step;
966  err = icmap_set(key_name, &u64, sizeof(u64), item->type);
967  break;
972  err = CS_ERR_INVALID_PARAM;
973  break;
974  }
975 
976  return (err);
977 }
978 
980  const char *key_name,
981  int32_t step)
982 {
983 
984  return (icmap_adjust_int_r(icmap_global_map, key_name, step));
985 }
986 
988  const icmap_map_t map,
989  const char *key_name,
990  int32_t step)
991 {
992  struct icmap_item *item;
993  cs_error_t err = CS_OK;
994 
995  if (key_name == NULL) {
996  return (CS_ERR_INVALID_PARAM);
997  }
998 
999  item = qb_map_get(map->qb_map, key_name);
1000  if (item == NULL) {
1001  return (CS_ERR_NOT_EXIST);
1002  }
1003 
1004  switch (item->type) {
1005  case ICMAP_VALUETYPE_INT8:
1006  case ICMAP_VALUETYPE_UINT8:
1007  *(uint8_t *)item->value += step;
1008  break;
1009  case ICMAP_VALUETYPE_INT16:
1011  *(uint16_t *)item->value += step;
1012  break;
1013  case ICMAP_VALUETYPE_INT32:
1015  *(uint32_t *)item->value += step;
1016  break;
1017  case ICMAP_VALUETYPE_INT64:
1019  *(uint64_t *)item->value += step;
1020  break;
1021  case ICMAP_VALUETYPE_FLOAT:
1025  err = CS_ERR_INVALID_PARAM;
1026  break;
1027  }
1028 
1029  if (err == CS_OK) {
1030  qb_map_put(map->qb_map, item->key_name, item);
1031  }
1032 
1033  return (err);
1034 }
1035 
1037  const char *key_name,
1038  int32_t step)
1039 {
1040 
1041  return (icmap_fast_adjust_int_r(icmap_global_map, key_name, step));
1042 }
1043 
1045 {
1046  return (icmap_adjust_int_r(map, key_name, 1));
1047 }
1048 
1050 {
1051  return (icmap_inc_r(icmap_global_map, key_name));
1052 }
1053 
1055 {
1056  return (icmap_adjust_int_r(map, key_name, -1));
1057 }
1058 
1060 {
1061  return (icmap_dec_r(icmap_global_map, key_name));
1062 }
1063 
1065 {
1066  return (icmap_fast_adjust_int_r(map, key_name, 1));
1067 }
1068 
1070 {
1071  return (icmap_fast_inc_r(icmap_global_map, key_name));
1072 }
1073 
1075 {
1076  return (icmap_fast_adjust_int_r(map, key_name, -1));
1077 }
1078 
1080 {
1081  return (icmap_fast_dec_r(icmap_global_map, key_name));
1082 }
1083 
1084 icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
1085 {
1086  return (qb_map_pref_iter_create(map->qb_map, prefix));
1087 }
1088 
1089 icmap_iter_t icmap_iter_init(const char *prefix)
1090 {
1091  return (icmap_iter_init_r(icmap_global_map, prefix));
1092 }
1093 
1094 
1096 {
1097  struct icmap_item *item;
1098  const char *res;
1099 
1100  res = qb_map_iter_next(iter, (void **)&item);
1101  if (res == NULL) {
1102  return (res);
1103  }
1104 
1105  if (value_len != NULL) {
1106  *value_len = item->value_len;
1107  }
1108 
1109  if (type != NULL) {
1110  *type = item->type;
1111  }
1112 
1113  return (res);
1114 }
1115 
1117 {
1118  qb_map_iter_free(iter);
1119 }
1120 
1121 static void icmap_notify_fn(uint32_t event, char *key, void *old_value, void *value, void *user_data)
1122 {
1124  struct icmap_item *new_item = (struct icmap_item *)value;
1125  struct icmap_item *old_item = (struct icmap_item *)old_value;
1126  struct icmap_notify_value new_val;
1127  struct icmap_notify_value old_val;
1128 
1129  if (value == NULL && old_value == NULL) {
1130  return ;
1131  }
1132 
1133  if (new_item != NULL) {
1134  new_val.type = new_item->type;
1135  new_val.len = new_item->value_len;
1136  new_val.data = new_item->value;
1137  } else {
1138  memset(&new_val, 0, sizeof(new_val));
1139  }
1140 
1141  /*
1142  * old_item == new_item if fast functions are used -> don't fill old value
1143  */
1144  if (old_item != NULL && old_item != new_item) {
1145  old_val.type = old_item->type;
1146  old_val.len = old_item->value_len;
1147  old_val.data = old_item->value;
1148  } else {
1149  memset(&old_val, 0, sizeof(old_val));
1150  }
1151 
1153  key,
1154  new_val,
1155  old_val,
1157 }
1158 
1160  const char *key_name,
1161  int32_t track_type,
1162  icmap_notify_fn_t notify_fn,
1163  void *user_data,
1165 {
1166  int32_t err;
1167 
1168  if (notify_fn == NULL || icmap_track == NULL) {
1169  return (CS_ERR_INVALID_PARAM);
1170  }
1171 
1172  if ((track_type & ~(ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX)) != 0) {
1173  return (CS_ERR_INVALID_PARAM);
1174  }
1175 
1176  *icmap_track = malloc(sizeof(**icmap_track));
1177  if (*icmap_track == NULL) {
1178  return (CS_ERR_NO_MEMORY);
1179  }
1180  memset(*icmap_track, 0, sizeof(**icmap_track));
1181 
1182  if (key_name != NULL) {
1183  (*icmap_track)->key_name = strdup(key_name);
1184  };
1185 
1186  (*icmap_track)->track_type = track_type;
1187  (*icmap_track)->notify_fn = notify_fn;
1188  (*icmap_track)->user_data = user_data;
1189 
1190  if ((err = qb_map_notify_add(icmap_global_map->qb_map, (*icmap_track)->key_name, icmap_notify_fn,
1191  icmap_tt_to_qbtt(track_type), *icmap_track)) != 0) {
1192  free((*icmap_track)->key_name);
1193  free(*icmap_track);
1194 
1195  return (qb_to_cs_error(err));
1196  }
1197 
1198  qb_list_init(&(*icmap_track)->list);
1199  qb_list_add (&(*icmap_track)->list, &icmap_track_list_head);
1200 
1201  return (CS_OK);
1202 }
1203 
1205 {
1206  int32_t err;
1207 
1208  if ((err = qb_map_notify_del_2(icmap_global_map->qb_map, icmap_track->key_name,
1209  icmap_notify_fn, icmap_tt_to_qbtt(icmap_track->track_type), icmap_track)) != 0) {
1210  return (qb_to_cs_error(err));
1211  }
1212 
1213  qb_list_del(&icmap_track->list);
1214  free(icmap_track->key_name);
1215  free(icmap_track);
1216 
1217  return (CS_OK);
1218 }
1219 
1221 {
1222  return (icmap_track->user_data);
1223 }
1224 
1225 cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
1226 {
1227  struct qb_list_head *iter, *tmp_iter;
1228  struct icmap_ro_access_item *icmap_ro_ai;
1229 
1230  qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
1231  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1232 
1233  if (icmap_ro_ai->prefix == prefix && strcmp(key_name, icmap_ro_ai->key_name) == 0) {
1234  /*
1235  * We found item
1236  */
1237  if (ro_access) {
1238  return (CS_ERR_EXIST);
1239  } else {
1240  qb_list_del(&icmap_ro_ai->list);
1241  free(icmap_ro_ai->key_name);
1242  free(icmap_ro_ai);
1243 
1244  return (CS_OK);
1245  }
1246  }
1247  }
1248 
1249  if (!ro_access) {
1250  return (CS_ERR_NOT_EXIST);
1251  }
1252 
1253  icmap_ro_ai = malloc(sizeof(*icmap_ro_ai));
1254  if (icmap_ro_ai == NULL) {
1255  return (CS_ERR_NO_MEMORY);
1256  }
1257 
1258  memset(icmap_ro_ai, 0, sizeof(*icmap_ro_ai));
1259  icmap_ro_ai->key_name = strdup(key_name);
1260  if (icmap_ro_ai->key_name == NULL) {
1261  free(icmap_ro_ai);
1262  return (CS_ERR_NO_MEMORY);
1263  }
1264 
1265  icmap_ro_ai->prefix = prefix;
1266  qb_list_init(&icmap_ro_ai->list);
1267  qb_list_add (&icmap_ro_ai->list, &icmap_ro_access_item_list_head);
1268 
1269  return (CS_OK);
1270 }
1271 
1272 int icmap_is_key_ro(const char *key_name)
1273 {
1274  struct qb_list_head *iter;
1275  struct icmap_ro_access_item *icmap_ro_ai;
1276 
1277  qb_list_for_each(iter, &icmap_ro_access_item_list_head) {
1278  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1279 
1280  if (icmap_ro_ai->prefix) {
1281  if (strlen(icmap_ro_ai->key_name) > strlen(key_name))
1282  continue;
1283 
1284  if (strncmp(icmap_ro_ai->key_name, key_name, strlen(icmap_ro_ai->key_name)) == 0) {
1285  return (CS_TRUE);
1286  }
1287  } else {
1288  if (strcmp(icmap_ro_ai->key_name, key_name) == 0) {
1289  return (CS_TRUE);
1290  }
1291  }
1292  }
1293 
1294  return (CS_FALSE);
1295 
1296 }
1297 
1299 {
1300  icmap_iter_t iter;
1301  size_t value_len;
1302  icmap_value_types_t value_type;
1303  const char *key_name;
1304  cs_error_t err;
1305  void *value;
1306 
1307  iter = icmap_iter_init_r(src_map, NULL);
1308  if (iter == NULL) {
1309  return (CS_ERR_NO_MEMORY);
1310  }
1311 
1312  err = CS_OK;
1313 
1314  while ((key_name = icmap_iter_next(iter, &value_len, &value_type)) != NULL) {
1315  err = icmap_get_ref_r(src_map, key_name, &value, &value_len, &value_type);
1316  if (err != CS_OK) {
1317  goto exit_iter_finalize;
1318  }
1319 
1320  err = icmap_set_r(dst_map, key_name, value, value_len, value_type);
1321  if (err != CS_OK) {
1322  goto exit_iter_finalize;
1323  }
1324  }
1325 
1326 exit_iter_finalize:
1327  icmap_iter_finalize(iter);
1328 
1329  return (err);
1330 }
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:844
ICMAP_VALUETYPE_FLOAT
@ 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:591
icmap_set_int64
cs_error_t icmap_set_int64(const char *key_name, int64_t value)
Definition: icmap.c:603
CS_ERR_NAME_TOO_LONG
@ 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:527
value
uint32_t value
Definition: exec/votequorum.c:101
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:551
icmap_item
Definition: icmap.c:48
ICMAP_VALUETYPE_UINT32
@ 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:609
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:1074
icmap_set_uint32
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:597
icmap_item::key_name
char * key_name
Definition: icmap.c:49
ICMAP_VALUETYPE_INT32
@ 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:1084
icmap_fini_r
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
Definition: icmap.c:238
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:407
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:802
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:808
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:487
ICMAP_VALUETYPE_INT64
@ 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:904
icmap_track::notify_fn
icmap_notify_fn_t notify_fn
Definition: icmap.c:64
type
char type
Definition: totem.h:4
icmap_get_uint16
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:880
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:1225
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:987
CS_ERR_NOT_EXIST
@ 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:1069
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:1064
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
@ 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:545
icmap_get_valuetype_len
size_t icmap_get_valuetype_len(icmap_value_types_t type)
Definition: icmap.c:306
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:898
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:521
icmap_set_float
cs_error_t icmap_set_float(const char *key_name, float value)
Definition: icmap.c:615
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:278
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:503
icmap_get_uint32
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:892
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:264
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:838
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:1089
icmap_set_uint16
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:585
ICMAP_VALUETYPE_BINARY
@ 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:579
icmap_item::value
char value[]
Definition: icmap.c:52
icmap.h
ICMAP_VALUETYPE_UINT16
@ 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:910
icmap_ro_access_item::list
struct qb_list_head list
Definition: icmap.c:72
CS_ERR_INIT
@ 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:725
CS_OK
@ 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:862
icmap_delete
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
Definition: icmap.c:653
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:539
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:497
icmap_fini
void icmap_fini(void)
Finalize global icmap.
Definition: icmap.c:247
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:850
ICMAP_KEYNAME_MAXLEN
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
ICMAP_VALUETYPE_INT8
@ 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:796
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:1095
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:385
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:1298
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:1272
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:1054
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
@ 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:868
icmap_get_int32
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
Definition: icmap.c:886
icmap_adjust_int
cs_error_t icmap_adjust_int(const char *key_name, int32_t step)
icmap_adjust_int
Definition: icmap.c:979
icmap_get_double
cs_error_t icmap_get_double(const char *key_name, double *dbl)
Definition: icmap.c:916
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:1159
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:515
icmap_inc
cs_error_t icmap_inc(const char *key_name)
Increase stored value by one.
Definition: icmap.c:1049
icmap_delete_r
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:633
icmap_iter_finalize
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1116
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:832
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:509
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:533
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:856
CS_FALSE
#define CS_FALSE
Definition: corotypes.h:53
icmap_init
cs_error_t icmap_init(void)
Initialize global icmap.
Definition: icmap.c:208
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:692
ICMAP_VALUETYPE_UINT64
@ ICMAP_VALUETYPE_UINT64
Definition: icmap.h:66
config.h
ICMAP_VALUETYPE_INT16
@ ICMAP_VALUETYPE_INT16
Definition: icmap.h:61
CS_ERR_INVALID_PARAM
@ 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:621
ICMAP_VALUETYPE_STRING
@ 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:1079
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:922
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:557
ICMAP_VALUETYPE_UINT8
@ 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:820
icmap_inc_r
cs_error_t icmap_inc_r(const icmap_map_t map, const char *key_name)
icmap_inc_r
Definition: icmap.c:1044
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:627
icmap_get_string_r
cs_error_t icmap_get_string_r(icmap_map_t map, const char *key_name, char **str)
Definition: icmap.c:735
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:814
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:1036
icmap_set_uint8
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:573
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:1220
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:567
CS_ERR_NO_MEMORY
@ 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:826
icmap_track_delete
cs_error_t icmap_track_delete(icmap_track_t icmap_track)
Remove previously added track.
Definition: icmap.c:1204
icmap_get_int16
cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
Definition: icmap.c:874
icmap_dec
cs_error_t icmap_dec(const char *key_name)
Decrease stored value by one.
Definition: icmap.c:1059