Selaa lähdekoodia

debugger: fifo module level/facility getters

Add kamctl fifo module level/facility getters.
Stefan Mititelu 9 vuotta sitten
vanhempi
commit
2bd153ce08
1 muutettua tiedostoa jossa 139 lisäystä ja 6 poistoa
  1. 139 6
      modules/debugger/debugger_mod.c

+ 139 - 6
modules/debugger/debugger_mod.c

@@ -66,6 +66,8 @@ extern char* dump_lump_list(struct lump *list, int s_offset, char *s_buf);
 /* mi commands */
 static struct mi_root* mi_set_dbg_mod_level(struct mi_root *cmd_tree, void *param);
 static struct mi_root* mi_set_dbg_mod_facility(struct mi_root *cmd_tree, void *param);
+static struct mi_root* mi_get_dbg_mod_level(struct mi_root *cmd_tree, void *param);
+static struct mi_root* mi_get_dbg_mod_facility(struct mi_root *cmd_tree, void *param);
 
 /* parameters */
 extern int _dbg_cfgtrace;
@@ -129,6 +131,8 @@ static param_export_t params[]={
 static mi_export_t mi_cmds[] = {
 	{"set_dbg_mod_level",         mi_set_dbg_mod_level, 0, 0, 0},
 	{"set_dbg_mod_facility",      mi_set_dbg_mod_facility, 0, 0, 0},
+	{"get_dbg_mod_level",         mi_get_dbg_mod_level, 0, 0, 0},
+	{"get_dbg_mod_facility",      mi_get_dbg_mod_facility, 0, 0, 0},
 	{ 0, 0, 0, 0, 0}
 };
 
@@ -193,11 +197,13 @@ static struct mi_root* mi_set_dbg_mod_level(struct mi_root *cmd_tree, void *para
 	}
 
 	/* set level int */
-	if (default_dbg_cfg.mod_hash_size <= 0 || default_dbg_cfg.mod_level_mode <= 0 ||
-	    dbg_set_mod_debug_level(mod_str.s, mod_str.len, &l) < 0) {
-		LM_ERR("cannot set level for %.*s; enable mod_hash_size and mod_level_mode\n",
+	if (default_dbg_cfg.mod_hash_size <= 0 || default_dbg_cfg.mod_level_mode <= 0) {
+		LM_ERR("can't set level for module=%.*s; enable mod_hash_size and mod_level_mode config parameters!\n",
 			mod_str.len, mod_str.s);
 		return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
+	} else if (dbg_set_mod_debug_level(mod_str.s, mod_str.len, &l) < 0) {
+		LM_ERR("failed set level for module=%.*s\n", mod_str.len, mod_str.s);
+		return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
 	} else {
 		LM_DBG("module=%.*s level_str=%.*s level_int=%d\n",
 			mod_str.len, mod_str.s, level_str.len, level_str.s, l);
@@ -252,11 +258,13 @@ static struct mi_root* mi_set_dbg_mod_facility(struct mi_root *cmd_tree, void *p
 	}
 
 	/* set facility int */
-	if (default_dbg_cfg.mod_hash_size <= 0 || default_dbg_cfg.mod_facility_mode <= 0 ||
-	    dbg_set_mod_debug_facility(mod_str.s, mod_str.len, &fl) < 0) {
-		LM_ERR("cannot set facility for %.*s; enable mod_hash_size and mod_facility_mode\n",
+	if (default_dbg_cfg.mod_hash_size <= 0 || default_dbg_cfg.mod_facility_mode <= 0) {
+		LM_ERR("can't set facility for module=%.*s; enable mod_hash_size and mod_facility_mode config parameters!\n",
 			mod_str.len, mod_str.s);
 		return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
+	} else if (dbg_set_mod_debug_facility(mod_str.s, mod_str.len, &fl) < 0) {
+		LM_ERR("failed set facility for module=%.*s\n", mod_str.len, mod_str.s);
+		return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
 	} else {
 		LM_DBG("module=%.*s facility_str=%.*s facility_int=%d\n",
 			mod_str.len, mod_str.s, facility_str.len, facility_str.s, fl);
@@ -265,6 +273,131 @@ static struct mi_root* mi_set_dbg_mod_facility(struct mi_root *cmd_tree, void *p
 	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
 }
 
+static struct mi_root* mi_get_dbg_mod_level(struct mi_root *cmd_tree, void *param) {
+	struct mi_node *node, *crt_node;
+	struct mi_root *root = NULL;
+	struct mi_attr *attr;
+	int l;
+	str mod_str, level_str;
+	str level_attr = {"level", strlen("level")};
+
+	/* get first param */
+	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 == NULL || node->value.len == 0) {
+		return init_mi_tree(400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
+	}
+
+	/* get module str */
+	mod_str = node->value;
+
+	/* no further params expected */
+	node = node->next;
+	if (node != NULL) {
+		return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
+	}
+
+	/* get module log level */
+	l = get_debug_level(mod_str.s, mod_str.len);
+	level_str.s = sint2str(l, &level_str.len);
+	LM_DBG("module=%.*s level_str=%.*s level_int=%d\n",
+		mod_str.len, mod_str.s, level_str.len, level_str.s, l);
+
+	/* return module log level */
+	root = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+	if (!root) {
+		LM_ERR("the MI tree cannot be initialized!\n");
+		goto error;
+	}
+	node = &root->node;
+
+	if (!(crt_node = add_mi_node_child(node, 0, mod_str.s, mod_str.len, 0, 0)) ) {
+		LM_ERR("cannot add the child node to the tree\n");
+		goto error;
+	}
+
+	if ((attr = add_mi_attr(crt_node, MI_DUP_VALUE,
+	    level_attr.s, level_attr.len,
+	    level_str.s, level_str.len)) == 0) {
+		LM_ERR("cannot add attributes to the node\n");
+		goto error;
+	}
+
+	return root;
+
+error:
+	if (root) {
+		free_mi_tree(root);
+	}
+
+	return NULL;
+}
+
+static struct mi_root* mi_get_dbg_mod_facility(struct mi_root *cmd_tree, void *param) {
+	struct mi_node *node, *crt_node;
+	struct mi_root *root = NULL;
+	struct mi_attr *attr;
+	int fl;
+	str mod_str, facility_str;
+	str facility_attr = {"facility", strlen("facility")};
+
+	/* get first param */
+	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 == NULL || node->value.len == 0) {
+		return init_mi_tree(400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
+	}
+
+	/* get module str */
+	mod_str = node->value;
+
+	/* no further params expected */
+	node = node->next;
+	if (node != NULL) {
+		return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
+	}
+
+	/* get module log facility */
+	fl = get_debug_facility(mod_str.s, mod_str.len);
+	facility_str.s = facility2str(fl, &facility_str.len);
+	LM_DBG("module=%.*s facility_str=%.*s facility_int=%d\n",
+		mod_str.len, mod_str.s, facility_str.len, facility_str.s, fl);
+
+	/* return module log facility */
+	root = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+	if (!root) {
+		LM_ERR("the MI tree cannot be initialized!\n");
+		goto error;
+	}
+	node = &root->node;
+
+	if (!(crt_node = add_mi_node_child(node, 0, mod_str.s, mod_str.len, 0, 0)) ) {
+		LM_ERR("cannot add the child node to the tree\n");
+		goto error;
+	}
+
+	if ((attr = add_mi_attr(crt_node, MI_DUP_VALUE,
+	    facility_attr.s, facility_attr.len,
+	    facility_str.s, facility_str.len)) == 0) {
+		LM_ERR("cannot add attributes to the node\n");
+		goto error;
+	}
+
+	return root;
+
+error:
+	if (root) {
+		free_mi_tree(root);
+	}
+
+	return NULL;
+}
 
 /**
  * init module function