whitepace cleanup and various minor fixes
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 8 Nov 2005 21:32:51 +0000 (21:32 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 8 Nov 2005 21:32:51 +0000 (21:32 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7032 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_meetme.c

index e9f52a7..55313c3 100755 (executable)
@@ -128,22 +128,22 @@ LOCAL_USER_DECL;
 
 static struct ast_conference {
        char confno[AST_MAX_EXTENSION];         /* Conference */
 
 static struct ast_conference {
        char confno[AST_MAX_EXTENSION];         /* Conference */
-       struct ast_channel *chan;       /* Announcements channel */
-       int fd;                         /* Announcements fd */
-       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 recording;                  /* recording status */
-       int isdynamic;                  /* Created on the fly? */
-       int locked;                       /* Is the conference locked? */
-       pthread_t recordthread;         /* thread for recording */
-       pthread_attr_t attr;            /* thread attribute */
-       char *recordingfilename;        /* Filename to record the Conference into */
-       char *recordingformat;          /* Format to record the Conference in */
-       char pin[AST_MAX_EXTENSION];                    /* If protected by a PIN */
+       struct ast_channel *chan;               /* Announcements channel */
+       int fd;                                 /* Announcements fd */
+       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 recording;                          /* recording status */
+       int isdynamic;                          /* Created on the fly? */
+       int locked;                             /* Is the conference locked? */
+       pthread_t recordthread;                 /* thread for recording */
+       pthread_attr_t attr;                    /* thread attribute */
+       char *recordingfilename;                /* Filename to record the Conference into */
+       char *recordingformat;                  /* Format to record the Conference in */
+       char pin[AST_MAX_EXTENSION];            /* If protected by a PIN */
        char pinadmin[AST_MAX_EXTENSION];       /* If protected by a admin PIN */
        struct ast_conference *next;
 } *confs;
        char pinadmin[AST_MAX_EXTENSION];       /* If protected by a admin PIN */
        struct ast_conference *next;
 } *confs;
@@ -197,28 +197,28 @@ static void *recordthread(void *args);
 
 #define CONF_SIZE 320
 
 
 #define CONF_SIZE 320
 
-#define CONFFLAG_ADMIN (1 << 1)        /* If set the user has admin access on the conference */
-#define CONFFLAG_MONITOR (1 << 2)      /* If set the user can only receive audio from the conference */
-#define CONFFLAG_POUNDEXIT (1 << 3)    /* If set asterisk will exit conference when '#' is pressed */
-#define CONFFLAG_STARMENU (1 << 4)     /* If set asterisk will provide a menu to the user what '*' is pressed */
-#define CONFFLAG_TALKER (1 << 5)       /* If set the use can only send audio to the conference */
-#define CONFFLAG_QUIET (1 << 6)                /* If set there will be no enter or leave sounds */
-#define CONFFLAG_VIDEO (1 << 7)                /* Set to enable video mode */
-#define CONFFLAG_AGI (1 << 8)          /* Set to run AGI Script in Background */
-#define CONFFLAG_MOH (1 << 9)          /* Set to have music on hold when user is alone in conference */
-#define CONFFLAG_MARKEDEXIT (1 << 10)    /* If set the MeetMe will return if all marked with this flag left */
-#define CONFFLAG_WAITMARKED (1 << 11)  /* If set, the MeetMe will wait until a marked user enters */
-#define CONFFLAG_EXIT_CONTEXT (1 << 12)        /* If set, the MeetMe will exit to the specified context */
-#define CONFFLAG_MARKEDUSER (1 << 13)  /* If set, the user will be marked */
-#define CONFFLAG_INTROUSER (1 << 14)   /* If set, user will be ask record name on entry of conference */
-#define CONFFLAG_RECORDCONF (1<< 15)   /* If set, the MeetMe will be recorded */
-#define CONFFLAG_MONITORTALKER (1 << 16) /* If set, the user will be monitored if the user is talking or not */
+#define CONFFLAG_ADMIN (1 << 1)                /* If set the user has admin access on the conference */
+#define CONFFLAG_MONITOR (1 << 2)              /* If set the user can only receive audio from the conference */
+#define CONFFLAG_POUNDEXIT (1 << 3)            /* If set asterisk will exit conference when '#' is pressed */
+#define CONFFLAG_STARMENU (1 << 4)             /* If set asterisk will provide a menu to the user when '*' is pressed */
+#define CONFFLAG_TALKER (1 << 5)               /* If set the use can only send audio to the conference */
+#define CONFFLAG_QUIET (1 << 6)                        /* If set there will be no enter or leave sounds */
+#define CONFFLAG_VIDEO (1 << 7)                        /* Set to enable video mode */
+#define CONFFLAG_AGI (1 << 8)                  /* Set to run AGI Script in Background */
+#define CONFFLAG_MOH (1 << 9)                  /* Set to have music on hold when user is alone in conference */
+#define CONFFLAG_MARKEDEXIT (1 << 10)          /* If set the MeetMe will return if all marked with this flag left */
+#define CONFFLAG_WAITMARKED (1 << 11)          /* If set, the MeetMe will wait until a marked user enters */
+#define CONFFLAG_EXIT_CONTEXT (1 << 12)                /* If set, the MeetMe will exit to the specified context */
+#define CONFFLAG_MARKEDUSER (1 << 13)          /* If set, the user will be marked */
+#define CONFFLAG_INTROUSER (1 << 14)           /* If set, user will be ask record name on entry of conference */
+#define CONFFLAG_RECORDCONF (1<< 15)           /* If set, the MeetMe will be recorded */
+#define CONFFLAG_MONITORTALKER (1 << 16)       /* If set, the user will be monitored if the user is talking or not */
 #define CONFFLAG_DYNAMIC (1 << 17)
 #define CONFFLAG_DYNAMICPIN (1 << 18)
 #define CONFFLAG_EMPTY (1 << 19)
 #define CONFFLAG_EMPTYNOPIN (1 << 20)
 #define CONFFLAG_ALWAYSPROMPT (1 << 21)
 #define CONFFLAG_DYNAMIC (1 << 17)
 #define CONFFLAG_DYNAMICPIN (1 << 18)
 #define CONFFLAG_EMPTY (1 << 19)
 #define CONFFLAG_EMPTYNOPIN (1 << 20)
 #define CONFFLAG_ALWAYSPROMPT (1 << 21)
-#define CONFFLAG_ANNOUNCEUSERCOUNT (1 << 22) /* If set, when user joins the conference, they will be told the number of users that are already in */
+#define CONFFLAG_ANNOUNCEUSERCOUNT (1 << 22)   /* If set, when user joins the conference, they will be told the number of users that are already in */
 
 
 AST_APP_OPTIONS(meetme_opts, {
 
 
 AST_APP_OPTIONS(meetme_opts, {
@@ -259,7 +259,8 @@ static int careful_write(int fd, unsigned char *data, int len)
 {
        int res;
        int x;
 {
        int res;
        int x;
-       while(len) {
+
+       while (len) {
                x = ZT_IOMUX_WRITE | ZT_IOMUX_SIGEVENT;
                res = ioctl(fd, ZT_IOMUX, &x);
                if (res >= 0)
                x = ZT_IOMUX_WRITE | ZT_IOMUX_SIGEVENT;
                res = ioctl(fd, ZT_IOMUX, &x);
                if (res >= 0)
@@ -274,6 +275,7 @@ static int careful_write(int fd, unsigned char *data, int len)
                len -= res;
                data += res;
        }
                len -= res;
                data += res;
        }
+
        return 0;
 }
 
        return 0;
 }
 
@@ -305,6 +307,7 @@ static int set_talk_volume(struct ast_conf_user *user, int volume)
           if successful, don't adjust in the frame reading routine
        */
        gain_adjust = gain_map[volume + 5];
           if successful, don't adjust in the frame reading routine
        */
        gain_adjust = gain_map[volume + 5];
+
        return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
 }
 
        return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
 }
 
@@ -316,6 +319,7 @@ static int set_listen_volume(struct ast_conf_user *user, int volume)
           if successful, don't adjust in the frame reading routine
        */
        gain_adjust = gain_map[volume + 5];
           if successful, don't adjust in the frame reading routine
        */
        gain_adjust = gain_map[volume + 5];
+
        return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
 }
 
        return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
 }
 
@@ -390,10 +394,13 @@ static void conf_play(struct ast_channel *chan, struct ast_conference *conf, int
 {
        unsigned char *data;
        int len;
 {
        unsigned char *data;
        int len;
-       int res=-1;
+       int res = -1;
+
        if (!chan->_softhangup)
                res = ast_autoservice_start(chan);
        if (!chan->_softhangup)
                res = ast_autoservice_start(chan);
+
        ast_mutex_lock(&conflock);
        ast_mutex_lock(&conflock);
+
        switch(sound) {
        case ENTER:
                data = enter;
        switch(sound) {
        case ENTER:
                data = enter;
@@ -409,7 +416,9 @@ static void conf_play(struct ast_channel *chan, struct ast_conference *conf, int
        }
        if (data) 
                careful_write(conf->fd, data, len);
        }
        if (data) 
                careful_write(conf->fd, data, len);
+
        ast_mutex_unlock(&conflock);
        ast_mutex_unlock(&conflock);
+
        if (!res) 
                ast_autoservice_stop(chan);
 }
        if (!res) 
                ast_autoservice_stop(chan);
 }
@@ -418,18 +427,18 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
 {
        struct ast_conference *cnf;
        struct zt_confinfo ztc;
 {
        struct ast_conference *cnf;
        struct zt_confinfo ztc;
+
        ast_mutex_lock(&conflock);
        ast_mutex_lock(&conflock);
-       cnf = confs;
-       while(cnf) {
+
+       for (cnf = confs; cnf; cnf = cnf->next) {
                if (!strcmp(confno, cnf->confno)) 
                        break;
                if (!strcmp(confno, cnf->confno)) 
                        break;
-               cnf = cnf->next;
        }
        }
+
        if (!cnf && (make || dynamic)) {
        if (!cnf && (make || dynamic)) {
-               cnf = malloc(sizeof(struct ast_conference));
+               /* Make a new one */
+               cnf = calloc(1, sizeof(*cnf));
                if (cnf) {
                if (cnf) {
-                       /* Make a new one */
-                       memset(cnf, 0, sizeof(struct ast_conference));
                        ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
                        ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
                        ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
                        ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
                        ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
                        ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
@@ -476,7 +485,7 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
                } else  
                        ast_log(LOG_WARNING, "Out of memory\n");
        }
                } else  
                        ast_log(LOG_WARNING, "Out of memory\n");
        }
-cnfout:
+ cnfout:
        ast_mutex_unlock(&conflock);
        return cnf;
 }
        ast_mutex_unlock(&conflock);
        return cnf;
 }
@@ -484,6 +493,7 @@ cnfout:
 static int confs_show(int fd, int argc, char **argv)
 {
        ast_cli(fd, "Deprecated! Please use 'meetme' instead.\n");
 static int confs_show(int fd, int argc, char **argv)
 {
        ast_cli(fd, "Deprecated! Please use 'meetme' instead.\n");
+
        return RESULT_SUCCESS;
 }
 
        return RESULT_SUCCESS;
 }
 
@@ -555,7 +565,7 @@ static int conf_cmd(int fd, int argc, char **argv) {
                if (strcmp(argv[1], "mute") == 0) {
                        /* Mute */
                        if (strcmp(argv[3], "all") == 0) {
                if (strcmp(argv[1], "mute") == 0) {
                        /* Mute */
                        if (strcmp(argv[3], "all") == 0) {
-                                strncat(cmdline, "|N", sizeof(cmdline) - strlen(cmdline) - 1);
+                               strncat(cmdline, "|N", sizeof(cmdline) - strlen(cmdline) - 1);
                        } else {
                                strncat(cmdline, "|M|", sizeof(cmdline) - strlen(cmdline) - 1); 
                                strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
                        } else {
                                strncat(cmdline, "|M|", sizeof(cmdline) - strlen(cmdline) - 1); 
                                strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
@@ -563,7 +573,7 @@ static int conf_cmd(int fd, int argc, char **argv) {
                } else {
                        /* Unmute */
                        if (strcmp(argv[3], "all") == 0) {
                } else {
                        /* Unmute */
                        if (strcmp(argv[3], "all") == 0) {
-                                strncat(cmdline, "|n", sizeof(cmdline) - strlen(cmdline) - 1);
+                               strncat(cmdline, "|n", sizeof(cmdline) - strlen(cmdline) - 1);
                        } else {
                                strncat(cmdline, "|m|", sizeof(cmdline) - strlen(cmdline) - 1);
                                strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
                        } else {
                                strncat(cmdline, "|m|", sizeof(cmdline) - strlen(cmdline) - 1);
                                strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
@@ -599,22 +609,29 @@ static int conf_cmd(int fd, int argc, char **argv) {
                        }
                }
                /* Show all the users */
                        }
                }
                /* Show all the users */
-               user = cnf->firstuser;
-               while(user) {
-                       ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s\n", user->user_no, user->chan->cid.cid_num ? user->chan->cid.cid_num : "<unknown>", user->chan->cid.cid_name ? user->chan->cid.cid_name : "<no name>", user->chan->name, (user->userflags & CONFFLAG_ADMIN) ? "(Admin)" : "", (user->userflags & CONFFLAG_MONITOR) ? "(Listen only)" : "", (user->adminflags & ADMINFLAG_MUTED) ? "(Admn Muted)" : "", istalking(user->talking));
-                       user = user->nextuser;
-               }
+               for (user = cnf->firstuser; user; user = user->nextuser)
+                       ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s\n",
+                               user->user_no,
+                               user->chan->cid.cid_num ? user->chan->cid.cid_num : "<unknown>",
+                               user->chan->cid.cid_name ? user->chan->cid.cid_name : "<no name>",
+                               user->chan->name,
+                               user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
+                               user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
+                               user->adminflags & ADMINFLAG_MUTED ? "(Admn Muted)" : "",
+                               istalking(user->talking));
                ast_cli(fd,"%d users in that conference.\n",cnf->users);
                ast_cli(fd,"%d users in that conference.\n",cnf->users);
+
                return RESULT_SUCCESS;
        } else 
                return RESULT_SHOWUSAGE;
        ast_log(LOG_DEBUG, "Cmdline: %s\n", cmdline);
        admin_exec(NULL, cmdline);
                return RESULT_SUCCESS;
        } else 
                return RESULT_SHOWUSAGE;
        ast_log(LOG_DEBUG, "Cmdline: %s\n", cmdline);
        admin_exec(NULL, cmdline);
+
        return 0;
 }
 
 static char *complete_confcmd(char *line, char *word, int pos, int state) {
        return 0;
 }
 
 static char *complete_confcmd(char *line, char *word, int pos, int state) {
-       #define CONF_COMMANDS 6
+#define CONF_COMMANDS 6
        int which = 0, x = 0;
        struct ast_conference *cnf = NULL;
        struct ast_conf_user *usr = NULL;
        int which = 0, x = 0;
        struct ast_conference *cnf = NULL;
        struct ast_conf_user *usr = NULL;
@@ -653,7 +670,6 @@ static char *complete_confcmd(char *line, char *word, int pos, int state) {
                        }
                        which++;
                        ast_mutex_lock(&conflock);
                        }
                        which++;
                        ast_mutex_lock(&conflock);
-                       cnf = confs;
 
                        /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
                        myline = ast_strdupa(line);
 
                        /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
                        myline = ast_strdupa(line);
@@ -662,28 +678,26 @@ static char *complete_confcmd(char *line, char *word, int pos, int state) {
                                        ;
                        }
                        
                                        ;
                        }
                        
-                       while(cnf) {
-                               if (strcmp(confno, cnf->confno) == 0) {
-                                       break;
-                               }
-                               cnf = cnf->next;
+                       for (cnf = confs; cnf; cnf = cnf->next) {
+                               if (!strcmp(confno, cnf->confno))
+                                   break;
                        }
                        }
+
                        if (cnf) {
                                /* Search for the user */
                        if (cnf) {
                                /* Search for the user */
-                               usr = cnf->firstuser;
-                               while(usr) {
+                               for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
                                        snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
                                        if (!strncasecmp(word, usrno, strlen(word))) {
                                                if (++which > state)
                                                        break;
                                        }
                                        snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
                                        if (!strncasecmp(word, usrno, strlen(word))) {
                                                if (++which > state)
                                                        break;
                                        }
-                                       usr = usr->nextuser;
                                }
                        }
                        ast_mutex_unlock(&conflock);
                        return usr ? strdup(usrno) : NULL;
                }
        }
                                }
                        }
                        ast_mutex_unlock(&conflock);
                        return usr ? strdup(usrno) : NULL;
                }
        }
