Thu Jul 9 13:41:02 2009

Asterisk developer's documentation


chan_misdn_config.h File Reference

Interface to mISDN - Config. More...

Go to the source code of this file.

Defines

#define BUFFERSIZE   512

Enumerations

enum  misdn_cfg_elements {
  MISDN_CFG_FIRST = 0, MISDN_CFG_GROUPNAME, MISDN_CFG_ALLOWED_BEARERS, MISDN_CFG_FAR_ALERTING,
  MISDN_CFG_RXGAIN, MISDN_CFG_TXGAIN, MISDN_CFG_TE_CHOOSE_CHANNEL, MISDN_CFG_PMP_L1_CHECK,
  MISDN_CFG_REJECT_CAUSE, MISDN_CFG_ALARM_BLOCK, MISDN_CFG_HDLC, MISDN_CFG_CONTEXT,
  MISDN_CFG_LANGUAGE, MISDN_CFG_MUSICCLASS, MISDN_CFG_CALLERID, MISDN_CFG_METHOD,
  MISDN_CFG_DIALPLAN, MISDN_CFG_LOCALDIALPLAN, MISDN_CFG_CPNDIALPLAN, MISDN_CFG_NATPREFIX,
  MISDN_CFG_INTERNATPREFIX, MISDN_CFG_PRES, MISDN_CFG_SCREEN, MISDN_CFG_ALWAYS_IMMEDIATE,
  MISDN_CFG_NODIALTONE, MISDN_CFG_IMMEDIATE, MISDN_CFG_SENDDTMF, MISDN_CFG_ASTDTMF,
  MISDN_CFG_HOLD_ALLOWED, MISDN_CFG_EARLY_BCONNECT, MISDN_CFG_INCOMING_EARLY_AUDIO, MISDN_CFG_ECHOCANCEL,
  MISDN_CFG_NEED_MORE_INFOS, MISDN_CFG_NOAUTORESPOND_ON_SETUP, MISDN_CFG_NTTIMEOUT, MISDN_CFG_BRIDGING,
  MISDN_CFG_JITTERBUFFER, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, MISDN_CFG_CALLGROUP, MISDN_CFG_PICKUPGROUP,
  MISDN_CFG_MAX_IN, MISDN_CFG_MAX_OUT, MISDN_CFG_L1_TIMEOUT, MISDN_CFG_OVERLAP_DIAL,
  MISDN_CFG_MSNS, MISDN_CFG_FAXDETECT, MISDN_CFG_FAXDETECT_CONTEXT, MISDN_CFG_FAXDETECT_TIMEOUT,
  MISDN_CFG_PTP, MISDN_CFG_LAST, MISDN_GEN_FIRST, MISDN_GEN_MISDN_INIT,
  MISDN_GEN_DEBUG, MISDN_GEN_TRACEFILE, MISDN_GEN_BRIDGING, MISDN_GEN_STOP_TONE,
  MISDN_GEN_APPEND_DIGITS2EXTEN, MISDN_GEN_DYNAMIC_CRYPT, MISDN_GEN_CRYPT_PREFIX, MISDN_GEN_CRYPT_KEYS,
  MISDN_GEN_NTKEEPCALLS, MISDN_GEN_NTDEBUGFLAGS, MISDN_GEN_NTDEBUGFILE, MISDN_GEN_LAST
}
enum  misdn_cfg_method { METHOD_STANDARD = 0, METHOD_ROUND_ROBIN, METHOD_STANDARD_DEC }

Functions

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 max_ports, int reload)
int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth)
int misdn_cfg_is_msn_valid (int port, char *msn)
int misdn_cfg_is_port_valid (int port)
void misdn_cfg_reload (void)
void misdn_cfg_update_ptp (void)
ast_jb_confmisdn_get_global_jbconf (void)


Detailed Description

Interface to mISDN - Config.

Author:
Christian Richter <crich@beronet.com>

Definition in file chan_misdn_config.h.


Define Documentation

#define BUFFERSIZE   512

Definition at line 25 of file chan_misdn_config.h.

Referenced by _build_port_config(), complete_show_config(), handle_cli_misdn_show_config(), load_module(), misdn_cfg_get_config_string(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_request(), process_ast_dsp(), read_config(), and show_config_description().


Enumeration Type Documentation

enum misdn_cfg_elements

Enumerator:
MISDN_CFG_FIRST 
MISDN_CFG_GROUPNAME 
MISDN_CFG_ALLOWED_BEARERS 
MISDN_CFG_FAR_ALERTING 
MISDN_CFG_RXGAIN 
MISDN_CFG_TXGAIN 
MISDN_CFG_TE_CHOOSE_CHANNEL 
MISDN_CFG_PMP_L1_CHECK 
MISDN_CFG_REJECT_CAUSE 
MISDN_CFG_ALARM_BLOCK 
MISDN_CFG_HDLC 
MISDN_CFG_CONTEXT 
MISDN_CFG_LANGUAGE 
MISDN_CFG_MUSICCLASS 
MISDN_CFG_CALLERID 
MISDN_CFG_METHOD 
MISDN_CFG_DIALPLAN 
MISDN_CFG_LOCALDIALPLAN 
MISDN_CFG_CPNDIALPLAN 
MISDN_CFG_NATPREFIX 
MISDN_CFG_INTERNATPREFIX 
MISDN_CFG_PRES 
MISDN_CFG_SCREEN 
MISDN_CFG_ALWAYS_IMMEDIATE 
MISDN_CFG_NODIALTONE 
MISDN_CFG_IMMEDIATE 
MISDN_CFG_SENDDTMF 
MISDN_CFG_ASTDTMF 
MISDN_CFG_HOLD_ALLOWED 
MISDN_CFG_EARLY_BCONNECT 
MISDN_CFG_INCOMING_EARLY_AUDIO 
MISDN_CFG_ECHOCANCEL 
MISDN_CFG_NEED_MORE_INFOS 
MISDN_CFG_NOAUTORESPOND_ON_SETUP 
MISDN_CFG_NTTIMEOUT 
MISDN_CFG_BRIDGING 
MISDN_CFG_JITTERBUFFER 
MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD 
MISDN_CFG_CALLGROUP 
MISDN_CFG_PICKUPGROUP 
MISDN_CFG_MAX_IN 
MISDN_CFG_MAX_OUT 
MISDN_CFG_L1_TIMEOUT 
MISDN_CFG_OVERLAP_DIAL 
MISDN_CFG_MSNS 
MISDN_CFG_FAXDETECT 
MISDN_CFG_FAXDETECT_CONTEXT 
MISDN_CFG_FAXDETECT_TIMEOUT 
MISDN_CFG_PTP 
MISDN_CFG_LAST 
MISDN_GEN_FIRST 
MISDN_GEN_MISDN_INIT 
MISDN_GEN_DEBUG 
MISDN_GEN_TRACEFILE 
MISDN_GEN_BRIDGING 
MISDN_GEN_STOP_TONE 
MISDN_GEN_APPEND_DIGITS2EXTEN 
MISDN_GEN_DYNAMIC_CRYPT 
MISDN_GEN_CRYPT_PREFIX 
MISDN_GEN_CRYPT_KEYS 
MISDN_GEN_NTKEEPCALLS 
MISDN_GEN_NTDEBUGFLAGS 
MISDN_GEN_NTDEBUGFILE 
MISDN_GEN_LAST 

Definition at line 27 of file chan_misdn_config.h.

00027                         {
00028 
00029    /* port config items */
00030    MISDN_CFG_FIRST = 0,
00031    MISDN_CFG_GROUPNAME,           /* char[] */
00032    MISDN_CFG_ALLOWED_BEARERS,           /* char[] */
00033    MISDN_CFG_FAR_ALERTING,        /* int (bool) */
00034    MISDN_CFG_RXGAIN,              /* int */
00035    MISDN_CFG_TXGAIN,              /* int */
00036    MISDN_CFG_TE_CHOOSE_CHANNEL,   /* int (bool) */
00037    MISDN_CFG_PMP_L1_CHECK,        /* int (bool) */
00038    MISDN_CFG_REJECT_CAUSE,    /* int */
00039    MISDN_CFG_ALARM_BLOCK,        /* int (bool) */
00040    MISDN_CFG_HDLC,                /* int (bool) */
00041    MISDN_CFG_CONTEXT,             /* char[] */
00042    MISDN_CFG_LANGUAGE,            /* char[] */
00043    MISDN_CFG_MUSICCLASS,            /* char[] */
00044    MISDN_CFG_CALLERID,            /* char[] */
00045    MISDN_CFG_METHOD,              /* char[] */
00046    MISDN_CFG_DIALPLAN,            /* int */
00047    MISDN_CFG_LOCALDIALPLAN,       /* int */
00048    MISDN_CFG_CPNDIALPLAN,       /* int */
00049    MISDN_CFG_NATPREFIX,           /* char[] */
00050    MISDN_CFG_INTERNATPREFIX,      /* char[] */
00051    MISDN_CFG_PRES,                /* int */
00052    MISDN_CFG_SCREEN,              /* int */
00053    MISDN_CFG_ALWAYS_IMMEDIATE,    /* int (bool) */
00054    MISDN_CFG_NODIALTONE,    /* int (bool) */
00055    MISDN_CFG_IMMEDIATE,           /* int (bool) */
00056    MISDN_CFG_SENDDTMF,           /* int (bool) */
00057    MISDN_CFG_ASTDTMF,            /* int (bool) */
00058    MISDN_CFG_HOLD_ALLOWED,        /* int (bool) */
00059    MISDN_CFG_EARLY_BCONNECT,      /* int (bool) */
00060    MISDN_CFG_INCOMING_EARLY_AUDIO,      /* int (bool) */
00061    MISDN_CFG_ECHOCANCEL,          /* int */
00062 #ifdef MISDN_1_2
00063    MISDN_CFG_PIPELINE,      /* char[] */
00064 #endif
00065 
00066 #ifdef WITH_BEROEC
00067    MISDN_CFG_BNECHOCANCEL,
00068    MISDN_CFG_BNEC_ANTIHOWL,
00069    MISDN_CFG_BNEC_NLP,
00070    MISDN_CFG_BNEC_ZEROCOEFF,
00071    MISDN_CFG_BNEC_TD,
00072    MISDN_CFG_BNEC_ADAPT,
00073 #endif
00074    MISDN_CFG_NEED_MORE_INFOS,     /* bool */
00075    MISDN_CFG_NOAUTORESPOND_ON_SETUP,     /* bool */
00076    MISDN_CFG_NTTIMEOUT,       /* bool */
00077    MISDN_CFG_BRIDGING,              /* bool */
00078    MISDN_CFG_JITTERBUFFER,             /* int */
00079    MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD,              /* int */
00080    MISDN_CFG_CALLGROUP,           /* ast_group_t */
00081    MISDN_CFG_PICKUPGROUP,         /* ast_group_t */
00082    MISDN_CFG_MAX_IN,              /* int */
00083    MISDN_CFG_MAX_OUT,              /* int */
00084    MISDN_CFG_L1_TIMEOUT,          /* int */
00085    MISDN_CFG_OVERLAP_DIAL,    /* int (bool)*/
00086    MISDN_CFG_MSNS,                /* char[] */
00087    MISDN_CFG_FAXDETECT,           /* char[] */
00088    MISDN_CFG_FAXDETECT_CONTEXT,   /* char[] */
00089    MISDN_CFG_FAXDETECT_TIMEOUT,   /* int */
00090    MISDN_CFG_PTP,                 /* int (bool) */
00091    MISDN_CFG_LAST,
00092    
00093    /* general config items */
00094    MISDN_GEN_FIRST,
00095 #ifndef MISDN_1_2
00096    MISDN_GEN_MISDN_INIT,           /* char[] */
00097 #endif
00098    MISDN_GEN_DEBUG,               /* int */
00099    MISDN_GEN_TRACEFILE,           /* char[] */
00100    MISDN_GEN_BRIDGING,            /* int (bool) */
00101    MISDN_GEN_STOP_TONE,           /* int (bool) */
00102    MISDN_GEN_APPEND_DIGITS2EXTEN, /* int (bool) */
00103    MISDN_GEN_DYNAMIC_CRYPT,       /* int (bool) */
00104    MISDN_GEN_CRYPT_PREFIX,        /* char[] */
00105    MISDN_GEN_CRYPT_KEYS,          /* char[] */
00106    MISDN_GEN_NTKEEPCALLS,          /* int (bool) */
00107    MISDN_GEN_NTDEBUGFLAGS,          /* int */
00108    MISDN_GEN_NTDEBUGFILE,          /* char[] */
00109    MISDN_GEN_LAST
00110 };

enum misdn_cfg_method

Enumerator:
METHOD_STANDARD 
METHOD_ROUND_ROBIN 
METHOD_STANDARD_DEC 

Definition at line 112 of file chan_misdn_config.h.

00112                       {
00113    METHOD_STANDARD = 0,
00114    METHOD_ROUND_ROBIN,
00115    METHOD_STANDARD_DEC
00116 };


Function Documentation

void misdn_cfg_destroy ( void   ) 

Definition at line 1088 of file misdn_config.c.

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

Referenced by unload_module().

01089 {
01090    misdn_cfg_lock();
01091 
01092    _free_port_cfg();
01093    _free_general_cfg();
01094 
01095    ast_free(port_cfg);
01096    ast_free(general_cfg);
01097    ast_free(ptp);
01098    ast_free(map);
01099 
01100    misdn_cfg_unlock();
01101    ast_mutex_destroy(&config_mutex);
01102 }

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

Definition at line 519 of file misdn_config.c.

References misdn_cfg_pt::any, ast_copy_string(), 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, S_OR, 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().

00520 {
00521    int place;
00522 
00523    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00524       memset(buf, 0, bufsize);
00525       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
00526       return;
00527    }
00528 
00529    misdn_cfg_lock();
00530    if (elem == MISDN_CFG_PTP) {
00531       if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
00532          memset(buf, 0, bufsize);
00533    } else {
00534       if ((place = map[elem]) < 0) {
00535          memset(buf, 0, bufsize);
00536          ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
00537       } else {
00538          if (elem < MISDN_CFG_LAST) {
00539             switch (port_spec[place].type) {
00540             case MISDN_CTYPE_STR:
00541                if (port_cfg[port][place].str) {
00542                   ast_copy_string(buf, port_cfg[port][place].str, bufsize);
00543                } else if (port_cfg[0][place].str) {
00544                   ast_copy_string(buf, port_cfg[0][place].str, bufsize);
00545                } else
00546                   memset(buf, 0, bufsize);
00547                break;
00548             default:
00549                if (port_cfg[port][place].any)
00550                   memcpy(buf, port_cfg[port][place].any, bufsize);
00551                else if (port_cfg[0][place].any)
00552                   memcpy(buf, port_cfg[0][place].any, bufsize);
00553                else
00554                   memset(buf, 0, bufsize);
00555             }
00556          } else {
00557             switch (gen_spec[place].type) {
00558             case MISDN_CTYPE_STR:
00559                ast_copy_string(buf, S_OR(general_cfg[place].str, ""), bufsize);
00560                break;
00561             default:
00562                if (general_cfg[place].any)
00563                   memcpy(buf, general_cfg[place].any, bufsize);
00564                else
00565                   memset(buf, 0, bufsize);
00566             }
00567          }
00568       }
00569    }
00570    misdn_cfg_unlock();
00571 }

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, num, port_cfg, port_spec, ptp, str, and type.

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                strncat(tempbuf, iter->msn, sizeof(tempbuf) - strlen(tempbuf) - 1);
00799             }
00800             if (strlen(tempbuf) > 1) {
00801                tempbuf[strlen(tempbuf)-2] = 0;
00802             }
00803          }
00804          snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
00805          break;
00806       case MISDN_CTYPE_STR:
00807          if ( port_cfg[port][place].str) {
00808             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
00809          } else if (port_cfg[0][place].str) {
00810             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
00811          } else {
00812             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00813          }
00814          break;
00815       }
00816    } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
00817       switch (gen_spec[place].type) {
00818       case MISDN_CTYPE_INT:
00819       case MISDN_CTYPE_BOOLINT:
00820          if (general_cfg[place].num)
00821             snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
00822          else
00823             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00824          break;
00825       case MISDN_CTYPE_BOOL:
00826          if (general_cfg[place].num)
00827             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
00828          else
00829             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00830          break;
00831       case MISDN_CTYPE_STR:
00832          if ( general_cfg[place].str) {
00833             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
00834          } else {
00835             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00836          }
00837          break;
00838       default:
00839          snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
00840          break;
00841       }
00842    } else {
00843       *buf = 0;
00844       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
00845    }
00846    misdn_cfg_unlock();
00847 }

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

Definition at line 620 of file misdn_config.c.

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

00621 {
00622    int place = map[elem];
00623    struct misdn_cfg_spec *spec = NULL;
00624 
00625    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00626    if (elem == MISDN_CFG_GROUPNAME) {
00627       ast_copy_string(buf, ports_description, bufsize);
00628       if (buf_default && bufsize_default)
00629          memset(buf_default, 0, 1);
00630       return;
00631    }
00632 
00633    if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
00634       spec = (struct misdn_cfg_spec *)port_spec;
00635    else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
00636       spec = (struct misdn_cfg_spec *)gen_spec;
00637       
00638    if (!spec || !spec[place].desc)
00639       memset(buf, 0, 1);
00640    else {
00641       ast_copy_string(buf, spec[place].desc, bufsize);
00642       if (buf_default && bufsize) {
00643          if (!strcmp(spec[place].def, NO_DEFAULT))
00644             memset(buf_default, 0, 1);
00645          else
00646             ast_copy_string(buf_default, spec[place].def, bufsize_default);
00647       }
00648    }
00649 }

enum misdn_cfg_elements misdn_cfg_get_elem ( char *  name  ) 

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

00574 {
00575    int pos;
00576 
00577    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00578    if (!strcmp(name, "ports"))
00579       return MISDN_CFG_GROUPNAME;
00580    if (!strcmp(name, "name"))
00581       return MISDN_CFG_FIRST;
00582 
00583    pos = get_cfg_position(name, PORT_CFG);
00584    if (pos >= 0)
00585       return port_spec[pos].elem;
00586    
00587    pos = get_cfg_position(name, GEN_CFG);
00588    if (pos >= 0)
00589       return gen_spec[pos].elem;
00590    
00591    return MISDN_CFG_FIRST;
00592 }

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

