Wed Jan 8 2020 09:50:15

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"

Go to the source code of this file.

Data Structures

union  misdn_cfg_pt
 
struct  misdn_cfg_spec
 
struct  msn_list
 

Macros

#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 (const 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. More...
 
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 []
 
static int * ptp
 

Detailed Description

chan_misdn configuration management

Author
Christian Richter crich.nosp@m.@ber.nosp@m.onet..nosp@m.com

Definition in file misdn_config.c.

Macro Definition 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); \
})
#define LOG_WARNING
Definition: logger.h:144
int value
Definition: syslog.c:39
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const char name[]

Definition at line 438 of file misdn_config.c.

Referenced by _build_general_config(), and _build_port_config().

#define GEN_CFG   1

Definition at line 49 of file misdn_config.c.

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

#define NO_DEFAULT   "<>"

Definition at line 46 of file misdn_config.c.

Referenced by _fill_defaults(), and misdn_cfg_get_desc().

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

Function Documentation

static void _build_general_config ( struct ast_variable v)
static

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

993 {
994  int pos;
995 
996  for (; v; v = v->next) {
997  if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
998  continue;
999  if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) ||
1000  (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
1001  CLI_ERROR(v->name, v->value, "general");
1002  }
1003 }
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:915
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
Definition: abstract_jb.c:577
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:65
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:480
const char * value
Definition: config.h:79
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
const char * name
Definition: config.h:77
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
enum misdn_cfg_type type
Definition: misdn_config.c:92
#define GEN_CFG
Definition: misdn_config.c:49
struct ast_variable * next
Definition: config.h:82
#define CLI_ERROR(name, value, section)
Definition: misdn_config.c:438
static void _build_port_config ( struct ast_variable v,
char *  cat 
)
static

Definition at line 1005 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(), type, misdn_cfg_spec::type, and ast_variable::value.

Referenced by misdn_cfg_init().

1006 {
1007  int pos, i;
1008  union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
1009  int cfg_for_ports[max_ports + 1];
1010 
1011  if (!v || !cat)
1012  return;
1013 
1014  memset(cfg_tmp, 0, sizeof(cfg_tmp));
1015  memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
1016 
1017  if (!strcasecmp(cat, "default")) {
1018  cfg_for_ports[0] = 1;
1019  }
1020 
1021  if (((pos = get_cfg_position("name", PORT_CFG)) < 0) ||
1022  (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
1023  CLI_ERROR(v->name, v->value, cat);
1024  return;
1025  }
1026 
1027  for (; v; v = v->next) {
1028  if (!strcasecmp(v->name, "ports")) {
1029  char *token, *tmp = ast_strdupa(v->value);
1030  char ptpbuf[BUFFERSIZE] = "";
1031  int start, end;
1032  for (token = strsep(&tmp, ","); token; token = strsep(&tmp, ","), *ptpbuf = 0) {
1033  if (!*token)
1034  continue;
1035  if (sscanf(token, "%30d-%30d%511s", &start, &end, ptpbuf) >= 2) {
1036  for (; start <= end; start++) {
1037  if (start <= max_ports && start > 0) {
1038  cfg_for_ports[start] = 1;
1039  ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
1040  } else
1041  CLI_ERROR(v->name, v->value, cat);
1042  }
1043  } else {
1044  if (sscanf(token, "%30d%511s", &start, ptpbuf)) {
1045  if (start <= max_ports && start > 0) {
1046  cfg_for_ports[start] = 1;
1047  ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
1048  } else
1049  CLI_ERROR(v->name, v->value, cat);
1050  } else
1051  CLI_ERROR(v->name, v->value, cat);
1052  }
1053  }
1054  } else {
1055  if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) ||
1056  (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
1057  CLI_ERROR(v->name, v->value, cat);
1058  }
1059  }
1060 
1061  for (i = 0; i < (max_ports + 1); ++i) {
1062  if (i > 0 && cfg_for_ports[0]) {
1063  /* default category, will populate the port_cfg with additional port
1064  categories in subsequent calls to this function */
1065  memset(cfg_tmp, 0, sizeof(cfg_tmp));
1066  }
1067  if (cfg_for_ports[i]) {
1068  memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
1069  }
1070  }
1071 }
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:915
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
char * strsep(char **str, const char *delims)
#define PORT_CFG
Definition: misdn_config.c:50
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static int max_ports
Definition: misdn_config.c:428
#define BUFFERSIZE
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:480
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static const char type[]
Definition: chan_nbs.c:57
enum misdn_cfg_type type
Definition: misdn_config.c:92
static int * ptp
Definition: misdn_config.c:432
struct ast_variable * next
Definition: config.h:82
#define CLI_ERROR(name, value, section)
Definition: misdn_config.c:438
static int _enum_array_map ( void  )
static

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

444 {
445  int i, j, ok;
446 
447  for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
448  if (i == MISDN_CFG_PTP)
449  continue;
450  ok = 0;
451  for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
452  if (port_spec[j].elem == i) {
453  map[i] = j;
454  ok = 1;
455  break;
456  }
457  }
458  if (!ok) {
459  ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
460  return -1;
461  }
462  }
463  for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
464  ok = 0;
465  for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
466  if (gen_spec[j].elem == i) {
467  map[i] = j;
468  ok = 1;
469  break;
470  }
471  }
472  if (!ok) {
473  ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
474  return -1;
475  }
476  }
477  return 0;
478 }
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
static int * map
Definition: misdn_config.c:434
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:51
#define LOG_WARNING
Definition: logger.h:144
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static void _fill_defaults ( void  )
static

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

