Sat Nov 25 00:46:07 2006

Asterisk developer's documentation


misdn_config.c File Reference

chan_misdn configuration management More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "chan_misdn_config.h"
#include <asterisk/config.h>
#include <asterisk/channel.h>
#include <asterisk/logger.h>
#include <asterisk/lock.h>
#include <asterisk/pbx.h>
#include <asterisk/strings.h>
#include <asterisk/utils.h>

Go to the source code of this file.

Data Structures

union  misdn_cfg_pt
struct  misdn_cfg_spec
struct  msn_list

Defines

#define AST_DESTROY_CFG   ast_config_destroy
#define AST_LOAD_CFG   ast_config_load
#define CLI_ERROR(name, value, section)
#define GEN_CFG   1
#define NO_DEFAULT   "<>"
#define NONE   0
#define NUM_GEN_ELEMENTS   (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec))
#define NUM_PORT_ELEMENTS   (sizeof(port_spec) / sizeof(struct misdn_cfg_spec))
#define PORT_CFG   2

Enumerations

enum  misdn_cfg_type {
  MISDN_CTYPE_STR, MISDN_CTYPE_INT, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT,
  MISDN_CTYPE_MSNLIST, MISDN_CTYPE_ASTGROUP
}

Functions

static void _build_general_config (struct ast_variable *v)
static void _build_port_config (struct ast_variable *v, char *cat)
static void _enum_array_map (void)
static void _fill_defaults (void)
static void _free_general_cfg (void)
static void _free_msn_list (struct msn_list *iter)
static void _free_port_cfg (void)
static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def)
static int get_cfg_position (char *name, int type)
void misdn_cfg_destroy (void)
void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
void misdn_cfg_get_config_string (int port, enum misdn_cfg_elements elem, char *buf, int bufsize)
int misdn_cfg_get_next_port (int port)
int misdn_cfg_get_next_port_spin (int port)
void misdn_cfg_get_ports_string (char *ports)
void misdn_cfg_init (int this_max_ports)
int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth)
int misdn_cfg_is_msn_valid (int port, char *msn)
int misdn_cfg_is_port_valid (int port)
static void misdn_cfg_lock (void)
void misdn_cfg_reload (void)
static void misdn_cfg_unlock (void)
void misdn_cfg_update_ptp (void)

Variables

static ast_mutex_t config_mutex
static const struct misdn_cfg_spec gen_spec []
static union misdn_cfg_ptgeneral_cfg
static int * map
static int max_ports
static union misdn_cfg_pt ** port_cfg
static const struct misdn_cfg_spec port_spec []
static int * ptp


Detailed Description

chan_misdn configuration management

Author:
Christian Richter <crich@beronet.com>

Definition in file misdn_config.c.


Define Documentation

#define AST_DESTROY_CFG   ast_config_destroy
 

Definition at line 45 of file misdn_config.c.

#define AST_LOAD_CFG   ast_config_load
 

Definition at line 44 of file misdn_config.c.

#define CLI_ERROR name,
value,
section   ) 
 

Value:

({ \
   ast_log(LOG_WARNING, "misdn.conf: \"%s=%s\" (section: %s) invalid or out of range. " \
      "Please edit your misdn.conf and then do a \"misdn reload\".\n", name, value, section); \
})

Definition at line 151 of file misdn_config.c.

Referenced by _build_general_config(), and _build_port_config().

#define GEN_CFG   1
 

Definition at line 50 of file misdn_config.c.

Referenced by _build_general_config(), and get_cfg_position().

#define NO_DEFAULT   "<>"
 

Definition at line 47 of file misdn_config.c.

Referenced by _fill_defaults().

#define NONE   0
 

Definition at line 48 of file misdn_config.c.

#define NUM_GEN_ELEMENTS   (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec))
 

Definition at line 52 of file misdn_config.c.

Referenced by _free_general_cfg(), and get_cfg_position().

#define NUM_PORT_ELEMENTS   (sizeof(port_spec) / sizeof(struct misdn_cfg_spec))
 

Definition at line 53 of file misdn_config.c.

Referenced by _build_port_config(), _enum_array_map(), _fill_defaults(), get_cfg_position(), and misdn_cfg_init().

#define PORT_CFG   2
 

