Module: kamailio
Branch: master
Commit: 899a10489e14a834267fcfbba36cc5aacdf45633
URL:
https://github.com/kamailio/kamailio/commit/899a10489e14a834267fcfbba36cc5a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-05-14T10:32:31+02:00
core: cfg - added cfg_get_group_id to the config var framework api
---
Modified: src/core/cfg/cfg.c
Modified: src/core/cfg/cfg.h
---
Diff:
https://github.com/kamailio/kamailio/commit/899a10489e14a834267fcfbba36cc5a…
Patch:
https://github.com/kamailio/kamailio/commit/899a10489e14a834267fcfbba36cc5a…
---
diff --git a/src/core/cfg/cfg.c b/src/core/cfg/cfg.c
index 488d72f35a..80e3fe3e55 100644
--- a/src/core/cfg/cfg.c
+++ b/src/core/cfg/cfg.c
@@ -285,3 +285,39 @@ void **cfg_get_handle(char *gname)
return group->handle;
}
+
+
+/* Set the group_id pointer based on the group string.
+ * The string is either "group_name", or "group_name[group_id]"
+ * *group_id is set to null in the former case.
+ * Warning: changes the group string
+ */
+int cfg_get_group_id(str *group, unsigned int **group_id)
+{
+ static unsigned int id;
+ str s;
+
+ if (!group->s || (group->s[group->len-1] != ']')) {
+ *group_id = NULL;
+ return 0;
+ }
+
+ s.s = group->s + group->len - 2;
+ s.len = 0;
+ while ((s.s > group->s) && (*s.s != '[')) {
+ s.s--;
+ s.len++;
+ }
+ if (s.s == group->s) /* '[' not found */
+ return -1;
+ group->len = s.s - group->s;
+ s.s++;
+ if (!group->len || !s.len)
+ return -1;
+ if (str2int(&s, &id))
+ return -1;
+
+ *group_id = &id;
+ return 0;
+}
+
diff --git a/src/core/cfg/cfg.h b/src/core/cfg/cfg.h
index b3c5a1ba29..19cb824055 100644
--- a/src/core/cfg/cfg.h
+++ b/src/core/cfg/cfg.h
@@ -102,4 +102,7 @@ int cfg_new_ginst(char *group_name, unsigned int group_id);
/*! \brief returns the handle of a cfg group */
void **cfg_get_handle(char *gname);
+/*! \brief get the id of a cfg group */
+int cfg_get_group_id(str *group, unsigned int **group_id);
+
#endif /* _CFG_H */