[asterisk-commits] branch bweschke/findme_followme r31770 -
/team/bweschke/findme_followme/apps/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Jun 3 08:48:05 MST 2006
Author: bweschke
Date: Sat Jun 3 10:48:05 2006
New Revision: 31770
URL: http://svn.digium.com/view/asterisk?rev=31770&view=rev
Log:
Doesn't compile, but committing to collab with the list macro gods.
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=31770&r1=31769&r2=31770&view=diff
==============================================================================
--- team/bweschke/findme_followme/apps/app_followme.c (original)
+++ team/bweschke/findme_followme/apps/app_followme.c Sat Jun 3 10:48:05 2006
@@ -70,7 +70,7 @@
struct number {
char number[512]; /*!< Phone Number and/or Extension */
long timeout; /*!< Dial Timeout, if used. */
- struct number *next; /*!< Next Number record */
+ AST_LIST_ENTRY(number) entry; /*!< Next Number record */
};
struct ast_call_followme {
@@ -79,11 +79,11 @@
char moh[AST_MAX_CONTEXT]; /*!< Music On Hold Class to be used */
char context[AST_MAX_CONTEXT]; /*!< Context to dial from */
unsigned int active; /*!< Profile is active (1), or disabled (0). */
-
- struct number *numbers; /*!< Head of the list of follow-me numbers */
- struct number *blnumbers; /*!< Head of the list of black-listed numbers */
- struct number *wlnumbers; /*!< Head of the list of white-listed numbers */
- struct ast_call_followme *next; /*!< Next Follow-Me record */
+
+ AST_LIST_HEAD_NOLOCK(numbers, number) numbers; /*!< Head of the list of follow-me numbers */
+ AST_LIST_HEAD_NOLOCK(blnumbers, number) blnumbers; /*!< Head of the list of black-listed numbers */
+ AST_LIST_HEAD_NOLOCK(wlnumbers, number) wlnumbers; /*!< Head of the list of white-listed numbers */
+ AST_LIST_ENTRY(ast_call_followme) entry; /*!< Next Follow-Me record */
};
struct thread_args {
@@ -102,7 +102,7 @@
char yn[10];
int ynidx;
int digts;
- struct findme_user *next;
+ AST_LIST_ENTRY(findme_user) entry;
};
static struct thread_args targs;
@@ -117,59 +117,33 @@
static char takecall[20] = "1", nextindp[20] = "2", nextinfmfm[20] = "", blindxferexten[20] = "", atxferexten[20] = "";
-static struct ast_call_followme *followmes = NULL;
-
-AST_MUTEX_DEFINE_STATIC(fmlock);
-
-static void free_numbers(struct ast_call_followme *f, int all)
+static AST_LIST_HEAD_STATIC(followmes, ast_call_followme);
+
+static void free_numbers(struct ast_call_followme *f)
{
/* Free numbers attached to the profile */
- struct number *curn, *next, *prev;
+ struct number *curn, *prev;
curn = f->numbers;
prev = NULL;
- while(curn) {
- next = curn->next;
- if (all) {
- if (prev)
- prev->next = next;
- else
- f->numbers = next;
- free(curn);
- } else
- prev = curn;
- curn = next;
- }
+ while ((prev = AST_LIST_REMOVE_HEAD(curn, entry)))
+ /* Free the number */
+ free(prev);
+ AST_LIST_HEAD_INIT_NOLOCK(curn);
curn = f->blnumbers;
prev = NULL;
- while(curn) {
- next = curn->next;
- if (all) {
- if (prev)
- prev->next = next;
- else
- f->blnumbers = next;
- free(curn);
- } else
- prev = curn;
- curn = next;
- }
+ while ((prev = AST_LIST_REMOVE_HEAD(curn, entry)))
+ /* Free the number */
+ free(prev);
+ AST_LIST_HEAD_INIT_NOLOCK(curn);
curn = f->wlnumbers;
prev = NULL;
- while(curn) {
- next = curn->next;
- if (all) {
- if (prev)
- prev->next = next;
- else
- f->wlnumbers = next;
- free(curn);
- } else
- prev = curn;
- curn = next;
- }
+ while ((prev = AST_LIST_REMOVE_HEAD(curn, entry)))
+ /* Free the number */
+ free(prev);
+ AST_LIST_HEAD_INIT_NOLOCK(curn);
}
@@ -184,6 +158,9 @@
ast_copy_string(f->name, fmname, sizeof(f->name));
ast_copy_string(f->moh, "", sizeof(f->moh));
ast_copy_string(f->context, "", sizeof(f->context));
+ AST_LIST_HEAD_INIT_NOLOCK(&f->numbers);
+ AST_LIST_HEAD_INIT_NOLOCK(&f->blnumbers);
+ AST_LIST_HEAD_INIT_NOLOCK(&f->wlnumbers);
}
return f;
}
@@ -249,16 +226,15 @@
ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
return 0;
}
- ast_mutex_lock(&fmlock);
+
+ AST_LIST_LOCK(&followmes);
/* Reset Global Var Values */
featuredigittimeout = 5000;
/* Mark all profiles as inactive for the moment */
- f = followmes;
- while(f) {
+ AST_LIST_TRAVERSE(&followmes, f, entry) {
f->active = 0;
- f = f->next;
}
featuredigittostr = ast_variable_retrieve(cfg, "general", "featuredigittimeout");
@@ -272,11 +248,9 @@
while(cat) {
/* Define a new profile */
/* Look for an existing one */
- f = followmes;
- while(f) {
+ AST_LIST_TRAVERSE(&followmes, f, entry) {
if (!strcmp(f->name, cat))
break;
- f = f->next;
}
if (option_debug > 2)
ast_log(LOG_DEBUG, "New profile %s.\n", cat);
@@ -292,13 +266,7 @@
ast_mutex_lock(&f->lock);
/* Re-initialize the profile */
init_profile(f);
- free_numbers(f, 1);
- prev = f->numbers;
- if (prev) {
- /* find the end of any dynamic numbers */
- while(prev->next)
- prev = prev->next;
- }
+ free_numbers(f);
var = ast_variable_browse(cfg, cat);
while(var) {
if (!strcasecmp(var->name, "number")) {
@@ -313,14 +281,8 @@
} else
timeout = 12;
cur = create_followme_number(numberstr, timeout);
-
- if (cur) {
- if (prev)
- prev->next = cur;
- else
- f->numbers = cur;
- prev = cur;
- }
+
+ AST_LIST_INSERT_HEAD(&f->numbers, cur, entry);
} else {
profile_set_param(f, var->name, var->value, var->lineno, 1);
if (option_debug > 2)
@@ -332,14 +294,15 @@
if (!new)
ast_mutex_unlock(&f->lock);
if (new) {
- f->next = followmes;
- followmes = f;
+ AST_LIST_INSERT_HEAD(&followmes, f, entry);
}
}
cat = ast_category_browse(cfg, cat);
}
ast_config_destroy(cfg);
- ast_mutex_unlock(&fmlock);
+
+ AST_LIST_UNLOCK(&followmes);
+
return 1;
}
@@ -372,10 +335,8 @@
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
ast_hangup(tmpuser->ochan);
}
- if (wholetree)
- tmpuser = tmpuser->next;
- else
- tmpuser = NULL;
+ if (!wholetree)
+ break;
}
}
@@ -935,7 +896,7 @@
f->active = 0;
prior = f;
f = f->next;
- free_numbers(f,1);
+ free_numbers(f);
free(prior);
}
STANDARD_HANGUP_LOCALUSERS;
More information about the asterisk-commits
mailing list