[asterisk-commits] branch oej/multiparking - r7721 in /team/oej/multiparking: ./ res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 2 13:42:26 CST 2006


Author: oej
Date: Mon Jan  2 13:42:23 2006
New Revision: 7721

URL: http://svn.digium.com/view/asterisk?rev=7721&view=rev
Log:
- Fix AST_LIST implementation
- Add default parking lot as standard configuration (backwards compatibility)


Modified:
    team/oej/multiparking/Makefile
    team/oej/multiparking/res/res_features.c

Modified: team/oej/multiparking/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/Makefile?rev=7721&r1=7720&r2=7721&view=diff
==============================================================================
--- team/oej/multiparking/Makefile (original)
+++ team/oej/multiparking/Makefile Mon Jan  2 13:42:23 2006
@@ -44,7 +44,7 @@
 #K6OPT  = -DK6OPT
 
 #Tell gcc to optimize the code
-OPTIMIZE+=-O6
+OPTIMIZE+=#-O6
 else
   # Stack backtraces, while useful for debugging, are incompatible with optimizations
   ifeq (${OSARCH},Linux)

Modified: team/oej/multiparking/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/res/res_features.c?rev=7721&r1=7720&r2=7721&view=diff
==============================================================================
--- team/oej/multiparking/res/res_features.c (original)
+++ team/oej/multiparking/res/res_features.c Mon Jan  2 13:42:23 2006
@@ -212,7 +212,7 @@
 
 /* Forward declarations */
 int ast_park_call_full(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout, struct ast_parkinglot *parkinglot);
-struct ast_parkinglot *find_parkinglot(char *name);
+struct ast_parkinglot *find_parkinglot(const char *name);
 
 /*! If GOTO_ON_BLINDXFR is set, transferer in a blind transfer will be sent there. */
 static void check_goto_on_transfer(struct ast_channel *chan) 
@@ -314,11 +314,11 @@
 	int i, x, parking_range;
 	char exten[AST_MAX_EXTENSION];
 	struct ast_context *con;
-	char *parkinglotname;
+	const char *parkinglotname;
 	
 
 	if (!parkinglot)
-		parkinglot = &default_parkinglot;
+		parkinglot = default_parkinglot;
 	parkinglotname = pbx_builtin_getvar_helper(chan, "PARKINGLOT");
 	if (parkinglotname) {
 		if (option_debug)
@@ -1543,7 +1543,7 @@
 	char *peername,*cp;
 	char returnexten[AST_MAX_EXTENSION];
 	struct ast_context *con;
-	struct ast_parkinglot *curlot = &default_parkinglot;
+	struct ast_parkinglot *curlot;
 	int x;
 	fd_set rfds, efds;
 	fd_set nrfds, nefds;
@@ -1556,7 +1556,7 @@
 		ast_mutex_lock(&parking_lock);
 		pl = NULL;
 		/* We need to do this for every parking lot */
-		while (curlot) {
+		AST_LIST_TRAVERSE(&parkinglots, curlot, list) {
 			pu = curlot->occupiedlots;
 			FD_ZERO(&nrfds);
 			FD_ZERO(&nefds);
@@ -1689,7 +1689,7 @@
 						}
 					}
 					if (x >= AST_MAX_FDS) {
-	std:					for (x=0; x<AST_MAX_FDS; x++) {
+	std:					for (x=0; x < AST_MAX_FDS; x++) {
 							/* Keep this one for next one */
 							if (pu->chan->fds[x] > -1) {
 								FD_SET(pu->chan->fds[x], &nrfds);
@@ -1706,7 +1706,6 @@
 					}
 				}
 			}
-			curlot = curlot -> next;
 		}
 		ast_mutex_unlock(&parking_lock);
 		rfds = nrfds;
@@ -1720,7 +1719,7 @@
 }
 
 /*--- find_parkinglot: Find parkinglot by name */
