Sat Aug 6 00:39:47 2011

Asterisk developer's documentation


chan_misdn_config.h File Reference

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


Define Documentation

#define BUFFERSIZE   512

Definition at line 19 of file chan_misdn_config.h.

Referenced by _build_port_config(), complete_show_config(), load_module(), misdn_cfg_get_config_string(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_request(), misdn_show_config(), process_ast_dsp(), read_config(), reload_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 21 of file chan_misdn_config.h.

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

enum misdn_cfg_method

Enumerator:
METHOD_STANDARD 
METHOD_ROUND_ROBIN 
METHOD_STANDARD_DEC 

Definition at line 106 of file chan_misdn_config.h.

00106                       {
00107    METHOD_STANDARD = 0,
00108    METHOD_ROUND_ROBIN,
00109    METHOD_STANDARD_DEC
00110 };


Function Documentation

void misdn_cfg_destroy ( void   ) 

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

01114 {
01115    misdn_cfg_lock();
01116 
01117    _free_port_cfg();
01118    _free_general_cfg();
01119 
01120    free(port_cfg);
01121    free(general_cfg);
01122    free(ptp);
01123    free(map);
01124 
01125    misdn_cfg_unlock();
01126    ast_mutex_destroy(&config_mutex);
01127 }

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

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

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

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

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

00757 {
00758    int place;
00759    char tempbuf[BUFFERSIZE] = "";
00760    struct msn_list *iter;
00761 
00762    if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
00763       *buf = 0;
00764       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
00765       return;
00766    }
00767 
00768    place = map[elem];
00769 
00770    misdn_cfg_lock();
00771    if (elem == MISDN_CFG_PTP) {
00772       snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
00773    }
00774    else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
00775       switch (port_spec[place].type) {
00776       case MISDN_CTYPE_INT:
00777       case MISDN_CTYPE_BOOLINT:
00778          if (port_cfg[port][place].num)
00779             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
00780          else if (port_cfg[0][place].num)
00781             snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
00782          else
00783             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00784          break;
00785       case MISDN_CTYPE_BOOL:
00786          if (port_cfg[port][place].num)
00787             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
00788          else if (port_cfg[0][place].num)
00789             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
00790          else
00791             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00792          break;
00793       case MISDN_CTYPE_ASTGROUP:
00794          if (port_cfg[port][place].grp)
00795             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00796                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
00797          else if (port_cfg[0][place].grp)
00798             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
00799                    ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
00800          else
00801             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00802          break;
00803       case MISDN_CTYPE_MSNLIST:
00804          if (port_cfg[port][place].ml)
00805             iter = port_cfg[port][place].ml;
00806          else
00807             iter = port_cfg[0][place].ml;
00808          if (iter) {
00809             for (; iter; iter = iter->next) {
00810                strncat(tempbuf, iter->msn, sizeof(tempbuf) - strlen(tempbuf) - 1);
00811             }
00812             if (strlen(tempbuf) > 1) {
00813                tempbuf[strlen(tempbuf)-2] = 0;
00814             }
00815          }
00816          snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
00817          break;
00818       case MISDN_CTYPE_STR:
00819          if ( port_cfg[port][place].str) {
00820             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
00821          } else if (port_cfg[0][place].str) {
00822             snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
00823          } else {
00824             snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
00825          }
00826          break;
00827       }
00828    } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
00829       switch (gen_spec[place].type) {
00830       case MISDN_CTYPE_INT:
00831       case MISDN_CTYPE_BOOLINT:
00832          if (general_cfg[place].num)
00833             snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
00834          else
00835             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00836          break;
00837       case MISDN_CTYPE_BOOL:
00838          if (general_cfg[place].num)
00839             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
00840          else
00841             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00842          break;
00843       case MISDN_CTYPE_STR:
00844          if ( general_cfg[place].str) {
00845             snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
00846          } else {
00847             snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
00848          }
00849          break;
00850       default:
00851          snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
00852          break;
00853       }
00854    } else {
00855       *buf = 0;
00856       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
00857    }
00858    misdn_cfg_unlock();
00859 }

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

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

00631 {
00632    int place = map[elem];
00633    struct misdn_cfg_spec *spec = NULL;
00634 
00635    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00636    if (elem == MISDN_CFG_GROUPNAME) {
00637       if (!memccpy(buf, ports_description, 0, bufsize))
00638          memset(buf, 0, 1);
00639       if (buf_default && bufsize_default)
00640          memset(buf_default, 0, 1);
00641       return;
00642    }
00643 
00644    if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
00645       spec = (struct misdn_cfg_spec *)port_spec;
00646    else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
00647       spec = (struct misdn_cfg_spec *)gen_spec;
00648       
00649    if (!spec || !spec[place].desc)
00650       memset(buf, 0, 1);
00651    else {
00652       if (!memccpy(buf, spec[place].desc, 0, bufsize))
00653          memset(buf, 0, 1);
00654       if (buf_default && bufsize) {
00655          if (!strcmp(spec[place].def, NO_DEFAULT))
00656             memset(buf_default, 0, 1);
00657          else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default))
00658             memset(buf_default, 0, 1);
00659       }
00660    }
00661 }

