Fri Aug 24 02:24:00 2007

Asterisk developer's documentation


chan_misdn_config.h File Reference

This graph shows which files directly or indirectly include this file:

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


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_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_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_HOLD_ALLOWED,        /* int (bool) */
00052    MISDN_CFG_EARLY_BCONNECT,      /* int (bool) */
00053    MISDN_CFG_INCOMING_EARLY_AUDIO,      /* int (bool) */
00054    MISDN_CFG_ECHOCANCEL,          /* int */
00055 #ifdef MISDN_1_2
00056    MISDN_CFG_PIPELINE,      /* char[] */
00057 #endif
00058 
00059 #ifdef WITH_BEROEC
00060    MISDN_CFG_BNECHOCANCEL,
00061    MISDN_CFG_BNEC_ANTIHOWL,
00062    MISDN_CFG_BNEC_NLP,
00063    MISDN_CFG_BNEC_ZEROCOEFF,
00064    MISDN_CFG_BNEC_TD,
00065    MISDN_CFG_BNEC_ADAPT,
00066 #endif
00067    MISDN_CFG_NEED_MORE_INFOS,     /* bool */
00068    MISDN_CFG_NOAUTORESPOND_ON_SETUP,     /* bool */
00069    MISDN_CFG_NTTIMEOUT,       /* bool */
00070    MISDN_CFG_BRIDGING,              /* bool */
00071    MISDN_CFG_JITTERBUFFER,             /* int */
00072    MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD,              /* int */
00073    MISDN_CFG_CALLGROUP,           /* ast_group_t */
00074    MISDN_CFG_PICKUPGROUP,         /* ast_group_t */
00075    MISDN_CFG_MAX_IN,              /* int */
00076    MISDN_CFG_MAX_OUT,              /* int */
00077    MISDN_CFG_L1_TIMEOUT,          /* int */
00078    MISDN_CFG_OVERLAP_DIAL,    /* int (bool)*/
00079    MISDN_CFG_MSNS,                /* char[] */
00080    MISDN_CFG_FAXDETECT,           /* char[] */
00081    MISDN_CFG_FAXDETECT_CONTEXT,   /* char[] */
00082    MISDN_CFG_FAXDETECT_TIMEOUT,   /* int */
00083    MISDN_CFG_PTP,                 /* int (bool) */
00084    MISDN_CFG_LAST,
00085    
00086    /* general config items */
00087    MISDN_GEN_FIRST,
00088 #ifndef MISDN_1_2
00089    MISDN_GEN_MISDN_INIT,           /* char[] */
00090 #endif
00091    MISDN_GEN_DEBUG,               /* int */
00092    MISDN_GEN_TRACEFILE,           /* char[] */
00093    MISDN_GEN_BRIDGING,            /* int (bool) */
00094    MISDN_GEN_STOP_TONE,           /* int (bool) */
00095    MISDN_GEN_APPEND_DIGITS2EXTEN, /* int (bool) */
00096    MISDN_GEN_DYNAMIC_CRYPT,       /* int (bool) */
00097    MISDN_GEN_CRYPT_PREFIX,        /* char[] */
00098    MISDN_GEN_CRYPT_KEYS,          /* char[] */
00099    MISDN_GEN_NTDEBUGFLAGS,          /* int */
00100    MISDN_GEN_NTDEBUGFILE,          /* char[] */
00101    MISDN_GEN_LAST
00102 };

enum misdn_cfg_method

Enumerator:
METHOD_STANDARD 
METHOD_ROUND_ROBIN 
METHOD_STANDARD_DEC 

Definition at line 104 of file chan_misdn_config.h.

00104                       {
00105    METHOD_STANDARD = 0,
00106    METHOD_ROUND_ROBIN,
00107    METHOD_STANDARD_DEC
00108 };


Function Documentation

void misdn_cfg_destroy ( void   ) 

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

References misdn_cfg_get_next_port().

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.

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

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

Definition at line 1078 of file misdn_config.c.

References _build_general_config(), _build_port_config(), _enum_array_map(), _fill_defaults(), _free_general_cfg(), _free_port_cfg(), ast_category_browse(), AST_DESTROY_CFG, AST_LOAD_CFG, ast_log(), ast_mutex_init(), ast_variable_browse(), calloc, config, config_mutex, general_cfg, LOG_WARNING, map, max_ports, misdn_cfg_lock(), misdn_cfg_unlock(), MISDN_GEN_LAST, NUM_GEN_ELEMENTS, NUM_PORT_ELEMENTS, port_cfg, and ptp.

Referenced by load_module(), and misdn_cfg_reload().

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.

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

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.

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

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.

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

00664 {
00665    int gn = map[MISDN_CFG_GROUPNAME];
00666 
00667    return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
00668 }

void misdn_cfg_reload ( void   ) 

Definition at line 1057 of file misdn_config.c.

References misdn_cfg_init().

Referenced by reload_config().

01058 {
01059    misdn_cfg_init (0);
01060 }

void misdn_cfg_update_ptp ( void   ) 

Definition at line 988 of file misdn_config.c.

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

Referenced by load_module(), and reload_config().

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 }


Generated on Fri Aug 24 02:24:00 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1