Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Data Structures | Macros | Enumerations | Functions | Variables
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, MISDN_CTYPE_ASTNAMEDGROUP
}
 

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 const 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 const 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

◆ CLI_ERROR

#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:274
int value
Definition: syslog.c:37
static const char name[]
Definition: cdr_mysql.c:74

Definition at line 442 of file misdn_config.c.

Referenced by _build_general_config(), and _build_port_config().

◆ GEN_CFG

#define GEN_CFG   1

Definition at line 47 of file misdn_config.c.

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

◆ NO_DEFAULT

#define NO_DEFAULT   "<>"

Definition at line 44 of file misdn_config.c.

Referenced by _fill_defaults(), and misdn_cfg_get_desc().

◆ NONE

#define NONE   0

◆ NUM_GEN_ELEMENTS

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

◆ NUM_PORT_ELEMENTS

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

◆ PORT_CFG

#define PORT_CFG   2

Definition at line 48 of file misdn_config.c.

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

Enumeration Type Documentation

◆ misdn_cfg_type

Enumerator
MISDN_CTYPE_STR 
MISDN_CTYPE_INT 
MISDN_CTYPE_BOOL 
MISDN_CTYPE_BOOLINT 
MISDN_CTYPE_MSNLIST 
MISDN_CTYPE_ASTGROUP 
MISDN_CTYPE_ASTNAMEDGROUP 

Definition at line 65 of file misdn_config.c.

Function Documentation

◆ _build_general_config()

static void _build_general_config ( struct ast_variable v)
static

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

1033 {
1034  int pos;
1035 
1036  for (; v; v = v->next) {
1037  if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
1038  continue;
1039  if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) ||
1040  (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
1041  CLI_ERROR(v->name, v->value, "general");
1042  }
1043 }
struct ast_variable * next
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:952
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
Definition: abstract_jb.c:545
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:63
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:484
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
enum misdn_cfg_type type
Definition: misdn_config.c:92
#define GEN_CFG
Definition: misdn_config.c:47
#define CLI_ERROR(name, value, section)
Definition: misdn_config.c:442

◆ _build_port_config()

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

Definition at line 1045 of file misdn_config.c.

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

Referenced by misdn_cfg_init().

1046 {
1047  int pos, i;
1048  union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
1049  int cfg_for_ports[max_ports + 1];
1050 
1051  if (!v || !cat)
1052  return;
1053 
1054  memset(cfg_tmp, 0, sizeof(cfg_tmp));
1055  memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
1056 
1057  if (!strcasecmp(cat, "default")) {
1058  cfg_for_ports[0] = 1;
1059  }
1060 
1061  if (((pos = get_cfg_position("name", PORT_CFG)) < 0) ||
1062  (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
1063  CLI_ERROR(v->name, v->value, cat);
1064  return;
1065  }
1066 
1067  for (; v; v = v->next) {
1068  if (!strcasecmp(v->name, "ports")) {
1069  char *token, *tmp = ast_strdupa(v->value);
1070  char ptpbuf[BUFFERSIZE] = "";
1071  int start, end;
1072  for (token = strsep(&tmp, ","); token; token = strsep(&tmp, ","), *ptpbuf = 0) {
1073  if (!*token)
1074  continue;
1075  if (sscanf(token, "%30d-%30d%511s", &start, &end, ptpbuf) >= 2) {
1076  for (; start <= end; start++) {
1077  if (start <= max_ports && start > 0) {
1078  cfg_for_ports[start] = 1;
1079  ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
1080  } else
1081  CLI_ERROR(v->name, v->value, cat);
1082  }
1083  } else {
1084  if (sscanf(token, "%30d%511s", &start, ptpbuf)) {
1085  if (start <= max_ports && start > 0) {
1086  cfg_for_ports[start] = 1;
1087  ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
1088  } else
1089  CLI_ERROR(v->name, v->value, cat);
1090  } else
1091  CLI_ERROR(v->name, v->value, cat);
1092  }
1093  }
1094  } else {
1095  if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) ||
1096  (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
1097  CLI_ERROR(v->name, v->value, cat);
1098  }
1099  }
1100 
1101  for (i = 0; i < (max_ports + 1); ++i) {
1102  if (i > 0 && cfg_for_ports[0]) {
1103  /* default category, will populate the port_cfg with additional port
1104  categories in subsequent calls to this function */
1105  memset(cfg_tmp, 0, sizeof(cfg_tmp));
1106  }
1107  if (cfg_for_ports[i]) {
1108  memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
1109  }
1110  }
1111 }
struct ast_variable * next
static const char type[]
Definition: chan_ooh323.c:109
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:952
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
#define PORT_CFG
Definition: misdn_config.c:48
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
static int tmp()
Definition: bt_open.c:389
static int max_ports
Definition: misdn_config.c:432
char * end
Definition: eagi_proxy.c:73
#define BUFFERSIZE
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:484
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
char * strsep(char **str, const char *delims)
enum misdn_cfg_type type
Definition: misdn_config.c:92
static int * ptp
Definition: misdn_config.c:436
#define CLI_ERROR(name, value, section)
Definition: misdn_config.c:442

◆ _enum_array_map()

static int _enum_array_map ( void  )
static

Definition at line 447 of file misdn_config.c.

References ast_log, LOG_WARNING, map, 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().

448 {
449  int i, j, ok;
450 
451  for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
452  if (i == MISDN_CFG_PTP)
453  continue;
454  ok = 0;
455  for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
456  if (port_spec[j].elem == i) {
457  map[i] = j;
458  ok = 1;
459  break;
460  }
461  }
462  if (!ok) {
463  ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
464  return -1;
465  }
466  }
467  for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
468  ok = 0;
469  for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
470  if (gen_spec[j].elem == i) {
471  map[i] = j;
472  ok = 1;
473  break;
474  }
475  }
476  if (!ok) {
477  ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
478  return -1;
479  }
480  }
481  return 0;
482 }
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
static int * map
Definition: misdn_config.c:438
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:49
#define LOG_WARNING
Definition: logger.h:274
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
#define ast_log
Definition: astobj2.c:42
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102

