Thu Apr 28 2011 17:13:57

Asterisk developer's documentation


misdn_config.c File Reference

chan_misdn configuration management More...

#include "asterisk.h"
#include "chan_misdn_config.h"
#include "asterisk/config.h"
#include "asterisk/channel.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 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, const char *value, enum misdn_cfg_type type, int boolint_def)
static int get_cfg_position (const 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)
 Generate a comma separated list of all active ports.
int misdn_cfg_init (int this_max_ports, int reload)
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)
struct ast_jb_confmisdn_get_global_jbconf ()

Variables

static ast_mutex_t config_mutex
static struct ast_jb_conf default_jbconf
static struct misdn_cfg_spec gen_spec []
static union misdn_cfg_ptgeneral_cfg
static struct ast_jb_conf global_jbconf
static int * map
static int max_ports
static union misdn_cfg_pt ** port_cfg
static struct misdn_cfg_spec port_spec []
static const char ports_description [] = "Define your ports, e.g. 1,2 (depends on mISDN-driver loading order)."
static int * ptp

Detailed Description

chan_misdn configuration management

Author:
Christian Richter <crich@beronet.com>

Definition in file misdn_config.c.


Define Documentation

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

Referenced by _build_general_config(), and _build_port_config().

#define GEN_CFG   1

Definition at line 45 of file misdn_config.c.

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

#define NO_DEFAULT   "<>"

Definition at line 42 of file misdn_config.c.

Referenced by _fill_defaults(), and misdn_cfg_get_desc().

#define NONE   0

Definition at line 43 of file misdn_config.c.

#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

Definition at line 46 of file misdn_config.c.

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


Enumeration Type Documentation

Enumerator:
MISDN_CTYPE_STR 
MISDN_CTYPE_INT 
MISDN_CTYPE_BOOL 
MISDN_CTYPE_BOOLINT 
MISDN_CTYPE_MSNLIST 
MISDN_CTYPE_ASTGROUP 

Definition at line 62 of file misdn_config.c.


Function Documentation

static void _build_general_config ( struct ast_variable v) [static]

Definition at line 947 of file misdn_config.c.

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

Referenced by misdn_cfg_init().

