コード例 #1
0
ファイル: pike_mi.c プロジェクト: 4N7HR4X/kamailio
static inline void print_ip_stack( int level, struct mi_node *node)
{
	if (level==IPv6_LEN) {
		/* IPv6 */
		addf_mi_node_child( node, 0, 0, 0,
			"%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
			ip_stack[0]->byte,  ip_stack[1]->byte,
			ip_stack[2]->byte,  ip_stack[3]->byte,
			ip_stack[4]->byte,  ip_stack[5]->byte,
			ip_stack[6]->byte,  ip_stack[7]->byte,
			ip_stack[8]->byte,  ip_stack[9]->byte,
			ip_stack[10]->byte, ip_stack[11]->byte,
			ip_stack[12]->byte, ip_stack[13]->byte,
			ip_stack[14]->byte, ip_stack[15]->byte );
	} else if (level==IPv4_LEN) {
		/* IPv4 */
		addf_mi_node_child( node, 0, 0, 0, "%d.%d.%d.%d",
			ip_stack[0]->byte,
			ip_stack[1]->byte,
			ip_stack[2]->byte,
			ip_stack[3]->byte );
	} else {
		LM_CRIT("leaf node at depth %d!!!\n", level);
		return;
	}
}
コード例 #2
0
ファイル: cfgutils.c プロジェクト: 4N7HR4X/kamailio
static struct mi_root*  mi_get_gflags(struct mi_root* cmd_tree, void* param )
{
	struct mi_root* rpl_tree= NULL;
	struct mi_node* node= NULL;
	static unsigned int flags;

	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
	if(rpl_tree == NULL)
		return 0;

	flags = *gflags;

	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "0x%X",(flags));
	if(node == NULL)
		goto error;

	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "%u",(flags));
	if(node == NULL)
		goto error;

	return rpl_tree;
error:
	free_mi_tree(rpl_tree);
	return 0;
}
コード例 #3
0
ファイル: core_stats.c プロジェクト: AlessioCasco/kamailio
inline static int mi_reset_and_add_stat(struct mi_node *rpl, stat_var *stat)
{
	struct mi_node *node;
	long old_val, new_val;

	if (stats_support()==0) return -1;

	old_val=get_stat_val(stat);
	reset_stat(stat);
	new_val=get_stat_val(stat);

	if (old_val==new_val)
	{
		node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu",
				ZSW(get_stat_module(stat)),
				ZSW(get_stat_name(stat)),
				new_val);
	} else {
		node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu (%lu)",
				ZSW(get_stat_module(stat)),
				ZSW(get_stat_name(stat)),
				new_val, old_val );
	}

	if (node==0)
		return -1;
	return 0;
}
コード例 #4
0
ファイル: cr_fifo.c プロジェクト: 2pac/kamailio
/**
 * does the work for dump_fifo, traverses the routing tree
 * and prints route rules if present.
 *
 * @param msg MI node that is used to append the informations
 * @param node pointer to the routing tree node
 * @param prefix carries the current scan prefix
 *
 * @return 0 for success, negative result for error 
 */
