[Asterisk-cvs] asterisk cdr.c,1.14,1.15

markster at lists.digium.com markster at lists.digium.com
Sun Jun 20 11:33:40 CDT 2004


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

Modified Files:
	cdr.c 
Log Message:
Allow CDR's to be linked and work on the linked list


Index: cdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cdr.c	9 Jun 2004 01:45:07 -0000	1.14
+++ cdr.c	20 Jun 2004 15:19:36 -0000	1.15
@@ -105,8 +105,10 @@
 
 void ast_cdr_free(struct ast_cdr *cdr)
 {
-	char *chan; 
-	if (cdr) {
+	char *chan;
+	struct ast_cdr *next; 
+	while (cdr) {
+		next = cdr->next;
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (!cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' not posted\n", chan);
@@ -115,6 +117,7 @@
 		if (!cdr->start.tv_sec && !cdr->start.tv_usec)
 			ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
 		free(cdr);
+		cdr = next;
 	}
 }
 
@@ -131,20 +134,21 @@
 void ast_cdr_start(struct ast_cdr *cdr)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
 		if (cdr->start.tv_sec || cdr->start.tv_usec)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already started\n", chan);
 		gettimeofday(&cdr->start, NULL);
+		cdr = cdr->next;
 	}
 }
 
 void ast_cdr_answer(struct ast_cdr *cdr)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
@@ -153,36 +157,39 @@
 		if (!cdr->answer.tv_sec && !cdr->answer.tv_usec) {
 			gettimeofday(&cdr->answer, NULL);
 		}
+		cdr = cdr->next;
 	}
 }
 
 void ast_cdr_busy(struct ast_cdr *cdr)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
 		if (cdr->disposition < AST_CDR_BUSY)
 			cdr->disposition = AST_CDR_BUSY;
+		cdr = cdr->next;
 	}
 }
 
 void ast_cdr_failed(struct ast_cdr *cdr)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(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;
+		cdr->disposition = AST_CDR_FAILED;
+		cdr = cdr->next;
 	}
 }
 
 int ast_cdr_disposition(struct ast_cdr *cdr, int cause)
 {
 	int res = 0;
-	if (cdr) {
+	while (cdr) {
 		switch(cause) {
 			case AST_CAUSE_BUSY:
 				ast_cdr_busy(cdr);
@@ -199,6 +206,7 @@
 				res = -1;
 				ast_log(LOG_WARNING, "We don't handle that cause yet\n");
 		}
+		cdr = cdr->next;
 	}
 	return res;
 }
@@ -206,18 +214,19 @@
 void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chann)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
 		strncpy(cdr->dstchannel, chann, sizeof(cdr->dstchannel) - 1);
+		cdr = cdr->next;
 	}
 }
 
 void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data)
 {
 	char *chan; 
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
@@ -227,6 +236,7 @@
 		if (!data)
 			data = "";
 		strncpy(cdr->lastdata, data, sizeof(cdr->lastdata) - 1);
+		cdr = cdr->next;
 	}
 }
 
@@ -234,7 +244,7 @@
 {
 	char tmp[AST_MAX_EXTENSION] = "";
 	char *num, *name;
-	if (cdr) {
+	while (cdr) {
 		/* Grab source from ANI or normal Caller*ID */
 		if (c->ani)
 			strncpy(tmp, c->ani, sizeof(tmp) - 1);
@@ -249,6 +259,7 @@
 			ast_shrink_phone_number(num);
 			strncpy(cdr->src, num, sizeof(cdr->src) - 1);
 		}
+		cdr = cdr->next;
 	}
 	return 0;
 }
@@ -258,7 +269,7 @@
 	char *chan;
 	char *num, *name;
 	char tmp[AST_MAX_EXTENSION] = "";
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (!ast_strlen_zero(cdr->channel)) 
 			ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan); 
@@ -292,6 +303,7 @@
 		strncpy(cdr->dcontext, c->context, sizeof(cdr->dcontext) - 1);
 		/* Unique call identifier */
 		strncpy(cdr->uniqueid, c->uniqueid, sizeof(cdr->uniqueid) - 1);
+		cdr = cdr->next;
 	}
 	return 0;
 }
@@ -299,7 +311,7 @@
 void ast_cdr_end(struct ast_cdr *cdr)
 {
 	char *chan;
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
@@ -307,6 +319,7 @@
 			ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan);
 		if (!cdr->end.tv_sec && !cdr->end.tv_usec) 
 			gettimeofday(&cdr->end, NULL);
+		cdr = cdr->next;
 	}
 }
 
@@ -344,8 +357,10 @@
 	struct ast_cdr *cdr = chan->cdr;
 
 	strncpy(chan->accountcode, account, sizeof(chan->accountcode) - 1);
-	if (cdr)
+	while (cdr) {
 		strncpy(cdr->accountcode, chan->accountcode, sizeof(cdr->accountcode) - 1);
+		cdr = cdr->next;
+	}
 	return 0;
 }
 
@@ -353,8 +368,10 @@
 {
 	struct ast_cdr *cdr = chan->cdr;
 
-	if (cdr)
+	while (cdr) {
 		strncpy(cdr->userfield, userfield, sizeof(cdr->userfield) - 1);
+		cdr = cdr->next;
+	}
 	return 0;
 }
 
@@ -362,10 +379,11 @@
 {
 	struct ast_cdr *cdr = chan->cdr;
 
-	if (cdr)
+	while (cdr)
 	{
 		int len = strlen(cdr->userfield);
 		strncpy(cdr->userfield+len, userfield, sizeof(cdr->userfield) - len - 1);
+		cdr = cdr->next;
 	}
 	return 0;
 }
@@ -376,7 +394,7 @@
 	char *name, *num;
 	char tmp[AST_MAX_EXTENSION] = "";
 	/* Grab source from ANI or normal Caller*ID */
-	if (cdr) {
+	while (cdr) {
 		if (c->ani)
 			strncpy(tmp, c->ani, sizeof(tmp) - 1);
 		else if (c->callerid && !ast_strlen_zero(c->callerid))
@@ -397,6 +415,7 @@
 		/* Destination information */
 		strncpy(cdr->dst, c->exten, sizeof(cdr->dst) - 1);
 		strncpy(cdr->dcontext, c->context, sizeof(cdr->dcontext) - 1);
+		cdr = cdr->next;
 	}
 	return 0;
 }
@@ -418,7 +437,7 @@
 {
 	char *chan;
 	struct ast_cdr_beitem *i;
-	if (cdr) {
+	while (cdr) {
 		chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";
 		if (cdr->posted)
 			ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
@@ -439,12 +458,13 @@
 			i = i->next;
 		}
 		ast_mutex_unlock(&cdrlock);
+		cdr = cdr->next;
 	}
 }
 
 void ast_cdr_reset(struct ast_cdr *cdr, int post)
 {
-	if (cdr) {
+	while (cdr) {
 		/* Post if requested */
 		if (post) {
 			ast_cdr_end(cdr);
@@ -459,5 +479,6 @@
 		cdr->duration = 0;
 		ast_cdr_start(cdr);
 		cdr->disposition = AST_CDR_NOANSWER;
+		cdr = cdr->next;
 	}
 }




More information about the svn-commits mailing list