Sat Nov 1 06:31:07 2008

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>

Include dependency graph for misdn_config.c:

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)
int 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 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 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 160 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 _enum_array_map(), _fill_defaults(), _free_general_cfg(), get_cfg_position(), and misdn_cfg_init().

#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(), _free_port_cfg(), 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 601 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.

Referenced by misdn_cfg_init().

00602 {
00603    int pos;
00604 
00605    for (; v; v = v->next) {
00606       if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 
00607          (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
00608          CLI_ERROR(v->name, v->value, "general");
00609    }
00610 }

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

Definition at line 612 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.

Referenced by misdn_cfg_init().

00613 {
00614    int pos, i;
00615    union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
00616    int cfg_for_ports[max_ports + 1];
00617 
00618    if (!v || !cat)
00619       return;
00620 
00621    memset(cfg_tmp, 0, sizeof(cfg_tmp));
00622    memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
00623 
00624    if (!strcasecmp(cat, "default")) {
00625       cfg_for_ports[0] = 1;
00626    }
00627 
00628    if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 
00629       (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
00630       CLI_ERROR(v->name, v->value, cat);
00631       return;
00632    }
00633 
00634    for (; v; v = v->next) {
00635       if (!strcasecmp(v->name, "ports")) {
00636          char *token;
00637          char ptpbuf[BUFFERSIZE] = "";
00638          int start, end;
00639          for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 
00640             if (!*token)
00641                continue;
00642             if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) {
00643                for (; start <= end; start++) {
00644                   if (start <= max_ports && start > 0) {
00645                      cfg_for_ports[start] = 1;
00646                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00647                   } else
00648                      CLI_ERROR(v->name, v->value, cat);
00649                }
00650             } else {
00651                if (sscanf(token, "%d%s", &start, ptpbuf)) {
00652                   if (start <= max_ports && start > 0) {
00653                      cfg_for_ports[start] = 1;
00654                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00655                   } else
00656                      CLI_ERROR(v->name, v->value, cat);
00657                } else
00658                   CLI_ERROR(v->name, v->value, cat);
00659             }
00660          }
00661       } else {
00662          if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 
00663             (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
00664             CLI_ERROR(v->name, v->value, cat);
00665       }
00666    }
00667 
00668    for (i = 0; i < (max_ports + 1); ++i) {
00669       if (cfg_for_ports[i]) {
00670          memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
00671       }
00672    }
00673 }

static void _enum_array_map ( void   )  [static]

Definition at line 165 of file misdn_config.c.

References gen_spec, map, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, and port_spec.

Referenced by misdn_cfg_init().

00166 {
00167    int i, j;
00168 
00169    for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
00170       if (i == MISDN_CFG_PTP)
00171          continue;
00172       for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
00173          if (port_spec[j].elem == i) {
00174             map[i] = j;
00175             break;
00176          }
00177       }
00178    }
00179    for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
00180       for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
00181          if (gen_spec[j].elem == i) {
00182             map[i] = j;
00183             break;
00184          }
00185       }
00186    }
00187 }

static void _fill_defaults ( void   )  [static]

Definition at line 730 of file misdn_config.c.

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

Referenced by misdn_cfg_init().

00731 {
00732    int i;
00733 
00734    for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00735       if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
00736          _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
00737    }
00738    for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
00739       if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
00740          _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
00741    }
00742 }

static void _free_general_cfg ( void   )  [static]

Definition at line 262 of file misdn_config.c.

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

Referenced by misdn_cfg_destroy(), and misdn_cfg_init().

00263 {
00264    int i;
00265 
00266    for (i = 0; i < NUM_GEN_ELEMENTS; i++) 
00267       if (general_cfg[i].any)
00268          free(general_cfg[i].any);
00269 }

static void _free_msn_list ( struct msn_list iter  )  [static]

Definition at line 220 of file misdn_config.c.

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

