[Asterisk-code-review] res parking: Increase size of parking space numbers (asterisk[15])

Karl Brose asteriskteam at digium.com
Fri Aug 17 13:40:57 CDT 2018


Karl Brose has uploaded this change for review. ( https://gerrit.asterisk.org/9931


Change subject: res_parking: Increase size of parking space numbers
......................................................................

res_parking: Increase size of parking space numbers

The parking feature processes parking space extensions
as 32-bit integers. It uses some 'unsigned int' and some
'int' (signed) types. Negative values are used in some
code sections to indicate specific conditions.
This modification expands the possible range of parking
space extensions to ca. 20 digits by using 64-bit
(long long) signed integers consistently by defining
the typedef 'ast_parkingspace_int'.

Issue ID: ASTERISK-26108
Reporter: David Sovereen (2016)
Author: Karl Brose

Change-Id: I6059f5469d4eb039245e30f31bca95d069f30c2e
---
M include/asterisk/parking.h
M main/cdr.c
M main/parking.c
M res/parking/parking_applications.c
M res/parking/parking_bridge.c
M res/parking/parking_bridge_features.c
M res/parking/parking_controller.c
M res/parking/parking_devicestate.c
M res/parking/parking_manager.c
M res/parking/parking_tests.c
M res/parking/parking_ui.c
M res/parking/res_parking.h
M res/res_parking.c
13 files changed, 106 insertions(+), 94 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/31/9931/1

diff --git a/include/asterisk/parking.h b/include/asterisk/parking.h
index 554c8d5..2f617a6 100644
--- a/include/asterisk/parking.h
+++ b/include/asterisk/parking.h
@@ -36,6 +36,9 @@
  */
 #define DEFAULT_PARKINGLOT "default"
 
+typedef long long ast_parkingspace_int;
+#define AST_PARKINGSPACE_FORMAT	"%lli"
+
 /*!
  * \brief Defines the type of parked call message being published
  * \since 12
@@ -57,9 +60,9 @@
 	struct ast_channel_snapshot *parkee;             /*!< Snapshot of the channel that is parked */
 	struct ast_channel_snapshot *retriever;          /*!< Snapshot of the channel that retrieved the call (may be NULL) */
 	enum ast_parked_call_event_type event_type;      /*!< Reason for issuing the parked call message */
-	long unsigned int timeout;                       /*!< Time remaining before the call times out (seconds ) */
-	long unsigned int duration;                      /*!< How long the parkee has been parked (seconds) */
-	unsigned int parkingspace;                       /*!< Which Parking Space the parkee occupies */
+	long unsigned int timeout;                       /*!< Time remaining before the call times out (seconds) */
+	long unsigned int duration;                      /*!< Duration (in seconds) that the parkee has been parked */
+	ast_parkingspace_int parkingspace;               /*!< Parking space of the parkee */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(parkinglot);                /*!< Name of the parking lot used to park the parkee */
 		AST_STRING_FIELD(parker_dial_string);          /*!< The device string used for call control on parking timeout */
@@ -87,7 +90,7 @@
 struct ast_parked_call_payload *ast_parked_call_payload_create(enum ast_parked_call_event_type event_type,
 		struct ast_channel_snapshot *parkee_snapshot, const char *parker_dial_string,
 		struct ast_channel_snapshot *retriever_snapshot, const char *parkinglot,
-		unsigned int parkingspace, unsigned long int timeout, unsigned long int duration);
+		ast_parkingspace_int parkingspace, unsigned long int timeout, unsigned long int duration);
 
 /*! \addtogroup StasisTopicsAndMessages
  * @{
diff --git a/main/cdr.c b/main/cdr.c
index 1b54604..7cf93ea 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1608,7 +1608,7 @@
 
 static int base_process_parked_channel(struct cdr_object *cdr, struct ast_parked_call_payload *parking_info)
 {
-	char park_info[128];
+	char park_info[AST_MAX_EXTENSION];	/* ideally: max. parking lot strlen + max. digits of ast_parkingspace_int */
 
 	ast_assert(!strcasecmp(parking_info->parkee->name, cdr->party_a.snapshot->name));
 
@@ -1617,7 +1617,7 @@
 
 	/* Fake out where we're parked */
 	ast_string_field_set(cdr, appl, "Park");
-	snprintf(park_info, sizeof(park_info), "%s:%u", parking_info->parkinglot, parking_info->parkingspace);
+	snprintf(park_info, sizeof(park_info), "%s:"AST_PARKINGSPACE_FORMAT, parking_info->parkinglot, parking_info->parkingspace);
 	ast_string_field_set(cdr, data, park_info);
 
 	/* Prevent any further changes to the App/Data fields for this record */
