[asterisk-commits] jrose: branch jrose/bridge_projects r387587 - in /team/jrose/bridge_projects:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 3 12:24:09 CDT 2013


Author: jrose
Date: Fri May  3 12:24:06 2013
New Revision: 387587

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387587
Log:
Respond to Mark's review, fix a memory leak involving park common datastore

Modified:
    team/jrose/bridge_projects/main/features.c
    team/jrose/bridge_projects/res/parking/parking_applications.c
    team/jrose/bridge_projects/res/parking/parking_bridge.c
    team/jrose/bridge_projects/res/parking/parking_bridge_features.c
    team/jrose/bridge_projects/res/parking/parking_manager.c
    team/jrose/bridge_projects/res/parking/parking_ui.c
    team/jrose/bridge_projects/res/parking/res_parking.h
    team/jrose/bridge_projects/res/res_parking.c

Modified: team/jrose/bridge_projects/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/features.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/main/features.c (original)
+++ team/jrose/bridge_projects/main/features.c Fri May  3 12:24:06 2013
@@ -406,6 +406,8 @@
 #define AST_MAX_WATCHERS 256
 #define MAX_DIAL_FEATURE_OPTIONS 30
 
+/* TODO Scrape all of the parking stuff out of features.c */
+
 struct feature_group_exten {
 	AST_LIST_ENTRY(feature_group_exten) entry;
 	AST_DECLARE_STRING_FIELDS(

Modified: team/jrose/bridge_projects/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_applications.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_applications.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_applications.c Fri May  3 12:24:06 2013
@@ -67,7 +67,7 @@
 					<option name="s">
 						<para>Silence announcement of the parking space number.</para>
 					</option>
-					<option name="c">
+					<option name="c" argsep=",">
 						<argument name="context" required="false" />
 						<argument name="extension" required="false" />
 						<argument name="priority" required="true" />
@@ -120,7 +120,7 @@
 		<description>
 			<para>Used to retrieve a parked call from a parking lot.</para>
 			<note>
-				<para>If a parkinglot's parkext option is set, then Parking lots
+				<para>If a parking lot's parkext option is set, then Parking lots
 				will automatically create and manage dialplan extensions in
 				the parking lot context. If that is the case then you will not
 				need to manage parking extensions yourself, just include the
@@ -225,6 +225,8 @@
 {
 	struct park_common_datastore *datastore = data;
 	ast_free(datastore->parker_uuid);
+	ast_free(datastore->comeback_override);
+	ast_free(datastore);
 }
 
 static const struct ast_datastore_info park_common_info = {
@@ -245,7 +247,7 @@
 	ast_channel_unlock(chan);
 }
 
-static int setup_park_common_datastore(struct ast_channel *parkee, const char *parker_uuid, int randomize, int time_limit, int silence_announce)
+static int setup_park_common_datastore(struct ast_channel *parkee, const char *parker_uuid, const char *comeback_override, int randomize, int time_limit, int silence_announce)
 {
 	struct ast_datastore *datastore = NULL;
 	struct park_common_datastore *park_datastore;
@@ -266,13 +268,20 @@
 	park_datastore->time_limit = time_limit;
 	park_datastore->silence_announce = silence_announce;
 
+	if (comeback_override) {
+		park_datastore->comeback_override = ast_strdup(comeback_override);
+	}
+
+
 	datastore->data = park_datastore;
+	ast_channel_lock(parkee);
 	ast_channel_datastore_add(parkee, datastore);
+	ast_channel_unlock(parkee);
 
 	return 0;
 }
 
-void get_park_common_datastore_data(struct ast_channel *parkee, char **parker_uuid, int *randomize, int *time_limit, int *silence_announce)
+void get_park_common_datastore_data(struct ast_channel *parkee, char **parker_uuid, char **comeback_override, int *randomize, int *time_limit, int *silence_announce)
 {
 	struct ast_datastore *datastore;
 	struct park_common_datastore *data;
@@ -294,6 +303,10 @@
 	*randomize = data->randomize;
 	*time_limit = data->time_limit;
 	*silence_announce = data->silence_announce;
+
+	if (data->comeback_override) {
+		*comeback_override = ast_strdup(data->comeback_override);
+	}
 
 	ast_channel_unlock(parkee);
 }
@@ -337,7 +350,7 @@
 	if (parking_bridge) {
 		/* Apply relevant bridge roles and such to the parking channel */
 		parking_channel_set_roles(parkee, lot, use_ringing);
-		setup_park_common_datastore(parkee, ast_channel_uniqueid(parker), randomize, time_limit,
+		setup_park_common_datastore(parkee, ast_channel_uniqueid(parker), comeback_override, randomize, time_limit,
 			silence_announcements ? *silence_announcements : 0);
 		return parking_bridge;
 	}

Modified: team/jrose/bridge_projects/res/parking/parking_bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_bridge.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_bridge.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_bridge.c Fri May  3 12:24:06 2013
@@ -171,6 +171,8 @@
 	return new_parked_user;
 }
 
+/* TODO CEL events for parking */
+
 /*!
  * \internal
  * \brief ast_bridge parking push method.
@@ -194,6 +196,7 @@
 	const char *blind_transfer;
 	RAII_VAR(struct ast_channel *, parker, NULL, ao2_cleanup);
 	RAII_VAR(char *, parker_uuid, NULL, ast_free);
+	RAII_VAR(char *, comeback_override, NULL, ast_free);
 
 	ast_bridge_base_v_table.push(&self->base, bridge_channel, swap);
 
@@ -221,7 +224,7 @@
 		return 0;
 	}
 
-	get_park_common_datastore_data(bridge_channel->chan, &parker_uuid, &randomize, &time_limit, &silence);
+	get_park_common_datastore_data(bridge_channel->chan, &parker_uuid, &comeback_override, &randomize, &time_limit, &silence);
 	parker = ast_channel_get_by_name(parker_uuid);
 
 	/* If the parker and the parkee are the same channel pointer, then the channel entered using
@@ -251,6 +254,12 @@
 	if (!pu) {
 		publish_parked_call_failure(bridge_channel->chan);
 		return -1;
+	}
+
+	/* If a comeback_override was provided, set it for the parked user's comeback string. */
+	if (comeback_override) {
+		strncpy(pu->comeback, comeback_override, sizeof(pu->comeback));
+		pu->comeback[sizeof(pu->comeback) - 1] = '\0';
 	}
 
 	/* Generate ParkedCall Stasis Message */

Modified: team/jrose/bridge_projects/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_bridge_features.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_bridge_features.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_bridge_features.c Fri May  3 12:24:06 2013
@@ -407,6 +407,8 @@
 
 	pbx_builtin_setvar_helper(chan, "PARKER", peername);
 
+	/* TODO Dialplan generation for park-dial extensions */
+
 	/* async_goto the proper PBX destination - this should happen when we come out of the bridge */
 	if (!ast_strlen_zero(user->comeback)) {
 		ast_async_parseable_goto(chan, user->comeback);

Modified: team/jrose/bridge_projects/res/parking/parking_manager.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_manager.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_manager.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_manager.c Fri May  3 12:24:06 2013
@@ -317,9 +317,11 @@
 	curlot = parking_lot_find_by_name(lot_name);
 
 	if (!curlot) {
-		astman_send_error(s, m, "Requested ParkingLot could not be found.");
+		astman_send_error(s, m, "Requested parking lot could not be found.");
 		return RESULT_SUCCESS;
 	}
+
+	astman_send_ack(s, m, "Parked calls will follow");
 
 	iter_users = ao2_iterator_init(curlot->parked_users, 0);
 	while ((curuser = ao2_iterator_next(&iter_users))) {
@@ -328,11 +330,13 @@
 
 		payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL);
 		if (!payload) {
+			astman_send_error(s, m, "Failed to retrieve parking data about a parked user.");
 			return RESULT_FAILURE;
 		}
 
 		parked_call_string = manager_build_parked_call_string(payload);
 		if (!parked_call_string) {
+			astman_send_error(s, m, "Failed to retrieve parkingd ata about a parked user.");
 			return RESULT_FAILURE;
 		}
 
@@ -587,6 +591,7 @@
 
 	res = ast_manager_register_xml_core("Parkinglots", 0, manager_parking_lot_list);
 	res |= ast_manager_register_xml_core("ParkedCalls", 0, manager_parking_status);
+	/* TODO Add a 'Park' manager action */
 	parking_manager_enable_stasis();
 	return res ? -1 : 0;
 }

Modified: team/jrose/bridge_projects/res/parking/parking_ui.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_ui.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_ui.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_ui.c Fri May  3 12:24:06 2013
@@ -152,7 +152,7 @@
 	return ret;
 }
 
-/* \brief Parkinglots command show <name> */
+/* \brief command parking show <name> */
 static char *handle_show_parking_lot_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	switch (cmd) {

Modified: team/jrose/bridge_projects/res/parking/res_parking.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/res_parking.h?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/parking/res_parking.h (original)
+++ team/jrose/bridge_projects/res/parking/res_parking.h Fri May  3 12:24:06 2013
@@ -54,7 +54,7 @@
 	PARKINGLOT_DYNAMIC,             /*! The parking lot is a dynamically created parking lot. It can be parked to at any time. Disabled on last parked call leaving.
 	                                 *  valid transitions: PARKINGLOT_DISABLED */
 	PARKINGLOT_DISABLED,            /*! The parking lot is no longer linked to a parking lot in configuration. It can no longer be parked to.
-	                                 *  and it can not be parked to. Terminal Mode doest. */
+	                                 *  and it can not be parked to. This mode has no transitions. */
 };
 
 struct parking_lot_cfg {
@@ -329,13 +329,28 @@
 	const char *app_data, int *silence_announcements);
 
 struct park_common_datastore {
-	char *parker_uuid;     /*!< Unique ID of the channel parking the call. */
+	char *parker_uuid;           /*!< Unique ID of the channel parking the call. */
+	char *comeback_override;     /*!< Optional goto string for where to send the call after we are done */
 	int randomize;               /*!< Pick a parking space to enter on at random */
 	int time_limit;              /*!< time limit override. -1 values don't override, 0 for unlimited time, >0 for custom time limit in seconds */
 	int silence_announce;        /*!< Used when a call parks itself to keep it from hearing the parked call announcement */
 };
 
-void get_park_common_datastore_data(struct ast_channel *parkee, char **parker_uuid, int *randomize, int *time_limit, int *silence_announce);
+/*!
+ * \since 12
+ * \brief Function that pulls data from the park common datastore on a channel in order to apply it to
+ *        the parked user struct upon bridging.
+ *
+ * \param parkee The channel entering parking with the datastore we are checking
+ * \param parker_uuid pointer to a string pointer for placing the name of the channel that parked parkee
+ * \param comeback_override pointer to a string pointer for placing the comeback_override option
+ * \param randomize integer pointer to an integer for placing the randomize option
+ * \param time_limit integer pointer to an integer for placing the time limit option
+ * \param silence_announce pointer to an integer for placing the silence_announcements option
+ */
+void get_park_common_datastore_data(struct ast_channel *parkee,
+		char **parker_uuid, char **comeback_override,
+		int *randomize, int *time_limit, int *silence_announce);
 
 /*!
  * \since 12

Modified: team/jrose/bridge_projects/res/res_parking.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/res_parking.c?view=diff&rev=387587&r1=387586&r2=387587
==============================================================================
--- team/jrose/bridge_projects/res/res_parking.c (original)
+++ team/jrose/bridge_projects/res/res_parking.c Fri May  3 12:24:06 2013
@@ -27,10 +27,10 @@
 	<configInfo name="res_parking" language="en_US">
 		<configFile name="res_parking.conf">
 			<configObject name="globals">
-				<synopsis>Options that apply to every parkinglot</synopsis>
+				<synopsis>Options that apply to every parking lot</synopsis>
 			</configObject>
 			<configObject name="parking_lot">
-				<synopsis>Defined parkinglots for res_parking to use to park calls on</synopsis>
+				<synopsis>Defined parking lots for res_parking to use to park calls on</synopsis>
 				<configOption name="context" default="parkedcalls">
 					<synopsis>The name of the context where calls are parked and picked up from.</synopsis>
 					<description><para>This option is only used if parkext is set.</para></description>
@@ -189,6 +189,8 @@
 
 #define PARKED_CALL_APPLICATION "ParkedCall"
 
+/* TODO Add unit tests for parking */
+
 static int parking_lot_sort_fn(const void *obj_left, const void *obj_right, int flags)
 {
 	const struct parking_lot *left = obj_left;
@@ -222,7 +224,8 @@
 static void link_configured_disable_marked_lots(void);
 
 struct parking_global_config {
-	int parkeddynamic; /* XXX This feature still needs to be implemented. Entirely. */
+	/* TODO Implement dynamic parking lots. Entirely. */
+	int parkeddynamic;
 };
 
 struct parking_config {
@@ -518,7 +521,7 @@
 	}
 
 	if (!parameter) {
-		ast_log(LOG_ERROR, "Attempted to handle option '%s', but option_handler_parkedfeature has no means of handling this.\n", var->name);
+		ast_log(LOG_ERROR, "Unable to handle option '%s'\n", var->name);
 		return -1;
 	}
 
@@ -572,24 +575,14 @@
 	ast_string_field_free_memory(lot);
 }
 
-struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *lot_cfg)
+static struct parking_lot *alloc_new_parking_lot(struct parking_lot_cfg *lot_cfg)
 {
 	struct parking_lot *lot;
-	struct parking_lot_cfg *replaced_cfg = NULL;
-	int found = 0;
-
-	/* Start by trying to find it. If that works we can skip the rest. */
-	if ((lot = named_item_find(parking_lot_container, lot_cfg->name))) {
-		found = 1;
-		goto found;
-	}
-
 	if (!(lot = ao2_alloc(sizeof(*lot), parking_lot_destructor))) {
 		return NULL;
 	}
 
 	if (ast_string_field_init(lot, 32)) {
-		ao2_cleanup(lot);
 		return NULL;
 	}
 
@@ -605,8 +598,28 @@
 	}
 
 	ast_string_field_set(lot, name, lot_cfg->name);
