changeset 114:a30c25fb4c2f

sip-in: generate CDR syslog entries
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 22:41:16 -0800
parents bfc97065bf51
children 1bbe57df74f6
files sip-in/call_clear.c sip-in/invite.c
diffstat 2 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/call_clear.c	Wed Sep 28 19:08:13 2022 -0800
+++ b/sip-in/call_clear.c	Wed Sep 28 22:41:16 2022 -0800
@@ -55,7 +55,7 @@
 		if (call->overall_state == OVERALL_STATE_DEAD_SIP &&
 		    call->sip_clear_time >= cur_event_time.tv_sec) {
 			*pp = call->next;
-			syslog(LOG_INFO, "call in%06u cleared",
+			syslog(LOG_INFO, "Call in%06u finished",
 				call->in_tag_num);
 			free(call);
 			continue;
--- a/sip-in/invite.c	Wed Sep 28 19:08:13 2022 -0800
+++ b/sip-in/invite.c	Wed Sep 28 22:41:16 2022 -0800
@@ -101,7 +101,8 @@
 	struct sdp_parse sdp_parse;
 	struct sdp_gen sdp_gen;
 	struct call *call;
-	char *dp;
+	char *dp, cdr_str[80];
+	unsigned cdr_num_len, cdr_cnam_len;
 	unsigned req_uri_len, to_hdr_len, copylen;
 	int rc;
 
@@ -242,10 +243,28 @@
 		sip_tx_packet(&resp, sin);
 		return;
 	}
-	/* SIP INVITE validation done - check if GSM service is up */
+	/* SIP INVITE validation done - gather CDR info */
+	cdr_num_len = gfrom.user_len;
+	if (cdr_num_len > 33)
+		cdr_num_len = 33;
+	cdr_cnam_len = gfrom.cnam_len;
+	if (cdr_cnam_len > 33)
+		cdr_cnam_len = 33;
+	if (cdr_cnam_len)
+		sprintf(cdr_str, "%.*s (%s%.*s%s)", cdr_num_len, gfrom.user,
+			gfrom.cnam_quoted ? "\"" : "", cdr_cnam_len, gfrom.cnam,
+			gfrom.cnam_quoted ? "\"" : "");
+	else
+		sprintf(cdr_str, "%.*s", cdr_num_len, gfrom.user);
+	hval = get_single_header(req, "P-Asserted-Identity", (char *) 0,
+				 (int *) 0);
+	/* check if GSM service is up */
 	rc = connect_gsm_mtcall();
 	if (rc < 0) {
-gsm_offline:	start_response_out_msg(&resp, "480 GSM service is offline");
+gsm_offline:	syslog(LOG_INFO, "Down-call from %s to %s", cdr_str, uri_user);
+		if (hval)
+			syslog(LOG_INFO, "Down-call PAI: %s", hval);
+		start_response_out_msg(&resp, "480 GSM service is offline");
 		goto error_resp;
 	}
 	rc = connect_tmgw_socket();
@@ -313,7 +332,10 @@
 	/* add to call list */
 	call->next = call_list;
 	call_list = call;
-	syslog(LOG_INFO, "call in%06u started", call->in_tag_num);
+	syslog(LOG_INFO, "Call in%06u from %s to %s", call->in_tag_num,
+		cdr_str, uri_user);
+	if (hval)
+		syslog(LOG_INFO, "Call in%06u PAI: %s", call->in_tag_num, hval);
 	/* send CRCX to TMGW */
 	tmgw_send_crcx(call);
 	call->overall_state = OVERALL_STATE_CRCX;