Sat Mar 26 11:10:11 2011

Asterisk developer's documentation


app_followme.c File Reference

Find-Me Follow-Me application. More...

#include "asterisk.h"
#include <signal.h>
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/say.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/astdb.h"
#include "asterisk/dsp.h"
#include "asterisk/app.h"

Include dependency graph for app_followme.c:

Go to the source code of this file.

Data Structures

struct  blnumbers
struct  call_followme
 Data structure for followme scripts. More...
struct  cnumbers
struct  findme_user
struct  findme_user_listptr
struct  fm_args
struct  followmes
struct  number
 Number structure. More...
struct  numbers
struct  wlnumbers

Enumerations

enum  { FOLLOWMEFLAG_STATUSMSG = (1 << 0), FOLLOWMEFLAG_RECORDNAME = (1 << 1), FOLLOWMEFLAG_UNREACHABLEMSG = (1 << 2), FOLLOWMEFLAG_DISABLEHOLDPROMPT = (1 << 3) }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static struct call_followme * alloc_profile (const char *fmname)
 Allocate and initialize followme profile.
static int app_exec (struct ast_channel *chan, const char *data)
static void clear_caller (struct findme_user *tmpuser)
static void clear_calling_tree (struct findme_user_listptr *findme_user_list)
static struct number * create_followme_number (const char *number, int timeout, int numorder)
 Add a new number.
