#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) |
| Generate a comma separated list of all active 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 389 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 932 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().
00933 { 00934 int pos; 00935 00936 for (; v; v = v->next) { 00937 if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 00938 (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0)) 00939 CLI_ERROR(v->name, v->value, "general"); 00940 } 00941 }
| static void _build_port_config | ( | struct ast_variable * | v, | |
| char * | cat | |||
| ) | [static] |
Definition at line 943 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().
00944 { 00945 int pos, i; 00946 union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS]; 00947 int cfg_for_ports[max_ports + 1]; 00948 00949 if (!v || !cat) 00950 return; 00951 00952 memset(cfg_tmp, 0, sizeof(cfg_tmp)); 00953 memset(cfg_for_ports, 0, sizeof(cfg_for_ports)); 00954 00955 if (!strcasecmp(cat, "default")) { 00956 cfg_for_ports[0] = 1; 00957 } 00958 00959 if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 00960 (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) { 00961 CLI_ERROR(v->name, v->value, cat); 00962 return; 00963 } 00964 00965 for (; v; v = v->next) { 00966 if (!strcasecmp(v->name, "ports")) { 00967 char *token; 00968 char ptpbuf[BUFFERSIZE] = ""; 00969 int start, end; 00970 for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) { 00971 if (!*token) 00972 continue; 00973 if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) { 00974 for (; start <= end; start++) { 00975 if (start <= max_ports && start > 0) { 00976 cfg_for_ports[start] = 1; 00977 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00978 } else 00979 CLI_ERROR(v->name, v->value, cat); 00980 } 00981 } else { 00982 if (sscanf(token, "%d%s", &start, ptpbuf)) { 00983 if (start <= max_ports && start > 0) { 00984 cfg_for_ports[start] = 1; 00985 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; 00986 } else 00987 CLI_ERROR(v->name, v->value, cat); 00988 } else 00989 CLI_ERROR(v->name, v->value, cat); 00990 } 00991 } 00992 } else { 00993 if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 00994 (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) 00995 CLI_ERROR(v->name, v->value, cat); 00996 } 00997 } 00998 00999 for (i = 0; i < (max_ports + 1); ++i) { 01000 if (cfg_for_ports[i]) { 01001 memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp)); 01002 } 01003 } 01004 }
| static int _enum_array_map | ( | void | ) | [static] |
Definition at line 394 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().
00395 { 00396 int i, j, ok; 00397 00398 for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) { 00399 if (i == MISDN_CFG_PTP) 00400 continue; 00401 ok = 0; 00402 for (j = 0; j < NUM_PORT_ELEMENTS; ++j) { 00403 if (port_spec[j].elem == i) { 00404 map[i] = j; 00405 ok = 1; 00406 break; 00407 } 00408 } 00409 if (!ok) { 00410 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i); 00411 return -1; 00412 } 00413 } 00414 for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) { 00415 ok = 0; 00416 for (j = 0; j < NUM_GEN_ELEMENTS; ++j) { 00417 if (gen_spec[j].elem == i) { 00418 map[i] = j; 00419 ok = 1; 00420 break; 00421 } 00422 } 00423 if (!ok) { 00424 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i); 00425 return -1; 00426 } 00427 } 00428 return 0; 00429 }
| static void _fill_defaults | ( | void | ) | [static] |
Definition at line 1061 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().
01062 { 01063 int i; 01064 01065 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 01066 if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT)) 01067 _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def); 01068 } 01069 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 01070 if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT)) 01071 _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def); 01072 } 01073 }
| static void _free_general_cfg | ( | void | ) | [static] |
Definition at line 504 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().
00505 { 00506 int i; 00507 00508 for (i = 0; i < NUM_GEN_ELEMENTS; i++) 00509 if (general_cfg[i].any) 00510 free(general_cfg[i].any); 00511 }
| static void _free_msn_list | ( | struct msn_list * | iter | ) | [static] |
Definition at line 462 of file misdn_config.c.
References free, msn_list::msn, and msn_list::next.
Referenced by _free_port_cfg().
00463 { 00464 if (iter->next) 00465 _free_msn_list(iter->next); 00466 if (iter->msn) 00467 free(iter->msn); 00468 free(iter); 00469 }
| static void _free_port_cfg | ( | void | ) | [static] |
Definition at line 471 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().
00472 { 00473 int i, j; 00474 int gn = map[MISDN_CFG_GROUPNAME]; 00475 union misdn_cfg_pt* free_list[max_ports + 2]; 00476 00477 memset(free_list, 0, sizeof(free_list)); 00478 free_list[0] = port_cfg[0]; 00479 for (i = 1; i <= max_ports; ++i) { 00480 if (port_cfg[i][gn].str) { 00481 /* we always have a groupname in the non-default case, so this is fine */ 00482 for (j = 1; j <= max_ports; ++j) { 00483 if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str) 00484 break; 00485 else if (!free_list[j]) { 00486 free_list[j] = port_cfg[i]; 00487 break; 00488 } 00489 } 00490 } 00491 } 00492 for (j = 0; free_list[j]; ++j) { 00493 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00494 if (free_list[j][i].any) { 00495 if (port_spec[i].type == MISDN_CTYPE_MSNLIST) 00496 _free_msn_list(free_list[j][i].ml); 00497 else 00498 free(free_list[j][i].any); 00499 } 00500 } 00501 } 00502 }
| static int _parse | ( | union misdn_cfg_pt * | dest, | |
| char * | value, | |||
| enum misdn_cfg_type | type, | |||
| int | boolint_def | |||
| ) | [static] |
Definition at line 869 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().
00870 { 00871 int re = 0; 00872 int len, tmp; 00873 char *valtmp; 00874 00875 switch (type) { 00876 case MISDN_CTYPE_STR: 00877 if ((len = strlen(value))) { 00878 dest->str = (char *)malloc((len + 1) * sizeof(char)); 00879 strncpy(dest->str, value, len); 00880 dest->str[len] = 0; 00881 } else { 00882 dest->str = (char *)malloc( sizeof(char)); 00883 dest->str[0] = 0; 00884 } 00885 break; 00886 case MISDN_CTYPE_INT: 00887 { 00888 char *pat; 00889 if (strchr(value,'x')) 00890 pat="%x"; 00891 else 00892 pat="%d"; 00893 if (sscanf(value, pat, &tmp)) { 00894 dest->num = (int *)malloc(sizeof(int)); 00895 memcpy(dest->num, &tmp, sizeof(int)); 00896 } else 00897 re = -1; 00898 } 00899 break; 00900 case MISDN_CTYPE_BOOL: 00901 dest->num = (int *)malloc(sizeof(int)); 00902 *(dest->num) = (ast_true(value) ? 1 : 0); 00903 break; 00904 case MISDN_CTYPE_BOOLINT: 00905 dest->num = (int *)malloc(sizeof(int)); 00906 if (sscanf(value, "%d", &tmp)) { 00907 memcpy(dest->num, &tmp, sizeof(int)); 00908 } else { 00909 *(dest->num) = (ast_true(value) ? boolint_def : 0); 00910 } 00911 break; 00912 case MISDN_CTYPE_MSNLIST: 00913 for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) { 00914 if ((len = strlen(valtmp))) { 00915 struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list)); 00916 ml->msn = (char *)calloc(len+1, sizeof(char)); 00917 strncpy(ml->msn, valtmp, len); 00918 ml->next = dest->ml; 00919 dest->ml = ml; 00920 } 00921 } 00922 break; 00923 case MISDN_CTYPE_ASTGROUP: 00924 dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t)); 00925 *(dest->grp) = ast_get_group(value); 00926 break; 00927 } 00928 00929 return re; 00930 }
| static int get_cfg_position | ( | char * | name, | |
| int | type | |||
| ) | [static] |
Definition at line 431 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().
00432 { 00433 int i; 00434 00435 switch (type) { 00436 case PORT_CFG: 00437 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { 00438 if (!strcasecmp(name, port_spec[i].name)) 00439 return i; 00440 } 00441 break; 00442 case GEN_CFG: 00443 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { 00444 if (!strcasecmp(name, gen_spec[i].name)) 00445 return i; 00446 } 00447 } 00448 00449 return -1; 00450 }
| void misdn_cfg_destroy | ( | void | ) |
Definition at line 1080 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().
01081 { 01082 misdn_cfg_lock(); 01083 01084 _free_port_cfg(); 01085 _free_general_cfg(); 01086 01087 free(port_cfg); 01088 free(general_cfg); 01089 free(ptp); 01090 free(map); 01091 01092 misdn_cfg_unlock(); 01093 ast_mutex_destroy(&config_mutex); 01094 }
| void misdn_cfg_get | ( | int | port, | |
| enum misdn_cfg_elements | elem, | |||
| void * | buf, | |||
| int | bufsize | |||
| ) |
Definition at line 513 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().
00514 { 00515 int place; 00516 00517 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00518 memset(buf, 0, bufsize); 00519 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); 00520 return; 00521 } 00522 00523 misdn_cfg_lock(); 00524 if (elem == MISDN_CFG_PTP) { 00525 if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) 00526 memset(buf, 0, bufsize); 00527 } else { 00528 if ((place = map[elem]) < 0) { 00529 memset (buf, 0, bufsize); 00530 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); 00531 } else { 00532 if (elem < MISDN_CFG_LAST) { 00533 switch (port_spec[place].type) { 00534 case MISDN_CTYPE_STR: 00535 if (port_cfg[port][place].str) { 00536 if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize)) 00537 memset(buf, 0, 1); 00538 } else if (port_cfg[0][place].str) { 00539 if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize)) 00540 memset(buf, 0, 1); 00541 } else 00542 memset(buf, 0, bufsize); 00543 break; 00544 default: 00545 if (port_cfg[port][place].any) 00546 memcpy(buf, port_cfg[port][place].any, bufsize); 00547 else if (port_cfg[0][place].any) 00548 memcpy(buf, port_cfg[0][place].any, bufsize); 00549 else 00550 memset(buf, 0, bufsize); 00551 } 00552 } else { 00553 switch (gen_spec[place].type) { 00554 case MISDN_CTYPE_STR: 00555 if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize)) 00556 memset(buf, 0, 1); 00557 break; 00558 default: 00559 if (general_cfg[place].any) 00560 memcpy(buf, general_cfg[place].any, bufsize); 00561 else 00562 memset(buf, 0, bufsize); 00563 } 00564 } 00565 } 00566 } 00567 misdn_cfg_unlock(); 00568 }
| void misdn_cfg_get_config_string | ( | int | port, | |
| enum misdn_cfg_elements | elem, | |||
| char * | buf, | |||
| int | bufsize | |||
| ) |
Definition at line 744 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().
00745 { 00746 int place; 00747 char tempbuf[BUFFERSIZE] = ""; 00748 struct msn_list *iter; 00749 00750 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { 00751 *buf = 0; 00752 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port); 00753 return; 00754 } 00755 00756 place = map[elem]; 00757 00758 misdn_cfg_lock(); 00759 if (elem == MISDN_CFG_PTP) { 00760 snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no"); 00761 } 00762 else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) { 00763 switch (port_spec[place].type) { 00764 case MISDN_CTYPE_INT: 00765 case MISDN_CTYPE_BOOLINT: 00766 if (port_cfg[port][place].num) 00767 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num); 00768 else if (port_cfg[0][place].num) 00769 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num); 00770 else 00771 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00772 break; 00773 case MISDN_CTYPE_BOOL: 00774 if (port_cfg[port][place].num) 00775 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no"); 00776 else if (port_cfg[0][place].num) 00777 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no"); 00778 else 00779 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00780 break; 00781 case MISDN_CTYPE_ASTGROUP: 00782 if (port_cfg[port][place].grp) 00783 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00784 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp)); 00785 else if (port_cfg[0][place].grp) 00786 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 00787 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp)); 00788 else 00789 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00790 break; 00791 case MISDN_CTYPE_MSNLIST: 00792 if (port_cfg[port][place].ml) 00793 iter = port_cfg[port][place].ml; 00794 else 00795 iter = port_cfg[0][place].ml; 00796 if (iter) { 00797 for (; iter; iter = iter->next) 00798 sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn); 00799 tempbuf[strlen(tempbuf)-2] = 0; 00800 } 00801 snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none"); 00802 break; 00803 case MISDN_CTYPE_STR: 00804 if ( port_cfg[port][place].str) { 00805 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str); 00806 } else if (port_cfg[0][place].str) { 00807 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str); 00808 } else { 00809 snprintf(buf, bufsize, " -> %s:", port_spec[place].name); 00810 } 00811 break; 00812 } 00813 } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) { 00814 switch (gen_spec[place].type) { 00815 case MISDN_CTYPE_INT: 00816 case MISDN_CTYPE_BOOLINT: 00817 if (general_cfg[place].num) 00818 snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num); 00819 else 00820 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00821 break; 00822 case MISDN_CTYPE_BOOL: 00823 if (general_cfg[place].num) 00824 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no"); 00825 else 00826 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00827 break; 00828 case MISDN_CTYPE_STR: 00829 if ( general_cfg[place].str) { 00830 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str); 00831 } else { 00832 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); 00833 } 00834 break; 00835 default: 00836 snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name); 00837 break; 00838 } 00839 } else { 00840 *buf = 0; 00841 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem); 00842 } 00843 misdn_cfg_unlock(); 00844 }
| void misdn_cfg_get_desc | ( | enum misdn_cfg_elements | elem, | |
| void * | buf, | |||
| int | bufsize, | |||
| void * | buf_default, | |||
| int | bufsize_default | |||
| ) |
Definition at line 618 of file misdn_config.c.
References 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().
00619 { 00620 int place = map[elem]; 00621 struct misdn_cfg_spec *spec = NULL; 00622 00623 /* here comes a hack to replace the (not existing) "name" element with the "ports" element */ 00624 if (elem == MISDN_CFG_GROUPNAME) { 00625 if (!memccpy(buf, ports_description, 0, bufsize)) 00626 memset(buf, 0, 1); 00627 if (buf_default && bufsize_default) 00628 memset(buf_default, 0, 1); 00629 return; 00630 } 00631 00632 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) 00633 spec = (struct misdn_cfg_spec *)port_spec; 00634 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) 00635 spec = (struct misdn_cfg_spec *)gen_spec; 00636 00637 if (!spec || !spec[place].desc) 00638 memset(buf, 0, 1); 00639 else { 00640 if (!memccpy(buf, spec[place].desc, 0, bufsize)) 00641 memset(buf, 0, 1); 00642 if (buf_default && bufsize) { 00643 if (!strcmp(spec[place].def, NO_DEFAULT)) 00644 memset(buf_default, 0, 1); 00645 else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default)) 00646 memset(buf_default, 0, 1); 00647 } 00648 } 00649 }
| enum misdn_cfg_elements misdn_cfg_get_elem | ( | char * | name | ) |
Definition at line 570 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().
00571 { 00572 int pos; 00573 00574 /* here comes a hack to replace the (not existing) "name" element with the "ports" element */ 00575 if (!strcmp(name, "ports")) 00576 return MISDN_CFG_GROUPNAME; 00577 if (!strcmp(name, "name")) 00578 return MISDN_CFG_FIRST;