static int dump_tree_recursor (struct mi_node* msg, struct dtrie_node_t *node, char *prefix) {
	char s[256];
	char *p;
	int i;
	struct route_flags *rf;
	struct route_rule *rr;
	struct route_rule_p_list * rl;
	double prob;
	struct mi_node* tmp_node = NULL;

	strcpy (s, prefix);
	p = s + strlen (s);
	p[1] = '\0';
	for (i = 0; i < cr_match_mode; ++i) {
		if (node->child[i] != NULL) {
			*p = i + '0';
			/* if there is a problem in processing the child nodes .. return an error */
			if(dump_tree_recursor (msg->next, node->child[i], s) < 0)
				return -1;
		}
	}
	*p = '\0';
	for (rf = (struct route_flags *)(node->data); rf != NULL; rf = rf->next) {
		for (rr = rf->rule_list; rr != NULL; rr = rr->next) {
			if(rf->dice_max){
				prob = (double)(rr->prob * DICE_MAX)/(double)rf->dice_max;
			} else {
				prob = rr->prob;
			}
			tmp_node = addf_mi_node_child(msg->next, 0, 0, 0, "%10s: %0.3f %%, '%.*s': %s, '%i', '%.*s', '%.*s', '%.*s'\n",
												 strlen(prefix) > 0 ? prefix : "NULL", prob * 100, rr->host.len, rr->host.s,
												 (rr->status ? "ON" : "OFF"), rr->strip,
												 rr->local_prefix.len, rr->local_prefix.s,
												 rr->local_suffix.len, rr->local_suffix.s,
												 rr->comment.len, rr->comment.s);
			if(!tmp_node) return -1;
			if(!rr->status && rr->backup && rr->backup->rr){
				tmp_node = addf_mi_node_child(msg->next, 0, 0, 0, "            Rule is backed up by: %.*s\n", rr->backup->rr->host.len, rr->backup->rr->host.s);
				if(!tmp_node) return -1;
			}
			if(rr->backed_up){
				rl = rr->backed_up;
				i=0;
				while(rl){
					if(rl->rr){
						tmp_node = addf_mi_node_child(msg->next, 0, 0, 0, "            Rule is backup for: %.*s", rl->rr->host.len, rl->rr->host.s);
						if(!tmp_node) return -1;
					}
					rl = rl->next;
					i++;
				}
			}
		}
	}
	return 0;
}
コード例 #5
0
ファイル: route_fifo.c プロジェクト: NormB/opensips
/**
 * does the work for dump_fifo, traverses the routing tree
 * and prints route rules if present.
 *
 * @param msg MI node that is used to append the informations
 * @param tree pointer to the routing tree node
 * @param prefix carries the current scan prefix
 *
 * @return mi node containing the route rules
 */
static int dump_tree_recursor (struct mi_node* msg, struct route_tree_item *tree, char *prefix) {
	char s[256];
	char *p;
	int i;
	struct route_flags *rf;
	struct route_rule *rr;
	struct route_rule_p_list * rl;
	double prob;

	strcpy (s, prefix);
	p = s + strlen (s);
	p[1] = '\0';
	for (i = 0; i < 10; ++i) {
		if (tree->nodes[i] != NULL) {
			*p = i + '0';
			dump_tree_recursor (msg->next, tree->nodes[i], s);
		}
	}
	*p = '\0';
	for (rf = tree->flag_list; rf != NULL; rf = rf->next) {
		for (rr = rf->rule_list; rr != NULL; rr = rr->next) {
			if(rf->dice_max){
				prob = (double)(rr->prob * DICE_MAX)/(double)rf->dice_max;
			} else {
				prob = rr->prob;
			}
			addf_mi_node_child(msg->next, 0, 0, 0, "%10s: %0.3f %%, '%.*s': %s, '%i', '%.*s', '%.*s', '%.*s'\n",
												 strlen(prefix) > 0 ? prefix : "NULL", prob * 100, rr->host.len, rr->host.s,
												 (rr->status ? "ON" : "OFF"), rr->strip,
												 rr->local_prefix.len, rr->local_prefix.s,
												 rr->local_suffix.len, rr->local_suffix.s,
												 rr->comment.len, rr->comment.s);
			if(!rr->status && rr->backup && rr->backup->rr){
				addf_mi_node_child(msg->next, 0, 0, 0, "            Rule is backed up by: %.*s\n", rr->backup->rr->host.len, rr->backup->rr->host.s);
			}
			if(rr->backed_up){
				rl = rr->backed_up;
				i=0;
				while(rl){
					if(rl->rr){
						addf_mi_node_child(msg->next, 0, 0, 0, "            Rule is backup for: %.*s", rl->rr->host.len, rl->rr->host.s);
					}
					rl = rl->next;
					i++;
				}
			}
		}
	}
	return 0;
}
コード例 #6
0
ファイル: conf.c プロジェクト: SibghatullahSheikh/kamailio
/*!
 * \brief Output configuration in FIFO format
 * \param rpl_tree FIFO root
 * \return 0 on success, -1 on failure
 */