static void end_bridge_callback (void *data)
static void end_bridge_callback_data_fixup (struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
static struct call_followme * find_realtime (const char *name)
static void findmeexec (struct fm_args *tpargs)
static void free_numbers (struct call_followme *f)
static void init_profile (struct call_followme *f)
static int load_module (void)
static void profile_set_param (struct call_followme *f, const char *param, const char *val, int linenum, int failunknown)
 Set parameter in profile from configuration file.
static int reload (void)
static int reload_followme (int reload)
 Reload followme application module.
static int unload_module (void)
static struct ast_channel * wait_for_winner (struct findme_user_listptr *findme_user_list, struct number *nm, struct ast_channel *caller, char *namerecloc, int *status, struct fm_args *tpargs)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Find-Me/Follow-Me Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static char * app = "FollowMe"
static struct ast_module_info * ast_module_info = &__mod_info
static char callfromprompt [PATH_MAX] = "followme/call-from"
static const char * defaultmoh = "default"
static int featuredigittimeout = 5000
static const char * featuredigittostr
static struct ast_app_option followme_opts [128] = { [ 's' ] = { .flag = FOLLOWMEFLAG_STATUSMSG }, [ 'a' ] = { .flag = FOLLOWMEFLAG_RECORDNAME }, [ 'n' ] = { .flag = FOLLOWMEFLAG_UNREACHABLEMSG }, [ 'd' ] = { .flag = FOLLOWMEFLAG_DISABLEHOLDPROMPT },}
static char nextindp [20] = "2"
static char norecordingprompt [PATH_MAX] = "followme/no-recording"
static char optionsprompt [PATH_MAX] = "followme/options"
static char plsholdprompt [PATH_MAX] = "followme/pls-hold-while-try"
static char sorryprompt [PATH_MAX] = "followme/sorry"
static char statusprompt [PATH_MAX] = "followme/status"
static char takecall [20] = "1"
static int ynlongest = 0


Detailed Description

Find-Me Follow-Me application.

Author:
BJ Weschke <bweschke@btwtech.com>

Definition in file app_followme.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
FOLLOWMEFLAG_STATUSMSG 
FOLLOWMEFLAG_RECORDNAME 
FOLLOWMEFLAG_UNREACHABLEMSG 
FOLLOWMEFLAG_DISABLEHOLDPROMPT 

Definition at line 161 of file app_followme.c.

00161      {
00162    FOLLOWMEFLAG_STATUSMSG = (1 << 0),
00163    FOLLOWMEFLAG_RECORDNAME = (1 << 1),
00164    FOLLOWMEFLAG_UNREACHABLEMSG = (1 << 2),
00165    FOLLOWMEFLAG_DISABLEHOLDPROMPT = (1 << 3)
00166 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 1206 of file app_followme.c.

static void __unreg_module ( void   )  [static]

Definition at line 1206 of file app_followme.c.

static struct call_followme* alloc_profile ( const char *  fmname  )  [static, read]

Allocate and initialize followme profile.

Definition at line 216 of file app_followme.c.

References ast_calloc, ast_copy_string(), AST_LIST_HEAD_INIT_NOLOCK, ast_mutex_init, call_followme::blnumbers, call_followme::callfromprompt, call_followme::context, f, call_followme::lock, call_followme::moh, call_followme::name, call_followme::nextindp, call_followme::norecordingprompt, call_followme::numbers, call_followme::optionsprompt, call_followme::plsholdprompt, call_followme::sorryprompt, call_followme::statusprompt, call_followme::takecall, and call_followme::wlnumbers.

Referenced by find_realtime(), and reload_followme().

00217 {
00218    struct call_followme *f;
00219 
00220    if (!(f = ast_calloc(1, sizeof(*f))))
00221       return NULL;
00222 
00223    ast_mutex_init(&f->lock);
00224    ast_copy_string(f->name, fmname, sizeof(f->name));
00225    f->moh[0] = '\0';
00226    f->context[0] = '\0';
00227    ast_copy_string(f->takecall, takecall, sizeof(f->takecall));
00228    ast_copy_string(f->nextindp, nextindp, sizeof(f->nextindp));
00229    ast_copy_string(f->callfromprompt, callfromprompt, sizeof(f->callfromprompt));
00230    ast_copy_string(f->norecordingprompt, norecordingprompt, sizeof(f->norecordingprompt));
00231    ast_copy_string(f->optionsprompt, optionsprompt, sizeof(f->optionsprompt));
00232    ast_copy_string(f->plsholdprompt, plsholdprompt, sizeof(f->plsholdprompt));
00233    ast_copy_string(f->statusprompt, statusprompt, sizeof(f->statusprompt));
00234    ast_copy_string(f->sorryprompt, sorryprompt, sizeof(f->sorryprompt));
00235    AST_LIST_HEAD_INIT_NOLOCK(&f->numbers);
00236    AST_LIST_HEAD_INIT_NOLOCK(&f->blnumbers);
00237    AST_LIST_HEAD_INIT_NOLOCK(&f->wlnumbers);
00238    return f;
00239 }

static int app_exec ( struct ast_channel *  chan,
const char *  data 
) [static]

Definition at line 1011 of file app_followme.c.

References ast_channel::_state, call_followme::active, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_bridge_call(), ast_channel_make_compatible(), ast_config_AST_SPOOL_DIR, ast_copy_string(), ast_deactivate_generator(), ast_debug, AST_DECLARE_APP_ARGS, ast_dsp_get_threshold_from_settings(), AST_FEATURE_AUTOMON, AST_FEATURE_REDIRECT, ast_fileexists(), ast_free, ast_hangup(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock, ast_mutex_unlock, ast_play_and_record(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_set_flag, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_stream_and_wait(), ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), ast_channel::caller, call_followme::callfromprompt, fm_args::callfromprompt, fm_args::chan, fm_args::cnumbers, call_followme::context, fm_args::context, create_followme_number(), end_bridge_callback(), ast_bridge_config::end_bridge_callback, ast_bridge_config::end_bridge_callback_data, end_bridge_callback_data_fixup(), ast_bridge_config::end_bridge_callback_data_fixup, f, ast_bridge_config::features_callee, ast_bridge_config::features_caller, find_realtime(), findmeexec(), followme_opts, FOLLOWMEFLAG_DISABLEHOLDPROMPT, FOLLOWMEFLAG_RECORDNAME, FOLLOWMEFLAG_STATUSMSG, FOLLOWMEFLAG_UNREACHABLEMSG, fm_args::followmeflags, free_numbers(), ast_channel::language, call_followme::lock, LOG_ERROR, LOG_WARNING, call_followme::moh, fm_args::mohclass, ast_channel::name, call_followme::name, fm_args::namerecloc, call_followme::nextindp, fm_args::nextindp, call_followme::norecordingprompt, fm_args::norecordingprompt, number::number, call_followme::numbers, call_followme::optionsprompt, fm_args::optionsprompt, number::order, fm_args::outbound, call_followme::plsholdprompt, fm_args::plsholdprompt, call_followme::realtime, S_OR, call_followme::sorryprompt, fm_args::sorryprompt, fm_args::status, call_followme::statusprompt, fm_args::statusprompt, call_followme::takecall, fm_args::takecall, THRESHOLD_SILENCE, number::timeout, and ast_channel::uniqueid.

Referenced by load_module().

01012 {
01013    struct fm_args targs = { 0, };
01014    struct ast_bridge_config config;
01015    struct call_followme *f;
01016    struct number *nm, *newnm;
01017    int res = 0;
01018    char *argstr;
01019    char namerecloc[255];
01020    int duration = 0;
01021    struct ast_channel *caller;
01022    struct ast_channel *outbound;
01023    AST_DECLARE_APP_ARGS(args,
01024       AST_APP_ARG(followmeid);
01025       AST_APP_ARG(options);
01026    );
01027 
01028    if (ast_strlen_zero(data)) {
01029       ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n", app);
01030       return -1;
01031    }
01032 
01033    if (!(argstr = ast_strdupa((char *)data))) {
01034       ast_log(LOG_ERROR, "Out of memory!\n");
01035       return -1;
01036    }
01037 
01038    AST_STANDARD_APP_ARGS(args, argstr);
01039 
01040    if (ast_strlen_zero(args.followmeid)) {
01041       ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n", app);
01042       return -1;
01043    }
01044 
01045    AST_RWLIST_RDLOCK(&followmes);
01046    AST_RWLIST_TRAVERSE(&followmes, f, entry) {
01047       if (!strcasecmp(f->name, args.followmeid) && (f->active))
01048          break;
01049    }
01050    AST_RWLIST_UNLOCK(&followmes);
01051 
01052    ast_debug(1, "New profile %s.\n", args.followmeid);
01053 
01054    if (!f) {
01055       f = find_realtime(args.followmeid);
01056    }
01057 
01058    if (!f) {
01059       ast_log(LOG_WARNING, "Profile requested, %s, not found in the configuration.\n", args.followmeid);
01060       return 0;
01061    }
01062 
01063    /* XXX TODO: Reinsert the db check value to see whether or not follow-me is on or off */
01064    if (args.options) 
01065       ast_app_parse_options(followme_opts, &targs.followmeflags, NULL, args.options);
01066 
01067    /* Lock the profile lock and copy out everything we need to run with before unlocking it again */
01068    ast_mutex_lock(&f->lock);
01069    targs.mohclass = ast_strdupa(f->moh);
01070    ast_copy_string(targs.context, f->context, sizeof(targs.context));
01071    ast_copy_string(targs.takecall, f->takecall, sizeof(targs.takecall));
01072    ast_copy_string(targs.nextindp, f->nextindp, sizeof(targs.nextindp));
01073    ast_copy_string(targs.callfromprompt, f->callfromprompt, sizeof(targs.callfromprompt));
01074    ast_copy_string(targs.norecordingprompt, f->norecordingprompt, sizeof(targs.norecordingprompt));
01075    ast_copy_string(targs.optionsprompt, f->optionsprompt, sizeof(targs.optionsprompt));
01076    ast_copy_string(targs.plsholdprompt, f->plsholdprompt, sizeof(targs.plsholdprompt));
01077    ast_copy_string(targs.statusprompt, f->statusprompt, sizeof(targs.statusprompt));
01078    ast_copy_string(targs.sorryprompt, f->sorryprompt, sizeof(targs.sorryprompt));
01079    /* Copy the numbers we're going to use into another list in case the master list should get modified 
01080       (and locked) while we're trying to do a follow-me */
01081    AST_LIST_HEAD_INIT_NOLOCK(&targs.cnumbers);
01082    AST_LIST_TRAVERSE(&f->numbers, nm, entry) {
01083       newnm = create_followme_number(nm->number, nm->timeout, nm->order);
01084       AST_LIST_INSERT_TAIL(&targs.cnumbers, newnm, entry);
01085    }
01086    ast_mutex_unlock(&f->lock);
01087 
01088    /* Answer the call */
01089    if (chan->_state != AST_STATE_UP) {
01090       ast_answer(chan);
01091    }
01092 
01093    if (ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_STATUSMSG)) 
01094       ast_stream_and_wait(chan, targs.statusprompt, "");
01095 
01096    snprintf(namerecloc,sizeof(namerecloc),"%s/followme.%s",ast_config_AST_SPOOL_DIR,chan->uniqueid);
01097    duration = 5;
01098 
01099    if (ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_RECORDNAME)) 
01100       if (ast_play_and_record(chan, "vm-rec-name", namerecloc, 5, "sln", &duration, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL) < 0)
01101          goto outrun;
01102 
01103    if (!ast_fileexists(namerecloc, NULL, chan->language))
01104       ast_copy_string(namerecloc, "", sizeof(namerecloc));
01105    if (!ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_DISABLEHOLDPROMPT)) {
01106       if (ast_streamfile(chan, targs.plsholdprompt, chan->language))
01107          goto outrun;
01108       if (ast_waitstream(chan, "") < 0)
01109          goto outrun;
01110    }
01111    ast_moh_start(chan, S_OR(targs.mohclass, NULL), NULL);
01112 
01113    targs.status = 0;
01114    targs.chan = chan;
01115    ast_copy_string(targs.namerecloc, namerecloc, sizeof(targs.namerecloc));
01116 
01117    findmeexec(&targs);
01118 
01119    while ((nm = AST_LIST_REMOVE_HEAD(&targs.cnumbers, entry)))
01120       ast_free(nm);
01121 
01122    if (!ast_strlen_zero(namerecloc))
01123       unlink(namerecloc);
01124 
01125    if (targs.status != 100) {
01126       ast_moh_stop(chan);
01127       if (ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_UNREACHABLEMSG)) 
01128          ast_stream_and_wait(chan, targs.sorryprompt, "");
01129       res = 0;
01130    } else {
01131       caller = chan;
01132       outbound = targs.outbound;
01133       /* Bridge the two channels. */
01134 
01135       memset(&config, 0, sizeof(config));
01136       ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
01137       ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
01138       ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
01139       config.end_bridge_callback = end_bridge_callback;
01140       config.end_bridge_callback_data = chan;
01141       config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
01142 
01143       ast_moh_stop(caller);
01144       /* Be sure no generators are left on it */
01145       ast_deactivate_generator(caller);
01146       /* Make sure channels are compatible */
01147       res = ast_channel_make_compatible(caller, outbound);
01148       if (res < 0) {
01149          ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", caller->name, outbound->name);
01150          ast_hangup(outbound);
01151          goto outrun;
01152       }
01153       res = ast_bridge_call(caller, outbound, &config);
01154       if (outbound)
01155          ast_hangup(outbound);
01156    }
01157 
01158    outrun:
01159 
01160    if (f->realtime) {
01161       /* Not in list */
01162       free_numbers(f);
01163       ast_free(f);
01164    }
01165 
01166    return res;
01167 }

