[asterisk-commits] kmoore: branch mjordan/pjsip-cli r404404 - in /team/mjordan/pjsip-cli: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 20 10:57:44 CST 2013


Author: kmoore
Date: Fri Dec 20 10:57:39 2013
New Revision: 404404

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404404
Log:
Fix memory leaks, reduce code duplication, and remove an unnecessary structure

Modified:
    team/mjordan/pjsip-cli/include/asterisk/res_pjsip.h
    team/mjordan/pjsip-cli/main/channel.c
    team/mjordan/pjsip-cli/res/res_pjsip/pjsip_configuration.c

Modified: team/mjordan/pjsip-cli/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/pjsip-cli/include/asterisk/res_pjsip.h?view=diff&rev=404404&r1=404403&r2=404404
==============================================================================
--- team/mjordan/pjsip-cli/include/asterisk/res_pjsip.h (original)
+++ team/mjordan/pjsip-cli/include/asterisk/res_pjsip.h Fri Dec 20 10:57:39 2013
@@ -683,11 +683,6 @@
     struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata);
 };
 
-struct ast_sip_channel_snapshot {
-	SORCERY_OBJECT(details);
-	struct ast_channel_snapshot channel_snapshot;
-};
-
 /*!
  * \brief Register a SIP service in Asterisk.
  *

Modified: team/mjordan/pjsip-cli/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/pjsip-cli/main/channel.c?view=diff&rev=404404&r1=404403&r2=404404
==============================================================================
--- team/mjordan/pjsip-cli/main/channel.c (original)
+++ team/mjordan/pjsip-cli/main/channel.c Fri Dec 20 10:57:39 2013
@@ -733,6 +733,8 @@
 		return "Dialing Offhook";
 	case AST_STATE_PRERING:
 		return "Pre-ring";
+	case AST_STATE_MUTE:
+		return "Mute";
 	default:
 		if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
 			return "Unknown";

Modified: team/mjordan/pjsip-cli/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/pjsip-cli/res/res_pjsip/pjsip_configuration.c?view=diff&rev=404404&r1=404403&r2=404404
==============================================================================
--- team/mjordan/pjsip-cli/res/res_pjsip/pjsip_configuration.c (original)
+++ team/mjordan/pjsip-cli/res/res_pjsip/pjsip_configuration.c Fri Dec 20 10:57:39 2013
@@ -861,32 +861,21 @@
 	ao2_callback_fn on_channel_snapshot, void *arg)
 {
 	int num, num_channels = endpoint_snapshot->num_channels;
-	RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
-
-	if (!on_channel_snapshot || !num_channels ||
-	    !(cache = ast_channel_cache())) {
+
+	if (!on_channel_snapshot || !num_channels) {
 		return 0;
 	}
 
-	ao2_ref(cache, +1);
-
 	for (num = 0; num < num_channels; ++num) {
-		RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-		RAII_VAR(struct ast_sip_channel_snapshot *, ao2_snapshot, NULL, ao2_cleanup);
-		struct ast_channel_snapshot *snapshot;
+		RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 		int res;
 
-		msg = stasis_cache_get(cache, ast_channel_snapshot_type(),
-			endpoint_snapshot->channel_ids[num]);
-
-		if (!(snapshot = stasis_message_data(msg))) {
+		snapshot = ast_channel_snapshot_get_latest(endpoint_snapshot->channel_ids[num]);
+		if (!snapshot) {
 			continue;
 		}
 
-		ao2_snapshot = ao2_alloc(sizeof(struct ast_sip_channel_snapshot), NULL);
-		memcpy(&ao2_snapshot->channel_snapshot, snapshot, sizeof(struct ast_channel_snapshot));
-		ao2_ref(ao2_snapshot, +1);
-		res = on_channel_snapshot(ao2_snapshot, arg, 0);
+		res = on_channel_snapshot(snapshot, arg, 0);
 		if (res) {
 			return -1;
 		}
@@ -898,15 +887,15 @@
 	const struct ast_sip_endpoint *endpoint,
 	ao2_callback_fn on_channel_snapshot, void *arg)
 {
-	struct ast_endpoint_snapshot *endpoint_snapshot = ast_sip_get_endpoint_snapshot(endpoint);
+	RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, ast_sip_get_endpoint_snapshot(endpoint), ao2_cleanup);
 	return ast_sip_for_each_channel_snapshot(endpoint_snapshot, on_channel_snapshot, arg);
 }
 
 static int active_channels_to_str_cb(void *object, void *arg, int flags)
 {
-	const struct ast_sip_channel_snapshot *snapshot = object;
+	const struct ast_channel_snapshot *snapshot = object;
 	struct ast_str **buf = arg;
-	ast_str_append(buf, 0, "%s,", snapshot->channel_snapshot.name);
+	ast_str_append(buf, 0, "%s,", snapshot->name);
 	return 0;
 }
 
@@ -1138,36 +1127,8 @@
 	return 0;
 }
 
-static const char *channel_state_to_str(enum ast_channel_state state) {
-	switch (state) {
-	case AST_STATE_DOWN:
-		return "Down";
-	case AST_STATE_RESERVED:
-		return "Reserved";
-	case AST_STATE_OFFHOOK:
-		return "Offhook";
-	case AST_STATE_DIALING:
-		return "Dialing";
-	case AST_STATE_RING:
-		return "Ring";
-	case AST_STATE_RINGING:
-		return "Ringing";
-	case AST_STATE_UP:
-		return "Up";
-	case AST_STATE_BUSY:
-		return "Busy";
-	case AST_STATE_DIALING_OFFHOOK:
-		return "Dialing";
-	case AST_STATE_PRERING:
-		return "PreRing";
-	case AST_STATE_MUTE:
-		return "Mute";
-	}
-	return "Unknown";
-}
-
 static int populate_channel_container(void *obj, void *arg, int flags) {
-	struct ast_sip_channel_snapshot *snapshot = obj;
+	struct ast_channel_snapshot *snapshot = obj;
 	struct ao2_container *container = arg;
 	ao2_link_flags(container, snapshot, OBJ_NOLOCK);
 	return 0;
@@ -1215,21 +1176,18 @@
 		"%*s:  <ChannelId%*.*s>  <State.....>  <Time(sec)>\n",
 		indent, "Channel", filler, filler, CLI_HEADER_FILLER);
 
-//	if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) {
-		context->indent_level++;
-		indent = CLI_INDENT_TO_SPACES(context->indent_level);
-		filler = CLI_LAST_TABSTOP - indent - 38;
-		ast_str_append(&context->output_buffer, 0,
-			"%*s:  <Codec>  Exten: <DialedExten%*.*s>  CLCID: <ConnectedLineCID.......>\n",
-			indent, "Codec", filler, filler, CLI_HEADER_FILLER);
-		context->indent_level--;
-//	}
+	context->indent_level++;
+	indent = CLI_INDENT_TO_SPACES(context->indent_level);
+	filler = CLI_LAST_TABSTOP - indent - 38;
+	ast_str_append(&context->output_buffer, 0,
+		"%*s:  <Codec>  Exten: <DialedExten%*.*s>  CLCID: <ConnectedLineCID.......>\n",
+		indent, "Codec", filler, filler, CLI_HEADER_FILLER);
+	context->indent_level--;
 	return 0;
 }
 
 static int cli_print_channel_body(void *obj, void *arg, int flags) {
-	struct ast_sip_channel_snapshot *sip_snapshot = obj;
-	struct ast_channel_snapshot *snapshot = &sip_snapshot->channel_snapshot;
+	struct ast_channel_snapshot *snapshot = obj;
 	struct ast_sip_cli_context *context = arg;
 	struct timeval current_time;
 	char *print_name = NULL;
@@ -1256,24 +1214,22 @@
 		CLI_INDENT_TO_SPACES(context->indent_level), "Channel",
 		flexwidth, flexwidth,
 		print_name,
-		channel_state_to_str(snapshot->state),
+		ast_state2str(snapshot->state),
 		current_time.tv_sec - snapshot->creationtime.tv_sec);
 
-//	if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) {
-		context->indent_level++;
-		indent = CLI_INDENT_TO_SPACES(context->indent_level);
-		flexwidth = CLI_LAST_TABSTOP - indent - 25;
-
-		ast_str_append(&context->output_buffer, 0, "%*s:  %-7s  Exten: %-*.*s  CLCID: \"%s\" <%s>\n",
-			indent, "Codec",
-			snapshot->nativeformats,
-			flexwidth, flexwidth,
-			snapshot->exten,
-			snapshot->connected_name,
-			snapshot->connected_number
-			);
-		context->indent_level--;
-//	}
+	context->indent_level++;
+	indent = CLI_INDENT_TO_SPACES(context->indent_level);
+	flexwidth = CLI_LAST_TABSTOP - indent - 25;
+
+	ast_str_append(&context->output_buffer, 0, "%*s:  %-7s  Exten: %-*.*s  CLCID: \"%s\" <%s>\n",
+		indent, "Codec",
+		snapshot->nativeformats,
+		flexwidth, flexwidth,
+		snapshot->exten,
+		snapshot->connected_name,
+		snapshot->connected_number
+		);
+	context->indent_level--;
 	return 0;
 }
 
@@ -1318,7 +1274,7 @@
 
 static int cli_print_endpoint_body(void *obj, void *arg, int flags) {
 	struct ast_sip_endpoint *endpoint = obj;
-	struct ast_endpoint_snapshot *endpoint_snapshot = ast_sip_get_endpoint_snapshot(endpoint);
+	RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, ast_sip_get_endpoint_snapshot(endpoint), ao2_cleanup);
 	struct ast_sip_cli_context *context = arg;
 	const char *id = ast_sorcery_object_get_id(endpoint);
 	struct ast_sip_cli_formatter_entry *formatter_entry;




More information about the asterisk-commits mailing list