[Pkg-voip-commits] [janus] 92/163: Added printf format to text2pcap dump method, and session/handle info when dumping

Jonas Smedegaard dr at jones.dk
Sat Oct 28 01:22:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.

commit c3fbbdf825f3077c4b6163e8d043be92eb75cb6a
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Wed Sep 6 11:34:49 2017 +0200

    Added printf format to text2pcap dump method, and session/handle info when dumping
---
 ice.c       | 13 +++++++++----
 text2pcap.c | 10 ++++++++--
 text2pcap.h |  4 ++--
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/ice.c b/ice.c
index 7974a38..f468323 100644
--- a/ice.c
+++ b/ice.c
@@ -1948,6 +1948,7 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 		JANUS_LOG(LOG_ERR, "No handle for stream %d??\n", stream_id);
 		return;
 	}
+	janus_session *session = (janus_session *)handle->session;
 	if(!component->dtls) {	/* Still waiting for the DTLS stack */
 		JANUS_LOG(LOG_WARN, "[%"SCNu64"] Still waiting for the DTLS stack for component %d in stream %d...\n", handle->handle_id, component_id, stream_id);
 		return;
@@ -2064,7 +2065,8 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 				}
 				/* Do we need to dump this packet for debugging? */
 				if(g_atomic_int_get(&handle->dump_packets))
-					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTP, TRUE, buf, buflen, NULL);
+					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTP, TRUE, buf, buflen,
+						"[session=%"SCNu64"][handle=%"SCNu64"]", session->session_id, handle->handle_id);
 				/* Pass the data to the responsible plugin */
 				janus_plugin *plugin = (janus_plugin *)handle->app;
 				if(plugin && plugin->incoming_rtp)
@@ -2239,7 +2241,8 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 			} else {
 				/* Do we need to dump this packet for debugging? */
 				if(g_atomic_int_get(&handle->dump_packets))
-					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTCP, TRUE, buf, buflen, NULL);
+					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTCP, TRUE, buf, buflen,
+						"[session=%"SCNu64"][handle=%"SCNu64"]", session->session_id, handle->handle_id);
 				/* Check if there's an RTCP BYE: in case, let's wrap up */
 				if(janus_rtcp_has_bye(buf, buflen)) {
 					JANUS_LOG(LOG_VERB, "[%"SCNu64"] Got RTCP BYE on stream %"SCNu16" (component %"SCNu16"), closing...\n", handle->handle_id, stream->stream_id, component->component_id);
@@ -3768,7 +3771,8 @@ void *janus_ice_send_thread(void *data) {
 				}
 				/* Do we need to dump this packet for debugging? */
 				if(g_atomic_int_get(&handle->dump_packets))
-					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTCP, FALSE, sbuf, pkt->length, NULL);
+					janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTCP, FALSE, sbuf, pkt->length,
+						"[session=%"SCNu64"][handle=%"SCNu64"]", session->session_id, handle->handle_id);
 				/* Encrypt SRTCP */
 				int protected = pkt->length;
 				int res = 0;
@@ -3861,7 +3865,8 @@ void *janus_ice_send_thread(void *data) {
 					}
 					/* Do we need to dump this packet for debugging? */
 					if(g_atomic_int_get(&handle->dump_packets))
-						janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTP, FALSE, sbuf, pkt->length, NULL);
+						janus_text2pcap_dump(handle->text2pcap, JANUS_TEXT2PCAP_RTP, FALSE, sbuf, pkt->length,
+							"[session=%"SCNu64"][handle=%"SCNu64"]", session->session_id, handle->handle_id);
 					/* Encrypt SRTP */
 					int protected = pkt->length;
 					int res = srtp_protect(component->dtls->srtp_out, sbuf, &protected);
diff --git a/text2pcap.c b/text2pcap.c
index c2d7d02..f30958a 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -105,7 +105,7 @@ janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename, i
 }
 
 int janus_text2pcap_dump(janus_text2pcap *instance,
-		janus_text2pcap_packet type, gboolean incoming, char *buf, int len, char *custom) {
+		janus_text2pcap_packet type, gboolean incoming, char *buf, int len, const char *format, ...) {
 	if(instance == NULL || buf == NULL || len < 1)
 		return -1;
 	janus_mutex_lock_nodebug(&instance->mutex);
@@ -135,7 +135,13 @@ int janus_text2pcap_dump(janus_text2pcap *instance,
 	}
 	g_strlcat(buffer, " ", sizeof(buffer));
 	g_strlcat(buffer, janus_text2pcap_packet_string(type), sizeof(buffer));
-	if(custom && strlen(custom)) {
+	if(format) {
+		/* This callback has variable arguments (error string) */
+		char custom[512];
+		va_list ap;
+		va_start(ap, format);
+		g_vsnprintf(custom, sizeof(custom), format, ap);
+		va_end(ap);
 		g_strlcat(buffer, " ", sizeof(buffer));
 		g_strlcat(buffer, custom, sizeof(buffer));
 	}
diff --git a/text2pcap.h b/text2pcap.h
index b105a35..b137f1d 100644
--- a/text2pcap.h
+++ b/text2pcap.h
@@ -80,10 +80,10 @@ janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename, i
  * @param[in] incoming Whether this is an incoming or outgoing packet
  * @param[in] buf Packet data to dump
  * @param[in] len Size of the packet data to dump
- * @param[in] custom Optional string to append to the line
+ * @param[in] format Format for the optional string to append to the line, if any
  * @returns 0 in case of success, a negative integer otherwise */
 int janus_text2pcap_dump(janus_text2pcap *instance,
-	janus_text2pcap_packet type, gboolean incoming, char *buf, int len, char *custom);
+	janus_text2pcap_packet type, gboolean incoming, char *buf, int len, const char *format, ...) G_GNUC_PRINTF(6, 7);
 
 /*! \brief Close a text2pcap recorder
  * @param[in] instance Instance of the janus_text2pcap recorder to close

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list