--- chan_sip.c.bak 2005-01-26 16:55:15.000000000 -0500 +++ chan_sip.c 2005-01-31 14:33:31.000000000 -0500 @@ -8986,6 +8986,66 @@ return 0; } +static char *synopsis_inuse = "SIPInUse(username[,maxusagecount])"; +static char *descrip_inuse = +"SIPInUse(username[,maxusagecount])\n" +" Checks the inuse counter of SIP user and sets channel variable INUSE.\n" +"If maxusagecount is given and inuse counter is less than maxusagecount,\n" +"we continue to the next step. Otherwise if inuse counter is more or equal\n" +"maxusagecount and if priority n+101 exists, then execution continues at\n" +"that step, otherwise -1 is returned\n"; + +static char *app_inuse = "SIPInUse"; + +/* returns inuse counter for sip peer */ +static int sip_inuse(struct ast_channel *chan, void *data) +{ + char user_name[256]; + struct sip_user *user; + char inuse_str[40]; + char *maxcnt_str=NULL; + int maxcnt = 0; + int inuse = 0; + int ret = 0; + + if (data && !ast_strlen_zero(data)) { + strncpy(user_name,data,sizeof(user_name)-1); + maxcnt_str=strchr(user_name,'|'); + if (maxcnt_str) { + *maxcnt_str='\0'; + maxcnt_str++; + if (maxcnt_str && !ast_strlen_zero(maxcnt_str)) { + maxcnt=atoi(maxcnt_str); + if (maxcnt<0) { + ast_log(LOG_WARNING,"Invalid maxusagecount specified: %d\n",maxcnt); + maxcnt=0; + } + } + } + } else { + ast_log(LOG_WARNING, "This application requires the argument: sip username\n"); + return 0; + } + ast_mutex_lock(&userl.lock); + user = find_user(user_name); + if (user) { + inuse=user->inUse; + if (maxcnt && inuse>=maxcnt) { + if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid)) + chan->priority += 100; + else + ret = -1; + } + } else { + ast_log(LOG_WARNING, "SIP user %s not found",user_name); + } + ast_mutex_unlock(&userl.lock); + snprintf(inuse_str,sizeof(inuse_str),"%d",inuse); + pbx_builtin_setvar_helper(chan,"INUSE",inuse_str); + + return ret; +} + static int sip_get_codec(struct ast_channel *chan) { struct sip_pvt *p = chan->pvt->pvt; @@ -9169,6 +9229,7 @@ sip_rtp.type = type; ast_rtp_proto_register(&sip_rtp); ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode); + ast_register_application(app_inuse,sip_inuse,synopsis_inuse,descrip_inuse); ast_mutex_lock(&peerl.lock); for (peer = peerl.peers; peer; peer = peer->next) sip_poke_peer(peer); @@ -9191,6 +9252,7 @@ /* First, take us out of the channel loop */ ast_unregister_application(app_dtmfmode); + ast_unregister_application(app_inuse); ast_cli_unregister(&cli_show_users); ast_cli_unregister(&cli_show_channels); ast_cli_unregister(&cli_show_channel);