asterisk/res/res_snmp.c
Kevin P. Fleming e61d3d91f3 The Eurostar Commit! (it's amazing how much work you can get done on a 150 minute train ride from Paris to London <G>)
support the new location for zaptel.h and tonezone.h
use the dependency information output by menuselect to build Makefile rules for each module for header files and libraries
combine the common rules into a top-level Makefile.rules file
remove all (now) unnecessary stuff from subdir Makefiles
change translator API so that the newpvt() callback returns an int instead of a pointer (it no longer allocates memory)
alphabetize --with-<foo> options in configure script
enhance Net-SNMP support in configure script to provide a --with-netsnmp option
fix support for --with-pq so that if pg-config is not found when --with-pq is specified, an error will be generated
add 'optional package' usage to modules now that menuselect can output it
allow res_snmp to build by default, since the new loader changes coming soon will solve the function naming problem (and users can disable it via menuselect anyway)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@35832 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-24 19:43:31 +00:00

144 lines
2.9 KiB
C

/*
* Copyright (C) 2006 Voop as
* Thorsten Lockert <tholo@voop.as>
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief SNMP Agent / SubAgent support for Asterisk
*
* \author Thorsten Lockert <tholo@voop.as>
*/
/*** MODULEINFO
<depend>netsnmp</depend>
***/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "snmp/agent.h"
#define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk"
int res_snmp_agentx_subagent;
int res_snmp_dont_stop;
int res_snmp_enabled;
static pthread_t thread = AST_PTHREADT_NULL;
static int load_config(void)
{
struct ast_variable *var;
struct ast_config *cfg;
char *cat;
res_snmp_enabled = 0;
res_snmp_agentx_subagent = 1;
cfg = ast_config_load("res_snmp.conf");
if (cfg) {
cat = ast_category_browse(cfg, NULL);
while (cat) {
var = ast_variable_browse(cfg, cat);
if (strcasecmp(cat, "general") == 0) {
while (var) {
if (strcasecmp(var->name, "subagent") == 0) {
if (ast_true(var->value))
res_snmp_agentx_subagent = 1;
else if (ast_false(var->value))
res_snmp_agentx_subagent = 0;
else {
ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n",
var->value);
ast_config_destroy(cfg);
return 1;
}
} else if (strcasecmp(var->name, "enabled") == 0) {
res_snmp_enabled = ast_true(var->value);
} else {
ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n",
var->name, cat);
ast_config_destroy(cfg);
return 1;
}
var = var->next;
}
}
else {
ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
ast_config_destroy(cfg);
return 1;
}
cat = ast_category_browse(cfg, cat);
}
ast_config_destroy(cfg);
}
return 0;
}
int load_module(void)
{
load_config();
ast_verbose(VERBOSE_PREFIX_1 "Loading [Sub]Agent Module\n");
res_snmp_dont_stop = 1;
if (res_snmp_enabled)
return ast_pthread_create(&thread, NULL, agent_thread, NULL);
else
return 0;
}
int unload_module(void)
{
ast_verbose(VERBOSE_PREFIX_1 "Unloading [Sub]Agent Module\n");
res_snmp_dont_stop = 0;
return pthread_join(thread, NULL);
}
int reload(void)
{
ast_verbose(VERBOSE_PREFIX_1 "Reloading [Sub]Agent Module\n");
res_snmp_dont_stop = 0;
if (thread != AST_PTHREADT_NULL)
pthread_join(thread, NULL);
thread = AST_PTHREADT_NULL;
load_config();
res_snmp_dont_stop = 1;
if (res_snmp_enabled)
return ast_pthread_create(&thread, NULL, agent_thread, NULL);
else
return 0;
}
int usecount(void)
{
return 0;
}
const char *key(void)
{
return ASTERISK_GPL_KEY;
}
const char *description(void)
{
return MODULE_DESCRIPTION;
}