Definition at line 594 of file misdn_config.c.

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

00595 {
00596    struct misdn_cfg_spec *spec = NULL;
00597    int place = map[elem];
00598 
00599    /* the ptp hack */
00600    if (elem == MISDN_CFG_PTP) {
00601       memset(buf, 0, 1);
00602       return;
00603    }
00604    
00605    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00606    if (elem == MISDN_CFG_GROUPNAME) {
00607       if (!snprintf(buf, bufsize, "ports"))
00608          memset(buf, 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    ast_copy_string(buf, spec ? spec[place].name : "", bufsize);
00618 }

int misdn_cfg_get_next_port ( int  port  ) 

Definition at line 849 of file misdn_config.c.

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

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

00850 {
00851    int p = -1;
00852    int gn = map[MISDN_CFG_GROUPNAME];
00853    
00854    misdn_cfg_lock();
00855    for (port++; port <= max_ports; port++) {
00856       if (port_cfg[port][gn].str) {
00857          p = port;
00858          break;
00859       }
00860    }
00861    misdn_cfg_unlock();
00862 
00863    return p;
00864 }

int misdn_cfg_get_next_port_spin ( int  port  ) 

Definition at line 866 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

00867 {
00868    int p = misdn_cfg_get_next_port(port);
00869    return (p > 0) ? p : misdn_cfg_get_next_port(0);
00870 }

void misdn_cfg_get_ports_string ( char *  ports  ) 

Generate a comma separated list of all active ports.

Definition at line 718 of file misdn_config.c.

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

Referenced by load_module().

00719 {
00720    char tmp[16];
00721    int l, i;
00722    int gn = map[MISDN_CFG_GROUPNAME];
00723 
00724    *ports = 0;
00725 
00726    misdn_cfg_lock();
00727    for (i = 1; i <= max_ports; i++) {
00728       if (port_cfg[i][gn].str) {
00729          if (ptp[i])
00730             sprintf(tmp, "%dptp,", i);
00731          else
00732             sprintf(tmp, "%d,", i);
00733          strcat(ports, tmp);
00734       }
00735    }
00736    misdn_cfg_unlock();
00737 
00738    if ((l = strlen(ports))) {
00739       /* Strip trailing ',' */
00740       ports[l-1] = 0;
00741    }
00742 }

int misdn_cfg_init ( int  max_ports,
int  reload 
)

Definition at line 1104 of file misdn_config.c.

References _build_general_config(), _build_port_config(), _enum_array_map(), _fill_defaults(), _free_general_cfg(), _free_port_cfg(), ast_calloc, ast_category_browse(), AST_DESTROY_CFG, AST_LOAD_CFG, ast_log(), ast_mutex_init(), ast_variable_browse(), config, CONFIG_FLAG_FILEUNCHANGED, config_mutex, CONFIG_STATUS_FILEUNCHANGED, default_jbconf, general_cfg, global_jbconf, 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().

01105 {
01106    char config[] = "misdn.conf";
01107    char *cat, *p;
01108    int i;
01109    struct ast_config *cfg;
01110    struct ast_variable *v;
01111    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
01112 
01113    if (!(cfg = AST_LOAD_CFG(config, config_flags))) {
01114       ast_log(LOG_WARNING, "missing file: misdn.conf\n");
01115       return -1;
01116    } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
01117       return 0;
01118 
01119    ast_mutex_init(&config_mutex);
01120 
01121    /* Copy the default jb config over global_jbconf */
01122    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
01123 
01124    misdn_cfg_lock();
01125 
01126    if (this_max_ports) {
01127       /* this is the first run */
01128       max_ports = this_max_ports;
01129       map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
01130       if (_enum_array_map())
01131          return -1;
01132       p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
01133                      + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
01134       port_cfg = (union misdn_cfg_pt **)p;
01135       p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
01136       for (i = 0; i <= max_ports; ++i) {
01137          port_cfg[i] = (union misdn_cfg_pt *)p;
01138          p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
01139       }
01140       general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01141       ptp = ast_calloc(max_ports + 1, sizeof(int));
01142    }
01143    else {
01144       /* misdn reload */
01145       _free_port_cfg();
01146       _free_general_cfg();
01147       memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
01148       memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01149       memset(ptp, 0, sizeof(int) * (max_ports + 1));
01150    }
01151 
01152    cat = ast_category_browse(cfg, NULL);
01153 
01154    while(cat) {
01155       v = ast_variable_browse(cfg, cat);
01156       if (!strcasecmp(cat, "general")) {
01157          _build_general_config(v);
01158       } else {
01159          _build_port_config(v, cat);
01160       }
01161       cat = ast_category_browse(cfg, cat);
01162    }
01163 
01164    _fill_defaults();
01165 
01166    misdn_cfg_unlock();
01167    AST_DESTROY_CFG(cfg);
01168 
01169    return 0;
01170 }

int misdn_cfg_is_group_method ( char *  group,
enum misdn_cfg_method  meth 
)

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

Referenced by misdn_request().

00684 {
00685    int i, re = 0;
00686    char *method ;
00687 
00688    misdn_cfg_lock();
00689 
00690    method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
00691 
00692    for (i = 1; i <= max_ports; i++) {
00693       if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
00694          if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
00695             method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 
00696                     port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
00697       }
00698    }
00699 
00700    if (method) {
00701       switch (meth) {
00702       case METHOD_STANDARD:      re = !strcasecmp(method, "standard");
00703                            break;
00704       case METHOD_ROUND_ROBIN:   re = !strcasecmp(method, "round_robin");
00705                            break;
00706       case METHOD_STANDARD_DEC:  re = !strcasecmp(method, "standard_dec");
00707                            break;
00708       }
00709    }
00710    misdn_cfg_unlock();
00711 
00712    return re;
00713 }

int misdn_cfg_is_msn_valid ( int  port,
char *  msn 
)

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

00652 {
00653    int re = 0;
00654    struct msn_list *iter;
00655 
00656    if (!misdn_cfg_is_port_valid(port)) {
00657       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
00658       return 0;
00659    }
00660 
00661    misdn_cfg_lock();
00662    if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
00663       iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
00664    else
00665       iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
00666    for (; iter; iter = iter->next) 
00667       if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
00668          re = 1;
00669          break;
00670       }
00671    misdn_cfg_unlock();
00672 
00673    return re;
00674 }

