Advertisement
Guest User

Untitled

a guest
Jan 5th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.25 KB | None | 0 0
  1. ### Limits Loaded frm DB here for a Known Caller
  2. route[CHECK_USER_LIMITS] {
  3.  
  4.         if(!is_method("INVITE"))
  5.                 return(1);
  6.  
  7.         if($avp(from-extension-id) == NULL ){
  8.                 $avp(from-extension-id) = $hdr(X-ext-id);
  9.                 if($avp(from-extension-id) == NULL ){
  10.                         xlog("L_CRIT", "[$cfg_file:$cfg_line] $xlog_level\t[$ci] - Unable to locate Limits for User:$fu !!");
  11.                 }
  12.         }
  13.         if (!cache_fetch("local", "limits-$fU@$fd", $var(cached-limits)) ) {
  14.                 if ($avp(from-extension-id) != "" && $avp(from-extension-id) != NULL) {
  15.                         # We know this is a user which is defined in DB, next we need to load its Limits.
  16.                         async(
  17.                                         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})'",
  18.                                                 "$avp(limit_results)",
  19.                                                 0),
  20.                                         CACHE_LIMITS
  21.                              );
  22.                         # This is really not needed because of async never resuming here.
  23.                         return(1);
  24.  
  25.                 }
  26.         }else{
  27.                 # Cache Limits found in Cache, Execute them
  28.                 route(EXECUTE_LIMITS);
  29.         }
  30. }
  31. route[CACHE_LIMITS] {
  32.         switch($rc) {
  33.                 case -1:
  34.                         # Mayeb use Global Limits instead of per-user limits since there is none in DB for this known-caller !
  35.                         xlog("L_ERR", "[$ci] - DB Query failed - Could not find Limits");
  36.                         send_reply(500, "Failure #F23-$cfg_line");
  37.                         exit;
  38.                         break;
  39.                 case -2:
  40.                         #Same as Case-1
  41.                         xlog("L_ERR", "[$ci] - No such user $avp(from-extension-id)");
  42.                         send_reply(403, "Forbidden #F24-$cfg_line");
  43.                         exit;
  44.                         break;
  45.                 default:
  46.                         #userInbound=-1;userOutbound=4;userConcurrent=6;userInternational=1
  47.                         $var(cached-limits) = $avp(limit_results);
  48.                         xlog("L_CRIT", "[$ci] Limits DB-Loaded for userId:$avp(from-extension-id) / $fu LIMITS: $var(cached-limits)");
  49.                         cache_store("local", "limits-$fU@$fd", "$var(cached-limits)", 600);
  50.                         route(EXECUTE_LIMITS);
  51.         }
  52. }
  53. route[EXECUTE_LIMITS]{
  54.         #We got 2 things here, 1: Total Limits $var(cached-limits) 2: Active-Calls-Count
  55.         #We fetch Dialogs' based limits ie ongoing calls for this user and
  56.         #compare them against the Max-supplied limits $var(cahed-limits)
  57.  
  58.         $avp(key) = $fU + "@" + $fd ;
  59.         #Caller Outbound,Intl,Total calls
  60.         route(DLG_PROFILE_OPS,$avp(key),"userOutbound");
  61.         route(DLG_PROFILE_OPS,$avp(key),"userConcurrent");
  62.  
  63.         #Callee Incoming Calls
  64.         $avp(key) = $rU + "@" + $fd;
  65.         route(DLG_PROFILE_OPS,$avp(key),"userInbound");
  66.         route(DLG_PROFILE_OPS,$avp(key),"userConcurrent");
  67.  
  68.         append_hf("X-user-limits: $var(cached-limits)\r\n");
  69. }
  70.  
  71. #1 :Profile Name
  72. #2 :Limit Type
  73. route[DLG_PROFILE_OPS] {
  74.         $var(keyName) = $param(1);
  75.         $var(profileName) = $param(2) + "/b";
  76.         $var(paramName) = $param(2);
  77.  
  78.         if ( $param(3) != NULL ) {
  79.                 $var(allowedLimit) = $(var(cached-limits){param.value,channels}{s.int});
  80.         }else{
  81.                 $var(allowedLimit) = $(var(cached-limits){param.value,$var(paramName)}{s.int});
  82.         }
  83.  
  84.         set_dlg_profile($var(profileName),$var(keyName));
  85.  
  86.         if( $var(allowedLimit) != -1) {
  87.                 get_profile_size($var(profileName), $var(keyName), $var(profileCount));
  88.                 if ($var(profileCount) > $var(allowedLimit) ){
  89.                         # Call not Allowed
  90.                         route(LIMIT_EXCEEDED,$var(profileCount),$var(keyName),$var(profileName),$var(allowedLimit));
  91.                 }
  92.         }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement