[asterisk-commits] mjordan: branch mjordan/12-hep r407936 - in /team/mjordan/12-hep: include/ast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 10 21:02:43 CST 2014


Author: mjordan
Date: Mon Feb 10 21:02:38 2014
New Revision: 407936

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407936
Log:
More HEP stuff

(1) We now push updates to HEP through a taskprocessor. That prevents a delay
    in res_hep from impacting the PJSIP stack
(2) More cleanup



Modified:
    team/mjordan/12-hep/include/asterisk/res_hep.h
    team/mjordan/12-hep/res/res_hep.c
    team/mjordan/12-hep/res/res_hep.exports.in
    team/mjordan/12-hep/res/res_hep_pjsip.c
    team/mjordan/12-hep/res/res_hep_rtcp.c
    team/mjordan/12-hep/res/res_rtp_asterisk.c

Modified: team/mjordan/12-hep/include/asterisk/res_hep.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/include/asterisk/res_hep.h?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/include/asterisk/res_hep.h (original)
+++ team/mjordan/12-hep/include/asterisk/res_hep.h Mon Feb 10 21:02:38 2014
@@ -63,19 +63,44 @@
 	char *uuid;
 	/*! If non-zero, the payload accompanying this capture info will be compressed */
 	int zipped:1;
+	/*! The actual payload */
+	void *payload;
+	/*! The size of the payload */
+	size_t len;
 };
+
+/*!
+ * \brief Create a \ref hepv3_capture_info object
+ *
+ * This returned object with be an ao2 reference counted object.
+ * Any parameter that is a pointer to an object should be
+ * allocated on the heap, and will be free'd when the
+ * \ref hepv3_capture_info object is reclaimed.
+ *
+ * \param payload The payload to send to the HEP capture node
+ * \param len     Length of \ref payload
+ * 
+ * \retval A \ref hepv3_capture_info ref counted object on success
+ * \retval NULL on error
+ */
+struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t len);
 
 /*!
  * \brief Send a generic packet capture to HEPv3
  *
- * \param capture_info Information describing the packet
- * \param buf The buffer containing the data to be sent
- * \param len The length of the buffer
+ * \param capture_info Information describing the packet. This
+ * should be a reference counted object, created via
+ * \ref hepv3_create_capture_info.
+ *
+ * Once this function is called, it assumes ownership of the
+ * \ref capture_info object and steals the reference of the
+ * object. Regardless of success or failure, the calling function
+ * should assumed that this function will own the object.
  *
  * \retval 0 on success
  * \retval -1 on error
  */
-int hepv3_send_packet(struct hepv3_capture_info *capture_info, const void *buf, size_t len);
+int hepv3_send_packet(struct hepv3_capture_info *capture_info);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/mjordan/12-hep/res/res_hep.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hep.c?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/res/res_hep.c (original)
+++ team/mjordan/12-hep/res/res_hep.c Mon Feb 10 21:02:38 2014
@@ -37,8 +37,8 @@
  */
 
 /*** MODULEINFO
-    <defaultenabled>no</defaultenabled>
-    <support_level>extended</support_level>
+	<defaultenabled>no</defaultenabled>
+	<support_level>extended</support_level>
  ***/
 
 /*** DOCUMENTATION
@@ -82,6 +82,7 @@
 #include "asterisk/module.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/config_options.h"
+#include "asterisk/taskprocessor.h"
 #include "asterisk/res_hep.h"
 
 #include <netinet/ip.h>
@@ -260,22 +261,28 @@
 /*! \brief Global configuration for the module */
 struct hepv3_global_config {
 	unsigned int enabled;                    /*!< Whether or not sending is enabled */
-    unsigned int capture_id;                 /*!< Capture ID for this agent */
+	unsigned int capture_id;                 /*!< Capture ID for this agent */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(capture_address);   /*!< Address to send to */
 		AST_STRING_FIELD(capture_password);  /*!< Password for Homer server */
 	);
 };
 
