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