Definition at line 51 of file misdn_config.c.

Referenced by _build_port_config(), and get_cfg_position().


Enumeration Type Documentation

enum misdn_cfg_type
 

Enumerator:
MISDN_CTYPE_STR 
MISDN_CTYPE_INT 
MISDN_CTYPE_BOOL 
MISDN_CTYPE_BOOLINT 
MISDN_CTYPE_MSNLIST 
MISDN_CTYPE_ASTGROUP 

Definition at line 55 of file misdn_config.c.


Function Documentation

static void _build_general_config struct ast_variable v  )  [static]
 

Definition at line 586 of file misdn_config.c.

References _parse(), misdn_cfg_spec::boolint_def, CLI_ERROR, GEN_CFG, gen_spec, general_cfg, get_cfg_position(), ast_variable::name, ast_variable::next, misdn_cfg_spec::type, and ast_variable::value.

00587 {
00588    int pos;
00589 
00590    for (; v; v = v->next) {
00591       if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 
00592          (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
00593          CLI_ERROR(v->name, v->value, "general");
00594    }
00595 }

static void _build_port_config struct ast_variable v,
char *  cat
[static]
 

Definition at line 597 of file misdn_config.c.

References _parse(), CLI_ERROR, get_cfg_position(), max_ports, ast_variable::name, ast_variable::next, NUM_PORT_ELEMENTS, PORT_CFG, port_spec, ptp, strsep(), type, and ast_variable::value.

00598 {
00599    int pos, i;
00600    union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
00601    int cfg_for_ports[max_ports + 1];
00602 
00603    if (!v || !cat)
00604       return;
00605 
00606    memset(cfg_tmp, 0, sizeof(cfg_tmp));
00607    memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
00608 
00609    if (!strcasecmp(cat, "default")) {
00610       cfg_for_ports[0] = 1;
00611    }
00612 
00613    if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 
00614       (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
00615       CLI_ERROR(v->name, v->value, cat);
00616       return;
00617    }
00618 
00619    for (; v; v = v->next) {
00620       if (!strcasecmp(v->name, "ports")) {
00621          char *token;
00622          char ptpbuf[BUFFERSIZE] = "";
00623          int start, end;
00624          for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 
00625             if (!*token)
00626                continue;
00627             if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) {
00628                for (; start <= end; start++) {
00629                   if (start <= max_ports && start > 0) {
00630                      cfg_for_ports[start] = 1;
00631                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00632                   } else
00633                      CLI_ERROR(v->name, v->value, cat);
00634                }
00635             } else {
00636                if (sscanf(token, "%d%s", &start, ptpbuf)) {
00637                   if (start <= max_ports && start > 0) {
00638                      cfg_for_ports[start] = 1;
00639                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00640                   } else
00641                      CLI_ERROR(v->name, v->value, cat);
00642                } else
00643                   CLI_ERROR(v->name, v->value, cat);
00644             }
00645          }
00646       } else {
00647          if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 
00648             (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
00649             CLI_ERROR(v->name, v->value, cat);
00650       }
00651    }
00652 
00653    for (i = 0; i < (max_ports + 1); ++i) {
00654       if (cfg_for_ports[i]) {
00655          memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
00656       }
00657    }
00658 }

static void _enum_array_map void   )  [static]
 

Definition at line 156 of file misdn_config.c.

References map, NUM_PORT_ELEMENTS, and port_spec.

Referenced by misdn_cfg_init().

00157 {
00158    int i, j;
00159 
00160    for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
00161       if (i == MISDN_CFG_PTP)
00162          continue;
00163       for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
00164          if (port_spec[j].elem == i) {
00165             map[i] = j;
00166             break;
00167          }
00168       }
00169    }
00170    for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
00171       for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
00172          if (gen_spec[j].elem == i) {
00173             map[i] = j;
00174             break;
00175          }
00176       }
00177    }
00178 }

static void _fill_defaults void   )  [static]
 

Definition at line 694 of file misdn_config.c.

References _parse(), misdn_cfg_pt::any, NO_DEFAULT, NUM_PORT_ELEMENTS, port_cfg, port_spec, and type.

00695 {
00696    int i;
00697 
00698    for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00699       if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
00700          _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
00701    }
00702    for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
00703       if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
00704          _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
00705    }
00706 }

