[asterisk-commits] branch bweschke/findme_followme r15513 - /team/bweschke/findme_followme/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 28 05:42:29 MST 2006


Author: bweschke
Date: Tue Mar 28 06:42:28 2006
New Revision: 15513

URL: http://svn.digium.com/view/asterisk?rev=15513&view=rev
Log:
 Code cleanup and fix for a segfault problem when we try to playback files that don't exist.


Modified:
    team/bweschke/findme_followme/apps/app_followme.c

Modified: team/bweschke/findme_followme/apps/app_followme.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/findme_followme/apps/app_followme.c?rev=15513&r1=15512&r2=15513&view=diff
==============================================================================
--- team/bweschke/findme_followme/apps/app_followme.c (original)
+++ team/bweschke/findme_followme/apps/app_followme.c Tue Mar 28 06:42:28 2006
@@ -3,13 +3,29 @@
  *
  * A full-featured Find-Me/Follow-Me Application
  * 
- * Copyright (C) 2005-2006, BJ Weschke
+ * Copyright (C) 2005-2006, BJ Weschke All Rights Reserved.
  *
  * BJ Weschke <bweschke at btwtech.com>
  *
- * This program is free software, distributed under the terms of
- * the GNU General Public License
+ * This code is released by the author with no restrictions on usage.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
  */
+
+/*! \file
+ *
+ * \brief Find-Me Follow-Me application
+ *
+ * \author BJ Weschke <bweschke at btwtech.com>
+ *
+ * \ingroup applications
+ */
+
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -387,9 +403,14 @@
 		int livechannels = 0;
 		int tmpto;
 		long totalwait = 0;
+		char *callfromname;
+		char *pressbuttonname;
 
 		/* ------------ wait_for_winner_channel start --------------- */ 
