#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"
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 377 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 _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 914 of file misdn_config.c.
References _parse(), misdn_cfg_spec::boolint_def, CLI_ERROR, GEN_CFG, get_cfg_position(), ast_variable::name, ast_variable::next, misdn_cfg_spec::type, and ast_variable::value.
Referenced by misdn_cfg_init().
00915 { 00916 int pos; 00917 00918 for (; v; v = v->next) { 00919 if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 00920 (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0)) 00921 CLI_ERROR(v->name, v->value, "general"); 00922 } 00923 }
static void _build_port_config | ( | struct ast_variable * | v, | |
char * | cat | |||
) | [static] |
Definition at line 925 of file misdn_config.c.
References _parse(), misdn_cfg_spec::boolint_def, BUFFERSIZE, CLI_ERROR, get_cfg_position(), ast_variable::name, ast_variable::next, PORT_CFG, strsep(), misdn_cfg_spec::type, type, and ast_variable::value.
Referenced by misdn_cfg_init().
00926 { 00927 int pos, i; 00928 union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS]; 00929 int cfg_for_ports[max_ports + 1]; 00930 00931 if (!v || !cat) 00932 return; 00933 00934 memset(cfg_tmp, 0, sizeof(cfg_tmp)); 00935 memset(cfg_for_ports, 0, sizeof(cfg_for_ports)); 00936 00937 if (!strcasecmp(cat, "default")) { 00938 cfg_for_ports[0] = 1; 00939 } 00940 00941 if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 00942 (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) { 00943 CLI_ERROR(v->name, v->value, cat); 00944 return; 00945 } 00946 00947 for (; v; v = v->next) { 00948 if (!strcasecmp(v->name, "ports")) { 00949 char *token; 00950 char ptpbuf[BUFFERSIZE] = ""; 00951 int start, end; 00952 for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 00953 if (!*token) 00954 continue; 00955 if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) { 00956 for (; start <= end; start++) { 00957 if (start <= max_ports && start > 0) { 00958 cfg_for_ports[start] = 1; 00959 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00960 } else 00961 CLI_ERROR(v->name, v->value, cat); 00962 } 00963 } else { 00964 if (sscanf(token, "%d%s", &start, ptpbuf)) { 00965 if (start <= max_ports && start > 0) { 00966 cfg_for_ports[start] = 1; 00967 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00968 } else 00969 CLI_ERROR(v->name, v->value, cat); 00970 } else 00971 CLI_ERROR(v->name, v->value, cat); 00972 } 00973 } 00974 } else { 00975 if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 00976 (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) 00977 CLI_ERROR(v->name, v->value, cat); 00978 } 00979 } 00980 00981 for (i = 0; i < (max_ports + 1); ++i) { 00982 if (cfg_for_ports[i]) { 00983 memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp)); 00984 } 00985 } 00986 }
static int _enum_array_map | ( | void | ) | [static] |
Definition at line 382 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().
00383 { 00384 int i, j, ok; 00385 00386 for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) { 00387 if (i == MISDN_CFG_PTP) 00388 continue; 00389 ok = 0; 00390 for (j = 0; j < NUM_PORT_ELEMENTS; ++j) { 00391 if (port_spec[j].elem == i) { 00392 map[i] = j; 00393 ok = 1; 00394 break; 00395 } 00396 } 00397 if (!ok) { 00398 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i); 00399 return -1; 00400 } 00401 } 00402 for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) { 00403 ok = 0; 00404 for (j = 0; j < NUM_GEN_ELEMENTS; ++j) { 00405 if (gen_spec[j].elem == i) { 00406 map[i] = j; 00407 ok = 1; 00408 break; 00409 } 00410 } 00411 if (!ok) { 00412 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i); 00413 return -1; 00414 } 00415 } 00416 return 0; 00417 }
static void _fill_defaults | ( | void | ) | [static] |
Definition at line 1043 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().
01044 { 01045 int i; 01046 01047 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 01048 if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT)) 01049 _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def); 01050 } 01051 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 01052 if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT)) 01053 _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def); 01054 } 01055 }
static void _free_general_cfg | ( | void | ) | [static] |
Definition at line 492 of file misdn_config.c.
References misdn_cfg_pt::any, free, and NUM_GEN_ELEMENTS.
Referenced by misdn_cfg_destroy(), and misdn_cfg_init().
00493 { 00494 int i; 00495 00496 for (i = 0; i < NUM_GEN_ELEMENTS; i++) 00497 if (general_cfg[i].any) 00498 free(general_cfg[i].any); 00499 }
static void _free_msn_list | ( | struct msn_list * | iter | ) | [static] |
Definition at line 450 of file misdn_config.c.
References free, msn_list::msn, and msn_list::next.
Referenced by _free_port_cfg().
00451 { 00452 if (iter->next) 00453 _free_msn_list(iter->next); 00454 if (iter->msn) 00455 free(iter->msn); 00456 free(iter); 00457 }
static void _free_port_cfg | ( | void | ) | [static] |
Definition at line 459 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, misdn_cfg_pt::str, and type.
Referenced by misdn_cfg_destroy(), and misdn_cfg_init().
00460 { 00461 int i, j; 00462 int gn = map[MISDN_CFG_GROUPNAME]; 00463 union misdn_cfg_pt* free_list[max_ports + 2]; 00464 00465 memset(free_list, 0, sizeof(free_list)); 00466 free_list[0] = port_cfg[0]; 00467 for (i = 1; i <= max_ports; ++i) { 00468 if (port_cfg[i][gn].str) { 00469 /* we always have a groupname in the non-default case, so this is fine */ 00470 for (j = 1; j <= max_ports; ++j) { 00471 if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str) 00472 break; 00473 else if (!free_list[j]) { 00474 free_list[j] = port_cfg[i]; 00475 break; 00476 } 00477 } 00478 } 00479 } 00480 for (j = 0; free_list[j]; ++j) { 00481 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00482 if (free_list[j][i].any) { 00483 if (port_spec[i].type == MISDN_CTYPE_MSNLIST) 00484 _free_msn_list(free_list[j][i].ml); 00485 else 00486 free(free_list[j][i].any); 00487 } 00488 } 00489 } 00490 }
static int _parse | ( | union misdn_cfg_pt * | dest, | |
char * | value, | |||
enum misdn_cfg_type | type, | |||
int | boolint_def | |||
) | [static] |
Definition at line 851 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().
00852 { 00853 int re = 0; 00854 int len, tmp; 00855 char *valtmp; 00856 00857 switch (type) { 00858 case MISDN_CTYPE_STR: 00859 if ((len = strlen(value))) { 00860 dest->str = (char *)malloc((len + 1) * sizeof(char)); 00861 strncpy(dest->str, value, len); 00862 dest->str[len] = 0; 00863 } else { 00864 dest->str = (char *)malloc( sizeof(char)); 00865 dest->str[0] = 0; 00866 } 00867 break; 00868 case MISDN_CTYPE_INT: 00869 { 00870 char *pat; 00871 if (strchr(value,'x')) 00872 pat="%x"; 00873 else 00874 pat="%d"; 00875 if (sscanf(value, pat, &tmp)) { 00876 dest->num = (int *)malloc(sizeof(int)); 00877 memcpy(dest->num, &tmp, sizeof(int)); 00878 } else 00879 re = -1; 00880 } 00881 break; 00882 case MISDN_CTYPE_BOOL: 00883 dest->num = (int *)malloc(sizeof(int)); 00884 *(dest->num) = (ast_true(value) ? 1 : 0); 00885 break; 00886 case MISDN_CTYPE_BOOLINT: 00887 dest->num = (int *)malloc(sizeof(int)); 00888 if (sscanf(value, "%d", &tmp)) { 00889 memcpy(dest->num, &tmp, sizeof(int)); 00890 } else { 00891 *(dest->num) = (ast_true(value) ? boolint_def : 0); 00892 } 00893 break; 00894 case MISDN_CTYPE_MSNLIST: 00895 for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) { 00896 if ((len = strlen(valtmp))) { 00897 struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list)); 00898 ml->msn = (char *)calloc(len+1, sizeof(char)); 00899 strncpy(ml->msn, valtmp, len); 00900 ml->next = dest->ml; 00901 dest->ml = ml; 00902 } 00903 } 00904 break; 00905 case MISDN_CTYPE_ASTGROUP: 00906 dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t)); 00907 *(dest->grp) = ast_get_group(value); 00908 break; 00909 } 00910 00911 return re; 00912 }
static int get_cfg_position | ( | char * | name, | |
int | type | |||
) | [static] |
Definition at line 419 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().
00420 { 00421 int i; 00422 00423 switch (type) { 00424 case PORT_CFG: 00425 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00426 if (!strcasecmp(name, port_spec[i].name)) 00427 return i; 00428 } 00429 break; 00430 case GEN_CFG: 00431 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 00432 if (!strcasecmp(name, gen_spec[i].name)) 00433 return i; 00434 } 00435 } 00436 00437 return -1; 00438 }
void misdn_cfg_destroy | ( | void | ) |
Definition at line 1062 of file misdn_config.c.
Referenced by unload_module().
01063 { 01064 misdn_cfg_lock(); 01065 01066 _free_port_cfg(); 01067 _free_general_cfg(); 01068 01069 free(port_cfg); 01070 free(general_cfg); 01071 free(ptp); 01072 free(map); 01073 01074 misdn_cfg_unlock(); 01075 ast_mutex_destroy(&config_mutex); 01076 }
void misdn_cfg_get | ( | int | port, | |
enum misdn_cfg_elements | elem, | |||
void * | buf, | |||
int | bufsize | |||
) |
Definition at line 501 of file misdn_config.c.
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().
00502 { 00503 int place; 00504 00505 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00506 memset(buf, 0, bufsize); 00507 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); 00508 return; 00509 } 00510 00511 misdn_cfg_lock(); 00512 if (elem == MISDN_CFG_PTP) { 00513 if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) 00514 memset(buf, 0, bufsize); 00515 } else { 00516 if ((place = map[elem]) < 0) { 00517 memset (buf, 0, bufsize); 00518 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); 00519 } else { 00520 if (elem < MISDN_CFG_LAST) { 00521 switch (port_spec[place].type) { 00522 case MISDN_CTYPE_STR: 00523 if (port_cfg[port][place].str) { 00524 if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize)) 00525 memset(buf, 0, 1); 00526 } else if (port_cfg[0][place].str) { 00527 if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize)) 00528 memset(buf, 0, 1); 00529 } 00530 break; 00531 default: 00532 if (port_cfg[port][place].any) 00533 memcpy(buf, port_cfg[port][place].any, bufsize); 00534 else if (port_cfg[0][place].any) 00535 memcpy(buf, port_cfg[0][place].any, bufsize); 00536 else 00537 memset(buf, 0, bufsize); 00538 } 00539 } else { 00540 switch (gen_spec[place].type) { 00541 case MISDN_CTYPE_STR: 00542 if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize)) 00543 memset(buf, 0, 1); 00544 break; 00545 default: 00546 if (general_cfg[place].any) 00547 memcpy(buf, general_cfg[place].any, bufsize); 00548 else 00549 memset(buf, 0, bufsize); 00550 } 00551 } 00552 } 00553 } 00554 misdn_cfg_unlock(); 00555 }
void misdn_cfg_get_config_string | ( | int | port, | |
enum misdn_cfg_elements | elem, | |||
char * | buf, | |||
int | bufsize | |||
) |
Definition at line 726 of file misdn_config.c.
Referenced by misdn_show_config().
00727 { 00728 int place; 00729 char tempbuf[BUFFERSIZE] = ""; 00730 struct msn_list *iter; 00731 00732 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00733 *buf = 0; 00734 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port); 00735 return; 00736 } 00737 00738 place = map[elem]; 00739 00740 misdn_cfg_lock(); 00741 if (elem == MISDN_CFG_PTP) { 00742 snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no"); 00743 } 00744 else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) { 00745 switch (port_spec[place].type) { 00746 case MISDN_CTYPE_INT: 00747 case MISDN_CTYPE_BOOLINT: 00748 if (port_cfg[port][place].num) 00749 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num); 00750 else if (port_cfg[0][place].num) 00751 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num); 00752 else 00753 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00754 break; 00755 case MISDN_CTYPE_BOOL: 00756 if (port_cfg[port][place].num) 00757 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no"); 00758 else if (port_cfg[0][place].num) 00759 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no"); 00760 else 00761 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00762 break; 00763 case MISDN_CTYPE_ASTGROUP: 00764 if (port_cfg[port][place].grp) 00765 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00766 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp)); 00767 else if (port_cfg[0][place].grp) 00768 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00769 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp)); 00770 else 00771 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00772 break; 00773 case MISDN_CTYPE_MSNLIST: 00774 if (port_cfg[port][place].ml) 00775 iter = port_cfg[port][place].ml; 00776 else 00777 iter = port_cfg[0][place].ml; 00778 if (iter) { 00779 for (; iter; iter = iter->next) 00780 sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn); 00781 tempbuf[strlen(tempbuf)-2] = 0; 00782 } 00783 snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none"); 00784 break; 00785 case MISDN_CTYPE_STR: 00786 if ( port_cfg[port][place].str) { 00787 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str); 00788 } else if (port_cfg[0][place].str) { 00789 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str); 00790 } else { 00791 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00792 } 00793 break; 00794 } 00795 } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) { 00796 switch (gen_spec[place].type) { 00797 case MISDN_CTYPE_INT: 00798 case MISDN_CTYPE_BOOLINT: 00799 if (general_cfg[place].num) 00800 snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num); 00801 else 00802 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00803 break; 00804 case MISDN_CTYPE_BOOL: 00805 if (general_cfg[place].num) 00806 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no"); 00807 else 00808 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00809 break; 00810 case MISDN_CTYPE_STR: 00811 if ( general_cfg[place].str) { 00812 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str); 00813 } else { 00814 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00815 } 00816 break; 00817 default: 00818 snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name); 00819 break; 00820 } 00821 } else { 00822 *buf = 0; 00823 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem); 00824 } 00825 misdn_cfg_unlock(); 00826 }
void misdn_cfg_get_desc | ( | enum misdn_cfg_elements | elem, | |
void * | buf, | |||
int | bufsize, | |||
void * | buf_default, | |||
int | bufsize_default | |||
) |
Definition at line 605 of file misdn_config.c.
Referenced by show_config_description().
00606 { 00607 int place = map[elem]; 00608 struct misdn_cfg_spec *spec = NULL; 00609 00610 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00611 if (elem == MISDN_CFG_GROUPNAME) { 00612 if (!memccpy(buf, ports_description, 0, bufsize)) 00613 memset(buf, 0, 1); 00614 if (buf_default && bufsize_default) 00615 memset(buf_default, 0, 1); 00616 return; 00617 } 00618 00619 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) 00620 spec = (struct misdn_cfg_spec *)port_spec; 00621 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) 00622 spec = (struct misdn_cfg_spec *)gen_spec; 00623 00624 if (!spec || !spec[place].desc) 00625 memset(buf, 0, 1); 00626 else { 00627 if (!memccpy(buf, spec[place].desc, 0, bufsize)) 00628 memset(buf, 0, 1); 00629 if (buf_default && bufsize) { 00630 if (!strcmp(spec[place].def, NO_DEFAULT)) 00631 memset(buf_default, 0, 1); 00632 else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default)) 00633 memset(buf_default, 0, 1); 00634 } 00635 } 00636 }
enum misdn_cfg_elements misdn_cfg_get_elem | ( | char * | name | ) |
Definition at line 557 of file misdn_config.c.
Referenced by misdn_show_config().
00558 { 00559 int pos; 00560 00561 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00562 if (!strcmp(name, "ports")) 00563 return MISDN_CFG_GROUPNAME; 00564 if (!strcmp(name, "name")) 00565 return MISDN_CFG_FIRST; 00566 00567 pos = get_cfg_position (name, PORT_CFG); 00568 if (pos >= 0) 00569 return port_spec[pos].elem; 00570 00571 pos = get_cfg_position (name, GEN_CFG); 00572 if (pos >= 0) 00573 return gen_spec[pos].elem; 00574 00575 return MISDN_CFG_FIRST; 00576 }
void misdn_cfg_get_name | ( | enum misdn_cfg_elements | elem, | |
void * | buf, | |||
int | bufsize | |||
) |
Definition at line 578 of file misdn_config.c.
Referenced by complete_show_config(), and show_config_description().
00579 { 00580 struct misdn_cfg_spec *spec = NULL; 00581 int place = map[elem]; 00582 00583 /* the ptp hack */ 00584 if (elem == MISDN_CFG_PTP) { 00585 memset(buf, 0, 1); 00586 return; 00587 } 00588 00589 /* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ 00590 if (elem == MISDN_CFG_GROUPNAME) { 00591 if (!snprintf(buf, bufsize, "ports")) 00592 memset(buf, 0, 1); 00593 return; 00594 } 00595 00596 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) 00597 spec = (struct misdn_cfg_spec *)port_spec; 00598 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) 00599 spec = (struct misdn_cfg_spec *)gen_spec; 00600 00601 if (!spec || !memccpy(buf, spec[place].name, 0, bufsize)) 00602 memset(buf, 0, 1); 00603 }
int misdn_cfg_get_next_port | ( | int | port | ) |
Definition at line 828 of file misdn_config.c.
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().
00829 { 00830 int p = -1; 00831 int gn = map[MISDN_CFG_GROUPNAME]; 00832 00833 misdn_cfg_lock(); 00834 for (port++; port <= max_ports; port++) { 00835 if (port_cfg[port][gn].str) { 00836 p = port; 00837 break; 00838 } 00839 } 00840 misdn_cfg_unlock(); 00841 00842 return p; 00843 }
int misdn_cfg_get_next_port_spin | ( | int | port | ) |
Definition at line 845 of file misdn_config.c.
Referenced by misdn_request().
00846 { 00847 int p = misdn_cfg_get_next_port(port); 00848 return (p > 0) ? p : misdn_cfg_get_next_port(0); 00849 }
void misdn_cfg_get_ports_string | ( | char * | ports | ) |
Definition at line 702 of file misdn_config.c.
Referenced by load_module().
00703 { 00704 char tmp[16]; 00705 int l, i; 00706 int gn = map[MISDN_CFG_GROUPNAME]; 00707 00708 *ports = 0; 00709 00710 misdn_cfg_lock(); 00711 for (i = 1; i <= max_ports; i++) { 00712 if (port_cfg[i][gn].str) { 00713 if (ptp[i]) 00714 sprintf(tmp, "%dptp,", i); 00715 else 00716 sprintf(tmp, "%d,", i); 00717 strcat(ports, tmp); 00718 } 00719 } 00720 misdn_cfg_unlock(); 00721 00722 if ((l = strlen(ports))) 00723 ports[l-1] = 0; 00724 }
int misdn_cfg_init | ( | int | this_max_ports | ) |
Definition at line 1078 of file misdn_config.c.
Referenced by load_module(), and misdn_cfg_reload().
01079 { 01080 char config[] = "misdn.conf"; 01081 char *cat, *p; 01082 int i; 01083 struct ast_config *cfg; 01084 struct ast_variable *v; 01085 01086 if (!(cfg = AST_LOAD_CFG(config))) { 01087 ast_log(LOG_WARNING, "missing file: misdn.conf\n"); 01088 return -1; 01089 } 01090 01091 ast_mutex_init(&config_mutex); 01092 01093 misdn_cfg_lock(); 01094 01095 if (this_max_ports) { 01096 /* this is the first run */ 01097 max_ports = this_max_ports; 01098 map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int)); 01099 if (_enum_array_map()) 01100 return -1; 01101 p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *) 01102 + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt)); 01103 port_cfg = (union misdn_cfg_pt **)p; 01104 p += (max_ports + 1) * sizeof(union misdn_cfg_pt *); 01105 for (i = 0; i <= max_ports; ++i) { 01106 port_cfg[i] = (union misdn_cfg_pt *)p; 01107 p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt); 01108 } 01109 general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); 01110 ptp = (int *)calloc(max_ports + 1, sizeof(int)); 01111 } 01112 else { 01113 /* misdn reload */ 01114 _free_port_cfg(); 01115 _free_general_cfg(); 01116 memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1)); 01117 memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); 01118 memset(ptp, 0, sizeof(int) * (max_ports + 1)); 01119 } 01120 01121 cat = ast_category_browse(cfg, NULL); 01122 01123 while(cat) { 01124 v = ast_variable_browse(cfg, cat); 01125 if (!strcasecmp(cat, "general")) { 01126 _build_general_config(v); 01127 } else { 01128 _build_port_config(v, cat); 01129 } 01130 cat = ast_category_browse(cfg, cat); 01131 } 01132 01133 _fill_defaults(); 01134 01135 misdn_cfg_unlock(); 01136 AST_DESTROY_CFG(cfg); 01137 01138 return 0; 01139 }
int misdn_cfg_is_group_method | ( | char * | group, | |
enum misdn_cfg_method | meth | |||
) |
Definition at line 670 of file misdn_config.c.
Referenced by misdn_request().
00671 { 00672 int i, re = 0; 00673 char *method ; 00674 00675 misdn_cfg_lock(); 00676 00677 method = port_cfg[0][map[MISDN_CFG_METHOD]].str; 00678 00679 for (i = 1; i <= max_ports; i++) { 00680 if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) { 00681 if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group)) 00682 method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 00683 port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str); 00684 } 00685 } 00686 00687 if (method) { 00688 switch (meth) { 00689 case METHOD_STANDARD: re = !strcasecmp(method, "standard"); 00690 break; 00691 case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin"); 00692 break; 00693 case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec"); 00694 break; 00695 } 00696 } 00697 misdn_cfg_unlock(); 00698 00699 return re; 00700 }
int misdn_cfg_is_msn_valid | ( | int | port, | |
char * | msn | |||
) |
Definition at line 638 of file misdn_config.c.
Referenced by cb_events().
00639 { 00640 int re = 0; 00641 struct msn_list *iter; 00642 00643 if (!misdn_cfg_is_port_valid(port)) { 00644 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port); 00645 return 0; 00646 } 00647 00648 misdn_cfg_lock(); 00649 if (port_cfg[port][map[MISDN_CFG_MSNS]].ml) 00650 iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml; 00651 else 00652 iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml; 00653 for (; iter; iter = iter->next) 00654 if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) { 00655 re = 1; 00656 break; 00657 } 00658 misdn_cfg_unlock(); 00659 00660 return re; 00661 }
int misdn_cfg_is_port_valid | ( | int | port | ) |
Definition at line 663 of file misdn_config.c.
Referenced by misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_is_msn_valid(), misdn_cfg_update_ptp(), and misdn_show_config().
00664 { 00665 int gn = map[MISDN_CFG_GROUPNAME]; 00666 00667 return (port >= 1 && port <= max_ports && port_cfg[port][gn].str); 00668 }
static void misdn_cfg_lock | ( | void | ) | [inline, static] |
Definition at line 440 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().
00441 { 00442 ast_mutex_lock(&config_mutex); 00443 }
void misdn_cfg_reload | ( | void | ) |
Definition at line 1057 of file misdn_config.c.
Referenced by reload_config().
01058 { 01059 misdn_cfg_init (0); 01060 }
static void misdn_cfg_unlock | ( | void | ) | [inline, static] |
Definition at line 445 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(), misdn_cfg_is_msn_valid(), and misdn_cfg_update_ptp().
00446 { 00447 ast_mutex_unlock(&config_mutex); 00448 }
void misdn_cfg_update_ptp | ( | void | ) |
Definition at line 988 of file misdn_config.c.
Referenced by load_module(), and reload_config().
00989 { 00990 #ifndef MISDN_1_2 00991 char misdn_init[BUFFERSIZE]; 00992 char line[BUFFERSIZE]; 00993 FILE *fp; 00994 char *tok, *p, *end; 00995 int port; 00996 00997 misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init)); 00998 00999 if (misdn_init) { 01000 fp = fopen(misdn_init, "r"); 01001 if (fp) { 01002 while(fgets(line, sizeof(line), fp)) { 01003 if (!strncmp(line, "nt_ptp", 6)) { 01004 for (tok = strtok_r(line,",=", &p); 01005 tok; 01006 tok = strtok_r(NULL,",=", &p)) { 01007 port = strtol(tok, &end, 10); 01008 if (end != tok && misdn_cfg_is_port_valid(port)) { 01009 misdn_cfg_lock(); 01010 ptp[port] = 1; 01011 misdn_cfg_unlock(); 01012 } 01013 } 01014 } 01015 } 01016 fclose(fp); 01017 } else { 01018 ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno)); 01019 } 01020 } 01021 #else 01022 int i; 01023 int proto; 01024 char filename[128]; 01025 FILE *fp; 01026 01027 for (i = 1; i <= max_ports; ++i) { 01028 snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8); 01029 fp = fopen(filename, "r"); 01030 if (!fp) { 01031 ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno)); 01032 continue; 01033 } 01034 if (fscanf(fp, "0x%08x", &proto) != 1) 01035 ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename); 01036 else 01037 ptp[i] = proto & 1<<5 ? 1 : 0; 01038 fclose(fp); 01039 } 01040 #endif 01041 }
ast_mutex_t config_mutex [static] |
Definition at line 375 of file misdn_config.c.
struct misdn_cfg_spec gen_spec[] [static] |
Definition at line 330 of file misdn_config.c.
union misdn_cfg_pt* general_cfg [static] |
Definition at line 369 of file misdn_config.c.
int* map [static] |
Definition at line 373 of file misdn_config.c.
Referenced by append_mapping(), build_mapping(), clear_config_maps(), config_command(), dundi_show_mappings(), find_engine(), mark_mappings(), and prune_mappings().
int max_ports [static] |
Definition at line 367 of file misdn_config.c.
union misdn_cfg_pt** port_cfg [static] |
Definition at line 365 of file misdn_config.c.
struct misdn_cfg_spec port_spec[] [static] |
Definition at line 94 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 91 of file misdn_config.c.
int* ptp [static] |