Allow to configure custom context,exten,priority to jump to

if a fax is detected.
This commit is contained in:
MelwareDE 2010-09-24 19:20:28 +00:00
parent 3e71cbcc24
commit 5a5bedc999
5 changed files with 68 additions and 18 deletions

View File

@ -19,6 +19,7 @@ HEAD
- Use Diva QSIG CAPI extensions for processing of Calling Party Name - Use Diva QSIG CAPI extensions for processing of Calling Party Name
- Add Slinear - Add Slinear
- Add HD voice using G.722, Siren7, Siren14 and Slinear16 - Add HD voice using G.722, Siren7, Siren14 and Slinear16
- added faxdestination= to capi.conf to configure custom context,exten,prio.
chan_capi-1.1.5 chan_capi-1.1.5
------------------ ------------------

2
README
View File

@ -543,7 +543,7 @@ DISCONNECT_IND_REASON
connection is physically broken (cable). connection is physically broken (cable).
FAXEXTEN FAXEXTEN
If chan_capi sends the call to extensions 'fax', the original extension number If chan_capi sends the call to configured fax extension, the original extension number
is saved in this variable. is saved in this variable.
PRI_CAUSE PRI_CAUSE

View File

@ -41,6 +41,8 @@ faxdetect=off ;enable faxdetection and redirection to EXTEN 'fax' for incomin
;outgoing calls. (default='off', possible values: 'incoming','outgoing','both') ;outgoing calls. (default='off', possible values: 'incoming','outgoing','both')
faxdetecttime=0 ;Only detect faxes during the first 'n' seconds of the call. faxdetecttime=0 ;Only detect faxes during the first 'n' seconds of the call.
;(default '0' meaning for the whole duration of the call) ;(default '0' meaning for the whole duration of the call)
faxdestination=custom-fax,fax,1 ;Set custom context, exten and priority to jump to on faxdetect.
;Default is "<current-context>,fax,1".
accountcode= ;PBX accountcode to use in CDRs accountcode= ;PBX accountcode to use in CDRs
;amaflags=default;AMA flags for CDR ('default', 'omit', 'billing', or 'documentation') ;amaflags=default;AMA flags for CDR ('default', 'omit', 'billing', or 'documentation')
context=isdn-in ;context for incoming calls context=isdn-in ;context for incoming calls

View File