static void _free_general_cfg void   )  [static]
 

Definition at line 253 of file misdn_config.c.

References misdn_cfg_pt::any, free, general_cfg, and NUM_GEN_ELEMENTS.

Referenced by misdn_cfg_destroy().

00254 {
00255    int i;
00256 
00257    for (i = 0; i < NUM_GEN_ELEMENTS; i++) 
00258       if (general_cfg[i].any)
00259          free(general_cfg[i].any);
00260 }

static void _free_msn_list struct msn_list iter  )  [static]
 

Definition at line 211 of file misdn_config.c.

References free, msn_list::msn, and msn_list::next.

00212 {
00213    if (iter->next)
00214       _free_msn_list(iter->next);
00215    if (iter->msn)
00216       free(iter->msn);
00217    free(iter);
00218 }

static void _free_port_cfg void   )  [static]
 

Definition at line 220 of file misdn_config.c.

References map, max_ports, port_cfg, and misdn_cfg_pt::str.

Referenced by misdn_cfg_destroy().

00221 {
00222    int i, j;
00223    int gn = map[MISDN_CFG_GROUPNAME];
00224    union misdn_cfg_pt* free_list[max_ports + 2];
00225    
00226    memset(free_list, 0, sizeof(free_list));
00227    free_list[0] = port_cfg[0];
00228    for (i = 1; i <= max_ports; ++i) {
00229       if (port_cfg[i][gn].str) {
00230          /* we always have a groupname in the non-default case, so this is fine */
00231          for (j = 1; j <= max_ports; ++j) {
00232             if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
00233                break;
00234             else if (!free_list[j]) {
00235                free_list[j] = port_cfg[i];
00236                break;
00237             }
00238          }
00239       }
00240    }
00241    for (j = 0; free_list[j]; ++j) {
00242       for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00243          if (free_list[j][i].any) {
00244             if (port_spec[i].type == MISDN_CTYPE_MSNLIST)
00245                _free_msn_list(free_list[j][i].ml);
00246             else
00247                free(free_list[j][i].any);
00248          }
00249       }
00250    }
00251 }

static int _parse union misdn_cfg_pt dest,
char *  value,
enum misdn_cfg_type  type,
int  boolint_def
[static]
 

Definition at line 523 of file misdn_config.c.

References ast_get_group(), ast_true(), calloc, misdn_cfg_pt::grp, malloc, MISDN_CTYPE_ASTGROUP, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_INT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_STR, misdn_cfg_pt::ml, msn_list::msn, msn_list::next, misdn_cfg_pt::num, misdn_cfg_pt::str, and strsep().

Referenced by _build_general_config(), _build_port_config(), and _fill_defaults().

00524 {
00525    int re = 0;
00526    int len, tmp;
00527    char *valtmp;
00528 
00529    switch (type) {
00530    case MISDN_CTYPE_STR:
00531       if ((len = strlen(value))) {
00532          dest->str = (char *)malloc((len + 1) * sizeof(char));
00533          strncpy(dest->str, value, len);
00534          dest->str[len] = 0;
00535       } else {
00536          dest->str = (char *)malloc( sizeof(char));
00537          dest->str[0] = 0;
00538       }
00539       break;
00540    case MISDN_CTYPE_INT:
00541    {
00542       char *pat;
00543       if (strchr(value,'x')) 
00544          pat="%x";
00545       else
00546          pat="%d";
00547       if (sscanf(value, pat, &tmp)) {
00548          dest->num = (int *)malloc(sizeof(int));
00549          memcpy(dest->num, &tmp, sizeof(int));
00550       } else
00551          re = -1;
00552    }
00553       break;
00554    case MISDN_CTYPE_BOOL:
00555       dest->num = (int *)malloc(sizeof(int));
00556       *(dest->num) = (ast_true(value) ? 1 : 0);
00557       break;
00558    case MISDN_CTYPE_BOOLINT:
00559       dest->num = (int *)malloc(sizeof(int));
00560       if (sscanf(value, "%d", &tmp)) {
00561          memcpy(dest->num, &tmp, sizeof(int));
00562       } else {
00563          *(dest->num) = (ast_true(value) ? boolint_def : 0);
00564       }
00565       break;
00566    case MISDN_CTYPE_MSNLIST:
00567       for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) {
00568          if ((len = strlen(valtmp))) {
00569             struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list));
00570             ml->msn = (char *)calloc(len+1, sizeof(char));
00571             strncpy(ml->msn, valtmp, len);
00572             ml->next = dest->ml;
00573             dest->ml = ml;
00574          }
00575       }
00576       break;
00577    case MISDN_CTYPE_ASTGROUP:
00578       dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
00579       *(dest->grp) = ast_get_group(value);
00580       break;
00581    }
00582 
00583    return re;
00584 }

