corosync  3.0.2
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 
232  icmap_track_delete(icmap_track);
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 
332  return (-1);
333  }
334 
335  if (type != ICMAP_VALUETYPE_STRING && type != ICMAP_VALUETYPE_BINARY) {
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 
439  if (type == ICMAP_VALUETYPE_BINARY || type == ICMAP_VALUETYPE_STRING) {
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 static cs_error_t icmap_get_int_r(
734  const icmap_map_t map,
735  const char *key_name,
736  void *value,
738 {
739  char key_value[16];
740  size_t key_size;
741  cs_error_t err;
742  icmap_value_types_t key_type;
743 
744  key_size = sizeof(key_value);
745  memset(key_value, 0, key_size);
746 
747  err = icmap_get(key_name, key_value, &key_size, &key_type);
748  if (err != CS_OK)
749  return (err);
750 
751  if (key_type != type) {
752  return (CS_ERR_INVALID_PARAM);
753  }
754 
755  memcpy(value, key_value, icmap_get_valuetype_len(key_type));
756 
757  return (CS_OK);
758 }
759 
760 cs_error_t icmap_get_int8_r(const icmap_map_t map, const char *key_name, int8_t *i8)
761 {
762 
763  return (icmap_get_int_r(map, key_name, i8, ICMAP_VALUETYPE_INT8));
764 }
765 
766 cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
767 {
768 
769  return (icmap_get_int_r(map, key_name, u8, ICMAP_VALUETYPE_UINT8));
770 }
771 
772 cs_error_t icmap_get_int16_r(const icmap_map_t map, const char *key_name, int16_t *i16)
773 {
774 
775  return (icmap_get_int_r(map, key_name, i16, ICMAP_VALUETYPE_INT16));
776 }
777 
778 cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
779 {
780 
781  return (icmap_get_int_r(map, key_name, u16, ICMAP_VALUETYPE_UINT16));
782 }
783 
784 cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
785 {
786 
787  return (icmap_get_int_r(map, key_name, i32, ICMAP_VALUETYPE_INT32));
788 }
789 
790 cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
791 {
792 
793  return (icmap_get_int_r(map, key_name, u32, ICMAP_VALUETYPE_UINT32));
794 }
795 
796 cs_error_t icmap_get_int64_r(const icmap_map_t map, const char *key_name, int64_t *i64)
797 {
798 
799  return(icmap_get_int_r(map, key_name, i64, ICMAP_VALUETYPE_INT64));
800 }
801 
802 cs_error_t icmap_get_uint64_r(const icmap_map_t map, const char *key_name, uint64_t *u64)
803 {
804 
805  return (icmap_get_int_r(map, key_name, u64, ICMAP_VALUETYPE_UINT64));
806 }
807 
808 cs_error_t icmap_get_float_r(const icmap_map_t map, const char *key_name, float *flt)
809 {
810 
811  return (icmap_get_int_r(map, key_name, flt, ICMAP_VALUETYPE_FLOAT));
812 }
813 
814 cs_error_t icmap_get_double_r(const icmap_map_t map, const char *key_name, double *dbl)
815 {
816 
817  return (icmap_get_int_r(map, key_name, dbl, ICMAP_VALUETYPE_DOUBLE));
818 }
819 
820 cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
821 {
822 
823  return (icmap_get_int8_r(icmap_global_map, key_name, i8));
824 }
825 
826 cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
827 {
828 
829  return (icmap_get_uint8_r(icmap_global_map, key_name, u8));
830 }
831 
832 cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
833 {
834 
835  return (icmap_get_int16_r(icmap_global_map, key_name, i16));
836 }
837 
838 cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
839 {
840 
841  return (icmap_get_uint16_r(icmap_global_map, key_name, u16));
842 }
843 
844 cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
845 {
846 
847  return (icmap_get_int32_r(icmap_global_map, key_name, i32));
848 }
849 
850 cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
851 {
852 
853  return (icmap_get_uint32_r(icmap_global_map, key_name, u32));
854 }
855 
856 cs_error_t icmap_get_int64(const char *key_name, int64_t *i64)
857 {
858 
859  return(icmap_get_int64_r(icmap_global_map, key_name, i64));
860 }
861 
862 cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
863 {
864 
865  return (icmap_get_uint64_r(icmap_global_map, key_name, u64));
866 }
867 
868 cs_error_t icmap_get_float(const char *key_name, float *flt)
869 {
870 
871  return (icmap_get_float_r(icmap_global_map, key_name, flt));
872 }
873 
874 cs_error_t icmap_get_double(const char *key_name, double *dbl)
875 {
876 
877  return (icmap_get_double_r(icmap_global_map, key_name, dbl));
878 }
879 
880 cs_error_t icmap_get_string(const char *key_name, char **str)
881 {
882  cs_error_t res;
883  size_t str_len;
885 
886  res = icmap_get(key_name, NULL, &str_len, &type);
887  if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) {
888  if (res == CS_OK) {
889  res = CS_ERR_INVALID_PARAM;
890  }
891 
892  goto return_error;
893  }
894 
895  *str = malloc(str_len);
896  if (*str == NULL) {
897  res = CS_ERR_NO_MEMORY;
898 
899  goto return_error;
900  }
901 
902  res = icmap_get(key_name, *str, &str_len, &type);
903  if (res != CS_OK) {
904  free(*str);
905  goto return_error;
906  }
907 
908  return (CS_OK);
909 
910 return_error:
911  return (res);
912 }
913 
915  const icmap_map_t map,
916  const char *key_name,
917  int32_t step)
918 {
919  struct icmap_item *item;
920  uint8_t u8;
921  uint16_t u16;
922  uint32_t u32;
923  uint64_t u64;
924  cs_error_t err = CS_OK;
925 
926  if (key_name == NULL) {
927  return (CS_ERR_INVALID_PARAM);
928  }
929 
930  item = qb_map_get(map->qb_map, key_name);
931  if (item == NULL) {
932  return (CS_ERR_NOT_EXIST);
933  }
934 
935  switch (item->type) {
938  memcpy(&u8, item->value, sizeof(u8));
939  u8 += step;
940  err = icmap_set(key_name, &u8, sizeof(u8), item->type);
941  break;
944  memcpy(&u16, item->value, sizeof(u16));
945  u16 += step;
946  err = icmap_set(key_name, &u16, sizeof(u16), item->type);
947  break;
950  memcpy(&u32, item->value, sizeof(u32));
951  u32 += step;
952  err = icmap_set(key_name, &u32, sizeof(u32), item->type);
953  break;
956  memcpy(&u64, item->value, sizeof(u64));
957  u64 += step;
958  err = icmap_set(key_name, &u64, sizeof(u64), item->type);
959  break;
964  err = CS_ERR_INVALID_PARAM;
965  break;
966  }
967 
968  return (err);
969 }
970 
972  const char *key_name,
973  int32_t step)
974 {
975 
976  return (icmap_adjust_int_r(icmap_global_map, key_name, step));
977 }
978 
980  const icmap_map_t map,
981  const char *key_name,
982  int32_t step)
983 {
984  struct icmap_item *item;
985  cs_error_t err = CS_OK;
986 
987  if (key_name == NULL) {
988  return (CS_ERR_INVALID_PARAM);
989  }
990 
991  item = qb_map_get(map->qb_map, key_name);
992  if (item == NULL) {
993  return (CS_ERR_NOT_EXIST);
994  }
995 
996  switch (item->type) {
999  *(uint8_t *)item->value += step;
1000  break;
1001  case ICMAP_VALUETYPE_INT16:
1003  *(uint16_t *)item->value += step;
1004  break;
1005  case ICMAP_VALUETYPE_INT32:
1007  *(uint32_t *)item->value += step;
1008  break;
1009  case ICMAP_VALUETYPE_INT64:
1011  *(uint64_t *)item->value += step;
1012  break;
1013  case ICMAP_VALUETYPE_FLOAT:
1017  err = CS_ERR_INVALID_PARAM;
1018  break;
1019  }
1020 
1021  if (err == CS_OK) {
1022  qb_map_put(map->qb_map, item->key_name, item);
1023  }
1024 
1025  return (err);
1026 }
1027 
1029  const char *key_name,
1030  int32_t step)
1031 {
1032 
1033  return (icmap_fast_adjust_int_r(icmap_global_map, key_name, step));
1034 }
1035 
1037 {
1038  return (icmap_adjust_int_r(map, key_name, 1));
1039 }
1040 
1042 {
1043  return (icmap_inc_r(icmap_global_map, key_name));
1044 }
1045 
1047 {
1048  return (icmap_adjust_int_r(map, key_name, -1));
1049 }
1050 
1052 {
1053  return (icmap_dec_r(icmap_global_map, key_name));
1054 }
1055 
1057 {
1058  return (icmap_fast_adjust_int_r(map, key_name, 1));
1059 }
1060 
1062 {
1063  return (icmap_fast_inc_r(icmap_global_map, key_name));
1064 }
1065 
1067 {
1068  return (icmap_fast_adjust_int_r(map, key_name, -1));
1069 }
1070 
1072 {
1073  return (icmap_fast_dec_r(icmap_global_map, key_name));
1074 }
1075 
1076 icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
1077 {
1078  return (qb_map_pref_iter_create(map->qb_map, prefix));
1079 }
1080 
1081 icmap_iter_t icmap_iter_init(const char *prefix)
1082 {
1083  return (icmap_iter_init_r(icmap_global_map, prefix));
1084 }
1085 
1086 
1088 {
1089  struct icmap_item *item;
1090  const char *res;
1091 
1092  res = qb_map_iter_next(iter, (void **)&item);
1093  if (res == NULL) {
1094  return (res);
1095  }
1096 
1097  if (value_len != NULL) {
1098  *value_len = item->value_len;
1099  }
1100 
1101  if (type != NULL) {
1102  *type = item->type;
1103  }
1104 
1105  return (res);
1106 }
1107 
1109 {
1110  qb_map_iter_free(iter);
1111 }
1112 
1113 static void icmap_notify_fn(uint32_t event, char *key, void *old_value, void *value, void *user_data)
1114 {
1116  struct icmap_item *new_item = (struct icmap_item *)value;
1117  struct icmap_item *old_item = (struct icmap_item *)old_value;
1118  struct icmap_notify_value new_val;
1119  struct icmap_notify_value old_val;
1120 
1121  if (value == NULL && old_value == NULL) {
1122  return ;
1123  }
1124 
1125  if (new_item != NULL) {
1126  new_val.type = new_item->type;
1127  new_val.len = new_item->value_len;
1128  new_val.data = new_item->value;
1129  } else {
1130  memset(&new_val, 0, sizeof(new_val));
1131  }
1132 
1133  /*
1134  * old_item == new_item if fast functions are used -> don't fill old value
1135  */
1136  if (old_item != NULL && old_item != new_item) {
1137  old_val.type = old_item->type;
1138  old_val.len = old_item->value_len;
1139  old_val.data = old_item->value;
1140  } else {
1141  memset(&old_val, 0, sizeof(old_val));
1142  }
1143 
1144  icmap_track->notify_fn(icmap_qbtt_to_tt(event),
1145  key,
1146  new_val,
1147  old_val,
1148  icmap_track->user_data);
1149 }
1150 
1152  const char *key_name,
1153  int32_t track_type,
1154  icmap_notify_fn_t notify_fn,
1155  void *user_data,
1157 {
1158  int32_t err;
1159 
1160  if (notify_fn == NULL || icmap_track == NULL) {
1161  return (CS_ERR_INVALID_PARAM);
1162  }
1163 
1164  if ((track_type & ~(ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX)) != 0) {
1165  return (CS_ERR_INVALID_PARAM);
1166  }
1167 
1168  *icmap_track = malloc(sizeof(**icmap_track));
1169  if (*icmap_track == NULL) {
1170  return (CS_ERR_NO_MEMORY);
1171  }
1172  memset(*icmap_track, 0, sizeof(**icmap_track));
1173 
1174  if (key_name != NULL) {
1175  (*icmap_track)->key_name = strdup(key_name);
1176  };
1177 
1178  (*icmap_track)->track_type = track_type;
1179  (*icmap_track)->notify_fn = notify_fn;
1180  (*icmap_track)->user_data = user_data;
1181 
1182  if ((err = qb_map_notify_add(icmap_global_map->qb_map, (*icmap_track)->key_name, icmap_notify_fn,
1183  icmap_tt_to_qbtt(track_type), *icmap_track)) != 0) {
1184  free((*icmap_track)->key_name);
1185  free(*icmap_track);
1186 
1187  return (qb_to_cs_error(err));
1188  }
1189 
1190  qb_list_init(&(*icmap_track)->list);
1191  qb_list_add (&(*icmap_track)->list, &icmap_track_list_head);
1192 
1193  return (CS_OK);
1194 }
1195 
1197 {
1198  int32_t err;
1199 
1200  if ((err = qb_map_notify_del_2(icmap_global_map->qb_map, icmap_track->key_name,
1201  icmap_notify_fn, icmap_tt_to_qbtt(icmap_track->track_type), icmap_track)) != 0) {
1202  return (qb_to_cs_error(err));
1203  }
1204 
1205  qb_list_del(&icmap_track->list);
1206  free(icmap_track->key_name);
1207  free(icmap_track);
1208 
1209  return (CS_OK);
1210 }
1211 
1213 {
1214  return (icmap_track->user_data);
1215 }
1216 
1217 cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
1218 {
1219  struct qb_list_head *iter, *tmp_iter;
1220  struct icmap_ro_access_item *icmap_ro_ai;
1221 
1222  qb_list_for_each_safe(iter, tmp_iter, &icmap_ro_access_item_list_head) {
1223  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1224 
1225  if (icmap_ro_ai->prefix == prefix && strcmp(key_name, icmap_ro_ai->key_name) == 0) {
1226  /*
1227  * We found item
1228  */
1229  if (ro_access) {
1230  return (CS_ERR_EXIST);
1231  } else {
1232  qb_list_del(&icmap_ro_ai->list);
1233  free(icmap_ro_ai->key_name);
1234  free(icmap_ro_ai);
1235 
1236  return (CS_OK);
1237  }
1238  }
1239  }
1240 
1241  if (!ro_access) {
1242  return (CS_ERR_NOT_EXIST);
1243  }
1244 
1245  icmap_ro_ai = malloc(sizeof(*icmap_ro_ai));
1246  if (icmap_ro_ai == NULL) {
1247  return (CS_ERR_NO_MEMORY);
1248  }
1249 
1250  memset(icmap_ro_ai, 0, sizeof(*icmap_ro_ai));
1251  icmap_ro_ai->key_name = strdup(key_name);
1252  if (icmap_ro_ai->key_name == NULL) {
1253  free(icmap_ro_ai);
1254  return (CS_ERR_NO_MEMORY);
1255  }
1256 
1257  icmap_ro_ai->prefix = prefix;
1258  qb_list_init(&icmap_ro_ai->list);
1259  qb_list_add (&icmap_ro_ai->list, &icmap_ro_access_item_list_head);
1260 
1261  return (CS_OK);
1262 }
1263 
1264 int icmap_is_key_ro(const char *key_name)
1265 {
1266  struct qb_list_head *iter;
1267  struct icmap_ro_access_item *icmap_ro_ai;
1268 
1269  qb_list_for_each(iter, &icmap_ro_access_item_list_head) {
1270  icmap_ro_ai = qb_list_entry(iter, struct icmap_ro_access_item, list);
1271 
1272  if (icmap_ro_ai->prefix) {
1273  if (strlen(icmap_ro_ai->key_name) > strlen(key_name))
1274  continue;
1275 
1276  if (strncmp(icmap_ro_ai->key_name, key_name, strlen(icmap_ro_ai->key_name)) == 0) {
1277  return (CS_TRUE);
1278  }
1279  } else {
1280  if (strcmp(icmap_ro_ai->key_name, key_name) == 0) {
1281  return (CS_TRUE);
1282  }
1283  }
1284  }
1285 
1286  return (CS_FALSE);
1287 
1288 }
1289 
1291 {
1292  icmap_iter_t iter;
1293  size_t value_len;
1294  icmap_value_types_t value_type;
1295  const char *key_name;
1296  cs_error_t err;
1297  void *value;
1298 
1299  iter = icmap_iter_init_r(src_map, NULL);
1300  if (iter == NULL) {
1301  return (CS_ERR_NO_MEMORY);
1302  }
1303 
1304  err = CS_OK;
1305 
1306  while ((key_name = icmap_iter_next(iter, &value_len, &value_type)) != NULL) {
1307  err = icmap_get_ref_r(src_map, key_name, &value, &value_len, &value_type);
1308  if (err != CS_OK) {
1309  goto exit_iter_finalize;
1310  }
1311 
1312  err = icmap_set_r(dst_map, key_name, value, value_len, value_type);
1313  if (err != CS_OK) {
1314  goto exit_iter_finalize;
1315  }
1316  }
1317 
1318 exit_iter_finalize:
1319  icmap_iter_finalize(iter);
1320 
1321  return (err);
1322 }
cs_error_t icmap_set_float(const char *key_name, float value)
Definition: icmap.c:613
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
#define CS_TRUE
Definition: corotypes.h:54
char * key_name
Definition: icmap.c:70
cs_error_t icmap_get_double(const char *key_name, double *dbl)
Definition: icmap.c:874
icmap_notify_fn_t notify_fn
Definition: icmap.c:64
cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
Definition: icmap.c:862
size_t len
Definition: icmap.h:93
cs_error_t icmap_set_int16_r(const icmap_map_t map, const char *key_name, int16_t value)
Definition: icmap.c:507
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&#39;s reentrant and operates on given icmap_map.
Definition: icmap.c:690
cs_error_t icmap_dec_r(const icmap_map_t map, const char *key_name)
icmap_dec_r
Definition: icmap.c:1046
cs_error_t icmap_get_int16(const char *key_name, int16_t *i16)
Definition: icmap.c:832
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:826
cs_error_t icmap_set_double(const char *key_name, double value)
Definition: icmap.c:619
int32_t icmap_qbtt_to_tt(int32_t track_type)
Definition: icmap.c:150
#define CS_FALSE
Definition: corotypes.h:53
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:1151
cs_error_t icmap_set_uint64_r(const icmap_map_t map, const char *key_name, uint64_t value)
Definition: icmap.c:537
struct qb_list_head list
Definition: icmap.c:72
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:595
cs_error_t icmap_set_uint16_r(const icmap_map_t map, const char *key_name, uint16_t value)
Definition: icmap.c:513
cs_error_t icmap_fast_inc(const char *key_name)
Increase stored value by one.
Definition: icmap.c:1061
cs_error_t icmap_set_int8_r(const icmap_map_t map, const char *key_name, int8_t value)
Definition: icmap.c:495
#define ICMAP_MAX_VALUE_LEN
Definition: icmap.c:46
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:1087
cs_error_t icmap_adjust_int(const char *key_name, int32_t step)
icmap_adjust_int
Definition: icmap.c:971
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
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
Definition: icmap.c:844
cs_error_t icmap_track_delete(icmap_track_t icmap_track)
Remove previously added track.
Definition: icmap.c:1196
icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
Definition: icmap.c:1076
cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
Definition: icmap.c:790
cs_error_t icmap_get_float_r(const icmap_map_t map, const char *key_name, float *flt)
Definition: icmap.c:808
cs_error_t icmap_inc(const char *key_name)
Increase stored value by one.
Definition: icmap.c:1041
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:850
char * key_name
Definition: icmap.c:62
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
Definition: icmap.c:188
cs_error_t icmap_set_int8(const char *key_name, int8_t value)
Definition: icmap.c:565
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
cs_error_t icmap_fast_inc_r(const icmap_map_t map, const char *key_name)
icmap_fast_inc_r
Definition: icmap.c:1056
cs_error_t icmap_get_int8_r(const icmap_map_t map, const char *key_name, int8_t *i8)
Definition: icmap.c:760
cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
Definition: icmap.c:555
cs_error_t icmap_set_int64_r(const icmap_map_t map, const char *key_name, int64_t value)
Definition: icmap.c:531
cs_error_t icmap_set_double_r(const icmap_map_t map, const char *key_name, double value)
Definition: icmap.c:549
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:262
void * user_data
Definition: sam.c:127
int32_t icmap_tt_to_qbtt(int32_t track_type)
Definition: icmap.c:127
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_error_t icmap_set_uint8_r(const icmap_map_t map, const char *key_name, uint8_t value)
Definition: icmap.c:501
cs_error_t icmap_get_int8(const char *key_name, int8_t *i8)
Definition: icmap.c:820
const void * data
Definition: icmap.h:94
cs_error_t icmap_set_uint64(const char *key_name, uint64_t value)
Definition: icmap.c:607
int icmap_is_key_ro(const char *key_name)
Check in given key is read only.
Definition: icmap.c:1264
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
icmap_value_types_t type
Definition: icmap.h:92
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:979
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:583
cs_error_t icmap_set_int16(const char *key_name, int16_t value)
Definition: icmap.c:577
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:94
cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
Definition: icmap.c:766
qb_map_t * qb_map
Definition: icmap.c:56
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
Definition: icmap.c:651
cs_error_t icmap_get_int16_r(const icmap_map_t map, const char *key_name, int16_t *i16)
Definition: icmap.c:772
QB_LIST_DECLARE(icmap_ro_access_item_list_head)
char value[]
Definition: icmap.c:52
cs_error_t icmap_set_float_r(const icmap_map_t map, const char *key_name, float value)
Definition: icmap.c:543
cs_error_t icmap_get_int64_r(const icmap_map_t map, const char *key_name, int64_t *i64)
Definition: icmap.c:796
cs_error_t icmap_fast_adjust_int(const char *key_name, int32_t step)
icmap_fast_adjust_int
Definition: icmap.c:1028
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:1290
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1081
int32_t track_type
Definition: icmap.c:63
cs_error_t icmap_init(void)
Initialize global icmap.
Definition: icmap.c:206
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1108
cs_error_t icmap_set_int64(const char *key_name, int64_t value)
Definition: icmap.c:601
icmap_value_types_t type
Definition: icmap.c:50
struct qb_list_head list
Definition: icmap.c:66
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_error_t icmap_fast_dec_r(const icmap_map_t map, const char *key_name)
icmap_fast_dec_r
Definition: icmap.c:1066
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:631
cs_error_t icmap_get_int64(const char *key_name, int64_t *i64)
Definition: icmap.c:856
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
Definition: icmap.c:589
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
cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
Definition: icmap.c:519
cs_error_t icmap_dec(const char *key_name)
Decrease stored value by one.
Definition: icmap.c:1051
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:571
struct icmap_track * icmap_track_t
Track type.
Definition: icmap.h:128
size_t icmap_get_valuetype_len(icmap_value_types_t type)
Definition: icmap.c:304
cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
Definition: icmap.c:778
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:625
#define ICMAP_KEYNAME_MINLEN
Minimum lenght of key in icmap.
Definition: icmap.h:53
size_t value_len
Definition: icmap.c:51
cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
Definition: icmap.c:525
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:914
void * user_data
Definition: icmap.c:65
cs_error_t icmap_inc_r(const icmap_map_t map, const char *key_name)
icmap_inc_r
Definition: icmap.c:1036
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
cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
Definition: icmap.c:784
char * key_name
Definition: icmap.c:49
void icmap_fini(void)
Finalize global icmap.
Definition: icmap.c:245
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition: icmap.c:880
cs_error_t icmap_get_uint64_r(const icmap_map_t map, const char *key_name, uint64_t *u64)
Definition: icmap.c:802
cs_error_t icmap_fast_dec(const char *key_name)
Decrease stored value by one.
Definition: icmap.c:1071
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:838
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:1217
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
icmap_value_types_t
Possible types of value.
Definition: icmap.h:58
cs_error_t icmap_get_double_r(const icmap_map_t map, const char *key_name, double *dbl)
Definition: icmap.c:814
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
Definition: icmap.c:236
cs_error_t icmap_get_float(const char *key_name, float *flt)
Definition: icmap.c:868
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
Structure passed as new_value and old_value in change callback.
Definition: icmap.h:91
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
Definition: icmap.h:85
void * icmap_track_get_user_data(icmap_track_t icmap_track)
Return user data associated with given track.
Definition: icmap.c:1212