diff --git a/main/parking.c b/main/parking.c
index bf0d0b6..31fce92 100644
--- a/main/parking.c
+++ b/main/parking.c
@@ -82,7 +82,7 @@
 struct ast_parked_call_payload *ast_parked_call_payload_create(enum ast_parked_call_event_type event_type,
 		struct ast_channel_snapshot *parkee_snapshot, const char *parker_dial_string,
 		struct ast_channel_snapshot *retriever_snapshot, const char *parkinglot,
-		unsigned int parkingspace, unsigned long int timeout,
+		ast_parkingspace_int parkingspace, unsigned long int timeout,
 		unsigned long int duration)
 {
 	RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup);
diff --git a/res/parking/parking_applications.c b/res/parking/parking_applications.c
index dd2fb75..be4f054 100644
--- a/res/parking/parking_applications.c
+++ b/res/parking/parking_applications.c
@@ -45,7 +45,7 @@
 		<syntax>
 			<parameter name="parking_lot_name">
 				<para>Specify in which parking lot to park a call.</para>
-				<para>The parking lot used is selected in the following order:</para>
+				<para>The parking lot is selected in the following order:</para>
 				<para>1) parking_lot_name option to this application</para>
 				<para>2) <variable>PARKINGLOT</variable> variable</para>
 				<para>3) <literal>CHANNEL(parkinglot)</literal> function
@@ -68,8 +68,8 @@
 						<argument name="context" required="false" />
 						<argument name="extension" required="false" />
 						<argument name="priority" required="true" />
-						<para>If the parking times out, go to this place in the dialplan
-							instead of where the parking lot defines the call should go.
+						<para>If parking times out, continue at this dialplan extension,
+							instead of the destination defined for the parking lot.
 						</para>
 					</option>
 					<option name="t">
@@ -84,9 +84,9 @@
 			<para>Used to park yourself (typically in combination with an attended
 			transfer to know the parking space).</para>
 			<para>If you set the <variable>PARKINGEXTEN</variable> variable to a
-				parking space extension in the parking lot, Park() will attempt to park the
-				call on that extension. If the extension is already in use then execution
-				will continue at the next priority.
+				parking space extension in the parking lot, Park() attempts to park the
+				call on that extension. If the extension is already in use, then execution
+				continues at the next priority.
 			</para>
 			<para>If the <literal>parkeddynamic</literal> option is enabled in
 				<filename>res_parking.conf</filename> the following variables can be
@@ -97,28 +97,28 @@
 			<para>The <variable>PARKINGDYNAMIC</variable> variable specifies the
 				parking lot to use as a template to create a dynamic parking lot. It
 				is an error to specify a non-existent parking lot for the template.
-				If not set then the default parking lot is used as the template.
+				If not set, then the default parking lot is used as the template.
 			</para>
 			<para>The <variable>PARKINGDYNCONTEXT</variable> variable specifies the
 				dialplan context to use for the newly created dynamic parking lot. If
-				not set then the context from the parking lot template is used. The
+				not set, then the context from the parking lot template is used. The
 				context is created if it does not already exist and the new parking lot
 				needs to create extensions.
 			</para>
 			<para>The <variable>PARKINGDYNEXTEN</variable> variable specifies the
 				<literal>parkext</literal> to use for the newly created dynamic
-				parking lot. If not set then the <literal>parkext</literal> is used from
+				parking lot. If not set, then the <literal>parkext</literal> is used from
 				the parking lot template. If the template does not specify a
-				<literal>parkext</literal> then no extensions are created for the newly
+				<literal>parkext</literal>, then no extensions are created for the newly
 				created parking lot. The dynamic parking lot cannot be created if it
 				needs to create extensions that overlap existing parking lot extensions.
 				The only exception to this is for the <literal>parkext</literal>
-				extension and only if neither of the overlaping parking lot's
+				extension, and only if neither of the overlaping parking lot's
 				<literal>parkext</literal> is exclusive.
 			</para>
 			<para>The <variable>PARKINGDYNPOS</variable> variable specifies the
 				parking positions to use for the newly created dynamic parking lot. If
-				not set then the <literal>parkpos</literal> from the parking lot template
+				not set, then the <literal>parkpos</literal> from the parking lot template
 				is used.
 			</para>
 			<note>
@@ -142,7 +142,7 @@
 		<syntax>
 			<parameter name="parking_lot_name">
 				<para>Specify from which parking lot to retrieve a parked call.</para>
-				<para>The parking lot used is selected in the following order:</para>
+				<para>The parking lot is selected in the following order:</para>
 				<para>1) parking_lot_name option</para>
 				<para>2) <variable>PARKINGLOT</variable> variable</para>
 				<para>3) <literal>CHANNEL(parkinglot)</literal> function
@@ -150,18 +150,18 @@
 				<para>4) Default parking lot.</para>
 			</parameter>
 			<parameter name="parking_space">
