Index: res/res_features.c =================================================================== RCS file: /usr/cvsroot/asterisk/res/res_features.c,v retrieving revision 1.16.2.5 diff -u -r1.16.2.5 res_features.c --- res/res_features.c 15 Apr 2005 07:15:39 -0000 1.16.2.5 +++ res/res_features.c 19 Apr 2005 21:43:09 -0000 @@ -49,6 +49,9 @@ /* Context for which parking is made accessible */ static char parking_con[AST_MAX_EXTENSION] = "parkedcalls"; +/* Context for dialback for parking (KLUDGE) */ +static char parking_con_dial[AST_MAX_EXTENSION] = "park-dial"; + /* Extension you type to park the call */ static char parking_ext[AST_MAX_EXTENSION] = "700"; @@ -103,6 +106,7 @@ int priority; int parkingtime; int notquiteyet; + char peername[1024]; unsigned char moh_trys; struct parkeduser *next; }; @@ -181,6 +185,8 @@ pu->parkingtime = parkingtime; if (extout) *extout = x; + if (peer) + strncpy(pu->peername, peer->name, sizeof(pu->peername) - 1); /* Remember what had been dialed, so that if the parking expires, we try to come back to the same place */ if (!ast_strlen_zero(chan->macrocontext)) @@ -551,19 +557,21 @@ struct timeval tv; struct ast_frame *f; char exten[AST_MAX_EXTENSION]; + char *peername,*cp; + char returnexten[AST_MAX_EXTENSION]; struct ast_context *con; int x; fd_set rfds, efds; fd_set nrfds, nefds; FD_ZERO(&rfds); FD_ZERO(&efds); + for (;;) { ms = -1; max = -1; ast_mutex_lock(&parking_lock); pl = NULL; pu = parkinglot; - gettimeofday(&tv, NULL); FD_ZERO(&nrfds); FD_ZERO(&nefds); while(pu) { @@ -573,17 +581,42 @@ pu = pu->next; continue; } + gettimeofday(&tv, NULL); tms = (tv.tv_sec - pu->start.tv_sec) * 1000 + (tv.tv_usec - pu->start.tv_usec) / 1000; if (tms > pu->parkingtime) { - /* They've been waiting too long, send them back to where they came. Theoretically they - should have their original extensions and such, but we copy to be on the safe side */ - strncpy(pu->chan->exten, pu->exten, sizeof(pu->chan->exten)-1); - strncpy(pu->chan->context, pu->context, sizeof(pu->chan->context)-1); - pu->chan->priority = pu->priority; - if (option_verbose > 1) - ast_verbose(VERBOSE_PREFIX_2 "Timeout for %s parked on %d. Returning to %s,%s,%d\n", pu->chan->name, pu->parkingnum, pu->chan->context, pu->chan->exten, pu->chan->priority); /* Stop music on hold */ ast_moh_stop(pu->chan); + /* Get chan, exten from derived kludge */ + if (pu->peername[0]) { + peername = ast_strdupa(pu->peername); + cp = strrchr(peername, '-'); + if (cp) + *cp = 0; + con = ast_context_find(parking_con_dial); + if (!con) { + con = ast_context_create(NULL, parking_con_dial, registrar); + if (!con) { + ast_log(LOG_ERROR, "Parking dial context '%s' does not exist and unable to create\n", parking_con_dial); + } + } + if (con) { + snprintf(returnexten, sizeof(returnexten), "%s||t", peername); + ast_add_extension2(con, 1, peername, 1, NULL, "Dial", strdup(returnexten), free, registrar); + } + strncpy(pu->chan->exten, peername, sizeof(pu->chan->exten) - 1); + strncpy(pu->chan->context, parking_con_dial, sizeof(pu->chan->context) - 1); + pu->chan->priority = 1; + + } else { + /* They've been waiting too long, send them back to where they came. Theoretically they + should have their original extensions and such, but we copy to be on the safe side */ + strncpy(pu->chan->exten, pu->exten, sizeof(pu->chan->exten)-1); + strncpy(pu->chan->context, pu->context, sizeof(pu->chan->context)-1); + pu->chan->priority = pu->priority; + } + + if (option_verbose > 1) + ast_verbose(VERBOSE_PREFIX_2 "Timeout for %s parked on %d. Returning to %s,%s,%d\n", pu->chan->name, pu->parkingnum, pu->chan->context, pu->chan->exten, pu->chan->priority); /* Start up the PBX, or hang them up */ if (ast_pbx_start(pu->chan)) { ast_log(LOG_WARNING, "Unable to restart the PBX for user on '%s', hanging them up...\n", pu->chan->name); @@ -605,14 +638,17 @@ ast_log(LOG_WARNING, "Whoa, no parking context?\n"); free(pt); } else { - for (x=0;xchan->fds[x] > -1) && (FD_ISSET(pu->chan->fds[x], &rfds) || FD_ISSET(pu->chan->fds[x], &efds))) { if (FD_ISSET(pu->chan->fds[x], &efds)) pu->chan->exception = 1; + else + pu->chan->exception = 0; pu->chan->fdno = x; /* See if they need servicing */ f = ast_read(pu->chan); if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) { + /* There's a problem, hang them up*/ if (option_verbose > 1) ast_verbose(VERBOSE_PREFIX_2 "%s got tired of being parked\n", pu->chan->name); @@ -637,7 +673,7 @@ /* XXX Maybe we could do something with packets, like dial "0" for operator or something XXX */ ast_frfree(f); if (pu->moh_trys < 3 && !pu->chan->generatordata) { - ast_log(LOG_DEBUG, "MOH on parked call stopped by outside source. Restarting\n"); + ast_log(LOG_DEBUG, "MOH on parked call stopped by outside source. Restarting.\n"); ast_moh_start(pu->chan, NULL); pu->moh_trys++; } @@ -646,7 +682,7 @@ } } if (x >= AST_MAX_FDS) { -std: for (x=0;xchan->fds[x] > -1) { FD_SET(pu->chan->fds[x], &nrfds);