int conf_show(struct mi_root* rpl_tree)
{
	int id, sfilter;
	struct mi_node * node = NULL;

	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "id switch %30s proxy\n", "filter");
	if(node == NULL)
		goto error;

	for (id=0; id<=fwd_max_id; id++) {
		char buf[BUFSIZE+1];
		char tmp[BUFSIZE+1];
		buf[0]='\0';
		for (sfilter=0; sfilter<sfilter_cnt; sfilter++) {
			if (fwd_settings[id].sfilter&sfilter_mask[sfilter]) {
				if (buf[0]) {
					strcpy(tmp, buf);
					snprintf(buf, BUFSIZE, "%s:%s", tmp, sfilter_str[sfilter]);
					buf[BUFSIZE]='\0';
				} else {
					snprintf(buf, BUFSIZE, "%s", sfilter_str[sfilter]);
					buf[BUFSIZE]='\0';
				}
			}
		}
		if (fwd_settings[id].filter_methods) {
			if (buf[0]) {
				strcpy(tmp, buf);
				snprintf(buf, BUFSIZE, "%s:%s", tmp, fwd_settings[id].filter_methods);
				buf[BUFSIZE]='\0';
			} else {
				snprintf(buf, BUFSIZE, "%s", fwd_settings[id].filter_methods);
				buf[BUFSIZE]='\0';
			}
		}
		node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "%2d %s %33s %s:%d\n", id,
			fwd_settings[id].active ? "on " : "off", buf,
			fwd_settings[id].proxy ? fwd_settings[id].proxy->name.s : "",
			fwd_settings[id].proxy ? fwd_settings[id].proxy->port : 0);
		if(node == NULL)
			goto error;

	}
	return 0;

error:
	return -1;
}
コード例 #7
0
ファイル: cr_fifo.c プロジェクト: 2pac/kamailio
/**
 * prints the routing data
 *
 * @param cmd_tree the MI command tree
 * @param param the parameter
 *
 * @return code 200 on success, code 400 or 500 on failure
 */
struct mi_root* dump_fifo (struct mi_root* cmd_tree, void *param) {
	struct route_data_t * rd;
	str *tmp_str;
	str empty_str = str_init("<empty>");

	if((rd = get_data ()) == NULL) {
		LM_ERR("error during retrieve data\n");
		return init_mi_tree(500, "error during command processing", 31);
	}
	
	struct mi_root* rpl_tree;
	struct mi_node* node = NULL;
	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
	if(rpl_tree == NULL)
		goto error2;
	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing routing information:");
	if(node == NULL)
		goto error;

	LM_DBG("start processing of data\n");
	int i, j;
 	for (i = 0; i < rd->carrier_num; i++) {
 		if (rd->carriers[i]) {
			tmp_str = (rd->carriers[i] ? rd->carriers[i]->name : &empty_str);
			node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing tree for carrier '%.*s' (%i)\n", tmp_str->len, tmp_str->s, rd->carriers[i] ? rd->carriers[i]->id : 0);
			if(node == NULL)
				goto error;
 			for (j=0; j<rd->carriers[i]->domain_num; j++) {
 				if (rd->carriers[i]->domains[j] && rd->carriers[i]->domains[j]->tree) {
					tmp_str = (rd->carriers[i]->domains[j] ? rd->carriers[i]->domains[j]->name : &empty_str);
					node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing tree for domain '%.*s' (%i)\n", tmp_str->len, tmp_str->s, rd->carriers[i]->domains[j]->id);
					if(node == NULL)
						goto error;
					if (dump_tree_recursor (&rpl_tree->node, rd->carriers[i]->domains[j]->tree, "") < 0) 
						goto error;
 				}
 			}
		}
	}
	release_data (rd);
	return rpl_tree;

error:
	free_mi_tree(rpl_tree);
error2:
	release_data (rd);
	return 0;
}
コード例 #8
0
ファイル: autheph_mod.c プロジェクト: krys1976/kamailio
static struct mi_root *mi_dump_secrets(struct mi_root *cmd, void *param)
{
	int pos = 0;
	struct secret *secret_struct = secret_list;
	struct mi_root *rpl_tree;

