libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_parser_mibs.c File Reference

Go to the source code of this file.

Data Structures

struct  _mib_info
 

Macros

#define _GNU_SOURCE
 

Typedefs

typedef struct _mib_info mib_info_t
 

Functions

static void amxo_parser_add_mib_info (amxc_htable_t *mibs, const char *name, const char *expression, const char *file)
 
static FILE * amxo_parser_open_mib_file (char *name, amxc_string_t *filename, char **first_line)
 
static bool amxo_parser_build_mib_info (amxo_parser_t *parser, struct dirent *ep, amxc_string_t *filename, char *first_line)
 
static int amxo_parser_scan (amxo_parser_t *parser, const char *path)
 
void amxo_parser_del_mib_info (UNUSED const char *key, amxc_htable_it_t *it)
 
int amxo_parser_scan_mib_dir (amxo_parser_t *parser, const char *path)
 Scans a directory for MIB odl files. More...
 
int amxo_parser_scan_mib_dirs (amxo_parser_t *parser, amxc_var_t *dirs)
 Scans multiple directories for MIB odl files. More...
 
const char * amxo_parser_get_mib_file (amxo_parser_t *parser, const char *mib_name)
 Get full path and file name of odl file describing a mib. More...
 
int amxo_parser_load_mib (amxo_parser_t *parser, amxd_dm_t *dm, const char *mib_name)
 Loads the mib definition. More...
 
int amxo_parser_apply_mib (amxo_parser_t *parser, amxd_object_t *object, const char *mib_name)
 Unconditionally applies a MIB to a data model object. More...
 
int amxo_parser_add_mibs (amxo_parser_t *parser, amxd_object_t *object, amxo_evaluate_expr_fn_t fn)
 Adds zero, one or more MIBs to a data model object. More...
 
int amxo_parser_remove_mibs (amxo_parser_t *parser, amxd_object_t *object, amxo_evaluate_expr_fn_t fn)
 Removes zero, one or more MIBs from a data model object. More...
 
int amxo_parser_apply_mibs (amxo_parser_t *parser, amxd_object_t *object, amxo_evaluate_expr_fn_t fn)
 Applies zero, one or more MIBs to a data model object. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxo_parser_mibs.c.

Typedef Documentation

◆ mib_info_t

typedef struct _mib_info mib_info_t

Function Documentation

◆ amxo_parser_add_mib_info()

static void amxo_parser_add_mib_info ( amxc_htable_t *  mibs,
const char *  name,
const char *  expression,
const char *  file 
)
static

Definition at line 68 of file amxo_parser_mibs.c.

71  {
72  mib_info_t* info = NULL;
73  when_true(amxc_htable_contains(mibs, name), exit);
74 
75  info = (mib_info_t*) calloc(1, sizeof(mib_info_t));
76  when_null(info, exit);
77 
78  info->expression = strdup(expression);
79  info->file = strdup(file);
80 
81  amxc_htable_insert(mibs, name, &info->hit);
82 
83 exit:
84  return;
85 }
char * expression
amxc_htable_it_t hit

◆ amxo_parser_build_mib_info()

static bool amxo_parser_build_mib_info ( amxo_parser_t parser,
struct dirent *  ep,
amxc_string_t *  filename,
char *  first_line 
)
static

Definition at line 106 of file amxo_parser_mibs.c.

109  {
110  bool retval = true;
111  const char* name = NULL;
112  const char* expression = NULL;
113  amxp_expr_t expr;
114 
115  name = basename(ep->d_name);
116  expression = name;
117  if(strncmp(first_line, "/*expr:", 7) == 0) {
118  first_line[ strlen(first_line) - 3 ] = 0;
119  expression = first_line + 7;
120  } else if(strncmp(first_line, "#expr:", 6) == 0) {
121  first_line[ strlen(first_line) - 3 ] = 0;
122  expression = first_line + 6;
123  }
124  if(amxp_expr_init(&expr, expression) == amxp_expr_status_ok) {
126  name,
127  expression,
128  amxc_string_get(filename, 0));
129  } else {
130  retval = false;
131  }
132  amxp_expr_clean(&expr);
133 
134  return retval;
135 }
static void amxo_parser_add_mib_info(amxc_htable_t *mibs, const char *name, const char *expression, const char *file)
amxc_htable_t mibs
Definition: amxo_types.h:282

◆ amxo_parser_del_mib_info()

void amxo_parser_del_mib_info ( UNUSED const char *  key,
amxc_htable_it_t *  it 
)

Definition at line 178 of file amxo_parser_mibs.c.

179  {
180  mib_info_t* info = amxc_htable_it_get_data(it, mib_info_t, hit);
181  free(info->expression);
182  free(info->file);
183  free(info);
184 }

◆ amxo_parser_open_mib_file()

static FILE* amxo_parser_open_mib_file ( char *  name,
amxc_string_t *  filename,
char **  first_line 
)
static

Definition at line 87 of file amxo_parser_mibs.c.

89  {
90  ssize_t read = 0;
91  size_t len = 0;
92  FILE* odlfile = fopen(amxc_string_get(filename, 0), "r");
93 
94  name[strlen(name) - 4] = 0;
95  read = getline(first_line, &len, odlfile);
96  if(read == -1) {
97  free(*first_line);
98  *first_line = NULL;
99  fclose(odlfile);
100  odlfile = NULL;
101  }
102 
103  return odlfile;
104 }

◆ amxo_parser_scan()

static int amxo_parser_scan ( amxo_parser_t parser,
const char *  path 
)
static

Definition at line 137 of file amxo_parser_mibs.c.

138  {
139  int retval = -1;
140  DIR* dp;
141  struct dirent* ep;
142  FILE* odlfile = NULL;
143  char* line = NULL;
144  amxc_string_t filename;
145 
146  amxc_string_init(&filename, 128);
147 
148  dp = opendir(path);
149  when_null(dp, exit);
150 
151  for(ep = readdir(dp); ep; ep = readdir(dp)) {
152  const char* extension = strstr(ep->d_name, ".odl");
153  if((extension == NULL) || (extension[4] != 0)) {
154  continue;
155  }
156 
157  amxc_string_reset(&filename);
158  amxc_string_setf(&filename, "%s/%s", path, ep->d_name);
159  odlfile = amxo_parser_open_mib_file(ep->d_name, &filename, &line);
160  if(odlfile == NULL) {
161  continue;
162  }
163 
164  amxo_parser_build_mib_info(parser, ep, &filename, line);
165  fclose(odlfile);
166  free(line);
167  line = NULL;
168  }
169  closedir(dp);
170 
171  retval = 0;
172 
173 exit:
174  amxc_string_clean(&filename);
175  return retval;
176 }
static bool amxo_parser_build_mib_info(amxo_parser_t *parser, struct dirent *ep, amxc_string_t *filename, char *first_line)
static FILE * amxo_parser_open_mib_file(char *name, amxc_string_t *filename, char **first_line)