-				<para>Parking space to retrieve a parked call from.
-				If not provided then the first available parked call in the
-				parking lot will be retrieved.</para>
+				<para>Parking space from which to retrieve a parked call.
+				If not provided, then the first available parked call in the
+				parking lot is retrieved.</para>
 			</parameter>
 		</syntax>
 		<description>
 			<para>Used to retrieve a parked call from a parking lot.</para>
 			<note>
-				<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
+				<para>If a parking lot's parkext option is set, then parking lots
+				automatically create and manage dialplan extensions in
+				the parking lot context. If that is the case, then you do not
+				need to manage parking extensions yourself; just include the
 				parking context of the parking lot.</para>
 			</note>
 		</description>
@@ -177,7 +177,7 @@
 		<syntax>
 			<parameter name="parking_lot_name">
 				<para>Specify in which parking lot to park a call.</para>
-				<para>The parking lot used is selected in the following order:</para>
+				<para>The parking lot is selected in the following order:</para>
 				<para>1) parking_lot_name option to this application</para>
 				<para>2) <variable>PARKINGLOT</variable> variable</para>
 				<para>3) <literal>CHANNEL(parkinglot)</literal> function
@@ -197,8 +197,8 @@
 						<argument name="context" required="false" />
 						<argument name="extension" required="false" />
 						<argument name="priority" required="true" />
-						<para>If the parking times out, go to this place in the dialplan
-							instead of where the parking lot defines the call should go.
+						<para>If parking times out, continue at this dialplan extension,
+							instead of the destination defined for the parking lot.
 						</para>
 					</option>
 					<option name="t">
@@ -211,20 +211,20 @@
 			<parameter name="announce_template" required="true" argsep=":">
 				<argument name="announce" required="true">
 					<para>Colon-separated list of files to announce. The word
-					<literal>PARKED</literal> will be replaced by a say_digits of the extension in which
+					<literal>PARKED</literal> is replaced by an announcement of the extension in which
 					the call is parked.</para>
 				</argument>
 				<argument name="announce1" multiple="true" />
 			</parameter>
 			<parameter name="dial" required="true">
-				<para>The app_dial style resource to call to make the
+				<para>The app_dial-style resource to call to make the
 				announcement. Console/dsp calls the console.</para>
 			</parameter>
 		</syntax>
 		<description>
-			<para>Park a call into the parkinglot and announce the call to another channel.</para>
-			<para>The variable <variable>PARKEDAT</variable> will contain the parking extension
-			into which the call was placed.  Use with the Local channel to allow the dialplan to make
+			<para>Park a call into the parking lot and announce the call to another channel.</para>
+			<para>The variable <variable>PARKEDAT</variable> is set to the parking extension
+			into which the call is placed.  Use with channel 'Local' to allow the dialplan to make
 			use of this information.</para>
 		</description>
 		<see-also>
@@ -606,7 +606,7 @@
 	RAII_VAR(struct parked_user *, pu, NULL, ao2_cleanup); /* Parked user being retrieved */
 	struct ast_bridge *retrieval_bridge;
 	int res;
-	int target_space = -1;
+	ast_parkingspace_int target_space = -1;
 	struct ast_bridge_features chan_features;
 	char *parse;
 	const char *lot_name;
