[Pkg-voip-commits] [janus] 91/163: Added option to truncate packets when dumping via text2pcap

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 fefaacc4ed07080f7d862e7280654321d369cea1
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Wed Sep 6 11:20:54 2017 +0200

    Added option to truncate packets when dumping via text2pcap
---
 janus.c      | 6 ++++--
 mainpage.dox | 6 ++++--
 text2pcap.c  | 8 ++++++--
 text2pcap.h  | 5 ++++-
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/janus.c b/janus.c
index e4bbf65..3a05d39 100644
--- a/janus.c
+++ b/janus.c
@@ -134,7 +134,8 @@ static struct janus_json_parameter nmt_parameters[] = {
 };
 static struct janus_json_parameter text2pcap_parameters[] = {
 	{"folder", JSON_STRING, 0},
-	{"filename", JSON_STRING, 0}
+	{"filename", JSON_STRING, 0},
+	{"truncate", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE}
 };
 
 /* Admin/Monitor helpers */
@@ -2212,11 +2213,12 @@ int janus_process_incoming_admin_request(janus_request *request) {
 			}
 			const char *folder = json_string_value(json_object_get(root, "folder"));
 			const char *filename = json_string_value(json_object_get(root, "filename"));
+			int truncate = json_integer_value(json_object_get(root, "truncate"));
 			if(handle->text2pcap != NULL) {
 				ret = janus_process_error(request, session_id, transaction_text, JANUS_ERROR_UNKNOWN, "text2pcap already started");
 				goto jsondone;
 			}
-			handle->text2pcap = janus_text2pcap_create(folder, filename);
+			handle->text2pcap = janus_text2pcap_create(folder, filename, truncate);
 			if(handle->text2pcap == NULL) {
 				ret = janus_process_error(request, session_id, transaction_text, JANUS_ERROR_UNKNOWN, "Error starting text2pcap dump");
 				goto jsondone;
diff --git a/mainpage.dox b/mainpage.dox
index 05788a6..3f9525c 100644
--- a/mainpage.dox
+++ b/mainpage.dox
@@ -1836,8 +1836,9 @@ POST /admin/12345678/98765432
  * all plugins make use of when they're interested in recordings.
  *
  * The syntax for the \c start_text2pcap command is trivial, as all you
- * need to specify are information on the handle to dump, and information
- * on the target file (target folder and filename):
+ * need to specify are information on the handle to dump, information
+ * on the target file (target folder and filename), and whether to truncate
+ * packets or not before dumping them:
  *
 \verbatim
 POST /admin/12345678/98765432
@@ -1845,6 +1846,7 @@ POST /admin/12345678/98765432
 	"janus" : "start_text2pcap",
 	"folder" : "<folder to save the dump to; optional, current folder if missing>",
 	"filename" : "<filename of the dump; optional, random filename if missing>",
+	"truncate" : "<number of bytes to truncate at; optional, truncate=0 (don't truncate) if missing>",
 	"transaction" : "<random alphanumeric string>",
 	"admin_secret" : "<password specified in janus.cfg, if any>"
 }
diff --git a/text2pcap.c b/text2pcap.c
index 6944ea2..c2d7d02 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -49,7 +49,9 @@ const char *janus_text2pcap_packet_string(janus_text2pcap_packet type) {
 	return NULL;
 }
 
-janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename) {
+janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename, int truncate) {
+	if(truncate < 0)
+		return NULL;
 	/* Create the text2pcap instance */
 	janus_text2pcap *tp = g_malloc0(sizeof(janus_text2pcap));
 	if(tp == NULL) {
@@ -58,6 +60,7 @@ janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename) {
 	}
 	tp->filename = NULL;
 	tp->file = NULL;
+	tp->truncate = truncate;
 	g_atomic_int_set(&tp->writable, 0);
 	if(dir != NULL) {
 		/* Create the directory, if needed */
@@ -124,7 +127,8 @@ int janus_text2pcap_dump(janus_text2pcap *instance,
 	memset(buffer, 0, sizeof(buffer));
 	g_snprintf(buffer, sizeof(buffer), "%s %s 000000 ", incoming ? "I" : "O", timestamp);
 	int i=0;
-	for(i=0; i<len; i++) {
+	int stop = instance->truncate ? (len > instance->truncate ? instance->truncate : len) : len;
+	for(i=0; i<stop; i++) {
 		memset(byte, 0, sizeof(byte));
 		g_snprintf(byte, sizeof(byte), " %02x", (unsigned char)buf[i]);
 		g_strlcat(buffer, byte, sizeof(buffer));
diff --git a/text2pcap.h b/text2pcap.h
index a246c3f..b105a35 100644
--- a/text2pcap.h
+++ b/text2pcap.h
@@ -49,6 +49,8 @@ typedef struct janus_text2pcap {
 	char *filename;
 	/*! \brief Pointer to the file handle */
 	FILE *file;
+	/*! \brief Number of bytes to truncate at */
+	int truncate;
 	/*! \brief Whether we can write to this file or not */
 	volatile int writable;
 	/*! \brief Mutex to lock/unlock this recorder instance */ 
@@ -68,8 +70,9 @@ const char *janus_text2pcap_packet_string(janus_text2pcap_packet type);
  * is passed, a random filename will be used.
  * @param[in] dir Path of the directory to save the recording into (will try to create it if it doesn't exist)
  * @param[in] filename Filename to use for the recording
+ * @param[in] truncate Number of bytes to truncate each packet at (0 to not truncate at all)
  * @returns A valid janus_text2pcap instance in case of success, NULL otherwise */
-janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename);
+janus_text2pcap *janus_text2pcap_create(const char *dir, const char *filename, int truncate);
 
 /*! \brief Dump an RTP or RTCP packet
  * @param[in] instance Instance of the janus_text2pcap recorder to dump the packet to

-- 
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