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