static void clear_caller ( struct findme_user *  tmpuser  )  [static]

Definition at line 473 of file app_followme.c.

References ast_cdr_alloc(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_init(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_hangup(), ast_log(), ast_channel::cdr, findme_user::dialarg, ast_channel::hangupcause, LOG_WARNING, findme_user::ochan, and findme_user::state.

Referenced by clear_calling_tree(), and findmeexec().

00474 {
00475    struct ast_channel *outbound;
00476 
00477    if (tmpuser && tmpuser->ochan && tmpuser->state >= 0) {
00478       outbound = tmpuser->ochan;
00479       if (!outbound->cdr) {
00480          outbound->cdr = ast_cdr_alloc();
00481          if (outbound->cdr)
00482             ast_cdr_init(outbound->cdr, outbound);
00483       }
00484       if (outbound->cdr) {
00485          char tmp[256];
00486 
00487          snprintf(tmp, sizeof(tmp), "%s/%s", "Local", tmpuser->dialarg);
00488          ast_cdr_setapp(outbound->cdr, "FollowMe", tmp);
00489          ast_cdr_update(outbound);
00490          ast_cdr_start(outbound->cdr);
00491          ast_cdr_end(outbound->cdr);
00492          /* If the cause wasn't handled properly */
00493          if (ast_cdr_disposition(outbound->cdr, outbound->hangupcause))
00494             ast_cdr_failed(outbound->cdr);
00495       } else
00496          ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
00497       ast_hangup(tmpuser->ochan);
00498    }
00499 
00500 }

static void clear_calling_tree ( struct findme_user_listptr *  findme_user_list  )  [static]

Definition at line 502 of file app_followme.c.

References AST_LIST_TRAVERSE, clear_caller(), and findme_user::cleared.

Referenced by wait_for_winner().

00503 {
00504    struct findme_user *tmpuser;
00505 
00506    AST_LIST_TRAVERSE(findme_user_list, tmpuser, entry) {
00507       clear_caller(tmpuser);
00508       tmpuser->cleared = 1;
00509    }
00510 }

static struct number* create_followme_number ( const char *  number,
int  timeout,
int  numorder 
) [static, read]

Add a new number.

Definition at line 282 of file app_followme.c.

References ast_calloc, ast_copy_string(), ast_debug, ast_strdupa, number::number, number::order, and number::timeout.

Referenced by app_exec(), find_realtime(), and reload_followme().

00283 {
00284    struct number *cur;
00285    char *buf = ast_strdupa(number);
00286    char *tmp;
00287 
00288    if (!(cur = ast_calloc(1, sizeof(*cur))))
00289       return NULL;
00290 
00291    cur->timeout = timeout;
00292    if ((tmp = strchr(buf, ',')))
00293       *tmp = '\0';
00294    ast_copy_string(cur->number, buf, sizeof(cur->number));
00295    cur->order = numorder;
00296    ast_debug(1, "Created a number, %s, order of , %d, with a timeout of %ld.\n", cur->number, cur->order, cur->timeout);
00297 
00298    return cur;
00299 }

static void end_bridge_callback ( void *  data  )  [static]

Definition at line 985 of file app_followme.c.

References ast_cdr::answer, ast_channel_lock, ast_channel_unlock, ast_channel::cdr, pbx_builtin_setvar_helper(), and ast_cdr::start.

Referenced by app_exec().

00986 {
00987    char buf[80];
00988    time_t end;
00989    struct ast_channel *chan = data;
00990 
00991    time(&end);
00992 
00993    ast_channel_lock(chan);
00994    if (chan->cdr->answer.tv_sec) {
00995       snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->answer.tv_sec);
00996       pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
00997    }
00998 
00999    if (chan->cdr->start.tv_sec) {
01000       snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->start.tv_sec);
01001       pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
01002    }
01003    ast_channel_unlock(chan);
01004 }

static void end_bridge_callback_data_fixup ( struct ast_bridge_config *  bconfig,
struct ast_channel *  originator,
struct ast_channel *  terminator 
) [static]

Definition at line 1006 of file app_followme.c.

References ast_bridge_config::end_bridge_callback_data.

Referenced by app_exec().

01007 {
01008    bconfig->end_bridge_callback_data = originator;
01009 }

static struct call_followme* find_realtime ( const char *  name  )  [static, read]

Definition at line 925 of file app_followme.c.

References alloc_profile(), ast_category_browse(), ast_config_destroy(), ast_false(), ast_free, AST_LIST_INSERT_TAIL, ast_load_realtime(), ast_load_realtime_multientry(), ast_mutex_destroy, ast_str_buffer(), ast_str_create(), ast_str_set(), ast_variable_retrieve(), ast_variables_destroy(), create_followme_number(), ast_variable::next, profile_set_param(), SENTINEL, str, number::timeout, and var.

Referenced by app_exec().

00926 {
00927    struct ast_variable *var = ast_load_realtime("followme", "name", name, SENTINEL), *v;
00928    struct ast_config *cfg;
00929    const char *catg;
00930    struct call_followme *new;
00931    struct ast_str *str = ast_str_create(16);
00932 
00933    if (!var) {
00934       return NULL;
00935    }
00936 
00937    if (!(new = alloc_profile(name))) {
00938       return NULL;
00939    }
00940 
00941    for (v = var; v; v = v->next) {
00942       if (!strcasecmp(v->name, "active")) {
00943          if (ast_false(v->value)) {
00944             ast_mutex_destroy(&new->lock);
00945             ast_free(new);
00946             return NULL;
00947          }
00948       } else {
00949          profile_set_param(new, v->name, v->value, 0, 0);
00950       }
00951    }
00952 
00953    ast_variables_destroy(var);
00954    new->realtime = 1;
00955 
00956    /* Load numbers */
00957    if (!(cfg = ast_load_realtime_multientry("followme_numbers", "ordinal LIKE", "%", "name", name, SENTINEL))) {
00958       ast_mutex_destroy(&new->lock);
00959       ast_free(new);
00960       return NULL;
00961    }
00962 
00963    for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
00964       const char *numstr, *timeoutstr, *ordstr;
00965       int timeout;
00966       struct number *cur;
00967       if (!(numstr = ast_variable_retrieve(cfg, catg, "phonenumber"))) {
00968          continue;
00969       }
00970       if (!(timeoutstr = ast_variable_retrieve(cfg, catg, "timeout")) || sscanf(timeoutstr, "%30d", &timeout) != 1 || timeout < 1) {
00971          timeout = 25;
00972       }
00973       /* This one has to exist; it was part of the query */
00974       ordstr = ast_variable_retrieve(cfg, catg, "ordinal");
00975       ast_str_set(&str, 0, "%s", numstr);
00976       if ((cur = create_followme_number(ast_str_buffer(str), timeout, atoi(ordstr)))) {
00977          AST_LIST_INSERT_TAIL(&new->numbers, cur, entry);
00978       }
00979    }
00980    ast_config_destroy(cfg);
00981 
00982    return new;
00983 }

