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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Dec 14 23:02:47 CST 2005


Author: bweschke
Date: Wed Dec 14 23:02:43 2005
New Revision: 7488

URL: http://svn.digium.com/view/asterisk?rev=7488&view=rev
Log:
 Getting this app ready to do forked dialing on each follow-me attempt along with the ability to do custom featuremapping of digits to actions via the config file. 

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=7488&r1=7487&r2=7488&view=diff
==============================================================================
--- team/bweschke/findme_followme/apps/app_followme.c (original)
+++ team/bweschke/findme_followme/apps/app_followme.c Wed Dec 14 23:02:43 2005
@@ -56,7 +56,7 @@
 LOCAL_USER_DECL;
 
 struct number {
-	char number[AST_MAX_EXTENSION];	/* Phone Number and/or Extension */
+	char number[512];	/* Phone Number and/or Extension */
 	unsigned int timeout;		/* Dial Timeout, if used. */
 	struct number *next;		/* Next Number record */
 };
@@ -82,6 +82,12 @@
 	char context[AST_MAX_CONTEXT];
 	char namerecloc[AST_MAX_CONTEXT];
 	struct ast_channel *outbound;
+};
+
+struct findme_user {
+	struct ast_channel *ochan;
+	int state;
+	struct findme_user *next;	
 };
 
 struct thread_args targs;
@@ -329,11 +335,18 @@
 				struct number *nm;
 				struct ast_channel *outbound = NULL;
 				struct ast_channel *caller;
-				char dialarg[AST_MAX_EXTENSION];
+				char dialarg[512];
 				int ynidx = 0, ynlongest = 0, passed = 0, attempts = 0;
 				char yn[5];
 				int d = 0,dg;
-				
+				struct ast_channel *watchers[AST_MAX_WATCHERS];
+				int pos;
+				struct ast_channel *winner;
+				struct ast_frame *f;
+				char *rest, *number;
+				int ctstatus;
+				struct findme_user *fmuser = NULL;
+				struct findme_user *tmpuser = NULL;
 				
 				tpargs = (struct thread_args *)args;
 				
@@ -362,26 +375,137 @@
 				
 				ast_log(LOG_DEBUG, "sleeping now inside the thread. number %s timeout %d\n",nm->number,nm->timeout);
 				time(&start_time);