enum misdn_cfg_elements misdn_cfg_get_elem ( char *  name  ) 

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

00583 {
00584    int pos;
00585 
00586    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00587    if (!strcmp(name, "ports"))
00588       return MISDN_CFG_GROUPNAME;
00589    if (!strcmp(name, "name"))
00590       return MISDN_CFG_FIRST;
00591 
00592    pos = get_cfg_position (name, PORT_CFG);
00593    if (pos >= 0)
00594       return port_spec[pos].elem;
00595    
00596    pos = get_cfg_position (name, GEN_CFG);
00597    if (pos >= 0)
00598       return gen_spec[pos].elem;
00599    
00600    return MISDN_CFG_FIRST;
00601 }

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

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

00604 {
00605    struct misdn_cfg_spec *spec = NULL;
00606    int place = map[elem];
00607 
00608    /* the ptp hack */
00609    if (elem == MISDN_CFG_PTP) {
00610       memset(buf, 0, 1);
00611       return;
00612    }
00613    
00614    /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
00615    if (elem == MISDN_CFG_GROUPNAME) {
00616       if (!snprintf(buf, bufsize, "ports"))
00617          memset(buf, 0, 1);
00618       return;
00619    }
00620    
00621    if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
00622       spec = (struct misdn_cfg_spec *)port_spec;
00623    else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
00624       spec = (struct misdn_cfg_spec *)gen_spec;
00625 
00626    if (!spec || !memccpy(buf, spec[place].name, 0, bufsize))
00627       memset(buf, 0, 1);
00628 }

int misdn_cfg_get_next_port ( int  port  ) 

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

00862 {
00863    int p = -1;
00864    int gn = map[MISDN_CFG_GROUPNAME];
00865    
00866    misdn_cfg_lock();
00867    for (port++; port <= max_ports; port++) {
00868       if (port_cfg[port][gn].str) {
00869          p = port;
00870          break;
00871       }
00872    }
00873    misdn_cfg_unlock();
00874 
00875    return p;
00876 }

int misdn_cfg_get_next_port_spin ( int  port  ) 

Definition at line 878 of file misdn_config.c.

References misdn_cfg_get_next_port().

Referenced by misdn_request().

00879 {
00880    int p = misdn_cfg_get_next_port(port);
00881    return (p > 0) ? p : misdn_cfg_get_next_port(0);
00882 }

void misdn_cfg_get_ports_string ( char *  ports  ) 

Generate a comma separated list of all active ports.

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

00731 {
00732    char tmp[16];
00733    int l, i;
00734    int gn = map[MISDN_CFG_GROUPNAME];
00735 
00736    *ports = 0;
00737 
00738    misdn_cfg_lock();
00739    for (i = 1; i <= max_ports; i++) {
00740       if (port_cfg[i][gn].str) {
00741          if (ptp[i])
00742             sprintf(tmp, "%dptp,", i);
00743          else
00744             sprintf(tmp, "%d,", i);
00745          strcat(ports, tmp);
00746       }
00747    }
00748    misdn_cfg_unlock();
00749 
00750    if ((l = strlen(ports))) {
00751       /* Strip trailing ',' */
00752       ports[l-1] = 0;
00753    }
00754 }

int misdn_cfg_init ( int  max_ports  ) 

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

01130 {
01131    char config[] = "misdn.conf";
01132    char *cat, *p;
01133    int i;
01134    struct ast_config *cfg;
01135    struct ast_variable *v;
01136 
01137    if (!(cfg = AST_LOAD_CFG(config))) {
01138       ast_log(LOG_WARNING, "missing file: misdn.conf\n");
01139       return -1;
01140    }
01141 
01142    ast_mutex_init(&config_mutex);
01143 
01144    /* Copy the default jb config over global_jbconf */
01145    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
01146 
01147    misdn_cfg_lock();
01148 
01149    if (this_max_ports) {
01150       /* this is the first run */
01151       max_ports = this_max_ports;
01152       map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
01153       if (_enum_array_map())
01154          return -1;
01155       p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
01156                      + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
01157       port_cfg = (union misdn_cfg_pt **)p;
01158       p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
01159       for (i = 0; i <= max_ports; ++i) {
01160          port_cfg[i] = (union misdn_cfg_pt *)p;
01161          p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
01162       }
01163       general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01164       ptp = (int *)calloc(max_ports + 1, sizeof(int));
01165    }
01166    else {
01167       /* misdn reload */
01168       _free_port_cfg();
01169       _free_general_cfg();
01170       memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
01171       memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
01172       memset(ptp, 0, sizeof(int) * (max_ports + 1));
01173    }
01174 
01175    cat = ast_category_browse(cfg, NULL);
01176 
01177    while(cat) {
01178       v = ast_variable_browse(cfg, cat);
01179       if (!strcasecmp(cat, "general")) {
01180          _build_general_config(v);
01181       } else {
01182          _build_port_config(v, cat);
01183       }
01184       cat = ast_category_browse(cfg, cat);
01185    }
01186 
01187    _fill_defaults();
01188 
01189    misdn_cfg_unlock();
01190    AST_DESTROY_CFG(cfg);
01191 
01192    return 0;
01193 }

