mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
Allow codecs to be specified on a per-peer and per-user basis
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1461 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -168,6 +168,7 @@ struct iax2_user {
|
|||||||
char inkeys[80]; /* Key(s) this user can use to authenticate to us */
|
char inkeys[80]; /* Key(s) this user can use to authenticate to us */
|
||||||
int amaflags;
|
int amaflags;
|
||||||
int hascallerid;
|
int hascallerid;
|
||||||
|
int capability;
|
||||||
int trunk;
|
int trunk;
|
||||||
char callerid[AST_MAX_EXTENSION];
|
char callerid[AST_MAX_EXTENSION];
|
||||||
struct ast_ha *ha;
|
struct ast_ha *ha;
|
||||||
@@ -2673,6 +2674,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
|
|||||||
strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
|
strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
|
||||||
/* Store whether this is a trunked call, too, of course, and move if appropriate */
|
/* Store whether this is a trunked call, too, of course, and move if appropriate */
|
||||||
iaxs[callno]->trunk = user->trunk;
|
iaxs[callno]->trunk = user->trunk;
|
||||||
|
iaxs[callno]->capability = user->capability;
|
||||||
/* And use the default context */
|
/* And use the default context */
|
||||||
if (!strlen(iaxs[callno]->context)) {
|
if (!strlen(iaxs[callno]->context)) {
|
||||||
if (user->contexts)
|
if (user->contexts)
|
||||||
@@ -4036,23 +4038,23 @@ retryowner:
|
|||||||
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
|
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
|
||||||
} else {
|
} else {
|
||||||
/* Select an appropriate format */
|
/* Select an appropriate format */
|
||||||
format = iaxs[fr.callno]->peerformat & iax2_capability;
|
format = iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability;
|
||||||
if (!format) {
|
if (!format) {
|
||||||
format = iaxs[fr.callno]->peercapability & iax2_capability;
|
format = iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability;
|
||||||
if (!format) {
|
if (!format) {
|
||||||
memset(&ied0, 0, sizeof(ied0));
|
memset(&ied0, 0, sizeof(ied0));
|
||||||
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
||||||
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
||||||
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
|
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
|
||||||
} else {
|
} else {
|
||||||
/* Pick one... */
|
/* Pick one... */
|
||||||
format = ast_best_codec(iaxs[fr.callno]->peercapability & iax2_capability);
|
format = ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
|
||||||
if (!format) {
|
if (!format) {
|
||||||
memset(&ied0, 0, sizeof(ied0));
|
memset(&ied0, 0, sizeof(ied0));
|
||||||
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
||||||
ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iax2_capability);
|
ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
|
||||||
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
||||||
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
|
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
|
||||||
iaxs[fr.callno]->alreadygone = 1;
|
iaxs[fr.callno]->alreadygone = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4145,7 +4147,7 @@ retryowner:
|
|||||||
if (iaxs[fr.callno]->owner)
|
if (iaxs[fr.callno]->owner)
|
||||||
iaxs[fr.callno]->peerformat = iaxs[fr.callno]->owner->nativeformats;
|
iaxs[fr.callno]->peerformat = iaxs[fr.callno]->owner->nativeformats;
|
||||||
else
|
else
|
||||||
iaxs[fr.callno]->peerformat = iax2_capability;
|
iaxs[fr.callno]->peerformat = iaxs[fr.callno]->capability;
|
||||||
}
|
}
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "Call accepted by %s (format %s)\n", inet_ntoa(iaxs[fr.callno]->addr.sin_addr), ast_getformatname(iaxs[fr.callno]->peerformat));
|
ast_verbose(VERBOSE_PREFIX_3 "Call accepted by %s (format %s)\n", inet_ntoa(iaxs[fr.callno]->addr.sin_addr), ast_getformatname(iaxs[fr.callno]->peerformat));
|
||||||
@@ -4284,21 +4286,21 @@ retryowner:
|
|||||||
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
||||||
} else {
|
} else {
|
||||||
/* Select an appropriate format */
|
/* Select an appropriate format */
|
||||||
format = iaxs[fr.callno]->peerformat & iax2_capability;
|
format = iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability;
|
||||||
if (!format) {
|
if (!format) {
|
||||||
ast_log(LOG_DEBUG, "We don't do requested format %s, falling back to peer capability %d\n", ast_getformatname(iaxs[fr.callno]->peerformat), iaxs[fr.callno]->peercapability);
|
ast_log(LOG_DEBUG, "We don't do requested format %s, falling back to peer capability %d\n", ast_getformatname(iaxs[fr.callno]->peerformat), iaxs[fr.callno]->peercapability);
|
||||||
format = iaxs[fr.callno]->peercapability & iax2_capability;
|
format = iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability;
|
||||||
if (!format) {
|
if (!format) {
|
||||||
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
|
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
|
||||||
memset(&ied0, 0, sizeof(ied0));
|
memset(&ied0, 0, sizeof(ied0));
|
||||||
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
||||||
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
||||||
} else {
|
} else {
|
||||||
/* Pick one... */
|
/* Pick one... */
|
||||||
format = ast_best_codec(iaxs[fr.callno]->peercapability & iax2_capability);
|
format = ast_best_codec(iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
|
||||||
if (!format) {
|
if (!format) {
|
||||||
ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iax2_capability);
|
ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability);
|
||||||
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
|
ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
|
||||||
memset(&ied0, 0, sizeof(ied0));
|
memset(&ied0, 0, sizeof(ied0));
|
||||||
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
|
||||||
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
|
||||||
@@ -4947,6 +4949,7 @@ static struct iax2_user *build_user(char *name, struct ast_variable *v)
|
|||||||
user = (struct iax2_user *)malloc(sizeof(struct iax2_user));
|
user = (struct iax2_user *)malloc(sizeof(struct iax2_user));
|
||||||
if (user) {
|
if (user) {
|
||||||
memset(user, 0, sizeof(struct iax2_user));
|
memset(user, 0, sizeof(struct iax2_user));
|
||||||
|
user->capability = iax2_capability;
|
||||||
strncpy(user->name, name, sizeof(user->name)-1);
|
strncpy(user->name, name, sizeof(user->name)-1);
|
||||||
while(v) {
|
while(v) {
|
||||||
if (!strcasecmp(v->name, "context")) {
|
if (!strcasecmp(v->name, "context")) {
|
||||||
@@ -4961,6 +4964,18 @@ static struct iax2_user *build_user(char *name, struct ast_variable *v)
|
|||||||
} else if (!strcasecmp(v->name, "permit") ||
|
} else if (!strcasecmp(v->name, "permit") ||
|
||||||
!strcasecmp(v->name, "deny")) {
|
!strcasecmp(v->name, "deny")) {
|
||||||
user->ha = ast_append_ha(v->name, v->value, user->ha);
|
user->ha = ast_append_ha(v->name, v->value, user->ha);
|
||||||
|
} else if (!strcasecmp(v->name, "allow")) {
|
||||||
|
format = ast_getformatbyname(v->value);
|
||||||
|
if (format < 1)
|
||||||
|
ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value);
|
||||||
|
else
|
||||||
|
user->capability |= format;
|
||||||
|
} else if (!strcasecmp(v->name, "disallow")) {
|
||||||
|
format = ast_getformatbyname(v->value);
|
||||||
|
if (format < 1)
|
||||||
|
ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value);
|
||||||
|
else
|
||||||
|
user->capability &= ~format;
|
||||||
} else if (!strcasecmp(v->name, "trunk")) {
|
} else if (!strcasecmp(v->name, "trunk")) {
|
||||||
user->trunk = ast_true(v->value);
|
user->trunk = ast_true(v->value);
|
||||||
if (user->trunk && (timingfd < 0)) {
|
if (user->trunk && (timingfd < 0)) {
|
||||||
|
Reference in New Issue
Block a user