{
   int pos;

   for (; v; v = v->next) {
      if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
         continue;
      if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 
         (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
         CLI_ERROR(v->name, v->value, "general");
   }
}
static void _build_port_config ( struct ast_variable v,
char *  cat 
) [static]

Definition at line 960 of file misdn_config.c.

References _parse(), ast_strdupa, misdn_cfg_spec::boolint_def, BUFFERSIZE, CLI_ERROR, get_cfg_position(), ast_variable::name, ast_variable::next, PORT_CFG, strsep(), misdn_cfg_spec::type, type, and ast_variable::value.

Referenced by misdn_cfg_init().

{
   int pos, i;
   union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
   int cfg_for_ports[max_ports + 1];

   if (!v || !cat)
      return;

   memset(cfg_tmp, 0, sizeof(cfg_tmp));
   memset(cfg_for_ports, 0, sizeof(cfg_for_ports));

   if (!strcasecmp(cat, "default")) {
      cfg_for_ports[0] = 1;
   }

   if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 
      (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
      CLI_ERROR(v->name, v->value, cat);
      return;
   }

   for (; v; v = v->next) {
      if (!strcasecmp(v->name, "ports")) {
         char *token, *tmp = ast_strdupa(v->value);
         char ptpbuf[BUFFERSIZE] = "";
         int start, end;
         for (token = strsep(&tmp, ","); token; token = strsep(&tmp, ","), *ptpbuf = 0) { 
            if (!*token)
               continue;
            if (sscanf(token, "%30d-%30d%511s", &start, &end, ptpbuf) >= 2) {
               for (; start <= end; start++) {
                  if (start <= max_ports && start > 0) {
                     cfg_for_ports[start] = 1;
                     ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
                  } else
                     CLI_ERROR(v->name, v->value, cat);
               }
            } else {
               if (sscanf(token, "%30d%511s", &start, ptpbuf)) {
                  if (start <= max_ports && start > 0) {
                     cfg_for_ports[start] = 1;
                     ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
                  } else
                     CLI_ERROR(v->name, v->value, cat);
               } else
                  CLI_ERROR(v->name, v->value, cat);
            }
         }
      } else {
         if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 
            (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
            CLI_ERROR(v->name, v->value, cat);
      }
   }

   for (i = 0; i < (max_ports + 1); ++i) {
      if (i > 0 && cfg_for_ports[0]) {
         /* default category, will populate the port_cfg with additional port
         categories in subsequent calls to this function */
         memset(cfg_tmp, 0, sizeof(cfg_tmp));
      }
      if (cfg_for_ports[i]) {
         memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
      }
   }
}
static int _enum_array_map ( void  ) [static]

Definition at line 398 of file misdn_config.c.

References ast_log(), LOG_WARNING, MISDN_CFG_FIRST, MISDN_CFG_LAST, MISDN_CFG_PTP, MISDN_GEN_FIRST, MISDN_GEN_LAST, NUM_GEN_ELEMENTS, and NUM_PORT_ELEMENTS.

Referenced by misdn_cfg_init().

{
   int i, j, ok;

   for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
      if (i == MISDN_CFG_PTP)
         continue;
      ok = 0;
      for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
         if (port_spec[j].elem == i) {
            map[i] = j;
            ok = 1;
            break;
         }
      }
      if (!ok) {
         ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
         return -1;
      }
   }
   for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
      ok = 0;
      for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
         if (gen_spec[j].elem == i) {
            map[i] = j;
            ok = 1;
            break;
         }
      }
      if (!ok) {
         ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
         return -1;
      }
   }
   return 0;
}
static void _fill_defaults ( void  ) [static]

Definition at line 1083 of file misdn_config.c.

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

Referenced by misdn_cfg_init().

{
   int i;

   for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
      if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
         _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
   }
   for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
      if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
         _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
   }
}
static void _free_general_cfg ( void  ) [static]

Definition at line 508 of file misdn_config.c.

References misdn_cfg_pt::any, ast_free, and NUM_GEN_ELEMENTS.

Referenced by misdn_cfg_destroy(), and misdn_cfg_init().

{
   int i;

   for (i = 0; i < NUM_GEN_ELEMENTS; i++) 
      if (general_cfg[i].any)
         ast_free(general_cfg[i].any);
}
static void _free_msn_list ( struct msn_list iter) [static]

Definition at line 466 of file misdn_config.c.

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

Referenced by _free_port_cfg().

{
   if (iter->next)
      _free_msn_list(iter->next);
   if (iter->msn)
      ast_free(iter->msn);
   ast_free(iter);
}
static void _free_port_cfg ( void  ) [static]

Definition at line 475 of file misdn_config.c.

References _free_msn_list(), misdn_cfg_pt::any, ast_free, max_ports, MISDN_CFG_GROUPNAME, MISDN_CTYPE_MSNLIST, misdn_cfg_pt::ml, NUM_PORT_ELEMENTS, str, and type.

Referenced by misdn_cfg_destroy(), and misdn_cfg_init().

{
   int i, j;
   int gn = map[MISDN_CFG_GROUPNAME];
   union misdn_cfg_pt* free_list[max_ports + 2];
   
   memset(free_list, 0, sizeof(free_list));
   free_list[0] = port_cfg[0];
   for (i = 1; i <= max_ports; ++i) {
      if (port_cfg[i][gn].str) {
         /* we always have a groupname in the non-default case, so this is fine */
         for (j = 1; j <= max_ports; ++j) {
            if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
               break;
            else if (!free_list[j]) {
               free_list[j] = port_cfg[i];
               break;
            }
         }
      }
   }
   for (j = 0; free_list[j]; ++j) {
      for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
         if (free_list[j][i].any) {
            if (port_spec[i].type == MISDN_CTYPE_MSNLIST)
               _free_msn_list(free_list[j][i].ml);
            else
               ast_free(free_list[j][i].any);
         }
      }
   }
}
static int _parse ( union misdn_cfg_pt dest,
const char *  value,
enum misdn_cfg_type  type,
int  boolint_def 
) [static]

Definition at line 870 of file misdn_config.c.

References ast_calloc, ast_free, ast_get_group(), ast_malloc, ast_strdupa, ast_true(), misdn_cfg_pt::grp, len(), 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().

{
   int re = 0;
   int len, tmp;
   char *valtmp;
   char *tmp2 = ast_strdupa(value);

   switch (type) {
   case MISDN_CTYPE_STR:
      if (dest->str) {
         ast_free(dest->str);
      }
      if ((len = strlen(value))) {
         dest->str = ast_malloc((len + 1) * sizeof(char));
         strncpy(dest->str, value, len);
         dest->str[len] = 0;
      } else {
         dest->str = ast_malloc(sizeof(char));
         dest->str[0] = 0;
      }
      break;
   case MISDN_CTYPE_INT:
   {
      int res;

      if (strchr(value,'x')) {
         res = sscanf(value, "%30x", &tmp);
      } else {
         res = sscanf(value, "%30d", &tmp);
      }
      if (res) {
         if (!dest->num) {
            dest->num = ast_malloc(sizeof(int));
         }
         memcpy(dest->num, &tmp, sizeof(int));
      } else
         re = -1;
   }
      break;
   case MISDN_CTYPE_BOOL:
      if (!dest->num) {
         dest->num = ast_malloc(sizeof(int));
      }
      *(dest->num) = (ast_true(value) ? 1 : 0);
      break;
   case MISDN_CTYPE_BOOLINT:
      if (!dest->num) {
         dest->num = ast_malloc(sizeof(int));
      }
      if (sscanf(value, "%30d", &tmp)) {
         memcpy(dest->num, &tmp, sizeof(int));
      } else {
         *(dest->num) = (ast_true(value) ? boolint_def : 0);
      }
      break;
   case MISDN_CTYPE_MSNLIST:
      for (valtmp = strsep(&tmp2, ","); valtmp; valtmp = strsep(&tmp2, ",")) {
         if ((len = strlen(valtmp))) {
            struct msn_list *ml = ast_malloc(sizeof(*ml));
            ml->msn = ast_calloc(len+1, sizeof(char));
            strncpy(ml->msn, valtmp, len);
            ml->next = dest->ml;
            dest->ml = ml;
         }
      }
      break;
   case MISDN_CTYPE_ASTGROUP:
      if (!dest->grp) {
         dest->grp = ast_malloc(sizeof(ast_group_t));
      }
      *(dest->grp) = ast_get_group(value);
      break;
   }

   return re;
}
static int get_cfg_position ( const char *  name,
int  type 
) [static]

Definition at line 435 of file misdn_config.c.

References GEN_CFG, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, and PORT_CFG.

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

{
   int i;

   switch (type) {
   case PORT_CFG:
      for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
         if (!strcasecmp(name, port_spec[i].name))
            return i;
      }
      break;
   case GEN_CFG:
      for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
         if (!strcasecmp(name, gen_spec[i].name))
            return i;
      }
   }

   return -1;
}
void misdn_cfg_get ( int  port,
enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize 
)

Definition at line 517 of file misdn_config.c.

References misdn_cfg_pt::any, ast_copy_string(), ast_log(), LOG_WARNING, misdn_cfg_is_port_valid(), MISDN_CFG_LAST, misdn_cfg_lock(), MISDN_CFG_PTP, misdn_cfg_unlock(), MISDN_CTYPE_STR, S_OR, 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_check_l2l1(), misdn_new(), misdn_request(), misdn_set_opt_exec(), process_ast_dsp(), read_config(), reload_config(), update_config(), and update_ec_config().

