[Asterisk-cvs] asterisk cdr.c,1.4,1.5 channel.c,1.43,1.44 pbx.c,1.48,1.49

martinp at lists.digium.com martinp at lists.digium.com
Fri Sep 12 11:50:26 CDT 2003


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv10727

Modified Files:
	cdr.c channel.c pbx.c 
Log Message:

Add distinguishing between BUSY and FAILURE for outgoing spool calls. Always save CDR record (even if the call fails). If the call fails try to see if there is
"failed" extension in the specified context (only if you use context,extension,priority syntax) and execute it.



Index: cdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cdr.c	13 Aug 2003 15:25:15 -0000	1.4
+++ cdr.c	12 Sep 2003 16:51:35 -0000	1.5
@@ -19,6 +19,7 @@
 #include <asterisk/cdr.h>
 #include <asterisk/logger.h>
 #include <asterisk/callerid.h>
+#include <asterisk/causes.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -163,6 +164,41 @@
 	}
 }
 
+void ast_cdr_failed(struct ast_cdr *cdr)
+{
+	char *chan; 
+	if (cdr) {
+		chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
+		if (cdr->posted)
+			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
+			cdr->disposition = AST_CDR_FAILED;
+	}
+}
+
+int ast_cdr_disposition(struct ast_cdr *cdr, int cause)
+{
+	int res = 0;
+	if (cdr) {
+		switch(cause) {
+			case AST_CAUSE_BUSY:
+				ast_cdr_busy(cdr);
+				break;
+			case AST_CAUSE_FAILURE:
+				ast_cdr_failed(cdr);
+				break;
+			case AST_CAUSE_NORMAL:
+				break;
+			case AST_CAUSE_NOTDEFINED:
+				res = -1;
+				break;
+			default:
+				res = -1;
+				ast_log(LOG_WARNING, "We don't handle that cause yet\n");
+		}
+	}
+	return res;
+}
+
 void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chann)
 {
 	char *chan; 
@@ -275,6 +311,8 @@
 	switch (disposition) {
 	case AST_CDR_NOANSWER:
 		return "NO ANSWER";
+	case AST_CDR_FAILED:
+		return "FAILED";		
 	case AST_CDR_BUSY:
 		return "BUSY";		
 	case AST_CDR_ANSWERED:
@@ -313,11 +351,15 @@
 	char *name, *num;
 	char tmp[AST_MAX_EXTENSION] = "";
 	/* Grab source from ANI or normal Caller*ID */
+	if (!cdr) {
+		ast_log(LOG_NOTICE, "The cdr pointer is not set\n");
+		return -1;
+	}
 	if (c->ani)
 		strncpy(tmp, c->ani, sizeof(tmp) - 1);
-	else if (c->callerid)
+	else if (c->callerid && strlen(c->callerid))
 		strncpy(tmp, c->callerid, sizeof(tmp) - 1);
-	if (c->callerid)
+	if (c->callerid && strlen(c->callerid))
 		strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
 	else
 		strcpy(cdr->clid, "");

Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- channel.c	8 Sep 2003 16:48:06 -0000	1.43
+++ channel.c	12 Sep 2003 16:51:35 -0000	1.44
@@ -34,6 +34,7 @@
 #include <asterisk/linkedlists.h>
 #include <asterisk/indications.h>
 #include <asterisk/monitor.h>
+#include <asterisk/causes.h>
 #ifdef ZAPTEL_OPTIMIZATIONS
 #include <sys/ioctl.h>
 #include <linux/zaptel.h>
@@ -1493,8 +1494,7 @@
 	int state = 0;
 	struct ast_channel *chan;
 	struct ast_frame *f;
-	int res;
-	
+	int res = 0;
 	chan = ast_request(type, format, data);
 	if (chan) {
 		if (callerid)
@@ -1504,8 +1504,6 @@
 				res = ast_waitfor(chan, timeout);
 				if (res < 0) {
 					/* Something not cool, or timed out */
-					ast_hangup(chan);
-					chan = NULL;
 					break;
 				}
 				/* If done, break out */
@@ -1516,8 +1514,7 @@
 				f = ast_read(chan);
 				if (!f) {
 					state = AST_CONTROL_HANGUP;
-					ast_hangup(chan);
-					chan = NULL;
+					res = 0;
 					break;
 				}
 				if (f->frametype == AST_FRAME_CONTROL) {
@@ -1537,17 +1534,36 @@
 				}
 				ast_frfree(f);
 			}
-		} else {
-			ast_hangup(chan);
-			chan = NULL;
+		} else
 			ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
-		}
 	} else
 		ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
 	if (chan && (chan->_state == AST_STATE_UP))
 		state = AST_CONTROL_ANSWER;
 	if (outstate)
 		*outstate = state;
+	if (chan && res <= 0) {
+		if (!chan->cdr) {
+			chan->cdr = ast_cdr_alloc();
+			if (chan->cdr)
+				ast_cdr_init(chan->cdr, chan);
+		}
+		if (chan->cdr) {
+			char tmp[256];
+			sprintf(tmp, "%s/%s",type,(char *)data);
+			ast_cdr_setapp(chan->cdr,"Dial",tmp);
+			ast_cdr_update(chan);
+			ast_cdr_start(chan->cdr);
+			ast_cdr_end(chan->cdr);
+			/* If the cause wasn't handled properly */
+			if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
+				ast_cdr_failed(chan->cdr);
+			ast_cdr_reset(chan->cdr,1);
+		} else 
+			ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
+		ast_hangup(chan);
+		chan = NULL;
+	}
 	return chan;
 }
 
@@ -2430,5 +2446,4 @@
 	}
 	return 0;
 }
-
 

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- pbx.c	10 Sep 2003 05:24:49 -0000	1.48
+++ pbx.c	12 Sep 2003 16:51:35 -0000	1.49
@@ -3779,7 +3779,7 @@
 	return NULL;
 }
 
-int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char *context, char *exten, int priority, int *reason, int sync, char *callerid, char *variable )
+int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char *context, char *exten, int priority, int *reason, int sync, char *callerid, char *variable)
 {
 	struct ast_channel *chan;
 	struct async_stat *as;
@@ -3827,6 +3827,27 @@
 				if (option_verbose > 3)
 					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
 				ast_hangup(chan);
+			}
+		} else {
+			/* create a fake channel and execute the "failed" extension (if it exists) within the requested context */
+			/* check if "failed" exists */
+			if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
+				chan = ast_channel_alloc(0);
+				if (chan) {
+					strncpy(chan->name, "OutgoingSpoolFailed", sizeof(chan->name) - 1);
+					if (context && strlen(context))
+						strncpy(chan->context, context, sizeof(chan->context) - 1);
+					strncpy(chan->exten, "failed", sizeof(chan->exten) - 1);
+					chan->priority = 1;
+					/* JDG chanvar */
+					tmp = variable;
+					/* FIXME replace this call with strsep  NOT*/
+					while( (var = strtok_r(NULL, "|", &tmp)) ) {
+						pbx_builtin_setvar( chan, var );
+					} /* /JDG */
+					ast_pbx_run(chan);	
+				} else
+					ast_log(LOG_WARNING, "Can't allocate the channel structure, skipping execution of extension 'failed'\n");
 			}
 		}
 	} else {




More information about the svn-commits mailing list