Add callingpres/calling limit support, small updates (bug #3577 with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5017 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 21 years ago
parent 3af7d5a342
commit 6a181832bb

@ -473,6 +473,11 @@ struct sip_peer {
char fullcontact[128]; /* Contact registred with us (not in sip.conf) */ char fullcontact[128]; /* Contact registred with us (not in sip.conf) */
char cid_num[80]; /* Caller ID num */ char cid_num[80]; /* Caller ID num */
char cid_name[80]; /* Caller ID name */ char cid_name[80]; /* Caller ID name */
int callingpres; /* Calling id presentation */
int inUse; /* Number of calls in use */
int incominglimit; /* Limit of incoming calls */
int outUse; /* disabled */
int outgoinglimit; /* disabled */
char mailbox[AST_MAX_EXTENSION]; /* Mailbox setting for MWI checks */ char mailbox[AST_MAX_EXTENSION]; /* Mailbox setting for MWI checks */
char language[MAX_LANGUAGE]; /* Default language for prompts */ char language[MAX_LANGUAGE]; /* Default language for prompts */
char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ char musicclass[MAX_LANGUAGE]; /* Music on Hold class */
@ -1597,43 +1602,65 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner)
/*--- update_user_counter: Handle incominglimit and outgoinglimit for SIP users ---*/ /*--- update_user_counter: Handle incominglimit and outgoinglimit for SIP users ---*/
/* Note: This is going to be replaced by app_groupcount */ /* Note: This is going to be replaced by app_groupcount */
/* Thought: For realtime, we should propably update storage with inuse counter... */
static int update_user_counter(struct sip_pvt *fup, int event) static int update_user_counter(struct sip_pvt *fup, int event)
{ {
char name[256] = ""; char name[256] = "";
struct sip_user *u; struct sip_user *u;
struct sip_peer *p;
int *inuse, *incominglimit;
strncpy(name, fup->username, sizeof(name) - 1); strncpy(name, fup->username, sizeof(name) - 1);
/* Check the list of users */
u = find_user(name, 1); u = find_user(name, 1);
if (!u) { if (u) {
inuse = &u->inUse;
incominglimit = &u->incominglimit;
p = NULL;
} else {
/* Try to find peer */
p = find_peer(fup->peername, NULL, 1);
if (p) {
inuse = &p->inUse;
incominglimit = &p->incominglimit;
strncpy(name, fup->peername, sizeof(name) -1);
} else {
ast_log(LOG_DEBUG, "%s is not a local user\n", name); ast_log(LOG_DEBUG, "%s is not a local user\n", name);
return 0; return 0;
} }
}
switch(event) { switch(event) {
/* incoming and outgoing affects the inUse counter */ /* incoming and outgoing affects the inUse counter */
case DEC_OUT_USE: case DEC_OUT_USE:
case DEC_IN_USE: case DEC_IN_USE:
if ( u->inUse > 0 ) { if ( *inuse > 0 ) {
u->inUse--; (*inuse)--;
} else { } else {
u->inUse = 0; *inuse = 0;
} }
break; break;
case INC_IN_USE: case INC_IN_USE:
case INC_OUT_USE: case INC_OUT_USE:
if (u->incominglimit > 0 ) { if (*incominglimit > 0 ) {
if (u->inUse >= u->incominglimit) { if (*inuse >= *incominglimit) {
ast_log(LOG_ERROR, "Call from user '%s' rejected due to usage limit of %d\n", u->name, u->incominglimit); ast_log(LOG_ERROR, "Call from %s '%s' rejected due to usage limit of %d\n", u?"user":"peer", name, *incominglimit);
/* inc inUse as well */ /* inc inUse as well */
if ( event == INC_OUT_USE ) { if ( event == INC_OUT_USE ) {
u->inUse++; (*inuse)++;
} }
if (u)
ASTOBJ_UNREF(u,sip_destroy_user); ASTOBJ_UNREF(u,sip_destroy_user);
else
ASTOBJ_UNREF(p,sip_destroy_peer);
return -1; return -1;
} }
} }
u->inUse++; u->inUse++;
ast_log(LOG_DEBUG, "Call from user '%s' is %d out of %d\n", u->name, u->inUse, u->incominglimit); ast_log(LOG_DEBUG, "Call from %s '%s' is %d out of %d\n", u?"user":"peer", name, *inuse, *incominglimit);
break; break;
/* we don't use these anymore #ifdef DISABLED_CODE
/* we don't use these anymore */
case DEC_OUT_USE: case DEC_OUT_USE:
if ( u->outUse > 0 ) { if ( u->outUse > 0 ) {
u->outUse--; u->outUse--;
@ -1654,11 +1681,14 @@ static int update_user_counter(struct sip_pvt *fup, int event)
} }
u->outUse++; u->outUse++;
break; break;
*/ #endif
default: default:
ast_log(LOG_ERROR, "update_user_counter(%s,%d) called with no event!\n",u->name,event); ast_log(LOG_ERROR, "update_user_counter(%s,%d) called with no event!\n",name,event);
} }
if (u)
ASTOBJ_UNREF(u,sip_destroy_user); ASTOBJ_UNREF(u,sip_destroy_user);
else
ASTOBJ_UNREF(p,sip_destroy_peer);
return 0; return 0;
} }
@ -5764,6 +5794,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd
p->peersecret[sizeof(p->peersecret)-1] = '\0'; p->peersecret[sizeof(p->peersecret)-1] = '\0';
strncpy(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret)-1); strncpy(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret)-1);
p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0'; p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0';
p->callingpres = peer->callingpres;
if (ast_test_flag(peer, SIP_INSECURE) == SIP_INSECURE_VERY) { if (ast_test_flag(peer, SIP_INSECURE) == SIP_INSECURE_VERY) {
/* Pretend there is no required authentication if insecure is "very" */ /* Pretend there is no required authentication if insecure is "very" */
p->peersecret[0] = '\0'; p->peersecret[0] = '\0';
@ -6197,6 +6228,8 @@ static int sip_show_peer(int fd, int argc, char *argv[])
print_group(fd, peer->pickupgroup); print_group(fd, peer->pickupgroup);
ast_cli(fd, " Mailbox : %s\n", peer->mailbox); ast_cli(fd, " Mailbox : %s\n", peer->mailbox);
ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent); ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent);
ast_cli(fd, " Inc. limit : %d\n", peer->incominglimit);
ast_cli(fd, " Outg. limit : %d\n", peer->outgoinglimit);
ast_cli(fd, " Dynamic : %s\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Yes":"No")); ast_cli(fd, " Dynamic : %s\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Yes":"No"));
ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>")); ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
ast_cli(fd, " Expire : %d\n", peer->expire); ast_cli(fd, " Expire : %d\n", peer->expire);
@ -9176,12 +9209,22 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int
peer->defaddr.sin_port = htons(atoi(v->value)); peer->defaddr.sin_port = htons(atoi(v->value));
else else
peer->addr.sin_port = htons(atoi(v->value)); peer->addr.sin_port = htons(atoi(v->value));
} else if (!strcasecmp(v->name, "callingpres")) {
peer->callingpres = atoi(v->value);
} else if (!strcasecmp(v->name, "username")) { } else if (!strcasecmp(v->name, "username")) {
strncpy(peer->username, v->value, sizeof(peer->username)-1); strncpy(peer->username, v->value, sizeof(peer->username)-1);
} else if (!strcasecmp(v->name, "language")) { } else if (!strcasecmp(v->name, "language")) {
strncpy(peer->language, v->value, sizeof(peer->language)-1); strncpy(peer->language, v->value, sizeof(peer->language)-1);
} else if (!strcasecmp(v->name, "regexten")) { } else if (!strcasecmp(v->name, "regexten")) {
strncpy(peer->regexten, v->value, sizeof(peer->regexten)-1); strncpy(peer->regexten, v->value, sizeof(peer->regexten)-1);
} else if (!strcasecmp(v->name, "incominglimit")) {
peer->incominglimit = atoi(v->value);
if (peer->incominglimit < 0)
peer->incominglimit = 0;
} else if (!strcasecmp(v->name, "outgoinglimit")) {
peer->outgoinglimit = atoi(v->value);
if (peer->outgoinglimit < 0)
peer->outgoinglimit = 0;
} else if (!strcasecmp(v->name, "amaflags")) { } else if (!strcasecmp(v->name, "amaflags")) {
format = ast_cdr_amaflags2int(v->value); format = ast_cdr_amaflags2int(v->value);
if (format < 0) { if (format < 0) {

@ -195,10 +195,10 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; useclientcode useclientcode ; useclientcode useclientcode
; accountcode accountcode ; accountcode accountcode
; setvar setvar ; setvar setvar
; callerid ; callerid callerid
; amaflags amaflags ; amaflags amaflags
; incominglimit ; incominglimit incominglimit
; restrictcid ; restrictcid restrictcid
; mailbox ; mailbox
; username ; username
; template ; template

Loading…
Cancel
Save