static int get_cfg_position char *  name,
int  type
[static]
 

Definition at line 180 of file misdn_config.c.

References GEN_CFG, gen_spec, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, PORT_CFG, and port_spec.

Referenced by _build_general_config(), and _build_port_config().

00181 {
00182    int i;
00183 
00184    switch (type) {
00185    case PORT_CFG:
00186       for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00187          if (!strcasecmp(name, port_spec[i].name))
00188             return i;
00189       }
00190       break;
00191    case GEN_CFG:
00192       for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
00193          if (!strcasecmp(name, gen_spec[i].name))
00194             return i;
00195       }
00196    }
00197 
00198    return -1;
00199 }

void misdn_cfg_destroy void   ) 
 

Definition at line 713 of file misdn_config.c.

References _free_general_cfg(), _free_port_cfg(), ast_mutex_destroy(), config_mutex, free, general_cfg, map, misdn_cfg_lock(), misdn_cfg_unlock(), port_cfg, and ptp.

Referenced by unload_module().

00714 {
00715    misdn_cfg_lock();
00716 
00717    _free_port_cfg();
00718    _free_general_cfg();
00719 
00720    free(port_cfg);
00721    free(general_cfg);
00722    free(ptp);
00723    free(map);
00724 
00725    misdn_cfg_unlock();
00726    ast_mutex_destroy(&config_mutex);
00727 }

void misdn_cfg_get int  port,
enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize
 

Definition at line 262 of file misdn_config.c.

References misdn_cfg_pt::any, ast_log(), gen_spec, general_cfg, LOG_WARNING, map, misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_CTYPE_STR, port_cfg, port_spec, ptp, misdn_cfg_pt::str, and type.

Referenced by cb_events(), dialtone_indicate(), load_module(), misdn_bridge(), misdn_cfg_update_ptp(), misdn_new(), misdn_request(), read_config(), reload_config(), update_config(), and update_ec_config().

00263 {
00264    int place;
00265 
00266    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00267       memset(buf, 0, bufsize);
00268       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
00269       return;
00270    }
00271 
00272    misdn_cfg_lock();
00273    if (elem == MISDN_CFG_PTP) {
00274       if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
00275          memset(buf, 0, bufsize);
00276    } else {
00277       if ((place = map[elem]) < 0) {
00278          memset (buf, 0, bufsize);
00279          ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
00280       } else {
00281          if (elem < MISDN_CFG_LAST) {
00282             switch (port_spec[place].type) {
00283             case MISDN_CTYPE_STR:
00284                if (port_cfg[port][place].str) {
00285                   if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
00286                      memset(buf, 0, 1);
00287                } else if (port_cfg[0][place].str) {
00288                   if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
00289                      memset(buf, 0, 1);
00290                }
00291                break;
00292             default:
00293                if (port_cfg[port][place].any)
00294                   memcpy(buf, port_cfg[port][place].any, bufsize);
00295                else if (port_cfg[0][place].any)
00296                   memcpy(buf, port_cfg[0][place].any, bufsize);
00297                else
00298                   memset(buf, 0, bufsize);
00299             }
00300          } else {
00301             switch (gen_spec[place].type) {
00302             case MISDN_CTYPE_STR:
00303                if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
00304                   memset(buf, 0, 1);
00305                break;
00306             default:
00307                if (general_cfg[place].any)
00308                   memcpy(buf, general_cfg[place].any, bufsize);
00309                else
00310                   memset(buf, 0, bufsize);
00311             }
00312          }
00313       }
00314    }
00315    misdn_cfg_unlock();
00316 }

void misdn_cfg_get_config_string int  port,
enum misdn_cfg_elements  elem,
char *  buf,
int  bufsize
 

