res_snmp.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "asterisk.h"
00026
00027 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00028
00029 #include "asterisk/channel.h"
00030 #include "asterisk/module.h"
00031
00032 #include "snmp/agent.h"
00033
00034 #define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk"
00035
00036 int res_snmp_agentx_subagent;
00037 int res_snmp_dont_stop;
00038 static int res_snmp_enabled;
00039
00040 static pthread_t thread = AST_PTHREADT_NULL;
00041
00042
00043
00044
00045
00046 static int load_config(void)
00047 {
00048 struct ast_variable *var;
00049 struct ast_config *cfg;
00050 struct ast_flags config_flags = { 0 };
00051 char *cat;
00052
00053 res_snmp_enabled = 0;
00054 res_snmp_agentx_subagent = 1;
00055 cfg = ast_config_load("res_snmp.conf", config_flags);
00056 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
00057 ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
00058 return 0;
00059 }
00060 cat = ast_category_browse(cfg, NULL);
00061 while (cat) {
00062 var = ast_variable_browse(cfg, cat);
00063
00064 if (strcasecmp(cat, "general") == 0) {
00065 while (var) {
00066 if (strcasecmp(var->name, "subagent") == 0) {
00067 if (ast_true(var->value))
00068 res_snmp_agentx_subagent = 1;
00069 else if (ast_false(var->value))
00070 res_snmp_agentx_subagent = 0;
00071 else {
00072 ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
00073 ast_config_destroy(cfg);
00074 return 1;
00075 }
00076 } else if (strcasecmp(var->name, "enabled") == 0) {
00077 res_snmp_enabled = ast_true(var->value);
00078 } else {
00079 ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
00080 ast_config_destroy(cfg);
00081 return 1;
00082 }
00083 var = var->next;
00084 }
00085 } else {
00086 ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
00087 ast_config_destroy(cfg);
00088 return 1;
00089 }
00090
00091 cat = ast_category_browse(cfg, cat);
00092 }
00093 ast_config_destroy(cfg);
00094 return 1;
00095 }
00096
00097 static int load_module(void)
00098 {
00099 if(!load_config())
00100 return AST_MODULE_LOAD_DECLINE;
00101
00102 ast_verb(1, "Loading [Sub]Agent Module\n");
00103
00104 res_snmp_dont_stop = 1;
00105 if (res_snmp_enabled)
00106 return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
00107 else
00108 return 0;
00109 }
00110
00111 static int unload_module(void)
00112 {
00113 ast_verb(1, "Unloading [Sub]Agent Module\n");
00114
00115 res_snmp_dont_stop = 0;
00116 return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
00117 }
00118
00119 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SNMP [Sub]Agent for Asterisk",
00120 .load = load_module,
00121 .unload = unload_module,
00122 );