	if (cmd->node.kids != NULL)
	{
		LM_WARN("too many parameters\n");
		return init_mi_tree(400, str_status_too_many_params.s,
					str_status_too_many_params.len);
	}

	rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
	if (rpl_tree == NULL)
		return 0;

	SECRET_LOCK;
	while (secret_struct != NULL)
	{
		if (addf_mi_node_child(&rpl_tree->node, 0, 0, 0,
					"ID %d: %.*s", pos++,
					secret_struct->secret_key.len,
					secret_struct->secret_key.s) == 0)
		{
			free_mi_tree(rpl_tree);
			SECRET_UNLOCK;
			return 0;
		}
		secret_struct = secret_struct->next;
	}
	SECRET_UNLOCK;

	return rpl_tree;
}
コード例 #9
0
ファイル: utils.c プロジェクト: mehulsbhatt/voip-foip
/*!
 * \brief fifo command for listing configuration
 * \return pointer to the mi_root on success, 0 otherwise
 */
static struct mi_root* forward_fifo_list(struct mi_root* cmd_tree, void *param)
{
	struct mi_node *node = NULL;
	struct mi_root * ret = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
	if(ret == NULL)
		return 0;

	node = addf_mi_node_child( &ret->node, 0, 0, 0, "Printing forwarding information:");
	if(node == NULL)
		goto error;

	// critical section start:
	// avoids dirty reads when updating configuration.
	lock_get(conf_lock);

	conf_show(ret);

	// critical section end
	lock_release(conf_lock);

	return ret;

error:
	free_mi_tree(ret);
	return 0;
}
コード例 #10
0
ファイル: sipluami.c プロジェクト: Distrotech/opensips
struct mi_root *siplua_mi_reload(struct mi_root *cmd_tree, void *param)
{
  struct mi_root *answer;

  answer = init_mi_tree(200, "xOK", 3);
  addf_mi_node_child(&answer->node, 0, "pid", 3, "%d", (int)getpid());
  return answer;
}
コード例 #11
0
ファイル: core_stats.c プロジェクト: AlessioCasco/kamailio
/* callback for counter_iterate_grp_vars. */
static void mi_add_grp_vars_cbk(void* r, str* g, str* n, counter_handle_t h)
{
	struct mi_node *rpl;
	
	rpl = r;
	addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
							g->len, g->s, n->len, n->s, counter_get_val(h));
}
コード例 #12
0
ファイル: cr_fifo.c プロジェクト: 2pac/kamailio
/**
 * prints a short help text for fifo command usage
 */
static struct mi_root* print_replace_help(void) {
       struct mi_root* rpl_tree;
       struct mi_node* node;

       rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
       if(rpl_tree == NULL)
               return 0;

       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "carrierroute options usage:");
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c searched/new remote host\n", OPT_HOST_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c replacement/backup host", OPT_NEW_TARGET_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: searched/new domain", OPT_DOMAIN_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: searched/new prefix", OPT_PREFIX_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: searched/new weight (0..1)", OPT_PROB_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: new rewrite prefix", OPT_R_PREFIX_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: new rewrite suffix", OPT_R_SUFFIX_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: new hash index", OPT_HASH_INDEX_CHR);
       if(node == NULL)
               goto error;
       node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "\t-%c: prints this help", OPT_HELP_CHR);
       if(node == NULL)
               goto error;

       return rpl_tree;