-
-found:
+	return lot;
+}
+
+struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *lot_cfg)
+{
+	struct parking_lot *lot;
+	struct parking_lot_cfg *replaced_cfg = NULL;
+	int found = 0;
+
+	/* Start by trying to find it. If that works we can skip the rest. */
+	lot = named_item_find(parking_lot_container, lot_cfg->name);
+	if (!lot) {
+		lot = alloc_new_parking_lot(lot_cfg);
+
+		/* If we still don't have a lot, we failed to alloc one. */
+		if (!lot) {
+			return NULL;
+		}
+	} else {
+		found = 1;
+	}
+
 	/* Set the configuration reference. Unref the one currently in the lot if it's there. */
 	if (lot->cfg) {
 		replaced_cfg = lot->cfg;
@@ -615,9 +628,7 @@
 	ao2_ref(lot_cfg, +1);
 	lot->cfg = lot_cfg;
 
-	if (replaced_cfg) {
-		ao2_cleanup(replaced_cfg);
-	}
+	ao2_cleanup(replaced_cfg);
 
 	/* Set the operating mode to normal since the parking lot has a configuration. */
 	lot->disable_mark = 0;
@@ -629,7 +640,6 @@
 	};
 
 	return lot;
-
 }
 
 static void generate_or_link_lots_to_configs(void)
