[asterisk-commits] mvanbaak: branch mvanbaak/skinny-realtime r127948 - in /team/mvanbaak/skinny-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 3 18:21:48 CDT 2008
Author: mvanbaak
Date: Thu Jul 3 18:21:48 2008
New Revision: 127948
URL: http://svn.digium.com/view/asterisk?view=rev&rev=127948
Log:
commit NON-WORKING code so I can continue this on another laptop.
this is the work I did in the car from my boat to home, so dont blame me if it blows up in your face.
Added:
team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt (with props)
Modified:
team/mvanbaak/skinny-realtime/channels/chan_skinny.c
Modified: team/mvanbaak/skinny-realtime/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/mvanbaak/skinny-realtime/channels/chan_skinny.c?view=diff&rev=127948&r1=127947&r2=127948
==============================================================================
--- team/mvanbaak/skinny-realtime/channels/chan_skinny.c (original)
+++ team/mvanbaak/skinny-realtime/channels/chan_skinny.c Thu Jul 3 18:21:48 2008
@@ -25,6 +25,14 @@
* \ingroup channel_drivers
*/
+/*! \todo
+ *
+ * - create a function to init defaults for a device
+ * - create a function to init defaults for a line
+ * - load_realtime_device should check if the device is already in inmemory list
+ * - create a function to attach lines to a device
+ * - and all that we forgot
+ */
#include "asterisk.h"
@@ -1197,6 +1205,7 @@
int hookstate;
int nat;
int canreinvite;
+ int realtime; /* is this line a realtime line */
struct ast_codec_pref prefs;
struct skinny_subchannel *sub;
@@ -1240,6 +1249,7 @@
int lastcallreference;
int capability;
int earlyrtp;
+ int realtime; /* is this a realtime device */
struct sockaddr_in addr;
struct in_addr ourip;
struct skinny_line *lines;
@@ -1275,6 +1285,7 @@
static int skinny_senddigit_begin(struct ast_channel *ast, char digit);
static int skinny_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
static int handle_time_date_req_message(struct skinny_req *req, struct skinnysession *s);
+static struct skinny_device *load_realtime_device(const char *devicename);
static const struct ast_channel_tech skinny_tech = {
.type = "Skinny",
@@ -1791,7 +1802,11 @@
}
ast_mutex_unlock(&devicelock);
if (!d) {
- return 0;
+ /* device not found in static config, look in realtime */
+ d = load_realtime_device(req->data.reg.name);
+ if (!d) {
+ return 0;
+ }
}
return 1;
}
@@ -2991,6 +3006,331 @@
AST_CLI_DEFINE(handle_skinny_set_debug, "Enable/Disable Skinny debugging", .deprecate_cmd = &cli_skinny_set_debug_deprecated),
AST_CLI_DEFINE(handle_skinny_reset, "Reset Skinny device(s)"),
};
+
+//XXX: finish this one
+static struct skinny_device *find_device_by_name_rt(const char *devicename, struct ast_variable *device_vars, struct ast_config *line_config)
+{
+ struct ast_variable *v;
+ struct skinny_device *d;
+ struct skinny_line *l;
+ char *line = NULL;
+ struct ast_variable *chanvars = NULL;
+ int lineInstance = 1;
+ int y = 0;
+ /*
+ struct skinny_speeddial *sd;
+ struct skinny_addon *a;
+ char device_vmexten[AST_MAX_EXTENSION];
+ struct ast_variable *chanvars = NULL;
+ int lineInstance = 1;
+ int speeddialInstance = 1;
+ int y = 0;
+ */
+ if (!(d = ast_calloc(1, sizeof(*d)))) {
+ return NULL;
+ } else {
+ ast_copy_string(d->name, devicename, sizeof(d->name));
+ d->lastlineinstance = 1;
+ d->capability = default_capability;
+ d->prefs = default_prefs;
+ /*
+ if (!ast_strlen_zero(vmexten))
+ ast_copy_string(device_vmexten, vmexten, sizeof(device_vmexten));
+ else
+ memset(device_vmexten, 0, sizeof(device_vmexten));
+ */
+
+ d->earlyrtp = 1;
+ for (v = device_vars; v; v = v->next) {
+ if (!strcasecmp(v->name, "host")) {
+ if (ast_get_ip(&d->addr, v->value)) {
+ ast_free(d);
+ return NULL;
+ }
+ } else if (!strcasecmp(v->name, "port")) {
+ d->addr.sin_port = htons(atoi(v->value));
+ } else if (!strcasecmp(v->name, "device")) {
+ ast_copy_string(d->id, v->value, sizeof(d->id));
+ } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
+ d->ha = ast_append_ha(v->name, v->value, d->ha, NULL);
+ } else if (!strcasecmp(v->name, "context")) {
+ ast_copy_string(context, v->value, sizeof(context));
+ } else if (!strcasecmp(v->name, "regexten")) {
+ ast_copy_string(regexten, v->value, sizeof(regexten));
+ } else if (!strcasecmp(v->name, "allow")) {
+ ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 1);
+ } else if (!strcasecmp(v->name, "disallow")) {
+ ast_parse_allow_disallow(&d->prefs, &d->capability, v->value, 0);
+ } else if (!strcasecmp(v->name, "version")) {
+ ast_copy_string(d->version_id, v->value, sizeof(d->version_id));
+ } else if (!strcasecmp(v->name, "canreinvite")) {
+ canreinvite = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "earlyrtp")) {
+ d->earlyrtp = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "nat")) {
+ nat = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "callerid")) {
+ if (!strcasecmp(v->value, "asreceived")) {
+ cid_num[0] = '\0';
+ cid_name[0] = '\0';
+ } else {
+ ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
+ }
+ } else if (!strcasecmp(v->name, "language")) {
+ ast_copy_string(language, v->value, sizeof(language));
+ } else if (!strcasecmp(v->name, "accountcode")) {
+ ast_copy_string(accountcode, v->value, sizeof(accountcode));
+ } else if (!strcasecmp(v->name, "amaflags")) {
+ y = ast_cdr_amaflags2int(v->value);
+ if (y < 0) {
+ ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
+ } else {
+ amaflags = y;
+ }
+ } else if (!strcasecmp(v->name, "mohinterpret") || !strcasecmp(v->name, "musiconhold")) {
+ ast_copy_string(mohinterpret, v->value, sizeof(mohinterpret));
+ } else if (!strcasecmp(v->name, "mohsuggest")) {
+ ast_copy_string(mohsuggest, v->value, sizeof(mohsuggest));
+ } else if (!strcasecmp(v->name, "callgroup")) {
+ cur_callergroup = ast_get_group(v->value);
+ } else if (!strcasecmp(v->name, "pickupgroup")) {
+ cur_pickupgroup = ast_get_group(v->value);
+ } else if (!strcasecmp(v->name, "immediate")) {
+ immediate = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "cancallforward")) {
+ cancallforward = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "mailbox")) {
+ ast_copy_string(mailbox, v->value, sizeof(mailbox));
+ } else if (!strcasecmp(v->name, "callreturn")) {
+ callreturn = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "callwaiting")) {
+ callwaiting = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "transfer")) {
+ transfer = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "threewaycalling")) {
+ threewaycalling = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "mwiblink")) {
+ mwiblink = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "linelabel")) {
+ ast_copy_string(linelabel, v->value, sizeof(linelabel));
+ } else if (!strcasecmp(v->name, "setvar")) {
+ chanvars = add_var(v->value, chanvars);
+ } else if ( !strcasecmp(v->name, "parkinglot")) {
+ ast_copy_string(parkinglot, v->value, sizeof(parkinglot));
+ /*
+ } else if (!strcasecmp(v->name, "speeddial")) {
+ if (!(sd = ast_calloc(1, sizeof(*sd)))) {
+ return NULL;
+ } else {
+ char buf[256];
+ char *stringp = buf, *exten, *context, *label;
+
+ ast_copy_string(buf, v->value, sizeof(buf));
+ exten = strsep(&stringp, ",");
+ if ((context = strchr(exten, '@'))) {
+ *context++ = '\0';
+ }
+ label = stringp;
+ ast_mutex_init(&sd->lock);
+ ast_copy_string(sd->exten, exten, sizeof(sd->exten));
+ if (!ast_strlen_zero(context)) {
+ sd->isHint = 1;
+ sd->instance = lineInstance++;
+ ast_copy_string(sd->context, context, sizeof(sd->context));
+ } else {
+ sd->isHint = 0;
+ sd->instance = speeddialInstance++;
+ sd->context[0] = '\0';
+ }
+ ast_copy_string(sd->label, S_OR(label, exten), sizeof(sd->label));
+
+ sd->parent = d;
+
+ sd->next = d->speeddials;
+ d->speeddials = sd;
+ }
+ } else if (!strcasecmp(v->name, "addon")) {
+ if (!(a = ast_calloc(1, sizeof(*a)))) {
+ return NULL;
+ } else {
+ ast_mutex_init(&a->lock);
+ ast_copy_string(a->type, v->value, sizeof(a->type));
+
+ a->next = d->addons;
+ d->addons = a;
+ }
+ */
+ } else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) {
+ if (!(l = ast_calloc(1, sizeof(*l)))) {
+ return NULL;
+ } else {
+ ast_mutex_init(&l->lock);
+ ast_copy_string(l->name, v->value, sizeof(l->name));
+
+ /* XXX Should we check for uniqueness?? XXX */
+ ast_copy_string(l->context, context, sizeof(l->context));
+ ast_copy_string(l->cid_num, cid_num, sizeof(l->cid_num));
+ ast_copy_string(l->cid_name, cid_name, sizeof(l->cid_name));
+ ast_copy_string(l->label, linelabel, sizeof(l->label));
+ ast_copy_string(l->parkinglot, parkinglot, sizeof(l->parkinglot));
+ ast_copy_string(l->language, language, sizeof(l->language));
+ ast_copy_string(l->mohinterpret, mohinterpret, sizeof(l->mohinterpret));
+ ast_copy_string(l->mohsuggest, mohsuggest, sizeof(l->mohsuggest));
+ ast_copy_string(l->regexten, regexten, sizeof(l->regexten));
+ ast_copy_string(l->mailbox, mailbox, sizeof(l->mailbox));
+ if (!ast_strlen_zero(mailbox)) {
+ char *cfg_mailbox, *cfg_context;
+ cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
+ ast_verb(3, "Setting mailbox '%s' on %s@%s\n", cfg_mailbox, d->name, l->name);
+ strsep(&cfg_context, "@");
+ if (ast_strlen_zero(cfg_context))
+ cfg_context = "default";
+ l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
+ AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+ }
+ l->chanvars = chanvars;
+ l->msgstate = -1;
+ l->capability = d->capability;
+ l->prefs = d->prefs;
+ l->parent = d;
+ if (!strcasecmp(v->name, "trunk")) {
+ l->type = TYPE_TRUNK;
+ } else {
+ l->type = TYPE_LINE;
+ }
+ l->immediate = immediate;
+ l->callgroup = cur_callergroup;
+ l->pickupgroup = cur_pickupgroup;
+ l->callreturn = callreturn;
+ l->cancallforward = cancallforward;
+ l->getforward = 0;
+ set_callforwards(l, NULL, 0);
+ l->callwaiting = callwaiting;
+ l->transfer = transfer;
+ l->threewaycalling = threewaycalling;
+ l->mwiblink = mwiblink;
+ l->onhooktime = time(NULL);
+ l->instance = lineInstance++;
+ /* ASSUME we're onhook at this point */
+ l->hookstate = SKINNY_ONHOOK;
+ l->nat = nat;
+ l->canreinvite = canreinvite;
+
+ l->next = d->lines;
+ d->lines = l;
+ }
+ } else {
+ ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
+ }
+ v = v->next;
+ }
+// add lines
+ while ((line = ast_category_browse(line_config, line))) {
+ if (!(l = ast_calloc(1, sizeof(*l)))) {
+ return NULL;
+ } else {
+ ast_mutex_init(&l->lock);
+ ast_copy_string(l->name, line, sizeof(l->name));
+
+ /* XXX Should we check for uniqueness?? XXX */
+ ast_copy_string(l->context, ast_variable_retrieve(line_config, line, "context"), sizeof(l->context));
+ ast_copy_string(l->cid_num, cid_num, sizeof(l->cid_num));
+ ast_copy_string(l->cid_name, cid_name, sizeof(l->cid_name));
+ ast_copy_string(l->label, linelabel, sizeof(l->label));
+ ast_copy_string(l->parkinglot, parkinglot, sizeof(l->parkinglot));
+ ast_copy_string(l->language, language, sizeof(l->language));
+ ast_copy_string(l->mohinterpret, mohinterpret, sizeof(l->mohinterpret));
+ ast_copy_string(l->mohsuggest, mohsuggest, sizeof(l->mohsuggest));
+ ast_copy_string(l->regexten, regexten, sizeof(l->regexten));
+ ast_copy_string(l->mailbox, mailbox, sizeof(l->mailbox));
+ if (!ast_strlen_zero(mailbox)) {
+ char *cfg_mailbox, *cfg_context;
+ cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
+ ast_verb(3, "Setting mailbox '%s' on %s@%s\n", cfg_mailbox, d->name, l->name);
+ strsep(&cfg_context, "@");
+ if (ast_strlen_zero(cfg_context))
+ cfg_context = "default";
+ l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
+ AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+ }
+ l->chanvars = chanvars;
+ l->msgstate = -1;
+ l->capability = d->capability;
+ l->prefs = d->prefs;
+ l->parent = d;
+ if (!strcasecmp(v->name, "trunk")) {
+ l->type = TYPE_TRUNK;
+ } else {
+ l->type = TYPE_LINE;
+ }
+ l->immediate = immediate;
+ l->callgroup = cur_callergroup;
+ l->pickupgroup = cur_pickupgroup;
+ l->callreturn = callreturn;
+ l->cancallforward = cancallforward;
+ l->getforward = 0;
+ set_callforwards(l, NULL, 0);
+ l->callwaiting = callwaiting;
+ l->transfer = transfer;
+ l->threewaycalling = threewaycalling;
+ l->mwiblink = mwiblink;
+ l->onhooktime = time(NULL);
+ l->instance = lineInstance++;
+ /* ASSUME we're onhook at this point */
+ l->hookstate = SKINNY_ONHOOK;
+ l->nat = nat;
+ l->canreinvite = canreinvite;
+
+ l->next = d->lines;
+ d->lines = l;
+ }
+ }
+
+ if (!d->lines) {
+ ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
+ return NULL;
+ }
+ if (!ntohs(d->addr.sin_port)) {
+ d->addr.sin_port = htons(DEFAULT_SKINNY_PORT);
+ }
+ }
+
+ return d;
+}
+
+//XXX: finish this one
+static struct skinny_device *load_realtime_device(const char *devicename)
+{
+ struct ast_variable *device_vars;
+ struct ast_config *line_config = NULL;
+ struct skinny_device *d;
+
+ // some logic here to find the device in the memory list of devices
+
+ // load device from realtime
+ device_vars = ast_load_realtime("skinny_devices", "name", devicename, SENTINEL);
+ if (device_vars) {
+ line_config = ast_load_realtime_multientry("skinny_lines", "device LIKE", "%", "device_name", devicename, SENTINEL);
+ if (!line_config) {
+ ast_log(LOG_ERROR, "no skinny_lines defined in your config (extconfig.conf).\n");
+ ast_variables_destroy(device_vars);
+ return NULL;
+ }
+ }
+ d = find_device_by_name_rt(devicename, device_vars, line_config);
+ if (line_config)
+ ast_config_destroy(line_config);
+ if (device_vars)
+ ast_variables_destroy(device_vars);
+
+ return d;
+}
static struct skinny_device *build_device(const char *cat, struct ast_variable *v)
{
Added: team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt
URL: http://svn.digium.com/view/asterisk/team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt?view=auto&rev=127948
==============================================================================
--- team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt (added)
+++ team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt Thu Jul 3 18:21:48 2008
@@ -1,0 +1,16 @@
+skinny_devices table fields
+
+skinny_lines table fields
+
+context
+callerid
+linelabel
+parkinglot
+language
+mohinterpret
+mohsuggest
+regexten
+mailbox
+vmexten
+chanvars
+
Propchange: team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mvanbaak/skinny-realtime/contrib/scripts/skinny-realtime.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list