error:
       free_mi_tree(rpl_tree);
       return 0;
}
コード例 #13
0
ファイル: core_stats.c プロジェクト: AlessioCasco/kamailio
/* callback for counter_iterate_grp_vars to reset counters */
static void mi_add_grp_vars_cbk2(void* r, str* g, str* n, counter_handle_t h)
{
	struct mi_node *rpl;
	counter_val_t old_val, new_val;

	rpl = r;
	old_val = counter_get_val(h);
	counter_reset(h);
	new_val = counter_get_val(h);

	if (old_val==new_val)
	{
		addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
					g->len, g->s, n->len, n->s, new_val);
	} else {
		addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu (%lu)",
					g->len, g->s, n->len, n->s, new_val, old_val);
	}
}
コード例 #14
0
ファイル: route_fifo.c プロジェクト: Drooids/openser-xmlrpc
/**
 * prints the routing data
 *
 * @param mi_root the fifo command tree
 * @param param the parameter
 *
 * @return code 200 on success, code 400 or 500 on failure
 */
struct mi_root* dump_fifo (struct mi_root* cmd_tree, void *param) {
	struct rewrite_data * rd;

	if((rd = get_data ()) == NULL) {
		LM_ERR("error during retrieve data\n");
		return init_mi_tree(500, "error during command processing", 31);
	}
		
	struct mi_root* rpl_tree;
	struct mi_node* node = NULL;
	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
	if(rpl_tree == NULL)
		return 0;
	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing routing information:");
	if(node == NULL)
		goto error;

	LM_DBG("start processing of data\n");
	int i, j;
 	for (i = 0; i < rd->tree_num; i++) {
 		if (rd->carriers[i]) {
			node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing tree for carrier %s (%i)\n", rd->carriers[i] ? rd->carriers[i]->name.s : "<empty>", rd->carriers[i] ? rd->carriers[i]->id : 0);
			if(node == NULL)
				goto error;
 			for (j=0; j<rd->carriers[i]->tree_num; j++) {
 				if (rd->carriers[i]->trees[j] && rd->carriers[i]->trees[j]->tree) {
					node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "Printing tree for domain %s\n", rd->carriers[i]->trees[j] ? rd->carriers[i]->trees[j]->name.s : "<empty>");
					if(node == NULL)
						goto error;
 					dump_tree_recursor (&rpl_tree->node, rd->carriers[i]->trees[j]->tree, "");
				}
 			}
		}
	}
	release_data (rd);
	return rpl_tree;
	return 0;