+
        return NULL;
 }
        
        return NULL;
 }
        
@@ -698,6 +712,7 @@ static struct ast_cli_entry cli_conf = {
 static void conf_flush(int fd)
 {
        int x;
 static void conf_flush(int fd)
 {
        int x;
+
        x = ZT_FLUSH_ALL;
        if (ioctl(fd, ZT_FLUSH, &x))
                ast_log(LOG_WARNING, "Error flushing channel\n");
        x = ZT_FLUSH_ALL;
        if (ioctl(fd, ZT_FLUSH, &x))
                ast_log(LOG_WARNING, "Error flushing channel\n");
@@ -709,7 +724,7 @@ static int conf_free(struct ast_conference *conf)
 {
        struct ast_conference *prev = NULL, *cur = confs;
 
 {
        struct ast_conference *prev = NULL, *cur = confs;
 
-       while(cur) {
+       while (cur) {
                if (cur == conf) {
                        if (prev)
                                prev->next = conf->next;
                if (cur == conf) {
                        if (prev)
                                prev->next = conf->next;
@@ -747,7 +762,7 @@ static int conf_free(struct ast_conference *conf)
 
 static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags)
 {
 
 static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags)
 {
-       struct ast_conf_user *user = malloc(sizeof(struct ast_conf_user));
+       struct ast_conf_user *user = calloc(1, sizeof(*user));
        struct ast_conf_user *usr = NULL;
        int fd;
        struct zt_confinfo ztc, ztc_empty;
        struct ast_conf_user *usr = NULL;
        int fd;
        struct zt_confinfo ztc, ztc_empty;
@@ -763,7 +778,6 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
        int origfd;
        int musiconhold = 0;
        int firstpass = 0;
        int origfd;
        int musiconhold = 0;
        int firstpass = 0;
-       int origquiet;
        int lastmarked = 0;
        int currentmarked = 0;
        int ret = -1;
        int lastmarked = 0;
        int currentmarked = 0;
        int ret = -1;
@@ -772,7 +786,6 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
        int using_pseudo = 0;
        int duration=20;
        struct ast_dsp *dsp=NULL;
        int using_pseudo = 0;
        int duration=20;
        struct ast_dsp *dsp=NULL;
-
        struct ast_app *app;
        char *agifile;
        char *agifiledefault = "conf-background.agi";
        struct ast_app *app;
        char *agifile;
        char *agifiledefault = "conf-background.agi";
@@ -780,36 +793,33 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
        char exitcontext[AST_MAX_CONTEXT] = "";
        char recordingtmp[AST_MAX_EXTENSION] = "";
        int dtmf;
        char exitcontext[AST_MAX_CONTEXT] = "";
        char recordingtmp[AST_MAX_EXTENSION] = "";
        int dtmf;
-
        ZT_BUFFERINFO bi;
        char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
        char *buf = __buf + AST_FRIENDLY_OFFSET;
        
        if (!user) {
                ast_log(LOG_ERROR, "Out of memory\n");
        ZT_BUFFERINFO bi;
        char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
        char *buf = __buf + AST_FRIENDLY_OFFSET;
        
        if (!user) {
                ast_log(LOG_ERROR, "Out of memory\n");
-               return(ret);
+               return ret;
        }
        }
-       memset(user, 0, sizeof(struct ast_conf_user));
 
        if (confflags & CONFFLAG_RECORDCONF && conf->recording !=MEETME_RECORD_ACTIVE) {
 
        if (confflags & CONFFLAG_RECORDCONF && conf->recording !=MEETME_RECORD_ACTIVE) {
-               conf->recordingfilename = pbx_builtin_getvar_helper(chan,"MEETME_RECORDINGFILE");
+               conf->recordingfilename = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE");
                if (!conf->recordingfilename) {
                if (!conf->recordingfilename) {
-                       snprintf(recordingtmp,sizeof(recordingtmp),"meetme-conf-rec-%s-%s",conf->confno,chan->uniqueid);
+                       snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, chan->uniqueid);
                        conf->recordingfilename = ast_strdupa(recordingtmp);
                }
                conf->recordingformat = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT");
                if (!conf->recordingformat) {
                        conf->recordingfilename = ast_strdupa(recordingtmp);
                }
                conf->recordingformat = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT");
                if (!conf->recordingformat) {
-                       snprintf(recordingtmp,sizeof(recordingtmp), "wav");
+                       snprintf(recordingtmp, sizeof(recordingtmp), "wav");
                        conf->recordingformat = ast_strdupa(recordingtmp);
                }
                pthread_attr_init(&conf->attr);
                pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
                        conf->recordingformat = ast_strdupa(recordingtmp);
                }
                pthread_attr_init(&conf->attr);
                pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
-               ast_verbose(VERBOSE_PREFIX_4 "Starting recording of MeetMe Conference %s into file %s.%s.\n", conf->confno, conf->recordingfilename, conf->recordingformat);
+               ast_verbose(VERBOSE_PREFIX_4 "Starting recording of MeetMe Conference %s into file %s.%s.\n",
+                           conf->confno, conf->recordingfilename, conf->recordingformat);
                ast_pthread_create(&conf->recordthread, &conf->attr, recordthread, conf);
        }
 
                ast_pthread_create(&conf->recordthread, &conf->attr, recordthread, conf);
        }
 
-       user->user_no = 0; /* User number 0 means starting up user! (dead - not in the list!) */
-
        time(&user->jointime);
 
        if (conf->locked) {
        time(&user->jointime);
 
        if (conf->locked) {
@@ -823,19 +833,16 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
                conf->markedusers++;
       
        ast_mutex_lock(&conflock);
                conf->markedusers++;
       
        ast_mutex_lock(&conflock);
-       if (conf->firstuser == NULL) {
+       if (!conf->firstuser) {
                /* Fill the first new User struct */
                user->user_no = 1;
                /* Fill the first new User struct */
                user->user_no = 1;
-               user->nextuser = NULL;
-               user->prevuser = NULL;
                conf->firstuser = user;
                conf->lastuser = user;
        } else {
                /* Fill the new user struct */  
                user->user_no = conf->lastuser->user_no + 1; 
                user->prevuser = conf->lastuser;
                conf->firstuser = user;
                conf->lastuser = user;
        } else {
                /* Fill the new user struct */  
                user->user_no = conf->lastuser->user_no + 1; 
                user->prevuser = conf->lastuser;
-               user->nextuser = NULL;
-               if (conf->lastuser->nextuser != NULL) {
+               if (conf->lastuser->nextuser) {
                        ast_log(LOG_WARNING, "Error in User Management!\n");
                        ast_mutex_unlock(&conflock);
                        goto outrun;
                        ast_log(LOG_WARNING, "Error in User Management!\n");
                        ast_mutex_unlock(&conflock);
                        goto outrun;
@@ -844,12 +851,14 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
                        conf->lastuser = user;
                }
        }
                        conf->lastuser = user;
                }
        }
+
        user->chan = chan;
        user->userflags = confflags;
        user->adminflags = 0;
        user->talking = -1;
        user->chan = chan;
        user->userflags = confflags;
        user->adminflags = 0;
        user->talking = -1;
+       conf->users++;
        ast_mutex_unlock(&conflock);
        ast_mutex_unlock(&conflock);
-       origquiet = confflags & CONFFLAG_QUIET;
+
        if (confflags & CONFFLAG_EXIT_CONTEXT) {
                if ((agifile = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT"))) 
                        ast_copy_string(exitcontext, agifile, sizeof(exitcontext));
        if (confflags & CONFFLAG_EXIT_CONTEXT) {
                if ((agifile = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT"))) 
                        ast_copy_string(exitcontext, agifile, sizeof(exitcontext));
@@ -860,12 +869,12 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
        }
 
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER)) {
        }
 
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER)) {
-               snprintf(user->namerecloc,sizeof(user->namerecloc),"%s/meetme/meetme-username-%s-%d",ast_config_AST_SPOOL_DIR,conf->confno,user->user_no);
-               ast_record_review(chan,"vm-rec-name",user->namerecloc, 10,"sln", &duration, NULL);
+               snprintf(user->namerecloc, sizeof(user->namerecloc),
+                        "%s/meetme/meetme-username-%s-%d", ast_config_AST_SPOOL_DIR,
+                        conf->confno, user->user_no);
+               ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
        }
 
        }
 
-       conf->users++;
-
        if (!(confflags & CONFFLAG_QUIET)) {
                if (conf->users == 1 && !(confflags & CONFFLAG_WAITMARKED))
                        if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
        if (!(confflags & CONFFLAG_QUIET)) {
                if (conf->users == 1 && !(confflags & CONFFLAG_WAITMARKED))
                        if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
@@ -876,7 +885,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
        }
 
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_ANNOUNCEUSERCOUNT) && conf->users > 1) {
        }
 
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_ANNOUNCEUSERCOUNT) && conf->users > 1) {
-               int keepplaying=1;
+               int keepplaying = 1;
 
                if (conf->users == 2) { 
                        if (!ast_streamfile(chan,"conf-onlyone",chan->language)) {
 
                if (conf->users == 2) { 
                        if (!ast_streamfile(chan,"conf-onlyone",chan->language)) {
@@ -911,21 +920,21 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
                }
        }
 
                }
        }
 
-       /* Set it into linear mode (write) */
        if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
                goto outrun;
        }
 
        if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
                goto outrun;
        }
 
-       /* Set it into linear mode (read) */
        if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
                goto outrun;
        }
        if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
                ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
                goto outrun;
        }
+
        ast_indicate(chan, -1);
        retryzap = strcasecmp(chan->type, "Zap");
        user->zapchannel = !retryzap;
        ast_indicate(chan, -1);
        retryzap = strcasecmp(chan->type, "Zap");
        user->zapchannel = !retryzap;
-zapretry:
+
+ zapretry:
        origfd = chan->fds[0];
        if (retryzap) {
                fd = open("/dev/zap/pseudo", O_RDWR);
        origfd = chan->fds[0];
        if (retryzap) {
                fd = open("/dev/zap/pseudo", O_RDWR);
@@ -990,7 +999,9 @@ zapretry:
        /* Add us to the conference */
        ztc.chan = 0;   
        ztc.confno = conf->zapconf;
        /* Add us to the conference */
        ztc.chan = 0;   
        ztc.confno = conf->zapconf;
+
        ast_mutex_lock(&conflock);
        ast_mutex_lock(&conflock);
+
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER) && conf->users > 1) {
                if (conf->chan && ast_fileexists(user->namerecloc, NULL, NULL)) {
                        if (!ast_streamfile(conf->chan, user->namerecloc, chan->language))
        if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_INTROUSER) && conf->users > 1) {
                if (conf->chan && ast_fileexists(user->namerecloc, NULL, NULL)) {
                        if (!ast_streamfile(conf->chan, user->namerecloc, chan->language))
@@ -1016,11 +1027,11 @@ zapretry:
        ast_log(LOG_DEBUG, "Placed channel %s in ZAP conf %d\n", chan->name, conf->zapconf);
 
        manager_event(EVENT_FLAG_CALL, "MeetmeJoin", 
        ast_log(LOG_DEBUG, "Placed channel %s in ZAP conf %d\n", chan->name, conf->zapconf);
 
        manager_event(EVENT_FLAG_CALL, "MeetmeJoin", 
-                       "Channel: %s\r\n"
-                       "Uniqueid: %s\r\n"
-                       "Meetme: %s\r\n"
-                       "Usernum: %d\r\n",
-                       chan->name, chan->uniqueid, conf->confno, user->user_no);
+                     "Channel: %s\r\n"
+                     "Uniqueid: %s\r\n"
+                     "Meetme: %s\r\n"
+                     "Usernum: %d\r\n",
+                     chan->name, chan->uniqueid, conf->confno, user->user_no);
 
        if (!firstpass && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN)) {
                firstpass = 1;
 
        if (!firstpass && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN)) {
                firstpass = 1;
@@ -1028,21 +1039,23 @@ zapretry:
                        if (!(confflags & CONFFLAG_WAITMARKED) || (conf->markedusers >= 1))
                                conf_play(chan, conf, ENTER);
        }
                        if (!(confflags & CONFFLAG_WAITMARKED) || (conf->markedusers >= 1))
                                conf_play(chan, conf, ENTER);
        }
-       conf_flush(fd);
+
        ast_mutex_unlock(&conflock);
        ast_mutex_unlock(&conflock);
-       if (confflags & CONFFLAG_AGI) {
 
 
+       conf_flush(fd);
+
+       if (confflags & CONFFLAG_AGI) {
                /* Get name of AGI file to run from $(MEETME_AGI_BACKGROUND)
                /* Get name of AGI file to run from $(MEETME_AGI_BACKGROUND)
-                 or use default filename of conf-background.agi */
+                  or use default filename of conf-background.agi */
 
 
-               agifile = pbx_builtin_getvar_helper(chan,"MEETME_AGI_BACKGROUND");
+               agifile = pbx_builtin_getvar_helper(chan, "MEETME_AGI_BACKGROUND");
                if (!agifile)
                        agifile = agifiledefault;
 
                if (user->zapchannel) {
                        /*  Set CONFMUTE mode on Zap channel to mute DTMF tones */
                        x = 1;
                if (!agifile)
                        agifile = agifiledefault;
 
                if (user->zapchannel) {
                        /*  Set CONFMUTE mode on Zap channel to mute DTMF tones */
                        x = 1;
-                       ast_channel_setoption(chan,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
+                       ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
                }
                /* Find a pointer to the agi app and execute the script */
                app = pbx_findapp("agi");
                }
                /* Find a pointer to the agi app and execute the script */
                app = pbx_findapp("agi");
@@ -1055,15 +1068,15 @@ zapretry:
                if (user->zapchannel) {
                        /*  Remove CONFMUTE mode on Zap channel */
                        x = 0;
                if (user->zapchannel) {
                        /*  Remove CONFMUTE mode on Zap channel */
                        x = 0;
-                       ast_channel_setoption(chan,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
+                       ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
                }
        } else {
                if (user->zapchannel && (confflags & CONFFLAG_STARMENU)) {
                        /*  Set CONFMUTE mode on Zap channel to mute DTMF tones when the menu is enabled */
                        x = 1;
                }
        } else {
                if (user->zapchannel && (confflags & CONFFLAG_STARMENU)) {
                        /*  Set CONFMUTE mode on Zap channel to mute DTMF tones when the menu is enabled */
                        x = 1;
-                       ast_channel_setoption(chan,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
+                       ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
                }       
                }       
-               if (confflags &  CONFFLAG_MONITORTALKER && !(dsp = ast_dsp_new())) {
+               if (confflags & CONFFLAG_MONITORTALKER && !(dsp = ast_dsp_new())) {
                        ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
                        res = -1;
                }
                        ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
                        res = -1;
                }
@@ -1082,7 +1095,10 @@ zapretry:
                        menu_was_active = menu_active;
 
                        currentmarked = conf->markedusers;
                        menu_was_active = menu_active;
 
                        currentmarked = conf->markedusers;
-                       if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_MARKEDUSER) && (confflags & CONFFLAG_WAITMARKED) && lastmarked == 0) {
+                       if (!(confflags & CONFFLAG_QUIET) &&
+                           (confflags & CONFFLAG_MARKEDUSER) &&
+                           (confflags & CONFFLAG_WAITMARKED) &&
+                           lastmarked == 0) {
                                if (currentmarked == 1 && conf->users > 1) {
                                        ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
                                        if (conf->users - 1 == 1) {
                                if (currentmarked == 1 && conf->users > 1) {
                                        ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
                                        if (conf->users - 1 == 1) {
@@ -1232,6 +1248,7 @@ zapretry:
 
                                        if (confflags &  CONFFLAG_MONITORTALKER) {
                                                int totalsilence;
 
                                        if (confflags &  CONFFLAG_MONITORTALKER) {
                                                int totalsilence;
+
                                                if (user->talking == -1)
                                                        user->talking = 0;
 
                                                if (user->talking == -1)
                                                        user->talking = 0;
 
@@ -1239,20 +1256,20 @@ zapretry:
                                                if (!user->talking && totalsilence < MEETME_DELAYDETECTTALK) {
                                                        user->talking = 1;
                                                        manager_event(EVENT_FLAG_CALL, "MeetmeTalking",
                                                if (!user->talking && totalsilence < MEETME_DELAYDETECTTALK) {
                                                        user->talking = 1;
                                                        manager_event(EVENT_FLAG_CALL, "MeetmeTalking",
-                                                               "Channel: %s\r\n"
-                                                               "Uniqueid: %s\r\n"
-                                                               "Meetme: %s\r\n"
-                                                               "Usernum: %d\r\n",
-                                                               chan->name, chan->uniqueid, conf->confno, user->user_no);
+                                                                     "Channel: %s\r\n"
+                                                                     "Uniqueid: %s\r\n"
+                                                                     "Meetme: %s\r\n"
+                                                                     "Usernum: %d\r\n",
+                                                                     chan->name, chan->uniqueid, conf->confno, user->user_no);
                                                }
                                                if (user->talking && totalsilence > MEETME_DELAYDETECTENDTALK) {
                                                        user->talking = 0;
                                                        manager_event(EVENT_FLAG_CALL, "MeetmeStopTalking",
                                                }
                                                if (user->talking && totalsilence > MEETME_DELAYDETECTENDTALK) {
                                                        user->talking = 0;
                                                        manager_event(EVENT_FLAG_CALL, "MeetmeStopTalking",
-                                                               "Channel: %s\r\n"
-                                                               "Uniqueid: %s\r\n"
-                                                               "Meetme: %s\r\n"
-                                                               "Usernum: %d\r\n",
-                                                               chan->name, chan->uniqueid, conf->confno, user->user_no);
+                                                                     "Channel: %s\r\n"
+                                                                     "Uniqueid: %s\r\n"
+                                                                     "Meetme: %s\r\n"
+                                                                     "Usernum: %d\r\n",
+                                                                     chan->name, chan->uniqueid, conf->confno, user->user_no);
                                                }
                                        }
                                        if (using_pseudo) {
                                                }
                                        }
                                        if (using_pseudo) {
@@ -1261,6 +1278,7 @@ zapretry:
                                        }
                                } else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT)) {
                                        char tmp[2];
                                        }
                                } else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT)) {
                                        char tmp[2];
+
                                        tmp[0] = f->subclass;
                                        tmp[1] = '\0';
                                        if (ast_goto_if_exists(chan, exitcontext, tmp, 1)) {
                                        tmp[0] = f->subclass;
                                        tmp[1] = '\0';
                                        if (ast_goto_if_exists(chan, exitcontext, tmp, 1)) {
@@ -1275,7 +1293,6 @@ zapretry:
                                        if (ioctl(fd, ZT_SETCONF, &ztc_empty)) {
                                                ast_log(LOG_WARNING, "Error setting conference\n");
                                                close(fd);
                                        if (ioctl(fd, ZT_SETCONF, &ztc_empty)) {
                                                ast_log(LOG_WARNING, "Error setting conference\n");
                                                close(fd);
-                                               ast_mutex_unlock(&conflock);
                                                goto outrun;
                                        }
 
                                                goto outrun;
                                        }
 
@@ -1293,7 +1310,7 @@ zapretry:
                                                if (!menu_active) {
                                                        menu_active = 1;
                                                        /* Record this sound! */
                                                if (!menu_active) {
                                                        menu_active = 1;
                                                        /* Record this sound! */
-                                                        if (!ast_streamfile(chan, "conf-adminmenu", chan->language))
+                                                       if (!ast_streamfile(chan, "conf-adminmenu", chan->language))
                                                                dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
                                                        else 
                                                                dtmf = 0;
                                                                dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
                                                        else 
                                                                dtmf = 0;
@@ -1345,27 +1362,21 @@ zapretry:
                                                                        usr->adminflags |= ADMINFLAG_KICKME;
                                                                ast_stopstream(chan);
                                                                break;  
                                                                        usr->adminflags |= ADMINFLAG_KICKME;
                                                                ast_stopstream(chan);
                                                                break;  
-
                                                        case '4':
                                                                tweak_listen_volume(user, VOL_DOWN);
                                                                break;
                                                        case '4':
                                                                tweak_listen_volume(user, VOL_DOWN);
                                                                break;
-
                                                        case '6':
                                                                tweak_listen_volume(user, VOL_UP);
                                                                break;
                                                        case '6':
                                                                tweak_listen_volume(user, VOL_UP);
                                                                break;
-
                                                        case '7':
                                                                tweak_talk_volume(user, VOL_DOWN);
                                                                break;
                                                        case '7':
                                                                tweak_talk_volume(user, VOL_DOWN);
                                                                break;
-                                                               
                                                        case '8':
                                                                menu_active = 0;
                                                                break;
                                                        case '8':
                                                                menu_active = 0;
                                                                break;
-                                                               
                                                        case '9':
                                                                tweak_talk_volume(user, VOL_UP);
                                                                break;
                                                        case '9':
                                                                tweak_talk_volume(user, VOL_UP);
                                                                break;
-                                                               
                                                        default:
                                                                menu_active = 0;
                                                                /* Play an error message! */
                                                        default:
                                                                menu_active = 0;
                                                                /* Play an error message! */
@@ -1378,7 +1389,6 @@ zapretry:
                                                /* User menu */
                                                if (!menu_active) {
                                                        menu_active = 1;
                                                /* User menu */
                                                if (!menu_active) {
                                                        menu_active = 1;
-                                                       /* Record this sound! */
                                                        if (!ast_streamfile(chan, "conf-usermenu", chan->language))
                                                                dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
                                                        else
                                                        if (!ast_streamfile(chan, "conf-usermenu", chan->language))
                                                                dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
                                                        else
@@ -1387,60 +1397,53 @@ zapretry:
                                                        dtmf = f->subclass;
                                                if (dtmf) {
                                                        switch(dtmf) {
                                                        dtmf = f->subclass;
                                                if (dtmf) {
                                                        switch(dtmf) {
-                                                               case '1': /* Un/Mute */
-                                                                       menu_active = 0;
-                                                                       if (ztc.confmode & ZT_CONF_TALKER) {
+                                                       case '1': /* Un/Mute */
+                                                               menu_active = 0;
+                                                               if (ztc.confmode & ZT_CONF_TALKER) {
                                                                        ztc.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
                                                                        confflags |= CONFFLAG_MONITOR ^ CONFFLAG_TALKER;
                                                                        ztc.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
                                                                        confflags |= CONFFLAG_MONITOR ^ CONFFLAG_TALKER;
-                                                                       } else if (!(user->adminflags & ADMINFLAG_MUTED)) {
-                                                                               ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
-                                                                               confflags ^= CONFFLAG_MONITOR | CONFFLAG_TALKER;
-                                                                       }
-                                                                       if (ioctl(fd, ZT_SETCONF, &ztc)) {
-                                                                               ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
-                                                                               ret = -1;
-                                                                               break;
-                                                                       }
-                                                                       if (ztc.confmode & ZT_CONF_TALKER) {
-                                                                               if (!ast_streamfile(chan, "conf-unmuted", chan->language))
-                                                                                       ast_waitstream(chan, "");
-                                                                       } else {
-                                                                               if (!ast_streamfile(chan, "conf-muted", chan->language))
-                                                                                       ast_waitstream(chan, "");
-                                                                       }
+                                                               } else if (!(user->adminflags & ADMINFLAG_MUTED)) {
+                                                                       ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
+                                                                       confflags ^= CONFFLAG_MONITOR | CONFFLAG_TALKER;
+                                                               }
+                                                               if (ioctl(fd, ZT_SETCONF, &ztc)) {
+                                                                       ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
+                                                                       ret = -1;
                                                                        break;
                                                                        break;
+                                                               }
+                                                               if (ztc.confmode & ZT_CONF_TALKER) {
+                                                                       if (!ast_streamfile(chan, "conf-unmuted", chan->language))
+                                                                               ast_waitstream(chan, "");
+                                                               } else {
+                                                                       if (!ast_streamfile(chan, "conf-muted", chan->language))
+                                                                               ast_waitstream(chan, "");
+                                                               }
+                                                               break;
                                                        case '4':
                                                                tweak_listen_volume(user, VOL_DOWN);
                                                                break;
                                                        case '4':
                                                                tweak_listen_volume(user, VOL_DOWN);
                                                                break;
-
                                                        case '6':
                                                                tweak_listen_volume(user, VOL_UP);
                                                                break;
                                                        case '6':
                                                                tweak_listen_volume(user, VOL_UP);
                                                                break;
-
                                                        case '7':
                                                                tweak_talk_volume(user, VOL_DOWN);
                                                                break;
                                                        case '7':
                                                                tweak_talk_volume(user, VOL_DOWN);
                                                                break;
-
                                                        case '8':
                                                                menu_active = 0;
                                                                break;
                                                        case '8':
                                                                menu_active = 0;
                                                                break;
-
                                                        case '9':
                                                                tweak_talk_volume(user, VOL_UP);
                                                                break;
                                                        case '9':
                                                                tweak_talk_volume(user, VOL_UP);
                                                                break;
-
                                                        default:
                                                                menu_active = 0;
                                                        default:
                                                                menu_active = 0;
-                                                               /* Play an error message! */
                                                                if (!ast_streamfile(chan, "conf-errormenu", chan->language))
                                                                        ast_waitstream(chan, "");
                                                                break;
                                                        }
                                                }
                                        }
                                                                if (!ast_streamfile(chan, "conf-errormenu", chan->language))
                                                                        ast_waitstream(chan, "");
                                                                break;
                                                        }
                                                }
                                        }
-                                       if (musiconhold) {
+                                       if (musiconhold)
                                                ast_moh_start(chan, NULL);
                                                ast_moh_start(chan, NULL);
-                                       }
 
                                        if (ioctl(fd, ZT_SETCONF, &ztc)) {
                                                ast_log(LOG_WARNING, "Error setting conference\n");
 
                                        if (ioctl(fd, ZT_SETCONF, &ztc)) {
                                                ast_log(LOG_WARNING, "Error setting conference\n");
@@ -1450,7 +1453,9 @@ zapretry:
                                        }
                                        conf_flush(fd);
                                } else if (option_debug) {
                                        }
                                        conf_flush(fd);
                                } else if (option_debug) {
-                                       ast_log(LOG_DEBUG, "Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",chan->name,f->frametype,f->subclass);
+                                       ast_log(LOG_DEBUG,
+                                               "Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",
+                                               chan->name, f->frametype, f->subclass);
                                }
                                ast_frfree(f);
                        } else if (outfd > -1) {
                                }
                                ast_frfree(f);
                        } else if (outfd > -1) {
@@ -1467,7 +1472,6 @@ zapretry:
                                                ast_frame_adjust_volume(&fr, user->listen.actual);
                                        if (ast_write(chan, &fr) < 0) {
                                                ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
                                                ast_frame_adjust_volume(&fr, user->listen.actual);
                                        if (ast_write(chan, &fr) < 0) {
                                                ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
-                                               /* break; */
                                        }
                                } else 
                                        ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
                                        }
                                } else 
                                        ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
@@ -1506,9 +1510,9 @@ zapretry:
        }
        ast_mutex_unlock(&conflock);
 
        }
        ast_mutex_unlock(&conflock);
 
-
-outrun:
+ outrun:
        ast_mutex_lock(&conflock);
        ast_mutex_lock(&conflock);
+
        if (confflags & CONFFLAG_MONITORTALKER && dsp)
                ast_dsp_free(dsp);
        
        if (confflags & CONFFLAG_MONITORTALKER && dsp)
                ast_dsp_free(dsp);
        
@@ -1560,6 +1564,7 @@ outrun:
        }
        free(user);
        ast_mutex_unlock(&conflock);
        }
        free(user);
        ast_mutex_unlock(&conflock);
+
        return ret;
 }
 
        return ret;
 }
 
@@ -1571,11 +1576,9 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
 
        /* Check first in the conference list */
        ast_mutex_lock(&conflock);
 
        /* Check first in the conference list */
        ast_mutex_lock(&conflock);
-       cnf = confs;
-       while (cnf) {
+       for (cnf = confs; cnf; cnf = cnf->next) {
                if (!strcmp(confno, cnf->confno)) 
                        break;
                if (!strcmp(confno, cnf->confno)) 
                        break;
-               cnf = cnf->next;
        }
        ast_mutex_unlock(&conflock);
 
        }
        ast_mutex_unlock(&conflock);
 
@@ -1600,7 +1603,7 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
                                return NULL;
                        }
                        var = ast_variable_browse(cfg, "rooms");
                                return NULL;
                        }
                        var = ast_variable_browse(cfg, "rooms");
-                       while(var) {
+                       while (var) {
                                if (!strcasecmp(var->name, "conf")) {
                                        /* Separate the PIN */
                                        char *pin, *pinadmin, *conf;
                                if (!strcasecmp(var->name, "conf")) {
                                        /* Separate the PIN */
                                        char *pin, *pinadmin, *conf;
@@ -1638,6 +1641,7 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
                if (dynamic_pin[0] == 'q')
                        dynamic_pin[0] = '\0';
        }
                if (dynamic_pin[0] == 'q')
                        dynamic_pin[0] = '\0';
        }
+
        return cnf;
 }
 
        return cnf;
 }
 
@@ -1674,14 +1678,15 @@ static int count_exec(struct ast_channel *chan, void *data)
 
        if (!ast_strlen_zero(localdata)){
                /* have var so load it and exit */
 
        if (!ast_strlen_zero(localdata)){
                /* have var so load it and exit */
-               snprintf(val,sizeof(val), "%d",count);
-               pbx_builtin_setvar_helper(chan, localdata,val);
+               snprintf(val, sizeof(val), "%d",count);
+               pbx_builtin_setvar_helper(chan, localdata, val);
        } else {
                if (chan->_state != AST_STATE_UP)
                        ast_answer(chan);
                res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */
        }
        LOCAL_USER_REMOVE(u);
        } else {
                if (chan->_state != AST_STATE_UP)
                        ast_answer(chan);
                res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */
        }
        LOCAL_USER_REMOVE(u);
+
        return res;
 }
 
        return res;
 }
 
@@ -1767,7 +1772,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
                                cfg = ast_config_load("meetme.conf");
                                if (cfg) {
                                        var = ast_variable_browse(cfg, "rooms");
                                cfg = ast_config_load("meetme.conf");
                                if (cfg) {
                                        var = ast_variable_browse(cfg, "rooms");
-                                       while(var) {
+                                       while (var) {
                                                if (!strcasecmp(var->name, "conf")) {
                                                        char *stringp = ast_strdupa(var->value);
                                                        if (stringp) {
                                                if (!strcasecmp(var->name, "conf")) {
                                                        char *stringp = ast_strdupa(var->value);
                                                        if (stringp) {
@@ -1780,7 +1785,7 @@ 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 */
                                                                        ast_mutex_lock(&conflock);
                                                                        cnf = confs;
                                                                        /* For static:  run through the list and see if this conference is empty */
                                                                        ast_mutex_lock(&conflock);
                                                                        cnf = confs;
@@ -1796,10 +1801,10 @@ static int conf_exec(struct ast_channel *chan, void *data)
                                                                        if (!found) {
                                                                                /* 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 (!found) {
                                                                                /* 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)) {
-                                                                               /* Case 1:  empty_no_pin and pin is nonexistent (NULL)
-                                                                                * Case 2:  empty_no_pin and pin is blank (but not NULL)
-                                                                                * Case 3:  not empty_no_pin
-                                                                                */
+                                                                                       /* Case 1:  empty_no_pin and pin is nonexistent (NULL)
+                                                                                        * Case 2:  empty_no_pin and pin is blank (but not NULL)
+                                                                                        * Case 3:  not empty_no_pin
+                                                                                        */
                                                                                        ast_copy_string(confno, confno_tmp, sizeof(confno));
                                                                                        break;
                                                                                        /* XXX the map is not complete (but we do have a confno) */
                                                                                        ast_copy_string(confno, confno_tmp, sizeof(confno));
                                                                                        break;
                                                                                        /* XXX the map is not complete (but we do have a confno) */
@@ -1863,13 +1868,16 @@ static int conf_exec(struct ast_channel *chan, void *data)
                                if (allowretry)
                                        confno[0] = '\0';
                        } else {
                                if (allowretry)
                                        confno[0] = '\0';
                        } else {
-                               if ((!ast_strlen_zero(cnf->pin) &&  !ast_test_flag(&confflags, CONFFLAG_ADMIN)) || (!ast_strlen_zero(cnf->pinadmin) && ast_test_flag(&confflags, CONFFLAG_ADMIN))) {
+                               if ((!ast_strlen_zero(cnf->pin) &&
+                                    !ast_test_flag(&confflags, CONFFLAG_ADMIN)) ||
+                                   (!ast_strlen_zero(cnf->pinadmin) &&
+                                    ast_test_flag(&confflags, CONFFLAG_ADMIN))) {
                                        char pin[AST_MAX_EXTENSION]="";
                                        int j;
 
                                        /* Allow the pin to be retried up to 3 times */
                                        char pin[AST_MAX_EXTENSION]="";
                                        int j;
 
                                        /* Allow the pin to be retried up to 3 times */
-                                       for (j=0; j<3; j++) {
-                                               if (*the_pin && (always_prompt==0)) {
+                                       for (j = 0; j < 3; j++) {
+                                               if (*the_pin && (always_prompt == 0)) {
                                                        ast_copy_string(pin, the_pin, sizeof(pin));
                                                        res = 0;
                                                } else {
                                                        ast_copy_string(pin, the_pin, sizeof(pin));
                                                        res = 0;
                                                } else {
@@ -1877,8 +1885,9 @@ static int conf_exec(struct ast_channel *chan, void *data)
                                                        res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
                                                }
                                                if (res >= 0) {
                                                        res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
                                                }
                                                if (res >= 0) {
-                                                       if (!strcasecmp(pin, cnf->pin)  || (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin))) {
-
+                                                       if (!strcasecmp(pin, cnf->pin) ||
+                                                           (!ast_strlen_zero(cnf->pinadmin) &&
+                                                            !strcasecmp(pin, cnf->pinadmin))) {
                                                                /* Pin correct */
                                                                allowretry = 0;
                                                                if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin)) 
                                                                /* Pin correct */
                                                                allowretry = 0;
                                                                if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin)) 
@@ -1936,9 +1945,10 @@ static int conf_exec(struct ast_channel *chan, void *data)
 static struct ast_conf_user* find_user(struct ast_conference *conf, char *callerident) {
        struct ast_conf_user *user = NULL;
        char usrno[1024] = "";
 static struct ast_conf_user* find_user(struct ast_conference *conf, char *callerident) {
        struct ast_conf_user *user = NULL;
        char usrno[1024] = "";
+
        if (conf && callerident) {
                user = conf->firstuser;
        if (conf && callerident) {
                user = conf->firstuser;
-               while(user) {
+               while (user) {
                        snprintf(usrno, sizeof(usrno), "%d", user->user_no);
                        if (strcmp(usrno, callerident) == 0)
                                return user;
                        snprintf(usrno, sizeof(usrno), "%d", user->user_no);
                        if (strcmp(usrno, callerident) == 0)
                                return user;
@@ -1972,11 +1982,9 @@ static int admin_exec(struct ast_channel *chan, void *data) {
                        LOCAL_USER_REMOVE(u);
                        return -1;
                }
                        LOCAL_USER_REMOVE(u);
                        return -1;
                }
-               cnf = confs;
-               while (cnf) {
-                       if (strcmp(cnf->confno, conf) == 0) 
+               for (cnf = confs; cnf; cnf = cnf->next) {
+                       if (!strcmp(cnf->confno, conf))
                                break;
                                break;
-                       cnf = cnf->next;
                }
                
                if (caller)
                }
                
                if (caller)
@@ -1984,77 +1992,77 @@ static int admin_exec(struct ast_channel *chan, void *data) {
                
                if (cnf) {
                        switch((int) (*command)) {
                
                if (cnf) {
                        switch((int) (*command)) {
-                               case 76: /* L: Lock */ 
-                                       cnf->locked = 1;
-                                       break;
-                               case 108: /* l: Unlock */ 
-                                       cnf->locked = 0;
-                                       break;
-                               case 75: /* K: kick all users*/
-                                       user = cnf->firstuser;
-                                       while(user) {
-                                               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->adminflags |= ADMINFLAG_KICKME;
+                       case 76: /* L: Lock */ 
+                               cnf->locked = 1;
+                               break;
+                       case 108: /* l: Unlock */ 
+                               cnf->locked = 0;
+                               break;
+                       case 75: /* K: kick all users*/
+                               user = cnf->firstuser;
+                               while(user) {
+                                       user->adminflags |= ADMINFLAG_KICKME;
+                                       if (user->nextuser) {
+                                               user = user->nextuser;
+                                       } else {
                                                break;
                                                break;
-                                       } else
-                                               ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
+                                       }
+                               }
+                               break;
+                       case 101: /* e: Eject last user*/
+                               user = cnf->lastuser;
+                               if (!(user->userflags & CONFFLAG_ADMIN)) {
+                                       user->adminflags |= ADMINFLAG_KICKME;
                                        break;
                                        break;
-                               case 77: /* M: Mute */ 
-                                       if (user) {
+                               } else
+                                       ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
+                               break;
+                       case 77: /* M: Mute */ 
+                               if (user) {
+                                       user->adminflags |= ADMINFLAG_MUTED;
+                               } else {
+                                       ast_log(LOG_NOTICE, "Specified User not found!\n");
+                               }
+                               break;
+                       case 78: /* N: Mute all users */
+                               user = cnf->firstuser;
+                               while(user) {
+                                       if (user && !(user->userflags & CONFFLAG_ADMIN))
                                                user->adminflags |= ADMINFLAG_MUTED;
                                                user->adminflags |= ADMINFLAG_MUTED;
+                                       if (user->nextuser) {
+                                               user = user->nextuser;
                                        } else {
                                        } else {
-                                               ast_log(LOG_NOTICE, "Specified User not found!\n");
-                                       }
-                                       break;
-                               case 78: /* N: Mute all users */
-                                       user = cnf->firstuser;
-                                       while(user) {
-                                               if (user && !(user->userflags & CONFFLAG_ADMIN))
-                                                       user->adminflags |= ADMINFLAG_MUTED;
-                                               if (user->nextuser) {
-                                                       user = user->nextuser;
-                                               } else {
-                                                       break;
-                                               }
+                                               break;
                                        }
                                        }
-                                       break;                                  
-                               case 109: /* m: Unmute */ 
-                                       if (user && (user->adminflags & ADMINFLAG_MUTED)) {
+                               }
+                               break;                                  
+                       case 109: /* m: Unmute */ 
+                               if (user && (user->adminflags & ADMINFLAG_MUTED)) {
+                                       user->adminflags ^= ADMINFLAG_MUTED;
+                               } else {
+                                       ast_log(LOG_NOTICE, "Specified User not found or he muted himself!");
+                               }
+                               break;
+                       case  110: /* n: Unmute all users */
+                               user = cnf->firstuser;
+                               while(user) {
+                                       if (user && (user-> adminflags & ADMINFLAG_MUTED)) {
                                                user->adminflags ^= ADMINFLAG_MUTED;
                                                user->adminflags ^= ADMINFLAG_MUTED;
-                                       } else {
-                                               ast_log(LOG_NOTICE, "Specified User not found or he muted himself!");
                                        }
                                        }
-                                       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;
-                                               }
-                                       }
-                                       break;
-                               case 107: /* k: Kick user */ 
-                                       if (user) {
-                                               user->adminflags |= ADMINFLAG_KICKME;
+                                       if (user->nextuser) {
+                                               user = user->nextuser;
                                        } else {
                                        } else {
-                                               ast_log(LOG_NOTICE, "Specified User not found!");
+                                               break;
                                        }
                                        }
-                                       break;
+                               }
+                               break;
+                       case 107: /* k: Kick user */ 
+                               if (user) {
+                                       user->adminflags |= ADMINFLAG_KICKME;
+                               } else {
+                                       ast_log(LOG_NOTICE, "Specified User not found!");
+                               }
+                               break;
                        }
                } else {
                        ast_log(LOG_NOTICE, "Conference Number not found\n");
                        }
                } else {
                        ast_log(LOG_NOTICE, "Conference Number not found\n");
@@ -2069,14 +2077,13 @@ static int admin_exec(struct ast_channel *chan, void *data) {
 
 static void *recordthread(void *args)
 {
 
 static void *recordthread(void *args)
 {
-       struct ast_conference *cnf;
+       struct ast_conference *cnf = args;
        struct ast_frame *f=NULL;
        int flags;
        struct ast_filestream *s;
        int res=0;
 
        struct ast_frame *f=NULL;
        int flags;
        struct ast_filestream *s;
        int res=0;
 
-       cnf = (struct ast_conference *)args;
-       if( !cnf || !cnf->chan ) {
+       if (!cnf || !cnf->chan) {
                pthread_exit(0);
        }
        ast_stopstream(cnf->chan);
                pthread_exit(0);
        }
        ast_stopstream(cnf->chan);
@@ -2145,7 +2152,9 @@ char *description(void)
 int usecount(void)
 {
        int res;
 int usecount(void)
 {
        int res;
+
        STANDARD_USECOUNT(res);
        STANDARD_USECOUNT(res);
+
        return res;
 }
 
        return res;
 }