#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "chan_misdn_config.h"
#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/lock.h"
#include "asterisk/pbx.h"
#include "asterisk/strings.h"
#include "asterisk/utils.h"
Include dependency graph for misdn_config.c:
Go to the source code of this file.
Data Structures | |
union | misdn_cfg_pt |
struct | misdn_cfg_spec |
struct | msn_list |
Defines | |
#define | AST_DESTROY_CFG ast_config_destroy |
#define | AST_LOAD_CFG ast_config_load |
#define | CLI_ERROR(name, value, section) |
#define | GEN_CFG 1 |
#define | NO_DEFAULT "<>" |
#define | NONE 0 |
#define | NUM_GEN_ELEMENTS (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec)) |
#define | NUM_PORT_ELEMENTS (sizeof(port_spec) / sizeof(struct misdn_cfg_spec)) |
#define | PORT_CFG 2 |
Enumerations | |
enum | misdn_cfg_type { MISDN_CTYPE_STR, MISDN_CTYPE_INT, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_ASTGROUP } |
Functions | |
static void | _build_general_config (struct ast_variable *v) |
static void | _build_port_config (struct ast_variable *v, char *cat) |
static int | _enum_array_map (void) |
static void | _fill_defaults (void) |
static void | _free_general_cfg (void) |
static void | _free_msn_list (struct msn_list *iter) |
static void | _free_port_cfg (void) |
static int | _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def) |
static int | get_cfg_position (char *name, int type) |
void | misdn_cfg_destroy (void) |
void | misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize) |
void | misdn_cfg_get_config_string (int port, enum misdn_cfg_elements elem, char *buf, int bufsize) |
void | misdn_cfg_get_desc (enum misdn_cfg_elements elem, void *buf, int bufsize, void *buf_default, int bufsize_default) |
enum misdn_cfg_elements | misdn_cfg_get_elem (char *name) |
void | misdn_cfg_get_name (enum misdn_cfg_elements elem, void *buf, int bufsize) |
int | misdn_cfg_get_next_port (int port) |
int | misdn_cfg_get_next_port_spin (int port) |
void | misdn_cfg_get_ports_string (char *ports) |
int | misdn_cfg_init (int this_max_ports) |
int | misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth) |
int | misdn_cfg_is_msn_valid (int port, char *msn) |
int | misdn_cfg_is_port_valid (int port) |
static void | misdn_cfg_lock (void) |
void | misdn_cfg_reload (void) |
static void | misdn_cfg_unlock (void) |
void | misdn_cfg_update_ptp (void) |
Variables | |
static ast_mutex_t | config_mutex |
static struct misdn_cfg_spec | gen_spec [] |
static union misdn_cfg_pt * | general_cfg |
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 |
Definition in file misdn_config.c.
#define AST_DESTROY_CFG ast_config_destroy |
#define AST_LOAD_CFG ast_config_load |
#define CLI_ERROR | ( | name, | |||
value, | |||||
section | ) |
Value:
({ \ ast_log(LOG_WARNING, "misdn.conf: \"%s=%s\" (section: %s) invalid or out of range. " \ "Please edit your misdn.conf and then do a \"misdn reload\".\n", name, value, section); \ })
Definition at line 370 of file misdn_config.c.
Referenced by _build_general_config(), and _build_port_config().
#define GEN_CFG 1 |
Definition at line 54 of file misdn_config.c.
Referenced by _build_general_config(), get_cfg_position(), and misdn_cfg_get_elem().
#define NO_DEFAULT "<>" |
Definition at line 51 of file misdn_config.c.
Referenced by _fill_defaults(), and misdn_cfg_get_desc().
#define NONE 0 |
Definition at line 52 of file misdn_config.c.
#define NUM_GEN_ELEMENTS (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec)) |
Definition at line 56 of file misdn_config.c.
Referenced by _enum_array_map(), _fill_defaults(), _free_general_cfg(), get_cfg_position(), and misdn_cfg_init().
#define NUM_PORT_ELEMENTS (sizeof(port_spec) / sizeof(struct misdn_cfg_spec)) |
Definition at line 57 of file misdn_config.c.
Referenced by _build_port_config(), _enum_array_map(), _fill_defaults(), _free_port_cfg(), get_cfg_position(), and misdn_cfg_init().
#define PORT_CFG 2 |
Definition at line 55 of file misdn_config.c.
Referenced by _build_port_config(), get_cfg_position(), and misdn_cfg_get_elem().
enum misdn_cfg_type |
MISDN_CTYPE_STR | |
MISDN_CTYPE_INT | |
MISDN_CTYPE_BOOL | |
MISDN_CTYPE_BOOLINT | |
MISDN_CTYPE_MSNLIST | |
MISDN_CTYPE_ASTGROUP |
Definition at line 59 of file misdn_config.c.
00059 { 00060 MISDN_CTYPE_STR, 00061 MISDN_CTYPE_INT, 00062 MISDN_CTYPE_BOOL, 00063 MISDN_CTYPE_BOOLINT, 00064 MISDN_CTYPE_MSNLIST, 00065 MISDN_CTYPE_ASTGROUP 00066 };
static void _build_general_config | ( | struct ast_variable * | v | ) | [static] |
Definition at line 907 of file misdn_config.c.
References _parse(), misdn_cfg_spec::boolint_def, CLI_ERROR, GEN_CFG, gen_spec, general_cfg, get_cfg_position(), ast_variable::name, ast_variable::next, misdn_cfg_spec::type, and ast_variable::value.
Referenced by misdn_cfg_init().
00908 { 00909 int pos; 00910 00911 for (; v; v = v->next) { 00912 if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 00913 (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0)) 00914 CLI_ERROR(v->name, v->value, "general"); 00915 } 00916 }
static void _build_port_config | ( | struct ast_variable * | v, | |
char * | cat | |||
) | [static] |
Definition at line 918 of file misdn_config.c.
References _parse(), BUFFERSIZE, CLI_ERROR, get_cfg_position(), max_ports, ast_variable::name, ast_variable::next, NUM_PORT_ELEMENTS, PORT_CFG, port_spec, ptp, strsep(), type, and ast_variable::value.
Referenced by misdn_cfg_init().
00919 { 00920 int pos, i; 00921 union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS]; 00922 int cfg_for_ports[max_ports + 1]; 00923 00924 if (!v || !cat) 00925 return; 00926 00927 memset(cfg_tmp, 0, sizeof(cfg_tmp)); 00928 memset(cfg_for_ports, 0, sizeof(cfg_for_ports)); 00929 00930 if (!strcasecmp(cat, "default")) { 00931 cfg_for_ports[0] = 1; 00932 } 00933 00934 if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 00935 (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) { 00936 CLI_ERROR(v->name, v->value, cat); 00937 return; 00938 } 00939 00940 for (; v; v = v->next) { 00941 if (!strcasecmp(v->name, "ports")) { 00942 char *token; 00943 char ptpbuf[BUFFERSIZE] = ""; 00944 int start, end; 00945 for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 00946 if (!*token) 00947 continue; 00948 if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) { 00949 for (; start <= end; start++) { 00950 if (start <= max_ports && start > 0) { 00951 cfg_for_ports[start] = 1; 00952 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00953 } else 00954 CLI_ERROR(v->name, v->value, cat); 00955 } 00956 } else { 00957 if (sscanf(token, "%d%s", &start, ptpbuf)) { 00958 if (start <= max_ports && start > 0) { 00959 cfg_for_ports[start] = 1; 00960 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00961 } else 00962 CLI_ERROR(v->name, v->value, cat); 00963 } else 00964 CLI_ERROR(v->name, v->value, cat); 00965 } 00966 } 00967 } else { 00968 if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 00969 (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) 00970 CLI_ERROR(v->name, v->value, cat); 00971 } 00972 } 00973 00974 for (i = 0; i < (max_ports + 1); ++i) { 00975 if (cfg_for_ports[i]) { 00976 memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp)); 00977 } 00978 } 00979 }
static int _enum_array_map | ( | void | ) | [static] |
Definition at line 375 of file misdn_config.c.
References ast_log(), gen_spec, LOG_WARNING, MISDN_CFG_FIRST, MISDN_CFG_LAST, MISDN_CFG_PTP, MISDN_GEN_FIRST, MISDN_GEN_LAST, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, and port_spec.
Referenced by misdn_cfg_init().
00376 { 00377 int i, j, ok; 00378 00379 for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) { 00380 if (i == MISDN_CFG_PTP) 00381 continue; 00382 ok = 0; 00383 for (j = 0; j < NUM_PORT_ELEMENTS; ++j) { 00384 if (port_spec[j].elem == i) { 00385 map[i] = j; 00386 ok = 1; 00387 break; 00388 } 00389 } 00390 if (!ok) { 00391 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i); 00392 return -1; 00393 } 00394 } 00395 for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) { 00396 ok = 0; 00397 for (j = 0; j < NUM_GEN_ELEMENTS; ++j) { 00398 if (gen_spec[j].elem == i) { 00399 map[i] = j; 00400 ok = 1; 00401 break; 00402 } 00403 } 00404 if (!ok) { 00405 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i); 00406 return -1; 00407 } 00408 } 00409 return 0; 00410 }
static void _fill_defaults | ( | void | ) | [static] |
Definition at line 1036 of file misdn_config.c.
References _parse(), misdn_cfg_pt::any, gen_spec, general_cfg, NO_DEFAULT, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, port_cfg, port_spec, and type.
Referenced by misdn_cfg_init().
01037 { 01038 int i; 01039 01040 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 01041 if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT)) 01042 _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def); 01043 } 01044 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 01045 if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT)) 01046 _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def); 01047 } 01048 }
static void _free_general_cfg | ( | void | ) | [static] |
Definition at line 485 of file misdn_config.c.
References misdn_cfg_pt::any, free, general_cfg, and NUM_GEN_ELEMENTS.
Referenced by misdn_cfg_destroy(), and misdn_cfg_init().
00486 { 00487 int i; 00488 00489 for (i = 0; i < NUM_GEN_ELEMENTS; i++) 00490 if (general_cfg[i].any) 00491 free(general_cfg[i].any); 00492 }
static void _free_msn_list | ( | struct msn_list * | iter | ) | [static] |
Definition at line 443 of file misdn_config.c.
References free, msn_list::msn, and msn_list::next.
Referenced by _free_port_cfg().
00444 { 00445 if (iter->next) 00446 _free_msn_list(iter->next); 00447 if (iter->msn) 00448 free(iter->msn); 00449 free(iter); 00450 }
static void _free_port_cfg | ( | void | ) | [static] |
Definition at line 452 of file misdn_config.c.
References _free_msn_list(), misdn_cfg_pt::any, free, MISDN_CFG_GROUPNAME, MISDN_CTYPE_MSNLIST, misdn_cfg_pt::ml, NUM_PORT_ELEMENTS, port_cfg, port_spec, misdn_cfg_pt::str, and type.
Referenced by misdn_cfg_destroy(), and misdn_cfg_init().
00453 { 00454 int i, j; 00455 int gn = map[MISDN_CFG_GROUPNAME]; 00456 union misdn_cfg_pt* free_list[max_ports + 2]; 00457 00458 memset(free_list, 0, sizeof(free_list)); 00459 free_list[0] = port_cfg[0]; 00460 for (i = 1; i <= max_ports; ++i) { 00461 if (port_cfg[i][gn].str) { 00462 /* we always have a groupname in the non-default case, so this is fine */ 00463 for (j = 1; j <= max_ports; ++j) { 00464 if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str) 00465 break; 00466 else if (!free_list[j]) { 00467 free_list[j] = port_cfg[i]; 00468 break; 00469 } 00470 } 00471 } 00472 } 00473 for (j = 0; free_list[j]; ++j) { 00474 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00475 if (free_list[j][i].any) { 00476 if (port_spec[i].type == MISDN_CTYPE_MSNLIST) 00477 _free_msn_list(free_list[j][i].ml); 00478 else 00479 free(free_list[j][i].any); 00480 } 00481 } 00482 } 00483 }
static int _parse | ( | union misdn_cfg_pt * | dest, | |
char * | value, | |||
enum misdn_cfg_type | type, | |||
int | boolint_def | |||
) | [static] |
Definition at line 844 of file misdn_config.c.
References ast_get_group(), ast_true(), calloc, misdn_cfg_pt::grp, len, malloc, MISDN_CTYPE_ASTGROUP, MISDN_CTYPE_BOOL, MISDN_CTYPE_BOOLINT, MISDN_CTYPE_INT, MISDN_CTYPE_MSNLIST, MISDN_CTYPE_STR, misdn_cfg_pt::ml, msn_list::msn, msn_list::next, misdn_cfg_pt::num, misdn_cfg_pt::str, and strsep().
Referenced by _build_general_config(), _build_port_config(), and _fill_defaults().
00845 { 00846 int re = 0; 00847 int len, tmp; 00848 char *valtmp; 00849 00850 switch (type) { 00851 case MISDN_CTYPE_STR: 00852 if ((len = strlen(value))) { 00853 dest->str = (char *)malloc((len + 1) * sizeof(char)); 00854 strncpy(dest->str, value, len); 00855 dest->str[len] = 0; 00856 } else { 00857 dest->str = (char *)malloc( sizeof(char)); 00858 dest->str[0] = 0; 00859 } 00860 break; 00861 case MISDN_CTYPE_INT: 00862 { 00863 char *pat; 00864 if (strchr(value,'x')) 00865 pat="%x"; 00866 else 00867 pat="%d"; 00868 if (sscanf(value, pat, &tmp)) { 00869 dest->num = (int *)malloc(sizeof(int)); 00870 memcpy(dest->num, &tmp, sizeof(int)); 00871 } else 00872 re = -1; 00873 } 00874 break; 00875 case MISDN_CTYPE_BOOL: 00876 dest->num = (int *)malloc(sizeof(int)); 00877 *(dest->num) = (ast_true(value) ? 1 : 0); 00878 break; 00879 case MISDN_CTYPE_BOOLINT: 00880 dest->num = (int *)malloc(sizeof(int)); 00881 if (sscanf(value, "%d", &tmp)) { 00882 memcpy(dest->num, &tmp, sizeof(int)); 00883 } else { 00884 *(dest->num) = (ast_true(value) ? boolint_def : 0); 00885 } 00886 break; 00887 case MISDN_CTYPE_MSNLIST: 00888 for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) { 00889 if ((len = strlen(valtmp))) { 00890 struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list)); 00891 ml->msn = (char *)calloc(len+1, sizeof(char)); 00892 strncpy(ml->msn, valtmp, len); 00893 ml->next = dest->ml; 00894 dest->ml = ml; 00895 } 00896 } 00897 break; 00898 case MISDN_CTYPE_ASTGROUP: 00899 dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t)); 00900 *(dest->grp) = ast_get_group(value); 00901 break; 00902 } 00903 00904 return re; 00905 }
static int get_cfg_position | ( | char * | name, | |
int | type | |||
) | [static] |
Definition at line 412 of file misdn_config.c.
References GEN_CFG, gen_spec, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, PORT_CFG, and port_spec.
Referenced by _build_general_config(), _build_port_config(), and misdn_cfg_get_elem().
00413 { 00414 int i; 00415 00416 switch (type) { 00417 case PORT_CFG: 00418 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00419 if (!strcasecmp(name, port_spec[i].name)) 00420 return i; 00421 } 00422 break; 00423 case GEN_CFG: 00424 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 00425 if (!strcasecmp(name, gen_spec[i].name)) 00426 return i; 00427 } 00428 } 00429 00430 return -1; 00431 }
void misdn_cfg_destroy | ( | void | ) |
Definition at line 1055 of file misdn_config.c.
References _free_general_cfg(), _free_port_cfg(), ast_mutex_destroy(), config_mutex, free, general_cfg, map, misdn_cfg_lock(), misdn_cfg_unlock(), port_cfg, and ptp.
Referenced by unload_module().
01056 { 01057 misdn_cfg_lock(); 01058 01059 _free_port_cfg(); 01060 _free_general_cfg(); 01061 01062 free(port_cfg); 01063 free(general_cfg); 01064 free(ptp); 01065 free(map); 01066 01067 misdn_cfg_unlock(); 01068 ast_mutex_destroy(&config_mutex); 01069 }
void misdn_cfg_get | ( | int | port, | |
enum misdn_cfg_elements | elem, | |||
void * | buf, | |||
int | bufsize | |||
) |
Definition at line 494 of file misdn_config.c.
References misdn_cfg_pt::any, ast_log(), gen_spec, general_cfg, LOG_WARNING, misdn_cfg_is_port_valid(), MISDN_CFG_LAST, misdn_cfg_lock(), MISDN_CFG_PTP, misdn_cfg_unlock(), MISDN_CTYPE_STR, port_cfg, port_spec, misdn_cfg_pt::str, and type.
Referenced by add_in_calls(), add_out_calls(), cb_events(), dialtone_indicate(), load_module(), misdn_bridge(), misdn_call(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_new(), misdn_request(), misdn_set_opt_exec(), process_ast_dsp(), read_config(), reload_config(), update_config(), and update_ec_config().
00495 { 00496 int place; 00497 00498 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00499 memset(buf, 0, bufsize); 00500 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); 00501 return; 00502 } 00503 00504 misdn_cfg_lock(); 00505 if (elem == MISDN_CFG_PTP) { 00506 if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) 00507 memset(buf, 0, bufsize); 00508 } else { 00509 if ((place = map[elem]) < 0) { 00510 memset (buf, 0, bufsize); 00511 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); 00512 } else { 00513 if (elem < MISDN_CFG_LAST) { 00514 switch (port_spec[place].type) { 00515 case MISDN_CTYPE_STR: 00516 if (port_cfg[port][place].str) { 00517 if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize)) 00518 memset(buf, 0, 1); 00519 } else if (port_cfg[0][place].str) { 00520 if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize)) 00521 memset(buf, 0, 1); 00522 } 00523 break; 00524 default: 00525 if (port_cfg[port][place].any) 00526 memcpy(buf, port_cfg[port][place].any, bufsize); 00527 else if (port_cfg[0][place].any) 00528 memcpy(buf, port_cfg[0][place].any, bufsize); 00529 else 00530 memset(buf, 0, bufsize); 00531 } 00532 } else { 00533 switch (gen_spec[place].type) { 00534 case MISDN_CTYPE_STR: 00535 if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize)) 00536 memset(buf, 0, 1); 00537 break; 00538 default: 00539 if (general_cfg[place].any) 00540 memcpy(buf, general_cfg[place].any, bufsize); 00541 else 00542 memset(buf, 0, bufsize); 00543 } 00544 } 00545 } 00546 } 00547 misdn_cfg_unlock(); 00548 }
void misdn_cfg_get_config_string | ( | int | port, | |
enum misdn_cfg_elements | elem, | |||
char * | buf, | |||
int | bufsize | |||
) |
Definition at line 719 of file misdn_config.c.
References ast_log(), ast_print_group(), BUFFERSIZE, gen_spec, general_cfg, 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_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, port_cfg, port_spec, ptp, and type.
Referenced by misdn_show_config().
00720 { 00721 int place; 00722 char tempbuf[BUFFERSIZE] = ""; 00723 struct msn_list *iter; 00724 00725 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00726 *buf = 0; 00727 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port); 00728 return; 00729 } 00730 00731 place = map[elem]; 00732 00733 misdn_cfg_lock(); 00734 if (elem == MISDN_CFG_PTP) { 00735 snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no"); 00736 } 00737 else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) { 00738 switch (port_spec[place].type) { 00739 case MISDN_CTYPE_INT: 00740 case MISDN_CTYPE_BOOLINT: 00741 if (port_cfg[port][place].num) 00742 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num); 00743 else if (port_cfg[0][place].num) 00744 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num); 00745 else 00746 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00747 break; 00748 case MISDN_CTYPE_BOOL: 00749 if (port_cfg[port][place].num) 00750 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no"); 00751 else if (port_cfg[0][place].num) 00752 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no"); 00753 else 00754 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00755 break; 00756 case MISDN_CTYPE_ASTGROUP: 00757 if (port_cfg[port][place].grp) 00758 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00759 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp)); 00760 else if (port_cfg[0][place].grp) 00761 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00762 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp)); 00763 else 00764 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00765 break; 00766 case MISDN_CTYPE_MSNLIST: 00767 if (port_cfg[port][place].ml) 00768 iter = port_cfg[port][place].ml; 00769 else 00770 iter = port_cfg[0][place].ml; 00771 if (iter) { 00772 for (; iter; iter = iter->next) 00773 sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn); 00774 tempbuf[strlen(tempbuf)-2] = 0; 00775 } 00776 snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none"); 00777 break; 00778 case MISDN_CTYPE_STR: 00779 if ( port_cfg[port][place].str) { 00780 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str); 00781 } else if (port_cfg[0][place].str) { 00782 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str); 00783 } else { 00784 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00785 } 00786 break; 00787 } 00788 } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) { 00789 switch (gen_spec[place].type) { 00790 case MISDN_CTYPE_INT: 00791 case MISDN_CTYPE_BOOLINT: 00792 if (general_cfg[place].num) 00793 snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num); 00794 else 00795 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00796 break; 00797 case MISDN_CTYPE_BOOL: 00798 if (general_cfg[place].num) 00799 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no"); 00800 else 00801 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00802 break; 00803 case MISDN_CTYPE_STR: 00804 if ( general_cfg[place].str) { 00805 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str); 00806 } else { 00807 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00808 } 00809 break; 00810 default: 00811 snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name); 00812 break; 00813 } 00814 } else { 00815 *buf = 0; 00816 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem); 00817 } 00818 misdn_cfg_unlock(); 00819 }
void misdn_cfg_get_desc | ( | enum misdn_cfg_elements | elem, | |
void * | buf, | |||
int | bufsize, | |||
void * | buf_default, | |||
int | bufsize_default | |||
) |
Definition at line 598 of file misdn_config.c.
References misdn_cfg_spec::def, desc, gen_spec, MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, MISDN_CFG_LAST, MISDN_GEN_FIRST, MISDN_GEN_LAST, NO_DEFAULT, and port_spec.
Referenced by show_config_description().
00599 { 00600 int place = map[elem]; 00601 struct misdn_cfg_spec *spec = NULL; 00602 00603 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00604 if (elem == MISDN_CFG_GROUPNAME) { 00605 if (!memccpy(buf, ports_description, 0, bufsize)) 00606 memset(buf, 0, 1); 00607 if (buf_default && bufsize_default) 00608 memset(buf_default, 0, 1); 00609 return; 00610 } 00611 00612 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) 00613 spec = (struct misdn_cfg_spec *)port_spec; 00614 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) 00615 spec = (struct misdn_cfg_spec *)gen_spec; 00616 00617 if (!spec || !spec[place].desc) 00618 memset(buf, 0, 1); 00619 else { 00620 if (!memccpy(buf, spec[place].desc, 0, bufsize)) 00621 memset(buf, 0, 1); 00622 if (buf_default && bufsize) { 00623 if (!strcmp(spec[place].def, NO_DEFAULT)) 00624 memset(buf_default, 0, 1); 00625 else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default)) 00626 memset(buf_default, 0, 1); 00627 } 00628 } 00629 }
enum misdn_cfg_elements misdn_cfg_get_elem | ( | char * | name | ) |
Definition at line 550 of file misdn_config.c.
References misdn_cfg_spec::elem, GEN_CFG, gen_spec, get_cfg_position(), MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, PORT_CFG, and port_spec.
Referenced by misdn_show_config().
00551 { 00552 int pos; 00553 00554 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00555 if (!strcmp(name, "ports")) 00556 return MISDN_CFG_GROUPNAME; 00557 if (!strcmp(name, "name")) 00558 return MISDN_CFG_FIRST; 00559 00560 pos = get_cfg_position (name, PORT_CFG); 00561 if (pos >= 0) 00562 return port_spec[pos].elem; 00563 00564 pos = get_cfg_position (name, GEN_CFG); 00565 if (pos >= 0) 00566 return gen_spec[pos].elem; 00567 00568 return MISDN_CFG_FIRST; 00569 }
void misdn_cfg_get_name | ( | enum misdn_cfg_elements | elem, | |
void * | buf, | |||
int | bufsize | |||
) |
Definition at line 571 of file misdn_config.c.
References gen_spec, MISDN_CFG_FIRST, MISDN_CFG_GROUPNAME, MISDN_CFG_LAST, MISDN_CFG_PTP, MISDN_GEN_FIRST, MISDN_GEN_LAST, name, and port_spec.
Referenced by complete_show_config(), and show_config_description().
00572 { 00573 struct misdn_cfg_spec *spec = NULL; 00574 int place = map[elem]; 00575 00576 /* the ptp hack */ 00577 if (elem == MISDN_CFG_PTP) { 00578 memset(buf, 0, 1); 00579 return; 00580 } 00581 00582 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00583 if (elem == MISDN_CFG_GROUPNAME) { 00584 if (!snprintf(buf, bufsize, "ports")) 00585 memset(buf, 0, 1); 00586 return; 00587 } 00588 00589 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) 00590 spec = (struct misdn_cfg_spec *)port_spec; 00591 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) 00592 spec = (struct misdn_cfg_spec *)gen_spec; 00593 00594 if (!spec || !memccpy(buf, spec[place].name, 0, bufsize)) 00595 memset(buf, 0, 1); 00596 }
int misdn_cfg_get_next_port | ( | int | port | ) |
Definition at line 821 of file misdn_config.c.
References map, max_ports, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), misdn_cfg_unlock(), and port_cfg.
Referenced by complete_show_config(), load_module(), misdn_cfg_get_next_port_spin(), misdn_check_l2l1(), misdn_new(), misdn_request(), misdn_show_config(), misdn_show_ports_stats(), misdn_show_stacks(), and update_name().
00822 { 00823 int p = -1; 00824 int gn = map[MISDN_CFG_GROUPNAME]; 00825 00826 misdn_cfg_lock(); 00827 for (port++; port <= max_ports; port++) { 00828 if (port_cfg[port][gn].str) { 00829 p = port; 00830 break; 00831 } 00832 } 00833 misdn_cfg_unlock(); 00834 00835 return p; 00836 }
int misdn_cfg_get_next_port_spin | ( | int | port | ) |
Definition at line 838 of file misdn_config.c.
References misdn_cfg_get_next_port().
Referenced by misdn_request().
00839 { 00840 int p = misdn_cfg_get_next_port(port); 00841 return (p > 0) ? p : misdn_cfg_get_next_port(0); 00842 }
void misdn_cfg_get_ports_string | ( | char * | ports | ) |
Definition at line 695 of file misdn_config.c.
References map, max_ports, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), misdn_cfg_unlock(), port_cfg, and ptp.
Referenced by load_module().
00696 { 00697 char tmp[16]; 00698 int l, i; 00699 int gn = map[MISDN_CFG_GROUPNAME]; 00700 00701 *ports = 0; 00702 00703 misdn_cfg_lock(); 00704 for (i = 1; i <= max_ports; i++) { 00705 if (port_cfg[i][gn].str) { 00706 if (ptp[i]) 00707 sprintf(tmp, "%dptp,", i); 00708 else 00709 sprintf(tmp, "%d,", i); 00710 strcat(ports, tmp); 00711 } 00712 } 00713 misdn_cfg_unlock(); 00714 00715 if ((l = strlen(ports))) 00716 ports[l-1] = 0; 00717 }
int misdn_cfg_init | ( | int | this_max_ports | ) |
Definition at line 1071 of file misdn_config.c.
References _build_general_config(), _build_port_config(), _enum_array_map(), _fill_defaults(), _free_general_cfg(), _free_port_cfg(), ast_category_browse(), AST_DESTROY_CFG, AST_LOAD_CFG, ast_log(), ast_mutex_init(), ast_variable_browse(), calloc, config, config_mutex, general_cfg, LOG_WARNING, map, max_ports, misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_GEN_LAST, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, port_cfg, and ptp.
Referenced by load_module(), and misdn_cfg_reload().
01072 { 01073 char config[] = "misdn.conf"; 01074 char *cat, *p; 01075 int i; 01076 struct ast_config *cfg; 01077 struct ast_variable *v; 01078 01079 if (!(cfg = AST_LOAD_CFG(config))) { 01080 ast_log(LOG_WARNING, "missing file: misdn.conf\n"); 01081 return -1; 01082 } 01083 01084 ast_mutex_init(&config_mutex); 01085 01086 misdn_cfg_lock(); 01087 01088 if (this_max_ports) { 01089 /* this is the first run */ 01090 max_ports = this_max_ports; 01091 map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int)); 01092 if (_enum_array_map()) 01093 return -1; 01094 p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *) 01095 + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt)); 01096 port_cfg = (union misdn_cfg_pt **)p; 01097 p += (max_ports + 1) * sizeof(union misdn_cfg_pt *); 01098 for (i = 0; i <= max_ports; ++i) { 01099 port_cfg[i] = (union misdn_cfg_pt *)p; 01100 p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt); 01101 } 01102 general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); 01103 ptp = (int *)calloc(max_ports + 1, sizeof(int)); 01104 } 01105 else { 01106 /* misdn reload */ 01107 _free_port_cfg(); 01108 _free_general_cfg(); 01109 memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1)); 01110 memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); 01111 memset(ptp, 0, sizeof(int) * (max_ports + 1)); 01112 } 01113 01114 cat = ast_category_browse(cfg, NULL); 01115 01116 while(cat) { 01117 v = ast_variable_browse(cfg, cat); 01118 if (!strcasecmp(cat, "general")) { 01119 _build_general_config(v); 01120 } else { 01121 _build_port_config(v, cat); 01122 } 01123 cat = ast_category_browse(cfg, cat); 01124 } 01125 01126 _fill_defaults(); 01127 01128 misdn_cfg_unlock(); 01129 AST_DESTROY_CFG(cfg); 01130 01131 return 0; 01132 }
int misdn_cfg_is_group_method | ( | char * | group, | |
enum misdn_cfg_method | meth | |||
) |
Definition at line 663 of file misdn_config.c.
References map, max_ports, METHOD_ROUND_ROBIN, METHOD_STANDARD, METHOD_STANDARD_DEC, MISDN_CFG_GROUPNAME, misdn_cfg_lock(), MISDN_CFG_METHOD, misdn_cfg_unlock(), port_cfg, and misdn_cfg_pt::str.
Referenced by misdn_request().
00664 { 00665 int i, re = 0; 00666 char *method ; 00667 00668 misdn_cfg_lock(); 00669 00670 method = port_cfg[0][map[MISDN_CFG_METHOD]].str; 00671 00672 for (i = 1; i <= max_ports; i++) { 00673 if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) { 00674 if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group)) 00675 method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 00676 port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str); 00677 } 00678 } 00679 00680 if (method) { 00681 switch (meth) { 00682 case METHOD_STANDARD: re = !strcasecmp(method, "standard"); 00683 break; 00684 case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin"); 00685 break; 00686 case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec"); 00687 break; 00688 } 00689 } 00690 misdn_cfg_unlock(); 00691 00692 return re; 00693 }
int misdn_cfg_is_msn_valid | ( | int | port, | |
char * | msn | |||
) |
Definition at line 631 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_pt::ml, msn_list::msn, msn_list::next, and port_cfg.
Referenced by cb_events().
00632 { 00633 int re = 0; 00634 struct msn_list *iter; 00635 00636 if (!misdn_cfg_is_port_valid(port)) { 00637 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port); 00638 return 0; 00639 } 00640 00641 misdn_cfg_lock(); 00642 if (port_cfg[port][map[MISDN_CFG_MSNS]].ml) 00643 iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml; 00644 else 00645 iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml; 00646 for (; iter; iter = iter->next) 00647 if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) { 00648 re = 1; 00649 break; 00650 } 00651 misdn_cfg_unlock(); 00652 00653 return re; 00654 }
int misdn_cfg_is_port_valid | ( | int | port | ) |
Definition at line 656 of file misdn_config.c.
References map, max_ports, MISDN_CFG_GROUPNAME, and port_cfg.
Referenced by misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_is_msn_valid(), misdn_cfg_update_ptp(), and misdn_show_config().
00657 { 00658 int gn = map[MISDN_CFG_GROUPNAME]; 00659 00660 return (port >= 1 && port <= max_ports && port_cfg[port][gn].str); 00661 }
static void misdn_cfg_lock | ( | void | ) | [inline, static] |
Definition at line 433 of file misdn_config.c.
References ast_mutex_lock().
Referenced by misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_msn_valid(), and misdn_cfg_update_ptp().
00434 { 00435 ast_mutex_lock(&config_mutex); 00436 }
void misdn_cfg_reload | ( | void | ) |
Definition at line 1050 of file misdn_config.c.
References misdn_cfg_init().
Referenced by reload_config().
01051 { 01052 misdn_cfg_init (0); 01053 }
static void misdn_cfg_unlock | ( | void | ) | [inline, static] |
Definition at line 438 of file misdn_config.c.
References ast_mutex_unlock().
Referenced by misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), and misdn_cfg_update_ptp().
00439 { 00440 ast_mutex_unlock(&config_mutex); 00441 }
void misdn_cfg_update_ptp | ( | void | ) |
Definition at line 981 of file misdn_config.c.
References ast_log(), BUFFERSIZE, LOG_WARNING, max_ports, misdn_cfg_get(), misdn_cfg_is_port_valid(), misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_GEN_MISDN_INIT, and ptp.
Referenced by load_module(), and reload_config().
00982 { 00983 #ifndef MISDN_1_2 00984 char misdn_init[BUFFERSIZE]; 00985 char line[BUFFERSIZE]; 00986 FILE *fp; 00987 char *tok, *p, *end; 00988 int port; 00989 00990 misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init)); 00991 00992 if (misdn_init) { 00993 fp = fopen(misdn_init, "r"); 00994 if (fp) { 00995 while(fgets(line, sizeof(line), fp)) { 00996 if (!strncmp(line, "nt_ptp", 6)) { 00997 for (tok = strtok_r(line,",=", &p); 00998 tok; 00999 tok = strtok_r(NULL,",=", &p)) { 01000 port = strtol(tok, &end, 10); 01001 if (end != tok && misdn_cfg_is_port_valid(port)) { 01002 misdn_cfg_lock(); 01003 ptp[port] = 1; 01004 misdn_cfg_unlock(); 01005 } 01006 } 01007 } 01008 } 01009 fclose(fp); 01010 } else { 01011 ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno)); 01012 } 01013 } 01014 #else 01015 int i; 01016 int proto; 01017 char filename[128]; 01018 FILE *fp; 01019 01020 for (i = 1; i <= max_ports; ++i) { 01021 snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8); 01022 fp = fopen(filename, "r"); 01023 if (!fp) { 01024 ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno)); 01025 continue; 01026 } 01027 if (fscanf(fp, "0x%08x", &proto) != 1) 01028 ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename); 01029 else 01030 ptp[i] = proto & 1<<5 ? 1 : 0; 01031 fclose(fp); 01032 } 01033 #endif 01034 }
ast_mutex_t config_mutex [static] |
Definition at line 368 of file misdn_config.c.
Referenced by misdn_cfg_destroy(), and misdn_cfg_init().
struct misdn_cfg_spec gen_spec[] [static] |
Definition at line 323 of file misdn_config.c.
Referenced by _build_general_config(), _enum_array_map(), _fill_defaults(), get_cfg_position(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_desc(), misdn_cfg_get_elem(), and misdn_cfg_get_name().
union misdn_cfg_pt* general_cfg [static] |
Definition at line 362 of file misdn_config.c.
Referenced by _build_general_config(), _fill_defaults(), _free_general_cfg(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), and misdn_cfg_init().
int* map [static] |
Definition at line 366 of file misdn_config.c.
Referenced by append_mapping(), build_mapping(), build_translators(), clear_config_maps(), config_command(), destroy_map(), dundi_lookup_local(), dundi_show_mappings(), find_engine(), find_transcoders(), mark_mappings(), misdn_cfg_destroy(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_port_valid(), and prune_mappings().
int max_ports [static] |
Definition at line 360 of file misdn_config.c.
union misdn_cfg_pt** port_cfg [static] |
Definition at line 358 of file misdn_config.c.
Referenced by _fill_defaults(), _free_port_cfg(), misdn_cfg_destroy(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_next_port(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_is_group_method(), misdn_cfg_is_msn_valid(), and misdn_cfg_is_port_valid().
struct misdn_cfg_spec port_spec[] [static] |
Definition at line 94 of file misdn_config.c.
Referenced by _build_port_config(), _enum_array_map(), _fill_defaults(), _free_port_cfg(), get_cfg_position(), misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_get_desc(), misdn_cfg_get_elem(), and misdn_cfg_get_name().
const char ports_description[] [static] |
Initial value:
"Define your ports, e.g. 1,2 (depends on mISDN-driver loading order)."
Definition at line 91 of file misdn_config.c.
int* ptp [static] |
Definition at line 364 of file misdn_config.c.
Referenced by _build_port_config(), misdn_cfg_destroy(), misdn_cfg_get_config_string(), misdn_cfg_get_ports_string(), misdn_cfg_init(), misdn_cfg_update_ptp(), and misdn_lib_init().