[svn-commits] oej: branch group/multiparking r104050 - /team/group/multiparking/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Feb 23 09:02:51 CST 2008


Author: oej
Date: Sat Feb 23 09:02:51 2008
New Revision: 104050

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104050
Log:
Add missing functions

Modified:
    team/group/multiparking/main/features.c

Modified: team/group/multiparking/main/features.c
URL: http://svn.digium.com/view/asterisk/team/group/multiparking/main/features.c?view=diff&rev=104050&r1=104049&r2=104050
==============================================================================
--- team/group/multiparking/main/features.c (original)
+++ team/group/multiparking/main/features.c Sat Feb 23 09:02:51 2008
@@ -2589,6 +2589,140 @@
 
 	return res;
 }
+
+/*! \brief Unreference parkinglot object. If no more references,
+	then go ahead and delete it */
+static void parkinglot_unref(struct ast_parkinglot *parkinglot) 
+{
+	if (option_debug > 2)
+		ast_log(LOG_DEBUG, "Multiparking: %s refcount now %d\n", parkinglot->name, parkinglot->refcount - 1);
+	ASTOBJ_UNREF(parkinglot, parkinglot_destroy);
+}
+
+static struct ast_parkinglot *parkinglot_addref(struct ast_parkinglot *parkinglot)
+{
+	if (option_debug > 2)
+		ast_log(LOG_DEBUG, "Multiparking: %s refcount now %d\n", parkinglot->name, parkinglot->refcount + 1);
+	return ASTOBJ_REF(parkinglot);
+}
+
+/*! \brief Allocate parking lot structure */
+static struct ast_parkinglot *create_parkinglot(char *name)
+{
+	struct ast_parkinglot *newlot = (struct ast_parkinglot *) NULL;
+
+	if (!name)
+		return NULL;
+
+	newlot = ast_calloc(1, sizeof(*newlot));
+	if (!newlot)
+		return NULL;
+
+	ASTOBJ_INIT(newlot);
+	ast_copy_string(newlot->name, name, sizeof(newlot->name));
+
+	return newlot;
+}
+
+/*! \brief Destroy a parking lot */
+static void parkinglot_destroy(struct ast_parkinglot *ruin)
+{
+	struct ast_context *con;
+	con = ast_context_find(ruin->parking_con);
+	if (con)
+		ast_context_destroy(con, registrar);
+	ASTOBJ_CONTAINER_UNLINK(&parkinglots, ruin);	/* Remove from parkinglot list */
+	free(ruin);
+}
+
+/*! \brief Build parkinglot from configuration and chain it in */
+static struct ast_parkinglot *build_parkinglot(char *name, struct ast_variable *var)
+{
+	struct ast_parkinglot *parkinglot;
+	struct ast_context *con = NULL;
+
+	struct ast_variable *confvar = var;
+	int error = 0;
+	int start = 0, end = 0;
+
+	parkinglot = find_parkinglot(name);
+	if (parkinglot)
+		ASTOBJ_UNMARK(parkinglot);
+	else
+		parkinglot = create_parkinglot(name);
+
+	if (!parkinglot)
+		return NULL;
+
+	ASTOBJ_WRLOCK(parkinglot);
+
+	if (option_debug)
+		ast_log(LOG_DEBUG, "Building parking lot %s\n", name);
+	
+	/* Do some config stuff */
+	while(confvar) {
+		if (!strcasecmp(confvar->name, "context")) {
+			ast_copy_string(parkinglot->parking_con, confvar->value, sizeof(parkinglot->parking_con));
+		} else if (!strcasecmp(confvar->name, "parkingtime")) {
+			if ((sscanf(confvar->value, "%d", &parkingtime) != 1) || (parkingtime < 1)) {
+				ast_log(LOG_WARNING, "%s is not a valid parkingtime\n", confvar->value);
+				parkinglot->parkingtime = DEFAULT_PARK_TIME;
+			} else
+				parkinglot->parkingtime = parkingtime * 1000;
+		} else if (!strcasecmp(confvar->name, "parkpos")) {
+			if (sscanf(confvar->value, "%d-%d", &start, &end) != 2) {
+				ast_log(LOG_WARNING, "Format for parking positions is a-b, where a and b are numbers at line %d of parking.conf\n", confvar->lineno);
+				error = 1;
+			} else {
+				parkinglot->parking_start = start;
+				parkinglot->parking_stop = end;
+			}
+		} else if (!strcasecmp(confvar->name, "findslot")) {
+			parkinglot->parkfindnext = (!strcasecmp(confvar->value, "next"));
+		}
+		confvar = confvar->next;
+	}
+
+	if (!var)	/* Default parking lot */
+		ast_copy_string(parkinglot->parking_con, "parkedcalls", sizeof(parkinglot->parking_con));
+
+	/* Check for errors */
+	if (ast_strlen_zero(parkinglot->parking_con)) {
+		ast_log(LOG_WARNING, "Parking lot %s lacks context\n", name);
+		error = 1;
+	}
+
+	/* Create context */
+	if (!error && !(con = ast_context_find(parkinglot->parking_con))) {
+		if (!(con = ast_context_create(NULL, parkinglot->parking_con, registrar))) {
+			ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parkinglot->parking_con);
+			error = 1;
+		}
+	}
+
+	/* Add a parking extension into the context */
+	if (ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), ast_free, registrar) == -1)
+		error = 1;
+
+	ASTOBJ_UNLOCK(parkinglot);
+
+	if (error) {
+		ast_log(LOG_WARNING, "Parking %s not open for business. Configuration error.\n", name);
+		parkinglot_destroy(parkinglot);
+		return NULL;
+	}
+	if (option_debug)
+		ast_log(LOG_DEBUG, "Parking %s now open for business. (start exten %d end %d)\n", name, start, end);
+
+
+	/* Move it into the list */
+	ASTOBJ_CONTAINER_LINK(&parkinglots, parkinglot);
+	parkinglot_unref(parkinglot);
+
+	return parkinglot;
+	
+}
+
 
 /*! 
  * \brief Add parking hints for all defined parking lots 




More information about the svn-commits mailing list