1129 {
1130  int i;
1131 
1132  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
1133  if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
1134  _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
1135  }
1136  for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
1137  if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
1138  _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
1139  }
1140 }
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:915
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:51
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char type[]
Definition: chan_nbs.c:57
#define NO_DEFAULT
Definition: misdn_config.c:46
static void _free_general_cfg ( void  )
static

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

554 {
555  int i;
556 
557  for (i = 0; i < NUM_GEN_ELEMENTS; i++)
558  if (general_cfg[i].any)
559  ast_free(general_cfg[i].any);
560 }
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:51
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
#define ast_free(a)
Definition: astmm.h:97
static void _free_msn_list ( struct msn_list iter)
static

Definition at line 511 of file misdn_config.c.

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

Referenced by _free_port_cfg().

512 {
513  if (iter->next)
514  _free_msn_list(iter->next);
515  if (iter->msn)
516  ast_free(iter->msn);
517  ast_free(iter);
518 }
struct msn_list * next
Definition: misdn_config.c:78
char * msn
Definition: misdn_config.c:77
static void _free_msn_list(struct msn_list *iter)
Definition: misdn_config.c:511
#define ast_free(a)
Definition: astmm.h:97
static void _free_port_cfg ( void  )
static

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

521 {
522  int i, j;
523  int gn = map[MISDN_CFG_GROUPNAME];
524  union misdn_cfg_pt* free_list[max_ports + 2];
525 
526  memset(free_list, 0, sizeof(free_list));
527  free_list[0] = port_cfg[0];
528  for (i = 1; i <= max_ports; ++i) {
529  if (port_cfg[i][gn].str) {
530  /* we always have a groupname in the non-default case, so this is fine */
531  for (j = 1; j <= max_ports; ++j) {
532  if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
533  break;
534  else if (!free_list[j]) {
535  free_list[j] = port_cfg[i];
536  break;
537  }
538  }
539  }
540  }
541  for (j = 0; free_list[j]; ++j) {
542  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
543  if (free_list[j][i].any) {
545  _free_msn_list(free_list[j][i].ml);
546  else
547  ast_free(free_list[j][i].any);
548  }
549  }
550  }
551 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
static int * map
Definition: misdn_config.c:434
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static int max_ports
Definition: misdn_config.c:428
const char * str
Definition: app_jack.c:144
static void _free_msn_list(struct msn_list *iter)
Definition: misdn_config.c:511
#define ast_free(a)
Definition: astmm.h:97
static const char type[]
Definition: chan_nbs.c:57
struct msn_list * ml
Definition: misdn_config.c:84
static int _parse ( union misdn_cfg_pt dest,
const char *  value,
enum misdn_cfg_type  type,
int  boolint_def 
)
static

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

