Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Limits Loaded frm DB here for a Known Caller
- route[CHECK_USER_LIMITS] {
- if(!is_method("INVITE"))
- return(1);
- if($avp(from-extension-id) == NULL ){
- $avp(from-extension-id) = $hdr(X-ext-id);
- if($avp(from-extension-id) == NULL ){
- xlog("L_CRIT", "[$cfg_file:$cfg_line] $xlog_level\t[$ci] - Unable to locate Limits for User:$fu !!");
- }
- }
- if (!cache_fetch("local", "limits-$fU@$fd", $var(cached-limits)) ) {
- if ($avp(from-extension-id) != "" && $avp(from-extension-id) != NULL) {
- # We know this is a user which is defined in DB, next we need to load its Limits.
- async(
- avp_db_query("SELECT CONCAT('userInbound=',max_inbound, ';userOutbound=', max_outbound, ';userConcurrent=', max_concurrent, ';userInternational=', max_international) FROM user_limits WHERE extension_id = '$(avp(from-extension-id){s.escape.common})'",
- "$avp(limit_results)",
- 0),
- CACHE_LIMITS
- );
- # This is really not needed because of async never resuming here.
- return(1);
- }
- }else{
- # Cache Limits found in Cache, Execute them
- route(EXECUTE_LIMITS);
- }
- }
- route[CACHE_LIMITS] {
- switch($rc) {
- case -1:
- # Mayeb use Global Limits instead of per-user limits since there is none in DB for this known-caller !
- xlog("L_ERR", "[$ci] - DB Query failed - Could not find Limits");
- send_reply(500, "Failure #F23-$cfg_line");
- exit;
- break;
- case -2:
- #Same as Case-1
- xlog("L_ERR", "[$ci] - No such user $avp(from-extension-id)");
- send_reply(403, "Forbidden #F24-$cfg_line");
- exit;
- break;
- default:
- #userInbound=-1;userOutbound=4;userConcurrent=6;userInternational=1
- $var(cached-limits) = $avp(limit_results);
- xlog("L_CRIT", "[$ci] Limits DB-Loaded for userId:$avp(from-extension-id) / $fu LIMITS: $var(cached-limits)");
- cache_store("local", "limits-$fU@$fd", "$var(cached-limits)", 600);
- route(EXECUTE_LIMITS);
- }
- }
- route[EXECUTE_LIMITS]{
- #We got 2 things here, 1: Total Limits $var(cached-limits) 2: Active-Calls-Count
- #We fetch Dialogs' based limits ie ongoing calls for this user and
- #compare them against the Max-supplied limits $var(cahed-limits)
- $avp(key) = $fU + "@" + $fd ;
- #Caller Outbound,Intl,Total calls
- route(DLG_PROFILE_OPS,$avp(key),"userOutbound");
- route(DLG_PROFILE_OPS,$avp(key),"userConcurrent");
- #Callee Incoming Calls
- $avp(key) = $rU + "@" + $fd;
- route(DLG_PROFILE_OPS,$avp(key),"userInbound");
- route(DLG_PROFILE_OPS,$avp(key),"userConcurrent");
- append_hf("X-user-limits: $var(cached-limits)\r\n");
- }
- #1 :Profile Name
- #2 :Limit Type
- route[DLG_PROFILE_OPS] {
- $var(keyName) = $param(1);
- $var(profileName) = $param(2) + "/b";
- $var(paramName) = $param(2);
- if ( $param(3) != NULL ) {
- $var(allowedLimit) = $(var(cached-limits){param.value,channels}{s.int});
- }else{
- $var(allowedLimit) = $(var(cached-limits){param.value,$var(paramName)}{s.int});
- }
- set_dlg_profile($var(profileName),$var(keyName));
- if( $var(allowedLimit) != -1) {
- get_profile_size($var(profileName), $var(keyName), $var(profileCount));
- if ($var(profileCount) > $var(allowedLimit) ){
- # Call not Allowed
- route(LIMIT_EXCEEDED,$var(profileCount),$var(keyName),$var(profileName),$var(allowedLimit));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement