make firmware version configurable per device

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1913 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jeremy McNamara
2004-01-09 21:12:21 +00:00
parent 5fc7f417da
commit d3c388db9c

View File

@@ -63,9 +63,9 @@ static char *config = "skinny.conf";
/* Just about everybody seems to support ulaw, so make it a nice default */ /* Just about everybody seems to support ulaw, so make it a nice default */
static int capability = AST_FORMAT_ULAW; static int capability = AST_FORMAT_ULAW;
#define DEFAULT_SKINNY_PORT 2000 #define DEFAULT_SKINNY_PORT 2000
#define DEFAULT_SKINNY_BACKLOG 2 // was 200 #define DEFAULT_SKINNY_BACKLOG 2
#define SKINNY_MAX_PACKET 1000 #define SKINNY_MAX_PACKET 1000
static int keep_alive = 120; static int keep_alive = 120;
static char date_format[6] = "D-M-Y"; static char date_format[6] = "D-M-Y";
@@ -506,6 +506,7 @@ static char mailbox[AST_MAX_EXTENSION];
static int amaflags = 0; static int amaflags = 0;
static int callnums = 1; static int callnums = 1;
#define SUB_REAL 0 #define SUB_REAL 0
#define SUB_ALT 1 #define SUB_ALT 1
#define MAX_SUBS 2 #define MAX_SUBS 2
@@ -668,6 +669,7 @@ static struct skinny_device {
/* A device containing one or more lines */ /* A device containing one or more lines */
char name[80]; char name[80];
char id[16]; char id[16];
char version_id[16];
int type; int type;
int registered; int registered;
struct sockaddr_in addr; struct sockaddr_in addr;
@@ -1046,55 +1048,56 @@ static struct skinny_device *build_device(char *cat, struct ast_variable *v)
d->addr.sin_port = htons(atoi(v->value)); d->addr.sin_port = htons(atoi(v->value));
} else if (!strcasecmp(v->name, "device")) { } else if (!strcasecmp(v->name, "device")) {
strncpy(d->id, v->value, sizeof(d->id)-1); strncpy(d->id, v->value, sizeof(d->id)-1);
} else if (!strcasecmp(v->name, "permit") || } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
!strcasecmp(v->name, "deny")) {
d->ha = ast_append_ha(v->name, v->value, d->ha); d->ha = ast_append_ha(v->name, v->value, d->ha);
} else if (!strcasecmp(v->name, "context")) { } else if (!strcasecmp(v->name, "context")) {
strncpy(context, v->value, sizeof(context) - 1); strncpy(context, v->value, sizeof(context) - 1);
} else if (!strcasecmp(v->name, "version")) {
strncpy(d->version_id, v->value, sizeof(d->version_id) -1);
} else if (!strcasecmp(v->name, "nat")) { } else if (!strcasecmp(v->name, "nat")) {
nat = ast_true(v->value); nat = ast_true(v->value);
} else if (!strcasecmp(v->name, "callerid")) { } else if (!strcasecmp(v->name, "callerid")) {
if (!strcasecmp(v->value, "asreceived")) if (!strcasecmp(v->value, "asreceived")) {
strcpy(callerid, ""); strcpy(callerid, "");
else } else {
strncpy(callerid, v->value, sizeof(callerid) - 1); strncpy(callerid, v->value, sizeof(callerid) - 1);
}
} else if (!strcasecmp(v->name, "language")) { } else if (!strcasecmp(v->name, "language")) {
strncpy(language, v->value, sizeof(language)-1); strncpy(language, v->value, sizeof(language)-1);
} else if (!strcasecmp(v->name, "accountcode")) { } else if (!strcasecmp(v->name, "accountcode")) {
strncpy(accountcode, v->value, sizeof(accountcode)-1); strncpy(accountcode, v->value, sizeof(accountcode)-1);
} else if (!strcasecmp(v->name, "amaflags")) { } else if (!strcasecmp(v->name, "amaflags")) {
y = ast_cdr_amaflags2int(v->value); y = ast_cdr_amaflags2int(v->value);
if (y < 0) { if (y < 0) {
ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno); ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno);
} else { } else {
amaflags = y; amaflags = y;
} }
} else if (!strcasecmp(v->name, "musiconhold")) { } else if (!strcasecmp(v->name, "musiconhold")) {
strncpy(musicclass, v->value, sizeof(musicclass)-1); strncpy(musicclass, v->value, sizeof(musicclass)-1);
} else if (!strcasecmp(v->name, "callgroup")) { } else if (!strcasecmp(v->name, "callgroup")) {
cur_callergroup = ast_get_group(v->value); cur_callergroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "pickupgroup")) { } else if (!strcasecmp(v->name, "pickupgroup")) {
cur_pickupgroup = ast_get_group(v->value); cur_pickupgroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "immediate")) { } else if (!strcasecmp(v->name, "immediate")) {
immediate = ast_true(v->value); immediate = ast_true(v->value);
} else if (!strcasecmp(v->name, "cancallforward")) { } else if (!strcasecmp(v->name, "cancallforward")) {
cancallforward = ast_true(v->value); cancallforward = ast_true(v->value);
} else if (!strcasecmp(v->name, "mailbox")) { } else if (!strcasecmp(v->name, "mailbox")) {
strncpy(mailbox, v->value, sizeof(mailbox) -1); strncpy(mailbox, v->value, sizeof(mailbox) -1);
} else if (!strcasecmp(v->name, "callreturn")) { } else if (!strcasecmp(v->name, "callreturn")) {
callreturn = ast_true(v->value); callreturn = ast_true(v->value);
} else if (!strcasecmp(v->name, "immediate")) { } else if (!strcasecmp(v->name, "immediate")) {
immediate = ast_true(v->value); immediate = ast_true(v->value);
} else if (!strcasecmp(v->name, "callwaiting")) { } else if (!strcasecmp(v->name, "callwaiting")) {
callwaiting = ast_true(v->value); callwaiting = ast_true(v->value);
} else if (!strcasecmp(v->name, "transfer")) { } else if (!strcasecmp(v->name, "transfer")) {
transfer = ast_true(v->value); transfer = ast_true(v->value);
} else if (!strcasecmp(v->name, "threewaycalling")) { } else if (!strcasecmp(v->name, "threewaycalling")) {
threewaycalling = ast_true(v->value); threewaycalling = ast_true(v->value);
} else if (!strcasecmp(v->name, "linelabel")) { } else if (!strcasecmp(v->name, "linelabel")) {
strncpy(linelabel, v->value, sizeof(linelabel)-1); strncpy(linelabel, v->value, sizeof(linelabel)-1);
} else if (!strcasecmp(v->name, "trunk") || } else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) {
!strcasecmp(v->name, "line")) {
l = malloc(sizeof(struct skinny_line));; l = malloc(sizeof(struct skinny_line));;
if (l) { if (l) {
memset(l, 0, sizeof(struct skinny_line)); memset(l, 0, sizeof(struct skinny_line));
@@ -1106,65 +1109,67 @@ static struct skinny_device *build_device(char *cat, struct ast_variable *v)
strncpy(l->callerid, callerid, sizeof(l->callerid) - 1); strncpy(l->callerid, callerid, sizeof(l->callerid) - 1);
strncpy(l->label, linelabel, sizeof(l->label) - 1); strncpy(l->label, linelabel, sizeof(l->label) - 1);
strncpy(l->language, language, sizeof(l->language) - 1); strncpy(l->language, language, sizeof(l->language) - 1);
strncpy(l->musicclass, musicclass, sizeof(l->musicclass)-1); strncpy(l->musicclass, musicclass, sizeof(l->musicclass)-1);
strncpy(l->mailbox, mailbox, sizeof(l->mailbox)-1);
strncpy(l->mailbox, mailbox, sizeof(l->mailbox)-1); strncpy(l->mailbox, mailbox, sizeof(l->mailbox)-1);
if (strlen(mailbox)) { if (strlen(mailbox)) {
ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, d->name, l->name); ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, d->name, l->name);
} }
l->msgstate = -1; l->msgstate = -1;
l->capability = capability; l->capability = capability;
l->parent = d; l->parent = d;
if (!strcasecmp(v->name, "trunk")) if (!strcasecmp(v->name, "trunk")) {
l->type = TYPE_TRUNK; l->type = TYPE_TRUNK;
else } else {
l->type = TYPE_LINE; l->type = TYPE_LINE;
}
l->immediate = immediate; l->immediate = immediate;
l->callgroup = cur_callergroup; l->callgroup = cur_callergroup;
l->pickupgroup = cur_pickupgroup; l->pickupgroup = cur_pickupgroup;
l->callreturn = callreturn; l->callreturn = callreturn;
l->cancallforward = cancallforward; l->cancallforward = cancallforward;
l->callwaiting = callwaiting; l->callwaiting = callwaiting;
l->transfer = transfer; l->transfer = transfer;
l->threewaycalling = threewaycalling; l->threewaycalling = threewaycalling;
l->onhooktime = time(NULL);
l->onhooktime = time(NULL);
l->instance = 1; l->instance = 1;
/* ASSUME we're onhook at this point*/ /* ASSUME we're onhook at this point*/
l->hookstate = SKINNY_ONHOOK; l->hookstate = SKINNY_ONHOOK;
for (i = 0; i < MAX_SUBS; i++) { for (i = 0; i < MAX_SUBS; i++) {
sub = malloc(sizeof(struct skinny_subchannel)); sub = malloc(sizeof(struct skinny_subchannel));
if (sub) { if (sub) {
ast_verbose(VERBOSE_PREFIX_3 "Allocating Skinny subchannel '%d' on %s@%s\n", i, l->name, d->name); ast_verbose(VERBOSE_PREFIX_3 "Allocating Skinny subchannel '%d' on %s@%s\n", i, l->name, d->name);
memset(sub, 0, sizeof(struct skinny_subchannel)); memset(sub, 0, sizeof(struct skinny_subchannel));
sub->parent = l; sub->parent = l;
/* Make a call*ID */ /* Make a call*ID */
sub->callid = callnums; sub->callid = callnums;
callnums++; callnums++;
sub->cxmode = SKINNY_CX_INACTIVE; sub->cxmode = SKINNY_CX_INACTIVE;
sub->nat = nat; sub->nat = nat;
sub->next = l->sub; sub->next = l->sub;
l->sub = sub; l->sub = sub;
} else { } else {
/* XXX Should find a way to clean up our memory */ /* XXX Should find a way to clean up our memory */
ast_log(LOG_WARNING, "Out of memory allocating subchannel"); ast_log(LOG_WARNING, "Out of memory allocating subchannel");
return NULL; return NULL;
} }
} }
l->next = d->lines; l->next = d->lines;
d->lines = l; d->lines = l;
} else { } else {
/* XXX Should find a way to clean up our memory */ /* XXX Should find a way to clean up our memory */
ast_log(LOG_WARNING, "Out of memory allocating line"); ast_log(LOG_WARNING, "Out of memory allocating line");
return NULL; return NULL;
} }
} else } else {
ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno); ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno);
}
v = v->next; v = v->next;
} }
if (!d->lines) { if (!d->lines) {
ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n"); ast_log(LOG_ERROR, "A Skinny device must have at least one line!\n");
return NULL; return NULL;
} }
@@ -1198,6 +1203,9 @@ static int skinny_register(skinny_req *req, struct skinnysession *s)
/* XXX Deal with IP authentication */ /* XXX Deal with IP authentication */
s->device = d; s->device = d;
d->type = req->data.reg.type; d->type = req->data.reg.type;
if (!strlen(d->version_id)) {
strncpy(d->version_id, version_id, sizeof(d->version_id));
}
d->registered = 1; d->registered = 1;
d->session = s; d->session = s;
break; break;
@@ -1924,7 +1932,7 @@ static int handle_message(skinny_req *req, struct skinnysession *s)
memset(req, 0, SKINNY_MAX_PACKET); memset(req, 0, SKINNY_MAX_PACKET);
req->len = sizeof(version_res_message)+4; req->len = sizeof(version_res_message)+4;
req->e = VERSION_RES_MESSAGE; req->e = VERSION_RES_MESSAGE;
sprintf(req->data.version.version, version_id); sprintf(req->data.version.version, s->device->version_id);
transmit_response(s, req); transmit_response(s, req);
break; break;
case SERVER_REQUEST_MESSAGE: case SERVER_REQUEST_MESSAGE:
@@ -2513,8 +2521,6 @@ static int reload_config(void)
keep_alive = atoi(v->value); keep_alive = atoi(v->value);
} else if (!strcasecmp(v->name, "dateFormat")) { } else if (!strcasecmp(v->name, "dateFormat")) {
strncpy(date_format, v->value, sizeof(date_format) - 1); strncpy(date_format, v->value, sizeof(date_format) - 1);
} else if (!strcasecmp(v->name, "versionId")) {
strncpy(version_id, v->value, sizeof(version_id) - 1);
} else if (!strcasecmp(v->name, "allow")) { } else if (!strcasecmp(v->name, "allow")) {
format = ast_getformatbyname(v->value); format = ast_getformatbyname(v->value);
if (format < 1) if (format < 1)