916 {
917  int re = 0;
918  int len, tmp;
919  char *valtmp;
920  char *tmp2 = ast_strdupa(value);
921 
922  switch (type) {
923  case MISDN_CTYPE_STR:
924  if (dest->str) {
925  ast_free(dest->str);
926  }
927  if ((len = strlen(value))) {
928  dest->str = ast_malloc((len + 1) * sizeof(char));
929  strncpy(dest->str, value, len);
930  dest->str[len] = 0;
931  } else {
932  dest->str = ast_malloc(sizeof(char));
933  dest->str[0] = 0;
934  }
935  break;
936  case MISDN_CTYPE_INT:
937  {
938  int res;
939 
940  if (strchr(value,'x')) {
941  res = sscanf(value, "%30x", &tmp);
942  } else {
943  res = sscanf(value, "%30d", &tmp);
944  }
945  if (res) {
946  if (!dest->num) {
947  dest->num = ast_malloc(sizeof(int));
948  }
949  memcpy(dest->num, &tmp, sizeof(int));
950  } else
951  re = -1;
952  }
953  break;
954  case MISDN_CTYPE_BOOL:
955  if (!dest->num) {
956  dest->num = ast_malloc(sizeof(int));
957  }
958  *(dest->num) = (ast_true(value) ? 1 : 0);
959  break;
960  case MISDN_CTYPE_BOOLINT:
961  if (!dest->num) {
962  dest->num = ast_malloc(sizeof(int));
963  }
964  if (sscanf(value, "%30d", &tmp)) {
965  memcpy(dest->num, &tmp, sizeof(int));
966  } else {
967  *(dest->num) = (ast_true(value) ? boolint_def : 0);
968  }
969  break;
970  case MISDN_CTYPE_MSNLIST:
971  for (valtmp = strsep(&tmp2, ","); valtmp; valtmp = strsep(&tmp2, ",")) {
972  if ((len = strlen(valtmp))) {
973  struct msn_list *ml = ast_malloc(sizeof(*ml));
974  ml->msn = ast_calloc(len+1, sizeof(char));
975  strncpy(ml->msn, valtmp, len);
976  ml->next = dest->ml;
977  dest->ml = ml;
978  }
979  }
980  break;
982  if (!dest->grp) {
983  dest->grp = ast_malloc(sizeof(ast_group_t));
984  }
985  *(dest->grp) = ast_get_group(value);
986  break;
987  }
988 
989  return re;
990 }
unsigned long long ast_group_t
Definition: channel.h:175
char * strsep(char **str, const char *delims)
int value
Definition: syslog.c:39
struct msn_list * next
Definition: misdn_config.c:78
ast_group_t * grp
Definition: misdn_config.c:85
char * msn
Definition: misdn_config.c:77
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7987
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:97
static const char type[]
Definition: chan_nbs.c:57
struct msn_list * ml
Definition: misdn_config.c:84
#define ast_calloc(a, b)
Definition: astmm.h:82
#define ast_malloc(a)
Definition: astmm.h:91
static int get_cfg_position ( const char *  name,
int  type 
)
static

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

481 {
482  int i;
483 
484  switch (type) {
485  case PORT_CFG:
486  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
487  if (!strcasecmp(name, port_spec[i].name))
488  return i;
489  }
490  break;
491  case GEN_CFG:
492  for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
493  if (!strcasecmp(name, gen_spec[i].name))
494  return i;
495  }
496  }
497 
498  return -1;
499 }
#define PORT_CFG
Definition: misdn_config.c:50
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:51
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char name[]
static const char type[]
Definition: chan_nbs.c:57
#define GEN_CFG
Definition: misdn_config.c:49
void misdn_cfg_destroy ( void  )