-		
+
+		callfromname = ast_strdupa("call-from");
+		pressbuttonname = ast_strdupa("press-1-to-be-connected-or");	
+	
 		if (headuser->ochan)
 		{
 			if (!caller) {
@@ -414,10 +435,12 @@
 							ast_log(LOG_NOTICE, "We've been waiting for digits longer than we should have.\n");
 							tmpuser->state = 1;
 							tmpuser->digts = 0;
-							if (!ast_streamfile(tmpuser->ochan, "call-from", tmpuser->ochan->language)) {
+							if (!ast_streamfile(tmpuser->ochan, callfromname, tmpuser->ochan->language)) {
 								ast_sched_runq(tmpuser->ochan->sched);
-							}
-							
+							} else {
+								ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
+								return NULL;
+							}							
 						}
 						if (tmpuser->ochan->stream) {
 							ast_sched_runq(tmpuser->ochan->sched);
@@ -430,15 +453,21 @@
 									ast_log(LOG_NOTICE, "Playback of the file appears to be done.\n");
 									if (!ast_streamfile(tmpuser->ochan, namerecloc, tmpuser->ochan->language)) {
 										tmpuser->state = 2;
+									} else {
+										ast_log(LOG_WARNING, "Unable to playback %s.\n", namerecloc);
+										return NULL;
 									}
 								} else if (tmpuser->state == 2) {
 									ast_log(LOG_NOTICE, "Playback of name file appears to be done.\n");
 									memset(tmpuser->yn, 0, sizeof(tmpuser->yn));
 									tmpuser->ynidx = 0;
 									tmpuser->digts = 0;
-									if (!ast_streamfile(tmpuser->ochan, "press-1-to-be-connected-or", tmpuser->ochan->language)) {
+									if (!ast_streamfile(tmpuser->ochan, pressbuttonname, tmpuser->ochan->language)) {
 										tmpuser->state = 3;
 										
+									} else {
+										ast_log(LOG_WARNING, "Unable to playback %s.\n", pressbuttonname);
+										return NULL;
 									} 
 								} else if (tmpuser->state == 3) {
 									ast_log(LOG_NOTICE, "Playback of the next step file appears to be done.\n");
@@ -490,11 +519,13 @@
 								winner->hangupcause = AST_CAUSE_NORMAL_CLEARING;
 								caller->hangupcause = AST_CAUSE_NORMAL_CLEARING;
 								if (dg > 0) {
-									if (!ast_streamfile(winner, "call-from", winner->language)) {
+									if (!ast_streamfile(winner, callfromname, winner->language)) {
 										ast_sched_runq(winner->sched);
 										tmpuser->state = 1;
-									}
-									
+									} else {
+										ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
+										return NULL;
+									}							
 								}
 								break;
 							case AST_CONTROL_BUSY:
@@ -603,219 +634,6 @@
 					
 				} 
 			}
-		/*	
-			if (tpargs->status == -50)
-			{ 
-				ast_log(LOG_DEBUG, "Got a signal that the other end hung up. exiting thread.\n");
-						 if (outbound) {
-							if (!outbound->cdr) {
-								outbound->cdr = ast_cdr_alloc();
-								if (outbound->cdr)
-									ast_cdr_init(outbound->cdr, outbound);
-							}
-							if (outbound->cdr) {
-								char tmp[256];
-								snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-								ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-								ast_cdr_update(outbound);
-								ast_cdr_start(outbound->cdr);
-								ast_cdr_end(outbound->cdr);
-								if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-									ast_cdr_failed(outbound->cdr);
-							} else
-								ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-							ast_hangup(outbound);
-							outbound = NULL;
-						}
-				pthread_exit(0);		
-
-			}  
-			if (winner->_state == AST_STATE_UP) 
-			{
-				ast_log(LOG_DEBUG, "Looks up! Sleeping!\n");
-				ast_safe_sleep(outbound, 500);
-				if (!ast_streamfile(outbound, "call-from", outbound->language)) {
-					if (ast_waitstream(outbound, "") < 0)
-						goto outrun;
-				} else
-				goto outrun;
-				if (!ast_streamfile(outbound, tpargs->namerecloc, outbound->language)) {
-					if (ast_waitstream(outbound, "") < 0)
-						goto outrun;
-				} else
-				goto outrun;
-				ast_streamfile(outbound, "press-1-to-be-connected-or", outbound->language);
-				if (outbound->stream) {
-					d = ast_waitstream(outbound, AST_DIGIT_ANY);
-					ast_stopstream(outbound);
-					usleep(1000);
-					ast_log(LOG_DEBUG, "digit is in?\n");
-				}
-				
-				if (!d)
-					d = -1;
-				
-				while ((!passed) && (attempts < maxretries)) {
-					
-					if (outbound->stream)
-						d = ast_waitstream(outbound, AST_DIGIT_ANY);
-						
-					if (d && (d != -1)) {
-						ast_log(LOG_DEBUG, "waitfordigit result %d\n", d);
-						if (d) {
-							yn[ynidx] = d;
-							ynidx++;
-						}
-					}
-					
-					ast_log(LOG_DEBUG, "d: %d ynidx: %d ynlongest: %d \n", d, ynidx, ynlongest);
-					
-					while ((d != 0) && (ynidx <= 3) && (ynidx < (ynlongest))) {
-						d = ast_waitfordigit(outbound, featuredigittimeout);
-						yn[ynidx] = d;
-						ynidx++;
-					}
-					yn[ynidx] = 0;
-					
-					if ( (strlen((void *)&yn) > 0) && (strcmp(yn, nextinfmfm))) {
-						ast_log(LOG_DEBUG, "YN is: %s\n", yn);
-						
-						if (!strcmp(yn, takecall))
-						{
-							tpargs->outbound = outbound;
-							tpargs->status = 100;
-							pthread_exit(0);
-							
-						} else if (!strcmp(yn, blindxferexten)) {
-							ast_log(LOG_DEBUG, "blind xfer exten dtmf featuremap received.\n");
-							
-						} else if (!strcmp(yn, atxferexten)) {
-							ast_log(LOG_DEBUG, "blind xfer exten dtmf featuremap received.\n");									
-						}
-						else if (!strcmp(yn, nextindp))
-						{
-							ast_log(LOG_DEBUG, "caller doesn't want to bothered right now.\n");
-							 if (outbound) {
-								if (!outbound->cdr) {
-									outbound->cdr = ast_cdr_alloc();
-									if (outbound->cdr)
-										ast_cdr_init(outbound->cdr, outbound);
-								}
-								if (outbound->cdr) {
-									char tmp[256];
-									snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-									ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-									ast_cdr_update(outbound);
-									ast_cdr_start(outbound->cdr);
-									ast_cdr_end(outbound->cdr);
-									if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-										ast_cdr_failed(outbound->cdr);
-								} else
-									ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-								ast_hangup(outbound);
-								outbound = NULL;
-							}
-							tpargs->status = 99;
-							pthread_exit(0);
-						}
-						else 
-						{
-							ast_log(LOG_DEBUG, "we got a call, and a digit, but it wasn't a 1 or a 2\n");
-							ast_streamfile(outbound, "press-1-to-be-connected-or", outbound->language);
-							ynidx = 0;
-						}
-					}
-					else
-					{
-						 // digit collection timed out
-						 ast_log(LOG_NOTICE, "Digit collection timed out. Proceed on to the next number (if any)\n");
-						 if (outbound) {
-							if (!outbound->cdr) {
-								outbound->cdr = ast_cdr_alloc();
-								if (outbound->cdr)
-									ast_cdr_init(outbound->cdr, outbound);
-							}
-							if (outbound->cdr) {
-								char tmp[256];
-								snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-								ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-								ast_cdr_update(outbound);
-								ast_cdr_start(outbound->cdr);
-								ast_cdr_end(outbound->cdr);
-								if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-									ast_cdr_failed(outbound->cdr);
-							} else
-								ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-							ast_hangup(outbound);
-							outbound = NULL;
-						}
-					}
-					
-				
-					attempts++;
-
-					if (attempts >= maxretries) {
-						ast_log(LOG_DEBUG, "caller still isn't inputting correct DTMF after max attempts.\n");
-						 if (outbound) {
-							if (!outbound->cdr) {
-								outbound->cdr = ast_cdr_alloc();
-								if (outbound->cdr)
-									ast_cdr_init(outbound->cdr, outbound);
-							}
-							if (outbound->cdr) {
-								char tmp[256];
-								snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-								ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-								ast_cdr_update(outbound);
-								ast_cdr_start(outbound->cdr);
-								ast_cdr_end(outbound->cdr);
-								if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-									ast_cdr_failed(outbound->cdr);
-							} else
-								ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-							ast_hangup(outbound);
-							outbound = NULL;
-						}
-						tpargs->status = 99;
-						pthread_exit(0);								
-					}
-					
-
-					if (!outbound)
-						break;
-
-				} // while attempt
-				
-				
-				outrun:
-				tpargs->status = 200;
-			} else { 
-					ast_log(LOG_DEBUG, "timeout or dial failure.\n"); 
-						 if (outbound) {
-							if (!outbound->cdr) {
-								outbound->cdr = ast_cdr_alloc();
-								if (outbound->cdr)
-									ast_cdr_init(outbound->cdr, outbound);
-							}
-							if (outbound->cdr) {
-								char tmp[256];
-								snprintf(tmp, 256, "%s/%s", "Local", dialarg);
-								ast_cdr_setapp(outbound->cdr,"FollowMe",tmp);
-								ast_cdr_update(outbound);
-								ast_cdr_start(outbound->cdr);
-								ast_cdr_end(outbound->cdr);
-								if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
-									ast_cdr_failed(outbound->cdr);
-							} else
-								ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
-							ast_hangup(outbound);
-							outbound = NULL;
-						}
-					
-				}
-		
-
-			*/	
 			
 		}
 		else
@@ -1053,13 +871,6 @@
 				ast_copy_string(targs.namerecloc, namerecloc, sizeof(targs.namerecloc));
 				ast_copy_string(targs.context, f->context, sizeof(targs.context));
 
-				/*
-				
-				pthread_attr_init(&tattr);
-				pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
-				ast_pthread_create(&finderthread, &tattr, findmethread, &targs);
- 				*/
-
 				findmethread(&targs);			
 	
 				unlink(namerecloc);	



More information about the asterisk-commits mailing list