Referenced by _free_port_cfg().

00221 {
00222    if (iter->next)
00223       _free_msn_list(iter->next);
00224    if (iter->msn)
00225       free(iter->msn);
00226    free(iter);
00227 }

static void _free_port_cfg ( void   )  [static]

Definition at line 229 of file misdn_config.c.

References _free_msn_list(), misdn_cfg_pt::any, free, map, max_ports, MISDN_CTYPE_MSNLIST, misdn_cfg_pt::ml, NUM_PORT_ELEMENTS, port_cfg, port_spec, misdn_cfg_pt::str, and type.

Referenced by misdn_cfg_destroy(), and misdn_cfg_init().

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

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

Definition at line 538 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().

00539 {
00540    int re = 0;
00541    int len, tmp;
00542    char *valtmp;
00543 
00544    switch (type) {
00545    case MISDN_CTYPE_STR:
00546       if ((len = strlen(value))) {
00547          dest->str = (char *)malloc((len + 1) * sizeof(char));
00548          strncpy(dest->str, value, len);
00549          dest->str[len] = 0;
00550       } else {
00551          dest->str = (char *)malloc( sizeof(char));
00552          dest->str[0] = 0;
00553       }
00554       break;
00555    case MISDN_CTYPE_INT:
00556    {
00557       char *pat;
00558       if (strchr(value,'x')) 
00559          pat="%x";
00560       else
00561          pat="%d";
00562       if (sscanf(value, pat, &tmp)) {
00563          dest->num = (int *)malloc(sizeof(int));
00564          memcpy(dest->num, &tmp, sizeof(int));
00565       } else
00566          re = -1;
00567    }
00568       break;
00569    case MISDN_CTYPE_BOOL:
00570       dest->num = (int *)malloc(sizeof(int));
00571       *(dest->num) = (ast_true(value) ? 1 : 0);
00572       break;
00573    case MISDN_CTYPE_BOOLINT:
00574       dest->num = (int *)malloc(sizeof(int));
00575       if (sscanf(value, "%d", &tmp)) {
00576          memcpy(dest->num, &tmp, sizeof(int));
00577       } else {
00578          *(dest->num) = (ast_true(value) ? boolint_def : 0);
00579       }
00580       break;
00581    case MISDN_CTYPE_MSNLIST:
00582       for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) {
00583          if ((len = strlen(valtmp))) {
00584             struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list));
00585             ml->msn = (char *)calloc(len+1, sizeof(char));
00586             strncpy(ml->msn, valtmp, len);
00587             ml->next = dest->ml;
00588             dest->ml = ml;
00589          }
00590       }
00591       break;
00592    case MISDN_CTYPE_ASTGROUP:
00593       dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
00594       *(dest->grp) = ast_get_group(value);
00595       break;
00596    }
00597 
00598    return re;
00599 }

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

Definition at line 189 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().

00190 {
00191    int i;
00192 
00193    switch (type) {
00194    case PORT_CFG:
00195       for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00196          if (!strcasecmp(name, port_spec[i].name))
00197             return i;
00198       }
00199       break;
00200    case GEN_CFG:
00201       for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
00202          if (!strcasecmp(name, gen_spec[i].name))
00203             return i;
00204       }
00205    }
00206 
00207    return -1;
00208 }

void misdn_cfg_destroy ( void   ) 

Definition at line 749 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().

00750 {
00751    misdn_cfg_lock();
00752 
00753    _free_port_cfg();
00754    _free_general_cfg();
00755 
00756    free(port_cfg);
00757    free(general_cfg);
00758    free(ptp);
00759    free(map);
00760 
00761    misdn_cfg_unlock();
00762    ast_mutex_destroy(&config_mutex);
00763 }

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