{
   int place;

   if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
      memset(buf, 0, bufsize);
      ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
      return;
   }

   misdn_cfg_lock();
   if (elem == MISDN_CFG_PTP) {
      if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
         memset(buf, 0, bufsize);
   } else {
      if ((place = map[elem]) < 0) {
         memset(buf, 0, bufsize);
         ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
      } else {
         if (elem < MISDN_CFG_LAST) {
            switch (port_spec[place].type) {
            case MISDN_CTYPE_STR:
               if (port_cfg[port][place].str) {
                  ast_copy_string(buf, port_cfg[port][place].str, bufsize);
               } else if (port_cfg[0][place].str) {
                  ast_copy_string(buf, port_cfg[0][place].str, bufsize);
               } else
                  memset(buf, 0, bufsize);
               break;
            default:
               if (port_cfg[port][place].any)
                  memcpy(buf, port_cfg[port][place].any, bufsize);
               else if (port_cfg[0][place].any)
                  memcpy(buf, port_cfg[0][place].any, bufsize);
               else
                  memset(buf, 0, bufsize);
            }
         } else {
            switch (gen_spec[place].type) {
            case MISDN_CTYPE_STR:
               ast_copy_string(buf, S_OR(general_cfg[place].str, ""), bufsize);
               break;
            default:
               if (general_cfg[place].any)
                  memcpy(buf, general_cfg[place].any, bufsize);
               else
                  memset(buf, 0, bufsize);
            }
         }
      }
   }
   misdn_cfg_unlock();
}
void misdn_cfg_get_config_string ( int  port,
enum misdn_cfg_elements  elem,
char *  buf,
int  bufsize 
)

Definition at line 742 of file misdn_config.c.

References ast_log(), ast_print_group(), BUFFERSIZE, LOG_WARNING, MISDN_CFG_FIRST, misdn_cfg_is_port_valid(), MISDN_CFG_LAST, misdn_cfg_lock(), MISDN_CFG_PTP, misdn_cfg_unlock(), MISDN_CTYPE_ASTGROUP, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_INT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_STR, MISDN_GEN_FIRST, MISDN_GEN_LAST, misdn_cfg_pt::ml, msn_list::msn, name, msn_list::next, num, str, and type.

Referenced by handle_cli_misdn_show_config().

{
   int place;
   char tempbuf[BUFFERSIZE] = "";
   struct msn_list *iter;

   if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
      *buf = 0;
      ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
      return;
   }

   place = map[elem];

   misdn_cfg_lock();
   if (elem == MISDN_CFG_PTP) {
      snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
   }
   else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
      switch (port_spec[place].type) {
      case MISDN_CTYPE_INT:
      case MISDN_CTYPE_BOOLINT:
         if (port_cfg[port][place].num)
            snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
         else if (port_cfg[0][place].num)
            snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
         else
            snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
         break;
      case MISDN_CTYPE_BOOL:
         if (port_cfg[port][place].num)
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
         else if (port_cfg[0][place].num)
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
         else
            snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
         break;
      case MISDN_CTYPE_ASTGROUP:
         if (port_cfg[port][place].grp)
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
                   ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
         else if (port_cfg[0][place].grp)
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
                   ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
         else
            snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
         break;
      case MISDN_CTYPE_MSNLIST:
         if (port_cfg[port][place].ml)
            iter = port_cfg[port][place].ml;
         else
            iter = port_cfg[0][place].ml;
         if (iter) {
            for (; iter; iter = iter->next) {
               strncat(tempbuf, iter->msn, sizeof(tempbuf) - strlen(tempbuf) - 1);
            }
            if (strlen(tempbuf) > 1) {
               tempbuf[strlen(tempbuf)-2] = 0;
            }
         }
         snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
         break;
      case MISDN_CTYPE_STR:
         if ( port_cfg[port][place].str) {
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
         } else if (port_cfg[0][place].str) {
            snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
         } else {
            snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
         }
         break;
      }
   } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
      switch (gen_spec[place].type) {
      case MISDN_CTYPE_INT:
      case MISDN_CTYPE_BOOLINT:
         if (general_cfg[place].num)
            snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
         else
            snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
         break;
      case MISDN_CTYPE_BOOL:
         if (general_cfg[place].num)
            snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
         else
            snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
         break;
      case MISDN_CTYPE_STR:
         if ( general_cfg[place].str) {
            snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
         } else {
            snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
         }
         break;
      default:
         snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
         break;
      }
   } else {
      *buf = 0;
      ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
   }
   misdn_cfg_unlock();
}
void misdn_cfg_get_desc ( enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize,
void *  buf_default,
int  bufsize_default 
)