@@ -703,7 +713,7 @@
 
 	/* Global options */
 
-	/* Register the per parkinglot options. */
+	/* Register the per parking lot options. */
 	aco_option_register(&cfg_info, "parkext", ACO_EXACT, parking_lot_types, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, parkext));
 	aco_option_register(&cfg_info, "context", ACO_EXACT, parking_lot_types, "parkedcalls", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, parking_con));
 	aco_option_register(&cfg_info, "parkingtime", ACO_EXACT, parking_lot_types, "45", OPT_UINT_T, 0, FLDSET(struct parking_lot_cfg, parkingtime));
@@ -715,7 +725,7 @@
 	aco_option_register(&cfg_info, "parkinghints", ACO_EXACT, parking_lot_types, "no", OPT_BOOL_T, 1, FLDSET(struct parking_lot_cfg, parkaddhints));
 	aco_option_register(&cfg_info, "courtesytone", ACO_EXACT, parking_lot_types, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, courtesytone));
 
-	/* More complicated parkinglot options that require special handling */
+	/* More complicated parking lot options that require special handling */
 	aco_option_register_custom(&cfg_info, "parkpos", ACO_EXACT, parking_lot_types, "701-750", option_handler_parkpos, 0);
 	aco_option_register_custom(&cfg_info, "findslot", ACO_EXACT, parking_lot_types, "first", option_handler_findslot, 0);
 	aco_option_register_custom(&cfg_info, "parkedplay", ACO_EXACT, parking_lot_types, "caller", option_handler_parkedfeature, OPT_PARKEDPLAY);
@@ -748,6 +758,9 @@
 		goto error;
 	}
 
+	/* TODO Dialplan generation for parking lots that set parkext */
+	/* TODO Generate hints for parking lots that set parkext and have hints enabled */
+
 	return AST_MODULE_LOAD_SUCCESS;
 
 error:




More information about the asterisk-commits mailing list