mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 23:08:32 +00:00
core: Config and XML tweaks needed for geolocation
Added:
Replace a variable in a list:
int ast_variable_list_replace_variable(struct ast_variable **head,
struct ast_variable *old, struct ast_variable *new);
Added test as well.
Create a "name=value" string from a variable list:
'name1="val1",name2="val2"', etc.
struct ast_str *ast_variable_list_join(
const struct ast_variable *head, const char *item_separator,
const char *name_value_separator, const char *quote_char,
struct ast_str **str);
Added test as well.
Allow the name of an XML element to be changed.
void ast_xml_set_name(struct ast_xml_node *node, const char *name);
Change-Id: I330a5f63dc0c218e0d8dfc0745948d2812141ccb
This commit is contained in:
committed by
Friendly Automation
parent
466a361626
commit
83372e7ab5
@@ -679,6 +679,49 @@ int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *r
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ast_variable_list_replace_variable(struct ast_variable **head, struct ast_variable *old,
|
||||
struct ast_variable *new)
|
||||
{
|
||||
struct ast_variable *v, **prev = head;
|
||||
|
||||
for (v = *head; v; prev = &v->next, v = v->next) {
|
||||
if (v == old) {
|
||||
new->next = v->next;
|
||||
*prev = new;
|
||||
ast_free(v);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ast_str *ast_variable_list_join(const struct ast_variable *head, const char *item_separator,
|
||||
const char *name_value_separator, const char *quote_char, struct ast_str **str)
|
||||
{
|
||||
struct ast_variable *var = (struct ast_variable *)head;
|
||||
struct ast_str *local_str = NULL;
|
||||
|
||||
if (str == NULL || *str == NULL) {
|
||||
local_str = ast_str_create(AST_MAX_USER_FIELD);
|
||||
if (!local_str) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
local_str = *str;
|
||||
}
|
||||
|
||||
for (; var; var = var->next) {
|
||||
ast_str_append(&local_str, 0, "%s%s%s%s%s%s", var->name, name_value_separator, S_OR(quote_char, ""),
|
||||
var->value, S_OR(quote_char, ""), var->next ? item_separator : "");
|
||||
}
|
||||
|
||||
if (str != NULL) {
|
||||
*str = local_str;
|
||||
}
|
||||
return local_str;
|
||||
}
|
||||
|
||||
const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
Reference in New Issue
Block a user