Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:37 2007

Asterisk developer's documentation :: Codename Pineapple


misdn_config.c File Reference


Detailed Description

chan_misdn configuration management

Author:
Christian Richter <crich@beronet.com>

Definition in file misdn_config.c.

#include "asterisk.h"
#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 int _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)
void misdn_cfg_get_desc (enum misdn_cfg_elements elem, void *buf, int bufsize, void *buf_default, int bufsize_default)
enum misdn_cfg_elements misdn_cfg_get_elem (char *name)
void misdn_cfg_get_name (enum misdn_cfg_elements elem, void *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 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 const char ports_description []
static int * ptp


Define Documentation

#define AST_DESTROY_CFG   ast_config_destroy
 

Definition at line 49 of file misdn_config.c.

#define AST_LOAD_CFG   ast_config_load
 

Definition at line 48 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 358 of file misdn_config.c.

Referenced by _build_general_config(), and _build_port_config().

#define GEN_CFG   1
 

Definition at line 54 of file misdn_config.c.

Referenced by _build_general_config(), get_cfg_position(), and misdn_cfg_get_elem().

#define NO_DEFAULT   "<>"
 

Definition at line 51 of file misdn_config.c.

Referenced by _fill_defaults(), and misdn_cfg_get_desc().

#define NONE   0
 

Definition at line 52 of file misdn_config.c.

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

Definition at line 56 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 57 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 55 of file misdn_config.c.

Referenced by _build_port_config(), get_cfg_position(), and misdn_cfg_get_elem().


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 59 of file misdn_config.c.


Function Documentation

static void _build_general_config struct ast_variable v  )  [static]
 

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

00890 {
00891    int pos;
00892 
00893    for (; v; v = v->next) {
00894       if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 
00895          (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
00896          CLI_ERROR(v->name, v->value, "general");
00897    }
00898 }

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

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

00901 {
00902    int pos, i;
00903    union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
00904    int cfg_for_ports[max_ports + 1];
00905 
00906    if (!v || !cat)
00907       return;
00908 
00909    memset(cfg_tmp, 0, sizeof(cfg_tmp));
00910    memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
00911 
00912    if (!strcasecmp(cat, "default")) {
00913       cfg_for_ports[0] = 1;
00914    }
00915 
00916    if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 
00917       (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
00918       CLI_ERROR(v->name, v->value, cat);
00919       return;
00920    }
00921 
00922    for (; v; v = v->next) {
00923       if (!strcasecmp(v->name, "ports")) {
00924          char *token;
00925          char ptpbuf[BUFFERSIZE] = "";
00926          int start, end;
00927          for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 
00928             if (!*token)
00929                continue;
00930             if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) {
00931                for (; start <= end; start++) {
00932                   if (start <= max_ports && start > 0) {
00933                      cfg_for_ports[start] = 1;
00934                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00935                   } else
00936                      CLI_ERROR(v->name, v->value, cat);
00937                }
00938             } else {
00939                if (sscanf(token, "%d%s", &start, ptpbuf)) {
00940                   if (start <= max_ports && start > 0) {
00941                      cfg_for_ports[start] = 1;
00942                      ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
00943                   } else
00944                      CLI_ERROR(v->name, v->value, cat);
00945                } else
00946                   CLI_ERROR(v->name, v->value, cat);
00947             }
00948          }
00949       } else {
00950          if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 
00951             (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
00952             CLI_ERROR(v->name, v->value, cat);
00953       }
00954    }
00955 
00956    for (i = 0; i < (max_ports + 1); ++i) {
00957       if (cfg_for_ports[i]) {
00958          memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
00959       }
00960    }
00961 }

static int _enum_array_map void   )  [static]
 

Definition at line 363 of file misdn_config.c.

References NUM_PORT_ELEMENTS, and port_spec.

Referenced by misdn_cfg_init().

00364 {
00365    int i, j, ok;
00366 
00367    for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
00368       if (i == MISDN_CFG_PTP)
00369          continue;
00370       ok = 0;
00371       for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
00372          if (port_spec[j].elem == i) {
00373             map[i] = j;
00374             ok = 1;
00375             break;
00376          }
00377       }
00378       if (!ok) {
00379          ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
00380          return -1;
00381       }
00382    }
00383    for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
00384       ok = 0;
00385       for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
00386          if (gen_spec[j].elem == i) {
00387             map[i] = j;
00388             ok = 1;
00389             break;
00390          }
00391       }
00392       if (!ok) {
00393          ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
00394          return -1;
00395       }
00396    }
00397    return 0;
00398 }