Definition at line 618 of file misdn_config.c.

References ast_copy_string(), misdn_cfg_spec::def, desc, misdn_cfg_spec::elem, MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, MISDN_CFG_LAST, MISDN_GEN_FIRST, MISDN_GEN_LAST, and NO_DEFAULT.

Referenced by show_config_description().

{
   int place = map[elem];
   struct misdn_cfg_spec *spec = NULL;

   /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
   if (elem == MISDN_CFG_GROUPNAME) {
      ast_copy_string(buf, ports_description, bufsize);
      if (buf_default && bufsize_default)
         memset(buf_default, 0, 1);
      return;
   }

   if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
      spec = (struct misdn_cfg_spec *)port_spec;
   else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
      spec = (struct misdn_cfg_spec *)gen_spec;
      
   if (!spec || !spec[place].desc)
      memset(buf, 0, 1);
   else {
      ast_copy_string(buf, spec[place].desc, bufsize);
      if (buf_default && bufsize) {
         if (!strcmp(spec[place].def, NO_DEFAULT))
            memset(buf_default, 0, 1);
         else
            ast_copy_string(buf_default, spec[place].def, bufsize_default);
      }
   }
}
enum misdn_cfg_elements misdn_cfg_get_elem ( char *  name)

Definition at line 571 of file misdn_config.c.

References misdn_cfg_spec::elem, GEN_CFG, get_cfg_position(), MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, and PORT_CFG.

Referenced by handle_cli_misdn_show_config().

{
   int pos;

   /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
   if (!strcmp(name, "ports"))
      return MISDN_CFG_GROUPNAME;
   if (!strcmp(name, "name"))
      return MISDN_CFG_FIRST;

   pos = get_cfg_position(name, PORT_CFG);
   if (pos >= 0)
      return port_spec[pos].elem;
   
   pos = get_cfg_position(name, GEN_CFG);
   if (pos >= 0)
      return gen_spec[pos].elem;
   
   return MISDN_CFG_FIRST;
}
void misdn_cfg_get_name ( enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize 
)

Definition at line 592 of file misdn_config.c.

References ast_copy_string(), misdn_cfg_spec::elem, MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, MISDN_CFG_LAST, MISDN_CFG_PTP, MISDN_GEN_FIRST, MISDN_GEN_LAST, and name.

Referenced by complete_show_config(), and show_config_description().

{
   struct misdn_cfg_spec *spec = NULL;
   int place = map[elem];

   /* the ptp hack */
   if (elem == MISDN_CFG_PTP) {
      memset(buf, 0, 1);
      return;
   }
   
   /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
   if (elem == MISDN_CFG_GROUPNAME) {
      if (!snprintf(buf, bufsize, "ports"))
         memset(buf, 0, 1);
      return;
   }

   if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
      spec = (struct misdn_cfg_spec *)port_spec;
   else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
      spec = (struct misdn_cfg_spec *)gen_spec;

   ast_copy_string(buf, spec ? spec[place].name : "", bufsize);
}
int misdn_cfg_get_next_port ( int  port)
int misdn_cfg_get_next_port_spin ( int  port)

Definition at line 864 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

{
   int p = misdn_cfg_get_next_port(port);
   return (p > 0) ? p : misdn_cfg_get_next_port(0);
}
void misdn_cfg_get_ports_string ( char *  ports)

