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