int misdn_cfg_is_group_method ( char *  group,
enum misdn_cfg_method  meth 
)

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

00696 {
00697    int i, re = 0;
00698    char *method ;
00699 
00700    misdn_cfg_lock();
00701 
00702    method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
00703 
00704    for (i = 1; i <= max_ports; i++) {
00705       if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
00706          if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
00707             method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ? 
00708                     port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
00709       }
00710    }
00711 
00712    if (method) {
00713       switch (meth) {
00714       case METHOD_STANDARD:      re = !strcasecmp(method, "standard");
00715                            break;
00716       case METHOD_ROUND_ROBIN:   re = !strcasecmp(method, "round_robin");
00717                            break;
00718       case METHOD_STANDARD_DEC:  re = !strcasecmp(method, "standard_dec");
00719                            break;
00720       }
00721    }
00722    misdn_cfg_unlock();
00723 
00724    return re;
00725 }

int misdn_cfg_is_msn_valid ( int  port,
char *  msn 
)

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

00664 {
00665    int re = 0;
00666    struct msn_list *iter;
00667 
00668    if (!misdn_cfg_is_port_valid(port)) {
00669       ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
00670       return 0;
00671    }
00672 
00673    misdn_cfg_lock();
00674    if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
00675       iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
00676    else
00677       iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
00678    for (; iter; iter = iter->next) 
00679       if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
00680          re = 1;
00681          break;
00682       }
00683    misdn_cfg_unlock();
00684 
00685    return re;
00686 }

int misdn_cfg_is_port_valid ( int  port  ) 

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

00689 {
00690    int gn = map[MISDN_CFG_GROUPNAME];
00691 
00692    return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
00693 }

void misdn_cfg_reload ( void   ) 

Definition at line 1108 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

01109 {
01110    misdn_cfg_init (0);
01111 }

void misdn_cfg_update_ptp ( void   ) 

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

01040 {
01041 #ifndef MISDN_1_2
01042    char misdn_init[BUFFERSIZE];
01043    char line[BUFFERSIZE];
01044    FILE *fp;
01045    char *tok, *p, *end;
01046    int port;
01047 
01048    misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
01049 
01050    if (!ast_strlen_zero(misdn_init)) {
01051       fp = fopen(misdn_init, "r");
01052       if (fp) {
01053          while(fgets(line, sizeof(line), fp)) {
01054             if (!strncmp(line, "nt_ptp", 6)) {
01055                for (tok = strtok_r(line,",=", &p);
01056                    tok;
01057                    tok = strtok_r(NULL,",=", &p)) {
01058                   port = strtol(tok, &end, 10);
01059                   if (end != tok && misdn_cfg_is_port_valid(port)) {
01060                      misdn_cfg_lock();
01061                      ptp[port] = 1;
01062                      misdn_cfg_unlock();
01063                   }
01064                }
01065             }
01066          }
01067          fclose(fp);
01068       } else {
01069          ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
01070       }
01071    }
01072 #else
01073    int i;
01074    int proto;
01075    char filename[128];
01076    FILE *fp;
01077 
01078    for (i = 1; i <= max_ports; ++i) {
01079       snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
01080       fp = fopen(filename, "r");
01081       if (!fp) {
01082          ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
01083          continue;
01084       }
01085       if (fscanf(fp, "0x%08x", &proto) != 1)
01086          ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
01087       else
01088          ptp[i] = proto & 1<<5 ? 1 : 0;
01089       fclose(fp);
01090    }
01091 #endif
01092 }

struct ast_jb_conf* misdn_get_global_jbconf ( void   ) 

Definition at line 1195 of file misdn_config.c.

References global_jbconf.

Referenced by misdn_new().

01195                                               {
01196    return &global_jbconf;
01197 }


Generated on Sat Aug 6 00:39:47 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7