update_call_counter(): indentation fixes and small simplifications

at the top of the function.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@44750 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 19 years ago
parent 06ef2c1907
commit ad63b4c7c1

@ -2910,7 +2910,7 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner)
static int update_call_counter(struct sip_pvt *fup, int event) static int update_call_counter(struct sip_pvt *fup, int event)
{ {
char name[256]; char name[256];
int *inuse, *call_limit, *inringing = NULL; int *inuse, *call_limit, *inringing;
int outgoing = ast_test_flag(&fup->flags[0], SIP_OUTGOING); int outgoing = ast_test_flag(&fup->flags[0], SIP_OUTGOING);
struct sip_user *u = NULL; struct sip_user *u = NULL;
struct sip_peer *p = NULL; struct sip_peer *p = NULL;
@ -2924,96 +2924,91 @@ static int update_call_counter(struct sip_pvt *fup, int event)
ast_copy_string(name, fup->username, sizeof(name)); ast_copy_string(name, fup->username, sizeof(name));
/* Check the list of users */ /* Check the list of users only for incoming calls */
if (!outgoing) /* Only check users for incoming calls */ if (!outgoing && (u = find_user(name, 1)) ) {
u = find_user(name, 1);
if (u) {
inuse = &u->inUse; inuse = &u->inUse;
call_limit = &u->call_limit; call_limit = &u->call_limit;
p = NULL; inringing = NULL;
} else if ( (p = find_peer(fup->peername, NULL, 1) ) ) { /* Try to find peer */
inuse = &p->inUse;
call_limit = &p->call_limit;
inringing = &p->inRinging;
ast_copy_string(name, fup->peername, sizeof(name));
} else { } else {
/* Try to find peer */ if (option_debug > 1)
if (!p) ast_log(LOG_DEBUG, "%s is not a local device, no call limit\n", name);
p = find_peer(fup->peername, NULL, 1); return 0;
if (p) {
inuse = &p->inUse;
call_limit = &p->call_limit;
inringing = &p->inRinging;
ast_copy_string(name, fup->peername, sizeof(name));
} else {
if (option_debug > 1)
ast_log(LOG_DEBUG, "%s is not a local device, no call limit\n", name);
return 0;
}
} }
switch(event) { switch(event) {
/* incoming and outgoing affects the inUse counter */ /* incoming and outgoing affects the inUse counter */
case DEC_CALL_LIMIT: case DEC_CALL_LIMIT:
if ( *inuse > 0 ) { if ( *inuse > 0 ) {
if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT))
(*inuse)--; (*inuse)--;
} else { } else {
*inuse = 0; *inuse = 0;
} }
if (inringing) { if (inringing) {
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
if (*inringing > 0) if (*inringing > 0)
(*inringing)--; (*inringing)--;
else else
ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername); ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername);
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING); ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
}
}
if (option_debug > 1 || sipdebug) {
ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
}
break;
case INC_CALL_RINGING:
case INC_CALL_LIMIT:
if (*call_limit > 0 ) {
if (*inuse >= *call_limit) {
ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
if (u)
ASTOBJ_UNREF(u, sip_destroy_user);
else
ASTOBJ_UNREF(p, sip_destroy_peer);
return -1;
}
} }
if (inringing && (event == INC_CALL_RINGING)) { }
if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { if (option_debug > 1 || sipdebug) {
(*inringing)++; ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING); }
} break;
case INC_CALL_RINGING:
case INC_CALL_LIMIT:
if (*call_limit > 0 ) {
if (*inuse >= *call_limit) {
ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
if (u)
ASTOBJ_UNREF(u, sip_destroy_user);
else
ASTOBJ_UNREF(p, sip_destroy_peer);
return -1;
} }
/* Continue */ }
(*inuse)++; if (inringing && (event == INC_CALL_RINGING)) {
ast_set_flag(&fup->flags[0], SIP_INC_COUNT); if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
if (option_debug > 1 || sipdebug) { (*inringing)++;
ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit); ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
} }
break; }
case DEC_CALL_RINGING: /* Continue */
if (inringing) { (*inuse)++;
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
if (*inringing > 0) if (option_debug > 1 || sipdebug) {
(*inringing)--; ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
else }
ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name); break;
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
} case DEC_CALL_RINGING:
if (inringing) {
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
if (*inringing > 0)
(*inringing)--;
else
ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name);
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
} }
break; }
default: break;
ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
default:
ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
} }
if (p) if (p) {
ast_device_state_changed("SIP/%s", p->name); ast_device_state_changed("SIP/%s", p->name);
if (u)
ASTOBJ_UNREF(u, sip_destroy_user);
else
ASTOBJ_UNREF(p, sip_destroy_peer); ASTOBJ_UNREF(p, sip_destroy_peer);
} else /* u must be set */
ASTOBJ_UNREF(u, sip_destroy_user);
return 0; return 0;
} }

Loading…
Cancel
Save