+/*! \brief The actual module config */
+struct module_config {
+	struct hepv3_global_config *general; /*!< The general config settings */
+};
+
+/*! \brief Run-time data derived from \ref hepv3_global_config */
 struct hepv3_runtime_data {
-    struct ast_sockaddr remote_addr;
-    int sockfd;
+	struct ast_sockaddr remote_addr;  /*!< The address to send to */
+	int sockfd;                       /*!< The socket file descriptor */
 };
 
 static struct aco_type global_option = {
 	.type = ACO_GLOBAL,
 	.name = "general",
-	.item_offset = 0,
+	.item_offset = offsetof(struct module_config, general),
 	.category_match = ACO_WHITELIST,
 	.category = "^general$",
 };
@@ -290,18 +297,20 @@
 /*! \brief The module configuration container */
 static AO2_GLOBAL_OBJ_STATIC(global_config);
 
+/*! \brief Current module data */
 static AO2_GLOBAL_OBJ_STATIC(global_data);
 
-static void *hepv3_config_alloc(void);
+static struct ast_taskprocessor *hep_queue_tp;
+
+static void *module_config_alloc(void);
 static void hepv3_config_post_apply(void);
 
 /*! \brief Register information about the configs being processed by this module */
-CONFIG_INFO_STANDARD(cfg_info, global_config, hepv3_config_alloc,
+CONFIG_INFO_STANDARD(cfg_info, global_config, module_config_alloc,
 	.files = ACO_FILES(&hepv3_conf),
-    .post_apply_config = hepv3_config_post_apply,
+	.post_apply_config = hepv3_config_post_apply,
 );
 
-/*! \brief HEPv3 configuration object destructor */
 static void hepv3_config_dtor(void *obj)
 {
 	struct hepv3_global_config *config = obj;
@@ -322,46 +331,106 @@
 	return config;
 }
 
+/*! \brief Configuration object destructor */
+static void module_config_dtor(void *obj)
+{
+	struct module_config *config = obj;
+
+	if (config->general) {
+		ao2_ref(config->general, -1);
+	}
+}
+
+/*! \brief Module config constructor */
+static void *module_config_alloc(void)
+{
+	struct module_config *config;
+
+	config = ao2_alloc(sizeof(*config), module_config_dtor);
+	if (!config) {
+		return NULL;
+	}
+
+	config->general = hepv3_config_alloc();
+	if (!config->general) {
+		ao2_ref(config, -1);
+		config = NULL;
+	}
+
+	return config;
+}
+
+/*! \brief HEPv3 run-time data destructor */
 static void hepv3_data_dtor(void *obj)
 {
-    struct hepv3_runtime_data *data = obj;
-
-    if (data->sockfd > -1) {
-        close(data->sockfd);
-        data->sockfd = -1;
-    }
-}
-
+	struct hepv3_runtime_data *data = obj;
+
+	if (data->sockfd > -1) {
+		close(data->sockfd);
+		data->sockfd = -1;
+	}
+}
+
+/*! \brief Allocate the HEPv3 run-time data */
 static struct hepv3_runtime_data *hepv3_data_alloc(struct hepv3_global_config *config)
 {
-    struct hepv3_runtime_data *data;
-
-    data = ao2_alloc(sizeof(*data), hepv3_data_dtor);
-    if (!data) {
-        return NULL;
-    }
-
-    if (ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
-        ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
-        ao2_ref(data, -1);
-        return NULL;
-    }
-
-    data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
-    if (data->sockfd < 0) {
-        ast_log(AST_LOG_WARNING, "Failed to create socket for address %s: %s\n",
-                config->capture_address, strerror(errno));
-        ao2_ref(data, -1);
-        return NULL;
-    }
-
-    return data;
-}
-
-int hepv3_send_packet(struct hepv3_capture_info *capture_info, const void *buf, size_t len)
-{
-	RAII_VAR(struct hepv3_global_config *, hepv3_config, ao2_global_obj_ref(global_config), ao2_cleanup);
+	struct hepv3_runtime_data *data;
+
+	data = ao2_alloc(sizeof(*data), hepv3_data_dtor);
+	if (!data) {
+		return NULL;
+	}
+
+	if (!ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
+		ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
+		ao2_ref(data, -1);
+		return NULL;
+	}
+
+	data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
+	if (data->sockfd < 0) {
+		ast_log(AST_LOG_WARNING, "Failed to create socket for address %s: %s\n",
+				config->capture_address, strerror(errno));
+		ao2_ref(data, -1);
+		return NULL;
+	}
+
+	return data;
+}
+
+static void capture_info_dtor(void *obj)
+{
+	struct hepv3_capture_info *info = obj;
+
+	ast_free(info->uuid);
+	ast_free(info->payload);
+}
+
+struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t len)
+{
+	struct hepv3_capture_info *info;
+
+	info = ao2_alloc(sizeof(*info), capture_info_dtor);
+	if (!info) {
+		return NULL;
+	}
+
+	info->payload = ast_malloc(len);
+	if (!info->payload) {
+		ao2_ref(info, -1);
+		return NULL;
+	}
+	memcpy(info->payload, payload, len);
+	info->len = len;
+
+	return info;
+}
+
+static int hep_queue_cb(void *data)
+{
+	RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
 	RAII_VAR(struct hepv3_runtime_data *, hepv3_data, ao2_global_obj_ref(global_data), ao2_cleanup);
+	struct hepv3_capture_info *capture_info = data;
 	struct hep_generic hg_pkt;
 	unsigned int packet_len = 0, sock_buffer_len;
 	struct hep_chunk_ip4 ipv4_src, ipv4_dst;
@@ -370,7 +439,7 @@
 	void *sock_buffer;
 	int res;
 
-	if (!hepv3_config || !hepv3_data || !hepv3_config->enabled) {
+	if (!capture_info || !config || !hepv3_data) {
 		return 0;
 	}
 
@@ -385,12 +454,13 @@
 	memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
 
 	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, 0x11);
-	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, ast_sockaddr_port(&capture_info->src_addr));
-	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, ast_sockaddr_port(&capture_info->dst_addr));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, htons(ast_sockaddr_port(&capture_info->src_addr)));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, htons(ast_sockaddr_port(&capture_info->dst_addr)));
 	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
 	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_usec, CHUNK_TYPE_TIMESTAMP_USEC, htonl(capture_info->capture_time.tv_usec));
 	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.proto_t, CHUNK_TYPE_PROTOCOL_TYPE, capture_info->capture_type);
