[asterisk-commits] nadi: branch group/trunk-cm-csel-hash r47795 -
/team/group/trunk-cm-csel-hash...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Nov 17 08:59:07 MST 2006
Author: nadi
Date: Fri Nov 17 09:59:06 2006
New Revision: 47795
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47795
Log:
no more crypting, lots of code reworking
Modified:
team/group/trunk-cm-csel-hash/channels/chan_misdn.c
Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?view=diff&rev=47795&r1=47794&r2=47795
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Fri Nov 17 09:59:06 2006
@@ -245,9 +245,7 @@
static const int prefformat = AST_FORMAT_ALAW;
static char tracefile[BUFFERSIZE];
static volatile int glob_channel = 0;
-
-static char ** misdn_key_vector = NULL;
-static int misdn_key_vector_size = 0;
+static volatile int module_initialized = 0;
static int * misdn_in_calls;
static int * misdn_out_calls;
@@ -278,13 +276,6 @@
"Set the path to the massively growing trace file, if you want that." },
{ "bridging", "yes",
"Set this to yes if you want mISDN_dsp to bridge the calls in HW." },
- { "dynamic_crypt", "no",
- "Wether to look out for dynamic crypting attempts." },
- { "crypt_prefix", 0,
- "What is used for crypting Protocol." },
- { "crypt_keys", 0,
- "Keys for cryption, you reference them in the dialplan\n"
- "\tLater also in dynamic encr." },
{ "ntdebugflags", "0",
"No description yet."},
{ "ntdebugfile", "/var/log/misdn-nt.log",
@@ -297,9 +288,6 @@
MCFG_MISDN_INIT,
MCFG_TRACEFILE,
MCFG_BRIDGING,
- MCFG_DYNAMIC_CRYPT,
- MCFG_CRYPT_PREFIX,
- MCFG_CRYPT_KEYS,
MCFG_NTDEBUGFLAGS,
MCFG_NTDEBUGFILE,
MCFG_GENERAL_END
@@ -605,8 +593,12 @@
static int config_reload (void)
{
- config_destroy();
- return config_load();
+ if (ast_atomic_fetchadd_int(&module_initialized, 0)) {
+ config_destroy();
+ return config_load();
+ }
+ ast_log(LOG_WARNING, "config_reload called with config not yet initialized.\n");
+ return -1;
}
/* Logger Function */
@@ -1057,7 +1049,7 @@
}
/* misdn_pvt Helper */
-static struct misdn_pvt * misdn_pvt_init (int orig)
+static struct misdn_pvt * misdn_pvt_new (int orig)
{
struct misdn_pvt *p = calloc(1, sizeof(struct misdn_pvt));
@@ -1068,8 +1060,8 @@
p->sm = statemachine_create(p, MISDN_NOTHING, misdn_state_table,
sizeof(misdn_state_table) / sizeof(struct statemachine_transition),
- send_event,
- log_event);
+ send_event, log_event);
+
p->orginator = orig;
p->need_queue_hangup = 1;
p->need_hangup = 1;
@@ -1077,6 +1069,15 @@
p->overlap_dial_task = -1;
return p;
+}
+
+static void misdn_pvt_destroy (struct misdn_pvt *p)
+{
+ if (!p)
+ return;
+
+ statemachine_destroy(p->sm);
+ free(p);
}
static inline void misdn_pvt_queue (struct misdn_pvt *p)
@@ -1537,7 +1538,7 @@
static void sighandler (int sig)
{}
-static void* misdn_tasks_thread_func (void *data)
+static void * misdn_tasks_thread_func (void *data)
{
int wait;
struct sigaction sa;
@@ -1611,17 +1612,17 @@
return task_id;
}
-static int misdn_tasks_add (int timeout, ast_sched_cb callback, void *data)
+static inline int misdn_tasks_add (int timeout, ast_sched_cb callback, void *data)
{
return _misdn_tasks_add_variable(timeout, callback, data, 0);
}
-static int misdn_tasks_add_variable (int timeout, ast_sched_cb callback, void *data)
+static inline int misdn_tasks_add_variable (int timeout, ast_sched_cb callback, void *data)
{
return _misdn_tasks_add_variable(timeout, callback, data, 1);
}
-static void misdn_tasks_remove (int task_id)
+static inline void misdn_tasks_remove (int task_id)
{
ast_sched_del(misdn_tasks, task_id);
}
@@ -1842,8 +1843,7 @@
}
misdn_pvt_dequeue(p);
- statemachine_destroy(p->sm);
- free(p);
+ misdn_pvt_destroy(p);
}
static void misdn_transfer_bc (struct misdn_pvt *p, struct misdn_pvt *holded_p)
@@ -2348,28 +2348,21 @@
};
/* Channel configuration */
-static int config_ch_pres_screen (struct misdn_pvt *p)
-{
- struct ast_channel *ast;
- struct misdn_bchannel *bc;
+static int config_pvt_pres_screen (struct misdn_pvt *p)
+{
+ struct ast_channel *ast = p ? p->ast : NULL;
+ struct misdn_bchannel *bc = p ? p->bc : NULL;
int pres = 0,
screen = 0;
- if (!p) {
- ast_log(LOG_WARNING, "Cannot configure without misdn_pvt\n");
- return -1;
- }
-
- ast = p->ast;
- bc = p->bc;
- if (!ast || !bc) {
- ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");
+ if (!p || !ast || !bc) {
+ ast_log(LOG_WARNING, "Cannot configure without misdn_pvt, ast or bc!\n");
return -1;
}
if (p->orginator == ORG_AST) {
/*misdn_call*/
- chan_misdn_log(5, bc->port, "config_ch_pres_screen: Getting Config\n");
+ chan_misdn_log(5, bc->port, "config_pvt_pres_screen: Getting Config\n");
cm_get_int(misdn_cm, pres, PORT, MCFG_PRESENTATION, bc->port);
cm_get_int(misdn_cm, screen, PORT, MCFG_SCREEN, bc->port);
chan_misdn_log(2, bc->port, " --> pres: %d screen: %d\n", pres, screen);
@@ -2445,14 +2438,96 @@
return 0;
}
-static int config_ch_hdlc (struct misdn_pvt *p)
+static void config_pvt_jitterbuffer (struct misdn_pvt *p)
{
struct misdn_bchannel *bc = p->bc;
+ int len = p->jb_len,
+ threshold = p->jb_upper_threshold;
+
+ chan_misdn_log(5, bc->port, "config_pvt_jitterbuffer: Called\n");
+
+ if (!len) {
+ chan_misdn_log(2, bc->port, "config_pvt_jitterbuffer: Deactivating Jitterbuffer\n");
+ bc->nojitter = 1;
+ } else {
+ if (len <= 100 || len > 8000) {
+ chan_misdn_log(0, bc->port, "config_pvt_jitterbuffer: Jitterbuffer out of Bounds, setting to 1000\n");
+ len = 1000;
+ }
+ if (threshold > len)
+ chan_misdn_log(0, bc->port, "config_pvt_jitterbuffer: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
+ if (p->jb) {
+ chan_misdn_log(0, bc->port, "config_pvt_jitterbuffer: We've got a Jitterbuffer Already on this port.\n");
+ misdn_jb_destroy(p->jb);
+ p->jb = NULL;
+ }
+ p->jb = misdn_jb_init(len, threshold);
+ if (!p->jb)
+ bc->nojitter = 1;
+ }
+}
+
+static void config_bc_echocancel (struct misdn_bchannel *bc)
+{
+ char buf[BUFFERSIZE];
+
+ if (cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_ECHOCANCEL, bc->port)) {
+ bc->ec_deftaps = 0;
+ } else {
+ if (!strcasecmp(buf, "yes") || !strcasecmp(buf, "y") || !strcasecmp(buf, "on"))
+ bc->ec_deftaps = 128;
+ else if (sscanf(buf, "%d", &bc->ec_deftaps) != 1)
+ bc->ec_deftaps = 0;
+ }
+ bc->ec_enable = bc->ec_deftaps ? 1 : 0;
+}
+
+static int config_pvt (struct misdn_pvt *p, int orig)
+{
+ struct ast_channel *ast = p ? p->ast : NULL;
+ struct misdn_bchannel *bc = p ? p->bc : NULL;
+ char faxdetect[BUFFERSIZE],
+ buf[BUFFERSIZE];
+ ast_group_t pg,
+ cg;
int hdlc;
- if (cm_get_bool(misdn_cm, hdlc, PORT, MCFG_HDLC, bc->port) || hdlc < 0)
- hdlc = 0;
- if (hdlc) {
+ if (!p || !ast || !bc) {
+ ast_log(LOG_WARNING, "Cannot configure without misdn_pvt, ast or bc!\n");
+ return -1;
+ }
+
+ chan_misdn_log(2, bc->port, "config_pvt: getting config\n");
+
+ cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_LANGUAGE, bc->port);
+ ast_string_field_set(ast, language, buf);
+
+ cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_MUSICCLASS, bc->port);
+ ast_string_field_set(ast, musicclass, buf);
+
+ cm_get_int(misdn_cm, bc->txgain, PORT, MCFG_TXGAIN, bc->port);
+ cm_get_int(misdn_cm, bc->rxgain, PORT, MCFG_RXGAIN, bc->port);
+ cm_get_bool(misdn_cm, bc->send_dtmf, PORT, MCFG_SENDDTMF, bc->port);
+ cm_get_int(misdn_cm, bc->need_more_infos, PORT, MCFG_NEED_MORE_INFOS, bc->port);
+ cm_get_bool(misdn_cm, bc->early_bconnect, PORT, MCFG_EARLY_BCONNECT, bc->port);
+
+ bc->AOCDtype = Fac_None;
+ config_bc_echocancel(bc);
+
+ cm_get_int(misdn_cm, p->incoming_early_audio, PORT, MCFG_INCOMING_EARLY_AUDIO, bc->port);
+ cm_get_int(misdn_cm, p->nttimeout, PORT, MCFG_NTTIMEOUT, bc->port);
+ cm_get(misdn_cm, p->allowed_bearers, sizeof(p->allowed_bearers), PORT, MCFG_ALLOWED_BEARERS, bc->port);
+
+ cm_get(misdn_cm, p->context, sizeof(p->context), PORT, MCFG_CONTEXT, bc->port);
+ ast_copy_string(ast->context, p->context, sizeof(ast->context));
+
+ cm_get_int(misdn_cm, p->jb_len, PORT, MCFG_JITTERBUFFER, bc->port);
+ cm_get_int(misdn_cm, p->jb_upper_threshold, PORT, MCFG_JITTERBUFFER_UPPER_THRES, bc->port);
+ config_pvt_jitterbuffer(p);
+
+ p->overlap_dial_task = -1;
+
+ if (!cm_get_bool(misdn_cm, hdlc, PORT, MCFG_HDLC, bc->port) && hdlc) {
switch (bc->capability) {
case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:
case INFO_CAPABILITY_DIGITAL_RESTRICTED:
@@ -2461,108 +2536,11 @@
}
}
- return 0;
-}
-
-static void config_ch_jitterbuffer (struct misdn_pvt *p)
-{
- struct misdn_bchannel *bc = p->bc;
- int len = p->jb_len,
- threshold = p->jb_upper_threshold;
-
- chan_misdn_log(5, bc->port, "config_ch_jitterbuffer: Called\n");
-
- if (!len) {
- chan_misdn_log(2, bc->port, "config_ch_jitterbuffer: Deactivating Jitterbuffer\n");
- bc->nojitter = 1;
- } else {
- if (len <= 100 || len > 8000) {
- chan_misdn_log(0, bc->port, "config_ch_jitterbuffer: Jitterbuffer out of Bounds, setting to 1000\n");
- len = 1000;
- }
- if (threshold > len)
- chan_misdn_log(0, bc->port, "config_ch_jitterbuffer: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
- if (p->jb) {
- chan_misdn_log(0, bc->port, "config_ch_jitterbuffer: We've got a Jitterbuffer Already on this port.\n");
- misdn_jb_destroy(p->jb);
- p->jb = NULL;
- }
- p->jb = misdn_jb_init(len, threshold);
- if (!p->jb)
- bc->nojitter = 1;
- }
-}
-
-static void config_bc_echocancel (struct misdn_bchannel *bc)
-{
- char buf[BUFFERSIZE];
-
- if (cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_ECHOCANCEL, bc->port)) {
- bc->ec_deftaps = 0;
- } else {
- if (!strcasecmp(buf, "yes") || !strcasecmp(buf, "y") || !strcasecmp(buf, "on"))
- bc->ec_deftaps = 128;
- else if (!strcasecmp(buf, "no") || !strcasecmp(buf, "n") || !strcasecmp(buf, "off"))
- bc->ec_deftaps = 0;
- else if (sscanf(buf, "%d", &bc->ec_deftaps) != 1)
- bc->ec_deftaps = 0;
- }
- bc->ec_enable = bc->ec_deftaps ? 1 : 0;
-}
-
-static int config_ch (struct misdn_pvt *p, int orig)
-{
- struct ast_channel *ast;
- struct misdn_bchannel *bc;
- char faxdetect[BUFFERSIZE],
- buf[BUFFERSIZE];
- ast_group_t pg,
- cg;
-
- if (!p) {
- ast_log(LOG_WARNING, "Cannot configure without misdn_pvt\n");
- return -1;
- }
-
- ast = p->ast;
- bc = p->bc;
- if (!ast || !bc) {
- ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");
- return -1;
- }
-
- chan_misdn_log(2, bc->port, "config_ch: Getting Config\n");
-
- cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_LANGUAGE, bc->port);
- ast_string_field_set(ast, language, buf);
-
- cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_MUSICCLASS, bc->port);
- ast_string_field_set(ast, musicclass, buf);
-
- cm_get_int(misdn_cm, bc->txgain, PORT, MCFG_TXGAIN, bc->port);
- cm_get_int(misdn_cm, bc->rxgain, PORT, MCFG_RXGAIN, bc->port);
- cm_get_bool(misdn_cm, bc->send_dtmf, PORT, MCFG_SENDDTMF, bc->port);
- cm_get_int(misdn_cm, bc->need_more_infos, PORT, MCFG_NEED_MORE_INFOS, bc->port);
- cm_get_bool(misdn_cm, bc->early_bconnect, PORT, MCFG_EARLY_BCONNECT, bc->port);
- bc->AOCDtype = Fac_None;
- config_bc_echocancel(bc);
-
- cm_get_int(misdn_cm, p->incoming_early_audio, PORT, MCFG_INCOMING_EARLY_AUDIO, bc->port);
- cm_get_int(misdn_cm, p->jb_len, PORT, MCFG_JITTERBUFFER, bc->port);
- cm_get_int(misdn_cm, p->jb_upper_threshold, PORT, MCFG_JITTERBUFFER_UPPER_THRES, bc->port);
- cm_get_int(misdn_cm, p->nttimeout, PORT, MCFG_NTTIMEOUT, bc->port);
- cm_get(misdn_cm, p->allowed_bearers, sizeof(p->allowed_bearers), PORT, MCFG_ALLOWED_BEARERS, bc->port);
- cm_get(misdn_cm, p->context, sizeof(p->context), PORT, MCFG_CONTEXT, bc->port);
- ast_copy_string(ast->context, p->context, sizeof(ast->context));
- p->overlap_dial_task = -1;
- config_ch_hdlc(p);
- config_ch_jitterbuffer(p);
-
cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_PICKUPGROUP, bc->port);
sscanf(buf, "%lld", &pg);
cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_CALLGROUP, bc->port);
sscanf(buf, "%lld", &cg);
- chan_misdn_log(5, bc->port, " --> * CallGrp:%s PickupGrp:%s\n",
+ chan_misdn_log(5, bc->port, " --> * Callgroup:%s Pickupgroup:%s\n",
ast_print_group(buf, sizeof(buf), cg), ast_print_group(buf, sizeof(buf), pg));
ast->pickupgroup = pg;
ast->callgroup = cg;
@@ -2570,12 +2548,8 @@
cm_get(misdn_cm, faxdetect, sizeof(faxdetect), PORT, MCFG_FAXDETECT, bc->port);
if (orig == ORG_AST) {
- if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both")) {
- if (strstr(faxdetect, "nojump"))
- p->faxdetect = 2;
- else
- p->faxdetect = 1;
- }
+ if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both"))
+ p->faxdetect = strstr(faxdetect, "nojump") ? 2 : 1;
if (!cm_get(misdn_cm, buf, sizeof(buf), PORT, MCFG_CALLERID, bc->port) && !ast_strlen_zero(buf)) {
chan_misdn_log(2, bc->port, " --> * Setting Cid to %s\n", buf);
@@ -2596,12 +2570,8 @@
p->ast->transfercapability = bc->capability;
pbx_builtin_setvar_helper(p->ast, "CALLTYPE", bc->capability == INFO_CAPABILITY_DIGITAL_UNRESTRICTED ? "DIGITAL" : "SPEECH");
- if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both")) {
- if (strstr(faxdetect, "nojump"))
- p->faxdetect = 2;
- else
- p->faxdetect = 1;
- }
+ if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both"))
+ p->faxdetect = strstr(faxdetect, "nojump") ? 2 : 1;
cm_get_int(misdn_cm, bc->cpnnumplan, PORT, MCFG_CPNDIALPLAN, bc->port);
print_numplan(bc->port, bc->cpnnumplan, "CTON");
@@ -2661,6 +2631,11 @@
*cid_num = NULL;
struct ast_channel *tmp;
+ if (pipe(p->pipe) < 0) {
+ ast_log(LOG_ERROR, "Pipe failed: %s!\n", strerror(errno));
+ return NULL;
+ }
+
if (callerid)
ast_callerid_parse(callerid, &cid_name, &cid_num);
@@ -2668,7 +2643,7 @@
get_chan_offset(port) + (c < 0 ? 0 : c), ast_atomic_fetchadd_int(&glob_channel, 1));
if (tmp) {
chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n", exten, callerid);
-
+ tmp->fds[0] = p->pipe[0];
tmp->nativeformats = prefformat;
tmp->readformat = format;
tmp->rawreadformat = format;
@@ -2676,29 +2651,19 @@
tmp->rawwriteformat = format;
tmp->tech_pvt = p;
tmp->priority = 1;
-
- if (cm_get_int(misdn_cm, bridging, GENERAL, MCFG_BRIDGING))
- bridging = 0;
- tmp->tech = bridging ? &misdn_tech : &misdn_tech_wo_bridge;
-
+ tmp->tech = !cm_get_bool(misdn_cm, bridging, GENERAL, MCFG_BRIDGING) && bridging ? &misdn_tech : &misdn_tech_wo_bridge;
+ tmp->rings = (state == AST_STATE_RING);
+
+ /* Don't use ast_set_callerid() here because it will
+ * generate a needless NewCallerID event */
+ tmp->cid.cid_num = ast_strdup(cid_num);
+ tmp->cid.cid_ani = ast_strdup(cid_num);
+ tmp->cid.cid_name = ast_strdup(cid_name);
+
if (exten)
ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
else
chan_misdn_log(2, 0, "misdn_new: no exten given.\n");
-
- if (callerid) {
- ast_callerid_parse(callerid, &cid_name, &cid_num);
- /* Don't use ast_set_callerid() here because it will
- * generate a needless NewCallerID event */
- tmp->cid.cid_num = ast_strdup(cid_num);
- tmp->cid.cid_ani = ast_strdup(cid_num);
- tmp->cid.cid_name = ast_strdup(cid_name);
- }
-
- if (pipe(p->pipe) < 0)
- perror("Pipe failed\n");
- tmp->fds[0] = p->pipe[0];
- tmp->rings = (state == AST_STATE_RING);
} else
chan_misdn_log(-1, 0, "Unable to allocate channel structure\n");
@@ -2716,9 +2681,12 @@
*pos = NULL;
int channel = 0,
port = 0;
- struct misdn_bchannel *newbc = NULL;
+ struct misdn_bchannel *bc = NULL;
struct csel *cs = NULL;
- struct misdn_pvt *p = misdn_pvt_init(ORG_AST);
+ struct misdn_pvt *p = misdn_pvt_new(ORG_AST);
+
+ if (!p)
+ return NULL;
ast_copy_string(buf, data, sizeof(buf));
@@ -2741,40 +2709,44 @@
port = atoi(port_str);
} else {
ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITHOUT PORT/Group, check extension.conf\n", ext);
- return NULL;
+ goto error;
}
if (!ast_strlen_zero(group)) {
if (!AST_HASH_LOOKUP(&group_csel_hash, group, cs)) {
- newbc = csel_get_next(cs);
- if (!newbc)
+ bc = csel_get_next(cs);
+ if (!bc)
chan_misdn_log(-1, port, "Failed! No free channel in group %d!", group);
}
} else {
if (channel)
chan_misdn_log(2, port, " --> preselected_channel: %d\n", channel);
- newbc = misdn_lib_get_free_bc(port, channel, 0);
- }
-
- if (!newbc) {
+ bc = misdn_lib_get_free_bc(port, channel, 0);
+ }
+
+ if (!bc) {
chan_misdn_log(-1, 0, "Could not create channel on port %d with extension %s\n", port, ext);
- return NULL;
+ goto error;
}
/* create ast_channel and link all the objects together */
- p->bc = newbc;
+ p->bc = bc;
p->ast = misdn_new(p, AST_STATE_RESERVED, ext, NULL, format, port, channel);
/* register chan in local list */
misdn_pvt_queue(p) ;
/* fill in the config into the objects */
- config_ch(p, ORG_AST);
+ config_pvt(p, ORG_AST);
/* important */
p->need_hangup = 0;
return p->ast;
+
+error:
+ misdn_pvt_destroy(p);
+ return NULL;
}
static int misdn_digit_begin (struct ast_channel *ast, char digit)
@@ -2826,48 +2798,41 @@
static int misdn_call (struct ast_channel *ast, char *dest, int timeout)
{
- int port = 0;
- int r;
- int exceed;
- struct misdn_pvt *p = MISDN_ASTERISK_TECH_PVT(ast);
- struct misdn_bchannel *newbc;
+ struct misdn_pvt *p = ast ? MISDN_ASTERISK_TECH_PVT(ast) : NULL;
+ struct misdn_bchannel *bc = p ? p->bc : NULL;
char *opts = NULL,
*ext,
- *tokb;
- char dest_cp[BUFFERSIZE];
- char tmp[16];
-
- if (!ast) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on ast_channel *ast where ast == NULL\n");
+ *tokb,
+ dest_cp[BUFFERSIZE],
+ tmp[16];
+ int port,
+ r,
+ exceed;
+
+ if (!ast || !dest || !p || !bc) {
+ ast_log(LOG_WARNING, " --> ! misdn_call called with !ast or !dest or !p or !bc!\n");
return -1;
}
- if (((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) || !dest || !p || !p->bc) {
- ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
+ if (ast->_state != AST_STATE_DOWN && ast->_state != AST_STATE_RESERVED) {
+ ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved!\n", ast->name);
ast->hangupcause = 41;
ast_setstate(ast, AST_STATE_DOWN);
return -1;
}
- newbc = p->bc;
- port = newbc->port;
-
+ port = bc->port;
strncpy(dest_cp, dest, sizeof(dest_cp));
dest_cp[sizeof(dest_cp) - 1] = 0;
-
ext = strtok_r(dest_cp, "/", &tokb);
if (ext) {
ext = strtok_r(NULL, "/", &tokb);
- if (ext) {
- opts = strtok_r(NULL, "/", &tokb);
- } else {
+ if (!ext) {
chan_misdn_log(0, 0, "misdn_call: No Extension given!\n");
return -1;
}
- }
-
- strncpy(newbc->dad, ext, sizeof(newbc->dad));
- strncpy(ast->exten, ext, sizeof(ast->exten));
+ opts = strtok_r(NULL, "/", &tokb);
+ }
if ((exceed = add_out_calls(port))) {
snprintf(tmp, sizeof(tmp), "%d", exceed);
@@ -2876,32 +2841,34 @@
}
chan_misdn_log(2, port, "* CALL: %s\n", dest);
- chan_misdn_log(2, port, " --> * dad:%s tech:%s ctx:%s\n", ast->exten, ast->name, ast->context);
- chan_misdn_log(3, port, " --> * adding2newbc ext %s\n", ast->exten);
-
+
+ strncpy(ast->exten, ext, sizeof(ast->exten));
+ ast->exten[sizeof(ast->exten) - 1] = 0;
if (ast->exten) {
- strncpy(newbc->dad, ast->exten, sizeof(newbc->dad));
- newbc->dad[sizeof(newbc->dad) - 1] = 0;
- }
-
- *newbc->rad = 0;
- chan_misdn_log(3, port, " --> * adding2newbc callerid %s\n", AST_CID_P(ast));
-
- if (ast_strlen_zero(newbc->oad) && AST_CID_P(ast) && AST_CID_P(ast)) {
- strncpy(newbc->oad, AST_CID_P(ast), sizeof(newbc->oad));
- newbc->oad[sizeof(newbc->oad) - 1] = 0;
- }
-
- newbc->capability = ast->transfercapability;
- pbx_builtin_setvar_helper(ast, "TRANSFERCAPABILITY", ast_transfercapability2str(newbc->capability));
+ strncpy(bc->dad, ast->exten, sizeof(bc->dad));
+ bc->dad[sizeof(bc->dad) - 1] = 0;
+ } else {
+ strncpy(bc->dad, ext, sizeof(bc->dad));
+ bc->dad[sizeof(bc->dad) - 1] = 0;
+ }
+ chan_misdn_log(2, port, " --> * dad:%s tech:%s ctx:%s\n", bc->dad, ast->name, ast->context);
+
+ if (ast_strlen_zero(bc->oad) && AST_CID_P(ast)) {
+ chan_misdn_log(3, port, " --> * adding2bc callerid %s\n", AST_CID_P(ast));
+ strncpy(bc->oad, AST_CID_P(ast), sizeof(bc->oad));
+ bc->oad[sizeof(bc->oad) - 1] = 0;
+ }
+
+ bc->rad[0] = 0;
+ bc->capability = ast->transfercapability;
+ pbx_builtin_setvar_helper(ast, "TRANSFERCAPABILITY", ast_transfercapability2str(bc->capability));
if (ast->transfercapability == INFO_CAPABILITY_DIGITAL_UNRESTRICTED)
chan_misdn_log(2, port, " --> * Call with flag Digital\n");
- config_ch_pres_screen(p);
- config_ch_hdlc(p);
+ config_pvt_pres_screen(p);
/* fill in some ies from channel vary*/
- import_ch(ast, newbc, p);
+ import_ch(ast, bc, p);
/* Finally The Options Override Everything */
if (opts)
@@ -2913,22 +2880,22 @@
chan_misdn_log(0, port, "statemachine_run failed on AEVENT_CALL: %d!\n", r);
/** we should have l3id after sending setup **/
- p->l3id = newbc->l3_id;
+ p->l3id = bc->l3_id;
if (r == -ENOCHAN) {
chan_misdn_log(0, port, " --> * Theres no Channel at the moment .. !\n");
- chan_misdn_log(2, port, " --> * SEND: State Down pid:%d\n", newbc ? newbc->pid : -1);
+ chan_misdn_log(2, port, " --> * SEND: State Down pid:%d\n", bc ? bc->pid : -1);
ast->hangupcause = 34;
ast_setstate(ast, AST_STATE_DOWN);
return -1;
}
- chan_misdn_log(2, port, " --> * SEND: State Dialing pid:%d\n", newbc ? newbc->pid : 1);
+ chan_misdn_log(2, port, " --> * SEND: State Dialing pid:%d\n", bc ? bc->pid : 1);
ast_setstate(ast, AST_STATE_DIALING);
ast->hangupcause = 16;
- if (newbc->nt)
+ if (bc->nt)
stop_bc_tones(p);
return 0;
@@ -3136,20 +3103,12 @@
static int misdn_answer (struct ast_channel *ast)
{
struct misdn_pvt *p;
- const char *tmp_key, *nodsp;
+ const char *nodsp;
if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)) || !p->bc)
return -1;
chan_misdn_log(2, p->bc->port, "* ANSWER:\n");
-
- tmp_key = pbx_builtin_getvar_helper(p->ast, "CRYPT_KEY");
- if (tmp_key) {
- chan_misdn_log(2, p->bc->port, " --> Connection will be BF crypted\n");
- strncpy(p->bc->crypt_key, tmp_key, sizeof(p->bc->crypt_key));
- p->bc->crypt_key[sizeof(p->bc->crypt_key) - 1] = 0;
- } else
- chan_misdn_log(3, p->bc->port, " --> Connection is without BF encryption\n");
nodsp = pbx_builtin_getvar_helper(ast, "MISDN_DIGITAL_TRANS");
if (nodsp) {
@@ -3211,7 +3170,7 @@
switch (p->faxdetect) {
case 1:
if (strcmp(ast->exten, "fax")) {
- cm_get(misdn_cm, context_tmp, sizeof(context_tmp), PORT, MCFG_FAXDETECT_TIMEOUT, p->bc->port);
+ cm_get(misdn_cm, context_tmp, sizeof(context_tmp), PORT, MCFG_FAXDETECT_CONTEXT, p->bc->port);
context = ast_strlen_zero(context_tmp) ? (ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext) : context_tmp;
if (ast_exists_extension(ast, context, "fax", 1, AST_CID_P(ast))) {
if (option_verbose > 2)
@@ -4133,7 +4092,7 @@
print_bearer(bc);
- p = misdn_pvt_init(ORG_MISDN);
+ p = misdn_pvt_new(ORG_MISDN);
if (!p) {
chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n");
return RESPONSE_IGNORE_SETUP;
@@ -4150,8 +4109,8 @@
pbx_builtin_setvar_helper(p->ast, "MAX_OVERFLOW", tmp);
}
- config_ch(p, ORG_MISDN);
- config_ch_pres_screen(p);
+ config_pvt(p, ORG_MISDN);
+ config_pvt_pres_screen(p);
export_chan(p->ast, bc, p);
misdn_pvt_queue(p) ;
@@ -4230,8 +4189,7 @@
struct misdn_pvt *p = MISDN_ASTERISK_TECH_PVT(ast);
char *tok,
*tokb;
- int keyidx,
- gain,
+ int gain,
change_jitter = 0,
neglect;
@@ -4296,15 +4254,6 @@
}
}
break;
- case 'c':
- keyidx = atoi(++tok);
- if (keyidx > misdn_key_vector_size || keyidx < 0) {
- ast_log(LOG_WARNING, "You entered the keyidx: %d but we have only %d keys\n", keyidx, misdn_key_vector_size);
- continue;
- }
- ast_copy_string(p->bc->crypt_key, misdn_key_vector[keyidx], sizeof(p->bc->crypt_key));
- chan_misdn_log(0, p->bc->port, "SETOPT: crypt with key:%s\n", misdn_key_vector[keyidx]);
- break;
case 'e':
chan_misdn_log(2, p->bc->port, "SETOPT: EchoCancel\n");
if (neglect) {
@@ -4352,7 +4301,7 @@
}
if (change_jitter)
- config_ch_jitterbuffer(p);
+ config_pvt_jitterbuffer(p);
if (p->faxdetect || p->ast_dsp) {
if (!p->dsp)
@@ -4375,8 +4324,10 @@
{
ast_log(LOG_VERBOSE, "-- Unregistering mISDN Channel Driver --\n");
+ if (!ast_atomic_fetchadd_int(&module_initialized, -1))
+ return 0;
+
misdn_tasks_destroy();
-
if (misdn_ports)
free(misdn_ports);
ast_cli_unregister_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
@@ -4465,7 +4416,6 @@
" d - Send display text on called phone, text is the optparam\n"
" n - don't detect dtmf tones on called channel\n"
" h - make digital outgoing call\n"
- " c - make crypted outgoing call, param is keyindex\n"
" e - perform echo cancelation on this channel,\n"
" takes taps as arguments (32, 64, 128, 256)\n"
" s - send Non Inband DTMF as inband\n"
@@ -4484,6 +4434,8 @@
ast_cli_register_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
+ ast_atomic_fetchadd_int(&module_initialized, 1);
+
chan_misdn_log(0, 0, "-- mISDN Channel Driver Registered --\n");
return 0;
More information about the asterisk-commits
mailing list