[asterisk-commits] russell: branch russell/sla_rewrite r51338 -
/team/russell/sla_rewrite/apps/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Jan 19 14:04:45 MST 2007
Author: russell
Date: Fri Jan 19 15:04:44 2007
New Revision: 51338
URL: http://svn.digium.com/view/asterisk?view=rev&rev=51338
Log:
Remove current SLA code ... It's easier to start fresh.
Modified:
team/russell/sla_rewrite/apps/app_meetme.c
Modified: team/russell/sla_rewrite/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_rewrite/apps/app_meetme.c?view=diff&rev=51338&r1=51337&r2=51338
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Fri Jan 19 15:04:44 2007
@@ -148,12 +148,6 @@
CONFFLAG_INTROUSERNOREVIEW = (1 << 23),
/*! If set, the user will be initially self-muted */
CONFFLAG_STARTMUTED = (1 << 24),
- /*! If set, the user is a shared line appearance station */
- CONFFLAG_SLA_STATION = (1 << 25),
- /*! If set, the user is a shared line appearance trunk */
- CONFFLAG_SLA_TRUNK = (1 << 26),
- /*! If set, the user has put us on hold */
- CONFFLAG_HOLD = (1 << 27)
};
enum {
@@ -195,14 +189,10 @@
static const char *app = "MeetMe";
static const char *app2 = "MeetMeCount";
static const char *app3 = "MeetMeAdmin";
-static const char *appslas = "SLAStation";
-static const char *appslat = "SLATrunk";
static const char *synopsis = "MeetMe conference bridge";
static const char *synopsis2 = "MeetMe participant count";
static const char *synopsis3 = "MeetMe conference Administration";
-static const char *synopslas = "Shared Line Appearance - Station";
-static const char *synopslat = "Shared Line Appearance - Trunk";
static const char *descrip =
" MeetMe([confno][,[options][,pin]]): Enters the user into a specified MeetMe\n"
@@ -281,20 +271,7 @@
" 'V' -- Raise entire conference listening volume\n"
"";
-static const char *descripslas =
-" SLAStation(sla[,options]): Run Shared Line Appearance for station\n"
-"Runs the share line appearance for a station calling in. If there are no\n"
-"other participants in the conference, the trunk is called and is dumped into\n"
-"the bridge.\n";
-
-static const char *descripslat =
-" SLATrunk(sla[,options]): Run Shared Line Appearance for trunk\n"
-"Runs the share line appearance for a trunk calling in. If there are no\n"
-"other participants in the conference, all member stations are invited into\n"
-"the bridge.\n";
-
#define CONFIG_FILE_NAME "meetme.conf"
-#define CONFIG_FILE_NAME_SLA "sla.conf"
/*! \brief The MeetMe Conference object */
struct ast_conference {
@@ -341,39 +318,11 @@
int zapchannel; /*!< Is a Zaptel channel */
char usrvalue[50]; /*!< Custom User Value */
char namerecloc[PATH_MAX]; /*!< Name Recorded file Location */
- int control; /*! Queue Control for transmission */
- int dtmf; /*! Queue DTMF for transmission */
time_t jointime; /*!< Time the user joined the conference */
struct volume talk;
struct volume listen;
AST_LIST_ENTRY(ast_conf_user) list;
};
-
-/*! SLA station - one device in an SLA configuration */
-struct ast_sla_station {
- ASTOBJ_COMPONENTS(struct ast_sla_station);
- char *dest;
- char tech[0];
-};
-
-struct ast_sla_station_box {
- ASTOBJ_CONTAINER_COMPONENTS(struct ast_sla_station);
-};
-
-/*! SLA - Shared Line Apperance object. These consist of one trunk (outbound line)
- and stations that receive incoming calls and place outbound calls over the trunk
-*/
-struct ast_sla {
- ASTOBJ_COMPONENTS (struct ast_sla);
- struct ast_sla_station_box stations; /*!< Stations connected to this SLA */
- char confname[80]; /*!< Name for this SLA bridge */
- char trunkdest[256]; /*!< Device (channel) identifier for the trunk line */
- char trunktech[20]; /*!< Technology used for the trunk (channel driver) */
-};
-
-struct ast_sla_box {
- ASTOBJ_CONTAINER_COMPONENTS(struct ast_sla);
-} slas;
static int audio_buffers; /*!< The number of audio buffers to be allocated on pseudo channels
when in a conference
@@ -566,18 +515,6 @@
if (!res)
ast_autoservice_stop(chan);
-}
-
-static void station_destroy(struct ast_sla_station *station)
-{
- free(station);
-}
-
-static void sla_destroy(struct ast_sla *sla)
-{
- ASTOBJ_CONTAINER_DESTROYALL(&sla->stations, station_destroy);
- ASTOBJ_CONTAINER_DESTROY(&sla->stations);
- free(sla);
}
static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin, int make, int dynamic, int refcount)
@@ -661,31 +598,6 @@
return cnf;
}
-/*! \brief CLI command for showing SLAs */
-static int sla_show(int fd, int argc, char *argv[])
-{
- struct ast_sla *sla;
- if (argc != 2)
- return RESULT_SHOWUSAGE;
-
- ast_cli(fd, "Shared line appearances:\n");
- ASTOBJ_CONTAINER_TRAVERSE(&slas, 1, {
- ASTOBJ_RDLOCK(iterator);
- ast_cli(fd, "SLA %s\n", iterator->name);
- if (ast_strlen_zero(iterator->trunkdest) || ast_strlen_zero(iterator->trunktech))
- ast_cli(fd, " Trunk => <unspecified>\n");
- else
- ast_cli(fd, " Trunk => %s/%s\n", iterator->trunktech, iterator->trunkdest);
- sla = iterator;
- ASTOBJ_CONTAINER_TRAVERSE(&sla->stations, 1, {
- ast_cli(fd, " Station: %s/%s\n", iterator->tech, iterator->dest);
- });
- ASTOBJ_UNLOCK(iterator);
- });
-
- return RESULT_SUCCESS;
-}
-
static int meetme_cmd(int fd, int argc, char **argv)
{
/* Process the command */
@@ -796,7 +708,7 @@
min = ((now - user->jointime) % 3600) / 60;
sec = (now - user->jointime) % 60;
if ( !concise )
- ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %s %02d:%02d:%02d\n",
+ ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %02d:%02d:%02d\n",
user->user_no,
S_OR(user->chan->cid.cid_num, "<unknown>"),
S_OR(user->chan->cid.cid_name, "<no name>"),
@@ -804,8 +716,7 @@
user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
- istalking(user->talking),
- user->userflags & CONFFLAG_HOLD ? " (On Hold) " : "", hr, min, sec);
+ istalking(user->talking), hr, min, sec);
else
ast_cli(fd, "%d!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
user->user_no,
@@ -896,15 +807,7 @@
"Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
" Executes a command for the conference or on a conferee\n";
-static char sla_show_usage[] =
-"Usage: sla show\n"
-" Lists status of all shared line appearances\n";
-
static struct ast_cli_entry cli_meetme[] = {
- { { "sla", "show", NULL },
- sla_show, "Show status of Shared Line Appearances",
- sla_show_usage, NULL },
-
{ { "meetme", NULL, NULL },
meetme_cmd, "Execute a command on a conference or conferee",
meetme_usage, complete_meetmecmd },
@@ -977,23 +880,6 @@
return 0;
}
-
-static void conf_queue_dtmf(struct ast_conference *conf, int digit)
-{
- struct ast_conf_user *user;
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- user->dtmf = digit;
- }
-}
-
-static void conf_queue_control(struct ast_conference *conf, int control)
-{
- struct ast_conf_user *user;
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- user->control = control;
- }
-}
-
static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags, char *optargs[])
{
@@ -1111,8 +997,6 @@
/* This device changed state now - if this is the first user */
if (conf->users == 1)
ast_device_state_changed("meetme:%s", conf->confno);
- if (confflags & (CONFFLAG_SLA_STATION|CONFFLAG_SLA_TRUNK))
- ast_device_state_changed("SLA:%s", conf->confno + 4);
ast_mutex_unlock(&conf->playlock);
@@ -1583,17 +1467,6 @@
if (user->talking || !(confflags & CONFFLAG_OPTIMIZETALKER))
careful_write(fd, f->data, f->datalen, 0);
}
- } else if ((f->frametype == AST_FRAME_DTMF) &&
- (confflags & (CONFFLAG_SLA_STATION|CONFFLAG_SLA_TRUNK))) {
- conf_queue_dtmf(conf, f->subclass);
- } else if ((f->frametype == AST_FRAME_CONTROL) &&
- (confflags & (CONFFLAG_SLA_STATION|CONFFLAG_SLA_TRUNK))) {
- conf_queue_control(conf, f->subclass);
- if (f->subclass == AST_CONTROL_HOLD)
- confflags |= CONFFLAG_HOLD;
- else if (f->subclass == AST_CONTROL_UNHOLD)
- confflags &= ~CONFFLAG_HOLD;
- user->userflags = confflags;
} else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT)) {
char tmp[2];
@@ -1772,33 +1645,6 @@
}
ast_frfree(f);
} else if (outfd > -1) {
- if (user->control) {
- switch(user->control) {
- case AST_CONTROL_RINGING:
- case AST_CONTROL_PROGRESS:
- case AST_CONTROL_PROCEEDING:
- ast_indicate(chan, user->control);
- break;
- case AST_CONTROL_ANSWER:
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- break;
- }
- user->control = 0;
- if (confflags & (CONFFLAG_SLA_STATION|CONFFLAG_SLA_TRUNK))
- ast_device_state_changed("SLA:%s", conf->confno + 4);
- continue;
- }
- if (user->dtmf) {
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_DTMF;
- fr.subclass = user->dtmf;
- if (ast_write(chan, &fr) < 0) {
- ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
- }
- user->dtmf = 0;
- continue;
- }
res = read(outfd, buf, CONF_SIZE);
if (res > 0) {
memset(&fr, 0, sizeof(fr));
@@ -1931,8 +1777,6 @@
/* Change any states */
if (!conf->users)
ast_device_state_changed("meetme:%s", conf->confno);
- if (confflags & (CONFFLAG_SLA_STATION|CONFFLAG_SLA_TRUNK))
- ast_device_state_changed("SLA:%s", conf->confno + 4);
if (AST_LIST_EMPTY(&conf->userlist)) {
/* close this one when no more users and no references*/
@@ -2412,177 +2256,6 @@
ast_module_user_remove(u);
return res;
-}
-
-struct sla_originate_helper {
- char tech[100];
- char data[200];
- char app[20];
- char appdata[100];
- char cid_name[100];
- char cid_num[100];
-};
-
-static void *sla_originate(void *data)
-{
- struct sla_originate_helper *in = data;
- int reason = 0;
- struct ast_channel *chan = NULL;
-
- ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, 99999, in->app, in->appdata, &reason, 1,
- S_OR(in->cid_num, NULL),
- S_OR(in->cid_name, NULL),
- NULL, NULL, &chan);
- /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
- if (chan)
- ast_channel_unlock(chan);
- free(in);
- return NULL;
-}
-
-/*! Call in stations and trunk to the SLA */
-static void do_invite(struct ast_channel *orig, const char *tech, const char *dest, const char *app, const char *data)
-{
- struct sla_originate_helper *slal;
- pthread_attr_t attr;
- pthread_t th;
-
- if (!(slal = ast_calloc(1, sizeof(*slal))))
- return;
-
- ast_copy_string(slal->tech, tech, sizeof(slal->tech));
- ast_copy_string(slal->data, dest, sizeof(slal->data));
- ast_copy_string(slal->app, app, sizeof(slal->app));
- ast_copy_string(slal->appdata, data, sizeof(slal->appdata));
- if (orig->cid.cid_num)
- ast_copy_string(slal->cid_num, orig->cid.cid_num, sizeof(slal->cid_num));
- if (orig->cid.cid_name)
- ast_copy_string(slal->cid_name, orig->cid.cid_name, sizeof(slal->cid_name));
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ast_pthread_create(&th, &attr, sla_originate, slal);
-}
-
-static void invite_stations(struct ast_channel *orig, struct ast_sla *sla)
-{
- ASTOBJ_CONTAINER_TRAVERSE(&sla->stations, 1, {
- do_invite(orig, iterator->tech, iterator->dest, "SLAStation", sla->name);
- });
-}
-
-static void invite_trunk(struct ast_channel *orig, struct ast_sla *sla)
-{
- do_invite(orig, sla->trunktech, sla->trunkdest, "SLATrunk", sla->name);
-}
-
-
-static int sla_checkforhold(struct ast_conference *conf, int hangup)
-{
- struct ast_conf_user *user;
- struct ast_channel *onhold=NULL;
- int holdcount = 0;
- int stationcount = 0;
- int amonhold = 0;
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- if (user->userflags & CONFFLAG_SLA_STATION) {
- stationcount++;
- if ((user->userflags & CONFFLAG_HOLD)) {
- holdcount++;
- onhold = user->chan;
- }
- }
- }
- if ((holdcount == 1) && (stationcount == 1)) {
- amonhold = 1;
- if (hangup)
- ast_softhangup(onhold, AST_SOFTHANGUP_EXPLICIT);
- } else if (holdcount && (stationcount == holdcount))
- amonhold = 1;
- return amonhold;
-}
-
-
-/*! \brief The slas()/slat() application */
-static int sla_exec(struct ast_channel *chan, void *data, int trunk)
-{
- int res=-1;
- struct ast_module_user *u;
- char confno[AST_MAX_EXTENSION] = "";
- struct ast_sla *sla;
- struct ast_conference *cnf;
- char *info;
- struct ast_flags confflags = {0};
- int dynamic = 1;
- char *options[OPT_ARG_ARRAY_SIZE] = { NULL, };
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(confno);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "SLA%c requires an argument (line)\n", trunk ? 'T' : 'S');
- return -1;
- }
-
- info = ast_strdupa(data);
-
- AST_STANDARD_APP_ARGS(args, info);
-
- if (ast_strlen_zero(args.confno)) {
- ast_log(LOG_WARNING, "SLA%c requires an SLA line number\n", trunk ? 'T' : 'S');
- return -1;
- }
-
- u = ast_module_user_add(chan);
-
- if (args.options)
- ast_app_parse_options(sla_opts, &confflags, NULL, args.options);
-
- ast_set_flag(&confflags, CONFFLAG_QUIET|CONFFLAG_DYNAMIC);
- if (trunk)
- ast_set_flag(&confflags, CONFFLAG_WAITMARKED|CONFFLAG_MARKEDEXIT|CONFFLAG_SLA_TRUNK);
- else
- ast_set_flag(&confflags, CONFFLAG_MARKEDUSER|CONFFLAG_SLA_STATION);
-
- sla = ASTOBJ_CONTAINER_FIND(&slas, args.confno);
- if (sla) {
- snprintf(confno, sizeof(confno), "sla-%s", args.confno);
- cnf = find_conf(chan, confno, 1, dynamic, "", 1, &confflags);
- if (cnf) {
- sla_checkforhold(cnf, 1);
- if (!cnf->users) {
- if (trunk) {
- ast_indicate(chan, AST_CONTROL_RINGING);
- invite_stations(chan, sla);
- } else
- invite_trunk(chan, sla);
- } else if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
-
- /* Run the conference */
- res = conf_run(chan, cnf, confflags.flags, options);
- } else
- ast_log(LOG_WARNING, "SLA%c: Found SLA '%s' but unable to build conference!\n", trunk ? 'T' : 'S', args.confno);
- ASTOBJ_UNREF(sla, sla_destroy);
- } else {
- ast_log(LOG_WARNING, "SLA%c: SLA '%s' not found!\n", trunk ? 'T' : 'S', args.confno);
- }
-
- ast_module_user_remove(u);
-
- return res;
-}
-
-/*! \brief The slas() wrapper */
-static int slas_exec(struct ast_channel *chan, void *data)
-{
- return sla_exec(chan, data, 0);
-}
-
-/*! \brief The slat() wrapper */
-static int slat_exec(struct ast_channel *chan, void *data)
-{
- return sla_exec(chan, data, 1);
}
static struct ast_conf_user *find_user(struct ast_conference *conf, char *callerident)
@@ -2909,48 +2582,6 @@
return AST_DEVICE_INUSE;
}
-/*! \brief Callback for devicestate providers */
-static int slastate(const char *data)
-{
- struct ast_conference *conf;
- struct ast_sla *sla, *sla2;
-
- ast_log(LOG_DEBUG, "asked for sla state for '%s'\n", data);
-
- /* Find conference */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, conf, list) {
- if (!strncmp(conf->confno, "sla-", 4) && !strcmp(data, conf->confno + 4))
- break;
- }
- AST_LIST_UNLOCK(&confs);
-
- /* Find conference */
- sla = sla2 = ASTOBJ_CONTAINER_FIND(&slas, data);
-
- if (!sla2)
- return AST_DEVICE_INVALID;
-
- ASTOBJ_UNREF(sla2, sla_destroy);
-
- ast_log(LOG_DEBUG, "for '%s' conf = %p, sla = %p\n", data, conf, sla);
-
- if (!conf && !sla)
- return AST_DEVICE_INVALID;
-
- /* SKREP to fill */
- if (!conf || !conf->users)
- return AST_DEVICE_NOT_INUSE;
-
- if (conf && sla_checkforhold(conf, 0))
- return AST_DEVICE_ONHOLD;
-
- if ((conf->users == 1) && (AST_LIST_FIRST(&conf->userlist)->userflags & CONFFLAG_SLA_TRUNK))
- return AST_DEVICE_RINGING;
-
- return AST_DEVICE_INUSE;
-}
-
static void load_config_meetme(void)
{
struct ast_config *cfg;
@@ -2977,88 +2608,9 @@
ast_config_destroy(cfg);
}
-/*! Append SLA station to station list */
-static void append_station(struct ast_sla *sla, const char *station)
-{
- struct ast_sla_station *s;
- char *c;
-
- s = ast_calloc(1, sizeof(struct ast_sla_station) + strlen(station) + 2);
- if (s) {
- ASTOBJ_INIT(s);
- strcpy(s->tech, station);
- c = strchr(s->tech, '/');
- if (c) {
- *c = '\0';
- s->dest = c + 1;
- ASTOBJ_CONTAINER_LINK(&sla->stations, s);
- } else {
- ast_log(LOG_WARNING, "station '%s' should be in tech/destination format! Ignoring!\n", station);
- free(s);
- }
- }
-}
-
-/*! Parse SLA configuration file and create objects */
-static void parse_sla(const char *cat, struct ast_variable *v)
-{
- struct ast_sla *sla;
-
- sla = ASTOBJ_CONTAINER_FIND(&slas, cat);
- if (!sla) {
- sla = ast_calloc(1, sizeof(struct ast_sla));
- if (sla) {
- ASTOBJ_INIT(sla);
- ast_copy_string(sla->name, cat, sizeof(sla->name));
- snprintf(sla->confname, sizeof(sla->confname), "sla-%s", sla->name);
- ASTOBJ_CONTAINER_LINK(&slas, sla);
- }
- }
- if (sla) {
- ASTOBJ_UNMARK(sla);
- ASTOBJ_WRLOCK(sla);
- ASTOBJ_CONTAINER_DESTROYALL(&sla->stations, station_destroy);
- while (v) {
- if (!strcasecmp(v->name, "trunk")) {
- char *c;
- c = strchr(v->value, '/');
- if (c) {
- ast_copy_string(sla->trunktech, v->value, (c - v->value) + 1);
- ast_copy_string(sla->trunkdest, c + 1, sizeof(sla->trunkdest));
- }
- } else if (!strcasecmp(v->name, "station")) {
- append_station(sla, v->value);
- }
- v = v->next;
- }
- ASTOBJ_UNLOCK(sla);
- ast_device_state_changed("SLA:%s", cat);
- }
-}
-
-/*! If there is a SLA configuration file, parse it */
-static void load_config_sla(void)
-{
- char *cat;
- struct ast_config *cfg;
- if (!(cfg = ast_config_load(CONFIG_FILE_NAME_SLA)))
- return;
-
- ASTOBJ_CONTAINER_MARKALL(&slas);
- cat = ast_category_browse(cfg, NULL);
- while(cat) {
- if (strcasecmp(cat, "general"))
- parse_sla(cat, ast_variable_browse(cfg, cat));
- cat = ast_category_browse(cfg, cat);
- }
- ast_config_destroy(cfg);
- ASTOBJ_CONTAINER_PRUNE_MARKED(&slas, sla_destroy);
-}
-
static void load_config(void)
{
load_config_meetme();
- load_config_sla();
}
static int unload_module(void)
@@ -3071,12 +2623,9 @@
res |= ast_unregister_application(app3);
res |= ast_unregister_application(app2);
res |= ast_unregister_application(app);
- res |= ast_unregister_application(appslas);
- res |= ast_unregister_application(appslat);
ast_module_user_hangup_all();
ast_devstate_prov_del("Meetme");
- ast_devstate_prov_del("SLA");
return res;
}
@@ -3085,18 +2634,14 @@
{
int res;
- ASTOBJ_CONTAINER_INIT(&slas);
ast_cli_register_multiple(cli_meetme, sizeof(cli_meetme) / sizeof(struct ast_cli_entry));
res = ast_manager_register("MeetmeMute", EVENT_FLAG_CALL, action_meetmemute, "Mute a Meetme user");
res |= ast_manager_register("MeetmeUnmute", EVENT_FLAG_CALL, action_meetmeunmute, "Unmute a Meetme user");
res |= ast_register_application(app3, admin_exec, synopsis3, descrip3);
res |= ast_register_application(app2, count_exec, synopsis2, descrip2);
res |= ast_register_application(app, conf_exec, synopsis, descrip);
- res |= ast_register_application(appslas, slas_exec, synopslas, descripslas);
- res |= ast_register_application(appslat, slat_exec, synopslat, descripslat);
res |= ast_devstate_prov_add("Meetme", meetmestate);
- res |= ast_devstate_prov_add("SLA", slastate);
load_config();
return res;
}
More information about the asterisk-commits
mailing list