Definition at line 1147 of file misdn_config.c.

References _free_general_cfg(), _free_port_cfg(), ast_free, ast_mutex_destroy, misdn_cfg_lock(), and misdn_cfg_unlock().

Referenced by unload_module().

1148 {
1149  misdn_cfg_lock();
1150 
1151  _free_port_cfg();
1153 
1154  ast_free(port_cfg);
1156  ast_free(ptp);
1157  ast_free(map);
1158 
1159  misdn_cfg_unlock();
1161 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
static void _free_port_cfg(void)
Definition: misdn_config.c:520
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
#define ast_free(a)
Definition: astmm.h:97
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
static void _free_general_cfg(void)
Definition: misdn_config.c:553
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
#define ast_mutex_destroy(a)
Definition: lock.h:154
static ast_mutex_t config_mutex
Definition: misdn_config.c:436
void misdn_cfg_get ( int  port,
enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize 
)

Definition at line 562 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_add_number_prefix(), misdn_bridge(), misdn_call(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_get_connected_line(), misdn_new(), misdn_request(), misdn_set_opt_exec(), process_ast_dsp(), read_config(), reload_config(), update_config(), and update_ec_config().

563 {
564  int place;
565 
566  if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
567  memset(buf, 0, bufsize);
568  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
569  return;
570  }
571 
572  misdn_cfg_lock();
573  if (elem == MISDN_CFG_PTP) {
574  if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
575  memset(buf, 0, bufsize);
576  } else {
577  if ((place = map[elem]) < 0) {
578  memset(buf, 0, bufsize);
579  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
580  } else {
581  if (elem < MISDN_CFG_LAST) {
582  switch (port_spec[place].type) {
583  case MISDN_CTYPE_STR:
584  if (port_cfg[port][place].str) {
585  ast_copy_string(buf, port_cfg[port][place].str, bufsize);
586  } else if (port_cfg[0][place].str) {
587  ast_copy_string(buf, port_cfg[0][place].str, bufsize);
588  } else
589  memset(buf, 0, bufsize);
590  break;
591  default:
592  if (port_cfg[port][place].any)
593  memcpy(buf, port_cfg[port][place].any, bufsize);
594  else if (port_cfg[0][place].any)
595  memcpy(buf, port_cfg[0][place].any, bufsize);
596  else
597  memset(buf, 0, bufsize);
598  }
599  } else {
600  switch (gen_spec[place].type) {
601  case MISDN_CTYPE_STR:
602  ast_copy_string(buf, S_OR(general_cfg[place].str, ""), bufsize);
603  break;
604  default:
605  if (general_cfg[place].any)
606  memcpy(buf, general_cfg[place].any, bufsize);
607  else
608  memset(buf, 0, bufsize);
609  }
610  }
611  }
612  }
614 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
#define LOG_WARNING
Definition: logger.h:144
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
const char * str
Definition: app_jack.c:144
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char type[]
Definition: chan_nbs.c:57
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:719
void misdn_cfg_get_config_string ( int  port,
enum misdn_cfg_elements  elem,
char *  buf,
int  bufsize 
)

Definition at line 787 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, str, and type.

Referenced by handle_cli_misdn_show_config().

788 {
789  int place;
790  char tempbuf[BUFFERSIZE] = "";
791  struct msn_list *iter;
792 
793  if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
794  *buf = 0;
795  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
796  return;
797  }
798 
799  place = map[elem];
800 
801  misdn_cfg_lock();
802  if (elem == MISDN_CFG_PTP) {
803  snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
804  }
805  else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
806  switch (port_spec[place].type) {
807  case MISDN_CTYPE_INT:
808  case MISDN_CTYPE_BOOLINT:
809  if (port_cfg[port][place].num)
810  snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
811  else if (port_cfg[0][place].num)
812  snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
813  else
814  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
815  break;
816  case MISDN_CTYPE_BOOL:
817  if (port_cfg[port][place].num)
818  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
819  else if (port_cfg[0][place].num)
820  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
821  else
822  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
823  break;
825  if (port_cfg[port][place].grp)
826  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
827  ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
828  else if (port_cfg[0][place].grp)
829  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
830  ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
831  else
832  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
833  break;
834  case MISDN_CTYPE_MSNLIST:
835  if (port_cfg[port][place].ml)
836  iter = port_cfg[port][place].ml;
837  else
838  iter = port_cfg[0][place].ml;
839  if (iter) {
840  for (; iter; iter = iter->next) {
841  strncat(tempbuf, iter->msn, sizeof(tempbuf) - strlen(tempbuf) - 1);
842  }
843  if (strlen(tempbuf) > 1) {
844  tempbuf[strlen(tempbuf)-2] = 0;
845  }
846  }
847  snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
848  break;
849  case MISDN_CTYPE_STR:
850  if ( port_cfg[port][place].str) {
851  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
852  } else if (port_cfg[0][place].str) {
853  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
854  } else {
855  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
856  }
857  break;
858  }
859  } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
860  switch (gen_spec[place].type) {
861  case MISDN_CTYPE_INT:
862  case MISDN_CTYPE_BOOLINT:
863  if (general_cfg[place].num)
864  snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
865  else
866  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
867  break;
868  case MISDN_CTYPE_BOOL:
869  if (general_cfg[place].num)
870  snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
871  else
872  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
873  break;
874  case MISDN_CTYPE_STR:
875  if ( general_cfg[place].str) {
876  snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
877  } else {
878  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
879  }
880  break;
881  default:
882  snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
883  break;
884  }
885  } else {
886  *buf = 0;
887  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
888  }
890 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
#define LOG_WARNING
Definition: logger.h:144
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
const char * str
Definition: app_jack.c:144
struct msn_list * next
Definition: misdn_config.c:78
char * ast_print_group(char *buf, int buflen, ast_group_t group)
print call- and pickup groups into buffer
Definition: channel.c:8236
#define BUFFERSIZE
char * msn
Definition: misdn_config.c:77
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char name[]
static const char type[]
Definition: chan_nbs.c:57
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
struct msn_list * ml
Definition: misdn_config.c:84
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:719
void misdn_cfg_get_desc ( enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize,
void *  buf_default,
int  bufsize_default 
)

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