-	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.capt_id, CHUNK_TYPE_CAPTURE_AGENT_ID, hepv3_config->capture_id);
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.capt_id, CHUNK_TYPE_CAPTURE_AGENT_ID, htonl(config->general->capture_id));
+
 	if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
 		INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_family,
 			CHUNK_TYPE_IP_PROTOCOL_FAMILY, AF_INET);
@@ -415,18 +485,15 @@
 		packet_len += (sizeof(ipv6_src) + sizeof(ipv6_dst));
 	}
 
-	if (!ast_strlen_zero(hepv3_config->capture_password))  {
-		INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(hepv3_config->capture_password));
-		packet_len += auth_key.length;
-	}
-
+	if (!ast_strlen_zero(config->general->capture_password))  {
+		INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(config->general->capture_password));
+		packet_len += strlen(config->general->capture_password);
+	}
 	INITIALIZE_GENERIC_HEP_IDS_VAR(&uuid, CHUNK_TYPE_UUID, strlen(capture_info->uuid));
-	packet_len += uuid.length;
-
+	packet_len += (sizeof(uuid) + strlen(capture_info->uuid));
 	INITIALIZE_GENERIC_HEP_IDS_VAR(&payload,
-		capture_info->zipped ? CHUNK_TYPE_PAYLOAD_ZIP : CHUNK_TYPE_PAYLOAD, len);
-	packet_len += payload.length;
-
+		capture_info->zipped ? CHUNK_TYPE_PAYLOAD_ZIP : CHUNK_TYPE_PAYLOAD, capture_info->len);
+	packet_len += (sizeof(payload) + capture_info->len);
 	hg_pkt.header.length = htons(packet_len);
 
 	/* Build the buffer to send */