Definition at line 271 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_call(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_new(), misdn_request(), misdn_set_opt_exec(), read_config(), reload_config(), update_config(), and update_ec_config().

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

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

Definition at line 413 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().

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

int misdn_cfg_get_next_port ( int  port  ) 

Definition at line 515 of file misdn_config.c.

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

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

00516 {
00517    int p = -1;
00518    int gn = map[MISDN_CFG_GROUPNAME];
00519    
00520    misdn_cfg_lock();
00521    for (port++; port <= max_ports; port++) {
00522       if (port_cfg[port][gn].str) {
00523          p = port;
00524          break;
00525       }
00526    }
00527    misdn_cfg_unlock();
00528 
00529    return p;
00530 }

int misdn_cfg_get_next_port_spin ( int  port  ) 

Definition at line 532 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

00533 {
00534    int p = misdn_cfg_get_next_port(port);
00535    return (p > 0) ? p : misdn_cfg_get_next_port(0);
00536 }

void misdn_cfg_get_ports_string ( char *  ports  ) 

Definition at line 389 of file misdn_config.c.

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

Referenced by load_module().

00390 {
00391    char tmp[16];
00392    int l, i;
00393    int gn = map[MISDN_CFG_GROUPNAME];
00394 
00395    *ports = 0;
00396 
00397    misdn_cfg_lock();
00398    for (i = 1; i <= max_ports; i++) {
00399       if (port_cfg[i][gn].str) {
00400          if (ptp[i])
00401             sprintf(tmp, "%dptp,", i);
00402          else
00403             sprintf(tmp, "%d,", i);
00404          strcat(ports, tmp);
00405       }
00406    }
00407    misdn_cfg_unlock();
00408 
00409    if ((l = strlen(ports)))
00410       ports[l-1] = 0;
00411 }

int misdn_cfg_init ( int  this_max_ports  ) 

Definition at line 765 of file misdn_config.c.

References _build_general_config(), _build_port_config(), _enum_array_map(), _fill_defaults(), _free_general_cfg(), _free_port_cfg(), ast_category_browse(), AST_DESTROY_CFG, AST_LOAD_CFG, ast_log(), ast_variable_browse(), calloc, cfg, config, general_cfg, LOG_WARNING, map, max_ports, misdn_cfg_lock(), misdn_cfg_unlock(), NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, port_cfg, and ptp.

Referenced by load_module(), and misdn_cfg_reload().

00766 {
00767    char config[] = "misdn.conf";
00768    char *cat, *p;
00769    int i;
00770    struct ast_config *cfg;
00771    struct ast_variable *v;
00772 
00773    if (!(cfg = AST_LOAD_CFG(config))) {
00774       ast_log(LOG_WARNING,"no misdn.conf ?\n");
00775       return -1;
00776    }
00777 
00778    misdn_cfg_lock();
00779 
00780    if (this_max_ports) {
00781       /* this is the first run */
00782       max_ports = this_max_ports;
00783       p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
00784                      + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
00785       port_cfg = (union misdn_cfg_pt **)p;
00786       p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
00787       for (i = 0; i <= max_ports; ++i) {
00788          port_cfg[i] = (union misdn_cfg_pt *)p;
00789          p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
00790       }
00791       general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
00792       ptp = (int *)calloc(max_ports + 1, sizeof(int));
00793       map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
00794       _enum_array_map();
00795    }
00796    else {
00797       /* misdn reload */
00798       _free_port_cfg();
00799       _free_general_cfg();
00800       memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
00801       memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
00802       memset(ptp, 0, sizeof(int) * (max_ports + 1));
00803    }
00804 
00805    cat = ast_category_browse(cfg, NULL);
00806 
00807    while(cat) {
00808       v = ast_variable_browse(cfg, cat);
00809       if (!strcasecmp(cat,"general")) {
00810          _build_general_config(v);
00811       } else {
00812          _build_port_config(v, cat);
00813       }
00814       cat = ast_category_browse(cfg,cat);
00815    }
00816 
00817    _fill_defaults();
00818 
00819