Definition at line 398 of file misdn_config.c.

References ast_log(), ast_print_group(), gen_spec, general_cfg, LOG_WARNING, map, misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_CTYPE_ASTGROUP, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_INT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_STR, misdn_cfg_pt::ml, msn_list::msn, name, msn_list::next, port_cfg, port_spec, ptp, and type.

Referenced by misdn_show_config().

00399 {
00400    int place;
00401    char tempbuf[BUFFERSIZE] = "";
00402    struct msn_list *iter;
00403 
00404    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00405       *buf = 0;
00406       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
00407       return;
00408    }
00409 
00410    place = map[elem];
00411 
00412    misdn_cfg_lock();
00413    if (elem == MISDN_CFG_PTP) {
00414       snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
00415    }
00416    else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
00417       switch (port_spec[place].type) {
00418       case MISDN_CTYPE_INT:
00419       case MISDN_CTYPE_BOOLINT:
00420          if (port_cfg[port][place].num)
00421             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
00422          else if (port_cfg[0][place].num)
00423             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
00424          else
00425             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00426          break;
00427       case MISDN_CTYPE_BOOL:
00428          if (port_cfg[port][place].num)
00429             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
00430          else if (port_cfg[0][place].num)
00431             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
00432          else
00433             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00434          break;
00435       case MISDN_CTYPE_ASTGROUP:
00436          if (port_cfg[port][place].grp)
00437             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00438                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
00439          else if (port_cfg[0][place].grp)
00440             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00441                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
00442          else
00443             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00444          break;
00445       case MISDN_CTYPE_MSNLIST:
00446          if (port_cfg[port][place].ml)
00447             iter = port_cfg[port][place].ml;
00448          else
00449             iter = port_cfg[0][place].ml;
00450          if (iter) {
00451             for (; iter; iter = iter->next)
00452                sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn);
00453             tempbuf[strlen(tempbuf)-2] = 0;
00454          }
00455          snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
00456          break;
00457       case MISDN_CTYPE_STR:
00458          if ( port_cfg[port][place].str) {
00459             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
00460          } else if (port_cfg[0][place].str) {
00461             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
00462          } else {
00463             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00464          }
00465          break;
00466       }
00467    } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
00468       switch (gen_spec[place].type) {
00469       case MISDN_CTYPE_INT:
00470       case MISDN_CTYPE_BOOLINT:
00471          if (general_cfg[place].num)
00472             snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
00473          else
00474             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00475          break;
00476       case MISDN_CTYPE_BOOL:
00477          if (general_cfg[place].num)
00478             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
00479          else
00480             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00481          break;
00482       case MISDN_CTYPE_STR:
00483          if ( general_cfg[place].str) {
00484             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
00485          } else {
00486             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00487          }
00488          break;
00489       default:
00490          snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
00491          break;
00492       }
00493    } else {
00494       *buf = 0;
00495       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
00496    }
00497    misdn_cfg_unlock();
00498 }

int misdn_cfg_get_next_port int  port  ) 
 

Definition at line 500 of file misdn_config.c.

References map, max_ports, misdn_cfg_lock(), and port_cfg.

Referenced by misdn_cfg_get_next_port_spin(), misdn_request(), and misdn_show_stacks().

00501 {
00502    int p = -1;
00503    int gn = map[MISDN_CFG_GROUPNAME];
00504    
00505    misdn_cfg_lock();
00506    for (port++; port <= max_ports; port++) {
00507       if (port_cfg[port][gn].str) {
00508          p = port;
00509          break;
00510       }
00511    }
00512    misdn_cfg_unlock();
00513 
00514    return p;
00515 }

int misdn_cfg_get_next_port_spin int  port  ) 
 

Definition at line 517 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

00518 {
00519    int p = misdn_cfg_get_next_port(port);
00520    return (p > 0) ? p : misdn_cfg_get_next_port(0);
00521 }

void misdn_cfg_get_ports_string char *  ports  ) 
 

Definition at line 374 of file misdn_config.c.

References map, max_ports, misdn_cfg_lock(), port_cfg, and ptp.

Referenced by load_module().