664 {
665  int place = map[elem];
666  struct misdn_cfg_spec *spec = NULL;
667 
668  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
669  if (elem == MISDN_CFG_GROUPNAME) {
670  ast_copy_string(buf, ports_description, bufsize);
671  if (buf_default && bufsize_default)
672  memset(buf_default, 0, 1);
673  return;
674  }
675 
676  if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
677  spec = (struct misdn_cfg_spec *)port_spec;
678  else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
679  spec = (struct misdn_cfg_spec *)gen_spec;
680 
681  if (!spec || !spec[place].desc)
682  memset(buf, 0, 1);
683  else {
684  ast_copy_string(buf, spec[place].desc, bufsize);
685  if (buf_default && bufsize) {
686  if (!strcmp(spec[place].def, NO_DEFAULT))
687  memset(buf_default, 0, 1);
688  else
689  ast_copy_string(buf_default, spec[place].def, bufsize_default);
690  }
691  }
692 }
static int * map
Definition: misdn_config.c:434
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static const char desc[]
Definition: cdr_radius.c:85
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
char def[BUFFERSIZE]
Definition: misdn_config.c:93
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char ports_description[]
Definition: misdn_config.c:99
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define NO_DEFAULT
Definition: misdn_config.c:46
enum misdn_cfg_elements misdn_cfg_get_elem ( const char *  name)

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