error:
	release_data (rd);
	free_mi_tree(rpl_tree);
	return 0;
}
コード例 #15
0
ファイル: benchmark.c プロジェクト: Distrotech/opensips
static void add_results_node(struct mi_node *node, benchmark_timer_t *timer) {
	struct mi_node *timer_node;

	timer_node = addf_mi_node_child(node, 0, 0, 0, "%s", timer->name);
	addf_mi_node_child(timer_node, 0, 0, 0,
			"%i/%lld/%lld/%lld/%f",
			timer->calls,
			timer->last_sum,
			timer->last_min==STARTING_MIN_VALUE?0:timer->last_min,
			timer->last_max,
			timer->calls?((double)timer->last_sum)/timer->calls:0.);
	addf_mi_node_child(timer_node, 0, 0, 0,
			"%lld/%lld/%lld/%lld/%f",
			timer->global_calls,
			timer->sum,
			timer->global_min==STARTING_MIN_VALUE?0:timer->global_min,
			timer->global_max,
			timer->global_calls?((double)timer->sum)/timer->global_calls:0.);
}
コード例 #16
0
ファイル: mi.c プロジェクト: Distrotech/opensips
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;
}
コード例 #17
0
ファイル: ws_conn.c プロジェクト: AlessioCasco/kamailio
static int add_node(struct mi_root *tree, ws_connection_t *wsc)
{
	int interval;
	char *src_proto, *dst_proto, *pong, *sub_protocol;
	char src_ip[IP6_MAX_STR_SIZE + 1], dst_ip[IP6_MAX_STR_SIZE + 1];
	struct tcp_connection *con = tcpconn_get(wsc->id, 0, 0, 0, 0);

	if (con)
	{
		src_proto = (con->rcv.proto== PROTO_WS) ? "ws" : "wss";
		memset(src_ip, 0, IP6_MAX_STR_SIZE + 1);
		ip_addr2sbuf(&con->rcv.src_ip, src_ip, IP6_MAX_STR_SIZE);

		dst_proto = (con->rcv.proto == PROTO_WS) ? "ws" : "wss";
		memset(dst_ip, 0, IP6_MAX_STR_SIZE + 1);
		ip_addr2sbuf(&con->rcv.dst_ip, dst_ip, IP6_MAX_STR_SIZE);

		pong = wsc->awaiting_pong ? "awaiting Pong, " : "";

		interval = (int)time(NULL) - wsc->last_used;
		if (wsc->sub_protocol == SUB_PROTOCOL_SIP)
			sub_protocol = "sip";
		else if (wsc->sub_protocol == SUB_PROTOCOL_MSRP)
			sub_protocol = "msrp";
		else
			sub_protocol = "**UNKNOWN**";

		if (addf_mi_node_child(&tree->node, 0, 0, 0,
					"%d: %s:%s:%hu -> %s:%s:%hu (state: %s"
					", %s last used %ds ago"
					", sub-protocol: %s)",
					wsc->id,
					src_proto,
					strlen(src_ip) ? src_ip : "*",
					con->rcv.src_port,
					dst_proto,
					strlen(dst_ip) ? dst_ip : "*",
					con->rcv.dst_port,
					wsconn_state_str[wsc->state],
					pong,
					interval,
					sub_protocol) == 0)
		{
			tcpconn_put(con);
			return -1;
		}

		tcpconn_put(con);
		return 1;
	}
	else
		return 0;
}
コード例 #18
0
ファイル: cfgutils.c プロジェクト: 4N7HR4X/kamailio
static struct mi_root* mi_check_hash(struct mi_root* cmd, void* param )
{
	struct mi_root* rpl_tree= NULL;
	struct mi_node* node= NULL;
	char tmp[MD5_LEN];
	memset(tmp, 0, MD5_LEN);

	if (!hash_file) {
		LM_INFO("no hash_file given, disable hash functionality\n");
		rpl_tree = init_mi_tree(404, "Functionality disabled\n", 23);
	} else {
		if (MD5File(tmp, hash_file) != 0) {
			LM_ERR("could not hash the config file");
			rpl_tree = init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN );
			return rpl_tree;
		}
		
		if (strncmp(config_hash, tmp, MD5_LEN) == 0) {
			rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
			if(rpl_tree == NULL)
				return 0;
			node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "The actual config file hash is identical to the stored one.\n");
		} else {
			rpl_tree = init_mi_tree( 400, "Error", 5 );
			if(rpl_tree == NULL)
				return 0;
			node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "The actual config file hash is not identical to the stored one.\n");
		}
		if(node == NULL)
			goto error;
	}
	
	return rpl_tree;