◆ _fill_defaults()

static void _fill_defaults ( void  )
static

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

1169 {
1170  int i;
1171 
1172  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
1173  if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
1174  _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
1175  }
1176  for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
1177  if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
1178  _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
1179  }
1180 }
static const char type[]
Definition: chan_ooh323.c:109
static int _parse(union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
Definition: misdn_config.c:952
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:49
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
#define NO_DEFAULT
Definition: misdn_config.c:44

◆ _free_general_cfg()

static void _free_general_cfg ( void  )
static

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

561 {
562  int i;
563 
564  for (i = 0; i < NUM_GEN_ELEMENTS; i++)
565  if (general_cfg[i].any)
566  ast_free(general_cfg[i].any);
567 }
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:49
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
#define ast_free(a)
Definition: astmm.h:182

◆ _free_msn_list()

static void _free_msn_list ( struct msn_list iter)
static

Definition at line 515 of file misdn_config.c.

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

Referenced by _free_port_cfg().

516 {
517  if (iter->next)
518  _free_msn_list(iter->next);
519  if (iter->msn)
520  ast_free(iter->msn);
521  ast_free(iter);
522 }
struct msn_list * next
Definition: misdn_config.c:77
char * msn
Definition: misdn_config.c:76
static void _free_msn_list(struct msn_list *iter)
Definition: misdn_config.c:515
#define ast_free(a)
Definition: astmm.h:182

◆ _free_port_cfg()

static void _free_port_cfg ( void  )
static

Definition at line 524 of file misdn_config.c.

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

Referenced by misdn_cfg_destroy(), and misdn_cfg_init().

525 {
526  int i, j;
527  int gn = map[MISDN_CFG_GROUPNAME];
528  union misdn_cfg_pt* free_list[max_ports + 2];
529 
530  memset(free_list, 0, sizeof(free_list));
531  free_list[0] = port_cfg[0];
532  for (i = 1; i <= max_ports; ++i) {
533  if (port_cfg[i][gn].str) {
534  /* we always have a groupname in the non-default case, so this is fine */
535  for (j = 1; j <= max_ports; ++j) {
536  if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
537  break;
538  else if (!free_list[j]) {
539  free_list[j] = port_cfg[i];
540  break;
541  }
542  }
543  }
544  }
545  for (j = 0; free_list[j]; ++j) {
546  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
547  if (free_list[j][i].any) {
548  if (port_spec[i].type == MISDN_CTYPE_MSNLIST) {
549  _free_msn_list(free_list[j][i].ml);
550  } else if (port_spec[i].type == MISDN_CTYPE_ASTNAMEDGROUP) {
551  ast_unref_namedgroups(free_list[j][i].namgrp);
552  } else {
553  ast_free(free_list[j][i].any);
554  }
555  }
556  }
557  }
558 }
static const char type[]
Definition: chan_ooh323.c:109
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
static int * map
Definition: misdn_config.c:438
static int max_ports
Definition: misdn_config.c:432
const char * str
Definition: app_jack.c:147
struct ast_namedgroups * namgrp
Definition: misdn_config.c:85
static void _free_msn_list(struct msn_list *iter)
Definition: misdn_config.c:515
#define ast_free(a)
Definition: astmm.h:182
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
struct msn_list * ml
Definition: misdn_config.c:83
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition: channel.c:7671

◆ _parse()

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

Definition at line 952 of file misdn_config.c.

References ast_calloc, ast_free, ast_get_group(), ast_get_namedgroups(), ast_malloc, ast_strdupa, ast_true(), misdn_cfg_pt::grp, len(), MISDN_CTYPE_ASTGROUP, MISDN_CTYPE_ASTNAMEDGROUP, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_INT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_STR, misdn_cfg_pt::ml, msn_list::msn, misdn_cfg_pt::namgrp, msn_list::next, misdn_cfg_pt::num, misdn_cfg_pt::str, strsep(), and tmp().

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

953 {
954  int re = 0;
955  int len, tmp;
956  char *valtmp;
957  char *tmp2 = ast_strdupa(value);
958 
959  switch (type) {
960  case MISDN_CTYPE_STR:
961  if (dest->str) {
962  ast_free(dest->str);
963  }
964  if ((len = strlen(value))) {
965  dest->str = ast_malloc((len + 1) * sizeof(char));
966  strncpy(dest->str, value, len);
967  dest->str[len] = 0;
968  } else {
969  dest->str = ast_malloc(sizeof(char));
970  dest->str[0] = 0;
971  }
972  break;
973  case MISDN_CTYPE_INT:
974  {
975  int res;
976 
977  if (strchr(value,'x')) {
978  res = sscanf(value, "%30x", &tmp);
979  } else {
980  res = sscanf(value, "%30d", &tmp);
981  }
982  if (res) {
983  if (!dest->num) {
984  dest->num = ast_malloc(sizeof(int));
985  }
986  memcpy(dest->num, &tmp, sizeof(int));
987  } else
988  re = -1;
989  }
990  break;
991  case MISDN_CTYPE_BOOL:
992  if (!dest->num) {
993  dest->num = ast_malloc(sizeof(int));
994  }
995  *(dest->num) = (ast_true(value) ? 1 : 0);
996  break;
997  case MISDN_CTYPE_BOOLINT:
998  if (!dest->num) {
999  dest->num = ast_malloc(sizeof(int));
1000  }
1001  if (sscanf(value, "%30d", &tmp)) {
1002  memcpy(dest->num, &tmp, sizeof(int));
1003  } else {
1004  *(dest->num) = (ast_true(value) ? boolint_def : 0);
1005  }
1006  break;
1007  case MISDN_CTYPE_MSNLIST:
1008  for (valtmp = strsep(&tmp2, ","); valtmp; valtmp = strsep(&tmp2, ",")) {
1009  if ((len = strlen(valtmp))) {
1010  struct msn_list *ml = ast_malloc(sizeof(*ml));
1011  ml->msn = ast_calloc(len+1, sizeof(char));
1012  strncpy(ml->msn, valtmp, len);
1013  ml->next = dest->ml;
1014  dest->ml = ml;
1015  }
1016  }
1017  break;
1018  case MISDN_CTYPE_ASTGROUP:
1019  if (!dest->grp) {
1020  dest->grp = ast_malloc(sizeof(ast_group_t));
1021  }
1022  *(dest->grp) = ast_get_group(value);
1023  break;
1025  dest->namgrp = ast_get_namedgroups(value);
1026  break;
1027  }
1028 
1029  return re;
1030 }
unsigned long long ast_group_t
Definition: channel.h:214
static const char type[]
Definition: chan_ooh323.c:109
static int tmp()
Definition: bt_open.c:389
int value
Definition: syslog.c:37
struct msn_list * next
Definition: misdn_config.c:77
ast_group_t * grp
Definition: misdn_config.c:84
struct ast_namedgroups * namgrp
Definition: misdn_config.c:85
char * msn
Definition: misdn_config.c:76
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7557
struct ast_namedgroups * ast_get_namedgroups(const char *s)
Create an ast_namedgroups set with group names from comma separated string.
Definition: channel.c:7614
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1822
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
char * strsep(char **str, const char *delims)
struct msn_list * ml
Definition: misdn_config.c:83

◆ get_cfg_position()

static int get_cfg_position ( const char *  name,
int  type 
)
static

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

485 {
486  int i;
487 
488  switch (type) {
489  case PORT_CFG:
490  for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
491  if (!strcasecmp(name, port_spec[i].name))
492  return i;
493  }
494  break;
495  case GEN_CFG:
496  for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
497  if (!strcasecmp(name, gen_spec[i].name))
498  return i;
499  }
500  }
501 
502  return -1;
503 }
static const char type[]
Definition: chan_ooh323.c:109
#define PORT_CFG
Definition: misdn_config.c:48
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:49
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
static const char name[]
Definition: cdr_mysql.c:74
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
#define GEN_CFG
Definition: misdn_config.c:47

◆ misdn_cfg_destroy()

void misdn_cfg_destroy ( void  )

