[asterisk-commits] branch oej/cdr_radius r28443 - /team/oej/cdr_radius/cdr/cdr_radius.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu May 18 19:03:50 MST 2006


Author: russell
Date: Thu May 18 21:03:50 2006
New Revision: 28443

URL: http://svn.digium.com/view/asterisk?rev=28443&view=rev
Log:
- remove a bunch of unnecessary copying into intermediate buffers when preparing
  the radius cdr record
- fix error detection from the function preparing the radius record

Modified:
    team/oej/cdr_radius/cdr/cdr_radius.c

Modified: team/oej/cdr_radius/cdr/cdr_radius.c
URL: http://svn.digium.com/view/asterisk/team/oej/cdr_radius/cdr/cdr_radius.c?rev=28443&r1=28442&r2=28443&view=diff
==============================================================================
--- team/oej/cdr_radius/cdr/cdr_radius.c (original)
+++ team/oej/cdr_radius/cdr/cdr_radius.c Thu May 18 21:03:50 2006
@@ -97,75 +97,66 @@
 
 static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
 {
-	int aux = PW_STATUS_STOP;
-	char buf[253];
+	int recordtype = PW_STATUS_STOP;
 	struct tm tm;
 	char timestr[128];
-
-	if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &aux, 0, 0)) {
+	char *tmp;
+
+	if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Account code */
-	ast_copy_string(buf, cdr->accountcode, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_ACCT_CODE, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
  	/* Source */
-	ast_copy_string(buf, cdr->src, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_SRC, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
  	/* Destination */
-	ast_copy_string(buf, cdr->dst, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_DST, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
  	/* Destination context */
-	ast_copy_string(buf, cdr->dcontext, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_DST_CTX, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Caller ID */
-	ast_copy_string(buf, cdr->clid, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_CLID, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Channel */
-	ast_copy_string(buf, cdr->channel, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_CHAN, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Destination Channel */
-	ast_copy_string(buf, cdr->dstchannel, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_DST_CHAN, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Last Application */
-	ast_copy_string(buf, cdr->lastapp, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_LAST_APP, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Last Data */
-	ast_copy_string(buf, cdr->lastdata, sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_LAST_DATA, &buf, strlen(buf), VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
@@ -176,7 +167,7 @@
 		gmtime_r(&(cdr->start.tv_sec), &tm);
 	else
 		localtime_r(&(cdr->start.tv_sec), &tm);
-	strftime(timestr, 128, DATE_FORMAT, &tm);
+	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
@@ -187,7 +178,7 @@
 		gmtime_r(&(cdr->answer.tv_sec), &tm);
 	else
 		localtime_r(&(cdr->answer.tv_sec), &tm);
-	strftime(timestr, 128, DATE_FORMAT, &tm);
+	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
@@ -198,44 +189,41 @@
 		gmtime_r(&(cdr->end.tv_sec), &tm);
 	else
 		localtime_r(&(cdr->end.tv_sec), &tm);
-	strftime(timestr, 128, DATE_FORMAT, &tm);
+	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
  	/* Duration */ 
-	aux = cdr->duration;
-	if (!rc_avpair_add(rh, send, PW_AST_DURATION, &aux, 0, VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Billable seconds */
-	aux = cdr->billsec;
-	if (!rc_avpair_add(rh, send, PW_AST_BILL_SEC, &aux, 0, VENDOR_CODE)) {
+	if (!rc_avpair_add(rh, send, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* Disposition */
-	ast_copy_string(buf, ast_cdr_disp2str(cdr->disposition), sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_DISPOSITION, &buf, strlen(buf), VENDOR_CODE)) {
+	tmp = ast_cdr_disp2str(cdr->disposition);
+	if (!rc_avpair_add(rh, send, PW_AST_DISPOSITION, &tmp, strlen(tmp), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	/* AMA Flags */
-	ast_copy_string(buf, ast_cdr_flags2str(cdr->amaflags), sizeof(buf));
-	if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, &buf, strlen(buf), VENDOR_CODE)) {
+	tmp = ast_cdr_flags2str(cdr->amaflags);
+	if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, &tmp, strlen(tmp), VENDOR_CODE)) {
 		ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 		return -1;
 	}
 
 	if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUNIQUEID)) {
 		/* Unique ID */
-		ast_copy_string(buf, cdr->uniqueid, sizeof(buf));
-		if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &buf, strlen(buf), VENDOR_CODE)) {
+		if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE)) {
 			ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 			return -1;
 		}
@@ -243,14 +231,13 @@
 
 	if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUSERFIELD)) {
 		/* append the user field */
-		ast_copy_string(buf, cdr->userfield, sizeof(buf));
-		if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &buf, strlen(buf), VENDOR_CODE)) {
+		if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE)) {
 			ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
 			return -1;
 		}
 	}
 
-	return 1;
+	return 0;
 }
 
 static int radius_log(struct ast_cdr *cdr)
@@ -258,14 +245,12 @@
 	int result = ERROR_RC;
 	VALUE_PAIR *send = NULL;
 
-	if (!build_radius_record(&send, cdr))
+	if (build_radius_record(&send, cdr))
 		ast_log(LOG_WARNING, "Unable to create RADIUS record. CDR not recorded!\n");
 	
 	result = rc_acct(rh, 0, send);
-	if (result == OK_RC)
-		ast_log(LOG_NOTICE, "RADIUS CDR recorded.\n");
-	else
-		ast_log(LOG_NOTICE, "Failed to record CDR.\n");
+	if (result != OK_RC)
+		ast_log(LOG_ERROR, "Failed to record Radius CDR record!\n");
 
 	return result;
 }



More information about the asterisk-commits mailing list