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