static void _fill_defaults void   )  [static]
 

Definition at line 997 of file misdn_config.c.

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

00998 {
00999    int i;
01000 
01001    for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
01002       if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
01003          _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
01004    }
01005    for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
01006       if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
01007          _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
01008    }
01009 }

static void _free_general_cfg void   )  [static]
 

Definition at line 473 of file misdn_config.c.

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

Referenced by misdn_cfg_destroy().

00474 {
00475    int i;
00476 
00477    for (i = 0; i < NUM_GEN_ELEMENTS; i++) 
00478       if (general_cfg[i].any)
00479          free(general_cfg[i].any);
00480 }

static void _free_msn_list struct msn_list iter  )  [static]
 

Definition at line 431 of file misdn_config.c.

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

00432 {
00433    if (iter->next)
00434       _free_msn_list(iter->next);
00435    if (iter->msn)
00436       free(iter->msn);
00437    free(iter);
00438 }

static void _free_port_cfg void   )  [static]
 

Definition at line 440 of file misdn_config.c.

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

Referenced by misdn_cfg_destroy().

00441 {
00442    int i, j;
00443    int gn = map[MISDN_CFG_GROUPNAME];
00444    union misdn_cfg_pt* free_list[max_ports + 2];
00445    
00446    memset(free_list, 0, sizeof(free_list));
00447    free_list[0] = port_cfg[0];
00448    for (i = 1; i <= max_ports; ++i) {
00449       if (port_cfg[i][gn].str) {
00450          /* we always have a groupname in the non-default case, so this is fine */
00451          for (j = 1; j <= max_ports; ++j) {
00452             if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
00453                break;
00454             else if (!free_list[j]) {
00455                free_list[j] = port_cfg[i];
00456                break;
00457             }
00458          }
00459       }
00460    }
00461    for (j = 0; free_list[j]; ++j) {
00462       for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00463          if (free_list[j][i].any) {
00464             if (port_spec[i].type == MISDN_CTYPE_MSNLIST)
00465                _free_msn_list(free_list[j][i].ml);
00466             else
00467                free(free_list[j][i].any);
00468          }
00469       }
00470    }
00471 }

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

Definition at line 826 of file misdn_config.c.

References ast_get_group(), ast_true(), calloc, misdn_cfg_pt::grp, len, 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().

00827 {
00828    int re = 0;
00829    int len, tmp;
00830    char *valtmp;
00831 
00832    switch (type) {
00833    case MISDN_CTYPE_STR:
00834       if ((len = strlen(value))) {
00835          dest->str = (char *)malloc((len + 1) * sizeof(char));
00836          strncpy(dest->str, value, len);
00837          dest->str[len] = 0;
00838       } else {
00839          dest->str = (char *)malloc( sizeof(char));
00840          dest->str[0] = 0;
00841       }
00842       break;
00843    case MISDN_CTYPE_INT:
00844    {
00845       char *pat;
00846       if (strchr(value,'x')) 
00847          pat="%x";
00848       else
00849          pat="%d";
00850       if (sscanf(value, pat, &tmp)) {
00851          dest->num = (int *)malloc(sizeof(int));
00852          memcpy(dest->num, &tmp, sizeof(int));
00853       } else
00854          re = -1;
00855    }
00856       break;
00857    case MISDN_CTYPE_BOOL:
00858       dest->num = (int *)malloc(sizeof(int));
00859       *(dest->num) = (ast_true(value) ? 1 : 0);
00860       break;
00861    case MISDN_CTYPE_BOOLINT:
00862       dest->num = (int *)malloc(sizeof(int));
00863       if (sscanf(value, "%d", &tmp)) {
00864          memcpy(dest->num, &tmp, sizeof(int));
00865       } else {
00866          *(dest->num) = (ast_true(value) ? boolint_def : 0);
00867       }
00868       break;
00869    case MISDN_CTYPE_MSNLIST:
00870       for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) {
00871          if ((len = strlen(valtmp))) {
00872             struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list));
00873             ml->msn = (char *)calloc(len+1, sizeof(char));
00874             strncpy(ml->msn, valtmp, len);
00875             ml->next = dest->ml;
00876             dest->ml = ml;
00877          }
00878       }
00879       break;
00880    case MISDN_CTYPE_ASTGROUP:
00881       dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
00882       *(dest->grp) = ast_get_group(value);
00883       break;
00884    }
00885 
00886    return re;
00887 }

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