@@ -453,11 +520,11 @@
 	}
 
 	/* Auth Key */
-	if (!ast_strlen_zero(hepv3_config->capture_password)) {
+	if (!ast_strlen_zero(config->general->capture_password)) {
 		memcpy(sock_buffer + sock_buffer_len, &auth_key, sizeof(auth_key));
 		sock_buffer_len += sizeof(auth_key);
-		memcpy(sock_buffer + sock_buffer_len, hepv3_config->capture_password, strlen(hepv3_config->capture_password));
-		sock_buffer_len += strlen(hepv3_config->capture_password);
+		memcpy(sock_buffer + sock_buffer_len, config->general->capture_password, strlen(config->general->capture_password));
+		sock_buffer_len += strlen(config->general->capture_password);
 	}
 
 	/* UUID */
@@ -465,12 +532,12 @@
 	sock_buffer_len += sizeof(uuid);
 	memcpy(sock_buffer + sock_buffer_len, capture_info->uuid, strlen(capture_info->uuid));
 	sock_buffer_len += strlen(capture_info->uuid);
-
+	ast_log(AST_LOG_ERROR, "UUID packet length: %d %ld\n", sock_buffer_len, strlen(capture_info->uuid));
 	/* Packet! */
 	memcpy(sock_buffer + sock_buffer_len, &payload, sizeof(payload));
 	sock_buffer_len += sizeof(payload);
-	memcpy(sock_buffer + sock_buffer_len, buf, len);
-	sock_buffer_len += len;
+	memcpy(sock_buffer + sock_buffer_len, capture_info->payload, capture_info->len);
+	sock_buffer_len += capture_info->len;
 
 	ast_assert(sock_buffer_len == packet_len);
 
@@ -488,17 +555,34 @@
 	return res;
 }
 