error:
	free_mi_tree(rpl_tree);
	return 0;
}
コード例 #19
0
inline static int mi_add_stat(struct mi_node *rpl, stat_var *stat)
{
	struct mi_node *node;

	node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
		collector->amodules[stat->mod_idx].name.len,
		collector->amodules[stat->mod_idx].name.s,
		stat->name.len, stat->name.s,
		get_stat_val(stat) );

	if (node==0)
		return -1;
	return 0;
}
コード例 #20
0
ファイル: core_stats.c プロジェクト: AlessioCasco/kamailio
inline static int mi_add_stat(struct mi_node *rpl, stat_var *stat)
{
	struct mi_node *node;

	if (stats_support()==0) return -1;

	node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu",
		ZSW(get_stat_module(stat)),
		ZSW(get_stat_name(stat)),
		get_stat_val(stat) );

	if (node==0)
		return -1;
	return 0;
}
コード例 #21
0
inline static int mi_add_module_stats(struct mi_node *rpl,
													module_stats *mods)
{
	struct mi_node *node;
	stat_var *stat;

	for( stat=mods->head ; stat ; stat=stat->lnext) {
		node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
			mods->name.len, mods->name.s,
			stat->name.len, stat->name.s,
			get_stat_val(stat) );
		if (node==0)
			return -1;
	}
	return 0;
}
コード例 #22
0
ファイル: cfgutils.c プロジェクト: 4N7HR4X/kamailio
static struct mi_root* mi_get_prob(struct mi_root* cmd, void* param )
{
	struct mi_root* rpl_tree= NULL;
	struct mi_node* node= NULL;
	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
	if(rpl_tree == NULL)
		return 0;
	node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "actual probability: %u percent\n",(*probability));
	if(node == NULL)
		goto error;
	
	return rpl_tree;

error:
	free_mi_tree(rpl_tree);
	return 0;
}
コード例 #23
0
ファイル: hash.c プロジェクト: 4N7HR4X/kamailio
/*
 * Print subnets stored in subnet table
 */
int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl)
{
	unsigned int count, i;

	count = table[PERM_MAX_SUBNETS].grp;

	for (i = 0; i < count; i++) {
		if (addf_mi_node_child(rpl, 0, 0, 0,
					"%4d <%u, %s, %u, %u> [%s]",
					i, table[i].grp, ip_addr2a(&table[i].subnet),
					table[i].mask, table[i].port,
					(table[i].tag.s==NULL)?"":table[i].tag.s) == 0) {
			return -1;
		}
	}
	return 0;
}
コード例 #24
0
ファイル: hash.c プロジェクト: 4N7HR4X/kamailio
/*! \brief
 * MI: Print addresses stored in hash table
 */
int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
{
	int i;
	struct addr_list *np;

	for (i = 0; i < PERM_HASH_SIZE; i++) {
		np = table[i];
		while (np) {
			if (addf_mi_node_child(rpl, 0, 0, 0,
						"%4d <%u, %s, %u> [%s]",
						i, np->grp, ip_addr2a(&np->addr),
						np->port, (np->tag.s==NULL)?"":np->tag.s) == 0)
				return -1;
			np = np->next;
		}
	}
	return 0;
}
コード例 #25
0
ファイル: hash.c プロジェクト: 4N7HR4X/kamailio
/*! \brief
 * MI: Print domain name stored in hash table
 */
int domain_name_table_mi_print(struct domain_name_list** table, struct mi_node* rpl)
{
	int i;
	struct domain_name_list *np;

	for (i = 0; i < PERM_HASH_SIZE; i++) {
		np = table[i];
		while (np) {
			if (addf_mi_node_child(rpl, 0, 0, 0,
						"%4d <%u, %.*s, %u> [%s]",
						i, np->grp, np->domain.len, np->domain.s,
						np->port, (np->tag.s==NULL)?"":np->tag.s) == 0)
				return -1;
			np = np->next;
		}
	}
	return 0;
}
コード例 #26
0
ファイル: hash.c プロジェクト: Drooids/openser-xmlrpc
/* 
 * Print subnets stored in subnet table 
 */
int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl)
{
    unsigned int count, i;
    struct ip_addr addr;
    
    count = table[PERM_MAX_SUBNETS].grp;

    for (i = 0; i < count; i++) {
	addr.af = AF_INET;
	addr.len = 4;
	addr.u.addr32[0] = table[i].subnet >> table[i].mask;
	if (addf_mi_node_child(rpl, 0, 0, 0,
			       "%4d <%u, %s, %u, %u>",
			       i, table[i].grp, ip_addr2a(&addr),
			       32 - table[i].mask, table[i].port) == 0) {
	    return -1;
	}
    }
    return 0;
}
コード例 #27
0
ファイル: hash.c プロジェクト: Drooids/openser-xmlrpc
/* 
 * Print addresses stored in hash table 
 */