-				if (!strcmp(tpargs->context, ""))
-					sprintf(dialarg, "%s", nm->number);
-				else
-				{
-					sprintf(dialarg, "%s@%s", nm->number, tpargs->context);
-				}
-
+
+				do {
+
+					rest = strchr(nm->number, '&');
+					if (rest) {
+						*rest = 0;
+						rest++;
+					}
+
+					number = ast_strdupa(nm->number);
+					if (!strcmp(tpargs->context, ""))
+						sprintf(dialarg, "%s", number);
+					else
+						sprintf(dialarg, "%s@%s", number, tpargs->context);
+					
+					tmpuser = malloc(sizeof(struct findme_user));
+					if (!tmpuser) {
+						ast_log(LOG_WARNING, "Out of memory!\n");
+						pthread_exit(0);
+					}
+					memset(tmpuser, 0, sizeof(struct findme_user));
+					
+					outbound = ast_request("Local", ast_best_codec(caller->nativeformats), dialarg, &dg);
+					if (outbound) {
+						ast_set_callerid(outbound, caller->cid.cid_num, caller->cid.cid_name, caller->cid.cid_num);
+						ast_channel_inherit_variables(tpargs->chan, outbound);
+						
+						if (!ast_call(outbound,dialarg,0)) {
+							tmpuser->ochan = outbound;
+							tmpuser->state = 0;
+							tmpuser->next = fmuser;
+							fmuser = tmpuser;
+						}
+						
+					} else {
+						ast_log(LOG_WARNING, "Unable to allocate a channel for Local/%s cause: %s\n", &dialarg, ast_cause2str(dg));
+					}
+					
+					nm->number = rest;
+				} while (nm->number);
+				
 				outbound = ast_request("Local", ast_best_codec(caller->nativeformats), dialarg, &dg);
 				if (outbound)
 				{
 					ast_set_callerid(outbound, caller->cid.cid_num, caller->cid.cid_name, caller->cid.cid_num);
-					ast_channel_inherit_variables(tpargs->chan, outbound);	
+					ast_channel_inherit_variables(tpargs->chan, outbound);
+					pos = 1;
+					watchers[0] = caller;
+					
 					if (!ast_call(outbound,dialarg,0))
 					{
 					dg = 0;	
-					while ((outbound) && (outbound->_state != AST_STATE_UP) && (tpargs->status != -50) && (dg < (nm->timeout*4)))
-					{
-						ast_safe_sleep(outbound, 250);
-						dg++;
+					
+					watchers[pos++] = outbound;
+					ctstatus = 0;
+					
+					while (!ctstatus) {
+						winner = ast_waitfor_n(watchers, pos, (nm->timeout*1000));
+
+						if (winner && winner == outbound) {
+							f = ast_read(winner);
+							if (f) {
+								if (f->frametype == AST_FRAME_CONTROL) {
+									switch(f->subclass) {
+									case AST_CONTROL_ANSWER:
+										/* This is our guy if someone answered. */
+										if (option_verbose > 2)
+											ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", outbound->name, caller->name);
+										/* If call has been answered, then the eventual hangup is likely to be normal hangup 
+										outbound->hangupcause = AST_CAUSE_NORMAL_CLEARING;
+										caller->hangupcause = AST_CAUSE_NORMAL_CLEARING;  */
+										ctstatus = 1;
+										break;
+									case AST_CONTROL_BUSY:
+										if (option_verbose > 2)
+											ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", outbound->name);
+										ctstatus = -1;
+										break;
+									case AST_CONTROL_CONGESTION:
+										if (option_verbose > 2)
+											ast_verbose( VERBOSE_PREFIX_3 "%s is circuit-busy\n", outbound->name);
+										ctstatus = -1;
+										break;
+									case AST_CONTROL_RINGING:
+										if (option_verbose > 2)
+											ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", outbound->name);
+										break;
+									case AST_CONTROL_PROGRESS:
+										if (option_verbose > 2)
+											ast_verbose ( VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", outbound->name,caller->name);
+										break;
+									case AST_CONTROL_VIDUPDATE:
+										if (option_verbose > 2)
+											ast_verbose ( VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", outbound->name,caller->name);
+										break;
+									case AST_CONTROL_PROCEEDING:
+										if (option_verbose > 2)
+											ast_verbose ( VERBOSE_PREFIX_3 "%s is proceeding passing it to %s\n", outbound->name,caller->name);
+										break;
+									case AST_CONTROL_HOLD:
+										if (option_verbose > 2)
+											ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", outbound->name);
+										break;
+									case AST_CONTROL_UNHOLD:
+										if (option_verbose > 2)
+											ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", outbound->name);
+										break;
+									case AST_CONTROL_OFFHOOK:
+									case AST_CONTROL_FLASH:
+										/* Ignore going off hook and flash */
+										break;
+									case -1:
+										if (option_verbose > 2)
+											ast_verbose( VERBOSE_PREFIX_3 "%s stopped sounds\n", outbound->name);
+										break;
+									default:
+										ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
+									}
+								}		
+								ast_frfree(f);
+							}					
+						} else if (winner && winner == caller) {
+							if (tpargs->status == -50)
+								ctstatus = -1;
+						} else {
+							if (option_verbose > 2)
+									ast_verbose(VERBOSE_PREFIEX_3 "%s timeout on the dialing channel %s\n", outbound->name);
+							ctstatus = -1;
+						}
 					}
+					
 					if (tpargs->status == -50)
 					{ 
 						ast_log(LOG_DEBUG, "Got a signal that the other end hung up. exiting thread.\n");



More information about the asterisk-commits mailing list