Definition at line 1187 of file misdn_config.c.

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

Referenced by unload_module().

1188 {
1189  misdn_cfg_lock();
1190 
1191  _free_port_cfg();
1193 
1194  ast_free(port_cfg);
1196  ast_free(ptp);
1197  ast_free(map);
1198 
1199  misdn_cfg_unlock();
1201 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
static void _free_port_cfg(void)
Definition: misdn_config.c:524
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
#define ast_free(a)
Definition: astmm.h:182
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static void _free_general_cfg(void)
Definition: misdn_config.c:560
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
#define ast_mutex_destroy(a)
Definition: lock.h:186
static ast_mutex_t config_mutex
Definition: misdn_config.c:440

◆ misdn_cfg_get()

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

Definition at line 569 of file misdn_config.c.

References ast_copy_string(), ast_log, LOG_WARNING, map, misdn_cfg_is_port_valid(), MISDN_CFG_LAST, misdn_cfg_lock(), MISDN_CFG_PTP, misdn_cfg_unlock(), MISDN_CTYPE_ASTNAMEDGROUP, MISDN_CTYPE_STR, misdn_cfg_pt::namgrp, NULL, ptp, S_OR, str, and type.

Referenced by add_in_calls(), add_out_calls(), cb_events(), debug_numtype(), dialtone_indicate(), load_module(), misdn_add_number_prefix(), misdn_call(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_get_connected_line(), misdn_request(), misdn_set_opt_exec(), misdn_write(), process_ast_dsp(), read_config(), reload(), reload_config(), update_config(), and update_ec_config().

570 {
571  int place;
572 
573  if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
574  memset(buf, 0, bufsize);
575  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
576  return;
577  }
578 
579  misdn_cfg_lock();
580  if (elem == MISDN_CFG_PTP) {
581  if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
582  memset(buf, 0, bufsize);
583  } else {
584  if ((place = map[elem]) < 0) {
585  memset(buf, 0, bufsize);
586  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
587  } else {
588  if (elem < MISDN_CFG_LAST) {
589  switch (port_spec[place].type) {
590  case MISDN_CTYPE_STR:
591  if (port_cfg[port][place].str) {
592  ast_copy_string(buf, port_cfg[port][place].str, bufsize);
593  } else if (port_cfg[0][place].str) {
594  ast_copy_string(buf, port_cfg[0][place].str, bufsize);
595  } else
596  memset(buf, 0, bufsize);
597  break;
599  if (bufsize >= sizeof(struct ast_namedgroups *)) {
600  if (port_cfg[port][place].namgrp) {
601  *(struct ast_namedgroups **)buf = port_cfg[port][place].namgrp;
602  } else if (port_cfg[0][place].namgrp) {
603  *(struct ast_namedgroups **)buf = port_cfg[0][place].namgrp;
604  } else {
605  *(struct ast_namedgroups **)buf = NULL;
606  }
607  }
608  break;
609  default:
610  if (port_cfg[port][place].any)
611  memcpy(buf, port_cfg[port][place].any, bufsize);
612  else if (port_cfg[0][place].any)
613  memcpy(buf, port_cfg[0][place].any, bufsize);
614  else
615  memset(buf, 0, bufsize);
616  }
617  } else {
618  switch (gen_spec[place].type) {
619  case MISDN_CTYPE_STR:
620  ast_copy_string(buf, S_OR(general_cfg[place].str, ""), bufsize);
621  break;
622  default:
623  if (general_cfg[place].any)
624  memcpy(buf, general_cfg[place].any, bufsize);
625  else
626  memset(buf, 0, bufsize);
627  }
628  }
629  }
630  }
632 }
static const char type[]
Definition: chan_ooh323.c:109
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int * map
Definition: misdn_config.c:438
#define LOG_WARNING
Definition: logger.h:274
const char * str
Definition: app_jack.c:147
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:737

◆ misdn_cfg_get_config_string()

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

Definition at line 805 of file misdn_config.c.

References ast_free, ast_log, ast_print_group(), ast_print_namedgroups(), ast_str_create, BUFFERSIZE, LOG_WARNING, map, 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_ASTNAMEDGROUP, 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, ptp, str, and type.

Referenced by handle_cli_misdn_show_config().

806 {
807  int place;
808  char tempbuf[BUFFERSIZE] = "";
809  struct msn_list *iter;
810 
811  if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
812  *buf = 0;
813  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
814  return;
815  }
816 
817  place = map[elem];
818 
819  misdn_cfg_lock();
820  if (elem == MISDN_CFG_PTP) {
821  snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
822  }
823  else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
824  switch (port_spec[place].type) {
825  case MISDN_CTYPE_INT:
826  case MISDN_CTYPE_BOOLINT:
827  if (port_cfg[port][place].num)
828  snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
829  else if (port_cfg[0][place].num)
830  snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
831  else
832  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
833  break;
834  case MISDN_CTYPE_BOOL:
835  if (port_cfg[port][place].num)
836  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
837  else if (port_cfg[0][place].num)
838  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
839  else
840  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
841  break;
843  if (port_cfg[port][place].grp)
844  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
845  ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
846  else if (port_cfg[0][place].grp)
847  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
848  ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
849  else
850  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
851  break;
853  if (port_cfg[port][place].namgrp) {
854  struct ast_str *tmp_str = ast_str_create(1024);
855  if (tmp_str) {
856  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
857  ast_print_namedgroups(&tmp_str, port_cfg[port][place].namgrp));
858  ast_free(tmp_str);
859  }
860  } else if (port_cfg[0][place].namgrp) {
861  struct ast_str *tmp_str = ast_str_create(1024);
862  if (tmp_str) {
863  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
864  ast_print_namedgroups(&tmp_str, port_cfg[0][place].namgrp));
865  ast_free(tmp_str);
866  }
867  } else {
868  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
869  }
870  break;
871  case MISDN_CTYPE_MSNLIST:
872  if (port_cfg[port][place].ml)
873  iter = port_cfg[port][place].ml;
874  else
875  iter = port_cfg[0][place].ml;
876  if (iter) {
877  for (; iter; iter = iter->next) {
878  strncat(tempbuf, iter->msn, sizeof(tempbuf) - strlen(tempbuf) - 1);
879  }
880  if (strlen(tempbuf) > 1) {
881  tempbuf[strlen(tempbuf)-2] = 0;
882  }
883  }
884  snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
885  break;
886  case MISDN_CTYPE_STR:
887  if ( port_cfg[port][place].str) {
888  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
889  } else if (port_cfg[0][place].str) {
890  snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
891  } else {
892  snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
893  }
894  break;
895  }
896  } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
897  switch (gen_spec[place].type) {
898  case MISDN_CTYPE_INT:
899  case MISDN_CTYPE_BOOLINT:
900  if (general_cfg[place].num)
901  snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
902  else
903  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
904  break;
905  case MISDN_CTYPE_BOOL:
906  if (general_cfg[place].num)
907  snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
908  else
909  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
910  break;
911  case MISDN_CTYPE_STR:
912  if ( general_cfg[place].str) {
913  snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
914  } else {
915  snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
916  }
917  break;
918  default:
919  snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
920  break;
921  }
922  } else {
923  *buf = 0;
924  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
925  }
927 }
static const char type[]
Definition: chan_ooh323.c:109
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int * map
Definition: misdn_config.c:438
#define LOG_WARNING
Definition: logger.h:274
const char * str
Definition: app_jack.c:147
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
struct msn_list * next
Definition: misdn_config.c:77
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call and pickup groups into buffer.
Definition: channel.c:7972
#define BUFFERSIZE
#define ast_log
Definition: astobj2.c:42
char * msn
Definition: misdn_config.c:76
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
struct msn_list * ml
Definition: misdn_config.c:83
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:737
char * ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups)
Print named call groups and named pickup groups.
Definition: channel.c:7997
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ misdn_cfg_get_desc()

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