Generate a comma separated list of all active ports.

Definition at line 716 of file misdn_config.c.

References max_ports, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), misdn_cfg_unlock(), and str.

Referenced by load_module().

{
   char tmp[16];
   int l, i;
   int gn = map[MISDN_CFG_GROUPNAME];

   *ports = 0;

   misdn_cfg_lock();
   for (i = 1; i <= max_ports; i++) {
      if (port_cfg[i][gn].str) {
         if (ptp[i])
            sprintf(tmp, "%dptp,", i);
         else
            sprintf(tmp, "%d,", i);
         strcat(ports, tmp);
      }
   }
   misdn_cfg_unlock();

   if ((l = strlen(ports))) {
      /* Strip trailing ',' */
      ports[l-1] = 0;
   }
}
int misdn_cfg_init ( int  this_max_ports,
int  reload 
)

Definition at line 1118 of file misdn_config.c.

References _build_general_config(), _build_port_config(), _enum_array_map(), _fill_defaults(), _free_general_cfg(), _free_port_cfg(), ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_log(), ast_mutex_init(), ast_variable_browse(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, global_jbconf, LOG_WARNING, max_ports, misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_GEN_LAST, NUM_GEN_ELEMENTS, and NUM_PORT_ELEMENTS.

Referenced by load_module(), and misdn_cfg_reload().

{
   char config[] = "misdn.conf";
   char *cat, *p;
   int i;
   struct ast_config *cfg;
   struct ast_variable *v;
   struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

   if (!(cfg = ast_config_load2(config, "chan_misdn", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
      ast_log(LOG_WARNING, "missing or invalid file: misdn.conf\n");
      return -1;
   } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
      return 0;

   ast_mutex_init(&config_mutex);

   /* Copy the default jb config over global_jbconf */
   memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));

   misdn_cfg_lock();

   if (this_max_ports) {
      /* this is the first run */
      max_ports = this_max_ports;
      map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
      if (_enum_array_map())
         return -1;
      p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
                     + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
      port_cfg = (union misdn_cfg_pt **)p;
      p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
      for (i = 0; i <= max_ports; ++i) {
         port_cfg[i] = (union misdn_cfg_pt *)p;
         p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
      }
      general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
      ptp = ast_calloc(max_ports + 1, sizeof(int));
   }
   else {
      /* misdn reload */
      _free_port_cfg();
      _free_general_cfg();
      memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
      memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
      memset(ptp, 0, sizeof(int) * (max_ports + 1));
   }

   cat = ast_category_browse(cfg, NULL);

   while(cat) {
      v = ast_variable_browse(cfg, cat);
      if (!strcasecmp(cat, "general")) {
         _build_general_config(v);
      } else {
         _build_port_config(v, cat);
      }
      cat = ast_category_browse(cfg, cat);
   }

   _fill_defaults();

   misdn_cfg_unlock();
   ast_config_destroy(cfg);

   return 0;
}
int misdn_cfg_is_group_method ( char *  group,
enum misdn_cfg_method  meth 
)

Definition at line 681 of file misdn_config.c.

References max_ports, METHOD_ROUND_ROBIN, METHOD_STANDARD, METHOD_STANDARD_DEC, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), MISDN_CFG_METHOD, misdn_cfg_unlock(), str, and misdn_cfg_pt::str.

Referenced by misdn_request().

{
   int i, re = 0;
   char *method ;

   misdn_cfg_lock();

   method = port_cfg[0][map[MISDN_CFG_METHOD]].str;

   for (i = 1; i <= max_ports; i++) {
      if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
         if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
            method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 
                    port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
      }
   }

   if (method) {
      switch (meth) {
      case METHOD_STANDARD:      re = !strcasecmp(method, "standard");
                           break;
      case METHOD_ROUND_ROBIN:   re = !strcasecmp(method, "round_robin");
                           break;
      case METHOD_STANDARD_DEC:  re = !strcasecmp(method, "standard_dec");
                           break;
      }
   }
   misdn_cfg_unlock();

   return re;
}
int misdn_cfg_is_msn_valid ( int  port,
char *  msn 
)

