[asterisk-commits] trunk r27153 - in /trunk: apps/app_meetme.c
include/asterisk/linkedlists.h
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon May 15 09:32:15 MST 2006
Author: russell
Date: Sat May 13 06:06:34 2006
New Revision: 27153
URL: http://svn.digium.com/view/asterisk?rev=27153&view=rev
Log:
simplify conference user list handling
Modified:
trunk/apps/app_meetme.c
trunk/include/asterisk/linkedlists.h
Modified: trunk/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_meetme.c?rev=27153&r1=27152&r2=27153&view=diff
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Sat May 13 06:06:34 2006
@@ -152,8 +152,6 @@
int zapconf; /* Zaptel Conf # */
int users; /* Number of active users */
int markedusers; /* Number of marked users */
- struct ast_conf_user *firstuser; /* Pointer to the first user struct */
- struct ast_conf_user *lastuser; /* Pointer to the last user struct */
time_t start; /* Start time (s) */
int refcount; /* reference count of usage */
unsigned int recording:2; /* recording status */
@@ -168,6 +166,7 @@
struct ast_frame *transframe[32];
struct ast_frame *origframe;
struct ast_trans_pvt *transpath[32];
+ AST_LIST_HEAD_NOLOCK(, ast_conf_user) userlist;
AST_LIST_ENTRY(ast_conference) list;
};
@@ -180,8 +179,6 @@
struct ast_conf_user {
int user_no; /* User Number */
- struct ast_conf_user *prevuser; /* Pointer to the previous user */
- struct ast_conf_user *nextuser; /* Pointer to the next user */
int userflags; /* Flags as set in the conference */
int adminflags; /* Flags set by the Admin */
struct ast_channel *chan; /* Connected channel */
@@ -192,6 +189,7 @@
time_t jointime; /* Time the user joined the conference */
struct volume talk;
struct volume listen;
+ AST_LIST_ENTRY(ast_conf_user) list;
};
static int audio_buffers; /* The number of audio buffers to be allocated on pseudo channels
@@ -532,9 +530,6 @@
cnf->start = time(NULL);
cnf->zapconf = ztc.confno;
cnf->isdynamic = dynamic ? 1 : 0;
- cnf->firstuser = NULL;
- cnf->lastuser = NULL;
- cnf->locked = 0;
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno);
AST_LIST_INSERT_HEAD(&confs, cnf, list);
@@ -665,7 +660,7 @@
return RESULT_SUCCESS;
}
/* Show all the users */
- for (user = cnf->firstuser; user; user = user->nextuser){
+ AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
now = time(NULL);
hr = (now - user->jointime) / 3600;
min = ((now - user->jointime) % 3600) / 60;
@@ -751,7 +746,7 @@
if (cnf) {
/* Search for the user */
- for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
+ AST_LIST_TRAVERSE(&cnf->userlist, usr, list) {
snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
if (!strncasecmp(word, usrno, len) && ++which > state)
break;
@@ -928,24 +923,13 @@
conf->markedusers++;
ast_mutex_lock(&conf->playlock);
- if (!conf->firstuser) {
- /* Fill the first new User struct */
+
+ if (AST_LIST_EMPTY(&conf->userlist))
user->user_no = 1;
- conf->firstuser = user;
- conf->lastuser = user;
- } else {
- /* Fill the new user struct */
- user->user_no = conf->lastuser->user_no + 1;
- user->prevuser = conf->lastuser;
- if (conf->lastuser->nextuser) {
- ast_log(LOG_WARNING, "Error in User Management!\n");
- ast_mutex_unlock(&conf->playlock);
- goto outrun;
- } else {
- conf->lastuser->nextuser = user;
- conf->lastuser = user;
- }
- }
+ else
+ user->user_no = AST_LIST_LAST(&conf->userlist)->user_no + 1;
+
+ AST_LIST_INSERT_TAIL(&conf->userlist, user, list);
user->chan = chan;
user->userflags = confflags;
@@ -1480,7 +1464,7 @@
break;
case '3': /* Eject last user */
menu_active = 0;
- usr = conf->lastuser;
+ usr = AST_LIST_LAST(&conf->userlist);
if ((usr->chan->name == chan->name)||(usr->userflags & CONFFLAG_ADMIN)) {
if(!ast_streamfile(chan, "conf-errormenu", chan->language))
ast_waitstream(chan, "");
@@ -1711,39 +1695,12 @@
ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
if (confflags & CONFFLAG_MARKEDUSER)
conf->markedusers--;
- if (!conf->users) {
+ if (AST_LIST_EMPTY(&conf->userlist)) {
/* close this one when no more users and no references*/
- if (!conf->refcount){
+ if (!conf->refcount)
conf_free(conf);
- }
} else {
- /* Remove the user struct */
- if (user == conf->firstuser) {
- if (user->nextuser) {
- /* There is another entry */
- user->nextuser->prevuser = NULL;
- } else {
- /* We are the only entry */
- conf->lastuser = NULL;
- }
- /* In either case */
- conf->firstuser = user->nextuser;
- } else if (user == conf->lastuser){
- if (user->prevuser)
- user->prevuser->nextuser = NULL;
- else
- ast_log(LOG_ERROR, "Bad bad bad! We're the last, not the first, but nobody before us??\n");
- conf->lastuser = user->prevuser;
- } else {
- if (user->nextuser)
- user->nextuser->prevuser = user->prevuser;
- else
- ast_log(LOG_ERROR, "Bad! Bad! Bad! user->nextuser is NULL but we're not the end!\n");
- if (user->prevuser)
- user->prevuser->nextuser = user->nextuser;
- else
- ast_log(LOG_ERROR, "Bad! Bad! Bad! user->prevuser is NULL but we're not the beginning!\n");
- }
+ AST_LIST_REMOVE(&conf->userlist, user, list);
}
/* Return the number of seconds the user was in the conf */
snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
@@ -2221,18 +2178,16 @@
return res;
}
-static struct ast_conf_user* find_user(struct ast_conference *conf, char *callerident)
+static struct ast_conf_user *find_user(struct ast_conference *conf, char *callerident)
{
struct ast_conf_user *user = NULL;
int cid;
sscanf(callerident, "%i", &cid);
if (conf && callerident) {
- user = conf->firstuser;
- while (user) {
+ AST_LIST_TRAVERSE(&conf->userlist, user, list) {
if (cid == user->user_no)
return user;
- user = user->nextuser;
}
}
return NULL;
@@ -2282,23 +2237,15 @@
case 108: /* l: Unlock */
cnf->locked = 0;
break;
- case 75: /* K: kick all users*/
- user = cnf->firstuser;
- while(user) {
+ case 75: /* K: kick all users */
+ AST_LIST_TRAVERSE(&cnf->userlist, user, list)
user->adminflags |= ADMINFLAG_KICKME;
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
- }
break;
case 101: /* e: Eject last user*/
- user = cnf->lastuser;
- if (!(user->userflags & CONFFLAG_ADMIN)) {
+ user = AST_LIST_LAST(&cnf->userlist);
+ if (!(user->userflags & CONFFLAG_ADMIN))
user->adminflags |= ADMINFLAG_KICKME;
- break;
- } else
+ else
ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
break;
case 77: /* M: Mute */
@@ -2314,15 +2261,9 @@
}
break;
case 78: /* N: Mute all users */
- user = cnf->firstuser;
- while(user) {
- if (user && !(user->userflags & CONFFLAG_ADMIN))
+ AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
+ if (!(user->userflags & CONFFLAG_ADMIN))
user->adminflags |= ADMINFLAG_MUTED;
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
}
break;
case 109: /* m: Unmute */
@@ -2337,25 +2278,15 @@
ast_log(LOG_NOTICE, "Specified User not found or he muted himself!\n");
}
break;
- case 110: /* n: Unmute all users */
- user = cnf->firstuser;
- while(user) {
- if (user && (user-> adminflags & ADMINFLAG_MUTED)) {
- user->adminflags ^= ADMINFLAG_MUTED;
- }
- if (user->nextuser) {
- user = user->nextuser;
- } else {
- break;
- }
- }
+ case 110: /* n: Unmute all users */
+ AST_LIST_TRAVERSE(&cnf->userlist, user, list)
+ user->adminflags &= ~ADMINFLAG_MUTED;
break;
case 107: /* k: Kick user */
- if (user) {
+ if (user)
user->adminflags |= ADMINFLAG_KICKME;
- } else {
+ else
ast_log(LOG_NOTICE, "Specified User not found!");
- }
break;
}
} else {
Modified: trunk/include/asterisk/linkedlists.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/linkedlists.h?rev=27153&r1=27152&r2=27153&view=diff
==============================================================================
--- trunk/include/asterisk/linkedlists.h (original)
+++ trunk/include/asterisk/linkedlists.h Sat May 13 06:06:34 2006
@@ -208,6 +208,12 @@
#define AST_LIST_FIRST(head) ((head)->first)
/*!
+ \brief Returns the last entry contained in a list.
+ \param head This is a pointer to the list tail structure
+ */
+#define AST_LIST_LAST(head) ((head)->last)
+
+/*!
\brief Returns the next entry in the list after the given entry.
\param elm This is a pointer to the current entry.
\param field This is the name of the field (declared using AST_LIST_ENTRY())
More information about the asterisk-commits
mailing list