@ -3487,6 +3487,7 @@ static int pbx_capi_send_fax(struct ast_channel *c, char *data)
static void capi_handle_dtmf_fax(struct capi_pvt *i) static void capi_handle_dtmf_fax(struct capi_pvt *i)
{ {
struct ast_channel *c = i->owner; struct ast_channel *c = i->owner;
char *faxcontext;
if (!c) { if (!c) {
/* no channel, ignore */ /* no channel, ignore */
@ -3516,21 +3517,26 @@ static void capi_handle_dtmf_fax(struct capi_pvt *i)
return; return;
} }
} }
faxcontext = c->context;
if (strlen(i->faxcontext) > 0)
faxcontext = i->faxcontext;
if (!strcmp(c->exten, "fax")) { if ((!strcmp(c->exten, i->faxexten)) &&
cc_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n"); (!strcmp(c->context, faxcontext))) {
cc_log(LOG_DEBUG, "Already in fax context/extension, not redirecting\n");
return; return;
} }
if (!ast_exists_extension(c, c->context, "fax", 1, i->cid)) { if (!ast_exists_extension(c, faxcontext, i->faxexten, i->faxpriority, i->cid)) {
cc_verbose(3, 0, VERBOSE_PREFIX_3 cc_verbose(3, 0, VERBOSE_PREFIX_3
"Fax tone detected, but no fax extension for %s in context '%s'\n", "Fax tone detected, but no extension '%s' for %s in context '%s'\n",
c->name, c->context); i->faxexten, c->name, faxcontext);
return; return;
} }
cc_verbose(2, 0, VERBOSE_PREFIX_3 "%s: Redirecting %s to fax extension\n", cc_verbose(2, 0, VERBOSE_PREFIX_3 "%s: Redirecting %s for fax to context,extension, %s,%s,%d\n",
i->vname, c->name); i->vname, c->name, faxcontext, i->faxexten, i->faxpriority);
capi_channel_task(c, CAPI_CHANNEL_TASK_GOTOFAX); capi_channel_task(c, CAPI_CHANNEL_TASK_GOTOFAX);
@ -5419,7 +5425,7 @@ void capidev_handle_connection_conf(struct capi_pvt **i, unsigned int PLCI,
cc_verbose(1, 1, VERBOSE_PREFIX_3 "%s: received CONNECT_CONF PLCI = %#x\n", cc_verbose(1, 1, VERBOSE_PREFIX_3 "%s: received CONNECT_CONF PLCI = %#x\n",
ii->vname, PLCI); ii->vname, PLCI);
*interface_owner = capidev_acquire_locks_from_thread_context (ii); *interface_owner = capidev_acquire_locks_from_thread_context(ii);
if (wInfo == 0) { if (wInfo == 0) {
ii->PLCI = PLCI; ii->PLCI = PLCI;
@ -5434,7 +5440,7 @@ void capidev_handle_connection_conf(struct capi_pvt **i, unsigned int PLCI,
/*! \brief acquire locks in the correct order /*! \brief acquire locks in the correct order
*/ */
static struct ast_channel* capidev_acquire_locks_from_thread_context (struct capi_pvt *i) static struct ast_channel* capidev_acquire_locks_from_thread_context(struct capi_pvt *i)
{ {
struct ast_channel *owner = 0; struct ast_channel *owner = 0;
@ -5639,7 +5645,7 @@ static void capidev_handle_msg(_cmsg *CMSG)
if (ii != 0) { if (ii != 0) {
if (do_lock) { if (do_lock) {
streaming_interface_owner = capidev_acquire_locks_from_thread_context (ii); streaming_interface_owner = capidev_acquire_locks_from_thread_context(ii);
} }
capi_DivaStreamingRemove(ii); capi_DivaStreamingRemove(ii);
if (do_lock) { if (do_lock) {
@ -7448,6 +7454,8 @@ static void capi_do_interface_task(void)
static void capi_do_channel_task(void) static void capi_do_channel_task(void)
{ {
struct capi_pvt *i;
if (chan_for_task == NULL) if (chan_for_task == NULL)
return; return;
@ -7471,10 +7479,12 @@ static void capi_do_channel_task(void)
/* deferred (out of lock) async goto fax extension */ /* deferred (out of lock) async goto fax extension */
/* Save the DID/DNIS when we transfer the fax call to a "fax" extension */ /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
pbx_builtin_setvar_helper(chan_for_task, "FAXEXTEN", chan_for_task->exten); pbx_builtin_setvar_helper(chan_for_task, "FAXEXTEN", chan_for_task->exten);
i = CC_CHANNEL_PVT(chan_for_task);
if (ast_async_goto(chan_for_task, chan_for_task->context, "fax", 1)) { if (i) {
cc_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", if (ast_async_goto(chan_for_task, i->faxcontext, i->faxexten, i->faxpriority)) {
chan_for_task->name, chan_for_task->context); cc_log(LOG_WARNING, "Failed to async goto '%s,%s,%d' for '%s'\n",
i->faxcontext, i->faxexten, i->faxpriority, chan_for_task->name);
}
} }
break; break;
default: default:
@ -7708,6 +7718,9 @@ int mkif(struct cc_capi_conf *conf)
tmp->bridge = conf->bridge; tmp->bridge = conf->bridge;
tmp->FaxState = conf->faxsetting; tmp->FaxState = conf->faxsetting;
tmp->faxdetecttime = conf->faxdetecttime; tmp->faxdetecttime = conf->faxdetecttime;
cc_copy_string(tmp->faxcontext, conf->faxcontext, sizeof(tmp->faxcontext));
cc_copy_string(tmp->faxexten, conf->faxexten, sizeof(tmp->faxexten));
tmp->faxpriority = conf->faxpriority;
tmp->smoother = ast_smoother_new(CAPI_MAX_B3_BLOCK_SIZE); tmp->smoother = ast_smoother_new(CAPI_MAX_B3_BLOCK_SIZE);
@ -8483,6 +8496,15 @@ static int cc_post_init_capi(void)
static int conf_interface(struct cc_capi_conf *conf, struct ast_variable *v) static int conf_interface(struct cc_capi_conf *conf, struct ast_variable *v)
{ {
int y; int y;
char faxcontext[AST_MAX_EXTENSION+1];
char faxexten[AST_MAX_EXTENSION+1];
int faxpriority = 1;
char faxdest[AST_MAX_EXTENSION+1];
char *p, *q;
memset(faxdest, 0, sizeof(faxdest));
cc_copy_string(faxcontext, "", sizeof(faxcontext));
cc_copy_string(faxexten, "fax", sizeof(faxexten));
#define CONF_STRING(var, token) \ #define CONF_STRING(var, token) \
if (!strcasecmp(v->name, token)) { \ if (!strcasecmp(v->name, token)) { \
@ -8517,6 +8539,7 @@ static int conf_interface(struct cc_capi_conf *conf, struct ast_variable *v)
CONF_STRING(conf->prefix, "prefix") CONF_STRING(conf->prefix, "prefix")
CONF_STRING(conf->accountcode, "accountcode") CONF_STRING(conf->accountcode, "accountcode")
CONF_STRING(conf->language, "language") CONF_STRING(conf->language, "language")
CONF_STRING(faxdest, "faxdestination")
if (!strcasecmp(v->name, "softdtmf")) { if (!strcasecmp(v->name, "softdtmf")) {
if ((!conf->softdtmf) && (ast_true(v->value))) { if ((!conf->softdtmf) && (ast_true(v->value))) {
@ -8660,6 +8683,25 @@ static int conf_interface(struct cc_capi_conf *conf, struct ast_variable *v)
#undef CONF_STRING #undef CONF_STRING
#undef CONF_INTEGER #undef CONF_INTEGER
#undef CONF_TRUE #undef CONF_TRUE
/* faxdestination */
if (strlen(faxdest) > 0) {
p = faxdest;
q = strsep(&p, ",");
cc_copy_string(faxcontext, q, sizeof(faxcontext));
if (p) {
q = strsep(&p, ",");
cc_copy_string(faxexten, q, sizeof(faxexten));
}
if (p) {
faxpriority = atoi(p);
}
}
cc_copy_string(conf->faxcontext, faxcontext, sizeof(conf->faxcontext));
cc_copy_string(conf->faxexten, faxexten, sizeof(conf->faxexten));
if (faxpriority < 1) faxpriority = 1;
conf->faxpriority = faxpriority;
return 0; return 0;
} }
@ -8722,9 +8764,6 @@ static int capi_eval_config(struct ast_config *cfg)
} }
#endif #endif
} }
} }
/* go through all other sections, which are our interfaces */ /* go through all other sections, which are our interfaces */

View File

@ -476,6 +476,10 @@ struct capi_pvt {
unsigned int FaxState; unsigned int FaxState;
/* Window for fax detection */ /* Window for fax detection */
unsigned int faxdetecttime; unsigned int faxdetecttime;
/* custom fax context,exten,prio */
char faxcontext[AST_MAX_EXTENSION+1];
char faxexten[AST_MAX_EXTENSION+1];
int faxpriority;
/* handle for CCBS/CCNR callback */ /* handle for CCBS/CCNR callback */
unsigned int ccbsnrhandle; unsigned int ccbsnrhandle;
@ -606,6 +610,10 @@ struct cc_capi_conf {
struct cc_capi_qsig_conf qsigconf; struct cc_capi_qsig_conf qsigconf;
unsigned int faxsetting; unsigned int faxsetting;
unsigned int faxdetecttime; unsigned int faxdetecttime;
/* custom fax context,exten,prio */
char faxcontext[AST_MAX_EXTENSION+1];
char faxexten[AST_MAX_EXTENSION+1];
int faxpriority;
ast_group_t callgroup; ast_group_t callgroup;
ast_group_t pickupgroup; ast_group_t pickupgroup;
ast_group_t group; ast_group_t group;