617 {
618  int pos;
619 
620  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
621  if (!strcmp(name, "ports"))
622  return MISDN_CFG_GROUPNAME;
623  if (!strcmp(name, "name"))
624  return MISDN_CFG_FIRST;
625 
627  if (pos >= 0)
628  return port_spec[pos].elem;
629 
630  pos = get_cfg_position(name, GEN_CFG);
631  if (pos >= 0)
632  return gen_spec[pos].elem;
633 
634  return MISDN_CFG_FIRST;
635 }
#define PORT_CFG
Definition: misdn_config.c:50
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:480
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char name[]
#define GEN_CFG
Definition: misdn_config.c:49
void misdn_cfg_get_name ( enum misdn_cfg_elements  elem,
void *  buf,
int  bufsize 
)

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

638 {
639  struct misdn_cfg_spec *spec = NULL;
640  int place = map[elem];
641 
642  /* the ptp hack */
643  if (elem == MISDN_CFG_PTP) {
644  memset(buf, 0, 1);
645  return;
646  }
647 
648  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
649  if (elem == MISDN_CFG_GROUPNAME) {
650  if (!snprintf(buf, bufsize, "ports"))
651  memset(buf, 0, 1);
652  return;
653  }
654 
655  if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
656  spec = (struct misdn_cfg_spec *)port_spec;
657  else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
658  spec = (struct misdn_cfg_spec *)gen_spec;
659 
660  ast_copy_string(buf, spec ? spec[place].name : "", bufsize);
661 }
static int * map
Definition: misdn_config.c:434
static struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
static struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:387
static const char name[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int misdn_cfg_get_next_port ( int  port)

Definition at line 892 of file misdn_config.c.

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

Referenced by complete_show_config(), handle_cli_misdn_show_config(), handle_cli_misdn_show_ports_stats(), handle_cli_misdn_show_stacks(), load_module(), misdn_cfg_get_next_port_spin(), misdn_check_l2l1(), misdn_new(), misdn_request(), and update_name().

893 {
894  int p = -1;
895  int gn = map[MISDN_CFG_GROUPNAME];
896 
897  misdn_cfg_lock();
898  for (port++; port <= max_ports; port++) {
899  if (port_cfg[port][gn].str) {
900  p = port;
901  break;
902  }
903  }
905 
906  return p;
907 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
static int max_ports
Definition: misdn_config.c:428
const char * str
Definition: app_jack.c:144
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_get_next_port_spin ( int  port)

Definition at line 909 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

910 {
911  int p = misdn_cfg_get_next_port(port);
912  return (p > 0) ? p : misdn_cfg_get_next_port(0);
913 }
int misdn_cfg_get_next_port(int port)
Definition: misdn_config.c:892
void misdn_cfg_get_ports_string ( char *  ports)

Generate a comma separated list of all active ports.

Definition at line 761 of file misdn_config.c.

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

Referenced by load_module().

762 {
763  char tmp[16];
764  int l, i;
765  int gn = map[MISDN_CFG_GROUPNAME];
766 
767  *ports = 0;
768 
769  misdn_cfg_lock();
770  for (i = 1; i <= max_ports; i++) {
771  if (port_cfg[i][gn].str) {
772  if (ptp[i])
773  sprintf(tmp, "%dptp,", i);
774  else
775  sprintf(tmp, "%d,", i);
776  strcat(ports, tmp);
777  }
778  }
780 
781  if ((l = strlen(ports))) {
782  /* Strip trailing ',' */
783  ports[l-1] = 0;
784  }
785 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
static int max_ports
Definition: misdn_config.c:428
const char * str
Definition: app_jack.c:144
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_init ( int  this_max_ports,
int  reload 
)

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

1164 {
1165  char config[] = "misdn.conf";
1166  char *cat, *p;
1167  int i;
1168  struct ast_config *cfg;
1169  struct ast_variable *v;
1170  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
1171 
1172  if (!(cfg = ast_config_load2(config, "chan_misdn", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
1173  ast_log(LOG_WARNING, "missing or invalid file: misdn.conf\n");
1174  return -1;
1175  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
1176  return 0;
1177 
1179 
1180  /* Copy the default jb config over global_jbconf */
1181  memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
1182 
1183  misdn_cfg_lock();
1184 
1185  if (this_max_ports) {
1186  /* this is the first run */
1187  max_ports = this_max_ports;
1188  map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
1189  if (_enum_array_map())
1190  return -1;
1191  p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
1192  + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
1193  port_cfg = (union misdn_cfg_pt **)p;
1194  p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
1195  for (i = 0; i <= max_ports; ++i) {
1196  port_cfg[i] = (union misdn_cfg_pt *)p;
1197  p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
1198  }
1199  general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1200  ptp = ast_calloc(max_ports + 1, sizeof(int));
1201  }
1202  else {
1203  /* misdn reload */
1204  _free_port_cfg();
1206  memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
1207  memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1208  memset(ptp, 0, sizeof(int) * (max_ports + 1));
1209  }
1210 
1211  cat = ast_category_browse(cfg, NULL);
1212 
1213  while(cat) {
1214  v = ast_variable_browse(cfg, cat);
1215  if (!strcasecmp(cat, "general")) {
1217  } else {
1218  _build_port_config(v, cat);
1219  }
1220  cat = ast_category_browse(cfg, cat);
1221  }
1222 
1223  _fill_defaults();
1224 
1225  misdn_cfg_unlock();
1226  ast_config_destroy(cfg);
1227 
1228  return 0;
1229 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static const char config[]
Definition: cdr_csv.c:57
static void _fill_defaults(void)
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:52
static int * map
Definition: misdn_config.c:434
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:51
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
static struct ast_jb_conf default_jbconf
Definition: misdn_config.c:56
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static int max_ports
Definition: misdn_config.c:428
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:65
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: config.c:2499
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static void _build_port_config(struct ast_variable *v, char *cat)
static void _free_port_cfg(void)
Definition: misdn_config.c:520
static int _enum_array_map(void)
Definition: misdn_config.c:443
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:430
static int reload(void)
Definition: app_amd.c:497
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
Structure used to handle boolean flags.
Definition: utils.h:200
static void _free_general_cfg(void)
Definition: misdn_config.c:553
static void _build_general_config(struct ast_variable *v)
Definition: misdn_config.c:992
#define ast_calloc(a, b)
Definition: astmm.h:82
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
#define ast_mutex_init(pmutex)
Definition: lock.h:152
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static ast_mutex_t config_mutex
Definition: misdn_config.c:436
General jitterbuffer configuration.
Definition: abstract_jb.h:55
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
int misdn_cfg_is_group_method ( char *  group,
enum misdn_cfg_method  meth 
)

Definition at line 726 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(), misdn_cfg_pt::str, and str.

Referenced by misdn_request().

727 {
728  int i, re = 0;
729  char *method ;
730 
731  misdn_cfg_lock();
732 
733  method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
734 
735  for (i = 1; i <= max_ports; i++) {
736  if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
737  if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
738  method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ?
740  }
741  }
742 
743  if (method) {
744  switch (meth) {
745  case METHOD_STANDARD: re = !strcasecmp(method, "standard");
746  break;
747  case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin");
748  break;
749  case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec");
750  break;
751  }
752  }
754 
755  return re;
756 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
static int max_ports
Definition: misdn_config.c:428
const char * str
Definition: app_jack.c:144
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_is_msn_valid ( int  port,
char *  msn 
)

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

695 {
696  int re = 0;
697  struct msn_list *iter;
698 
699  if (!misdn_cfg_is_port_valid(port)) {
700  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
701  return 0;
702  }
703 
704  misdn_cfg_lock();
705  if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
706  iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
707  else
708  iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
709  for (; iter; iter = iter->next)
710  if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
711  re = 1;
712  break;
713  }
715 
716  return re;
717 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
#define LOG_WARNING
Definition: logger.h:144
struct msn_list * next
Definition: misdn_config.c:78
char * msn
Definition: misdn_config.c:77
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
struct msn_list * ml
Definition: misdn_config.c:84
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:719
int misdn_cfg_is_port_valid ( int  port)

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

720 {
721  int gn = map[MISDN_CFG_GROUPNAME];
722 
723  return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
724 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:426
static int * map
Definition: misdn_config.c:434
static int max_ports
Definition: misdn_config.c:428
const char * str
Definition: app_jack.c:144
static void misdn_cfg_lock ( void  )
inlinestatic
void misdn_cfg_reload ( void  )

Definition at line 1142 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

1143 {
1144  misdn_cfg_init(0, 1);
1145 }
int misdn_cfg_init(int this_max_ports, int reload)
static void misdn_cfg_unlock ( void  )
inlinestatic
void misdn_cfg_update_ptp ( void  )

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

1074 {
1075 #ifndef MISDN_1_2
1076  char misdn_init[BUFFERSIZE];
1077  char line[BUFFERSIZE];
1078  FILE *fp;
1079  char *tok, *p, *end;
1080  int port;
1081 
1082  misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
1083 
1084  if (!ast_strlen_zero(misdn_init)) {
1085  fp = fopen(misdn_init, "r");
1086  if (fp) {
1087  while(fgets(line, sizeof(line), fp)) {
1088  if (!strncmp(line, "nt_ptp", 6)) {
1089  for (tok = strtok_r(line,",=", &p);
1090  tok;
1091  tok = strtok_r(NULL,",=", &p)) {
1092  port = strtol(tok, &end, 10);
1093  if (end != tok && misdn_cfg_is_port_valid(port)) {
1094  misdn_cfg_lock();
1095  ptp[port] = 1;
1096  misdn_cfg_unlock();
1097  }
1098  }
1099  }
1100  }
1101  fclose(fp);
1102  } else {
1103  ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
1104  }
1105  }
1106 #else
1107  int i;
1108  int proto;
1109  char filename[128];
1110  FILE *fp;
1111 
1112  for (i = 1; i <= max_ports; ++i) {
1113  snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
1114  fp = fopen(filename, "r");
1115  if (!fp) {
1116  ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
1117  continue;
1118  }
1119  if (fscanf(fp, "0x%08x", &proto) != 1)
1120  ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
1121  else
1122  ptp[i] = proto & 1<<5 ? 1 : 0;
1123  fclose(fp);
1124  }
1125 #endif
1126 }
#define LOG_WARNING
Definition: logger.h:144
static int max_ports
Definition: misdn_config.c:428
#define BUFFERSIZE
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:506
void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
Definition: misdn_config.c:562
static int * ptp
Definition: misdn_config.c:432
static void misdn_cfg_lock(void)
Definition: misdn_config.c:501
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:719
struct ast_jb_conf* misdn_get_global_jbconf ( void  )

Definition at line 1231 of file misdn_config.c.

References global_jbconf.

Referenced by misdn_new().

1231  {
1232  return &global_jbconf;
1233 }
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:65

Variable Documentation

ast_mutex_t config_mutex
static

Definition at line 436 of file misdn_config.c.

struct ast_jb_conf default_jbconf
static

Global jitterbuffer configuration - by default, jb is disabled

Note
Values shown here match the defaults shown in misdn.conf.sample

Definition at line 56 of file misdn_config.c.

struct misdn_cfg_spec gen_spec[]
static

Definition at line 387 of file misdn_config.c.

union misdn_cfg_pt* general_cfg
static

Definition at line 430 of file misdn_config.c.

struct ast_jb_conf global_jbconf
static

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

struct misdn_cfg_spec port_spec[]
static

Definition at line 102 of file misdn_config.c.

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

Definition at line 99 of file misdn_config.c.

int* ptp
static

Definition at line 432 of file misdn_config.c.

Referenced by misdn_lib_init(), and stack_init().