static struct mi_root* mi_set_dbg_mod_facility(struct mi_root *cmd_tree, void *param) { struct mi_node *node; str mod_str, facility_str; int fl; /* 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; /* get second param */ node = node->next; 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 facility str */ facility_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 facility int */ facility_str.s[facility_str.len] = '\0'; if ((fl = str2facility(facility_str.s)) == -1) { LM_ERR("invalid parameter - facility value: %.*s\n", facility_str.len, facility_str.s); return init_mi_tree(400, MI_BAD_PARM_S, MI_BAD_PARM_LEN); } /* set facility int */ 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); } return init_mi_tree(200, MI_OK_S, MI_OK_LEN); }
static int dbg_mod_facility_param(modparam_t type, void *val) { char *p; str s; int fl; if(val==NULL) return -1; p = strchr((char*)val, '='); if(p==NULL) { LM_ERR("invalid parameter value: %s\n", (char*)val); return -1; } s.s = p + 1; s.len = strlen(s.s); if ((fl = str2facility(s.s)) == -1) { LM_ERR("invalid parameter - facility value: %s\n", (char*)val); return -1; } s.s = (char*)val; s.len = p - s.s; if (!dbg_cfg) { return -1; } LM_DBG("cfg facility_mode:%d hash_size:%d\n", cfg_get(dbg, dbg_cfg, mod_facility_mode), cfg_get(dbg, dbg_cfg, mod_hash_size)); if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0) { LM_ERR("failed to init per module log level\n"); return -1; } if(dbg_set_mod_debug_facility(s.s, s.len, &fl)<0) { LM_ERR("cannot store parameter: %s\n", (char*)val); return -1; } return 0; }