[asterisk-commits] dlee: branch dlee/ASTERISK-21096 r383578 - /team/dlee/ASTERISK-21096/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 22 08:54:45 CDT 2013


Author: dlee
Date: Fri Mar 22 08:54:41 2013
New Revision: 383578

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383578
Log:
Addressed review feedback.

 * Used ARRAY_LEN
 * Used stringfields instead of alloc+copy
 * Added va_end
 * Removed unneeded linked list code

Modified:
    team/dlee/ASTERISK-21096/main/manager_channels.c

Modified: team/dlee/ASTERISK-21096/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/main/manager_channels.c?view=diff&rev=383578&r1=383577&r2=383578
==============================================================================
--- team/dlee/ASTERISK-21096/main/manager_channels.c (original)
+++ team/dlee/ASTERISK-21096/main/manager_channels.c Fri Mar 22 08:54:41 2013
@@ -218,11 +218,21 @@
 
 /*! \brief Struct containing info for an AMI channel event to send out. */
 struct snapshot_manager_event {
-	AST_LIST_ENTRY(snapshot_manager_event) list;
+	/*! event_flags manager_event() flags parameter. */
+	int event_flags;
+	/*!  manager_event manager_event() category. */
 	const char *manager_event;
-	int event_flags;
-	char extra_fields[];
+	AST_DECLARE_STRING_FIELDS(
+		/* extra_fields_fmt Format string for extra fields to include. */
+		AST_STRING_FIELD(extra_fields);
+		);
 };
+
+static void snapshot_manager_event_dtor(void *obj)
+{
+	struct snapshot_manager_event *ev = obj;
+	ast_string_field_free_memory(ev);
+}
 
 /*!
  * \brief Construct a \ref snapshot_manager_event.
@@ -242,26 +252,27 @@
 
 {
 	RAII_VAR(struct snapshot_manager_event *, ev, NULL, ao2_cleanup);
-	RAII_VAR(char *, extra_fields, NULL, ast_free);
 	va_list argp;
 
 	ast_assert(extra_fields_fmt != NULL);
 	ast_assert(manager_event != NULL);
 
-	va_start(argp, extra_fields_fmt);
-	ast_vasprintf(&extra_fields, extra_fields_fmt, argp);
-	if (!extra_fields) {
-		return NULL;
-	}
-
-	ev = ao2_alloc(sizeof(*ev) + strlen(extra_fields) + 1, NULL);
+	ev = ao2_alloc(sizeof(*ev), snapshot_manager_event_dtor);
 	if (!ev) {
+		return NULL;
+	}
+
+	if (ast_string_field_init(ev, 20)) {
 		return NULL;
 	}
 
 	ev->manager_event = manager_event;
 	ev->event_flags = event_flags;
-	strcpy(ev->extra_fields, extra_fields);
+
+	va_start(argp, extra_fields_fmt);
+	ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt,
+				      argp);
+	va_end(argp);
 
 	ao2_ref(ev, +1);
 	return ev;
@@ -396,7 +407,7 @@
 	ast_assert(old_snapshot != NULL);
 	ast_assert(new_snapshot != NULL);
 	return strcmp(old_snapshot->caller_number, new_snapshot->caller_number) == 0 &&
-		strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0);
+		strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
 }
 
 static struct snapshot_manager_event *channel_new_callerid(
@@ -425,8 +436,6 @@
 	channel_new_callerid
 };
 
-size_t monitors_size = sizeof(monitors) / sizeof(monitors[0]);
-
 static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
 				    struct stasis_topic *topic,
 				    struct stasis_message *message)
@@ -446,7 +455,7 @@
 	old_snapshot = stasis_message_data(update->old_snapshot);
 	new_snapshot = stasis_message_data(update->new_snapshot);
 
-	for (i = 0; i < monitors_size; ++i) {
+	for (i = 0; i < ARRAY_LEN(monitors); ++i) {
 		RAII_VAR(struct snapshot_manager_event *, ev, NULL, ao2_cleanup);
 		ev = monitors[i](old_snapshot, new_snapshot);
 




More information about the asterisk-commits mailing list