Definition at line 649 of file misdn_config.c.

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

Referenced by cb_events().

{
   int re = 0;
   struct msn_list *iter;

   if (!misdn_cfg_is_port_valid(port)) {
      ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
      return 0;
   }

   misdn_cfg_lock();
   if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
      iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
   else
      iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
   for (; iter; iter = iter->next) 
      if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
         re = 1;
         break;
      }
   misdn_cfg_unlock();

   return re;
}
int misdn_cfg_is_port_valid ( int  port)

Definition at line 674 of file misdn_config.c.

References MISDN_CFG_GROUPNAME, and str.

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

{
   int gn = map[MISDN_CFG_GROUPNAME];

   return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
}
void misdn_cfg_reload ( void  )

Definition at line 1097 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

{
   misdn_cfg_init(0, 1);
}
void misdn_cfg_update_ptp ( void  )

Definition at line 1028 of file misdn_config.c.

References ast_log(), ast_strlen_zero(), BUFFERSIZE, errno, LOG_WARNING, max_ports, misdn_cfg_get(), misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_unlock(), and MISDN_GEN_MISDN_INIT.

Referenced by load_module(), and reload_config().

{
#ifndef MISDN_1_2
   char misdn_init[BUFFERSIZE];
   char line[BUFFERSIZE];
   FILE *fp;
   char *tok, *p, *end;
   int port;

   misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));

   if (!ast_strlen_zero(misdn_init)) {
      fp = fopen(misdn_init, "r");
      if (fp) {
         while(fgets(line, sizeof(line), fp)) {
            if (!strncmp(line, "nt_ptp", 6)) {
               for (tok = strtok_r(line,",=", &p);
                   tok;
                   tok = strtok_r(NULL,",=", &p)) {
                  port = strtol(tok, &end, 10);
                  if (end != tok && misdn_cfg_is_port_valid(port)) {
                     misdn_cfg_lock();
                     ptp[port] = 1;
                     misdn_cfg_unlock();
                  }
               }
            }
         }
         fclose(fp);
      } else {
         ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
      }
   }
#else
   int i;
   int proto;
   char filename[128];
   FILE *fp;

   for (i = 1; i <= max_ports; ++i) {
      snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
      fp = fopen(filename, "r");
      if (!fp) {
         ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
         continue;
      }
      if (fscanf(fp, "0x%08x", &proto) != 1)
         ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
      else
         ptp[i] = proto & 1<<5 ? 1 : 0;
      fclose(fp);
   }
#endif
}
struct ast_jb_conf* misdn_get_global_jbconf ( void  ) [read]

Definition at line 1186 of file misdn_config.c.

References global_jbconf.

Referenced by misdn_new().

                                              {
   return &global_jbconf;
}

Variable Documentation

Definition at line 391 of file misdn_config.c.

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 51 of file misdn_config.c.

struct misdn_cfg_spec gen_spec[] [static]

Definition at line 342 of file misdn_config.c.

union misdn_cfg_pt* general_cfg [static]

Definition at line 385 of file misdn_config.c.

struct ast_jb_conf global_jbconf [static]

Definition at line 60 of file misdn_config.c.

Referenced by _build_general_config(), misdn_cfg_init(), and misdn_get_global_jbconf().

union misdn_cfg_pt** port_cfg [static]

Definition at line 381 of file misdn_config.c.

struct misdn_cfg_spec port_spec[] [static]

Definition at line 97 of file misdn_config.c.

const char ports_description[] = "Define your ports, e.g. 1,2 (depends on mISDN-driver loading order)." [static]

Definition at line 94 of file misdn_config.c.

int* ptp [static]

Definition at line 387 of file misdn_config.c.

Referenced by misdn_lib_init().