int misdn_cfg_is_port_valid ( int  port  ) 

Definition at line 676 of file misdn_config.c.

References map, max_ports, MISDN_CFG_GROUPNAME, port_cfg, and str.

Referenced by misdn_cfg_get(), misdn_cfg_get_config_string(), misdn_cfg_is_msn_valid(), and misdn_cfg_update_ptp().

00677 {
00678    int gn = map[MISDN_CFG_GROUPNAME];
00679 
00680    return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
00681 }

void misdn_cfg_reload ( void   ) 

Definition at line 1083 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

01084 {
01085    misdn_cfg_init(0, 1);
01086 }

void misdn_cfg_update_ptp ( void   ) 

Definition at line 1014 of file misdn_config.c.

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

Referenced by load_module(), and reload_config().

01015 {
01016 #ifndef MISDN_1_2
01017    char misdn_init[BUFFERSIZE];
01018    char line[BUFFERSIZE];
01019    FILE *fp;
01020    char *tok, *p, *end;
01021    int port;
01022 
01023    misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
01024 
01025    if (!ast_strlen_zero(misdn_init)) {
01026       fp = fopen(misdn_init, "r");
01027       if (fp) {
01028          while(fgets(line, sizeof(line), fp)) {
01029             if (!strncmp(line, "nt_ptp", 6)) {
01030                for (tok = strtok_r(line,",=", &p);
01031                    tok;
01032                    tok = strtok_r(NULL,",=", &p)) {
01033                   port = strtol(tok, &end, 10);
01034                   if (end != tok && misdn_cfg_is_port_valid(port)) {
01035                      misdn_cfg_lock();
01036                      ptp[port] = 1;
01037                      misdn_cfg_unlock();
01038                   }
01039                }
01040             }
01041          }
01042          fclose(fp);
01043       } else {
01044          ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
01045       }
01046    }
01047 #else
01048    int i;
01049    int proto;
01050    char filename[128];
01051    FILE *fp;
01052 
01053    for (i = 1; i <= max_ports; ++i) {
01054       snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
01055       fp = fopen(filename, "r");
01056       if (!fp) {
01057          ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
01058          continue;
01059       }
01060       if (fscanf(fp, "0x%08x", &proto) != 1)
01061          ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
01062       else
01063          ptp[i] = proto & 1<<5 ? 1 : 0;
01064       fclose(fp);
01065    }
01066 #endif
01067 }

struct ast_jb_conf* misdn_get_global_jbconf ( void   ) 

Definition at line 1172 of file misdn_config.c.

References global_jbconf.

Referenced by misdn_new().

01172                                               {
01173    return &global_jbconf;
01174 }


Generated on Thu Jul 9 13:41:02 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7