浏览代码

modules_k: ratelimit - removing the old mi interface

Ovidiu Sas 15 年之前
父节点
当前提交
a52d454125
共有 2 个文件被更改,包括 1 次插入419 次删除
  1. 0 1
      modules_k/ratelimit/Makefile
  2. 1 418
      modules_k/ratelimit/ratelimit.c

+ 0 - 1
modules_k/ratelimit/Makefile

@@ -13,5 +13,4 @@ DEFS+=-DOPENSER_MOD_INTERFACE
 
 SERLIBPATH=../../lib
 SER_LIBS+=$(SERLIBPATH)/kcore/kcore
-SER_LIBS+=$(SERLIBPATH)/kmi/kmi
 include ../../Makefile.modules

+ 1 - 418
modules_k/ratelimit/ratelimit.c

@@ -51,7 +51,6 @@
 #include "../../lib/kcore/statistics.h"
 #include "../sl/sl_api.h"
 #include "../../lib/kcore/km_ut.h"
-#include "../../lib/kmi/mi.h"
 #include "../../rpc_lookup.h"
 
 #include "config.h"
@@ -243,29 +242,6 @@ static param_export_t params[]={
 	{0,0,0}
 };
 
-struct mi_root* mi_stats(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_set_queue(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_get_queues(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_set_pid(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_get_pid(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_push_load(struct mi_root* cmd_tree, void* param);
-struct mi_root* mi_set_dbg(struct mi_root* cmd_tree, void* param);
-
-static mi_export_t mi_cmds [] = {
-	{"rl_stats",      mi_stats,      MI_NO_INPUT_FLAG, 0, 0},
-	{"rl_set_pipe",   mi_set_pipe,   0,                0, 0},
-	{"rl_get_pipes",  mi_get_pipes,  MI_NO_INPUT_FLAG, 0, 0},
-	{"rl_set_queue",  mi_set_queue,  0,                0, 0},
-	{"rl_get_queues", mi_get_queues, MI_NO_INPUT_FLAG, 0, 0},
-	{"rl_set_pid",    mi_set_pid,    0,                0, 0},
-	{"rl_get_pid",    mi_get_pid,    MI_NO_INPUT_FLAG, 0, 0},
-	{"rl_push_load",  mi_push_load,  0,                0, 0},
-	{"rl_set_dbg",    mi_set_dbg,    0,                0, 0},
-	{0,0,0,0,0}
-};
-
 static rpc_export_t rpc_methods[];
 
 /** module exports */
@@ -275,7 +251,7 @@ struct module_exports exports= {
 	cmds,
 	params,
 	0,				/* exported statistics */
-	mi_cmds,			/* exported MI functions */
+	0,				/* exported MI functions */
 	0,				/* exported pseudo-variables */
 	0,				/* extra processes */
 	mod_init,			/* module initialization function */
@@ -439,12 +415,6 @@ static int mod_init(void)
 {
 	int i;
 
-	if(register_mi_mod(exports.name, mi_cmds)!=0)
-	{
-		LM_ERR("failed to register MI commands\n");
-		return -1;
-	}
-
 	if (rpc_register_array(rpc_methods)!=0) {
 		LM_ERR("failed to register RPC commands\n");
 		return -1;
@@ -1200,393 +1170,6 @@ static ticks_t rl_timer_handle(ticks_t ticks, struct timer_ln* tl, void* data)
 }
 
 
-/*
- * MI functions
- *
- * mi_stats() dumps the current config/statistics
- * mi_{invite|register|subscribe}() set the limits
- */
-
-/* mi function implementations */
-struct mi_root* mi_stats(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_root *rpl_tree;
-	struct mi_node *node=NULL, *rpl=NULL;
-	struct mi_attr* attr;
-	char* p;
-	int i, len;
-
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-	if (rpl_tree==0)
-		return 0;
-	rpl = &rpl_tree->node;
-
-	LOCK_GET(rl_lock);
-	for (i=0; i<MAX_PIPES; i++) {
-		if (*pipes[i].algo != PIPE_ALGO_NOP) {
-			node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0);
-			if(node == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(i), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "id", 2, p, len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*pipes[i].load), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "load", 4, p, len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*pipes[i].last_counter), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len);
-			if(attr == NULL)
-				goto error;
-		}
-	}
-
-	p = int2str((unsigned long)(*drop_rate), &len);
-	node = add_mi_node_child(rpl, MI_DUP_VALUE, "DROP_RATE", 9, p, len);
-
-	LOCK_RELEASE(rl_lock);
-	return rpl_tree;
-error:
-	LOCK_RELEASE(rl_lock);
-	LM_ERR("Unable to create reply\n");
-	free_mi_tree(rpl_tree); 
-	return 0;
-}
-
-struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_root *rpl_tree;
-	struct mi_node *node=NULL, *rpl=NULL;
-	struct mi_attr* attr;
-	str algo;
-	char* p;
-	int i, len;
-
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-	if (rpl_tree==0)
-		return 0;
-	rpl = &rpl_tree->node;
-
-	LOCK_GET(rl_lock);
-	for (i=0; i<MAX_PIPES; i++) {
-		if (*pipes[i].algo != PIPE_ALGO_NOP) {
-			node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0);
-			if(node == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(i), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, p, len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*pipes[i].algo), &len);
-			if (str_map_int(algo_names, *pipes[i].algo, &algo))
-				goto error;
-			attr = add_mi_attr(node, 0, "algorithm", 9, algo.s, algo.len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*pipes[i].limit), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*pipes[i].counter), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len);
-			if(attr == NULL)
-				goto error;
-		}
-	}
-	LOCK_RELEASE(rl_lock);
-	return rpl_tree;
-error:
-	LOCK_RELEASE(rl_lock);
-	LM_ERR("Unable to create reply\n");
-	free_mi_tree(rpl_tree); 
-	return 0;
-}
-
-struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_node *node;
-	unsigned int pipe_no = MAX_PIPES, algo_id, limit = 0;
-	//str algo;
-
-	node = cmd_tree->node.kids;
-	if (node == NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&pipe_no)<0)
-		goto bad_syntax;
-	
-	node = node->next;
-	if ( !node->value.s || !node->value.len)
-		goto bad_syntax;
-	if (str_map_str(algo_names, &(node->value), (int*)&algo_id)) {
-		LM_ERR("unknown algorithm: '%.*s'\n", node->value.len, node->value.s);
-		goto bad_syntax;
-	}
-	
-	node = node->next;
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&limit)<0)
-		goto bad_syntax;
-
-	LM_DBG("set_pipe: %d:%d:%d\n", pipe_no, algo_id, limit);
-
-	if (pipe_no >= MAX_PIPES) {
-		LM_ERR("wrong pipe_no: %d\n", pipe_no);
-		goto bad_syntax;
-	}
-
-	LOCK_GET(rl_lock);
-	*pipes[pipe_no].algo = algo_id;
-	*pipes[pipe_no].limit = limit;
-
-	if (check_feedback_setpoints(0)) {
-		LM_ERR("feedback limits don't match\n");
-		goto error;
-	} else {
-		*pid_setpoint = 0.01 * (double)cfg_setpoint;
-	}
-
-	LOCK_RELEASE(rl_lock);
-
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-error:
-	LOCK_RELEASE(rl_lock);
-bad_syntax:
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
-}
-
-struct mi_root* mi_get_queues(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_root *rpl_tree;
-	struct mi_node *node=NULL, *rpl=NULL;
-	struct mi_attr* attr;
-	char* p;
-	int i, len;
-
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-	if (rpl_tree==0)
-		return 0;
-	rpl = &rpl_tree->node;
-
-	LOCK_GET(rl_lock);
-	for (i=0; i<MAX_QUEUES; i++) {
-		if (queues[i].pipe) {
-			node = add_mi_node_child(rpl, 0, "QUEUE", 5, 0, 0);
-			if(node == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(i), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, p, len);
-			if(attr == NULL)
-				goto error;
-
-			p = int2str((unsigned long)(*queues[i].pipe), &len);
-			attr = add_mi_attr(node, MI_DUP_VALUE, "pipe" , 4, p, len);
-			if(attr == NULL)
-				goto error;
-
-			attr = add_mi_attr(node, 0, "method", 6,
-				(*queues[i].method).s, (*queues[i].method).len);
-			if(attr == NULL)
-				goto error;
-		}
-	}
-	LOCK_RELEASE(rl_lock);
-
-	return rpl_tree;
-error:
-	LOCK_RELEASE(rl_lock);
-	LM_ERR("Unable to create reply\n");
-	free_mi_tree(rpl_tree); 
-	return 0;
-}
-
-struct mi_root* mi_set_queue(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_node *node;
-	unsigned int queue_no = MAX_QUEUES, pipe_no = MAX_PIPES;
-	str method;
-
-	node = cmd_tree->node.kids;
-	if (node == NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&queue_no)<0)
-		goto bad_syntax;
-
-	node = node->next;
-	if ( !node->value.s || !node->value.len )
-		goto bad_syntax;
-	if (str_cpy(&method, &(node->value))) {
-		LM_ERR("out of memory\n");
-		goto early_error;
-	}
-
-	node = node->next;
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&pipe_no)<0)
-		goto early_error;
-	if (pipe_no >= MAX_PIPES) {
-		LM_ERR("invalid pipe number: %d\n", pipe_no);
-		goto early_error;
-	}
-
-	LOCK_GET(rl_lock);
-	if (queue_no >= *nqueues) {
-		LM_ERR("MAX_QUEUES reached for queue: %d\n", queue_no);
-		goto error;
-	}
-	
-	*queues[queue_no].pipe = pipe_no;
-	if (!queues[queue_no].method->s)
-		shm_free(queues[queue_no].method->s);
-	queues[queue_no].method->s = method.s;
-	queues[queue_no].method->len = method.len;
-	LOCK_RELEASE(rl_lock);
-
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-error:
-	LOCK_RELEASE(rl_lock);
-early_error:
-	shm_free(method.s);
-bad_syntax:
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
-}
-
-struct mi_root* mi_get_pid(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_root *rpl_tree;
-	struct mi_node *node=NULL, *rpl=NULL;
-	struct mi_attr* attr;
-
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-	if (rpl_tree==0)
-		return 0;
-	rpl = &rpl_tree->node;
-	node = add_mi_node_child(rpl, 0, "PID", 3, 0, 0);
-	if(node == NULL)
-		goto error;
-	LOCK_GET(rl_lock);
-	attr= addf_mi_attr(node, 0, "ki", 2, "%0.3f", *pid_ki);
-	if(attr == NULL)
-		goto error;
-	attr= addf_mi_attr(node, 0, "kp", 2, "%0.3f", *pid_kp);
-	if(attr == NULL)
-		goto error;
-	attr= addf_mi_attr(node, 0, "kd", 2, "%0.3f", *pid_kd);
-	LOCK_RELEASE(rl_lock);
-	if(attr == NULL)
-		goto error;
-
-	return rpl_tree;
-
-error:
-	LOCK_RELEASE(rl_lock);
-	LM_ERR("Unable to create reply\n");
-	free_mi_tree(rpl_tree);
-	return 0;
-}
-
-struct mi_root* mi_set_pid(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_node *node;
-	char i[5], p[5], d[5];
-
-	node = cmd_tree->node.kids;
-	if (node == NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
-	if ( !node->value.s || !node->value.len || node->value.len >= 5)
-		goto bad_syntax;
-	memcpy(i, node->value.s, node->value.len);
-	i[node->value.len] = '\0';
-
-	node = node->next;
-	if ( !node->value.s || !node->value.len || node->value.len >= 5)
-		goto bad_syntax;
-	memcpy(p, node->value.s, node->value.len);
-	p[node->value.len] = '\0';
-
-	node = node->next;
-	if ( !node->value.s || !node->value.len || node->value.len >= 5)
-		goto bad_syntax;
-	memcpy(d, node->value.s, node->value.len);
-	d[node->value.len] = '\0';
-
-	LOCK_GET(rl_lock);
-	*pid_ki = strtod(i, NULL);
-	*pid_kp = strtod(p, NULL);
-	*pid_kd = strtod(d, NULL);
-	LOCK_RELEASE(rl_lock);
-
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-bad_syntax:
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
-}
-
-struct mi_root* mi_push_load(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_node *node;
-	double value;
-	char c[5];
-
-	node = cmd_tree->node.kids;
-	if (node == NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
-	if ( !node->value.s || !node->value.len || node->value.len >= 5)
-		goto bad_syntax;
-	memcpy(c, node->value.s, node->value.len);
-	c[node->value.len] = '\0';
-	value = strtod(c, NULL);
-	if (value < 0.0 || value > 1.0) {
-		LM_ERR("value out of range: %0.3f in not in [0.0,1.0]\n", value);
-		goto bad_syntax;
-	}
-	LOCK_GET(rl_lock);
-	*load_value = value;
-	LOCK_RELEASE(rl_lock);
-
-	do_update_load();
-
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-bad_syntax:
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
-}
-
-struct mi_root* mi_set_dbg(struct mi_root* cmd_tree, void* param)
-{
-	struct mi_node *node;
-	unsigned int dbg_mode = 0;
-
-	node = cmd_tree->node.kids; 
-	if (node == NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&dbg_mode)<0)
-		goto bad_syntax;
-
-	LOCK_GET(rl_lock);
-	if (dbg_mode) {
-		if (!rl_dbg_str->s) {
-			rl_dbg_str->len = (MAX_PIPES * 5 * sizeof(char));
-			rl_dbg_str->s = (char *)shm_malloc(rl_dbg_str->len);
-			if (!rl_dbg_str->s) {
-				rl_dbg_str->len = 0;
-				LM_ERR("oom: %d\n", rl_dbg_str->len);
-			}
-		}
-	} else {
-		if (rl_dbg_str->s) {
-			shm_free(rl_dbg_str->s);
-			rl_dbg_str->s = NULL;
-			rl_dbg_str->len = 0;
-		}
-	}
-	LOCK_RELEASE(rl_lock);
-
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
-bad_syntax:
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
-}
-
-
 /* rpc function documentation */
 static const char *rpc_stats_doc[2] = {
 	"Print ratelimit statistics: PIPE[<pipe_id>]: \