int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
{
    int i;
    struct addr_list *np;
    struct ip_addr addr;
    
    for (i = 0; i < PERM_HASH_SIZE; i++) {
	np = table[i];
	while (np) {
	    addr.af = AF_INET;
	    addr.len = 4;
	    addr.u.addr32[0] = np->ip_addr;
	    if (addf_mi_node_child(rpl, 0, 0, 0,
				   "%4d <%u, %s, %u>",
				   i, np->grp, ip_addr2a(&addr),
				   np->port) == 0)
		return -1;
	    np = np->next;
	}
    }
    return 0;
}
コード例 #28
0
ファイル: cfgutils.c プロジェクト: 4N7HR4X/kamailio
static struct mi_root* mi_get_hash(struct mi_root* cmd, void* param )
{
	struct mi_root* rpl_tree= NULL;
	struct mi_node* node= NULL;

	if (!hash_file) {
		LM_INFO("no hash_file given, disable hash functionality\n");
		rpl_tree = init_mi_tree(404, "Functionality disabled\n", 23);
	} else {
		rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
		if(rpl_tree == NULL)
			return 0;
		node = addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "%.*s\n", MD5_LEN, config_hash);
		if(node == NULL)
			goto error;
	}
	return rpl_tree;

error:
	free_mi_tree(rpl_tree);
	return 0;
}
コード例 #29
0
ファイル: hash.c プロジェクト: mattvv/kamailio
/* 
 * Print trusted entries stored in hash table 
 */
int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
{
	int i;
	struct trusted_list *np;

	for (i = 0; i < PERM_HASH_SIZE; i++) {
		np = table[i];
		while (np) {
			if (addf_mi_node_child(rpl, 0, 0, 0,
						"%4d <%.*s, %d, %s, %s>",
						i,
						np->src_ip.len, ZSW(np->src_ip.s),
						np->proto,
						np->pattern?np->pattern:"NULL",
						np->tag.len?np->tag.s:"NULL") == 0) {
				return -1;
			}
			np = np->next;
		}
	}
	return 0;
}
コード例 #30
0
ファイル: sipluami.c プロジェクト: Distrotech/opensips
struct mi_root *siplua_mi_watch(struct mi_root *cmd_tree, void *param)
{
  struct mi_root *answer;
  struct mi_node *node;
  str action;

  node = cmd_tree->node.kids;
  if (!node)
    return init_mi_tree(200, SIPLUAMI_USAGE, sizeof(SIPLUAMI_USAGE) - 1);
  action = node->value;
  node = node->next;
  if (action.len == 3 && !strncmp("add", action.s, action.len))
    {
      if (!node)
	return init_mi_tree(200, "usage: missing extension", 24);
      sipwatch_add(node->value.s, node->value.len);
    }
  if (action.len == 6 && !strncmp("delete", action.s, action.len))
    {
      if (!node)
	return init_mi_tree(200, "usage: missing extension", 24);
      sipwatch_delete(node->value.s, node->value.len);
    }
  if (action.len == 4 && !strncmp("show", action.s, action.len))
    {
      int i;

      answer = init_mi_tree(200, "xOK", 3);
      answer->node.flags |= MI_IS_ARRAY;
      sipwatch_lock();
      for (i = 0; i < siplua_watch->nb; ++i)
	addf_mi_node_child(&answer->node, 0, "extension", 9, "%s",
			   siplua_watch->ext[i].str);
      sipwatch_unlock();
      return answer;
    }
  answer = init_mi_tree(200, "xOK", 3);
  return answer;
}