Definition at line 681 of file misdn_config.c.

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

Referenced by show_config_description().

682 {
683  int place = map[elem];
684  struct misdn_cfg_spec *spec = NULL;
685 
686  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
687  if (elem == MISDN_CFG_GROUPNAME) {
689  if (buf_default && bufsize_default)
690  memset(buf_default, 0, 1);
691  return;
692  }
693 
694  if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
695  spec = (struct misdn_cfg_spec *)port_spec;
696  else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
697  spec = (struct misdn_cfg_spec *)gen_spec;
698 
699  if (!spec)
700  memset(buf, 0, 1);
701  else {
702  ast_copy_string(buf, spec[place].desc, bufsize);
703  if (buf_default && bufsize) {
704  if (!strcmp(spec[place].def, NO_DEFAULT))
705  memset(buf_default, 0, 1);
706  else
707  ast_copy_string(buf_default, spec[place].def, bufsize_default);
708  }
709  }
710 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int * map
Definition: misdn_config.c:438
static const char desc[]
Definition: cdr_mysql.c:73
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
#define NULL
Definition: resample.c:96
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
char def[BUFFERSIZE]
Definition: misdn_config.c:93
static const char ports_description[]
Definition: misdn_config.c:99
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define NO_DEFAULT
Definition: misdn_config.c:44

◆ misdn_cfg_get_elem()

enum misdn_cfg_elements misdn_cfg_get_elem ( const char *  name)

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

635 {
636  int pos;
637 
638  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
639  if (!strcmp(name, "ports"))
640  return MISDN_CFG_GROUPNAME;
641  if (!strcmp(name, "name"))
642  return MISDN_CFG_FIRST;
643 
645  if (pos >= 0)
646  return port_spec[pos].elem;
647 
648  pos = get_cfg_position(name, GEN_CFG);
649  if (pos >= 0)
650  return gen_spec[pos].elem;
651 
652  return MISDN_CFG_FIRST;
653 }
#define PORT_CFG
Definition: misdn_config.c:48
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
static int get_cfg_position(const char *name, int type)
Definition: misdn_config.c:484
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
static const char name[]
Definition: cdr_mysql.c:74
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
#define GEN_CFG
Definition: misdn_config.c:47

◆ misdn_cfg_get_name()

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

Definition at line 655 of file misdn_config.c.

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

Referenced by complete_show_config(), and show_config_description().

656 {
657  struct misdn_cfg_spec *spec = NULL;
658  int place = map[elem];
659 
660  /* the ptp hack */
661  if (elem == MISDN_CFG_PTP) {
662  memset(buf, 0, 1);
663  return;
664  }
665 
666  /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
667  if (elem == MISDN_CFG_GROUPNAME) {
668  if (!snprintf(buf, bufsize, "ports"))
669  memset(buf, 0, 1);
670  return;
671  }
672 
673  if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
674  spec = (struct misdn_cfg_spec *)port_spec;
675  else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
676  spec = (struct misdn_cfg_spec *)gen_spec;
677 
678  ast_copy_string(buf, spec ? spec[place].name : "", bufsize);
679 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int * map
Definition: misdn_config.c:438
static const struct misdn_cfg_spec gen_spec[]
Definition: misdn_config.c:391
#define NULL
Definition: resample.c:96
enum misdn_cfg_elements elem
Definition: misdn_config.c:91
static const char name[]
Definition: cdr_mysql.c:74
static const struct misdn_cfg_spec port_spec[]
Definition: misdn_config.c:102
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ misdn_cfg_get_next_port()

int misdn_cfg_get_next_port ( int  port)

Definition at line 929 of file misdn_config.c.

References map, 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().

930 {
931  int p = -1;
932  int gn = map[MISDN_CFG_GROUPNAME];
933 
934  misdn_cfg_lock();
935  for (port++; port <= max_ports; port++) {
936  if (port_cfg[port][gn].str) {
937  p = port;
938  break;
939  }
940  }
942 
943  return p;
944 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
static int max_ports
Definition: misdn_config.c:432
const char * str
Definition: app_jack.c:147
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505

◆ misdn_cfg_get_next_port_spin()

int misdn_cfg_get_next_port_spin ( int  port)

Definition at line 946 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

947 {
948  int p = misdn_cfg_get_next_port(port);
949  return (p > 0) ? p : misdn_cfg_get_next_port(0);
950 }
int misdn_cfg_get_next_port(int port)
Definition: misdn_config.c:929

◆ misdn_cfg_get_ports_string()

void misdn_cfg_get_ports_string ( char *  ports)

Generate a comma separated list of all active ports.

Definition at line 779 of file misdn_config.c.

References map, max_ports, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), misdn_cfg_unlock(), ptp, str, and tmp().

Referenced by load_module().

780 {
781  char tmp[16];
782  int l, i;
783  int gn = map[MISDN_CFG_GROUPNAME];
784 
785  *ports = 0;
786 
787  misdn_cfg_lock();
788  for (i = 1; i <= max_ports; i++) {
789  if (port_cfg[i][gn].str) {
790  if (ptp[i])
791  sprintf(tmp, "%dptp,", i);
792  else
793  sprintf(tmp, "%d,", i);
794  strcat(ports, tmp);
795  }
796  }
798 
799  if ((l = strlen(ports))) {
800  /* Strip trailing ',' */
801  ports[l-1] = 0;
802  }
803 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
static int tmp()
Definition: bt_open.c:389
static int max_ports
Definition: misdn_config.c:432
const char * str
Definition: app_jack.c:147
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505

◆ misdn_cfg_init()

int misdn_cfg_init ( int  this_max_ports,
int  reload 
)

Definition at line 1203 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, map, max_ports, misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_GEN_LAST, NULL, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, and ptp.

Referenced by load_module(), and misdn_cfg_reload().

1204 {
1205  char config[] = "misdn.conf";
1206  char *cat, *p;
1207  int i;
1208  struct ast_config *cfg;
1209  struct ast_variable *v;
1210  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
1211 
1212  if (!(cfg = ast_config_load2(config, "chan_misdn", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
1213  ast_log(LOG_WARNING, "missing or invalid file: misdn.conf\n");
1214  return -1;
1215  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
1216  return 0;
1217 
1219 
1220  /* Copy the default jb config over global_jbconf */
1221  memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
1222 
1223  misdn_cfg_lock();
1224 
1225  if (this_max_ports) {
1226  /* this is the first run */
1227  max_ports = this_max_ports;
1228  map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
1229  if (_enum_array_map())
1230  return -1;
1231  p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
1232  + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
1233  port_cfg = (union misdn_cfg_pt **)p;
1234  p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
1235  for (i = 0; i <= max_ports; ++i) {
1236  port_cfg[i] = (union misdn_cfg_pt *)p;
1237  p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
1238  }
1239  general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1240  ptp = ast_calloc(max_ports + 1, sizeof(int));
1241  }
1242  else {
1243  /* misdn reload */
1244  _free_port_cfg();
1246  memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
1247  memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1248  memset(ptp, 0, sizeof(int) * (max_ports + 1));
1249  }
1250 
1251  cat = ast_category_browse(cfg, NULL);
1252 
1253  while(cat) {
1254  v = ast_variable_browse(cfg, cat);
1255  if (!strcasecmp(cat, "general")) {
1257  } else {
1258  _build_port_config(v, cat);
1259  }
1260  cat = ast_category_browse(cfg, cat);
1261  }
1262 
1263  _fill_defaults();
1264 
1265  misdn_cfg_unlock();
1266  ast_config_destroy(cfg);
1267 
1268  return 0;
1269 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static void _fill_defaults(void)
char * config
Definition: conf2ael.c:66
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
#define NUM_PORT_ELEMENTS
Definition: misdn_config.c:50
static int * map
Definition: misdn_config.c:438
#define NUM_GEN_ELEMENTS
Definition: misdn_config.c:49
#define LOG_WARNING
Definition: logger.h:274
static struct ast_jb_conf default_jbconf
Definition: misdn_config.c:54
#define CONFIG_STATUS_FILEINVALID
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
Structure for variables, used for configurations and for channel variables.
static int max_ports
Definition: misdn_config.c:432
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
#define NULL
Definition: resample.c:96
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:63
static void _build_port_config(struct ast_variable *v, char *cat)
static void _free_port_cfg(void)
Definition: misdn_config.c:524
#define ast_log
Definition: astobj2.c:42
static int _enum_array_map(void)
Definition: misdn_config.c:447
static union misdn_cfg_pt * general_cfg
Definition: misdn_config.c:434
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define CONFIG_STATUS_FILEUNCHANGED
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static int reload(void)
Definition: cdr_mysql.c:741
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
Structure used to handle boolean flags.
Definition: utils.h:199
static void _free_general_cfg(void)
Definition: misdn_config.c:560
static void _build_general_config(struct ast_variable *v)
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
#define ast_mutex_init(pmutex)
Definition: lock.h:184
static ast_mutex_t config_mutex
Definition: misdn_config.c:440
General jitterbuffer configuration.
Definition: abstract_jb.h:69

◆ misdn_cfg_is_group_method()

int misdn_cfg_is_group_method ( char *  group,
enum misdn_cfg_method  meth 
)

Definition at line 744 of file misdn_config.c.

References map, max_ports, method, 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().

745 {
746  int i, re = 0;
747  char *method ;
748 
749  misdn_cfg_lock();
750 
751  method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
752 
753  for (i = 1; i <= max_ports; i++) {
754  if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
755  if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
756  method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ?
758  }
759  }
760 
761  if (method) {
762  switch (meth) {
763  case METHOD_STANDARD: re = !strcasecmp(method, "standard");
764  break;
765  case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin");
766  break;
767  case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec");
768  break;
769  }
770  }
772 
773  return re;
774 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
static int max_ports
Definition: misdn_config.c:432
const char * str
Definition: app_jack.c:147
const char * method
Definition: res_pjsip.c:4180
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505

◆ misdn_cfg_is_msn_valid()

int misdn_cfg_is_msn_valid ( int  port,
char *  msn 
)

Definition at line 712 of file misdn_config.c.

References ast_extension_match(), ast_log, LOG_WARNING, map, 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().

713 {
714  int re = 0;
715  struct msn_list *iter;
716 
717  if (!misdn_cfg_is_port_valid(port)) {
718  ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
719  return 0;
720  }
721 
722  misdn_cfg_lock();
723  if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
724  iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
725  else
726  iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
727  for (; iter; iter = iter->next)
728  if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
729  re = 1;
730  break;
731  }
733 
734  return re;
735 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
#define LOG_WARNING
Definition: logger.h:274
struct msn_list * next
Definition: misdn_config.c:77
#define ast_log
Definition: astobj2.c:42
char * msn
Definition: misdn_config.c:76
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: extconf.c:4297
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
struct msn_list * ml
Definition: misdn_config.c:83
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:737

◆ misdn_cfg_is_port_valid()

int misdn_cfg_is_port_valid ( int  port)

Definition at line 737 of file misdn_config.c.

References map, max_ports, 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().

738 {
739  int gn = map[MISDN_CFG_GROUPNAME];
740 
741  return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
742 }
static union misdn_cfg_pt ** port_cfg
Definition: misdn_config.c:430
static int * map
Definition: misdn_config.c:438
static int max_ports
Definition: misdn_config.c:432
const char * str
Definition: app_jack.c:147

◆ misdn_cfg_lock()

static void misdn_cfg_lock ( void  )
inlinestatic

◆ misdn_cfg_reload()

void misdn_cfg_reload ( void  )

Definition at line 1182 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

1183 {
1184  misdn_cfg_init(0, 1);
1185 }
int misdn_cfg_init(int this_max_ports, int reload)

◆ misdn_cfg_unlock()

static void misdn_cfg_unlock ( void  )
inlinestatic

◆ misdn_cfg_update_ptp()

void misdn_cfg_update_ptp ( void  )

Definition at line 1113 of file misdn_config.c.

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

Referenced by load_module(), and reload_config().

1114 {
1115 #ifndef MISDN_1_2
1116  char misdn_init[BUFFERSIZE];
1117  char line[BUFFERSIZE];
1118  FILE *fp;
1119  char *tok, *p, *end;
1120  int port;
1121 
1122  misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
1123 
1124  if (!ast_strlen_zero(misdn_init)) {
1125  fp = fopen(misdn_init, "r");
1126  if (fp) {
1127  while(fgets(line, sizeof(line), fp)) {
1128  if (!strncmp(line, "nt_ptp", 6)) {
1129  for (tok = strtok_r(line,",=", &p);
1130  tok;
1131  tok = strtok_r(NULL,",=", &p)) {
1132  port = strtol(tok, &end, 10);
1133  if (end != tok && misdn_cfg_is_port_valid(port)) {
1134  misdn_cfg_lock();
1135  ptp[port] = 1;
1136  misdn_cfg_unlock();
1137  }
1138  }
1139  }
1140  }
1141  fclose(fp);
1142  } else {
1143  ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
1144  }
1145  }
1146 #else
1147  int i;
1148  int proto;
1149  char filename[128];
1150  FILE *fp;
1151 
1152  for (i = 1; i <= max_ports; ++i) {
1153  snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
1154  fp = fopen(filename, "r");
1155  if (!fp) {
1156  ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
1157  continue;
1158  }
1159  if (fscanf(fp, "0x%08x", &proto) != 1)
1160  ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
1161  else
1162  ptp[i] = proto & 1<<5 ? 1 : 0;
1163  fclose(fp);
1164  }
1165 #endif
1166 }
#define LOG_WARNING
Definition: logger.h:274
static int max_ports
Definition: misdn_config.c:432
#define NULL
Definition: resample.c:96
char * end
Definition: eagi_proxy.c:73
#define BUFFERSIZE
#define ast_log
Definition: astobj2.c:42
int errno
#define ast_strlen_zero(a)
Definition: muted.c:73
static void misdn_cfg_unlock(void)
Definition: misdn_config.c:510
void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
Definition: misdn_config.c:569
static int * ptp
Definition: misdn_config.c:436
static void misdn_cfg_lock(void)
Definition: misdn_config.c:505
int misdn_cfg_is_port_valid(int port)
Definition: misdn_config.c:737

◆ misdn_get_global_jbconf()

struct ast_jb_conf* misdn_get_global_jbconf ( void  )

Definition at line 1271 of file misdn_config.c.

References global_jbconf.

Referenced by misdn_new().

1271  {
1272  return &global_jbconf;
1273 }
static struct ast_jb_conf global_jbconf
Definition: misdn_config.c:63

Variable Documentation

◆ config_mutex

ast_mutex_t config_mutex
static

Definition at line 440 of file misdn_config.c.

◆ default_jbconf

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

◆ gen_spec

const struct misdn_cfg_spec gen_spec[]
static

Definition at line 391 of file misdn_config.c.

◆ general_cfg

union misdn_cfg_pt* general_cfg
static

Definition at line 434 of file misdn_config.c.

◆ global_jbconf

struct ast_jb_conf global_jbconf
static

Definition at line 63 of file misdn_config.c.

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

◆ map

int* map
static

◆ max_ports

int max_ports
static

◆ port_cfg

union misdn_cfg_pt** port_cfg
static

Definition at line 430 of file misdn_config.c.

◆ port_spec

const struct misdn_cfg_spec port_spec[]
static

Definition at line 102 of file misdn_config.c.

◆ ports_description

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.

Referenced by misdn_cfg_get_desc().

◆ ptp

int* ptp
static