Minor clean up of app_followme.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@77773 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-07-30 16:02:01 +00:00
parent 3733874f49
commit 6e771511da

View File

@@ -162,7 +162,7 @@ static char statusprompt[PATH_MAX] = "followme/status";
static char sorryprompt[PATH_MAX] = "followme/sorry";
static AST_LIST_HEAD_STATIC(followmes, call_followme);
static AST_RWLIST_HEAD_STATIC(followmes, call_followme);
AST_LIST_HEAD_NOLOCK(findme_user_listptr, findme_user);
static void free_numbers(struct call_followme *f)
@@ -282,7 +282,6 @@ static int reload_followme(void)
char *cat = NULL, *tmp;
struct ast_variable *var;
struct number *cur, *nm;
int new, idx;
char numberstr[90];
int timeout;
char *timeoutstr;
@@ -291,21 +290,21 @@ static int reload_followme(void)
const char *declinecallstr;
const char *tmpstr;
cfg = ast_config_load("followme.conf");
if (!cfg) {
if (!(cfg = ast_config_load("followme.conf"))) {
ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
return 0;
}
AST_LIST_LOCK(&followmes);
AST_RWLIST_WRLOCK(&followmes);
/* Reset Global Var Values */
featuredigittimeout = 5000;
/* Mark all profiles as inactive for the moment */
AST_LIST_TRAVERSE(&followmes, f, entry) {
AST_RWLIST_TRAVERSE(&followmes, f, entry) {
f->active = 0;
}
featuredigittostr = ast_variable_retrieve(cfg, "general", "featuredigittimeout");
if (!ast_strlen_zero(featuredigittostr)) {
@@ -347,23 +346,29 @@ static int reload_followme(void)
/* Chug through config file */
while ((cat = ast_category_browse(cfg, cat))) {
int new = 0;
if (!strcasecmp(cat, "general"))
continue;
/* Define a new profile */
/* Look for an existing one */
AST_LIST_TRAVERSE(&followmes, f, entry) {
if (!strcasecmp(f->name, cat))
break;
}
ast_debug(1, "New profile %s.\n", cat);
if (!f) {
/* Make one then */
f = alloc_profile(cat);
new = 1;
} else
new = 0;
}
/* Totally fail if we fail to find/create an entry */
if (!f)
continue;
if (f) {
if (!new)
ast_mutex_lock(&f->lock);
/* Re-initialize the profile */
@@ -372,15 +377,15 @@ static int reload_followme(void)
var = ast_variable_browse(cfg, cat);
while(var) {
if (!strcasecmp(var->name, "number")) {
int idx = 0;
/* Add a new number */
ast_copy_string(numberstr, var->value, sizeof(numberstr));
if ((tmp = strchr(numberstr, ','))) {
*tmp = '\0';
tmp++;
*tmp++ = '\0';
timeoutstr = ast_strdupa(tmp);
if ((tmp = strchr(timeoutstr, ','))) {
*tmp = '\0';
tmp++;
*tmp++ = '\0';
numorder = atoi(tmp);
if (numorder < 0)
numorder = 0;
@@ -412,12 +417,12 @@ static int reload_followme(void)
if (!new)
ast_mutex_unlock(&f->lock);
else
AST_LIST_INSERT_HEAD(&followmes, f, entry);
}
AST_RWLIST_INSERT_HEAD(&followmes, f, entry);
}
ast_config_destroy(cfg);
AST_LIST_UNLOCK(&followmes);
AST_RWLIST_UNLOCK(&followmes);
return 1;
}
@@ -470,13 +475,13 @@ static struct ast_channel *wait_for_winner(struct findme_user_listptr *findme_us
int pos;
struct ast_channel *winner;
struct ast_frame *f;
int ctstatus;
int ctstatus = 0;
int dg;
struct findme_user *tmpuser;
int to = 0;
int livechannels = 0;
int tmpto;
long totalwait = 0, wtd, towas = 0;
long totalwait = 0, wtd = 0, towas = 0;
char *callfromname;
char *pressbuttonname;
@@ -485,15 +490,19 @@ static struct ast_channel *wait_for_winner(struct findme_user_listptr *findme_us
callfromname = ast_strdupa(tpargs->callfromprompt);
pressbuttonname = ast_strdupa(tpargs->optionsprompt);
if (!AST_LIST_EMPTY(findme_user_list)) {
if (AST_LIST_EMPTY(findme_user_list)) {
ast_verb(3, "couldn't reach at this number.\n");
return NULL;
}
if (!caller) {
ast_verb(3, "Original caller hungup. Cleanup.\n");
clear_calling_tree(findme_user_list);
return NULL;
}
ctstatus = 0;
totalwait = nm->timeout * 1000;
wtd = 0;
while (!ctstatus) {
to = 1000;
pos = 1;
@@ -721,10 +730,6 @@ static struct ast_channel *wait_for_winner(struct findme_user_listptr *findme_us
ast_debug(1, "timed out waiting for action\n");
}
} else {
ast_verb(3, "couldn't reach at this number.\n");
}
/* --- WAIT FOR WINNER NUMBER END! -----------*/
return NULL;
}
@@ -890,34 +895,38 @@ static int app_exec(struct ast_channel *chan, void *data)
AST_APP_ARG(options);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n", app);
return -1;
}
if (!(argstr = ast_strdupa((char *)data))) {
ast_log(LOG_ERROR, "Out of memory!\n");
return -1;
}
if (!data) {
ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n",app);
AST_STANDARD_APP_ARGS(args, argstr);
if (ast_strlen_zero(args.followmeid)) {
ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n", app);
return -1;
}
AST_STANDARD_APP_ARGS(args, argstr);
if (!ast_strlen_zero(args.followmeid))
AST_LIST_LOCK(&followmes);
AST_LIST_TRAVERSE(&followmes, f, entry) {
AST_RWLIST_RDLOCK(&followmes);
AST_RWLIST_TRAVERSE(&followmes, f, entry) {
if (!strcasecmp(f->name, args.followmeid) && (f->active))
break;
}
AST_LIST_UNLOCK(&followmes);
AST_RWLIST_UNLOCK(&followmes);
ast_debug(1, "New profile %s.\n", args.followmeid);
if (!f) {
ast_log(LOG_WARNING, "Profile requested, %s, not found in the configuration.\n", args.followmeid);
res = 0;
} else {
return 0;
}
/* XXX TODO: Reinsert the db check value to see whether or not follow-me is on or off */
if (args.options)
ast_app_parse_options(followme_opts, &targs.followmeflags, NULL, args.options);
@@ -1016,7 +1025,7 @@ static int app_exec(struct ast_channel *chan, void *data)
ast_hangup(outbound);
res = 1;
}
}
outrun:
return res;
@@ -1029,13 +1038,13 @@ static int unload_module(void)
ast_unregister_application(app);
/* Free Memory. Yeah! I'm free! */
AST_LIST_LOCK(&followmes);
while ((f = AST_LIST_REMOVE_HEAD(&followmes, entry))) {
AST_RWLIST_WRLOCK(&followmes);
while ((f = AST_RWLIST_REMOVE_HEAD(&followmes, entry))) {
free_numbers(f);
ast_free(f);
}
AST_LIST_UNLOCK(&followmes);
AST_RWLIST_UNLOCK(&followmes);
return 0;
}