Definition at line 400 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(), _build_port_config(), and misdn_cfg_get_elem().

00401 {
00402    int i;
00403 
00404    switch (type) {
00405    case PORT_CFG:
00406       for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
00407          if (!strcasecmp(name, port_spec[i].name))
00408             return i;
00409       }
00410       break;
00411    case GEN_CFG:
00412       for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
00413          if (!strcasecmp(name, gen_spec[i].name))
00414             return i;
00415       }
00416    }
00417 
00418    return -1;
00419 }

void misdn_cfg_destroy void   ) 
 

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

01017 {
01018    misdn_cfg_lock();
01019 
01020    _free_port_cfg();
01021    _free_general_cfg();
01022 
01023    free(port_cfg);
01024    free(general_cfg);
01025    free(ptp);
01026    free(map);
01027 
01028    misdn_cfg_unlock();
01029    ast_mutex_destroy(&config_mutex);
01030 }

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

Definition at line 482 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 add_in_calls(), add_out_calls(), cb_events(), dialtone_indicate(), load_module(), misdn_bridge(), misdn_call(), misdn_cfg_update_ptp(), misdn_request(), misdn_set_opt_exec(), process_ast_dsp(), read_config(), reload_config(), update_config(), and update_ec_config().

00483 {
00484    int place;
00485 
00486    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00487       memset(buf, 0, bufsize);
00488       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
00489       return;
00490    }
00491 
00492    misdn_cfg_lock();
00493    if (elem == MISDN_CFG_PTP) {
00494       if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
00495          memset(buf, 0, bufsize);
00496    } else {
00497       if ((place = map[elem]) < 0) {
00498          memset (buf, 0, bufsize);
00499          ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
00500       } else {
00501          if (elem < MISDN_CFG_LAST) {
00502             switch (port_spec[place].type) {
00503             case MISDN_CTYPE_STR:
00504                if (port_cfg[port][place].str) {
00505                   if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
00506                      memset(buf, 0, 1);
00507                } else if (port_cfg[0][place].str) {
00508                   if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
00509                      memset(buf, 0, 1);
00510                }
00511                break;
00512             default:
00513                if (port_cfg[port][place].any)
00514                   memcpy(buf, port_cfg[port][place].any, bufsize);
00515                else if (port_cfg[0][place].any)
00516                   memcpy(buf, port_cfg[0][place].any, bufsize);
00517                else
00518                   memset(buf, 0, bufsize);
00519             }
00520          } else {
00521             switch (gen_spec[place].type) {
00522             case MISDN_CTYPE_STR:
00523                if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
00524                   memset(buf, 0, 1);
00525                break;
00526             default:
00527                if (general_cfg[place].any)
00528                   memcpy(buf, general_cfg[place].any, bufsize);
00529                else
00530                   memset(buf, 0, bufsize);
00531             }
00532          }
00533       }
00534    }
00535    misdn_cfg_unlock();
00536 }

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

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

00702 {
00703    int place;
00704    char tempbuf[BUFFERSIZE] = "";
00705    struct msn_list *iter;
00706 
00707    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00708       *buf = 0;
00709       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
00710       return;
00711    }
00712 
00713    place = map[elem];
00714 
00715    misdn_cfg_lock();
00716    if (elem == MISDN_CFG_PTP) {
00717       snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
00718    }
00719    else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
00720       switch (port_spec[place].type) {
00721       case MISDN_CTYPE_INT:
00722       case MISDN_CTYPE_BOOLINT:
00723          if (port_cfg[port][place].num)
00724             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
00725          else if (port_cfg[0][place].num)
00726             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
00727          else
00728             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00729          break;
00730       case MISDN_CTYPE_BOOL:
00731          if (port_cfg[port][place].num)
00732             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
00733          else if (port_cfg[0][place].num)
00734             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
00735          else
00736             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00737          break;
00738       case MISDN_CTYPE_ASTGROUP:
00739          if (port_cfg[port][place].grp)
00740             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00741                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
00742          else if (port_cfg[0][place].grp)
00743             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00744                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
00745          else
00746             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00747          break;
00748       case MISDN_CTYPE_MSNLIST:
00749          if (port_cfg[port][place].ml)
00750             iter = port_cfg[port][place].ml;
00751          else
00752             iter = port_cfg[0][place].ml;
00753          if (iter) {
00754             for (; iter; iter = iter->next)
00755                sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn);
00756             tempbuf[strlen(tempbuf)-2] = 0;
00757          }
00758          snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
00759          break;
00760       case MISDN_CTYPE_STR:
00761          if ( port_cfg[port][place].str) {
00762             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
00763          } else if (port_cfg[0][place].str) {
00764             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
00765          } else {
00766             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00767          }
00768          break;
00769       }
00770    } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
00771       switch (gen_spec[place].type) {
00772       case MISDN_CTYPE_INT:
00773       case MISDN_CTYPE_BOOLINT:
00774          if (general_cfg[place].num)
00775             snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
00776          else
00777             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00778          break;
00779       case MISDN_CTYPE_BOOL:
00780          if (general_cfg[place].num)
00781             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
00782          else
00783             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00784          break;
00785       case MISDN_CTYPE_STR:
00786          if ( general_cfg[place].str) {
00787             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
00788          } else {
00789             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00790          }
00791          break;
00792       default:
00793          snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
00794          break;
00795       }
00796    } else {
00797       *buf = 0;
00798       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
00799    }
00800    misdn_cfg_unlock();
00801 }

void misdn_cfg_get_desc enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize,
void *  buf_default,
int  bufsize_default
 

Definition at line 586 of file misdn_config.c.

References misdn_cfg_spec::def, desc, gen_spec, map, NO_DEFAULT, port_spec, and ports_description.

Referenced by show_config_description().

00587 {
00588    int place = map[elem];
00589    struct misdn_cfg_spec *spec = NULL;
00590 
00591    /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */
00592    if (elem == MISDN_CFG_GROUPNAME) {
00593       if (!memccpy(buf, ports_description, 0, bufsize))
00594          memset(buf, 0, 1);
00595       if (buf_default && bufsize_default)
00596          memset(buf_default, 0, 1);
00597       return;
00598    }
00599 
00600    if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
00601       spec = (struct misdn_cfg_spec *)port_spec;
00602    else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
00603       spec = (struct misdn_cfg_spec *)gen_spec;
00604       
00605    if (!spec || !spec[place].desc)
00606       memset(buf, 0, 1);
00607    else {
00608       if (!memccpy(buf, spec[place].desc, 0, bufsize))
00609          memset(buf, 0, 1);
00610       if (buf_default && bufsize) {
00611          if (!strcmp(spec[place].def, NO_DEFAULT))
00612             memset(buf_default, 0, 1);
00613          else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default))
00614             memset(buf_default, 0, 1);
00615       }
00616    }
00617 }

enum misdn_cfg_elements misdn_cfg_get_elem char *  name  ) 
 

Definition at line 538 of file misdn_config.c.

References misdn_cfg_spec::elem, GEN_CFG, gen_spec, get_cfg_position(), PORT_CFG, and port_spec.

Referenced by misdn_show_config().

00539 {
00540    int pos;
00541 
00542    /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */
00543    if (!strcmp(name, "ports"))
00544       return MISDN_CFG_GROUPNAME;
00545    if (!strcmp(name, "name"))
00546       return MISDN_CFG_FIRST;
00547 
00548    pos = get_cfg_position (name, PORT_CFG);
00549    if (pos >= 0)
00550       return port_spec[pos].elem;
00551    
00552    pos = get_cfg_position (name, GEN_CFG);
00553    if (pos >= 0)
00554       return gen_spec[pos].elem;
00555    
00556    return MISDN_CFG_FIRST;
00557 }

void misdn_cfg_get_name enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize
 

Definition at line 559 of file misdn_config.c.

References gen_spec, map, name, and port_spec.

Referenced by complete_show_config(), and show_config_description().

00560 {
00561    struct misdn_cfg_spec *spec = NULL;
00562    int place = map[elem];
00563 
00564    /* the ptp hack */
00565    if (elem == MISDN_CFG_PTP) {
00566       memset(buf, 0, 1);
00567       return;
00568    }
00569    
00570    /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */
00571    if (elem == MISDN_CFG_GROUPNAME) {
00572       if (!snprintf(buf, bufsize, "ports"))
00573          memset(buf, 0, 1);
00574       return;
00575    }
00576    
00577    if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
00578       spec = (struct misdn_cfg_spec *)port_spec;
00579    else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
00580       spec = (struct misdn_cfg_spec *)gen_spec;
00581 
00582    if (!spec || !memccpy(buf, spec[place].name, 0, bufsize))
00583       memset(buf, 0, 1);
00584 }