00375 {
00376    char tmp[16];
00377    int l, i;
00378    int gn = map[MISDN_CFG_GROUPNAME];
00379 
00380    *ports = 0;
00381 
00382    misdn_cfg_lock();
00383    for (i = 1; i <= max_ports; i++) {
00384       if (port_cfg[i][gn].str) {
00385          if (ptp[i])
00386             sprintf(tmp, "%dptp,", i);
00387          else
00388             sprintf(tmp, "%d,", i);
00389          strcat(ports, tmp);
00390       }
00391    }
00392    misdn_cfg_unlock();
00393 
00394    if ((l = strlen(ports)))
00395       ports[l-1] = 0;
00396 }

void misdn_cfg_init int  this_max_ports  ) 
 

Definition at line 729 of file misdn_config.c.

References _enum_array_map(), AST_LOAD_CFG, ast_log(), calloc, cfg, config, general_cfg, LOG_WARNING, map, max_ports, misdn_cfg_lock(), NUM_PORT_ELEMENTS, port_cfg, and ptp.

Referenced by load_module(), and misdn_cfg_reload().

00730 {
00731    char config[] = "misdn.conf";
00732    char *cat, *p;
00733    int i;
00734    struct ast_config *cfg;
00735    struct ast_variable *v;
00736 
00737    if (!(cfg = AST_LOAD_CFG(config))) {
00738       ast_log(LOG_WARNING,"no misdn.conf ?\n");
00739       return;
00740    }
00741 
00742    misdn_cfg_lock();
00743 
00744    if (this_max_ports) {
00745       /* this is the first run */
00746       max_ports = this_max_ports;
00747       p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
00748                      + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
00749       port_cfg = (union misdn_cfg_pt **)p;
00750       p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
00751       for (i = 0; i <= max_ports; ++i) {
00752          port_cfg[i] = (union misdn_cfg_pt *)p;
00753          p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
00754       }
00755       general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
00756       ptp = (int *)calloc(max_ports + 1, sizeof(int));
00757       map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
00758       _enum_array_map();
00759    }
00760    else {
00761       /* misdn reload */
00762       _free_port_cfg();
00763       _free_general_cfg();
00764       memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
00765       memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
00766       memset(ptp, 0, sizeof(int) * (max_ports + 1));
00767    }
00768 
00769    cat = ast_category_browse(cfg, NULL);
00770 
00771    while(cat) {
00772       v = ast_variable_browse(cfg, cat);
00773       if (!strcasecmp(cat,"general")) {
00774          _build_general_config(v);
00775       } else {
00776          _build_port_config(v, cat);
00777       }
00778       cat = ast_category_browse(cfg,cat);
00779    }
00780 
00781    _fill_defaults();
00782 
00783    misdn_cfg_unlock();
00784    AST_DESTROY_CFG(cfg);
00785 }

int misdn_cfg_is_group_method char *  group,
enum misdn_cfg_method  meth
 

Definition at line 348 of file misdn_config.c.

References map, max_ports, misdn_cfg_lock(), and port_cfg.

Referenced by misdn_request().

00349 {
00350    int i, re = 0;
00351    char *method = NULL;
00352 
00353    misdn_cfg_lock();
00354    for (i = 1; i <= max_ports; i++) {
00355       if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
00356          if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
00357             method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 
00358                     port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
00359       }
00360    }
00361    if (method) {
00362       switch (meth) {
00363       case METHOD_STANDARD:      re = !strcasecmp(method, "standard");
00364                            break;
00365       case METHOD_ROUND_ROBIN:   re = !strcasecmp(method, "round_robin");
00366                            break;
00367       }
00368    }
00369    misdn_cfg_unlock();
00370 
00371    return re;
00372 }

int misdn_cfg_is_msn_valid int  port,
char *  msn
 

Definition at line 318 of file misdn_config.c.

References ast_extension_match(), ast_log(), LOG_WARNING, map, misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_pt::ml, msn_list::msn, msn_list::next, and port_cfg.

Referenced by cb_events().

00319 {
00320    int re = 0;
00321    struct msn_list *iter;
00322 
00323    if (!misdn_cfg_is_port_valid(port)) {
00324       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
00325       return 0;
00326    }
00327 
00328    misdn_cfg_lock();
00329    if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
00330       iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
00331    else
00332       iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
00333    for (; iter; iter = iter->next) 
00334       if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
00335          re = 1;
00336          break;
00337       }
00338    misdn_cfg_unlock();
00339 
00340    return re;
00341 }

int misdn_cfg_is_port_valid int  port  ) 
 

Definition at line 343 of file misdn_config.c.

References max_ports.

Referenced by misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_is_msn_valid(), and misdn_cfg_update_ptp().

00344 {
00345    return (port >= 1 && port <= max_ports);
00346 }

static void misdn_cfg_lock void   )  [inline, static]
 

Definition at line 201 of file misdn_config.c.

References ast_mutex_lock(), and config_mutex.

Referenced by misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_msn_valid(), and misdn_cfg_update_ptp().

00202 {
00203    ast_mutex_lock(&config_mutex);
00204 }

void misdn_cfg_reload void   ) 
 

Definition at line 708 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

00709 {
00710    misdn_cfg_init (0);
00711 }

static void misdn_cfg_unlock void   )  [inline, static]
 

Definition at line 206 of file misdn_config.c.

References ast_mutex_unlock(), and config_mutex.

Referenced by misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), and misdn_cfg_update_ptp().

00207 {
00208    ast_mutex_unlock(&config_mutex);
00209 }

void misdn_cfg_update_ptp void   ) 
 

Definition at line 660 of file misdn_config.c.

References ast_log(), LOG_WARNING, misdn_cfg_get(), misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_unlock(), and ptp.

Referenced by load_module(), and reload_config().

00661 {
00662    char misdn_init[BUFFERSIZE];
00663    char line[BUFFERSIZE];
00664    FILE *fp;
00665    char *tok, *p, *end;
00666    int port;
00667 
00668    misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
00669 
00670    if (misdn_init) {
00671       fp = fopen(misdn_init, "r");
00672       if (fp) {
00673          while(fgets(line, sizeof(line), fp)) {
00674             if (!strncmp(line, "nt_ptp", 6)) {
00675                for (tok = strtok_r(line,",=", &p);
00676                    tok;
00677                    tok = strtok_r(NULL,",=", &p)) {
00678                   port = strtol(tok, &end, 10);
00679                   if (end != tok && misdn_cfg_is_port_valid(port)) {
00680                      misdn_cfg_lock();
00681                      ptp[port] = 1;
00682                      misdn_cfg_unlock();
00683                   }
00684                }
00685             }
00686          }
00687          fclose(fp);
00688       } else {
00689          ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
00690       }
00691    }
00692 }


Variable Documentation

ast_mutex_t config_mutex [static]
 

Definition at line 149 of file misdn_config.c.

Referenced by misdn_cfg_destroy(), misdn_cfg_lock(), and misdn_cfg_unlock().

const struct misdn_cfg_spec gen_spec[] [static]
 

Definition at line 124 of file misdn_config.c.

Referenced by _build_general_config(), get_cfg_position(), misdn_cfg_get(), and misdn_cfg_get_config_string().

union misdn_cfg_pt* general_cfg [static]
 

Definition at line 143 of file misdn_config.c.

Referenced by _build_general_config(), _free_general_cfg(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), and misdn_cfg_init().

int* map [static]
 

Definition at line 147 of file misdn_config.c.

Referenced by _enum_array_map(), _free_port_cfg(), append_mapping(), build_mapping(), clear_config_maps(), conf_exec(), config_command(), destroy_map(), dundi_lookup_local(), dundi_show_mappings(), find_engine(), mark_mappings(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_msn_valid(), and prune_mappings().

int max_ports [static]
 

Definition at line 141 of file misdn_config.c.

union misdn_cfg_pt** port_cfg [static]
 

Definition at line 139 of file misdn_config.c.

Referenced by _fill_defaults(), _free_port_cfg(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), and misdn_cfg_is_msn_valid().

const struct misdn_cfg_spec port_spec[] [static]
 

Definition at line 85 of file misdn_config.c.

Referenced by _build_port_config(), _enum_array_map(), _fill_defaults(), get_cfg_position(), misdn_cfg_get(), and misdn_cfg_get_config_string().

int* ptp [static]
 

Definition at line 145 of file misdn_config.c.

Referenced by _build_port_config(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_ports_string(), misdn_cfg_init(), and misdn_cfg_update_ptp().


Generated on Sat Nov 25 00:46:07 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.6