|
@@ -34,21 +34,21 @@
|
|
cfg_group_t *cfg_group = NULL; /* linked list of registered cfg groups */
|
|
cfg_group_t *cfg_group = NULL; /* linked list of registered cfg groups */
|
|
cfg_block_t **cfg_global = NULL; /* pointer to the active cfg block */
|
|
cfg_block_t **cfg_global = NULL; /* pointer to the active cfg block */
|
|
cfg_block_t *cfg_local = NULL; /* per-process pointer to the active cfg block.
|
|
cfg_block_t *cfg_local = NULL; /* per-process pointer to the active cfg block.
|
|
- Updated only when the child process
|
|
|
|
- finishes working on the SIP message */
|
|
|
|
|
|
+ * Updated only when the child process
|
|
|
|
+ * finishes working on the SIP message */
|
|
int cfg_block_size = 0; /* size of the cfg block including the meta-data (constant) */
|
|
int cfg_block_size = 0; /* size of the cfg block including the meta-data (constant) */
|
|
gen_lock_t *cfg_global_lock = 0; /* protects *cfg_global */
|
|
gen_lock_t *cfg_global_lock = 0; /* protects *cfg_global */
|
|
gen_lock_t *cfg_writer_lock = 0; /* This lock makes sure that two processes do not
|
|
gen_lock_t *cfg_writer_lock = 0; /* This lock makes sure that two processes do not
|
|
- try to clone *cfg_global at the same time.
|
|
|
|
- Never try to get cfg_writer_lock when
|
|
|
|
- cfg_global_lock is held */
|
|
|
|
|
|
+ * try to clone *cfg_global at the same time.
|
|
|
|
+ * Never try to get cfg_writer_lock when
|
|
|
|
+ * cfg_global_lock is held */
|
|
int cfg_shmized = 0; /* indicates whether the cfg block has been
|
|
int cfg_shmized = 0; /* indicates whether the cfg block has been
|
|
- already shmized */
|
|
|
|
|
|
+ * already shmized */
|
|
|
|
|
|
cfg_child_cb_t **cfg_child_cb_first = NULL; /* first item of the per-child process
|
|
cfg_child_cb_t **cfg_child_cb_first = NULL; /* first item of the per-child process
|
|
- callback list */
|
|
|
|
|
|
+ * callback list */
|
|
cfg_child_cb_t **cfg_child_cb_last = NULL; /* last item of the above list */
|
|
cfg_child_cb_t **cfg_child_cb_last = NULL; /* last item of the above list */
|
|
-cfg_child_cb_t *cfg_child_cb = NULL; /* pointer to the previously executed cb */
|
|
|
|
|
|
+cfg_child_cb_t *cfg_child_cb = NULL; /* pointer to the previously executed cb */
|
|
int cfg_ginst_count = 0; /* number of group instances set within the child process */
|
|
int cfg_ginst_count = 0; /* number of group instances set within the child process */
|
|
|
|
|
|
|
|
|
|
@@ -64,21 +64,21 @@ cfg_group_t *cfg_new_group(char *name, int name_len,
|
|
cfg_group_t *group;
|
|
cfg_group_t *group;
|
|
|
|
|
|
if (cfg_shmized) {
|
|
if (cfg_shmized) {
|
|
- LOG(L_ERR, "ERROR: cfg_new_group(): too late config declaration\n");
|
|
|
|
|
|
+ LM_ERR("too late config declaration\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
if (num > CFG_MAX_VAR_NUM) {
|
|
if (num > CFG_MAX_VAR_NUM) {
|
|
- LOG(L_ERR, "ERROR: cfg_new_group(): too many variables (%d) within a single group,"
|
|
|
|
- " the limit is %d. Increase CFG_MAX_VAR_NUM, or split the group into multiple"
|
|
|
|
- " definitions.\n",
|
|
|
|
- num, CFG_MAX_VAR_NUM);
|
|
|
|
|
|
+ LM_ERR("too many variables (%d) within a single group,"
|
|
|
|
+ " the limit is %d. Increase CFG_MAX_VAR_NUM, or split the group"
|
|
|
|
+ " into multiple definitions.\n",
|
|
|
|
+ num, CFG_MAX_VAR_NUM);
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
group = (cfg_group_t *)pkg_malloc(sizeof(cfg_group_t)+name_len-1);
|
|
group = (cfg_group_t *)pkg_malloc(sizeof(cfg_group_t)+name_len-1);
|
|
if (!group) {
|
|
if (!group) {
|
|
- LOG(L_ERR, "ERROR: cfg_new_group(): not enough memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough memory\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
memset(group, 0, sizeof(cfg_group_t)+name_len-1);
|
|
memset(group, 0, sizeof(cfg_group_t)+name_len-1);
|
|
@@ -129,7 +129,7 @@ int cfg_clone_str(str *src, str *dst)
|
|
|
|
|
|
c = (char *)shm_malloc(sizeof(char)*(src->len+1));
|
|
c = (char *)shm_malloc(sizeof(char)*(src->len+1));
|
|
if (!c) {
|
|
if (!c) {
|
|
- LOG(L_ERR, "ERROR: cfg_clone_str(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
memcpy(c, src->s, src->len);
|
|
memcpy(c, src->s, src->len);
|
|
@@ -149,8 +149,8 @@ static int cfg_shmize_strings(cfg_group_t *group)
|
|
str s;
|
|
str s;
|
|
|
|
|
|
/* We do not know in advance whether the variable will be changed or not,
|
|
/* We do not know in advance whether the variable will be changed or not,
|
|
- and it can happen that we try to free the shm memory area when the variable
|
|
|
|
- is changed, hence, it must be already in shm mem */
|
|
|
|
|
|
+ * and it can happen that we try to free the shm memory area when
|
|
|
|
+ * the variable is changed, hence, it must be already in shm mem */
|
|
mapping = group->mapping;
|
|
mapping = group->mapping;
|
|
for (i=0; i<group->num; i++) {
|
|
for (i=0; i<group->num; i++) {
|
|
/* the cfg driver module may have already shmized the variable */
|
|
/* the cfg driver module may have already shmized the variable */
|
|
@@ -201,10 +201,10 @@ int cfg_shmize(void)
|
|
* The additional array for the multiple values
|
|
* The additional array for the multiple values
|
|
* of the same variable is linked to the meta-data.
|
|
* of the same variable is linked to the meta-data.
|
|
*/
|
|
*/
|
|
- for ( size=0, group = cfg_group;
|
|
|
|
- group;
|
|
|
|
- group=group->next
|
|
|
|
- ) {
|
|
|
|
|
|
+ for (size=0, group = cfg_group;
|
|
|
|
+ group;
|
|
|
|
+ group=group->next
|
|
|
|
+ ) {
|
|
size = ROUND_POINTER(size);
|
|
size = ROUND_POINTER(size);
|
|
group->meta_offset = size;
|
|
group->meta_offset = size;
|
|
size += sizeof(cfg_group_meta_t);
|
|
size += sizeof(cfg_group_meta_t);
|
|
@@ -216,7 +216,7 @@ int cfg_shmize(void)
|
|
|
|
|
|
block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+size-1);
|
|
block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+size-1);
|
|
if (!block) {
|
|
if (!block) {
|
|
- LOG(L_ERR, "ERROR: cfg_shmize(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
memset(block, 0, sizeof(cfg_block_t)+size-1);
|
|
memset(block, 0, sizeof(cfg_block_t)+size-1);
|
|
@@ -224,9 +224,9 @@ int cfg_shmize(void)
|
|
|
|
|
|
/* copy the memory fragments to the single block */
|
|
/* copy the memory fragments to the single block */
|
|
for ( group = cfg_group;
|
|
for ( group = cfg_group;
|
|
- group;
|
|
|
|
- group=group->next
|
|
|
|
- ) {
|
|
|
|
|
|
+ group;
|
|
|
|
+ group=group->next
|
|
|
|
+ ) {
|
|
if (group->dynamic == CFG_GROUP_STATIC) {
|
|
if (group->dynamic == CFG_GROUP_STATIC) {
|
|
/* clone the strings to shm mem */
|
|
/* clone the strings to shm mem */
|
|
if (cfg_shmize_strings(group)) goto error;
|
|
if (cfg_shmize_strings(group)) goto error;
|
|
@@ -249,14 +249,13 @@ int cfg_shmize(void)
|
|
group->mapping->def);
|
|
group->mapping->def);
|
|
*(group->handle) = NULL;
|
|
*(group->handle) = NULL;
|
|
} else {
|
|
} else {
|
|
- LOG(L_ERR, "ERROR: cfg_shmize(): Configuration group is declared "
|
|
|
|
- "without any variable: %.*s\n",
|
|
|
|
|
|
+ LM_ERR("configuration group is declared without any variable: %.*s\n",
|
|
group->name_len, group->name);
|
|
group->name_len, group->name);
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
|
|
|
|
/* Create the additional group instances with applying
|
|
/* Create the additional group instances with applying
|
|
- the temporary list. */
|
|
|
|
|
|
+ * the temporary list. */
|
|
if (apply_add_var_list(block, group))
|
|
if (apply_add_var_list(block, group))
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
@@ -293,11 +292,11 @@ static void cfg_destory_groups(unsigned char *block)
|
|
if (block && def)
|
|
if (block && def)
|
|
for (i=0; i<group->num; i++)
|
|
for (i=0; i<group->num; i++)
|
|
if (((CFG_VAR_TYPE(&mapping[i]) == CFG_VAR_STRING) ||
|
|
if (((CFG_VAR_TYPE(&mapping[i]) == CFG_VAR_STRING) ||
|
|
- (CFG_VAR_TYPE(&mapping[i]) == CFG_VAR_STR)) &&
|
|
|
|
- mapping[i].flag & cfg_var_shmized) {
|
|
|
|
|
|
+ (CFG_VAR_TYPE(&mapping[i]) == CFG_VAR_STR)) &&
|
|
|
|
+ mapping[i].flag & cfg_var_shmized) {
|
|
|
|
|
|
- old_string = *(char **)(block + group->var_offset + mapping[i].offset);
|
|
|
|
- if (old_string) shm_free(old_string);
|
|
|
|
|
|
+ old_string = *(char **)(block + group->var_offset + mapping[i].offset);
|
|
|
|
+ if (old_string) shm_free(old_string);
|
|
}
|
|
}
|
|
|
|
|
|
if (group->dynamic == CFG_GROUP_DYNAMIC) {
|
|
if (group->dynamic == CFG_GROUP_DYNAMIC) {
|
|
@@ -305,7 +304,7 @@ static void cfg_destory_groups(unsigned char *block)
|
|
cfg_script_destroy(group);
|
|
cfg_script_destroy(group);
|
|
} else {
|
|
} else {
|
|
/* only the mapping was allocated, all the other
|
|
/* only the mapping was allocated, all the other
|
|
- pointers are just set to static variables */
|
|
|
|
|
|
+ * pointers are just set to static variables */
|
|
if (mapping) pkg_free(mapping);
|
|
if (mapping) pkg_free(mapping);
|
|
}
|
|
}
|
|
/* Delete the additional variable list */
|
|
/* Delete the additional variable list */
|
|
@@ -322,11 +321,11 @@ int sr_cfg_init(void)
|
|
{
|
|
{
|
|
cfg_global_lock = lock_alloc();
|
|
cfg_global_lock = lock_alloc();
|
|
if (!cfg_global_lock) {
|
|
if (!cfg_global_lock) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
if (lock_init(cfg_global_lock) == 0) {
|
|
if (lock_init(cfg_global_lock) == 0) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): failed to init lock\n");
|
|
|
|
|
|
+ LM_ERR("failed to init lock\n");
|
|
lock_dealloc(cfg_global_lock);
|
|
lock_dealloc(cfg_global_lock);
|
|
cfg_global_lock = 0;
|
|
cfg_global_lock = 0;
|
|
goto error;
|
|
goto error;
|
|
@@ -334,11 +333,11 @@ int sr_cfg_init(void)
|
|
|
|
|
|
cfg_writer_lock = lock_alloc();
|
|
cfg_writer_lock = lock_alloc();
|
|
if (!cfg_writer_lock) {
|
|
if (!cfg_writer_lock) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
if (lock_init(cfg_writer_lock) == 0) {
|
|
if (lock_init(cfg_writer_lock) == 0) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): failed to init lock\n");
|
|
|
|
|
|
+ LM_ERR("failed to init lock\n");
|
|
lock_dealloc(cfg_writer_lock);
|
|
lock_dealloc(cfg_writer_lock);
|
|
cfg_writer_lock = 0;
|
|
cfg_writer_lock = 0;
|
|
goto error;
|
|
goto error;
|
|
@@ -346,28 +345,28 @@ int sr_cfg_init(void)
|
|
|
|
|
|
cfg_global = (cfg_block_t **)shm_malloc(sizeof(cfg_block_t *));
|
|
cfg_global = (cfg_block_t **)shm_malloc(sizeof(cfg_block_t *));
|
|
if (!cfg_global) {
|
|
if (!cfg_global) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
*cfg_global = NULL;
|
|
*cfg_global = NULL;
|
|
|
|
|
|
cfg_child_cb_first = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
|
|
cfg_child_cb_first = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
|
|
if (!cfg_child_cb_first) {
|
|
if (!cfg_child_cb_first) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
*cfg_child_cb_first = NULL;
|
|
*cfg_child_cb_first = NULL;
|
|
|
|
|
|
cfg_child_cb_last = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
|
|
cfg_child_cb_last = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
|
|
if (!cfg_child_cb_last) {
|
|
if (!cfg_child_cb_last) {
|
|
- LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
*cfg_child_cb_last = NULL;
|
|
*cfg_child_cb_last = NULL;
|
|
|
|
|
|
/* A new cfg_child_cb struct must be created with a NULL callback function.
|
|
/* A new cfg_child_cb struct must be created with a NULL callback function.
|
|
- This stucture will be the entry point for the child processes, and
|
|
|
|
- will be freed later, when none of the processes refers to it */
|
|
|
|
|
|
+ * This stucture will be the entry point for the child processes, and
|
|
|
|
+ * will be freed later, when none of the processes refers to it */
|
|
*cfg_child_cb_first = *cfg_child_cb_last =
|
|
*cfg_child_cb_first = *cfg_child_cb_last =
|
|
cfg_child_cb_new(NULL, NULL, NULL, 0);
|
|
cfg_child_cb_new(NULL, NULL, NULL, 0);
|
|
|
|
|
|
@@ -505,24 +504,24 @@ void cfg_child_destroy(void)
|
|
if (!cfg_child_cb || cfg_child_cb==CFG_NO_CHILD_CBS) return;
|
|
if (!cfg_child_cb || cfg_child_cb==CFG_NO_CHILD_CBS) return;
|
|
|
|
|
|
/* The lock must be held to make sure that the global config
|
|
/* The lock must be held to make sure that the global config
|
|
- is not replaced meantime, and the other child processes do not
|
|
|
|
- leave the old value of *cfg_child_cb_last. Otherwise it could happen,
|
|
|
|
- that all the other processes move their own cfg_child_cb pointer before
|
|
|
|
- this process reaches *cfg_child_cb_last, though, it is very unlikely. */
|
|
|
|
|
|
+ * is not replaced meantime, and the other child processes do not
|
|
|
|
+ * leave the old value of *cfg_child_cb_last. Otherwise it could happen,
|
|
|
|
+ * that all the other processes move their own cfg_child_cb pointer before
|
|
|
|
+ * this process reaches *cfg_child_cb_last, though, it is very unlikely. */
|
|
CFG_LOCK();
|
|
CFG_LOCK();
|
|
|
|
|
|
/* go through the list and check whether there is any item that
|
|
/* go through the list and check whether there is any item that
|
|
- has to be freed (similar to cfg_update_local(), but without executing
|
|
|
|
- the callback functions) */
|
|
|
|
|
|
+ * has to be freed (similar to cfg_update_local(), but without executing
|
|
|
|
+ * the callback functions) */
|
|
while (cfg_child_cb != *cfg_child_cb_last) {
|
|
while (cfg_child_cb != *cfg_child_cb_last) {
|
|
prev_cb = cfg_child_cb;
|
|
prev_cb = cfg_child_cb;
|
|
cfg_child_cb = cfg_child_cb->next;
|
|
cfg_child_cb = cfg_child_cb->next;
|
|
atomic_inc(&cfg_child_cb->refcnt);
|
|
atomic_inc(&cfg_child_cb->refcnt);
|
|
if (atomic_dec_and_test(&prev_cb->refcnt)) {
|
|
if (atomic_dec_and_test(&prev_cb->refcnt)) {
|
|
/* No more pocess refers to this callback.
|
|
/* No more pocess refers to this callback.
|
|
- Did this process block the deletion,
|
|
|
|
- or is there any other process that has not
|
|
|
|
- reached prev_cb yet? */
|
|
|
|
|
|
+ * Did this process block the deletion,
|
|
|
|
+ * or is there any other process that has not
|
|
|
|
+ * reached prev_cb yet? */
|
|
if (*cfg_child_cb_first == prev_cb) {
|
|
if (*cfg_child_cb_first == prev_cb) {
|
|
/* yes, this process was blocking the deletion */
|
|
/* yes, this process was blocking the deletion */
|
|
*cfg_child_cb_first = cfg_child_cb;
|
|
*cfg_child_cb_first = cfg_child_cb;
|
|
@@ -530,8 +529,8 @@ void cfg_child_destroy(void)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
/* no need to continue, because there is at least
|
|
/* no need to continue, because there is at least
|
|
- one process that stays exactly at the same point
|
|
|
|
- in the list, so it will free the items later */
|
|
|
|
|
|
+ * one process that stays exactly at the same point
|
|
|
|
+ * in the list, so it will free the items later */
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -547,11 +546,11 @@ cfg_group_t *cfg_lookup_group(char *name, int len)
|
|
cfg_group_t *g;
|
|
cfg_group_t *g;
|
|
|
|
|
|
for ( g = cfg_group;
|
|
for ( g = cfg_group;
|
|
- g;
|
|
|
|
- g = g->next
|
|
|
|
- )
|
|
|
|
|
|
+ g;
|
|
|
|
+ g = g->next
|
|
|
|
+ )
|
|
if ((g->name_len == len)
|
|
if ((g->name_len == len)
|
|
- && (memcmp(g->name, name, len)==0))
|
|
|
|
|
|
+ && (memcmp(g->name, name, len)==0))
|
|
return g;
|
|
return g;
|
|
|
|
|
|
return NULL;
|
|
return NULL;
|
|
@@ -559,26 +558,26 @@ cfg_group_t *cfg_lookup_group(char *name, int len)
|
|
|
|
|
|
/* searches a variable definition by group and variable name */
|
|
/* searches a variable definition by group and variable name */
|
|
int cfg_lookup_var(str *gname, str *vname,
|
|
int cfg_lookup_var(str *gname, str *vname,
|
|
- cfg_group_t **group, cfg_mapping_t **var)
|
|
|
|
|
|
+ cfg_group_t **group, cfg_mapping_t **var)
|
|
{
|
|
{
|
|
cfg_group_t *g;
|
|
cfg_group_t *g;
|
|
int i;
|
|
int i;
|
|
|
|
|
|
- for ( g = cfg_group;
|
|
|
|
- g;
|
|
|
|
- g = g->next
|
|
|
|
- )
|
|
|
|
|
|
+ for (g = cfg_group;
|
|
|
|
+ g;
|
|
|
|
+ g = g->next
|
|
|
|
+ )
|
|
if ((g->name_len == gname->len)
|
|
if ((g->name_len == gname->len)
|
|
- && (memcmp(g->name, gname->s, gname->len)==0)) {
|
|
|
|
|
|
+ && (memcmp(g->name, gname->s, gname->len)==0)) {
|
|
|
|
|
|
if (!g->mapping) return -1; /* dynamic group is not ready */
|
|
if (!g->mapping) return -1; /* dynamic group is not ready */
|
|
|
|
|
|
for ( i = 0;
|
|
for ( i = 0;
|
|
- i < g->num;
|
|
|
|
- i++
|
|
|
|
- ) {
|
|
|
|
|
|
+ i < g->num;
|
|
|
|
+ i++
|
|
|
|
+ ) {
|
|
if ((g->mapping[i].name_len == vname->len)
|
|
if ((g->mapping[i].name_len == vname->len)
|
|
- && (memcmp(g->mapping[i].def->name, vname->s, vname->len)==0)) {
|
|
|
|
|
|
+ && (memcmp(g->mapping[i].def->name, vname->s, vname->len)==0)) {
|
|
if (group) *group = g;
|
|
if (group) *group = g;
|
|
if (var) *var = &(g->mapping[i]);
|
|
if (var) *var = &(g->mapping[i]);
|
|
return 0;
|
|
return 0;
|
|
@@ -587,7 +586,7 @@ int cfg_lookup_var(str *gname, str *vname,
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_lookup_var(): variable not found: %.*s.%.*s\n",
|
|
|
|
|
|
+ LM_DBG("variable not found: %.*s.%.*s\n",
|
|
gname->len, gname->s,
|
|
gname->len, gname->s,
|
|
vname->len, vname->s);
|
|
vname->len, vname->s);
|
|
return -1;
|
|
return -1;
|
|
@@ -601,16 +600,16 @@ cfg_mapping_t *cfg_lookup_var2(cfg_group_t *group, char *name, int len)
|
|
if (!group->mapping) return NULL; /* dynamic group is not ready */
|
|
if (!group->mapping) return NULL; /* dynamic group is not ready */
|
|
|
|
|
|
for ( i = 0;
|
|
for ( i = 0;
|
|
- i < group->num;
|
|
|
|
- i++
|
|
|
|
- ) {
|
|
|
|
|
|
+ i < group->num;
|
|
|
|
+ i++
|
|
|
|
+ ) {
|
|
if ((group->mapping[i].name_len == len)
|
|
if ((group->mapping[i].name_len == len)
|
|
- && (memcmp(group->mapping[i].def->name, name, len)==0)) {
|
|
|
|
|
|
+ && (memcmp(group->mapping[i].def->name, name, len)==0)) {
|
|
return &(group->mapping[i]);
|
|
return &(group->mapping[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_lookup_var2(): variable not found: %.*s.%.*s\n",
|
|
|
|
|
|
+ LM_DBG("variable not found: %.*s.%.*s\n",
|
|
group->name_len, group->name,
|
|
group->name_len, group->name,
|
|
len, name);
|
|
len, name);
|
|
return NULL;
|
|
return NULL;
|
|
@@ -625,7 +624,7 @@ cfg_block_t *cfg_clone_global(void)
|
|
|
|
|
|
block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+cfg_block_size-1);
|
|
block = (cfg_block_t*)shm_malloc(sizeof(cfg_block_t)+cfg_block_size-1);
|
|
if (!block) {
|
|
if (!block) {
|
|
- LOG(L_ERR, "ERROR: cfg_clone_global(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
memcpy(block, *cfg_global, sizeof(cfg_block_t)+cfg_block_size-1);
|
|
memcpy(block, *cfg_global, sizeof(cfg_block_t)+cfg_block_size-1);
|
|
@@ -648,7 +647,7 @@ cfg_group_inst_t *cfg_clone_array(cfg_group_meta_t *meta, cfg_group_t *group)
|
|
size = (sizeof(cfg_group_inst_t) + group->size - 1) * meta->num;
|
|
size = (sizeof(cfg_group_inst_t) + group->size - 1) * meta->num;
|
|
new_array = (cfg_group_inst_t *)shm_malloc(size);
|
|
new_array = (cfg_group_inst_t *)shm_malloc(size);
|
|
if (!new_array) {
|
|
if (!new_array) {
|
|
- LOG(L_ERR, "ERROR: cfg_clone_array(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
memcpy(new_array, meta->array, size);
|
|
memcpy(new_array, meta->array, size);
|
|
@@ -659,8 +658,8 @@ cfg_group_inst_t *cfg_clone_array(cfg_group_meta_t *meta, cfg_group_t *group)
|
|
/* Extend the array of configuration group instances with one more instance.
|
|
/* Extend the array of configuration group instances with one more instance.
|
|
* Only the ID of the new group is set, nothing else. */
|
|
* Only the ID of the new group is set, nothing else. */
|
|
cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
- unsigned int group_id,
|
|
|
|
- cfg_group_inst_t **new_group)
|
|
|
|
|
|
+ unsigned int group_id,
|
|
|
|
+ cfg_group_inst_t **new_group)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
cfg_group_inst_t *new_array, *old_array;
|
|
cfg_group_inst_t *new_array, *old_array;
|
|
@@ -669,21 +668,21 @@ cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
|
|
inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
|
|
new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num + 1));
|
|
new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num + 1));
|
|
if (!new_array) {
|
|
if (!new_array) {
|
|
- LOG(L_ERR, "ERROR: cfg_extend_array(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
/* Find the position of the new group in the array. The array is ordered
|
|
/* Find the position of the new group in the array. The array is ordered
|
|
- by the group IDs. */
|
|
|
|
|
|
+ * by the group IDs. */
|
|
old_array = meta->array;
|
|
old_array = meta->array;
|
|
for ( i = 0;
|
|
for ( i = 0;
|
|
- (i < meta->num)
|
|
|
|
|
|
+ (i < meta->num)
|
|
&& (((cfg_group_inst_t *)((char *)old_array + inst_size * i))->id < group_id);
|
|
&& (((cfg_group_inst_t *)((char *)old_array + inst_size * i))->id < group_id);
|
|
- i++
|
|
|
|
- );
|
|
|
|
|
|
+ i++
|
|
|
|
+ );
|
|
if (i > 0)
|
|
if (i > 0)
|
|
memcpy( new_array,
|
|
memcpy( new_array,
|
|
- old_array,
|
|
|
|
- inst_size * i);
|
|
|
|
|
|
+ old_array,
|
|
|
|
+ inst_size * i);
|
|
|
|
|
|
memset((char*)new_array + inst_size * i, 0, inst_size);
|
|
memset((char*)new_array + inst_size * i, 0, inst_size);
|
|
*new_group = (cfg_group_inst_t *)((char*)new_array + inst_size * i);
|
|
*new_group = (cfg_group_inst_t *)((char*)new_array + inst_size * i);
|
|
@@ -691,8 +690,8 @@ cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
|
|
|
|
if (i < meta->num)
|
|
if (i < meta->num)
|
|
memcpy( (char*)new_array + inst_size * (i + 1),
|
|
memcpy( (char*)new_array + inst_size * (i + 1),
|
|
- (char*)old_array + inst_size * i,
|
|
|
|
- inst_size * (meta->num - i));
|
|
|
|
|
|
+ (char*)old_array + inst_size * i,
|
|
|
|
+ inst_size * (meta->num - i));
|
|
|
|
|
|
return new_array;
|
|
return new_array;
|
|
}
|
|
}
|
|
@@ -701,8 +700,8 @@ cfg_group_inst_t *cfg_extend_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
* inst must point to an instance within meta->array.
|
|
* inst must point to an instance within meta->array.
|
|
* *_new_array is set to the newly allocated array. */
|
|
* *_new_array is set to the newly allocated array. */
|
|
int cfg_collapse_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
int cfg_collapse_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
- cfg_group_inst_t *inst,
|
|
|
|
- cfg_group_inst_t **_new_array)
|
|
|
|
|
|
+ cfg_group_inst_t *inst,
|
|
|
|
+ cfg_group_inst_t **_new_array)
|
|
{
|
|
{
|
|
cfg_group_inst_t *new_array, *old_array;
|
|
cfg_group_inst_t *new_array, *old_array;
|
|
int inst_size, offset;
|
|
int inst_size, offset;
|
|
@@ -718,7 +717,7 @@ int cfg_collapse_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
|
|
inst_size = sizeof(cfg_group_inst_t) + group->size - 1;
|
|
new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num - 1));
|
|
new_array = (cfg_group_inst_t *)shm_malloc(inst_size * (meta->num - 1));
|
|
if (!new_array) {
|
|
if (!new_array) {
|
|
- LOG(L_ERR, "ERROR: cfg_collapse_array(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -726,13 +725,13 @@ int cfg_collapse_array(cfg_group_meta_t *meta, cfg_group_t *group,
|
|
offset = (char *)inst - (char *)old_array;
|
|
offset = (char *)inst - (char *)old_array;
|
|
if (offset)
|
|
if (offset)
|
|
memcpy( new_array,
|
|
memcpy( new_array,
|
|
- old_array,
|
|
|
|
- offset);
|
|
|
|
|
|
+ old_array,
|
|
|
|
+ offset);
|
|
|
|
|
|
if (meta->num * inst_size > offset + inst_size)
|
|
if (meta->num * inst_size > offset + inst_size)
|
|
memcpy( (char *)new_array + offset,
|
|
memcpy( (char *)new_array + offset,
|
|
- (char *)old_array + offset + inst_size,
|
|
|
|
- (meta->num - 1) * inst_size - offset);
|
|
|
|
|
|
+ (char *)old_array + offset + inst_size,
|
|
|
|
+ (meta->num - 1) * inst_size - offset);
|
|
|
|
|
|
*_new_array = new_array;
|
|
*_new_array = new_array;
|
|
return 0;
|
|
return 0;
|
|
@@ -747,11 +746,10 @@ cfg_group_inst_t *cfg_find_group(cfg_group_meta_t *meta, int group_size, unsigne
|
|
if (!meta)
|
|
if (!meta)
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
- /* For now, search lineray.
|
|
|
|
- TODO: improve */
|
|
|
|
|
|
+ /* For now, search lineray. TODO: improve */
|
|
for (i = 0; i < meta->num; i++) {
|
|
for (i = 0; i < meta->num; i++) {
|
|
ginst = (cfg_group_inst_t *)((char *)meta->array
|
|
ginst = (cfg_group_inst_t *)((char *)meta->array
|
|
- + (sizeof(cfg_group_inst_t) + group_size - 1) * i);
|
|
|
|
|
|
+ + (sizeof(cfg_group_inst_t) + group_size - 1) * i);
|
|
if (ginst->id == group_id)
|
|
if (ginst->id == group_id)
|
|
return ginst;
|
|
return ginst;
|
|
else if (ginst->id > group_id)
|
|
else if (ginst->id > group_id)
|
|
@@ -780,10 +778,10 @@ void cfg_install_child_cb(cfg_child_cb_t *cb_first, cfg_child_cb_t *cb_last)
|
|
* callbacks. This list is added to the global linked list.
|
|
* callbacks. This list is added to the global linked list.
|
|
*/
|
|
*/
|
|
void cfg_install_global(cfg_block_t *block, void **replaced,
|
|
void cfg_install_global(cfg_block_t *block, void **replaced,
|
|
- cfg_child_cb_t *cb_first, cfg_child_cb_t *cb_last)
|
|
|
|
|
|
+ cfg_child_cb_t *cb_first, cfg_child_cb_t *cb_last)
|
|
{
|
|
{
|
|
cfg_block_t* old_cfg;
|
|
cfg_block_t* old_cfg;
|
|
-
|
|
|
|
|
|
+
|
|
CFG_REF(block);
|
|
CFG_REF(block);
|
|
|
|
|
|
if (replaced) {
|
|
if (replaced) {
|
|
@@ -798,7 +796,7 @@ void cfg_install_global(cfg_block_t *block, void **replaced,
|
|
cb_last = cb_first;
|
|
cb_last = cb_first;
|
|
cb_first->replaced = replaced;
|
|
cb_first->replaced = replaced;
|
|
} else {
|
|
} else {
|
|
- LOG(L_ERR, "ERROR: cfg_install_global(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
/* Nothing more can be done here, the replaced strings are still needed,
|
|
/* Nothing more can be done here, the replaced strings are still needed,
|
|
* they cannot be freed at this moment.
|
|
* they cannot be freed at this moment.
|
|
*/
|
|
*/
|
|
@@ -815,21 +813,21 @@ void cfg_install_global(cfg_block_t *block, void **replaced,
|
|
cfg_install_child_cb(cb_first, cb_last);
|
|
cfg_install_child_cb(cb_first, cb_last);
|
|
|
|
|
|
CFG_UNLOCK();
|
|
CFG_UNLOCK();
|
|
-
|
|
|
|
|
|
+
|
|
if (old_cfg)
|
|
if (old_cfg)
|
|
CFG_UNREF(old_cfg);
|
|
CFG_UNREF(old_cfg);
|
|
}
|
|
}
|
|
|
|
|
|
/* creates a structure for a per-child process callback */
|
|
/* creates a structure for a per-child process callback */
|
|
cfg_child_cb_t *cfg_child_cb_new(str *gname, str *name,
|
|
cfg_child_cb_t *cfg_child_cb_new(str *gname, str *name,
|
|
- cfg_on_set_child cb,
|
|
|
|
- unsigned int type)
|
|
|
|
|
|
+ cfg_on_set_child cb,
|
|
|
|
+ unsigned int type)
|
|
{
|
|
{
|
|
cfg_child_cb_t *cb_struct;
|
|
cfg_child_cb_t *cb_struct;
|
|
|
|
|
|
cb_struct = (cfg_child_cb_t *)shm_malloc(sizeof(cfg_child_cb_t));
|
|
cb_struct = (cfg_child_cb_t *)shm_malloc(sizeof(cfg_child_cb_t));
|
|
if (!cb_struct) {
|
|
if (!cb_struct) {
|
|
- LOG(L_ERR, "ERROR: cfg_child_cb_new(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
memset(cb_struct, 0, sizeof(cfg_child_cb_t));
|
|
memset(cb_struct, 0, sizeof(cfg_child_cb_t));
|
|
@@ -868,10 +866,10 @@ void cfg_child_cb_free_list(cfg_child_cb_t *child_cb_first)
|
|
{
|
|
{
|
|
cfg_child_cb_t *cb, *cb_next;
|
|
cfg_child_cb_t *cb, *cb_next;
|
|
|
|
|
|
- for( cb = child_cb_first;
|
|
|
|
- cb;
|
|
|
|
- cb = cb_next
|
|
|
|
- ) {
|
|
|
|
|
|
+ for(cb = child_cb_first;
|
|
|
|
+ cb;
|
|
|
|
+ cb = cb_next
|
|
|
|
+ ) {
|
|
cb_next = cb->next;
|
|
cb_next = cb->next;
|
|
cfg_child_cb_free_item(cb);
|
|
cfg_child_cb_free_item(cb);
|
|
}
|
|
}
|
|
@@ -884,28 +882,28 @@ void cfg_child_cb_free_list(cfg_child_cb_t *child_cb_first)
|
|
* Note: this function is usable only before the configuration is shmized.
|
|
* Note: this function is usable only before the configuration is shmized.
|
|
*/
|
|
*/
|
|
int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
- void *val, unsigned int type)
|
|
|
|
|
|
+ void *val, unsigned int type)
|
|
{
|
|
{
|
|
cfg_group_t *group;
|
|
cfg_group_t *group;
|
|
cfg_add_var_t *add_var = NULL, **add_var_p;
|
|
cfg_add_var_t *add_var = NULL, **add_var_p;
|
|
int len;
|
|
int len;
|
|
|
|
|
|
if (type && !var_name) {
|
|
if (type && !var_name) {
|
|
- LOG(L_ERR, "ERROR: new_add_var(): Missing variable specification\n");
|
|
|
|
|
|
+ LM_ERR("Missing variable specification\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
if (type)
|
|
if (type)
|
|
- LOG(L_DBG, "DEBUG: new_add_var(): declaring a new variable instance %.*s[%u].%.*s\n",
|
|
|
|
- group_name->len, group_name->s,
|
|
|
|
- group_id,
|
|
|
|
- var_name->len, var_name->s);
|
|
|
|
|
|
+ LM_DBG("declaring a new variable instance %.*s[%u].%.*s\n",
|
|
|
|
+ group_name->len, group_name->s,
|
|
|
|
+ group_id,
|
|
|
|
+ var_name->len, var_name->s);
|
|
else
|
|
else
|
|
- LOG(L_DBG, "DEBUG: new_add_var(): declaring a new group instance %.*s[%u]\n",
|
|
|
|
- group_name->len, group_name->s,
|
|
|
|
- group_id);
|
|
|
|
|
|
+ LM_DBG("declaring a new group instance %.*s[%u]\n",
|
|
|
|
+ group_name->len, group_name->s,
|
|
|
|
+ group_id);
|
|
|
|
|
|
if (cfg_shmized) {
|
|
if (cfg_shmized) {
|
|
- LOG(L_ERR, "ERROR: new_add_var(): too late, the configuration has already been shmized\n");
|
|
|
|
|
|
+ LM_ERR("too late, the configuration has already been shmized\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -913,8 +911,8 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
if (!group) {
|
|
if (!group) {
|
|
/* create a new group with NULL values, it will be filled in later */
|
|
/* create a new group with NULL values, it will be filled in later */
|
|
group = cfg_new_group(group_name->s, group_name->len,
|
|
group = cfg_new_group(group_name->s, group_name->len,
|
|
- 0 /* num */, NULL /* mapping */,
|
|
|
|
- NULL /* vars */, 0 /* size */, NULL /* handle */);
|
|
|
|
|
|
+ 0 /* num */, NULL /* mapping */,
|
|
|
|
+ NULL /* vars */, 0 /* size */, NULL /* handle */);
|
|
|
|
|
|
if (!group)
|
|
if (!group)
|
|
goto error;
|
|
goto error;
|
|
@@ -923,13 +921,13 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
}
|
|
}
|
|
|
|
|
|
add_var = (cfg_add_var_t *)pkg_malloc(sizeof(cfg_add_var_t) +
|
|
add_var = (cfg_add_var_t *)pkg_malloc(sizeof(cfg_add_var_t) +
|
|
- (type ? (var_name->len - 1) : 0));
|
|
|
|
|
|
+ (type ? (var_name->len - 1) : 0));
|
|
if (!add_var) {
|
|
if (!add_var) {
|
|
- LOG(L_ERR, "ERROR: new_add_var(): Not enough memory\n");
|
|
|
|
|
|
+ LM_ERR("Not enough memory\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
memset(add_var, 0, sizeof(cfg_add_var_t) +
|
|
memset(add_var, 0, sizeof(cfg_add_var_t) +
|
|
- (type ? (var_name->len - 1) : 0));
|
|
|
|
|
|
+ (type ? (var_name->len - 1) : 0));
|
|
|
|
|
|
add_var->group_id = group_id;
|
|
add_var->group_id = group_id;
|
|
if (type) {
|
|
if (type) {
|
|
@@ -937,52 +935,52 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
memcpy(add_var->name, var_name->s, var_name->len);
|
|
memcpy(add_var->name, var_name->s, var_name->len);
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
- case CFG_VAR_INT:
|
|
|
|
- add_var->val.i = (int)(long)val;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case CFG_VAR_STR:
|
|
|
|
- len = ((str *)val)->len;
|
|
|
|
- if (len) {
|
|
|
|
- add_var->val.s.s = (char *)pkg_malloc(sizeof(char) * len);
|
|
|
|
- if (!add_var->val.s.s) {
|
|
|
|
- LOG(L_ERR, "ERROR: new_add_var(): Not enough memory\n");
|
|
|
|
- goto error;
|
|
|
|
|
|
+ case CFG_VAR_INT:
|
|
|
|
+ add_var->val.i = (int)(long)val;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case CFG_VAR_STR:
|
|
|
|
+ len = ((str *)val)->len;
|
|
|
|
+ if (len) {
|
|
|
|
+ add_var->val.s.s = (char *)pkg_malloc(sizeof(char) * len);
|
|
|
|
+ if (!add_var->val.s.s) {
|
|
|
|
+ LM_ERR("Not enough memory\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ memcpy(add_var->val.s.s, ((str *)val)->s, len);
|
|
|
|
+ } else {
|
|
|
|
+ add_var->val.s.s = NULL;
|
|
}
|
|
}
|
|
- memcpy(add_var->val.s.s, ((str *)val)->s, len);
|
|
|
|
- } else {
|
|
|
|
- add_var->val.s.s = NULL;
|
|
|
|
- }
|
|
|
|
- add_var->val.s.len = len;
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case CFG_VAR_STRING:
|
|
|
|
- if (val) {
|
|
|
|
- len = strlen((char *)val);
|
|
|
|
- add_var->val.ch = (char *)pkg_malloc(sizeof(char) * (len + 1));
|
|
|
|
- if (!add_var->val.ch) {
|
|
|
|
- LOG(L_ERR, "ERROR: new_add_var(): Not enough memory\n");
|
|
|
|
- goto error;
|
|
|
|
|
|
+ add_var->val.s.len = len;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case CFG_VAR_STRING:
|
|
|
|
+ if (val) {
|
|
|
|
+ len = strlen((char *)val);
|
|
|
|
+ add_var->val.ch = (char *)pkg_malloc(sizeof(char) * (len + 1));
|
|
|
|
+ if (!add_var->val.ch) {
|
|
|
|
+ LM_ERR("Not enough memory\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ memcpy(add_var->val.ch, (char *)val, len);
|
|
|
|
+ add_var->val.ch[len] = '\0';
|
|
|
|
+ } else {
|
|
|
|
+ add_var->val.ch = NULL;
|
|
}
|
|
}
|
|
- memcpy(add_var->val.ch, (char *)val, len);
|
|
|
|
- add_var->val.ch[len] = '\0';
|
|
|
|
- } else {
|
|
|
|
- add_var->val.ch = NULL;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
|
- LOG(L_ERR, "ERROR: new_add_var(): unsupported value type: %u\n",
|
|
|
|
- type);
|
|
|
|
- goto error;
|
|
|
|
|
|
+ default:
|
|
|
|
+ LM_ERR("unsupported value type: %u\n", type);
|
|
|
|
+ goto error;
|
|
}
|
|
}
|
|
add_var->type = type;
|
|
add_var->type = type;
|
|
}
|
|
}
|
|
|
|
|
|
- /* order the list by group_id, it will be easier to count the group instances */
|
|
|
|
|
|
+ /* order the list by group_id, it will be easier
|
|
|
|
+ * to count the group instances */
|
|
for( add_var_p = &group->add_var;
|
|
for( add_var_p = &group->add_var;
|
|
- *add_var_p && ((*add_var_p)->group_id <= group_id);
|
|
|
|
- add_var_p = &((*add_var_p)->next));
|
|
|
|
|
|
+ *add_var_p && ((*add_var_p)->group_id <= group_id);
|
|
|
|
+ add_var_p = &((*add_var_p)->next));
|
|
|
|
|
|
add_var->next = *add_var_p;
|
|
add_var->next = *add_var_p;
|
|
*add_var_p = add_var;
|
|
*add_var_p = add_var;
|
|
@@ -991,12 +989,13 @@ int new_add_var(str *group_name, unsigned int group_id, str *var_name,
|
|
|
|
|
|
error:
|
|
error:
|
|
if (!type)
|
|
if (!type)
|
|
- LOG(L_ERR, "ERROR: new_add_var(): failed to add the additional group instance: %.*s[%u]\n",
|
|
|
|
- group_name->len, group_name->s, group_id);
|
|
|
|
|
|
+ LM_ERR("failed to add the additional group instance: %.*s[%u]\n",
|
|
|
|
+ group_name->len, group_name->s, group_id);
|
|
else
|
|
else
|
|
- LOG(L_ERR, "ERROR: new_add_var(): failed to add the additional variable instance: %.*s[%u].%.*s\n",
|
|
|
|
- group_name->len, group_name->s, group_id,
|
|
|
|
- (var_name)?var_name->len:0, (var_name&&var_name->s)?var_name->s:"");
|
|
|
|
|
|
+ LM_ERR("failed to add the additional variable instance: %.*s[%u].%.*s\n",
|
|
|
|
+ group_name->len, group_name->s, group_id,
|
|
|
|
+ (var_name)?var_name->len:0,
|
|
|
|
+ (var_name&&var_name->s)?var_name->s:"");
|
|
|
|
|
|
if (add_var)
|
|
if (add_var)
|
|
pkg_free(add_var);
|
|
pkg_free(add_var);
|
|
@@ -1032,9 +1031,9 @@ static int apply_add_var_list(cfg_block_t *block, cfg_group_t *group)
|
|
|
|
|
|
/* count the number of group instances */
|
|
/* count the number of group instances */
|
|
for ( add_var = group->add_var, num = 0, group_id = 0;
|
|
for ( add_var = group->add_var, num = 0, group_id = 0;
|
|
- add_var;
|
|
|
|
- add_var = add_var->next
|
|
|
|
- ) {
|
|
|
|
|
|
+ add_var;
|
|
|
|
+ add_var = add_var->next
|
|
|
|
+ ) {
|
|
if (!num || (group_id != add_var->group_id)) {
|
|
if (!num || (group_id != add_var->group_id)) {
|
|
num++;
|
|
num++;
|
|
group_id = add_var->group_id;
|
|
group_id = add_var->group_id;
|
|
@@ -1044,40 +1043,41 @@ static int apply_add_var_list(cfg_block_t *block, cfg_group_t *group)
|
|
if (!num) /* nothing to do */
|
|
if (!num) /* nothing to do */
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: apply_add_var_list(): creating the group instance array "
|
|
|
|
- "for '%.*s' with %d slots\n",
|
|
|
|
- group->name_len, group->name, num);
|
|
|
|
|
|
+ LM_DBG("creating the group instance array "
|
|
|
|
+ "for '%.*s' with %d slots\n",
|
|
|
|
+ group->name_len, group->name, num);
|
|
size = (sizeof(cfg_group_inst_t) + group->size - 1) * num;
|
|
size = (sizeof(cfg_group_inst_t) + group->size - 1) * num;
|
|
new_array = (cfg_group_inst_t *)shm_malloc(size);
|
|
new_array = (cfg_group_inst_t *)shm_malloc(size);
|
|
if (!new_array) {
|
|
if (!new_array) {
|
|
- LOG(L_ERR, "ERROR: apply_add_var_list(): not enough shm memory\n");
|
|
|
|
|
|
+ LM_ERR("not enough shm memory\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
memset(new_array, 0, size);
|
|
memset(new_array, 0, size);
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
for (i = 0; i < num; i++) {
|
|
/* Go though each group instance, set the default values,
|
|
/* Go though each group instance, set the default values,
|
|
- and apply the changes */
|
|
|
|
|
|
+ * and apply the changes */
|
|
|
|
|
|
if (!group->add_var) {
|
|
if (!group->add_var) {
|
|
- LOG(L_ERR, "BUG: apply_add_var_list(): no more additional variable left\n");
|
|
|
|
|
|
+ LM_ERR("BUG: no more additional variable left\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
- ginst = (cfg_group_inst_t *)((char*)new_array + (sizeof(cfg_group_inst_t) + group->size - 1) * i);
|
|
|
|
|
|
+ ginst = (cfg_group_inst_t *)((char*)new_array
|
|
|
|
+ + (sizeof(cfg_group_inst_t) + group->size - 1) * i);
|
|
ginst->id = group->add_var->group_id;
|
|
ginst->id = group->add_var->group_id;
|
|
/* fill in the new group instance with the default data */
|
|
/* fill in the new group instance with the default data */
|
|
memcpy( ginst->vars,
|
|
memcpy( ginst->vars,
|
|
- CFG_GROUP_DATA(block, group),
|
|
|
|
- group->size);
|
|
|
|
|
|
+ CFG_GROUP_DATA(block, group),
|
|
|
|
+ group->size);
|
|
/* cfg_apply_list() moves the group->add_var pointer to
|
|
/* cfg_apply_list() moves the group->add_var pointer to
|
|
- the beginning of the new group instance. */
|
|
|
|
|
|
+ * the beginning of the new group instance. */
|
|
if (cfg_apply_list(ginst, group, ginst->id, &group->add_var))
|
|
if (cfg_apply_list(ginst, group, ginst->id, &group->add_var))
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef EXTRA_DEBUG
|
|
#ifdef EXTRA_DEBUG
|
|
if (group->add_var) {
|
|
if (group->add_var) {
|
|
- LOG(L_ERR, "BUG: apply_add_var_list(): not all the additional variables have been consumed\n");
|
|
|
|
|
|
+ LM_ERR("not all the additional variables have been consumed\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
@@ -1088,14 +1088,14 @@ static int apply_add_var_list(cfg_block_t *block, cfg_group_t *group)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
error:
|
|
error:
|
|
- LOG(L_ERR, "ERROR: apply_add_var_list(): Failed to apply the additional variable list\n");
|
|
|
|
|
|
+ LM_ERR("failed to apply the additional variable list\n");
|
|
shm_free(new_array);
|
|
shm_free(new_array);
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
/* Move the group handle to the specified group instance pointed by dst_ginst.
|
|
/* Move the group handle to the specified group instance pointed by dst_ginst.
|
|
* src_ginst shall point to the active group instance.
|
|
* src_ginst shall point to the active group instance.
|
|
- * Both parameters can be NULL meaning that the src/dst config is the default,
|
|
|
|
|
|
+ * Both parameters can be NULL meaning that the src/dst config is the default,
|
|
* not an additional group instance.
|
|
* not an additional group instance.
|
|
* The function executes all the per-child process callbacks which are different
|
|
* The function executes all the per-child process callbacks which are different
|
|
* in the two instaces.
|
|
* in the two instaces.
|
|
@@ -1111,18 +1111,18 @@ void cfg_move_handle(cfg_group_t *group, cfg_group_inst_t *src_ginst, cfg_group_
|
|
return; /* nothing to do */
|
|
return; /* nothing to do */
|
|
|
|
|
|
/* move the handle to the variables of the dst group instance,
|
|
/* move the handle to the variables of the dst group instance,
|
|
- or to the local config if no dst group instance is specified */
|
|
|
|
|
|
+ * or to the local config if no dst group instance is specified */
|
|
*(group->handle) = dst_ginst ?
|
|
*(group->handle) = dst_ginst ?
|
|
- dst_ginst->vars
|
|
|
|
- : CFG_GROUP_DATA(cfg_local, group);
|
|
|
|
|
|
+ dst_ginst->vars
|
|
|
|
+ : CFG_GROUP_DATA(cfg_local, group);
|
|
|
|
|
|
if (cfg_child_cb != CFG_NO_CHILD_CBS) {
|
|
if (cfg_child_cb != CFG_NO_CHILD_CBS) {
|
|
/* call the per child process callback of those variables
|
|
/* call the per child process callback of those variables
|
|
- that have different value in the two group instances */
|
|
|
|
|
|
+ * that have different value in the two group instances */
|
|
/* TODO: performance optimization: this entire loop can be
|
|
/* TODO: performance optimization: this entire loop can be
|
|
- skipped if the group does not have any variable with
|
|
|
|
- per-child process callback. Use some flag in the group
|
|
|
|
- structure for this purpose. */
|
|
|
|
|
|
+ * skipped if the group does not have any variable with
|
|
|
|
+ * per-child process callback. Use some flag in the group
|
|
|
|
+ * structure for this purpose. */
|
|
gname.s = group->name;
|
|
gname.s = group->name;
|
|
gname.len = group->name_len;
|
|
gname.len = group->name_len;
|
|
for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
|
|
for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
|
|
@@ -1147,8 +1147,8 @@ void cfg_move_handle(cfg_group_t *group, cfg_group_inst_t *src_ginst, cfg_group_
|
|
cfg_ginst_count--;
|
|
cfg_ginst_count--;
|
|
#ifdef EXTRA_DEBUG
|
|
#ifdef EXTRA_DEBUG
|
|
if (cfg_ginst_count < 0)
|
|
if (cfg_ginst_count < 0)
|
|
- LOG(L_ERR, "ERROR: cfg_select(): BUG, cfg_ginst_count is negative: %d. group=%.*s\n",
|
|
|
|
- cfg_ginst_count, group->name_len, group->name);
|
|
|
|
|
|
+ LM_ERR("BUG: cfg_ginst_count is negative: %d. group=%.*s\n",
|
|
|
|
+ cfg_ginst_count, group->name_len, group->name);
|
|
#endif
|
|
#endif
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1159,15 +1159,15 @@ int cfg_select(cfg_group_t *group, unsigned int id)
|
|
cfg_group_inst_t *ginst;
|
|
cfg_group_inst_t *ginst;
|
|
|
|
|
|
if (!cfg_local) {
|
|
if (!cfg_local) {
|
|
- LOG(L_ERR, "ERROR: The child process has no local configuration\n");
|
|
|
|
|
|
+ LM_ERR("The child process has no local configuration\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
if (!(ginst = cfg_find_group(CFG_GROUP_META(cfg_local, group),
|
|
if (!(ginst = cfg_find_group(CFG_GROUP_META(cfg_local, group),
|
|
- group->size,
|
|
|
|
- id))
|
|
|
|
- ) {
|
|
|
|
- LOG(L_ERR, "ERROR: cfg_select(): group instance '%.*s[%u]' does not exist\n",
|
|
|
|
|
|
+ group->size,
|
|
|
|
+ id))
|
|
|
|
+ ) {
|
|
|
|
+ LM_ERR("group instance '%.*s[%u]' does not exist\n",
|
|
group->name_len, group->name, id);
|
|
group->name_len, group->name, id);
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -1176,7 +1176,7 @@ int cfg_select(cfg_group_t *group, unsigned int id)
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
ginst);
|
|
ginst);
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_select(): group instance '%.*s[%u]' has been selected\n",
|
|
|
|
|
|
+ LM_DBG("group instance '%.*s[%u]' has been selected\n",
|
|
group->name_len, group->name, id);
|
|
group->name_len, group->name, id);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1185,7 +1185,7 @@ int cfg_select(cfg_group_t *group, unsigned int id)
|
|
int cfg_reset(cfg_group_t *group)
|
|
int cfg_reset(cfg_group_t *group)
|
|
{
|
|
{
|
|
if (!cfg_local) {
|
|
if (!cfg_local) {
|
|
- LOG(L_ERR, "ERROR: The child process has no local configuration\n");
|
|
|
|
|
|
+ LM_ERR("The child process has no local configuration\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1193,7 +1193,7 @@ int cfg_reset(cfg_group_t *group)
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
NULL);
|
|
NULL);
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_reset(): default group '%.*s' has been selected\n",
|
|
|
|
|
|
+ LM_DBG("default group '%.*s' has been selected\n",
|
|
group->name_len, group->name);
|
|
group->name_len, group->name);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1212,7 +1212,7 @@ int cfg_select_first(cfg_group_t *group)
|
|
cfg_group_inst_t *ginst;
|
|
cfg_group_inst_t *ginst;
|
|
|
|
|
|
if (!cfg_local) {
|
|
if (!cfg_local) {
|
|
- LOG(L_ERR, "ERROR: The child process has no local configuration\n");
|
|
|
|
|
|
+ LM_ERR("The child process has no local configuration\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1225,7 +1225,7 @@ int cfg_select_first(cfg_group_t *group)
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
|
|
ginst);
|
|
ginst);
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_select_first(): group instance '%.*s[%u]' has been selected\n",
|
|
|
|
|
|
+ LM_DBG("group instance '%.*s[%u]' has been selected\n",
|
|
group->name_len, group->name, ginst->id);
|
|
group->name_len, group->name, ginst->id);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1246,14 +1246,16 @@ int cfg_select_next(cfg_group_t *group)
|
|
int size;
|
|
int size;
|
|
|
|
|
|
if (!cfg_local) {
|
|
if (!cfg_local) {
|
|
- LOG(L_ERR, "ERROR: The child process has no local configuration\n");
|
|
|
|
|
|
+ LM_ERR("The child process has no local configuration\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
meta = CFG_GROUP_META(cfg_local, group);
|
|
meta = CFG_GROUP_META(cfg_local, group);
|
|
|
|
|
|
- if (!(old_ginst = CFG_HANDLE_TO_GINST(*(group->handle)) /* the active group instance */)) {
|
|
|
|
- LOG(L_ERR, "ERROR: cfg_select_next(): No group instance is set currently. Forgot to call cfg_select_first()?\n");
|
|
|
|
|
|
+ if (!(old_ginst = CFG_HANDLE_TO_GINST(*(group->handle))
|
|
|
|
+ /* the active group instance */)) {
|
|
|
|
+ LM_ERR("No group instance is set currently."
|
|
|
|
+ "Forgot to call cfg_select_first()?\n");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1266,7 +1268,7 @@ int cfg_select_next(cfg_group_t *group)
|
|
old_ginst, /* the active group instance */
|
|
old_ginst, /* the active group instance */
|
|
new_ginst);
|
|
new_ginst);
|
|
|
|
|
|
- LOG(L_DBG, "DEBUG: cfg_select_next(): group instance '%.*s[%u]' has been selected\n",
|
|
|
|
|
|
+ LM_DBG("group instance '%.*s[%u]' has been selected\n",
|
|
group->name_len, group->name, new_ginst->id);
|
|
group->name_len, group->name, new_ginst->id);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1299,9 +1301,9 @@ void cfg_main_reset_local(void)
|
|
|
|
|
|
/* restore the original value of the module handles */
|
|
/* restore the original value of the module handles */
|
|
for ( group = cfg_group;
|
|
for ( group = cfg_group;
|
|
- group;
|
|
|
|
- group = group->next
|
|
|
|
- )
|
|
|
|
|
|
+ group;
|
|
|
|
+ group = group->next
|
|
|
|
+ )
|
|
*(group->handle) = group->orig_handle;
|
|
*(group->handle) = group->orig_handle;
|
|
/* The handle might have pointed to a group instance,
|
|
/* The handle might have pointed to a group instance,
|
|
* reset the instance counter. */
|
|
* reset the instance counter. */
|
|
@@ -1309,5 +1311,3 @@ void cfg_main_reset_local(void)
|
|
}
|
|
}
|
|
cfg_child_cb = NULL;
|
|
cfg_child_cb = NULL;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|