-struct ast_parkinglot *find_parkinglot(char *name)
+struct ast_parkinglot *find_parkinglot(const char *name)
 {
 	struct ast_parkinglot *parkinglot = NULL;
 	
@@ -1746,7 +1745,8 @@
 	   lot context eventually */
 	int res=0;
 	struct localuser *u;
-	char *parkinglotname = DEFAULT_PARKINGLOT;
+	const char *parkinglotname = DEFAULT_PARKINGLOT;
+	struct ast_parkinglot *parkinglot = NULL;
 
 	LOCAL_USER_ADD(u);
 	parkinglotname = pbx_builtin_getvar_helper(chan, "PARKINGLOT");
@@ -1778,7 +1778,7 @@
 	struct ast_channel *peer=NULL;
 	struct parkeduser *pu, *pl=NULL;
 	char exten[AST_MAX_EXTENSION];
-	char *parkinglotname;
+	const char *parkinglotname;
 	struct ast_context *con;
 	int park;
 	int dres;
@@ -1895,7 +1895,7 @@
 
 static int park_exec(struct ast_channel *chan, void *data) 
 {
-	return park_exec_full(chan, data, &default_parkinglot);
+	return park_exec_full(chan, data, default_parkinglot);
 }
 
 static int handle_showfeatures(int fd, int argc, char *argv[])
@@ -1951,7 +1951,7 @@
 {
 	struct parkeduser *cur;
 	int numparked = 0;
-	struct ast_parkinglot *parkinglot = &default_parkinglot;
+	struct ast_parkinglot *parkinglot;
 	
 
 	ast_cli(fd, "%4s %25s (%-15s %-12s %-4s) %-6s \n", "Num", "Channel"
@@ -1959,8 +1959,9 @@
 
 	ast_mutex_lock(&parking_lock);
 
-	while (parkinglot) {
+	AST_LIST_TRAVERSE(&parkinglots, parkinglot, list) {
 		int lotparked = 0;
+
 		cur = parkinglot->occupiedlots;
 		if (cur)
 			ast_cli(fd, "*** Parking lot: %s\n", parkinglot->name);
@@ -1973,8 +1974,8 @@
 			lotparked++;
 		}
 		if (lotparked)
-			ast_cli(fd, "%d parked call%s in this parking lot.\n", lotparked, (numparked != 1) ? "s" : "");
-		parkinglot = parkinglot->next;
+			ast_cli(fd, "   %d parked call%s in parking lot %s\n", lotparked, (lotparked != 1) ? "s" : "", parkinglot->name);
+		numparked += lotparked;
 	}
 	ast_cli(fd, "---\n%d parked call%s in total.\n", numparked, (numparked != 1) ? "s" : "");
 
@@ -1996,7 +1997,7 @@
 	struct parkeduser *cur;
 	char *id = astman_get_header(m,"ActionID");
 	char idText[256] = "";
-	struct ast_parkinglot *parkinglot = &default_parkinglot;
+	struct ast_parkinglot *parkinglot;
 
 	if (id && !ast_strlen_zero(id))
 		snprintf(idText,256,"ActionID: %s\r\n",id);
@@ -2007,7 +2008,7 @@
         ast_mutex_lock(&parking_lock);
 
 	
-	while (parkinglot) {
+	AST_LIST_TRAVERSE(&parkinglots, parkinglot, list) {
         	cur=parkinglot->occupiedlots;
         	while(cur) {
 			ast_cli(s->fd, "Event: ParkedCall\r\n"
@@ -2029,13 +2030,12 @@
 
 			cur = cur->next;
 		}
-		parkinglot = parkinglot->next;
 	}
 
 	ast_cli(s->fd,
-	"Event: ParkedCallsComplete\r\n"
-	"%s"
-	"\r\n",idText);
+		"Event: ParkedCallsComplete\r\n"
+		"%s"
+		"\r\n",idText);
 
         ast_mutex_unlock(&parking_lock);
 
@@ -2094,7 +2094,8 @@
 	return newlot;
 }
 
-static void destroy_parkinglot(ast_parkinglot *ruin)
+/*! \brief Destroy a parking lot */
+static void destroy_parkinglot(struct ast_parkinglot *ruin)
 {
 	struct ast_context *con;
 	con = ast_context_find(ruin->parking_con);
@@ -2104,19 +2105,20 @@
 }
 
 /*! \brief Build parkinglot from configuration and chain it in */
-static int build_parking_lot(char *name, struct ast_variable *var)
+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;
 
 	/* Check if parkinglot with this name already exists */
 	/* OEJ */
 	parkinglot = create_parkinglot(name);
 	if (!parkinglot)
-		return;
+		return NULL;
 	
 	/* Do some config stuff */
 	while(confvar) {
@@ -2141,6 +2143,10 @@
 		}
 		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);
@@ -2150,7 +2156,7 @@
 	/* 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", cur->parking_con);
+			ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", parkinglot->parking_con);
 			error = 1;
 		}
 	}
@@ -2162,12 +2168,13 @@
 	if (error) {
 		ast_log(LOG_WARNING, "Parking %s not open for business. Configuration error.\n", name);
 		destroy_parkinglot(parkinglot);
-		return -1;
+		return NULL;
 	}
 
 	/* Move it into the list */
 	AST_LIST_INSERT_TAIL(&parkinglots, parkinglot, list);
-	return 0;
+
+	return parkinglot;
 	
 }
 
@@ -2179,15 +2186,27 @@
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
 
+
 	if (!default_parkinglot) {
-		default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT);
-		AST_LIST_INSERT_TAIL(&parkinglots, parkinglot, list);
+		default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
+		if (default_parkinglot) {
+			default_parkinglot->parking_start = 701;
+			default_parkinglot->parking_stop = 750;
+			default_parkinglot->parking_offset = 0;
+			default_parkinglot->parkfindnext = 0;
+			default_parkinglot->parkingtime = 0;
+		}
+	}
+	if (default_parkinglot)
+		ast_log(LOG_DEBUG, "Configuration of default parkinglot done.\n");
+	else {
+		ast_log(LOG_DEBUG, "Configuration of default parkinglot failed.\n");
+		return -1;
 	}
 	
 	transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
 	featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
 
-	AST_LIST_HEAD_INIT(&parkinglots);
 	
 	strcpy(xfersound, "beep");
 	strcpy(xferfailsound, "pbx-invalid");
@@ -2213,12 +2232,14 @@
 				} else
 					parkingtime = parkingtime * 1000;
 			} else if (!strcasecmp(var->name, "parkpos")) {
+				ast_log(LOG_DEBUG, "Found parking position in general: %s\n", var->value);
 				if (sscanf(var->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", var->lineno);
-				} else {
+				} else if (default_parkinglot) {
 					default_parkinglot->parking_start = start;
 					default_parkinglot->parking_stop = end;
-				}
+				} else 
+					ast_log(LOG_WARNING, "No default parking lot!\n");
 			} else if (!strcasecmp(var->name, "findslot")) {
 				default_parkinglot->parkfindnext = (!strcasecmp(var->value, "next"));
 			} else if (!strcasecmp(var->name, "adsipark")) {
@@ -2325,16 +2346,18 @@
 			var = var->next;
 		}	 
 	}
+
 	/* Now, find parking lot definitions */
 	ast_config_destroy(cfg);
-
 	
 	if (con)
 		ast_context_remove_extension2(con, ast_parking_ext(), 1, registrar);
 	
+	ast_log(LOG_DEBUG, "Trying to find contexts for default parking lot\n");
+
 	if (!(con = ast_context_find(default_parkinglot->parking_con))) {
-		if (!(con = ast_context_create(NULL, cur->parking_con, registrar))) {
-			ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", cur->parking_con);
+		if (!(con = ast_context_create(NULL, default_parkinglot->parking_con, registrar))) {
+			ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", default_parkinglot->parking_con);
 			return -1;
 		}
 	}
@@ -2362,6 +2385,7 @@
 	int res;
 	
 	AST_LIST_HEAD_INIT(&feature_list);
+	AST_LIST_HEAD_INIT(&parkinglots);
 
 	if ((res = load_config()))
 		return res;



More information about the asterisk-commits mailing list