struct mi_root *mi_set_shtag_active(struct mi_root *cmd_tree, void *param) { struct mi_node* node; struct dlg_sharing_tag *tag; if (!dialog_repl_cluster) return init_mi_tree(400, MI_SSTR("Dialog replication disabled")); node = cmd_tree->node.kids; if (node == NULL || !node->value.s || !node->value.len) return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM)); lock_start_write(shtags_lock); if ((tag = get_shtag_unsafe(&node->value)) == NULL) return init_mi_tree(500, MI_SSTR("Unable to set sharing tag")); tag->state = SHTAG_STATE_ACTIVE; lock_stop_write(shtags_lock); if (send_shtag_active_info(&node->value, 0) < 0) LM_WARN("Failed to broadcast message about tag [%.*s] going active\n", node->value.len, node->value.s); return init_mi_tree( 200, MI_SSTR(MI_OK)); }
static struct mi_root *mi_debug(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *node; char *p; int len; int new_debug; node = cmd->node.kids; if (node!=NULL) { if (str2sint( &node->value, &new_debug) < 0) return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM)); } else new_debug = debug; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==0) return 0; p = sint2str((long)new_debug, &len); node = add_mi_node_child( &rpl_tree->node, MI_DUP_VALUE, MI_SSTR("DEBUG"),p, len); if (node==0) { free_mi_tree(rpl_tree); return 0; } debug = new_debug; return rpl_tree; }
static struct mi_root* clusterer_set_status(struct mi_root *cmd, void *param) { unsigned int cluster_id; unsigned int state; int rc; struct mi_node *node; node = cmd->node.kids; if (node == NULL || node->next == NULL || node->next->next != NULL) return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rc = str2int(&node->value, &cluster_id); if (rc < 0 || cluster_id < 1) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); rc = str2int(&node->next->value, &state); if (rc < 0 || (state != STATE_DISABLED && state != STATE_ENABLED)) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); rc = cl_set_state(cluster_id, state); if (rc == -1) return init_mi_tree(404, "Cluster id not found", 20); if (rc == 1) return init_mi_tree(404, "Node id not found", 17); return init_mi_tree(200, MI_SSTR(MI_OK)); }
static mi_response_t *clusterer_set_status(const mi_params_t *params, struct mi_handler *async_hdl) { int cluster_id; int state; int rc; if (get_mi_int_param(params, "cluster_id", &cluster_id) < 0) return init_mi_param_error(); if (cluster_id < 1) return init_mi_error(400, MI_SSTR("Bad value for 'cluster_id'")); if (get_mi_int_param(params, "status", &state) < 0) return init_mi_param_error(); if (state != STATE_DISABLED && state != STATE_ENABLED) return init_mi_error(400, MI_SSTR("Bad value for 'status'")); rc = cl_set_state(cluster_id, state); if (rc == -1) return init_mi_error(404, MI_SSTR("Cluster id not found")); if (rc == 1) return init_mi_error(404, MI_SSTR("Node id not found")); return init_mi_result_ok(); }
struct mi_root* mi_sync_db_dlg(struct mi_root *cmd, void *param) { if (sync_dlg_db_mem() < 0) return init_mi_tree( 400, MI_SSTR("Sync mem with DB failed")); else return init_mi_tree( 200, MI_SSTR(MI_OK)); }
static mi_response_t *mi_list_root_path(const mi_params_t *params, struct mi_handler *async_hdl) { mi_response_t *resp; mi_item_t *resp_arr; mi_item_t *root_item; struct httpd_cb *cb = httpd_cb_list; resp = init_mi_result_array(&resp_arr); if (!resp) return 0; while(cb) { root_item = add_mi_object(resp_arr, 0, 0); if (!root_item) goto error; if (add_mi_string(root_item, MI_SSTR("http_root"), cb->http_root->s, cb->http_root->len) < 0) goto error; if (add_mi_string(root_item, MI_SSTR("module"), (char*)cb->module, strlen(cb->module)) < 0) goto error; cb = cb->next; } return resp; error: free_mi_response(resp); return 0; }
/*! \brief * MI function to reload address table */ struct mi_root* mi_address_reload(struct mi_root *cmd_tree, void *param) { if (reload_address_table_cmd () == 1) { return init_mi_tree( 200, MI_SSTR(MI_OK)); } else { return init_mi_tree( 400, MI_SSTR("Address table reload failed")); } }
static struct mi_root* mi_lb_resize(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct lb_dst *dst; struct mi_node *node; unsigned int id, size; str *name; int n; for( n=0,node = cmd->node.kids; n<3 && node ; n++,node=node->next ); if (n!=3 || node!=0) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); node = cmd->node.kids; /* id (param 1) */ if (str2int( &node->value, &id) < 0) goto bad_syntax; /* resource (param 2) */ node = node->next; name = &node->value; /* id (param 3) */ node = node->next; if (str2int( &node->value, &size) < 0) goto bad_syntax; lock_start_read( ref_lock ); /* get destination */ for( dst=(*curr_data)->dsts ; dst && dst->id!=id ; dst=dst->next); if (dst==NULL) { rpl_tree = init_mi_tree( 404, MI_SSTR("Destination ID not found")); } else { /* get resource */ for( n=0 ; n<dst->rmap_no ; n++) if (dst->rmap[n].resource->name.len == name->len && memcmp( dst->rmap[n].resource->name.s, name->s, name->len)==0) break; if (n==dst->rmap_no) { rpl_tree = init_mi_tree( 404, MI_SSTR("Destination has no such resource")); } else { dst->rmap[n].max_load = size; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK_S)); } } lock_stop_read( ref_lock ); return rpl_tree; bad_syntax: return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM_S)); }
struct mi_root* mi_sync_cl_dlg(struct mi_root *cmd, void *param) { if (!dialog_repl_cluster) return init_mi_tree(400, MI_SSTR("Dialog replication disabled")); if (clusterer_api.request_sync(&dlg_repl_cap, dialog_repl_cluster, 1) < 0) return init_mi_tree(400, MI_SSTR("Failed to send sync request")); else return init_mi_tree(200, MI_SSTR(MI_OK)); }
struct mi_root *mi_help(struct mi_root *root, void *param) { struct mi_root *rpl_tree = 0; struct mi_node *node; struct mi_node *rpl; struct mi_cmd *cmd; if (!root) { LM_ERR("invalid MI command\n"); return 0; } node = root->node.kids; if (!node || !node->value.len || !node->value.s) { rpl_tree = init_mi_tree(200, MI_SSTR(MI_OK)); if (!rpl_tree) { LM_ERR("cannot init mi tree\n"); return 0; } rpl = &rpl_tree->node; if (!add_mi_node_child(rpl, 0, "Usage", 5, MI_SSTR(MI_HELP_STR))) { LM_ERR("cannot add new child\n"); goto error; } } else { /* search the command */ cmd = lookup_mi_cmd(node->value.s, node->value.len); if (!cmd) return init_mi_tree(404, MI_SSTR(MI_UNKNOWN_CMD)); rpl_tree = init_mi_tree(200, MI_SSTR(MI_OK)); if (!rpl_tree) { LM_ERR("cannot init mi tree\n"); return 0; } rpl = &rpl_tree->node; if (!addf_mi_node_child(rpl, 0, "Help", 4, "%s", cmd->help.s ? cmd->help.s : MI_NO_HELP)) { LM_ERR("cannot add new child\n"); goto error; } if (cmd->module.len && cmd->module.s && !add_mi_node_child(rpl, 0, "Exported by", 11, cmd->module.s, cmd->module.len)) { LM_ERR("cannot add new child\n"); goto error; } } return rpl_tree; error: if (rpl_tree) free_mi_tree(rpl_tree); return 0; }
static inline struct mi_root* process_mi_params(struct mi_root *cmd_tree, struct dlg_cell **dlg_p) { struct mi_node* node; struct dlg_entry *d_entry; struct dlg_cell *dlg; str *callid; str *from_tag; unsigned int h_entry; node = cmd_tree->node.kids; if (node == NULL) { /* no parameters at all */ *dlg_p = NULL; return NULL; } /* we have params -> get callid and fromtag */ callid = &node->value; if(callid->s==NULL || callid->len<=0) return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM)); LM_DBG("callid='%.*s'\n", callid->len, callid->s); node = node->next; if ( !node || !node->value.s || !node->value.len) { from_tag = NULL; } else { from_tag = &node->value; LM_DBG("from_tag='%.*s'\n", from_tag->len, from_tag->s); if ( node->next!=NULL ) return init_mi_tree( 400, MI_SSTR(MI_MISSING_PARM)); } h_entry = core_hash( callid, 0, d_table->size); d_entry = &(d_table->entries[h_entry]); dlg_lock( d_table, d_entry); for( dlg = d_entry->first ; dlg ; dlg = dlg->next ) { if (match_downstream_dialog( dlg, callid, from_tag)==1) { if (dlg->state==DLG_STATE_DELETED) { *dlg_p = NULL; break; } else { *dlg_p = dlg; dlg_unlock( d_table, d_entry); return 0; } } } dlg_unlock( d_table, d_entry); return init_mi_tree( 404, MI_SSTR("Nu such dialog")); }
/* FORMAT : agent_id log_state */ static struct mi_root* mi_agent_login(struct mi_root *cmd_tree, void *param) { struct mi_node *node; struct cc_agent *agent; unsigned int loged_in; struct cc_agent* prev_agent= 0; node = cmd_tree->node.kids; if (node==NULL || node->next==NULL || node->next->next!=NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); /* block access to data */ lock_get( data->lock ); /* name of the agent */ agent = get_agent_by_name( data, &node->value, &prev_agent); if (agent==NULL) { lock_release( data->lock ); return init_mi_tree( 404, MI_SSTR("Agent not found") ); } /* login state */ node = node->next; if (str2int( &node->value , &loged_in)!=0 ) { lock_release( data->lock ); return init_mi_tree( 400, MI_SSTR("Bad loged_in state") ); } if (agent->loged_in != loged_in) { if(loged_in && (agent->state==CC_AGENT_WRAPUP) && (get_ticks() - agent->last_call_end > wrapup_time)) agent->state = CC_AGENT_FREE; if(loged_in && data->agents[CC_AG_ONLINE] == NULL) data->last_online_agent = agent; agent_switch_login(data, agent, prev_agent); if(loged_in) { data->logedin_agents++; log_agent_to_flows( data, agent, 1); } else { data->logedin_agents--; log_agent_to_flows(data, agent, 0); } } /* release the readers */ lock_release( data->lock ); return init_mi_tree( 200, MI_OK_S, MI_OK_LEN); }
static inline int internal_mi_print_b2bl_entity_id(mi_item_t *item, b2bl_entity_id_t *c) { if (c->scenario_id.s && c->scenario_id.len != 0) if (add_mi_string(item, MI_SSTR("scenario_id"), c->scenario_id.s, c->scenario_id.len) < 0) goto error; if (c->key.s && c->key.len != 0) if (add_mi_string(item, MI_SSTR("key"), c->key.s, c->key.len) < 0) goto error; if (add_mi_number(item, MI_SSTR("disconnected"), c->disconnected) < 0) goto error; if (add_mi_number(item, MI_SSTR("state"), c->state) < 0) goto error; if (add_mi_number(item, MI_SSTR("no"), c->no) < 0) goto error; if (add_mi_number(item, MI_SSTR("type"), c->type) < 0) goto error; if (c->peer) { if (c->peer->key.s && c->peer->key.len != 0) if (add_mi_string(item, MI_SSTR("peer"), c->peer->key.s, c->peer->key.len) < 0) goto error; } if (c->to_uri.s && c->to_uri.len != 0) if (add_mi_string(item, MI_SSTR("to_uri"), c->to_uri.s, c->to_uri.len) < 0) goto error; if (c->from_uri.s && c->from_uri.len != 0) if (add_mi_string(item, MI_SSTR("from_uri"), c->from_uri.s, c->from_uri.len) < 0) goto error; if (c->from_dname.s && c->from_dname.len != 0) if (add_mi_string(item, MI_SSTR("from_dname"), c->from_dname.s, c->from_dname.len) < 0) goto error; return 0; error: LM_ERR("failed to add mi item\n"); return -1; }
/* * MI function to reload trusted table */ struct mi_root* mi_trusted_reload(struct mi_root *cmd_tree, void *param) { if (hash_table==NULL) { return init_mi_tree( 200, MI_SSTR(MI_OK)); } if (reload_trusted_table () == 1) { return init_mi_tree( 200, MI_SSTR(MI_OK)); } else { return init_mi_tree( 400, MI_SSTR("Trusted table reload failed")); } }
static struct mi_root* cluster_send_mi(struct mi_root *cmd, void *param) { struct mi_node *node, *cmd_params_n; unsigned int cluster_id, node_id; int rc; str cl_cmd_name; str cl_cmd_params[MI_CMD_MAX_NR_PARAMS]; int no_params = 0; node = cmd->node.kids; if (node == NULL || node->next == NULL || node->next->next == NULL) return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM)); rc = str2int(&node->value, &cluster_id); if (rc < 0 || cluster_id < 1) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); rc = str2int(&node->next->value, &node_id); if (rc < 0 || node_id < 1) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); if (node_id == current_id) return init_mi_tree(400, MI_SSTR("Local node specified as destination")); cl_cmd_name = node->next->next->value; cmd_params_n = node->next->next->next; for (; cmd_params_n; cmd_params_n = cmd_params_n->next, no_params++) cl_cmd_params[no_params] = cmd_params_n->value; /* send MI cmd in cluster */ rc = send_mi_cmd(cluster_id, node_id, cl_cmd_name, cl_cmd_params, no_params); switch (rc) { case CLUSTERER_SEND_SUCCES: LM_DBG("MI command <%.*s> sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_CURR_DISABLED: LM_INFO("Local node disabled, MI command <%.*s> not sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_DEST_DOWN: LM_ERR("Destination down, MI command <%.*s> not sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_SEND_ERR: LM_ERR("Error sending MI command <%.*s>+\n", cl_cmd_name.len, cl_cmd_name.s); break; } return init_mi_tree(200, MI_SSTR(MI_OK)); }
static struct mi_root* cluster_bcast_mi(struct mi_root *cmd, void *param) { struct mi_node *node, *cmd_params_n; struct mi_cmd *f; unsigned int cluster_id; int rc; str cl_cmd_name; str cl_cmd_params[MI_CMD_MAX_NR_PARAMS]; int no_params = 0; node = cmd->node.kids; if (node == NULL || node->next == NULL || node->next->next == NULL) return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM)); rc = str2int(&node->value, &cluster_id); if (rc < 0 || cluster_id < 1) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); cl_cmd_name = node->next->value; f = lookup_mi_cmd(cl_cmd_name.s, cl_cmd_name.len); if (!f) return init_mi_tree(400, MI_SSTR("MI command to be run not found")); cmd_params_n = node->next->next; for (; cmd_params_n; cmd_params_n = cmd_params_n->next, no_params++) cl_cmd_params[no_params] = cmd_params_n->value; /* send MI cmd in cluster */ rc = send_mi_cmd(cluster_id, 0, cl_cmd_name, cl_cmd_params, no_params); switch (rc) { case CLUSTERER_SEND_SUCCES: LM_DBG("MI command <%.*s> sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_CURR_DISABLED: LM_INFO("Local node disabled, MI command <%.*s> not sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_DEST_DOWN: LM_ERR("All nodes down, MI command <%.*s> not sent\n", cl_cmd_name.len, cl_cmd_name.s); break; case CLUSTERER_SEND_ERR: LM_ERR("Error sending MI command <%.*s>+\n", cl_cmd_name.len, cl_cmd_name.s); break; } /* run MI cmd locally */ return run_mi_cmd_local(f, cl_cmd_params, no_params, cmd->async_hdl); }
static struct mi_root * clusterer_list_cap(struct mi_root *cmd_tree, void *param) { cluster_info_t *cl; struct local_cap *cap; struct mi_root *rpl_tree = NULL; struct mi_node *node = NULL; struct mi_node *node_s = NULL; struct mi_attr* attr; str val; static str str_ok = str_init("Ok"); static str str_not_synced = str_init("not synced"); rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN); if (!rpl_tree) return NULL; rpl_tree->node.flags |= MI_IS_ARRAY; lock_start_read(cl_list_lock); for (cl = *cluster_list; cl; cl = cl->next) { val.s = int2str(cl->cluster_id, &val.len); node = add_mi_node_child(&rpl_tree->node, MI_DUP_VALUE|MI_IS_ARRAY, MI_SSTR("Cluster"), val.s, val.len); if (!node) goto error; for (cap = cl->capabilities; cap; cap = cap->next) { val.s = cap->reg.name.s; val.len = cap->reg.name.len; node_s = add_mi_node_child(node, MI_DUP_VALUE|MI_IS_ARRAY, MI_SSTR("Capability"), val.s, val.len); if (!node_s) goto error; lock_get(cl->lock); val.s = int2str((cap->flags & CAP_STATE_OK) ? 1 : 0, &val.len); lock_release(cl->lock); attr = add_mi_attr(node_s, MI_DUP_VALUE, MI_SSTR("State"), (cap->flags & CAP_STATE_OK) ? str_ok.s : str_not_synced.s, (cap->flags & CAP_STATE_OK) ? str_ok.len : str_not_synced.len); if (!attr) goto error; } } lock_stop_read(cl_list_lock); return rpl_tree; error: lock_stop_read(cl_list_lock); if (rpl_tree) free_mi_tree(rpl_tree); return NULL; }
/*! * \brief Print a dialog context via the MI interface * \param cmd_tree MI command tree * \param param unused * \return mi node with the dialog information, or NULL on failure */ struct mi_root * mi_print_dlgs_ctx(struct mi_root *cmd_tree, void *param ) { struct mi_root* rpl_tree= NULL; struct mi_node* rpl = NULL; struct dlg_cell* dlg = NULL; rpl_tree = process_mi_params( cmd_tree, &dlg); if (rpl_tree) /* param error */ return rpl_tree; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; if (dlg==NULL) { if ( internal_mi_print_dlgs(rpl,1)!=0 ) goto error; } else { if ( internal_mi_print_dlg(rpl,dlg,1)!=0 ) goto error; } return rpl_tree; error: free_mi_tree(rpl_tree); return NULL; }
struct mi_root * mi_print_dlgs_ctx(struct mi_root *cmd_tree, void *param ) { struct mi_root* rpl_tree= NULL; struct mi_node* rpl = NULL; struct dlg_cell* dlg = NULL; unsigned int idx,cnt; rpl_tree = process_mi_params( cmd_tree, &dlg, &idx, &cnt); if (rpl_tree) /* param error */ return rpl_tree; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==0) goto error; rpl = &rpl_tree->node; if (dlg==NULL) { if ( internal_mi_print_dlgs(rpl_tree, rpl, 1, idx, cnt)!=0 ) goto error; } else { if ( internal_mi_print_dlg(rpl,dlg,1)!=0 ) goto error; /* done with the dialog -> unlock it */ dlg_unlock_dlg(dlg); } return rpl_tree; error: /* if a dialog ref was returned, unlock it now */ if (dlg) dlg_unlock_dlg(dlg); /* trash everything that was built so far */ if (rpl_tree) free_mi_tree(rpl_tree); return NULL; }
static struct mi_root *mi_which(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_cmd *cmds; struct mi_node *rpl; struct mi_node *node; int size; int i; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; get_mi_cmds( &cmds, &size); for ( i=0 ; i<size ; i++ ) { node = add_mi_node_child( rpl, 0, 0, 0, cmds[i].name.s, cmds[i].name.len); if (node==0) { LM_ERR("failed to add node\n"); free_mi_tree(rpl_tree); return 0; } } return rpl_tree; }
static struct mi_root* ds_mi_list(struct mi_root* cmd_tree, void* param) { struct mi_root* rpl_tree; struct mi_node* part_node; int flags = 0; if (cmd_tree->node.kids){ if(cmd_tree->node.kids->value.len == 4 && memcmp(cmd_tree->node.kids->value.s,"full",4)==0) flags |= MI_FULL_LISTING; else return init_mi_tree(400, MI_SSTR(MI_BAD_PARM_S)); } rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN); if (rpl_tree==NULL) return 0; rpl_tree->node.flags |= MI_IS_ARRAY; ds_partition_t *part_it; for (part_it = partitions; part_it; part_it = part_it->next) { part_node = add_mi_node_child(&rpl_tree->node, MI_IS_ARRAY,"PARTITION", 9, part_it->name.s, part_it->name.len); if (part_node == NULL || ds_print_mi_list(part_node, part_it, flags) < 0) { LM_ERR("failed to add node\n"); free_mi_tree(rpl_tree); return 0; } } return rpl_tree; }
static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param) { if (ds_reload_db()<0) return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN); return init_mi_tree(200, MI_SSTR(MI_OK_S)); }
/*parameters from MI: dialog ID of the requested dialog*/ mi_response_t *mi_terminate_dlg(const mi_params_t *params, str *extra_hdrs) { unsigned int h_entry, h_id; unsigned long long d_id; struct dlg_cell * dlg = NULL; str dialog_id; char *end; char bkp; int shtag_state = 1; if( d_table ==NULL) return init_mi_error(404, MI_SSTR(MI_DIALOG_NOT_FOUND)); h_entry = h_id = 0; if (get_mi_string_param(params, "dialog_id", &dialog_id.s, &dialog_id.len) < 0) return init_mi_param_error(); /* Get the dialog based of the dialog_id. This may be a * numerical DID or a string SIP Call-ID */ /* make value null terminated (in an ugly way) */ bkp = dialog_id.s[dialog_id.len]; dialog_id.s[dialog_id.len] = 0; /* conver to long long */ d_id = strtoll( dialog_id.s, &end, 10); dialog_id.s[dialog_id.len] = bkp; if (end-dialog_id.s==dialog_id.len) { /* the ID is numeric, so let's consider it DID */ h_entry = (unsigned int)(d_id>>(8*sizeof(int))); h_id = (unsigned int)(d_id & (((unsigned long long)1<<(8*sizeof(int)))-1) ); LM_DBG("ID: %llu (h_entry %u h_id %u)\n", d_id, h_entry, h_id); dlg = lookup_dlg(h_entry, h_id); } else {
static struct mi_root* clusterer_reload(struct mi_root* root, void *param) { cluster_info_t *new_info; cluster_info_t *old_info; if (!db_mode) { LM_ERR("Running in non-DB mode\n"); return init_mi_tree(400, "Non-DB mode", 11); } if (load_db_info(&dr_dbf, db_hdl, &db_table, &new_info) != 0) { LM_ERR("Failed to load info from DB\n"); return init_mi_tree(500, "Failed to reload", 16); } lock_start_write(cl_list_lock); old_info = *cluster_list; *cluster_list = new_info; lock_stop_write(cl_list_lock); if (old_info) free_info(old_info); LM_INFO("Reloaded DB info\n"); return init_mi_tree(200, MI_SSTR(MI_OK)); }
/*! \brief Reload pcres by reading the file again */ mi_response_t *mi_pcres_reload(const mi_params_t *params, struct mi_handler *async_hdl) { /* Check if group matching feature is enabled */ if (file == NULL) { LM_NOTICE("'file' parameter is not set, group matching disabled\n"); return init_mi_error(403, MI_SSTR("Group matching not enabled")); } LM_NOTICE("reloading pcres...\n"); if (load_pcres(RELOAD)) { LM_ERR("failed to reload pcres\n"); return init_mi_error(500, MI_SSTR("Internal error")); } LM_NOTICE("reload success\n"); return init_mi_result_ok(); }
static struct mi_root *mi_ps(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *node; struct mi_attr *attr; char *p; int len; int i,threads_no; struct thread_info *threads_table; rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; get_threads_info( &threads_table, &threads_no); for ( i=0 ; i<threads_no ; i++ ) { node = add_mi_node_child(rpl, 0, MI_SSTR("Thread"), 0, 0 ); if (node==0) goto error; p = int2str((unsigned long)i, &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("ID"), p, len); if (attr==0) goto error; p = int2str((unsigned long)threads_table[i].id, &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("TID"), p, len); if (attr==0) goto error; attr = add_mi_attr( node, 0, MI_SSTR("Type"), threads_table[i].name, strlen(threads_table[i].name)); if (attr==0) goto error; } return rpl_tree; error: LM_ERR("failed to add node\n"); free_mi_tree(rpl_tree); return 0; }
struct mi_root * mi_event_subscribe(struct mi_root *root, void *param ) { struct mi_node *node; int ret; unsigned int expire = 0; str event_name, transport_sock; /* event name */ node = root->node.kids; if (!node || !node->value.len || !node->value.s) { LM_ERR("no parameters received\n"); goto missing_param; } event_name = node->value; /* socket */ node = node->next; if (!node || !node->value.len || !node->value.s) { LM_ERR("no transport type\n"); goto missing_param; } transport_sock = node->value; /* check expire */ node = node->next; if (node) { /* expiration period is set */ if (str2int(&node->value, &expire) < 0) { LM_ERR("invalid expire value %.*s", node->value.len, node->value.s); goto bad_param; } } else expire = DEFAULT_EXPIRE; ret = evi_event_subscribe(event_name, transport_sock, expire, 1); if (ret < 0) goto bad_param; return ret ? init_mi_tree(200, MI_SSTR(MI_OK)) : 0; missing_param: return init_mi_tree( 400, MI_SSTR(MI_MISSING_PARM)); bad_param: return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM)); }
static struct mi_root* mi_cc_list_flows(struct mi_root *cmd, void *param) { struct cc_flow *flow; struct mi_root *rpl_tree; struct mi_node *node; struct mi_node *rpl; struct mi_attr *attr; int len; char *p; rpl_tree = init_mi_tree( 200, MI_SSTR("OK") ); if ( rpl_tree==NULL) return NULL; rpl = &rpl_tree->node; /* block access to data */ lock_get( data->lock ); for( flow=data->flows; flow ; flow=flow->next ) { node = add_mi_node_child( rpl, MI_DUP_VALUE, MI_SSTR("Flow"), flow->id.s, flow->id.len ); if (node==NULL) goto error; p = int2str( (unsigned long)(flow->avg_call_duration), &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("Avg Call Duration"), p, len); if (attr==NULL) goto error; p = int2str( (unsigned long)(flow->processed_calls), &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("Processed Calls"), p, len); if (attr==NULL) goto error; p = int2str( (unsigned long)(flow->logged_agents), &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("Logged Agents"), p, len); if (attr==NULL) goto error; p = int2str( (unsigned long)(flow->ongoing_calls), &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("Ongoing Calls"), p, len); if (attr==NULL) goto error; p = int2str( (unsigned long)(flow->ref_cnt), &len); attr = add_mi_attr( node, MI_DUP_VALUE, MI_SSTR("Ref"), p, len); if (attr==NULL) goto error; } lock_release( data->lock ); return rpl_tree; error: lock_release( data->lock ); return 0; }
int rl_stats(mi_item_t *resp_obj, str * value) { mi_item_t *pipe_item, *pipe_arr; rl_pipe_t **pipe; int i; if (value && value->s && value->len) { i = RL_GET_INDEX(*value); RL_GET_LOCK(i); pipe = RL_FIND_PIPE(i, *value); if (!pipe || !*pipe) { LM_DBG("pipe %.*s not found\n", value->len, value->s); goto error; } pipe_item = add_mi_object(resp_obj, MI_SSTR("Pipe")); if (!pipe_item) goto error; if (rl_map_print(pipe_item, *value, *pipe)) { LM_ERR("cannot print value for key %.*s\n", value->len, value->s); goto error; } RL_RELEASE_LOCK(i); } else { /* iterate through each map */ pipe_arr = add_mi_array(resp_obj, MI_SSTR("Pipes")); if (!pipe_arr) return -1; for (i = 0; i < rl_htable.size; i++) { pipe_item = add_mi_object(pipe_arr, NULL, 0); if (!pipe_item) return -1; RL_GET_LOCK(i); if (map_for_each(rl_htable.maps[i], rl_map_print, pipe_item)) { LM_ERR("cannot print values\n"); goto error; } RL_RELEASE_LOCK(i); } } return 0; error: RL_RELEASE_LOCK(i); return -1; }
/*! \brief * MI function to print trusted entries from current hash table */ struct mi_root* mi_trusted_dump(struct mi_root *cmd_tree, void *param) { struct mi_root* rpl_tree; if (hash_table==NULL) return init_mi_tree( 500, MI_SSTR("Trusted-module not in use")); rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK)); if (rpl_tree==NULL) return 0; if(hash_table_mi_print(*hash_table, &rpl_tree->node)< 0) { LM_ERR("failed to add a node\n"); free_mi_tree(rpl_tree); return 0; } return rpl_tree; }