int misdn_cfg_get_next_port int  port  ) 
 

Definition at line 803 of file misdn_config.c.

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

Referenced by complete_show_config(), misdn_cfg_get_next_port_spin(), misdn_new(), misdn_request(), misdn_show_ports_stats(), misdn_show_stacks(), and update_name().

00804 {
00805    int p = -1;
00806    int gn = map[MISDN_CFG_GROUPNAME];
00807    
00808    misdn_cfg_lock();
00809    for (port++; port <= max_ports; port++) {
00810       if (port_cfg[port][gn].str) {
00811          p = port;
00812          break;
00813       }
00814    }
00815    misdn_cfg_unlock();
00816 
00817    return p;
00818 }

int misdn_cfg_get_next_port_spin int  port  ) 
 

Definition at line 820 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

00821 {
00822    int p = misdn_cfg_get_next_port(port);
00823    return (p > 0) ? p : misdn_cfg_get_next_port(0);
00824 }

void misdn_cfg_get_ports_string char *  ports  ) 
 

Definition at line 677 of file misdn_config.c.

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

00678 {
00679    char tmp[16];
00680    int l, i;
00681    int gn = map[MISDN_CFG_GROUPNAME];
00682 
00683    *ports = 0;
00684 
00685    misdn_cfg_lock();
00686    for (i = 1; i <= max_ports; i++) {
00687       if (port_cfg[i][gn].str) {
00688          if (ptp[i])
00689             sprintf(tmp, "%dptp,", i);
00690          else
00691             sprintf(tmp, "%d,", i);
00692          strcat(ports, tmp);
00693       }
00694    }
00695    misdn_cfg_unlock();
00696 
00697    if ((l = strlen(ports)))
00698       ports[l-1] = 0;
00699 }

int misdn_cfg_init int  this_max_ports  ) 
 

Definition at line 1032 of file misdn_config.c.

References _enum_array_map(), AST_LOAD_CFG, ast_log(), ast_mutex_init(), calloc, config, config_mutex, 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().

01033 {
01034    char config[] = "misdn.conf";
01035    char *cat, *p;
01036    int i;
01037    struct ast_config *cfg;
01038    struct ast_variable *v;
01039 
01040    if (!(cfg = AST_LOAD_CFG(config))) {
01041       ast_log(LOG_WARNING, "missing file: misdn.conf\n");
01042       return -1;
01043    }
01044 
01045    ast_mutex_init(&config_mutex);
01046 
01047    misdn_cfg_lock();
01048 
01049    if (this_max_ports) {
01050       /* this is the first run */
01051       max_ports = this_max_ports;
01052       map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
01053       if (_enum_array_map())
01054          return -1;
01055       p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
01056                      + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
01057       port_cfg = (union misdn_cfg_pt **)p;
01058       p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
01059       for (i = 0; i <= max_ports; ++i) {
01060          port_cfg[i] = (union misdn_cfg_pt *)p;
01061          p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
01062       }
01063       general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01064       ptp = (int *)calloc(max_ports + 1, sizeof(int));
01065    }
01066    else {
01067       /* misdn reload */
01068       _free_port_cfg();
01069       _free_general_cfg();
01070       memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
01071       memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01072       memset(ptp, 0, sizeof(int) * (max_ports + 1));
01073    }
01074 
01075    cat = ast_category_browse(cfg, NULL);
01076 
01077    while(cat) {
01078       v = ast_variable_browse(cfg, cat);
01079       if (!strcasecmp(cat, "general")) {
01080          _build_general_config(v);
01081       } else {
01082          _build_port_config(v, cat);
01083       }
01084       cat = ast_category_browse(cfg, cat);
01085    }
01086 
01087    _fill_defaults();
01088 
01089    misdn_cfg_unlock();
01090    AST_DESTROY_CFG(cfg);
01091 
01092    return 0;
01093 }

int misdn_cfg_is_group_method char *  group,
enum misdn_cfg_method  meth
 

Definition at line 651 of file misdn_config.c.

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

Referenced by misdn_request().

