| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include "asterisk.h" |
| 35 |
|
| 36 |
#include "asterisk/channel.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
|
| 39 |
#include "snmp/agent.h" |
| 40 |
|
| 41 |
#define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk" |
| 42 |
|
| 43 |
int res_snmp_agentx_subagent; |
| 44 |
int res_snmp_dont_stop; |
| 45 |
static int res_snmp_enabled; |
| 46 |
|
| 47 |
static pthread_t thread = AST_PTHREADT_NULL; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
static int load_config(void) |
| 54 |
{ |
| 55 |
struct ast_variable *var; |
| 56 |
struct ast_config *cfg; |
| 57 |
struct ast_flags config_flags = { 0 }; |
| 58 |
char *cat; |
| 59 |
|
| 60 |
res_snmp_enabled = 0; |
| 61 |
res_snmp_agentx_subagent = 1; |
| 62 |
cfg = ast_config_load("res_snmp.conf", config_flags); |
| 63 |
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) { |
| 64 |
ast_log(LOG_WARNING, "Could not load res_snmp.conf\n"); |
| 65 |
return 0; |
| 66 |
} |
| 67 |
cat = ast_category_browse(cfg, NULL); |
| 68 |
while (cat) { |
| 69 |
var = ast_variable_browse(cfg, cat); |
| 70 |
|
| 71 |
if (strcasecmp(cat, "general") == 0) { |
| 72 |
while (var) { |
| 73 |
if (strcasecmp(var->name, "subagent") == 0) { |
| 74 |
if (ast_true(var->value)) |
| 75 |
res_snmp_agentx_subagent = 1; |
| 76 |
else if (ast_false(var->value)) |
| 77 |
res_snmp_agentx_subagent = 0; |
| 78 |
else { |
| 79 |
ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value); |
| 80 |
ast_config_destroy(cfg); |
| 81 |
return 1; |
| 82 |
} |
| 83 |
} else if (strcasecmp(var->name, "enabled") == 0) { |
| 84 |
res_snmp_enabled = ast_true(var->value); |
| 85 |
} else { |
| 86 |
ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat); |
| 87 |
ast_config_destroy(cfg); |
| 88 |
return 1; |
| 89 |
} |
| 90 |
var = var->next; |
| 91 |
} |
| 92 |
} else { |
| 93 |
ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat); |
| 94 |
ast_config_destroy(cfg); |
| 95 |
return 1; |
| 96 |
} |
| 97 |
|
| 98 |
cat = ast_category_browse(cfg, cat); |
| 99 |
} |
| 100 |
ast_config_destroy(cfg); |
| 101 |
return 1; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
static int load_module(void) |
| 115 |
{ |
| 116 |
if(!load_config()) |
| 117 |
return AST_MODULE_LOAD_DECLINE; |
| 118 |
|
| 119 |
ast_verb(1, "Loading [Sub]Agent Module\n"); |
| 120 |
|
| 121 |
res_snmp_dont_stop = 1; |
| 122 |
if (res_snmp_enabled) |
| 123 |
return ast_pthread_create_background(&thread, NULL, agent_thread, NULL); |
| 124 |
else |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
static int unload_module(void) |
| 129 |
{ |
| 130 |
ast_verb(1, "Unloading [Sub]Agent Module\n"); |
| 131 |
|
| 132 |
res_snmp_dont_stop = 0; |
| 133 |
return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0); |
| 134 |
} |
| 135 |
|
| 136 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SNMP [Sub]Agent for Asterisk", |
| 137 |
.support_level = AST_MODULE_SUPPORT_EXTENDED, |
| 138 |
.load = load_module, |
| 139 |
.unload = unload_module, |
| 140 |
); |