Skip to content

Commit

Permalink
domain: port MI commands to jsonrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Jan 10, 2019
1 parent dc5d586 commit 3c3fac8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
13 changes: 9 additions & 4 deletions modules/domain/domain_mod.c
Expand Up @@ -136,12 +136,17 @@ static param_export_t params[] = {
* Exported MI functions
*/
static mi_export_t mi_cmds[] = {
{ MI_DOMAIN_RELOAD, 0, mi_domain_reload, MI_NO_INPUT_FLAG, 0, mi_child_init },
{ MI_DOMAIN_DUMP, 0, mi_domain_dump, MI_NO_INPUT_FLAG, 0, 0 },
{ 0, 0, 0, 0, 0, 0}
{ MI_DOMAIN_RELOAD, 0, 0, mi_child_init, {
{mi_domain_reload, {0}},
{EMPTY_MI_RECIPE}}
},
{ MI_DOMAIN_DUMP, 0, 0, 0, {
{mi_domain_dump, {0}},
{EMPTY_MI_RECIPE}}
},
{EMPTY_MI_EXPORT}
};


/*
* Module interface
*/
Expand Down
22 changes: 11 additions & 11 deletions modules/domain/hash.c
Expand Up @@ -92,28 +92,28 @@ int hash_table_lookup (struct sip_msg *msg, str *domain, pv_spec_t *pv)
}


int hash_table_mi_print(struct domain_list **hash_table, struct mi_node* rpl)
int hash_table_mi_print(struct domain_list **hash_table, mi_item_t *domains_arr)
{
int i;
struct domain_list *np;
struct mi_node* node;
mi_item_t *domain_item;

if(hash_table==0)
return -1;
for (i = 0; i < DOM_HASH_SIZE; i++) {
np = hash_table[i];
while (np) {
node = add_mi_node_child(rpl, 0, 0, 0,
np->domain.s, np->domain.len);
if(node == 0)
domain_item = add_mi_object(domains_arr, NULL, 0);
if (!domain_item)
return -1;
if (np->attrs.s) {
if (!add_mi_attr(node, 0, "attributes", 10,
np->attrs.s, np->attrs.len)) {
LM_ERR("cannot add attributes\n");

if (add_mi_string(domain_item, MI_SSTR("name"),
np->domain.s, np->domain.len) < 0)
return -1;
if (np->attrs.s)
if (add_mi_string(domain_item, MI_SSTR("attributes"),
np->attrs.s, np->attrs.len) < 0)
return -1;
}
}

np = np->next;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/domain/hash.h
Expand Up @@ -30,7 +30,7 @@

int hash_table_install (struct domain_list **hash_table, str *d, str *a);
int hash_table_lookup (struct sip_msg *msg, str *domain, pv_spec_t *pv);
int hash_table_mi_print(struct domain_list **hash_table, struct mi_node* rpl);
int hash_table_mi_print(struct domain_list **hash_table, mi_item_t *domains_arr);
void hash_table_free (struct domain_list **hash_table);

#endif
38 changes: 23 additions & 15 deletions modules/domain/mi.c
Expand Up @@ -36,40 +36,48 @@
/*
* MI function to reload domain table
*/
struct mi_root* mi_domain_reload(struct mi_root *cmd_tree, void *param)
mi_response_t *mi_domain_reload(const mi_params_t *params,
struct mi_handler *async_hdl)
{
if(db_mode==0)
return init_mi_tree( 500, "command not activated", 21);
return init_mi_error( 500, MI_SSTR("command not activated"));

if (reload_domain_table () == 1) {
return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
return init_mi_result_ok();
} else {
return init_mi_tree( 500, "Domain table reload failed", 26);
return init_mi_error( 500, MI_SSTR("Domain table reload failed"));
}
}


/*
* MI function to print domains from current hash table
*/
struct mi_root* mi_domain_dump(struct mi_root *cmd_tree, void *param)
mi_response_t *mi_domain_dump(const mi_params_t *params,
struct mi_handler *async_hdl)
{
struct mi_root* rpl_tree;
mi_response_t *resp;
mi_item_t *resp_obj, *domains_arr;

if(db_mode==0)
return init_mi_tree( 500, "command not activated", 21);
return init_mi_error(500, MI_SSTR("command not activated"));

rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
if (rpl_tree==NULL)
resp = init_mi_result_object(&resp_obj);
if (!resp)
return 0;
rpl_tree->node.flags |= MI_IS_ARRAY;
domains_arr = add_mi_array(resp_obj, MI_SSTR("Domains"));
if (!domains_arr)
goto error;

if(hash_table_mi_print(*hash_table, &rpl_tree->node)< 0)
if(hash_table_mi_print(*hash_table, domains_arr)< 0)
{
LM_ERR("Error while adding node\n");
free_mi_tree(rpl_tree);
return 0;
LM_ERR("Error while adding item\n");
goto error;
}

return rpl_tree;
return resp;

error:
free_mi_response(resp);
return 0;
}
7 changes: 4 additions & 3 deletions modules/domain/mi.h
Expand Up @@ -30,9 +30,10 @@
#define MI_DOMAIN_DUMP "domain_dump"


struct mi_root* mi_domain_reload(struct mi_root *cmd, void *param);

struct mi_root* mi_domain_dump(struct mi_root *cmd, void *param);
mi_response_t *mi_domain_reload(const mi_params_t *params,
struct mi_handler *async_hdl);
mi_response_t *mi_domain_dump(const mi_params_t *params,
struct mi_handler *async_hdl);


#endif

0 comments on commit 3c3fac8

Please sign in to comment.