@@ -642,7 +642,7 @@
 	}
 
 	if (!ast_strlen_zero(args.parking_space)) {
-		if (sscanf(args.parking_space, "%d", &target_space) != 1 || target_space < 0) {
+		if (sscanf(args.parking_space, AST_PARKINGSPACE_FORMAT, &target_space) != 1 || target_space < 0) {
 			ast_stream_and_wait(chan, "pbx-invalidpark", "");
 			ast_log(LOG_ERROR, "value '%s' for parking_space argument is invalid. Must be an integer greater than 0.\n", args.parking_space);
 			return -1;
@@ -797,15 +797,15 @@
 	ast_channel_cleanup(chan);
 }
 
-static void announce_to_dial(char *dial_string, char *announce_string, int parkingspace, struct ast_channel_snapshot *parkee_snapshot)
+static void announce_to_dial(char *dial_string, char *announce_string, ast_parkingspace_int parkingspace, struct ast_channel_snapshot *parkee_snapshot)
 {
 	struct ast_channel *dchan;
 	struct outgoing_helper oh = { 0, };
 	int outstate;
 	struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
-	char buf[13];
 	char *dial_tech;
 	char *cur_announce;
+	char buf[24]; /* A long long int has 20 characters with sign */
 
 	dial_tech = strsep(&dial_string, "/");
 	ast_verb(3, "Dial Tech,String: (%s,%s)\n", dial_tech, dial_string);
@@ -816,7 +816,7 @@
 	}
 	ast_format_cap_append(cap_slin, ast_format_slin, 0);
 
-	snprintf(buf, sizeof(buf), "%d", parkingspace);
+	sprintf(buf, AST_PARKINGSPACE_FORMAT, parkingspace);
 	oh.vars = ast_variable_new("_PARKEDAT", buf, "");
 
 	inherit_channel_vars_from_id(&oh, parkee_snapshot->uniqueid);
@@ -838,7 +838,7 @@
 	for (cur_announce = strsep(&announce_string, ":"); cur_announce; cur_announce = strsep(&announce_string, ":")) {
 		ast_verb(4, "Announce:%s\n", cur_announce);
 		if (!strcmp(cur_announce, "PARKED")) {
-			ast_say_digits(dchan, parkingspace, "", ast_channel_language(dchan));
+			parking_space_announce(dchan, parkingspace);
 		} else {
 			int dres = ast_streamfile(dchan, cur_announce, ast_channel_language(dchan));
 			if (!dres) {
diff --git a/res/parking/parking_bridge.c b/res/parking/parking_bridge.c
index e61486e..1e318bb 100644
--- a/res/parking/parking_bridge.c
+++ b/res/parking/parking_bridge.c
@@ -109,8 +109,8 @@
 static struct parked_user *generate_parked_user(struct parking_lot *lot, struct ast_channel *chan, struct ast_channel *parker, const char *parker_dial_string, int use_random_space, int time_limit)
 {
 	struct parked_user *new_parked_user;
-	int preferred_space = -1; /* Initialize to use parking lot defaults */
-	int parking_space;
+	ast_parkingspace_int preferred_space = -1; /* Initialize to use parking lot defaults */
+	ast_parkingspace_int parking_space;
 	const char *parkingexten;
 
 	if (lot->mode == PARKINGLOT_DISABLED) {
@@ -124,7 +124,7 @@
 	}
 
 	if (use_random_space) {
-		preferred_space = ast_random() % (lot->cfg->parking_stop - lot->cfg->parking_start + 1);
+		preferred_space = ((ast_parkingspace_int) ast_random() * (ast_parkingspace_int) ast_random()) % (lot->cfg->parking_stop - lot->cfg->parking_start + 1);
 		preferred_space += lot->cfg->parking_start;
 	} else {
 		ast_channel_lock(chan);
@@ -134,7 +134,7 @@
 		ast_channel_unlock(chan);
 
 		if (!ast_strlen_zero(parkingexten)) {
-			if (sscanf(parkingexten, "%30d", &preferred_space) != 1 || preferred_space <= 0) {
+			if (sscanf(parkingexten, AST_PARKINGSPACE_FORMAT, &preferred_space) != 1 || preferred_space <= 0) {
 				ast_log(LOG_WARNING, "PARKINGEXTEN='%s' is not a valid parking space.\n", parkingexten);
 				ao2_ref(new_parked_user, -1);
 				return NULL;
@@ -301,7 +301,7 @@
 	if (ast_strlen_zero(blind_transfer) && !park_datastore->silence_announce) {
 		char saynum_buf[16];
 
-		snprintf(saynum_buf, sizeof(saynum_buf), "%d %d", 0, pu->parking_space);
+		snprintf(saynum_buf, sizeof(saynum_buf), "%d "AST_PARKINGSPACE_FORMAT, 0, pu->parking_space);
 		ast_bridge_channel_queue_playfile(bridge_channel, say_parking_space, saynum_buf, NULL);
 	}
 
@@ -311,7 +311,7 @@
 	/* Set this to the bridge pvt so that we don't have to refind the parked user associated with this bridge channel again. */
 	bridge_channel->bridge_pvt = pu;
 
-	ast_verb(3, "Parking '" COLORIZE_FMT "' in '" COLORIZE_FMT "' at space %d\n",
+	ast_verb(3, "Parking '" COLORIZE_FMT "' in '" COLORIZE_FMT "' at space "AST_PARKINGSPACE_FORMAT"\n",
 		COLORIZE(COLOR_BRMAGENTA, 0, ast_channel_name(bridge_channel->chan)),
 		COLORIZE(COLOR_BRMAGENTA, 0, self->lot->name),
 		pu->parking_space);
diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c
index 2770233..293b7a1 100644
--- a/res/parking/parking_bridge_features.c
+++ b/res/parking/parking_bridge_features.c
@@ -116,7 +116,7 @@
 	 * parked_subscription_data is tracking a transfer_channel_data struct. */
 	if (message->event_type == PARKED_CALL) {
 		/* queue the saynum on the bridge channel and hangup */
-		snprintf(saynum_buf, sizeof(saynum_buf), "%d %u", data->hangup_after, message->parkingspace);
+		snprintf(saynum_buf, sizeof(saynum_buf), "%d "AST_PARKINGSPACE_FORMAT, data->hangup_after, message->parkingspace);
 		if (!data->transfer_data) {
 			ast_bridge_channel_queue_playfile(bridge_channel, say_parking_space, saynum_buf, NULL);
 		} else {
@@ -273,7 +273,7 @@
 	struct pbx_find_info info = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
 	const char *app_at_exten;
 
-	ast_debug(4, "Checking if %s@%s is a parking exten\n", exten, context);
+	ast_debug(4, "Checking whether %s@%s is a parking extension.\n", exten, context);
 	exten_obj = pbx_find_extension(NULL, NULL, &info, context, exten, 1, NULL, NULL, E_MATCH);
 	if (!exten_obj) {
 		return 0;
@@ -579,7 +579,7 @@
 	flatten_dial_string(dial_string_flat);
 
 	/* Set parking timeout channel variables */
-	snprintf(parking_space, sizeof(parking_space), "%d", user->parking_space);
+	snprintf(parking_space, sizeof(parking_space), AST_PARKINGSPACE_FORMAT, user->parking_space);
 	ast_channel_lock(chan);
 	ast_channel_stage_snapshot(chan);
 	pbx_builtin_setvar_helper(chan, "PARKING_SPACE", parking_space);
@@ -657,10 +657,11 @@
 
 void say_parking_space(struct ast_bridge_channel *bridge_channel, const char *payload)
 {
-	unsigned int numeric_value;
+	ast_parkingspace_int numeric_value;
 	unsigned int hangup_after;
+	char buf[40];
 
-	if (sscanf(payload, "%u %u", &hangup_after, &numeric_value) != 2) {
+	if (sscanf(payload, "%u "AST_PARKINGSPACE_FORMAT, &hangup_after, &numeric_value) != 2) {
 		/* If say_parking_space is called with a non-numeric string, we have a problem. */
 		ast_assert(0);
 		ast_bridge_channel_leave_bridge(bridge_channel,
@@ -668,8 +669,8 @@
 		return;
 	}
 
-	ast_say_digits(bridge_channel->chan, numeric_value, "",
-		ast_channel_language(bridge_channel->chan));
+	sprintf(buf, AST_PARKINGSPACE_FORMAT, numeric_value);
+	ast_say_digit_str(bridge_channel->chan, buf, "", ast_channel_language(bridge_channel->chan));
 
 	if (hangup_after) {
 		ast_bridge_channel_leave_bridge(bridge_channel,
diff --git a/res/parking/parking_controller.c b/res/parking/parking_controller.c
index 9e9e540..54a7f8f 100644
--- a/res/parking/parking_controller.c
+++ b/res/parking/parking_controller.c
@@ -93,13 +93,13 @@
 	return -1;
 }
 
-int parking_lot_get_space(struct parking_lot *lot, int target_override)
+ast_parkingspace_int parking_lot_get_space(struct parking_lot *lot, ast_parkingspace_int target_override)
 {
-	int original_target;
-	int current_target;
+	ast_parkingspace_int original_target;
+	ast_parkingspace_int current_target;
 	struct ao2_iterator i;
 	struct parked_user *user;
-	int wrap;
+	ast_parkingspace_int wrap;
 
 	if (lot->cfg->parkfindnext) {
 		/* Use next_space if the lot already has next_space set; otherwise use lot start. */
@@ -154,7 +154,7 @@
 
 static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
 {
-	int *target = arg;
+	ast_parkingspace_int *target = arg;
 	struct parked_user *user = obj;
 	if (user->parking_space == *target) {
 		return CMP_MATCH;
@@ -163,7 +163,7 @@
 	return 0;
 }
 
-struct parked_user *parking_lot_retrieve_parked_user(struct parking_lot *lot, int target)
+struct parked_user *parking_lot_retrieve_parked_user(struct parking_lot *lot, ast_parkingspace_int target)
 {
 	RAII_VAR(struct parked_user *, user, NULL, ao2_cleanup);
 
diff --git a/res/parking/parking_devicestate.c b/res/parking/parking_devicestate.c
index 3f6d07d..d23c3ab 100644
--- a/res/parking/parking_devicestate.c
+++ b/res/parking/parking_devicestate.c
@@ -30,7 +30,7 @@
 
 struct parking_lot_extension_inuse_search {
 	char *context;
-	int exten;
+	ast_parkingspace_int exten;
 };
 
 static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
@@ -91,11 +91,11 @@
 	}
 
 	search.context = context;
-	if (sscanf(exten, "%d", &search.exten) != 1) {
+	if (sscanf(exten, AST_PARKINGSPACE_FORMAT, &search.exten) != 1) {
 		return AST_DEVICE_INVALID;
 	}
 
-	ast_debug(4, "Checking state of exten %d in context %s\n", search.exten, context);
+	ast_debug(4, "Checking state of extension "AST_PARKINGSPACE_FORMAT" in context %s\n", search.exten, context);
 
 	lot = ao2_callback(global_lots, 0, parking_lot_search_context_extension_inuse, &data);
 	if (!lot) {
@@ -105,12 +105,12 @@
 	return AST_DEVICE_INUSE;
 }
 
-void parking_notify_metermaids(int exten, const char *context, enum ast_device_state state)
+void parking_notify_metermaids(ast_parkingspace_int exten, const char *context, enum ast_device_state state)
 {
-	ast_debug(4, "Notification of state change to metermaids %d@%s\n to state '%s'\n",
+	ast_debug(4, "Notification of state change to metermaids "AST_PARKINGSPACE_FORMAT"@%s\n to state '%s'\n",
 		exten, context, ast_devstate2str(state));
 
-	ast_devstate_changed(state, AST_DEVSTATE_CACHABLE, "park:%d@%s", exten, context);
+	ast_devstate_changed(state, AST_DEVSTATE_CACHABLE, "park:"AST_PARKINGSPACE_FORMAT"@%s", exten, context);
 }
 
 void unload_parking_devstate(void)
diff --git a/res/parking/parking_manager.c b/res/parking/parking_manager.c
index 6d0a4c0..89dd545 100644
--- a/res/parking/parking_manager.c
+++ b/res/parking/parking_manager.c
@@ -241,7 +241,7 @@
 		"%s" /* retriever channel state (when available) */
 		"ParkerDialString: %s\r\n"
 		"Parkinglot: %s\r\n"
-		"ParkingSpace: %u\r\n"
+		"ParkingSpace: "AST_PARKINGSPACE_FORMAT"\r\n"
 		"ParkingTimeout: %lu\r\n"
 		"ParkingDuration: %lu\r\n",
 
@@ -403,8 +403,8 @@
 	astman_append(s, "Event: Parkinglot\r\n"
 		"%s" /* The Action ID */
 		"Name: %s\r\n"
-		"StartSpace: %d\r\n"
-		"StopSpace: %d\r\n"
+		"StartSpace: "AST_PARKINGSPACE_FORMAT"\r\n"
+		"StopSpace: "AST_PARKINGSPACE_FORMAT"\r\n"
 		"Timeout: %u\r\n"
 		"\r\n",
 		list_data->id_text,
diff --git a/res/parking/parking_tests.c b/res/parking/parking_tests.c
index 1572788..1e9b886 100644
--- a/res/parking/parking_tests.c
+++ b/res/parking/parking_tests.c
@@ -137,7 +137,7 @@
 
 #define TEST_LOT_NAME "unit_tests_res_parking_test_lot"
 
-static struct parking_lot *generate_test_parking_lot(const char *name, int low_space, int high_space, const char *park_exten, const char *park_context, struct ast_test *test)
+static struct parking_lot *generate_test_parking_lot(const char *name, ast_parkingspace_int low_space, ast_parkingspace_int high_space, const char *park_exten, const char *park_context, struct ast_test *test)
 {
 	RAII_VAR(struct parking_lot_cfg *, test_cfg, NULL, ao2_cleanup);
 	struct parking_lot *test_lot;
diff --git a/res/parking/parking_ui.c b/res/parking/parking_ui.c
index f12963a..b2debe0 100644
--- a/res/parking/parking_ui.c
+++ b/res/parking/parking_ui.c
@@ -37,7 +37,7 @@
 
 static void display_parked_call(struct parked_user *user, int fd)
 {
-	ast_cli(fd, "  Space               :  %d\n", user->parking_space);
+	ast_cli(fd, "  Space               :  "AST_PARKINGSPACE_FORMAT"\n", user->parking_space);
 	ast_cli(fd, "  Channel             :  %s\n", ast_channel_name(user->chan));
 	ast_cli(fd, "  Parker Dial String  :  %s\n", user->parker_dial_string);
 	ast_cli(fd, "\n");
@@ -56,7 +56,7 @@
 	ast_cli(fd, "Parking Lot: %s\n--------------------------------------------------------------------------\n", lot->name);
 	ast_cli(fd, "Parking Extension   :  %s\n", lot->cfg->parkext);
 	ast_cli(fd, "Parking Context     :  %s\n", lot->cfg->parking_con);
-	ast_cli(fd, "Parking Spaces      :  %d-%d\n", lot->cfg->parking_start, lot->cfg->parking_stop);
+	ast_cli(fd, "Parking Spaces      :  "AST_PARKINGSPACE_FORMAT"-"AST_PARKINGSPACE_FORMAT"\n", lot->cfg->parking_start, lot->cfg->parking_stop);
 	ast_cli(fd, "Parking Time        :  %u sec\n", lot->cfg->parkingtime);
 	ast_cli(fd, "Comeback to Origin  :  %s\n", lot->cfg->comebacktoorigin ? "yes" : "no");
 	ast_cli(fd, "Comeback Context    :  %s%s\n", lot->cfg->comebackcontext, lot->cfg->comebacktoorigin ? " (comebacktoorigin=yes, not used)" : "");
@@ -124,8 +124,8 @@
 }
 
 struct parking_lot_complete {
-	int seeking;    /*! Nth match to return. */
-	int which;      /*! Which match currently on. */
+	ast_parkingspace_int seeking;    /*! Nth match to return. */
+	ast_parkingspace_int which;      /*! Which match currently on. */
 };
 
 static int complete_parking_lot_search(void *obj, void *arg, void *data, int flags)
@@ -137,7 +137,7 @@
 	return 0;
 }
 
-static char *complete_parking_lot(const char *word, int seeking)
+static char *complete_parking_lot(const char *word, ast_parkingspace_int seeking)
 {
 	char *ret = NULL;
 	struct parking_lot *lot;
diff --git a/res/parking/res_parking.h b/res/parking/res_parking.h
index 3c34e5c..f7040a2 100644
--- a/res/parking/res_parking.h
+++ b/res/parking/res_parking.h
@@ -60,8 +60,8 @@
 };
 
 struct parking_lot_cfg {
-	int parking_start;                        /*!< First space in the parking lot */
-	int parking_stop;                         /*!< Last space in the parking lot */
+	ast_parkingspace_int parking_start;                  /*!< First space in the parking lot */
+	ast_parkingspace_int parking_stop;                   /*!< Last space in the parking lot */
 
 	unsigned int parkingtime;                 /*!< Analogous to parkingtime config option */
 	unsigned int comebackdialtime;            /*!< Analogous to comebackdialtime config option */
@@ -87,7 +87,7 @@
 };
 
 struct parking_lot {
-	int next_space;                           /*!< When using parkfindnext, which space we should start searching from next time we park */
+	ast_parkingspace_int next_space;                     /*!< When using parkfindnext, which space we should start searching from next time we park */
 	struct ast_bridge *parking_bridge;        /*!< Bridged where parked calls will rest until they are answered or otherwise leave */
 	struct ao2_container *parked_users;       /*!< List of parked users rigidly ordered by their parking space */
 	struct parking_lot_cfg *cfg;              /*!< Reference to configuration object for the parking lot */
@@ -103,7 +103,7 @@
 	struct ast_channel *chan;                 /*!< Parked channel */
 	struct ast_channel_snapshot *retriever;   /*!< Snapshot of the channel that retrieves a parked call */
 	struct timeval start;                     /*!< When the call was parked */
-	int parking_space;                        /*!< Which parking space is used */
+	ast_parkingspace_int parking_space;                  /*!< Which parking space is used */
 	char comeback[AST_MAX_CONTEXT];           /*!< Where to go on parking timeout */
 	char *parker_dial_string;                 /*!< dialstring to call back with comebacktoorigin. Used timeout extension generation and call control */
 	unsigned int time_limit;                  /*!< How long this specific channel may remain in the parking lot before timing out */
@@ -111,6 +111,14 @@
 	enum park_call_resolution resolution;     /*!< How did the parking session end? If the call is in a bridge, lock parked_user before checking/setting */
 };
 
+
+#define parking_space_announce(channel_, space_)	do { \
+	char buf[24]; /* even a long long int has never more that 20 characters. */ \
+	sprintf(buf, AST_PARKINGSPACE_FORMAT, space_); \
+	ast_say_digit_str(channel_, buf, "", ast_channel_language(channel_)); \
+	} while (0)
+
+
 #if defined(TEST_FRAMEWORK)
 /*!
  * \since 12.0.0
@@ -193,7 +201,7 @@
  * \note lot should be locked before this is called and unlocked only after a parked_user with the space
  *       returned has been added to the parking lot.
  */
-int parking_lot_get_space(struct parking_lot *lot, int target_override);
+ast_parkingspace_int parking_lot_get_space(struct parking_lot *lot, ast_parkingspace_int target_override);
 
 /*!
  * \since 12.0.0
@@ -209,7 +217,7 @@
  * \note The parked user will be removed from parking lot as part of this process
  * \note Remove this reference with ao2_cleanup once it falls out of scope.
  */
-struct parked_user *parking_lot_retrieve_parked_user(struct parking_lot *lot, int target);
+struct parked_user *parking_lot_retrieve_parked_user(struct parking_lot *lot, ast_parkingspace_int target);
 
 /*!
  * \since 12.0.0
@@ -465,7 +473,7 @@
  * \param context Context of the call parked/unparked
  * \param state new device state
  */
-void parking_notify_metermaids(int exten, const char *context, enum ast_device_state state);
+void parking_notify_metermaids(ast_parkingspace_int exten, const char *context, enum ast_device_state state);
 
 /*!
  * \since 12.0.0
diff --git a/res/res_parking.c b/res/res_parking.c
index 2082718..ec406a6 100644
--- a/res/res_parking.c
+++ b/res/res_parking.c
@@ -435,9 +435,9 @@
 /* The arg just needs to have the parking space with it */
 static int parked_user_cmp_fn(void *obj, void *arg, int flags)
 {
-	int *search_space = arg;
 	struct parked_user *user = obj;
-	int object_space = user->parking_space;
+	ast_parkingspace_int *search_space = arg;
+	ast_parkingspace_int object_space = user->parking_space;
 
 	if (*search_space == object_space) {
 		return CMP_MATCH;
@@ -505,10 +505,10 @@
 static int option_handler_parkpos(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct parking_lot_cfg *lot_cfg = obj;
-	int low;
-	int high;
+	ast_parkingspace_int low;
+	ast_parkingspace_int high;
 
-	if (sscanf(var->value, "%30d-%30d", &low, &high) != 2) {
+	if (sscanf(var->value, AST_PARKINGSPACE_FORMAT"-"AST_PARKINGSPACE_FORMAT, &low, &high) != 2) {
 		ast_log(LOG_WARNING, "Format for parking positions is a-b, where a and b are numbers\n");
 	} else if (high < low || low <= 0 || high <= 0) {
 		ast_log(LOG_WARNING, "Format for parking positions is a-b, where a <= b\n");
@@ -759,7 +759,7 @@
 
 int parking_lot_cfg_create_extensions(struct parking_lot_cfg *lot_cfg)
 {
-	int parkingspace;
+	ast_parkingspace_int parkingspace;
 	struct ast_exten *existing_exten;
 	struct ast_context *lot_context;
 	struct pbx_find_info find_info = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
@@ -812,11 +812,11 @@
 
 	/* Handle generation/confirmation for the ParkedCall extensions and hints */
 	for (parkingspace = lot_cfg->parking_start; parkingspace <= lot_cfg->parking_stop; parkingspace++) {
-		char space[AST_MAX_EXTENSION];
+		char space[24];	/* even a long long int is only 20 characters long */
 		RAII_VAR(struct ast_str *, arguments_string, NULL, ast_free);
 		find_info.stacklen = 0; /* reset for pbx_find_exten */
 
-		snprintf(space, sizeof(space), "%d", parkingspace);
+		snprintf(space, sizeof space, AST_PARKINGSPACE_FORMAT, parkingspace);
 
 		/* Unlike the Park extensions, ParkedCall extensions and their hints may never be shared for any reason. */
 		if ((existing_exten = pbx_find_extension(NULL, NULL, &find_info, lot_cfg->parking_con, space, 1, NULL, NULL, E_MATCH))) {
@@ -824,15 +824,15 @@
 			return -1;
 		}
 
-		arguments_string = ast_str_create(32);
+		arguments_string = ast_str_create(strlen(lot_cfg->name) + 1 + sizeof space);
 		if (!arguments_string) {
 			ast_unlock_context(lot_context);
 			return -1;
 		}
 
 		ast_str_set(&arguments_string, 0, "%s,%s", lot_cfg->name, space);
-		if (parking_add_extension(lot_context, 0, space, 1, PARKED_CALL_APPLICATION,
-		    ast_str_buffer(arguments_string), parkedcall_registrar_pointer)) {
+		if (parking_add_extension(lot_context, 0, space, 1, PARKED_CALL_APPLICATION, ast_str_buffer(arguments_string), parkedcall_registrar_pointer)
+			) {
 			ast_log(LOG_ERROR, "Parking lot '%s' -- Failed to add %s extension '%s@%s' to the PBX.\n",
 			        lot_cfg->name, PARKED_CALL_APPLICATION, space, lot_cfg->parking_con);
 			ast_unlock_context(lot_context);
@@ -847,7 +847,7 @@
 			snprintf(hint_device, sizeof(hint_device), "park:%s@%s", space, lot_cfg->parking_con);
 
 			if ((existing_exten = pbx_find_extension(NULL, NULL, &find_info, lot_cfg->parking_con, space, PRIORITY_HINT, NULL, NULL, E_MATCH))) {
-				ast_log(LOG_ERROR, "Parking lot '%s' -- Needs to add a hint '%s' at '%s@%s' but one already exists owned by %s\n",
+				ast_log(LOG_ERROR, "Parking lot '%s' -- Failed to add hint '%s' at '%s@%s' because it already exists, owned by %s.\n",
 			        lot_cfg->name, hint_device, space, lot_cfg->parking_con, ast_get_extension_registrar(existing_exten));
 					ast_unlock_context(lot_context);
 					return -1;

-- 
To view, visit https://gerrit.asterisk.org/9931
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6059f5469d4eb039245e30f31bca95d069f30c2e
Gerrit-Change-Number: 9931
Gerrit-PatchSet: 1
Gerrit-Owner: Karl Brose <karlbrose at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180817/d425b609/attachment-0001.html>


More information about the asterisk-code-review mailing list