[asterisk-commits] file: trunk r48639 - /trunk/apps/app_page.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Dec 19 21:32:59 MST 2006


Author: file
Date: Tue Dec 19 22:32:59 2006
New Revision: 48639

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48639
Log:
Clean up app_page

Modified:
    trunk/apps/app_page.c

Modified: trunk/apps/app_page.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_page.c?view=diff&rev=48639&r1=48638&r2=48639
==============================================================================
--- trunk/apps/app_page.c (original)
+++ trunk/apps/app_page.c Tue Dec 19 22:32:59 2006
@@ -88,9 +88,12 @@
 static void *page_thread(void *data)
 {
 	struct calloutdata *cd = data;
+
 	ast_pbx_outgoing_app(cd->tech, AST_FORMAT_SLINEAR, cd->resource, 30000,
 		"MeetMe", cd->meetmeopts, NULL, 0, cd->cidnum, cd->cidname, cd->variables, NULL, NULL);
+
 	free(cd);
+
 	return NULL;
 }
 
@@ -102,42 +105,46 @@
 	struct ast_var_t *varptr;
 	pthread_t t;
 	pthread_attr_t attr;
-	if ((cd = ast_calloc(1, sizeof(*cd)))) {
-		ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
-		ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
-		ast_copy_string(cd->tech, tech, sizeof(cd->tech));
-		ast_copy_string(cd->resource, resource, sizeof(cd->resource));
-		ast_copy_string(cd->meetmeopts, meetmeopts, sizeof(cd->meetmeopts));
-
-		AST_LIST_TRAVERSE(&chan->varshead, varptr, entries) {
-			if (!(varname = ast_var_full_name(varptr)))
-				continue;
-			if (varname[0] == '_') {
-				struct ast_variable *newvar = NULL;
-
-				if (varname[1] == '_') {
-					newvar = ast_variable_new(varname, ast_var_value(varptr));
-				} else {
-					newvar = ast_variable_new(&varname[1], ast_var_value(varptr));
-				}
-
-				if (newvar) {
-					if (lastvar)
-						lastvar->next = newvar;
-					else
-						cd->variables = newvar;
-					lastvar = newvar;
-				}
-			}
+
+	if (!(cd = ast_calloc(1, sizeof(*cd))))
+		return;
+
+	/* Copy data from our page over */
+	ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
+	ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
+	ast_copy_string(cd->tech, tech, sizeof(cd->tech));
+	ast_copy_string(cd->resource, resource, sizeof(cd->resource));
+	ast_copy_string(cd->meetmeopts, meetmeopts, sizeof(cd->meetmeopts));
+	
+	AST_LIST_TRAVERSE(&chan->varshead, varptr, entries) {
+		struct ast_variable *newvar = NULL;
+
+		if (!(varname = ast_var_full_name(varptr)) || (varname[0] != '_'))
+			continue;
+			
+		if (varname[1] == '_')
+			newvar = ast_variable_new(varname, ast_var_value(varptr));
+		else
+			newvar = ast_variable_new(&varname[1], ast_var_value(varptr));
+		
+		if (newvar) {
+			if (lastvar)
+				lastvar->next = newvar;
+			else
+				cd->variables = newvar;
+			lastvar = newvar;
 		}
-
-		pthread_attr_init(&attr);
-		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-		if (ast_pthread_create(&t, &attr, page_thread, cd)) {
-			ast_log(LOG_WARNING, "Unable to create paging thread: %s\n", strerror(errno));
-			free(cd);
-		}
-	}
+	}
+
+	/* Spawn thread to handle this page */
+	pthread_attr_init(&attr);
+	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+	if (ast_pthread_create(&t, &attr, page_thread, cd)) {
+		ast_log(LOG_WARNING, "Unable to create paging thread: %s\n", strerror(errno));
+		free(cd);
+	}
+
+	return;
 }
 
 static int page_exec(struct ast_channel *chan, void *data)
@@ -197,6 +204,7 @@
 		if (!res)
 			res = ast_waitstream(chan, "");
 	}
+
 	if (!res) {
 		snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"), 
 			(ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );



More information about the asterisk-commits mailing list