Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
Macros | Functions | Variables
res_snmp.c File Reference

SNMP Agent / SubAgent support for Asterisk. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "snmp/agent.h"
Include dependency graph for res_snmp.c:

Go to the source code of this file.

Macros

#define MODULE_DESCRIPTION   "SNMP [Sub]Agent for Asterisk"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_config (void)
 Load res_snmp.conf config file.
 
static int load_module (void)
 Load the module.
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SNMP [Sub]Agent for Asterisk" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
int res_snmp_agentx_subagent
 
int res_snmp_dont_stop
 
static int res_snmp_enabled
 
static pthread_t thread = AST_PTHREADT_NULL
 

Detailed Description

SNMP Agent / SubAgent support for Asterisk.

Author
Thorsten Lockert tholo.nosp@m.@voo.nosp@m.p.as

Uses the Net-SNMP libraries available at http://net-snmp.sourceforge.net/

Definition in file res_snmp.c.

Macro Definition Documentation

◆ MODULE_DESCRIPTION

#define MODULE_DESCRIPTION   "SNMP [Sub]Agent for Asterisk"

Definition at line 41 of file res_snmp.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 140 of file res_snmp.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 140 of file res_snmp.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 140 of file res_snmp.c.

◆ load_config()

static int load_config ( void  )
static

Load res_snmp.conf config file.

Returns
1 on load, 0 file does not exist

Definition at line 53 of file res_snmp.c.

54{
55 struct ast_variable *var;
56 struct ast_config *cfg;
57 struct ast_flags config_flags = { 0 };
58 char *cat;
59
62 cfg = ast_config_load("res_snmp.conf", config_flags);
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))
76 else if (ast_false(var->value))
78 else {
79 ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
81 return 1;
82 }
83 } else if (strcasecmp(var->name, "enabled") == 0) {
85 } else {
86 ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
88 return 1;
89 }
90 var = var->next;
91 }
92 } else {
93 ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
95 return 1;
96 }
97
98 cat = ast_category_browse(cfg, cat);
99 }
101 return 1;
102}
#define var
Definition ast_expr2f.c:605
#define ast_log
Definition astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition extconf.c:3324
#define CONFIG_STATUS_FILEMISSING
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
#define LOG_ERROR
#define LOG_WARNING
int res_snmp_agentx_subagent
Definition res_snmp.c:43
static int res_snmp_enabled
Definition res_snmp.c:45
#define NULL
Definition resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2235
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition utils.c:2252
Structure used to handle boolean flags.
Definition utils.h:217
Structure for variables, used for configurations and for channel variables.

References ast_category_browse(), ast_config_destroy(), ast_config_load, ast_false(), ast_log, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, LOG_ERROR, LOG_WARNING, NULL, res_snmp_agentx_subagent, res_snmp_enabled, and var.

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Load the module.

Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.

Definition at line 114 of file res_snmp.c.

115{
116 if(!load_config())
118
119 ast_verb(1, "Loading [Sub]Agent Module\n");
120
124 else
125 return 0;
126}
void * agent_thread(void *arg)
Definition agent.c:186
#define ast_verb(level,...)
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
static pthread_t thread
Definition res_snmp.c:47
int res_snmp_dont_stop
Definition res_snmp.c:44
static int load_config(void)
Load res_snmp.conf config file.
Definition res_snmp.c:53
#define ast_pthread_create_background(a, b, c, d)
Definition utils.h:629

References agent_thread(), AST_MODULE_LOAD_DECLINE, ast_pthread_create_background, ast_verb, load_config(), NULL, res_snmp_dont_stop, res_snmp_enabled, and thread.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 128 of file res_snmp.c.

129{
130 ast_verb(1, "Unloading [Sub]Agent Module\n");
131
133 return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
134}
#define AST_PTHREADT_NULL
Definition lock.h:73

References AST_PTHREADT_NULL, ast_verb, NULL, res_snmp_dont_stop, and thread.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SNMP [Sub]Agent for Asterisk" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, }
static

Definition at line 140 of file res_snmp.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 140 of file res_snmp.c.

◆ res_snmp_agentx_subagent

int res_snmp_agentx_subagent

Definition at line 43 of file res_snmp.c.

Referenced by agent_thread(), and load_config().

◆ res_snmp_dont_stop

int res_snmp_dont_stop

Definition at line 44 of file res_snmp.c.

Referenced by agent_thread(), load_module(), and unload_module().

◆ res_snmp_enabled

int res_snmp_enabled
static

Definition at line 45 of file res_snmp.c.

Referenced by load_config(), and load_module().

◆ thread

pthread_t thread = AST_PTHREADT_NULL
static

Definition at line 47 of file res_snmp.c.

Referenced by load_module(), and unload_module().