[asterisk-commits] moy: branch moy/mfcr2 r168017 - /team/moy/mfcr2/channels/chan_dahdi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jan 9 10:54:45 CST 2009
Author: moy
Date: Fri Jan 9 10:54:45 2009
New Revision: 168017
URL: http://svn.digium.com/view/asterisk?view=rev&rev=168017
Log:
addressed comments from reviewboard to improve the code
Modified:
team/moy/mfcr2/channels/chan_dahdi.c
Modified: team/moy/mfcr2/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2/channels/chan_dahdi.c?view=diff&rev=168017&r1=168016&r2=168017
==============================================================================
--- team/moy/mfcr2/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2/channels/chan_dahdi.c Fri Jan 9 10:54:45 2009
@@ -455,21 +455,26 @@
int metering_pulse_timeout;
int max_ani;
int max_dnis;
- int get_ani_first;
- int call_files;
- int allow_collect_calls;
- int charge_calls;
- int forced_release;
- int double_answer;
- int immediate_accept;
+ int get_ani_first:1;
+ int call_files:1;
+ int allow_collect_calls:1;
+ int charge_calls:1;
+ int forced_release:1;
+ int double_answer:1;
+ int immediate_accept:1;
char logdir[OR2_MAX_PATH];
char r2proto_file[OR2_MAX_PATH];
openr2_log_level_t loglevel;
openr2_calling_party_category_t category;
};
-static struct dahdi_mfcr2 **r2links = NULL; // malloc'd r2links
-static int r2links_count = 0; // how many r2links have been malloc'd
-static int r2links_index = 0; // current link when configuring
+
+/* malloc'd r2links */
+static struct dahdi_mfcr2 **r2links;
+/* how many r2links have been malloc'd */
+static int r2links_count;
+/* current link when configuring */
+static int r2links_index;
+
#endif /* HAVE_OPENR2 */
#ifdef HAVE_PRI
@@ -1212,13 +1217,14 @@
static struct ast_channel *dahdi_new(struct dahdi_pvt *, int, int, int, int, int);
#ifdef HAVE_OPENR2
+/* should be called with the ast_channel locked */
static openr2_calling_party_category_t dahdi_r2_get_channel_category(struct ast_channel *c)
{
openr2_calling_party_category_t cat;
const char *catstr = pbx_builtin_getvar_helper(c, "MFCR2_CATEGORY");
struct dahdi_pvt *p = c->tech_pvt;
if (ast_strlen_zero(catstr)) {
- ast_log(LOG_DEBUG, "No MFC/R2 category specified for chan %s, using default %s\n",
+ ast_debug(1, "No MFC/R2 category specified for chan %s, using default %s\n",
c->name, openr2_proto_get_category_string(p->mfcr2_category));
return p->mfcr2_category;
}
@@ -1227,7 +1233,7 @@
catstr, c->name, openr2_proto_get_category_string(p->mfcr2_category));
return p->mfcr2_category;
}
- ast_log(LOG_DEBUG, "Using category %s\n", catstr);
+ ast_debug(1, "Using category %s\n", catstr);
return cat;
}
@@ -1247,13 +1253,13 @@
}
p->mfcr2call = 1;
/* better safe than sorry ... */
- p->cid_name[0] = 0;
- p->cid_num[0] = 0;
- p->rdnis[0] = 0;
- p->exten[0] = 0;
- p->mfcr2_ani_index = 0;
- p->mfcr2_dnis_index = 0;
- p->mfcr2_dnis_matched = 0;
+ p->cid_name[0] = '\0';
+ p->cid_num[0] = '\0';
+ p->rdnis[0] = '\0';
+ p->exten[0] = '\0';
+ p->mfcr2_ani_index = '\0';
+ p->mfcr2_dnis_index = '\0';
+ p->mfcr2_dnis_matched = '\0';
ast_mutex_unlock(&p->lock);
ast_log(LOG_NOTICE, "New MFC/R2 call detected on chan %d.\n", openr2_chan_get_number(r2chan));
}
@@ -1356,7 +1362,7 @@
} else {
mfcr2->monitored_count--;
if (mfcr2->monitored_count < 0) {
- ast_log(LOG_ERROR, "wtf? we have a bug here!.\n");
+ ast_log(LOG_ERROR, "we have a bug here!.\n");
}
}
ast_mutex_unlock(&mfcr2->monitored_count_lock);
@@ -1376,7 +1382,6 @@
/* chan_dahdi will take care of reading from now on, tell the library to forget about it */
openr2_chan_disable_read(r2chan);
} else {
- ast_log(LOG_WARNING, "Unable to start PBX on chan %d\n", p->channel);
openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER);
return;
}
@@ -1426,42 +1431,42 @@
static void dahdi_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disconnect_cause_t cause)
{
struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
- ast_log(LOG_NOTICE, "MFC/R2 call disconnected on chan %d\n", openr2_chan_get_number(r2chan));
+ ast_verb(3, "MFC/R2 call disconnected on chan %d\n", openr2_chan_get_number(r2chan));
ast_mutex_lock(&p->lock);
- if (p->owner) {
- /* when we have an owner we don't call openr2_chan_disconnect_call here, that will
- be done in dahdi_hangup */
- if (p->owner->_state == AST_STATE_UP) {
- p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_mutex_unlock(&p->lock);
- } else if (openr2_chan_get_direction(r2chan) == OR2_DIR_FORWARD) {
- /* being the forward side we must report what happened to the call to whoever requested it */
- switch (cause) {
- case OR2_CAUSE_BUSY_NUMBER:
- p->subs[SUB_REAL].needbusy = 1;
- break;
- case OR2_CAUSE_NETWORK_CONGESTION:
- case OR2_CAUSE_OUT_OF_ORDER:
- case OR2_CAUSE_UNALLOCATED_NUMBER:
- case OR2_CAUSE_NO_ANSWER:
- case OR2_CAUSE_UNSPECIFIED:
- case OR2_CAUSE_NORMAL_CLEARING:
- p->subs[SUB_REAL].needcongestion = 1;
- break;
- default:
- p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- }
- ast_mutex_unlock(&p->lock);
- } else {
- ast_mutex_unlock(&p->lock);
- /* being the backward side and not UP yet, we only need to request hangup */
- /* TODO: what about doing this same thing when were AST_STATE_UP? */
- ast_queue_hangup_with_cause(p->owner, dahdi_r2_cause_to_ast_cause(cause));
- }
- } else {
+ if (!p->owner) {
ast_mutex_unlock(&p->lock);
/* no owner, therefore we can't use dahdi_hangup to disconnect, do it right now */
openr2_chan_disconnect_call(r2chan, OR2_CAUSE_NORMAL_CLEARING);
+ return;
+ }
+ /* when we have an owner we don't call openr2_chan_disconnect_call here, that will
+ be done in dahdi_hangup */
+ if (p->owner->_state == AST_STATE_UP) {
+ p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
+ ast_mutex_unlock(&p->lock);
+ } else if (openr2_chan_get_direction(r2chan) == OR2_DIR_FORWARD) {
+ /* being the forward side we must report what happened to the call to whoever requested it */
+ switch (cause) {
+ case OR2_CAUSE_BUSY_NUMBER:
+ p->subs[SUB_REAL].needbusy = 1;
+ break;
+ case OR2_CAUSE_NETWORK_CONGESTION:
+ case OR2_CAUSE_OUT_OF_ORDER:
+ case OR2_CAUSE_UNALLOCATED_NUMBER:
+ case OR2_CAUSE_NO_ANSWER:
+ case OR2_CAUSE_UNSPECIFIED:
+ case OR2_CAUSE_NORMAL_CLEARING:
+ p->subs[SUB_REAL].needcongestion = 1;
+ break;
+ default:
+ p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
+ }
+ ast_mutex_unlock(&p->lock);
+ } else {
+ ast_mutex_unlock(&p->lock);
+ /* being the backward side and not UP yet, we only need to request hangup */
+ /* TODO: what about doing this same thing when were AST_STATE_UP? */
+ ast_queue_hangup_with_cause(p->owner, dahdi_r2_cause_to_ast_cause(cause));
}
}
@@ -1513,21 +1518,24 @@
__attribute__((format (printf, 3, 0)));
static void dahdi_r2_on_context_log(openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap)
{
+#define CONTEXT_TAG "Context - "
char logmsg[256];
- char completemsg[sizeof(logmsg)+50];
+ char completemsg[sizeof(logmsg) + sizeof(CONTEXT_TAG) - 1];
vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
- snprintf(completemsg, sizeof(completemsg), "Context - %s", logmsg);
+ snprintf(completemsg, sizeof(completemsg), CONTEXT_TAG "%s", logmsg);
dahdi_r2_write_log(level, completemsg);
+#undef CONTEXT_TAG
}
static void dahdi_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap)
__attribute__((format (printf, 3, 0)));
static void dahdi_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level, const char *fmt, va_list ap)
{
+#define CHAN_TAG "Chan "
char logmsg[256];
- char completemsg[sizeof(logmsg)+50];
+ char completemsg[sizeof(logmsg) + sizeof(CHAN_TAG) - 1];
vsnprintf(logmsg, sizeof(logmsg), fmt, ap);
- snprintf(completemsg, sizeof(completemsg), "Chan %d - %s", openr2_chan_get_number(r2chan), logmsg);
+ snprintf(completemsg, sizeof(completemsg), CHAN_TAG "%d - %s", openr2_chan_get_number(r2chan), logmsg);
dahdi_r2_write_log(level, completemsg);
}
@@ -1543,14 +1551,6 @@
p->mfcr2_dnis_index++;
p->exten[p->mfcr2_dnis_index] = 0;
p->rdnis[p->mfcr2_dnis_index] = 0;
- /*
- ast_log(LOG_DEBUG, "Got digit %c in dahdi, dnis so far: %s\n", digit, p->exten);
- int ret;
- ret = ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num);
- ast_log(LOG_DEBUG, "ast_exists_extension(%s, %s, 1, %s) = %d\n", p->context, p->exten, p->cid_num, ret);
- ret = ast_matchmore_extension(NULL, p->context, p->exten, 1, p->cid_num);
- ast_log(LOG_DEBUG, "ast_matchmore_extension(%s, %s, 1, %s) = %d\n", p->context, p->exten, p->cid_num, ret);
- */
/* if the DNIS is a match and cannot match more, stop requesting DNIS */
if ((p->mfcr2_dnis_matched ||
(ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num) && (p->mfcr2_dnis_matched = 1))) &&
@@ -3084,6 +3084,7 @@
#endif /* HAVE_SS7 */
#ifdef HAVE_OPENR2
if (p->mfcr2) {
+ openr2_calling_party_category_t chancat;
int strip = p->stripmsd;
int callres = 0;
c = strchr(dest, '/');
@@ -3102,7 +3103,10 @@
strip = 0;
}
p->dialing = 1;
- callres = openr2_chan_make_call(p->r2chan, l, (c + strip), dahdi_r2_get_channel_category(ast));
+ ast_channel_lock(ast);
+ chancat = dahdi_r2_get_channel_category(ast);
+ ast_channel_unlock(ast);
+ callres = openr2_chan_make_call(p->r2chan, l, (c + strip), chancat);
if (-1 == callres) {
ast_mutex_unlock(&p->lock);
ast_log(LOG_ERROR, "unable to make new MFC/R2 call!\n");
@@ -6085,15 +6089,8 @@
(needanswer, needbusy etc), if we continue we will read()
twice, lets just return a null frame. This should only
happen when openr2 is dialing out */
- p->subs[idx].f.frametype = AST_FRAME_NULL;
- p->subs[idx].f.subclass = 0;
- p->subs[idx].f.samples = 0;
- p->subs[idx].f.mallocd = 0;
- p->subs[idx].f.offset = 0;
- p->subs[idx].f.data.ptr = NULL;
- p->subs[idx].f.datalen= 0;
ast_mutex_unlock(&p->lock);
- return &p->subs[idx].f;
+ return &ast_null_frame;
}
#endif
if (p->subs[idx].needflash) {
@@ -11020,7 +11017,7 @@
openr2_chan_set_idle(mfcr2->pvts[i]->r2chan);
openr2_chan_handle_cas(mfcr2->pvts[i]->r2chan);
}
- while(1) {
+ while (1) {
/* we trust here that the mfcr2 channel list will not ever change once
the module is loaded */
nextms = openr2_context_get_time_to_next_event(mfcr2->protocol_context);
@@ -12986,22 +12983,19 @@
ast_cli(a->fd, FORMAT, "Chan", "Variant", "Max ANI", "Max DNIS", "ANI First", "Immediate Accept", "Tx CAS", "Rx CAS");
ast_mutex_lock(&iflock);
p = iflist;
- while (p) {
+ for (p = iflist; p; p = p->next) {
if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
- p = p->next;
continue;
}
if (filtertype) {
switch(filtertype) {
case 1: /* mfcr2 show channels group <group> */
if (p->group != targetnum) {
- p = p->next;
continue;
}
break;
case 2: /* mfcr2 show channels context <context> */
if (strcasecmp(p->context, a->argv[4])) {
- p= p->next;
continue;
}
break;
@@ -13018,7 +13012,6 @@
anino, dnisno, openr2_context_get_ani_first(r2context) ? "Yes" : "No",
openr2_context_get_immediate_accept(r2context) ? "Yes" : "No",
openr2_chan_get_tx_cas_string(p->r2chan), openr2_chan_get_rx_cas_string(p->r2chan));
- p = p->next;
}
ast_mutex_unlock(&iflock);
return CLI_SUCCESS;
@@ -13067,23 +13060,18 @@
}
}
ast_mutex_lock(&iflock);
- p = iflist;
- while (p) {
+ for (p = iflist; p; p = p->next) {
if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
- p = p->next;
continue;
}
if ((channo != -1) && (p->channel != channo )) {
- p = p->next;
continue;
}
openr2_chan_set_log_level(p->r2chan, loglevel);
if (channo != -1) {
ast_cli(a->fd, "MFC/R2 debugging set to '%s' for channel %d.\n", a->argv[3], p->channel);
break;
- } else {
- p = p->next;
- }
+ }
}
if ((channo != -1) && !p) {
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
@@ -13115,14 +13103,11 @@
}
channo = (a->argc == 5) ? atoi(a->argv[4]) : -1;
ast_mutex_lock(&iflock);
- p = iflist;
- while (p) {
+ for (p = iflist; p; p = p->next) {
if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
- p = p->next;
continue;
}
if ((channo != -1) && (p->channel != channo )) {
- p = p->next;
continue;
}
if (ast_true(a->argv[3])) {
@@ -13137,9 +13122,7 @@
ast_cli(a->fd, "MFC/R2 call files disabled for channel %d.\n", p->channel);
}
break;
- } else {
- p = p->next;
- }
+ }
}
if ((channo != -1) && !p) {
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
@@ -13173,14 +13156,11 @@
}
channo = (a->argc == 4) ? atoi(a->argv[3]) : -1;
ast_mutex_lock(&iflock);
- p = iflist;
- while (p) {
+ for (p = iflist; p; p = p->next) {
if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
- p = p->next;
continue;
}
if ((channo != -1) && (p->channel != channo )) {
- p = p->next;
continue;
}
openr2_chan_set_idle(p->r2chan);
@@ -13189,9 +13169,7 @@
ast_mutex_unlock(&p->lock);
if (channo != -1) {
break;
- } else {
- p = p->next;
- }
+ }
}
if ((channo != -1) && !p) {
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
@@ -13218,14 +13196,11 @@
}
channo = (a->argc == 4) ? atoi(a->argv[3]) : -1;
ast_mutex_lock(&iflock);
- p = iflist;
- while (p) {
+ for (p = iflist; p; p = p->next) {
if (!(p->sig & SIG_MFCR2) || !p->r2chan) {
- p = p->next;
continue;
}
if ((channo != -1) && (p->channel != channo )) {
- p = p->next;
continue;
}
openr2_chan_set_blocked(p->r2chan);
@@ -13234,9 +13209,7 @@
ast_mutex_unlock(&p->lock);
if (channo != -1) {
break;
- } else {
- p = p->next;
- }
+ }
}
if ((channo != -1) && !p) {
ast_cli(a->fd, "MFC/R2 channel %d not found.\n", channo);
@@ -14821,7 +14794,7 @@
#endif
#if defined(HAVE_OPENR2)
dahdi_r2_destroy_links();
- ast_cli_unregister_multiple(dahdi_mfcr2_cli, sizeof(dahdi_mfcr2_cli) / sizeof(dahdi_mfcr2_cli[0]));
+ ast_cli_unregister_multiple(dahdi_mfcr2_cli, ARRAY_LEN(dahdi_mfcr2_cli));
#endif
ast_cli_unregister_multiple(dahdi_cli, sizeof(dahdi_cli) / sizeof(struct ast_cli_entry));
@@ -15790,23 +15763,15 @@
}
} else if (!strcasecmp(v->name, "mfcr2_logging")) {
openr2_log_level_t tmplevel;
- char *toklevel = NULL;
- char *saveptr = NULL;
+ char *clevel;
char *logval = ast_strdupa(v->value);
- toklevel = strtok_r(logval, ",", &saveptr);
- if (-1 == (tmplevel = openr2_log_get_level(toklevel))) {
- ast_log(LOG_WARNING, "Invalid MFC/R2 logging level '%s' at line %d.\n", v->value, v->lineno);
- } else if (OR2_LOG_NOTHING == tmplevel) {
- confp->mfcr2.loglevel = tmplevel;
- } else {
+ while (logval) {
+ clevel = strsep(&logval,",");
+ if (-1 == (tmplevel = openr2_log_get_level(clevel))) {
+ ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", clevel, v->lineno);
+ continue;
+ }
confp->mfcr2.loglevel |= tmplevel;
- while ((toklevel = strtok_r(NULL, ",", &saveptr))) {
- if (-1 == (tmplevel = openr2_log_get_level(toklevel))) {
- ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", toklevel, v->lineno);
- continue;
- }
- confp->mfcr2.loglevel |= tmplevel;
- }
}
#endif /* HAVE_OPENR2 */
} else if (!strcasecmp(v->name, "cadence")) {
More information about the asterisk-commits
mailing list