static void findmeexec ( struct fm_args *  tpargs  )  [static]

Definition at line 782 of file app_followme.c.

References ast_channel::accountcode, accountcode, ast_best_codec(), ast_call(), ast_calloc, ast_cause2str(), ast_cdr_alloc(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_init(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_check_hangup(), ast_copy_string(), ast_debug, ast_free, ast_hangup(), AST_LIST_EMPTY, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_log(), ast_request(), ast_set_callerid(), ast_strdupa, ast_string_field_set, ast_verb, ast_channel::caller, ast_channel::cdr, fm_args::chan, clear_caller(), findme_user::cleared, fm_args::cnumbers, fm_args::context, findme_user::dialarg, ast_channel::hangupcause, ast_party_caller::id, ast_channel::language, language, LOG_ERROR, LOG_WARNING, ast_channel::musicclass, musicclass, ast_party_id::name, fm_args::namerecloc, ast_channel::nativeformats, fm_args::nextindp, ast_party_id::number, number::number, findme_user::ochan, number::order, fm_args::outbound, S_COR, findme_user::state, fm_args::status, ast_party_name::str, ast_party_number::str, fm_args::takecall, number::timeout, ast_party_name::valid, ast_party_number::valid, and wait_for_winner().

Referenced by app_exec().

00783 {
00784    struct number *nm;
00785    struct ast_channel *outbound;
00786    struct ast_channel *caller;
00787    struct ast_channel *winner = NULL;
00788    char dialarg[512];
00789    int dg, idx;
00790    char *rest, *number;
00791    struct findme_user *tmpuser;
00792    struct findme_user *fmuser;
00793    struct findme_user *headuser;
00794    struct findme_user_listptr *findme_user_list;
00795    int status;
00796 
00797    findme_user_list = ast_calloc(1, sizeof(*findme_user_list));
00798    AST_LIST_HEAD_INIT_NOLOCK(findme_user_list);
00799 
00800    /* We're going to figure out what the longest possible string of digits to collect is */
00801    ynlongest = 0;
00802    if (strlen(tpargs->takecall) > ynlongest)
00803       ynlongest = strlen(tpargs->takecall);
00804    if (strlen(tpargs->nextindp) > ynlongest)
00805       ynlongest = strlen(tpargs->nextindp);
00806 
00807    idx = 1;
00808    caller = tpargs->chan;
00809    AST_LIST_TRAVERSE(&tpargs->cnumbers, nm, entry)
00810       if (nm->order == idx)
00811          break;
00812 
00813    while (nm) {
00814 
00815       ast_debug(2, "Number %s timeout %ld\n", nm->number,nm->timeout);
00816 
00817       number = ast_strdupa(nm->number);
00818       ast_debug(3, "examining %s\n", number);
00819       do {
00820          rest = strchr(number, '&');
00821          if (rest) {
00822             *rest = 0;
00823             rest++;
00824          }
00825 
00826          if (!strcmp(tpargs->context, ""))
00827             snprintf(dialarg, sizeof(dialarg), "%s", number);
00828          else
00829             snprintf(dialarg, sizeof(dialarg), "%s@%s", number, tpargs->context);
00830 
00831          tmpuser = ast_calloc(1, sizeof(*tmpuser));
00832          if (!tmpuser) {
00833             ast_log(LOG_WARNING, "Out of memory!\n");
00834             ast_free(findme_user_list);
00835             return;
00836          }
00837 
00838          outbound = ast_request("Local", ast_best_codec(caller->nativeformats), caller, dialarg, &dg);
00839          if (outbound) {
00840             ast_set_callerid(outbound,
00841                S_COR(caller->caller.id.number.valid, caller->caller.id.number.str, NULL),
00842                S_COR(caller->caller.id.name.valid, caller->caller.id.name.str, NULL),
00843                S_COR(caller->caller.id.number.valid, caller->caller.id.number.str, NULL));
00844             ast_channel_inherit_variables(tpargs->chan, outbound);
00845             ast_channel_datastore_inherit(tpargs->chan, outbound);
00846             ast_string_field_set(outbound, language, tpargs->chan->language);
00847             ast_string_field_set(outbound, accountcode, tpargs->chan->accountcode);
00848             ast_string_field_set(outbound, musicclass, tpargs->chan->musicclass);
00849             ast_verb(3, "calling %s\n", dialarg);
00850             if (!ast_call(outbound,dialarg,0)) {
00851                tmpuser->ochan = outbound;
00852                tmpuser->state = 0;
00853                tmpuser->cleared = 0;
00854                ast_copy_string(tmpuser->dialarg, dialarg, sizeof(dialarg));
00855                AST_LIST_INSERT_TAIL(findme_user_list, tmpuser, entry);
00856             } else {
00857                ast_verb(3, "couldn't reach at this number.\n"); 
00858                if (outbound) {
00859                   if (!outbound->cdr) 
00860                      outbound->cdr = ast_cdr_alloc();
00861                   if (outbound->cdr) {
00862                      char tmp[256];
00863 
00864                      ast_cdr_init(outbound->cdr, outbound);
00865                      snprintf(tmp, sizeof(tmp), "%s/%s", "Local", dialarg);
00866                      ast_cdr_setapp(outbound->cdr, "FollowMe", tmp);
00867                      ast_cdr_update(outbound);
00868                      ast_cdr_start(outbound->cdr);
00869                      ast_cdr_end(outbound->cdr);
00870                      /* If the cause wasn't handled properly */
00871                      if (ast_cdr_disposition(outbound->cdr,outbound->hangupcause))
00872                         ast_cdr_failed(outbound->cdr);
00873                   } else {
00874                      ast_log(LOG_ERROR, "Unable to create Call Detail Record\n");
00875                      ast_hangup(outbound);
00876                      outbound = NULL;
00877                   }
00878                }
00879             }
00880          } else 
00881             ast_log(LOG_WARNING, "Unable to allocate a channel for Local/%s cause: %s\n", dialarg, ast_cause2str(dg));
00882 
00883          number = rest;
00884       } while (number);
00885 
00886       status = 0;
00887       if (!AST_LIST_EMPTY(findme_user_list))
00888          winner = wait_for_winner(findme_user_list, nm, caller, tpargs->namerecloc, &status, tpargs);
00889 
00890       while ((fmuser = AST_LIST_REMOVE_HEAD(findme_user_list, entry))) {
00891          if (!fmuser->cleared && fmuser->ochan != winner)
00892             clear_caller(fmuser);
00893          ast_free(fmuser);
00894       }
00895 
00896       fmuser = NULL;
00897       tmpuser = NULL;
00898       headuser = NULL;
00899       if (winner)
00900          break;
00901 
00902       if (!caller || ast_check_hangup(caller)) {
00903          tpargs->status = 1;
00904          ast_free(findme_user_list);
00905          return;
00906       }
00907 
00908       idx++;
00909       AST_LIST_TRAVERSE(&tpargs->cnumbers, nm, entry) {
00910          if (nm->order == idx)
00911             break;
00912       }
00913    }
00914    ast_free(findme_user_list);
00915    if (!winner) 
00916       tpargs->status = 1;
00917    else {
00918       tpargs->status = 100;
00919       tpargs->outbound = winner;
00920    }
00921 
00922    return;
00923 }

static void free_numbers ( struct call_followme *  f  )  [static]

Definition at line 193 of file app_followme.c.

References ast_free, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_REMOVE_HEAD, call_followme::blnumbers, call_followme::numbers, and call_followme::wlnumbers.

Referenced by app_exec(), reload_followme(), and unload_module().

00194 {
00195    /* Free numbers attached to the profile */
00196    struct number *prev;
00197 
00198    while ((prev = AST_LIST_REMOVE_HEAD(&f->numbers, entry)))
00199       /* Free the number */
00200       ast_free(prev);
00201    AST_LIST_HEAD_INIT_NOLOCK(&f->numbers);
00202 
00203    while ((prev = AST_LIST_REMOVE_HEAD(&f->blnumbers, entry)))
00204       /* Free the blacklisted number */
00205       ast_free(prev);
00206    AST_LIST_HEAD_INIT_NOLOCK(&f->blnumbers);
00207 
00208    while ((prev = AST_LIST_REMOVE_HEAD(&f->wlnumbers, entry)))
00209       /* Free the whitelisted number */
00210       ast_free(prev);
00211    AST_LIST_HEAD_INIT_NOLOCK(&f->wlnumbers);
00212 }

static void init_profile ( struct call_followme *  f  )  [static]

Definition at line 241 of file app_followme.c.

References call_followme::active, ast_copy_string(), and call_followme::moh.

Referenced by reload_followme().

00242 {
00243    f->active = 1;
00244    ast_copy_string(f->moh, defaultmoh, sizeof(f->moh));
00245 }

static int load_module ( void   )  [static]

Definition at line 1187 of file app_followme.c.

References app_exec(), AST_MODULE_LOAD_DECLINE, ast_register_application_xml, and reload_followme().

01188 {
01189    if(!reload_followme(0))
01190       return AST_MODULE_LOAD_DECLINE;
01191 
01192    return ast_register_application_xml(app, app_exec);
01193 }

static void profile_set_param ( struct call_followme *  f,
const char *  param,
const char *  val,
int  linenum,
int  failunknown 
) [static]

Set parameter in profile from configuration file.

Definition at line 250 of file app_followme.c.

References ast_copy_string(), ast_log(), call_followme::callfromprompt, call_followme::context, LOG_WARNING, call_followme::moh, call_followme::name, call_followme::nextindp, call_followme::norecordingprompt, call_followme::optionsprompt, call_followme::plsholdprompt, call_followme::sorryprompt, call_followme::statusprompt, and call_followme::takecall.

Referenced by find_realtime(), and reload_followme().

00251 {
00252 
00253    if (!strcasecmp(param, "musicclass") || !strcasecmp(param, "musiconhold") || !strcasecmp(param, "music")) 
00254       ast_copy_string(f->moh, val, sizeof(f->moh));
00255    else if (!strcasecmp(param, "context")) 
00256       ast_copy_string(f->context, val, sizeof(f->context));
00257    else if (!strcasecmp(param, "takecall"))
00258       ast_copy_string(f->takecall, val, sizeof(f->takecall));
00259    else if (!strcasecmp(param, "declinecall"))
00260       ast_copy_string(f->nextindp, val, sizeof(f->nextindp));
00261    else if (!strcasecmp(param, "call-from-prompt") || !strcasecmp(param, "call_from_prompt"))
00262       ast_copy_string(f->callfromprompt, val, sizeof(f->callfromprompt));
00263    else if (!strcasecmp(param, "followme-norecording-prompt") || !strcasecmp(param, "norecording_prompt")) 
00264       ast_copy_string(f->norecordingprompt, val, sizeof(f->norecordingprompt));
00265    else if (!strcasecmp(param, "followme-options-prompt") || !strcasecmp(param, "options_prompt")) 
00266       ast_copy_string(f->optionsprompt, val, sizeof(f->optionsprompt));
00267    else if (!strcasecmp(param, "followme-pls-hold-prompt") || !strcasecmp(param, "pls_hold_prompt"))
00268       ast_copy_string(f->plsholdprompt, val, sizeof(f->plsholdprompt));
00269    else if (!strcasecmp(param, "followme-status-prompt") || !strcasecmp(param, "status_prompt")) 
00270       ast_copy_string(f->statusprompt, val, sizeof(f->statusprompt));
00271    else if (!strcasecmp(param, "followme-sorry-prompt") || !strcasecmp(param, "sorry_prompt")) 
00272       ast_copy_string(f->sorryprompt, val, sizeof(f->sorryprompt));
00273    else if (failunknown) {
00274       if (linenum >= 0)
00275          ast_log(LOG_WARNING, "Unknown keyword in profile '%s': %s at line %d of followme.conf\n", f->name, param, linenum);
00276       else
00277          ast_log(LOG_WARNING, "Unknown keyword in profile '%s': %s\n", f->name, param);
00278    }
00279 }

static int reload ( void   )  [static]

Definition at line 1195 of file app_followme.c.

References reload_followme().

01196 {
01197    reload_followme(1);
01198 
01199    return 0;
01200 }

static int reload_followme ( int  reload  )  [static]

Reload followme application module.

Definition at line 302 of file app_followme.c.

References call_followme::active, alloc_profile(), ast_category_browse(), ast_config_destroy(), ast_config_load, ast_copy_string(), ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_mutex_lock, ast_mutex_unlock, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdupa, ast_strlen_zero(), ast_variable_browse(), ast_variable_retrieve(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, create_followme_number(), f, free_numbers(), init_profile(), ast_variable::lineno, call_followme::lock, LOG_ERROR, LOG_WARNING, ast_variable::name, call_followme::name, ast_variable::next, call_followme::numbers, profile_set_param(), number::timeout, ast_variable::value, and var.

Referenced by load_module(), and reload().

00303 {
00304    struct call_followme *f;
00305    struct ast_config *cfg;
00306    char *cat = NULL, *tmp;
00307    struct ast_variable *var;
00308    struct number *cur, *nm;
00309    char numberstr[90];
00310    int timeout;
00311    char *timeoutstr;
00312    int numorder;
00313    const char *takecallstr;
00314    const char *declinecallstr;
00315    const char *tmpstr;
00316    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
00317 
00318    if (!(cfg = ast_config_load("followme.conf", config_flags))) {
00319       ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
00320       return 0;
00321    } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
00322       return 0;
00323    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
00324       ast_log(LOG_ERROR, "Config file followme.conf is in an invalid format.  Aborting.\n");
00325       return 0;
00326    }
00327 
00328    AST_RWLIST_WRLOCK(&followmes);
00329 
00330    /* Reset Global Var Values */
00331    featuredigittimeout = 5000;
00332 
00333    /* Mark all profiles as inactive for the moment */
00334    AST_RWLIST_TRAVERSE(&followmes, f, entry) {
00335       f->active = 0;
00336    }
00337 
00338    featuredigittostr = ast_variable_retrieve(cfg, "general", "featuredigittimeout");
00339 
00340    if (!ast_strlen_zero(featuredigittostr)) {
00341       if (!sscanf(featuredigittostr, "%30d", &featuredigittimeout))
00342          featuredigittimeout = 5000;
00343    }
00344 
00345    if ((takecallstr = ast_variable_retrieve(cfg, "general", "takecall")) && !ast_strlen_zero(takecallstr)) {
00346       ast_copy_string(takecall, takecallstr, sizeof(takecall));
00347    }
00348 
00349    if ((declinecallstr = ast_variable_retrieve(cfg, "general", "declinecall")) && !ast_strlen_zero(declinecallstr)) {
00350       ast_copy_string(nextindp, declinecallstr, sizeof(nextindp));
00351    }
00352 
00353    if ((tmpstr = ast_variable_retrieve(cfg, "general", "call-from-prompt")) && !ast_strlen_zero(tmpstr)) {
00354       ast_copy_string(callfromprompt, tmpstr, sizeof(callfromprompt));
00355    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "call_from_prompt")) && !ast_strlen_zero(tmpstr)) {
00356       ast_copy_string(callfromprompt, tmpstr, sizeof(callfromprompt));
00357    }
00358 
00359    if ((tmpstr = ast_variable_retrieve(cfg, "general", "norecording-prompt")) && !ast_strlen_zero(tmpstr)) {
00360       ast_copy_string(norecordingprompt, tmpstr, sizeof(norecordingprompt));
00361    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "norecording_prompt")) && !ast_strlen_zero(tmpstr)) {
00362       ast_copy_string(norecordingprompt, tmpstr, sizeof(norecordingprompt));
00363    }
00364 
00365 
00366    if ((tmpstr = ast_variable_retrieve(cfg, "general", "options-prompt")) && !ast_strlen_zero(tmpstr)) {
00367       ast_copy_string(optionsprompt, tmpstr, sizeof(optionsprompt));
00368    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "options_prompt")) && !ast_strlen_zero(tmpstr)) {
00369       ast_copy_string(optionsprompt, tmpstr, sizeof(optionsprompt));
00370    }
00371 
00372    if ((tmpstr = ast_variable_retrieve(cfg, "general", "pls-hold-prompt")) && !ast_strlen_zero(tmpstr)) {
00373       ast_copy_string(plsholdprompt, tmpstr, sizeof(plsholdprompt));
00374    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "pls_hold_prompt")) && !ast_strlen_zero(tmpstr)) {
00375       ast_copy_string(plsholdprompt, tmpstr, sizeof(plsholdprompt));
00376    }
00377 
00378    if ((tmpstr = ast_variable_retrieve(cfg, "general", "status-prompt")) && !ast_strlen_zero(tmpstr)) {
00379       ast_copy_string(statusprompt, tmpstr, sizeof(statusprompt));
00380    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "status_prompt")) && !ast_strlen_zero(tmpstr)) {
00381       ast_copy_string(statusprompt, tmpstr, sizeof(statusprompt));
00382    }
00383 
00384    if ((tmpstr = ast_variable_retrieve(cfg, "general", "sorry-prompt")) && !ast_strlen_zero(tmpstr)) {
00385       ast_copy_string(sorryprompt, tmpstr, sizeof(sorryprompt));
00386    } else if ((tmpstr = ast_variable_retrieve(cfg, "general", "sorry_prompt")) && !ast_strlen_zero(tmpstr)) {
00387       ast_copy_string(sorryprompt, tmpstr, sizeof(sorryprompt));
00388    }
00389 
00390    /* Chug through config file */
00391    while ((cat = ast_category_browse(cfg, cat))) {
00392       int new = 0;
00393 
00394       if (!strcasecmp(cat, "general"))
00395          continue;
00396 
00397       /* Look for an existing one */
00398       AST_LIST_TRAVERSE(&followmes, f, entry) {
00399          if (!strcasecmp(f->name, cat))
00400             break;
00401       }
00402 
00403       ast_debug(1, "New profile %s.\n", cat);
00404 
00405       if (!f) {
00406          /* Make one then */
00407          f = alloc_profile(cat);
00408          new = 1;
00409       }
00410 
00411       /* Totally fail if we fail to find/create an entry */
00412       if (!f)
00413          continue;
00414 
00415       if (!new)
00416          ast_mutex_lock(&f->lock);
00417       /* Re-initialize the profile */
00418       init_profile(f);
00419       free_numbers(f);
00420       var = ast_variable_browse(cfg, cat);
00421       while (var) {
00422          if (!strcasecmp(var->name, "number")) {
00423             int idx = 0;
00424 
00425             /* Add a new number */
00426             ast_copy_string(numberstr, var->value, sizeof(numberstr));
00427             if ((tmp = strchr(numberstr, ','))) {
00428                *tmp++ = '\0';
00429                timeoutstr = ast_strdupa(tmp);
00430                if ((tmp = strchr(timeoutstr, ','))) {
00431                   *tmp++ = '\0';
00432                   numorder = atoi(tmp);
00433                   if (numorder < 0)
00434                      numorder = 0;
00435                } else 
00436                   numorder = 0;
00437                timeout = atoi(timeoutstr);
00438                if (timeout < 0) 
00439                   timeout = 25;
00440             } else {
00441                timeout = 25;
00442                numorder = 0;
00443             }
00444 
00445             if (!numorder) {
00446                idx = 1;
00447                AST_LIST_TRAVERSE(&f->numbers, nm, entry) 
00448                   idx++;
00449                numorder = idx;
00450             }
00451             cur = create_followme_number(numberstr, timeout, numorder);
00452             AST_LIST_INSERT_TAIL(&f->numbers, cur, entry);
00453          } else {
00454             profile_set_param(f, var->name, var->value, var->lineno, 1);
00455             ast_debug(2, "Logging parameter %s with value %s from lineno %d\n", var->name, var->value, var->lineno);
00456          }
00457          var = var->next;
00458       } /* End while(var) loop */
00459 
00460       if (!new) 
00461          ast_mutex_unlock(&f->lock);
00462       else
00463          AST_RWLIST_INSERT_HEAD(&followmes, f, entry);
00464    }
00465 
00466    ast_config_destroy(cfg);
00467 
00468    AST_RWLIST_UNLOCK(&followmes);
00469 
00470    return 1;
00471 }

static int unload_module ( void   )  [static]

Definition at line 1169 of file app_followme.c.

References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_unregister_application(), f, and free_numbers().

01170 {
01171    struct call_followme *f;
01172 
01173    ast_unregister_application(app);
01174 
01175    /* Free Memory. Yeah! I'm free! */
01176    AST_RWLIST_WRLOCK(&followmes);
01177    while ((f = AST_RWLIST_REMOVE_HEAD(&followmes, entry))) {
01178       free_numbers(f);
01179       ast_free(f);
01180    }
01181 
01182    AST_RWLIST_UNLOCK(&followmes);
01183 
01184    return 0;
01185 }

static struct ast_channel* wait_for_winner ( struct findme_user_listptr *  findme_user_list,
struct number *  nm,
struct ast_channel *  caller,
char *  namerecloc,
int *  status,
struct fm_args *  tpargs 
) [static, read]

Definition at line 514 of file app_followme.c.

References AST_CAUSE_NORMAL_CLEARING, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_hangup(), AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_log(), ast_read(), ast_sched_runq(), ast_sched_wait(), ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_verb, ast_waitfor_n(), fm_args::callfromprompt, clear_calling_tree(), ast_frame::data, findme_user::digts, f, ast_frame::frametype, ast_channel::hangupcause, ast_frame_subclass::integer, ast_channel::language, LOG_NOTICE, LOG_WARNING, ast_channel::name, fm_args::nextindp, fm_args::norecordingprompt, findme_user::ochan, fm_args::optionsprompt, ast_channel::sched, findme_user::state, ast_channel::stream, ast_frame::subclass, fm_args::takecall, number::timeout, ast_channel::timingfunc, ast_frame::uint32, findme_user::yn, and findme_user::ynidx.

Referenced by findmeexec().

00515 {
00516    struct ast_channel *watchers[256];
00517    int pos;
00518    struct ast_channel *winner;
00519    struct ast_frame *f;
00520    int ctstatus = 0;
00521    int dg;
00522    struct findme_user *tmpuser;
00523    int to = 0;
00524    int livechannels = 0;
00525    int tmpto;
00526    long totalwait = 0, wtd = 0, towas = 0;
00527    char *callfromname;
00528    char *pressbuttonname;
00529 
00530    /* ------------ wait_for_winner_channel start --------------- */ 
00531 
00532    callfromname = ast_strdupa(tpargs->callfromprompt);
00533    pressbuttonname = ast_strdupa(tpargs->optionsprompt);
00534 
00535    if (AST_LIST_EMPTY(findme_user_list)) {
00536       ast_verb(3, "couldn't reach at this number.\n");
00537       return NULL;
00538    }
00539 
00540    if (!caller) {
00541       ast_verb(3, "Original caller hungup. Cleanup.\n");
00542       clear_calling_tree(findme_user_list);
00543       return NULL;
00544    }
00545 
00546    totalwait = nm->timeout * 1000;
00547 
00548    while (!ctstatus) {
00549       to = 1000;
00550       pos = 1; 
00551       livechannels = 0;
00552       watchers[0] = caller;
00553 
00554       dg = 0;
00555       winner = NULL;
00556       AST_LIST_TRAVERSE(findme_user_list, tmpuser, entry) {
00557          if (tmpuser->state >= 0 && tmpuser->ochan) {
00558             if (tmpuser->state == 3) 
00559                tmpuser->digts += (towas - wtd);
00560             if (tmpuser->digts && (tmpuser->digts > featuredigittimeout)) {
00561                ast_verb(3, "We've been waiting for digits longer than we should have.\n");
00562                if (!ast_strlen_zero(namerecloc)) {
00563                   tmpuser->state = 1;
00564                   tmpuser->digts = 0;
00565                   if (!ast_streamfile(tmpuser->ochan, callfromname, tmpuser->ochan->language)) {
00566                      ast_sched_runq(tmpuser->ochan->sched);
00567                   } else {
00568                      ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
00569                      return NULL;
00570                   }
00571                } else {
00572                   tmpuser->state = 2;
00573                   tmpuser->digts = 0;
00574                   if (!ast_streamfile(tmpuser->ochan, tpargs->norecordingprompt, tmpuser->ochan->language))
00575                      ast_sched_runq(tmpuser->ochan->sched);
00576                   else {
00577                      ast_log(LOG_WARNING, "Unable to playback %s.\n", tpargs->norecordingprompt);
00578                      return NULL;
00579                   }
00580                }
00581             }
00582             if (tmpuser->ochan->stream) {
00583                ast_sched_runq(tmpuser->ochan->sched);
00584                tmpto = ast_sched_wait(tmpuser->ochan->sched);
00585                if (tmpto > 0 && tmpto < to)
00586                   to = tmpto;
00587                else if (tmpto < 0 && !tmpuser->ochan->timingfunc) {
00588                   ast_stopstream(tmpuser->ochan);
00589                   if (tmpuser->state == 1) {
00590                      ast_verb(3, "Playback of the call-from file appears to be done.\n");
00591                      if (!ast_streamfile(tmpuser->ochan, namerecloc, tmpuser->ochan->language)) {
00592                         tmpuser->state = 2;
00593                      } else {
00594                         ast_log(LOG_NOTICE, "Unable to playback %s. Maybe the caller didn't record their name?\n", namerecloc);
00595                         memset(tmpuser->yn, 0, sizeof(tmpuser->yn));
00596                         tmpuser->ynidx = 0;
00597                         if (!ast_streamfile(tmpuser->ochan, pressbuttonname, tmpuser->ochan->language))
00598                            tmpuser->state = 3;
00599                         else {
00600                            ast_log(LOG_WARNING, "Unable to playback %s.\n", pressbuttonname);
00601                            return NULL;
00602                         } 
00603                      }
00604                   } else if (tmpuser->state == 2) {
00605                      ast_verb(3, "Playback of name file appears to be done.\n");
00606                      memset(tmpuser->yn, 0, sizeof(tmpuser->yn));
00607                      tmpuser->ynidx = 0;
00608                      if (!ast_streamfile(tmpuser->ochan, pressbuttonname, tmpuser->ochan->language)) {
00609                         tmpuser->state = 3;
00610                      } else {
00611                         return NULL;
00612                      } 
00613                   } else if (tmpuser->state == 3) {
00614                      ast_verb(3, "Playback of the next step file appears to be done.\n");
00615                      tmpuser->digts = 0;
00616                   }
00617                }
00618             }
00619             watchers[pos++] = tmpuser->ochan;
00620             livechannels++;
00621          }
00622       }
00623 
00624       tmpto = to;
00625       if (to < 0) {
00626          to = 1000;
00627          tmpto = 1000;
00628       }
00629       towas = to;
00630       winner = ast_waitfor_n(watchers, pos, &to);
00631       tmpto -= to;
00632       totalwait -= tmpto;
00633       wtd = to;
00634       if (totalwait <= 0) {
00635          ast_verb(3, "We've hit our timeout for this step. Drop everyone and move on to the next one. %ld\n", totalwait);
00636          clear_calling_tree(findme_user_list);
00637          return NULL;
00638       }
00639       if (winner) {
00640          /* Need to find out which channel this is */
00641          dg = 0;
00642          while ((winner != watchers[dg]) && (dg < 256))
00643             dg++;
00644          AST_LIST_TRAVERSE(findme_user_list, tmpuser, entry)
00645             if (tmpuser->ochan == winner)
00646                break;
00647          f = ast_read(winner);
00648          if (f) {
00649             if (f->frametype == AST_FRAME_CONTROL) {
00650                switch (f->subclass.integer) {
00651                case AST_CONTROL_HANGUP:
00652                   ast_verb(3, "%s received a hangup frame.\n", winner->name);
00653                   if (f->data.uint32) {
00654                      winner->hangupcause = f->data.uint32;
00655                   }
00656                   if (dg == 0) {
00657                      ast_verb(3, "The calling channel hungup. Need to drop everyone else.\n");
00658                      clear_calling_tree(findme_user_list);
00659                      ctstatus = -1;
00660                   }
00661                   break;
00662                case AST_CONTROL_ANSWER:
00663                   ast_verb(3, "%s answered %s\n", winner->name, caller->name);
00664                   /* If call has been answered, then the eventual hangup is likely to be normal hangup */ 
00665                   winner->hangupcause = AST_CAUSE_NORMAL_CLEARING;
00666                   caller->hangupcause = AST_CAUSE_NORMAL_CLEARING;
00667                   ast_verb(3, "Starting playback of %s\n", callfromname);
00668                   if (dg > 0) {
00669                      if (!ast_strlen_zero(namerecloc)) {
00670                         if (!ast_streamfile(winner, callfromname, winner->language)) {
00671                            ast_sched_runq(winner->sched);
00672                            tmpuser->state = 1;
00673                         } else {
00674                            ast_log(LOG_WARNING, "Unable to playback %s.\n", callfromname);
00675                            ast_frfree(f);
00676                            return NULL;
00677                         }
00678                      } else {
00679                         tmpuser->state = 2;
00680                         if (!ast_streamfile(tmpuser->ochan, tpargs->norecordingprompt, tmpuser->ochan->language))
00681                            ast_sched_runq(tmpuser->ochan->sched);
00682                         else {
00683                            ast_log(LOG_WARNING, "Unable to playback %s.\n", tpargs->norecordingprompt);
00684                            ast_frfree(f);
00685                            return NULL;
00686                         }
00687                      }
00688                   }
00689                   break;
00690                case AST_CONTROL_BUSY:
00691                   ast_verb(3, "%s is busy\n", winner->name);
00692                   break;
00693                case AST_CONTROL_CONGESTION:
00694                   ast_verb(3, "%s is circuit-busy\n", winner->name);
00695                   break;
00696                case AST_CONTROL_RINGING:
00697                   ast_verb(3, "%s is ringing\n", winner->name);
00698                   break;
00699                case AST_CONTROL_PROGRESS:
00700                   ast_verb(3, "%s is making progress passing it to %s\n", winner->name, caller->name);
00701                   break;
00702                case AST_CONTROL_VIDUPDATE:
00703                   ast_verb(3, "%s requested a video update, passing it to %s\n", winner->name, caller->name);
00704                   break;
00705                case AST_CONTROL_SRCUPDATE:
00706                   ast_verb(3, "%s requested a source update, passing it to %s\n", winner->name, caller->name);
00707                   break;
00708                case AST_CONTROL_PROCEEDING:
00709                   ast_verb(3, "%s is proceeding passing it to %s\n", winner->name,caller->name);
00710                   break;
00711                case AST_CONTROL_HOLD:
00712                   ast_verb(3, "Call on %s placed on hold\n", winner->name);
00713                   break;
00714                case AST_CONTROL_UNHOLD:
00715                   ast_verb(3, "Call on %s left from hold\n", winner->name);
00716                   break;
00717                case AST_CONTROL_OFFHOOK:
00718                case AST_CONTROL_FLASH:
00719                   /* Ignore going off hook and flash */
00720                   break;
00721                case -1:
00722                   ast_verb(3, "%s stopped sounds\n", winner->name);
00723                   break;
00724                default:
00725                   ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
00726                   break;
00727                }
00728             } 
00729             if (tmpuser && tmpuser->state == 3 && f->frametype == AST_FRAME_DTMF) {
00730                if (winner->stream)
00731                   ast_stopstream(winner);
00732                tmpuser->digts = 0;
00733                ast_debug(1, "DTMF received: %c\n", (char) f->subclass.integer);
00734                tmpuser->yn[tmpuser->ynidx] = (char) f->subclass.integer;
00735                tmpuser->ynidx++;
00736                ast_debug(1, "DTMF string: %s\n", tmpuser->yn);
00737                if (tmpuser->ynidx >= ynlongest) {
00738                   ast_debug(1, "reached longest possible match - doing evals\n");
00739                   if (!strcmp(tmpuser->yn, tpargs->takecall)) {
00740                      ast_debug(1, "Match to take the call!\n");
00741                      ast_frfree(f);
00742                      return tmpuser->ochan;
00743                   }
00744                   if (!strcmp(tmpuser->yn, tpargs->nextindp)) {
00745                      ast_debug(1, "Next in dial plan step requested.\n");
00746                      *status = 1;
00747                      ast_frfree(f);
00748                      return NULL;
00749                   }
00750 
00751                }
00752             }
00753 
00754             ast_frfree(f);
00755          } else {
00756             if (winner) {
00757                ast_debug(1, "we didn't get a frame. hanging up. dg is %d\n",dg);                   
00758                if (!dg) {
00759                   clear_calling_tree(findme_user_list);
00760                   return NULL;
00761                } else {
00762                   tmpuser->state = -1;
00763                   ast_hangup(winner);  
00764                   livechannels--;
00765                   ast_debug(1, "live channels left %d\n", livechannels);
00766                   if (!livechannels) {
00767                      ast_verb(3, "no live channels left. exiting.\n");
00768                      return NULL;
00769                   }
00770                }
00771             }
00772          }
00773 
00774       } else
00775          ast_debug(1, "timed out waiting for action\n");
00776    }
00777 
00778    /* --- WAIT FOR WINNER NUMBER END! -----------*/
00779    return NULL;
00780 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Find-Me/Follow-Me Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 1206 of file app_followme.c.

char* app = "FollowMe" [static]

Definition at line 98 of file app_followme.c.

Definition at line 1206 of file app_followme.c.

char callfromprompt[PATH_MAX] = "followme/call-from" [static]

Definition at line 182 of file app_followme.c.

const char* defaultmoh = "default" [static]

Default Music-On-Hold Class

Definition at line 179 of file app_followme.c.

int featuredigittimeout = 5000 [static]

Feature Digit Timeout

Definition at line 178 of file app_followme.c.

const char* featuredigittostr [static]

Definition at line 177 of file app_followme.c.

struct ast_app_option followme_opts[128] = { [ 's' ] = { .flag = FOLLOWMEFLAG_STATUSMSG }, [ 'a' ] = { .flag = FOLLOWMEFLAG_RECORDNAME }, [ 'n' ] = { .flag = FOLLOWMEFLAG_UNREACHABLEMSG }, [ 'd' ] = { .flag = FOLLOWMEFLAG_DISABLEHOLDPROMPT },} [static]

Definition at line 173 of file app_followme.c.

Referenced by app_exec().

char nextindp[20] = "2" [static]

Definition at line 181 of file app_followme.c.

char norecordingprompt[PATH_MAX] = "followme/no-recording" [static]

Definition at line 183 of file app_followme.c.

char optionsprompt[PATH_MAX] = "followme/options" [static]

Definition at line 184 of file app_followme.c.

char plsholdprompt[PATH_MAX] = "followme/pls-hold-while-try" [static]

Definition at line 185 of file app_followme.c.

char sorryprompt[PATH_MAX] = "followme/sorry" [static]

Definition at line 187 of file app_followme.c.

char statusprompt[PATH_MAX] = "followme/status" [static]

Definition at line 186 of file app_followme.c.

char takecall[20] = "1" [static]

Definition at line 181 of file app_followme.c.

int ynlongest = 0 [static]

Definition at line 175 of file app_followme.c.


Generated on Sat Mar 26 11:10:14 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9