+int hepv3_send_packet(struct hepv3_capture_info *capture_info)
+{
+	RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
+	int res;
+
+	if (!config->general->enabled) {
+		return 0;
+	}
+
+	res = ast_taskprocessor_push(hep_queue_tp, hep_queue_cb, capture_info);
+	if (res == -1) {
+		ao2_ref(capture_info, -1);
+	}
+
+	return res;
+}
+
 static void hepv3_config_post_apply(void)
 {
-    RAII_VAR(struct hepv3_global_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
-    struct hepv3_runtime_data *data;
-
-    data = hepv3_data_alloc(mod_cfg);
-    if (!data) {
-        return;
-    }
-
-    ao2_global_obj_replace_unref(global_data, data);
+	RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
+	struct hepv3_runtime_data *data;
+
+	data = hepv3_data_alloc(mod_cfg->general);
+	if (!data) {
+		return;
+	}
+
+	ao2_global_obj_replace_unref(global_data, data);
 }
 
 static int reload_module(void)
@@ -511,9 +595,13 @@
 
 static int unload_module(void)
 {
+	if (hep_queue_tp) {
+		hep_queue_tp = ast_taskprocessor_unreference(hep_queue_tp);
+	}
+
 	ao2_global_obj_release(global_config);
-    ao2_global_obj_release(global_data);
-    aco_info_destroy(&cfg_info);
+	ao2_global_obj_release(global_data);
+	aco_info_destroy(&cfg_info);
 
 	return 0;
 }
@@ -523,16 +611,19 @@
  */
 static int load_module(void)
 {
-    RAII_VAR(struct hepv3_global_config *, mod_cfg, NULL, ao2_cleanup);
-
 	if (aco_info_init(&cfg_info)) {
+		goto error;
+	}
+
+	hep_queue_tp = ast_taskprocessor_get("hep_queue_tp", TPS_REF_DEFAULT);
+	if (!hep_queue_tp) {
 		goto error;
 	}
 
 	aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
 	aco_option_register(&cfg_info, "capture-address", ACO_EXACT, global_options, DEFAULT_HEP_SERVER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_address));
 	aco_option_register(&cfg_info, "capture-password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
-    aco_option_register(&cfg_info, "capture-id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
+	aco_option_register(&cfg_info, "capture-id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
 
 	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
 		goto error;
@@ -545,7 +636,7 @@
 	return AST_MODULE_LOAD_DECLINE;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "HEPv3 API",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "HEPv3 API",
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload_module,

Modified: team/mjordan/12-hep/res/res_hep.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hep.exports.in?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/res/res_hep.exports.in (original)
+++ team/mjordan/12-hep/res/res_hep.exports.in Mon Feb 10 21:02:38 2014
@@ -1,6 +1,7 @@
 {
 	global:
 		LINKER_SYMBOL_PREFIX*hepv3_send_packet;
+		LINKER_SYMBOL_PREFIX*hepv3_create_capture_info;
 	local:
 		*;
 };

Modified: team/mjordan/12-hep/res/res_hep_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hep_pjsip.c?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/res/res_hep_pjsip.c (original)
+++ team/mjordan/12-hep/res/res_hep_pjsip.c Mon Feb 10 21:02:38 2014
@@ -47,21 +47,35 @@
 {
 	char local_buf[256];
 	char remote_buf[256];
-	struct hepv3_capture_info capture_info;
+	char *uuid;
+	struct hepv3_capture_info *capture_info;
 	pjsip_cid_hdr *cid_hdr;
+
+	capture_info = hepv3_create_capture_info(tdata->buf.start, (size_t)(tdata->buf.cur - tdata->buf.start));
+	if (!capture_info) {
+		return PJ_SUCCESS;
+	}
 
 	pj_sockaddr_print(&tdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 1);
 	pj_sockaddr_print(&tdata->tp_info.dst_addr, remote_buf, sizeof(remote_buf), 1);
+
 	cid_hdr = PJSIP_MSG_CID_HDR(tdata->msg);
+	uuid = ast_malloc(pj_strlen(&cid_hdr->id) + 1);
+	if (!uuid) {
+		ao2_ref(capture_info, -1);
+		return PJ_SUCCESS;
+	}
+	ast_copy_pj_str(uuid, &cid_hdr->id, pj_strlen(&cid_hdr->id));
 
-	ast_sockaddr_parse(&capture_info.src_addr, local_buf, PARSE_PORT_REQUIRE);
-	ast_sockaddr_parse(&capture_info.dst_addr, remote_buf, PARSE_PORT_REQUIRE);
-	capture_info.capture_time = ast_tvnow();
-	capture_info.capture_type = hepv3_capture_type_sip;
-	capture_info.uuid = ast_strdupa(pj_strbuf(&cid_hdr->id));
-	capture_info.zipped = 0;
+	ast_sockaddr_parse(&capture_info->src_addr, local_buf, PARSE_PORT_REQUIRE);
+	ast_sockaddr_parse(&capture_info->dst_addr, remote_buf, PARSE_PORT_REQUIRE);
 
-	hepv3_send_packet(&capture_info, tdata->buf.start, (int)(tdata->buf.end - tdata->buf.start));
+	capture_info->capture_time = ast_tvnow();
+	capture_info->capture_type = hepv3_capture_type_sip;
+	capture_info->uuid = uuid;
+	capture_info->zipped = 0;
+
+	hepv3_send_packet(capture_info);
 
 	return PJ_SUCCESS;
 }
@@ -70,20 +84,33 @@
 {
 	char local_buf[256];
 	char remote_buf[256];
-	struct hepv3_capture_info capture_info;
+	char *uuid;
+	struct hepv3_capture_info *capture_info;
+
+	capture_info = hepv3_create_capture_info(&rdata->pkt_info.packet, rdata->pkt_info.len);
+	if (!capture_info) {
+		return PJ_SUCCESS;
+	}
 
 	pj_sockaddr_print(&rdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 1);
 	pj_sockaddr_print(&rdata->pkt_info.src_addr, remote_buf, sizeof(remote_buf), 1);
 
-	ast_sockaddr_parse(&capture_info.src_addr, local_buf, PARSE_PORT_REQUIRE);
-	ast_sockaddr_parse(&capture_info.dst_addr, remote_buf, PARSE_PORT_REQUIRE);
-	capture_info.capture_time.tv_sec = rdata->pkt_info.timestamp.sec;
-	capture_info.capture_time.tv_usec = rdata->pkt_info.timestamp.msec * 1000;
-	capture_info.capture_type = hepv3_capture_type_sip;
-	capture_info.uuid = ast_strdupa(pj_strbuf(&rdata->msg_info.cid->id));
-	capture_info.zipped = 0;
+	uuid = ast_malloc(pj_strlen(&rdata->msg_info.cid->id) + 1);
+	if (!uuid) {
+		ao2_ref(capture_info, -1);
+		return PJ_SUCCESS;
+	}
+	ast_copy_pj_str(uuid, &rdata->msg_info.cid->id, pj_strlen(&rdata->msg_info.cid->id));
 
-	hepv3_send_packet(&capture_info, &rdata->pkt_info.packet, rdata->pkt_info.len);
+	ast_sockaddr_parse(&capture_info->src_addr, remote_buf, PARSE_PORT_REQUIRE);
+	ast_sockaddr_parse(&capture_info->dst_addr, local_buf, PARSE_PORT_REQUIRE);
+	capture_info->capture_time.tv_sec = rdata->pkt_info.timestamp.sec;
+	capture_info->capture_time.tv_usec = rdata->pkt_info.timestamp.msec * 1000;
+	capture_info->capture_type = hepv3_capture_type_sip;
+	capture_info->uuid = uuid;
+	capture_info->zipped = 0;
+
+	hepv3_send_packet(capture_info);
 
 	return PJ_FALSE;
 }

Modified: team/mjordan/12-hep/res/res_hep_rtcp.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hep_rtcp.c?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/res/res_hep_rtcp.c (original)
+++ team/mjordan/12-hep/res/res_hep_rtcp.c Mon Feb 10 21:02:38 2014
@@ -53,11 +53,11 @@
 	struct ast_json *json_blob;
 	struct ast_json *json_channel;
 	struct ast_json *json_rtcp;
-	struct hepv3_capture_info capture_info;
+	struct hepv3_capture_info *capture_info;
 	struct ast_json *from;
 	struct ast_json *to;
 	struct timeval current_time = ast_tvnow();
-	const char *payload;
+	RAII_VAR(char *,  payload, NULL, ast_json_free);
 
 	json_payload = stasis_message_to_json(message, NULL);
 	if (!json_payload) {
@@ -85,18 +85,29 @@
 		return;
 	}
 
-	ast_sockaddr_parse(&capture_info.src_addr, ast_json_string_get(from), PARSE_PORT_REQUIRE);
-	ast_sockaddr_parse(&capture_info.dst_addr, ast_json_string_get(to), PARSE_PORT_REQUIRE);
+	payload = ast_json_dump_string(json_rtcp);
+	if (ast_strlen_zero(payload)) {
+		return;
+	}
 
-	capture_info.uuid = ast_strdupa(ast_json_string_get(ast_json_object_get(json_channel, "name")));
-	capture_info.capture_time.tv_sec = current_time.tv_sec;
-	capture_info.capture_time.tv_usec = current_time.tv_usec;
-	capture_info.capture_type = hepv3_capture_type_rtcp;
-	capture_info.zipped = 0;
+	capture_info = hepv3_create_capture_info(payload, strlen(payload));
+	if (!capture_info) {
+		return;
+	}
+	ast_sockaddr_parse(&capture_info->src_addr, ast_json_string_get(from), PARSE_PORT_REQUIRE);
+	ast_sockaddr_parse(&capture_info->dst_addr, ast_json_string_get(to), PARSE_PORT_REQUIRE);
 
-	payload = ast_json_string_get(json_rtcp);
+	capture_info->uuid = ast_strdup(ast_json_string_get(ast_json_object_get(json_channel, "name")));
+	if (!capture_info->uuid) {
+		ao2_ref(capture_info, -1);
+		return;
+	}
+	capture_info->capture_time.tv_sec = current_time.tv_sec;
+	capture_info->capture_time.tv_usec = current_time.tv_usec;
+	capture_info->capture_type = hepv3_capture_type_rtcp;
+	capture_info->zipped = 0;
 
-	hepv3_send_packet(&capture_info, &payload, strlen(payload));
+	hepv3_send_packet(capture_info);
 }
 
 static void rtp_topic_handler(void *data, struct stasis_subscription *sub, struct stasis_message *message)

Modified: team/mjordan/12-hep/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_rtp_asterisk.c?view=diff&rev=407936&r1=407935&r2=407936
==============================================================================
--- team/mjordan/12-hep/res/res_rtp_asterisk.c (original)
+++ team/mjordan/12-hep/res/res_rtp_asterisk.c Mon Feb 10 21:02:38 2014
@@ -2393,7 +2393,7 @@
 
 	update_address_with_ice_candidate(rtp, AST_RTP_ICE_COMPONENT_RTCP, &remote_address);
 
-	if (rtcp_debug_test_addr(&rtp->rtcp->them)) {
+	if (/*rtcp_debug_test_addr(&rtp->rtcp->them)*/1) {
 		ast_verbose("* Sent RTCP %s to %s%s\n", sr ? "SR" : "RR",
 				ast_sockaddr_stringify(&remote_address), ice ? " (via ICE)" : "");
 		ast_verbose("  Our SSRC: %u\n", rtcp_report->ssrc);
@@ -3325,7 +3325,7 @@
 			return &ast_null_frame;
 		}
 
-		if (rtcp_debug_test_addr(&addr)) {
+		if (/*rtcp_debug_test_addr(&addr)*/1) {
 			ast_verbose("\n\nGot RTCP from %s\n",
 				    ast_sockaddr_stringify(&addr));
 			ast_verbose("PT: %d(%s)\n", pt, (pt == RTCP_PT_SR) ? "Sender Report" :
@@ -3355,7 +3355,7 @@
 					(unsigned int)ntohl(rtcpheader[i + 1]),
 					&rtcp_report->sender_information.ntp_timestamp);
 			rtcp_report->sender_information.rtp_timestamp = ntohl(rtcpheader[i + 2]);
-			if (rtcp_debug_test_addr(&addr)) {
+			if (/*rtcp_debug_test_addr(&addr)*/1) {
 				ast_verbose("NTP timestamp: %u.%010u\n",
 						(unsigned int)rtcp_report->sender_information.ntp_timestamp.tv_sec,
 						(unsigned int)rtcp_report->sender_information.ntp_timestamp.tv_usec * 4096);
@@ -3389,7 +3389,7 @@
 			report_block->dlsr = ntohl(rtcpheader[i + 5]);
 			if (report_block->lsr
 				&& update_rtt_stats(rtp, report_block->lsr, report_block->dlsr)
-				&& rtcp_debug_test_addr(&addr)) {
+				&& /*rtcp_debug_test_addr(&addr)*/1) {
 				struct timeval now;
 				unsigned int lsr_now, lsw, msw;
 				gettimeofday(&now, NULL);
@@ -3406,7 +3406,7 @@
 			update_lost_stats(rtp, report_block->lost_count.packets);
 			rtp->rtcp->reported_jitter_count++;
 
-			if (rtcp_debug_test_addr(&addr)) {
+			if (/*rtcp_debug_test_addr(&addr)*/1) {
 			ast_verbose("  Fraction lost: %u\n", report_block->lost_count.fraction);
 				ast_verbose("  Packets lost so far: %u\n", report_block->lost_count.packets);
 				ast_verbose("  Highest sequence number: %u\n", report_block->highest_seq_no & 0x0000ffff);




More information about the asterisk-commits mailing list