00652 {
00653    int i, re = 0;
00654    char *method = NULL;
00655 
00656    misdn_cfg_lock();
00657    for (i = 1; i <= max_ports; i++) {
00658       if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
00659          if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
00660             method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 
00661                     port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
00662       }
00663    }
00664    if (method) {
00665       switch (meth) {
00666       case METHOD_STANDARD:      re = !strcasecmp(method, "standard");
00667                            break;
00668       case METHOD_ROUND_ROBIN:   re = !strcasecmp(method, "round_robin");
00669                            break;
00670       }
00671    }
00672    misdn_cfg_unlock();
00673 
00674    return re;
00675 }

int misdn_cfg_is_msn_valid int  port,
char *  msn
 

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

00620 {
00621    int re = 0;
00622    struct msn_list *iter;
00623 
00624    if (!misdn_cfg_is_port_valid(port)) {
00625       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
00626       return 0;
00627    }
00628 
00629    misdn_cfg_lock();
00630    if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
00631       iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
00632    else
00633       iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
00634    for (; iter; iter = iter->next) 
00635       if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
00636          re = 1;
00637          break;
00638       }
00639    misdn_cfg_unlock();
00640 
00641    return re;
00642 }

int misdn_cfg_is_port_valid int  port  ) 
 

Definition at line 644 of file misdn_config.c.

References map, max_ports, and port_cfg.

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

00645 {
00646    int gn = map[MISDN_CFG_GROUPNAME];
00647 
00648    return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
00649 }

static void misdn_cfg_lock void   )  [inline, static]
 

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

00422 {
00423    ast_mutex_lock(&config_mutex);
00424 }

void misdn_cfg_reload void   ) 
 

Definition at line 1011 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

01012 {
01013    misdn_cfg_init (0);
01014 }

static void misdn_cfg_unlock void   )  [inline, static]
 

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

00427 {
00428    ast_mutex_unlock(&config_mutex);
00429 }

void misdn_cfg_update_ptp void   ) 
 

Definition at line 963 of file misdn_config.c.

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

Referenced by reload_config().

00964 {
00965    char misdn_init[BUFFERSIZE];
00966    char line[BUFFERSIZE];
00967    FILE *fp;
00968    char *tok, *p, *end;
00969    int port;
00970 
00971    misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
00972 
00973    if (misdn_init) {
00974       fp = fopen(misdn_init, "r");
00975       if (fp) {
00976          while(fgets(line, sizeof(line), fp)) {
00977             if (!strncmp(line, "nt_ptp", 6)) {
00978                for (tok = strtok_r(line,",=", &p);
00979                    tok;
00980                    tok = strtok_r(NULL,",=", &p)) {
00981                   port = strtol(tok, &end, 10);
00982                   if (end != tok && misdn_cfg_is_port_valid(port)) {
00983                      misdn_cfg_lock();
00984                      ptp[port] = 1;
00985                      misdn_cfg_unlock();
00986                   }
00987                }
00988             }
00989          }
00990          fclose(fp);
00991       } else {
00992          ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
00993       }
00994    }
00995 }


Variable Documentation

ast_mutex_t config_mutex [static]
 

Definition at line 356 of file misdn_config.c.

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

const struct misdn_cfg_spec gen_spec[] [static]
 

Definition at line 313 of file misdn_config.c.

Referenced by _build_general_config(), get_cfg_position(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_desc(), misdn_cfg_get_elem(), and misdn_cfg_get_name().

union misdn_cfg_pt* general_cfg [static]
 

Definition at line 350 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 354 of file misdn_config.c.

Referenced by _free_port_cfg(), append_mapping(), build_mapping(), clear_config_maps(), 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_desc(), misdn_cfg_get_name(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_msn_valid(), misdn_cfg_is_port_valid(), and prune_mappings().

int max_ports [static]
 

Definition at line 348 of file misdn_config.c.

union misdn_cfg_pt** port_cfg [static]
 

Definition at line 346 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(), misdn_cfg_is_msn_valid(), and misdn_cfg_is_port_valid().

const struct misdn_cfg_spec port_spec[] [static]
 

Definition at line 94 of file misdn_config.c.

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

const char ports_description[] [static]
 

Initial value:

   "Define your ports, e.g. 1,2 (depends on mISDN-driver loading order)."

Definition at line 91 of file misdn_config.c.

Referenced by misdn_cfg_get_desc().

int* ptp [static]
 

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


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen