store conference list using linked list macros (issue #6327)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8727 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Russell Bryant 20 years ago
parent 0f4b7a78f6
commit 7707b953e1

@ -136,7 +136,7 @@ STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
static struct ast_conference { struct ast_conference {
ast_mutex_t playlock; /* Conference specific lock (players) */ ast_mutex_t playlock; /* Conference specific lock (players) */
ast_mutex_t listenlock; /* Conference specific lock (listeners) */ ast_mutex_t listenlock; /* Conference specific lock (listeners) */
char confno[AST_MAX_EXTENSION]; /* Conference */ char confno[AST_MAX_EXTENSION]; /* Conference */
@ -161,8 +161,10 @@ static struct ast_conference {
struct ast_frame *transframe[32]; struct ast_frame *transframe[32];
struct ast_frame *origframe; struct ast_frame *origframe;
struct ast_trans_pvt *transpath[32]; struct ast_trans_pvt *transpath[32];
struct ast_conference *next; AST_LIST_ENTRY(ast_conference) list;
} *confs; };
static AST_LIST_HEAD_STATIC(confs, ast_conference);
struct volume { struct volume {
int desired; /* Desired volume adjustment */ int desired; /* Desired volume adjustment */
@ -203,8 +205,6 @@ enum volume_action {
VOL_DOWN, VOL_DOWN,
}; };
AST_MUTEX_DEFINE_STATIC(conflock);
static int admin_exec(struct ast_channel *chan, void *data); static int admin_exec(struct ast_channel *chan, void *data);
static struct ast_frame null_frame = { AST_FRAME_NULL, }; static struct ast_frame null_frame = { AST_FRAME_NULL, };
@ -432,7 +432,7 @@ static void conf_play(struct ast_channel *chan, struct ast_conference *conf, int
if (!chan->_softhangup) if (!chan->_softhangup)
res = ast_autoservice_start(chan); res = ast_autoservice_start(chan);
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
switch(sound) { switch(sound) {
case ENTER: case ENTER:
@ -454,7 +454,7 @@ static void conf_play(struct ast_channel *chan, struct ast_conference *conf, int
careful_write(conf->fd, (unsigned char *)data2, len << 1, 1); careful_write(conf->fd, (unsigned char *)data2, len << 1, 1);
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
if (!res) if (!res)
ast_autoservice_stop(chan); ast_autoservice_stop(chan);
@ -465,9 +465,9 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
struct ast_conference *cnf; struct ast_conference *cnf;
struct zt_confinfo ztc; struct zt_confinfo ztc;
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
for (cnf = confs; cnf; cnf = cnf->next) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (!strcmp(confno, cnf->confno)) if (!strcmp(confno, cnf->confno))
break; break;
} }
@ -532,12 +532,11 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
cnf->locked = 0; cnf->locked = 0;
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno); ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno);
cnf->next = confs; AST_LIST_INSERT_HEAD(&confs, cnf, list);
confs = cnf;
} }
} }
cnfout: cnfout:
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
return cnf; return cnf;
} }
@ -576,13 +575,12 @@ static int conf_cmd(int fd, int argc, char **argv) {
if (argc == 1) { if (argc == 1) {
/* 'MeetMe': List all the conferences */ /* 'MeetMe': List all the conferences */
now = time(NULL); now = time(NULL);
cnf = confs; if (AST_LIST_EMPTY(&confs)) {
if (!cnf) {
ast_cli(fd, "No active MeetMe conferences.\n"); ast_cli(fd, "No active MeetMe conferences.\n");
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
ast_cli(fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation"); ast_cli(fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation");
while(cnf) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (cnf->markedusers == 0) if (cnf->markedusers == 0)
strcpy(cmdline, "N/A "); strcpy(cmdline, "N/A ");
else else
@ -594,7 +592,6 @@ static int conf_cmd(int fd, int argc, char **argv) {
ast_cli(fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static"); ast_cli(fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static");
total += cnf->users; total += cnf->users;
cnf = cnf->next;
} }
ast_cli(fd, "* Total number of MeetMe users: %d\n", total); ast_cli(fd, "* Total number of MeetMe users: %d\n", total);
return RESULT_SUCCESS; return RESULT_SUCCESS;
@ -643,21 +640,18 @@ static int conf_cmd(int fd, int argc, char **argv) {
} }
} else if(strcmp(argv[1], "list") == 0) { } else if(strcmp(argv[1], "list") == 0) {
/* List all the users in a conference */ /* List all the users in a conference */
if (!confs) { if (AST_LIST_EMPTY(&confs)) {
ast_cli(fd, "No active conferences.\n"); ast_cli(fd, "No active conferences.\n");
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
cnf = confs;
/* Find the right conference */ /* Find the right conference */
while(cnf) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (strcmp(cnf->confno, argv[2]) == 0) if (strcmp(cnf->confno, argv[2]) == 0)
break; break;
if (cnf->next) { }
cnf = cnf->next; if (!cnf) {
} else { ast_cli(fd, "No such conference: %s.\n",argv[2]);
ast_cli(fd, "No such conference: %s.\n",argv[2]); return RESULT_SUCCESS;
return RESULT_SUCCESS;
}
} }
/* Show all the users */ /* Show all the users */
for (user = cnf->firstuser; user; user = user->nextuser){ for (user = cnf->firstuser; user; user = user->nextuser){
@ -709,16 +703,14 @@ static char *complete_confcmd(const char *line, const char *word, int pos, int s
} }
} else if (pos == 2) { } else if (pos == 2) {
/* Conference Number */ /* Conference Number */
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
cnf = confs; AST_LIST_TRAVERSE(&confs, cnf, list) {
while(cnf) {
if (!strncasecmp(word, cnf->confno, strlen(word))) { if (!strncasecmp(word, cnf->confno, strlen(word))) {
if (++which > state) if (++which > state)
break; break;
} }
cnf = cnf->next;
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
return cnf ? strdup(cnf->confno) : NULL; return cnf ? strdup(cnf->confno) : NULL;
} else if (pos == 3) { } else if (pos == 3) {
/* User Number || Conf Command option*/ /* User Number || Conf Command option*/
@ -727,7 +719,7 @@ static char *complete_confcmd(const char *line, const char *word, int pos, int s
return strdup("all"); return strdup("all");
} }
which++; which++;
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
/* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */ /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
myline = ast_strdupa(line); myline = ast_strdupa(line);
@ -736,7 +728,7 @@ static char *complete_confcmd(const char *line, const char *word, int pos, int s
; ;
} }
for (cnf = confs; cnf; cnf = cnf->next) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (!strcmp(confno, cnf->confno)) if (!strcmp(confno, cnf->confno))
break; break;
} }
@ -751,7 +743,7 @@ static char *complete_confcmd(const char *line, const char *word, int pos, int s
} }
} }
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
return usr ? strdup(usrno) : NULL; return usr ? strdup(usrno) : NULL;
} }
} }
@ -798,32 +790,18 @@ static void conf_flush(int fd, struct ast_channel *chan)
We assume that this was called while holding conflock. */ We assume that this was called while holding conflock. */
static int conf_free(struct ast_conference *conf) static int conf_free(struct ast_conference *conf)
{ {
struct ast_conference *prev = NULL, *cur = confs;
int x; int x;
while (cur) { AST_LIST_REMOVE(&confs, conf, list);
if (cur == conf) {
if (prev)
prev->next = conf->next;
else
confs = conf->next;
break;
}
prev = cur;
cur = cur->next;
}
if (!cur)
ast_log(LOG_WARNING, "Conference not found\n");
if (conf->recording == MEETME_RECORD_ACTIVE) { if (conf->recording == MEETME_RECORD_ACTIVE) {
conf->recording = MEETME_RECORD_TERMINATE; conf->recording = MEETME_RECORD_TERMINATE;
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
while (1) { while (1) {
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
if (conf->recording == MEETME_RECORD_OFF) if (conf->recording == MEETME_RECORD_OFF)
break; break;
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
} }
} }
@ -1561,7 +1539,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
if (ioctl(fd, ZT_SETCONF, &ztc)) { if (ioctl(fd, ZT_SETCONF, &ztc)) {
ast_log(LOG_WARNING, "Error setting conference\n"); ast_log(LOG_WARNING, "Error setting conference\n");
close(fd); close(fd);
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
goto outrun; goto outrun;
} }
@ -1643,7 +1621,7 @@ bailoutandtrynormal:
reset_volumes(user); reset_volumes(user);
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
if (!(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN)) if (!(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN))
conf_play(chan, conf, LEAVE); conf_play(chan, conf, LEAVE);
@ -1658,10 +1636,10 @@ bailoutandtrynormal:
ast_filedelete(user->namerecloc, NULL); ast_filedelete(user->namerecloc, NULL);
} }
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
outrun: outrun:
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
if (dsp) if (dsp)
ast_dsp_free(dsp); ast_dsp_free(dsp);
@ -1727,7 +1705,7 @@ bailoutandtrynormal:
pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs); pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs);
} }
free(user); free(user);
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
return ret; return ret;
} }
@ -1745,12 +1723,12 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
); );
/* Check first in the conference list */ /* Check first in the conference list */
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
for (cnf = confs; cnf; cnf = cnf->next) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (!strcmp(confno, cnf->confno)) if (!strcmp(confno, cnf->confno))
break; break;
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
if (!cnf) { if (!cnf) {
if (dynamic) { if (dynamic) {
@ -1928,15 +1906,15 @@ static int conf_exec(struct ast_channel *chan, void *data)
struct ast_variable *var; struct ast_variable *var;
int confno_int; int confno_int;
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
for (cnf = confs; cnf; cnf = cnf->next) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (sscanf(cnf->confno, "%d", &confno_int) == 1) { if (sscanf(cnf->confno, "%d", &confno_int) == 1) {
/* Disqualify in use conference */ /* Disqualify in use conference */
if (confno_int >= 0 && confno_int < 1024) if (confno_int >= 0 && confno_int < 1024)
map[confno_int]++; map[confno_int]++;
} }
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
/* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */ /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */
if ((empty_no_pin) || (!dynamic)) { if ((empty_no_pin) || (!dynamic)) {
@ -1958,17 +1936,15 @@ static int conf_exec(struct ast_channel *chan, void *data)
} }
if (!dynamic) { if (!dynamic) {
/* For static: run through the list and see if this conference is empty */ /* For static: run through the list and see if this conference is empty */
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
cnf = confs; AST_LIST_TRAVERSE(&confs, cnf, list) {
while (cnf) {
if (!strcmp(confno_tmp, cnf->confno)) { if (!strcmp(confno_tmp, cnf->confno)) {
/* The conference exists, therefore it's not empty */ /* The conference exists, therefore it's not empty */
found = 1; found = 1;
break; break;
} }
cnf = cnf->next;
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
if (!found) { if (!found) {
/* At this point, we have a confno_tmp (static conference) that is empty */ /* At this point, we have a confno_tmp (static conference) that is empty */
if ((empty_no_pin && ((!stringp) || (stringp && (stringp[0] == '\0')))) || (!empty_no_pin)) { if ((empty_no_pin && ((!stringp) || (stringp && (stringp[0] == '\0')))) || (!empty_no_pin)) {
@ -2084,11 +2060,11 @@ static int conf_exec(struct ast_channel *chan, void *data)
res = -1; res = -1;
allowretry = 0; allowretry = 0;
/* see if we need to get rid of the conference */ /* see if we need to get rid of the conference */
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
if (!cnf->users) { if (!cnf->users) {
conf_free(cnf); conf_free(cnf);
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
break; break;
} }
@ -2145,7 +2121,7 @@ static int admin_exec(struct ast_channel *chan, void *data) {
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
/* The param has the conference number the user and the command to execute */ /* The param has the conference number the user and the command to execute */
if (!ast_strlen_zero(data)) { if (!ast_strlen_zero(data)) {
params = ast_strdupa((char *) data); params = ast_strdupa((char *) data);
@ -2154,11 +2130,11 @@ static int admin_exec(struct ast_channel *chan, void *data) {
if (!args.command) { if (!args.command) {
ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n"); ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return -1; return -1;
} }
for (cnf = confs; cnf; cnf = cnf->next) { AST_LIST_TRAVERSE(&confs, cnf, list) {
if (!strcmp(cnf->confno, args.confno)) if (!strcmp(cnf->confno, args.confno))
break; break;
} }
@ -2244,7 +2220,7 @@ static int admin_exec(struct ast_channel *chan, void *data) {
ast_log(LOG_NOTICE, "Conference Number not found\n"); ast_log(LOG_NOTICE, "Conference Number not found\n");
} }
} }
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
@ -2272,8 +2248,8 @@ static void *recordthread(void *args)
cnf->recording = MEETME_RECORD_ACTIVE; cnf->recording = MEETME_RECORD_ACTIVE;
while (ast_waitfor(cnf->lchan, -1) > -1) { while (ast_waitfor(cnf->lchan, -1) > -1) {
if (cnf->recording == MEETME_RECORD_TERMINATE) { if (cnf->recording == MEETME_RECORD_TERMINATE) {
ast_mutex_lock(&conflock); AST_LIST_LOCK(&confs);
ast_mutex_unlock(&conflock); AST_LIST_UNLOCK(&confs);
break; break;
} }
if (!s && cnf->recordingfilename && (cnf->recordingfilename != oldrecordingfilename)) { if (!s && cnf->recordingfilename && (cnf->recordingfilename != oldrecordingfilename)) {

Loading…
Cancel
Save