Skip to content
Browse files

WHISTLE-788: update logging in j5

  • Loading branch information...
1 parent 41d77c4 commit e1ce493883d4bf3028b8f0a6ef26fbd75f9e59cd @jamesaimonetti jamesaimonetti committed Feb 2, 2012
Showing with 26 additions and 31 deletions.
  1. +20 −22 whistle_apps/apps/jonny5/src/authz_req.erl
  2. +6 −9 whistle_apps/apps/jonny5/src/j5_util.erl
View
42 whistle_apps/apps/jonny5/src/authz_req.erl
@@ -18,44 +18,42 @@ init() ->
handle_req(JObj, _Props) ->
case wapi_authz:req_v(JObj) of
- false -> throw({failed_api_validation, JObj});
- true -> ?LOG("Valid authz_req")
+ false -> throw({failed_api_validation, JObj});
+ true -> ?LOG("valid authz_req")
end,
wh_util:put_callid(JObj),
- ?LOG("Authorize ~s can make the call to ~s", [wh_json:get_value(<<"From">>, JObj), wh_json:get_value(<<"To">>, JObj)]),
+ ?LOG("authorize ~s can make the call to ~s", [wh_json:get_value(<<"From">>, JObj), wh_json:get_value(<<"Request">>, JObj)]),
AuthZResp = case {wh_json:get_value([<<"Custom-Channel-Vars">>, <<"Account-ID">>], JObj)
- ,wh_json:get_value([<<"Custom-Channel-Vars">>, <<"Authorizing-ID">>], JObj)
- } of
- {AcctID, undefined} when is_binary(AcctID) ->
- %% Coming from carrier (off-net)
- ?LOG("Trying to authorize inbound call"),
- j5_acctmgr:authz_trunk(AcctID, JObj, inbound);
- {AcctID, AuthID} when is_binary(AcctID) andalso is_binary(AuthID) ->
- %% Coming from PBX (on-net); authed by Registrar
- ?LOG("Trying to authorize outbound call"),
- j5_acctmgr:authz_trunk(AcctID, JObj, outbound);
- {_AcctID, _AuthID} ->
- ?LOG("Error in finding authorization: AcctID: ~s AuthID: ~s", [_AcctID, _AuthID]),
- undefined
- end,
+ ,wh_json:get_value([<<"Custom-Channel-Vars">>, <<"Authorizing-ID">>], JObj)
+ } of
+ {AcctID, undefined} when is_binary(AcctID) ->
+ %% Coming from carrier (off-net)
+ ?LOG("trying to authorize inbound call"),
+ j5_acctmgr:authz_trunk(AcctID, JObj, inbound);
+ {AcctID, AuthID} when is_binary(AcctID) andalso is_binary(AuthID) ->
+ %% Coming from PBX (on-net); authed by Registrar
+ ?LOG("trying to authorize outbound call"),
+ j5_acctmgr:authz_trunk(AcctID, JObj, outbound);
+ {_AcctID, _AuthID} ->
+ ?LOG("error in finding authorization: AcctID: ~s AuthID: ~s", [_AcctID, _AuthID]),
+ undefined
+ end,
send_resp(JObj, AuthZResp).
send_resp(_JObj, undefined) ->
?LOG_END("No response for authz");
send_resp(JObj, {AuthzResp, CCV}) ->
?LOG_SYS("sending authz response ~s", [AuthzResp]),
- ?LOG_SYS("CCVs: ~p", [CCV]),
- ?LOG_SYS("Send authz_win to ~s", [props:get_value(<<"Server-ID">>, CCV, missing)]),
Resp = [{<<"Is-Authorized">>, wh_util:to_binary(AuthzResp)}
,{<<"Custom-Channel-Vars">>, wh_json:from_list(props:delete(<<"Server-ID">>, CCV))}
,{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj)}
,{<<"Call-ID">>, wh_json:get_value(<<"Call-ID">>, JObj)}
- ,{<<"Server-ID">>, props:get_value(<<"Server-ID">>, CCV)}
+ ,{<<"Server-ID">>, props:get_value(<<"Server-ID">>, CCV)}
,{<<"App-Name">>, ?APP_NAME}
- ,{<<"App-Version">>, ?APP_VERSION}
- ],
+ ,{<<"App-Version">>, ?APP_VERSION}
+ ],
wapi_authz:publish_resp(wh_json:get_value(<<"Server-ID">>, JObj), Resp).
View
15 whistle_apps/apps/jonny5/src/j5_util.erl
@@ -37,29 +37,26 @@ fetch_all_accounts(Cache) ->
-spec fetch_account/1 :: (ne_binary()) -> wh_json:json_object() | {'error', 'not_found'}.
fetch_account(AcctID) ->
case fetch_account_handler(AcctID) of
- {ok, Pid} ->
- j5_acctmgr:status(Pid);
+ {ok, Pid} -> j5_acctmgr:status(Pid);
{error, _}=E -> E
end.
-spec fetch_account_handler/1 :: (ne_binary()) -> {'ok', pid()} | {'error', 'not_found'}.
+-spec fetch_account_handler/2 :: (ne_binary(), pid()) -> {'ok', pid()} | {'error', 'not_found'}.
fetch_account_handler(AcctID) ->
{ok, Cache} = jonny5_sup:cache_proc(),
fetch_account_handler(AcctID, Cache).
-
--spec fetch_account_handler/2 :: (ne_binary(), pid()) -> {'ok', pid()} | {'error', 'not_found'}.
fetch_account_handler(AcctID, Cache) when is_pid(Cache) ->
wh_cache:fetch_local(Cache, cache_account_handler_key(AcctID)).
-spec store_account_handler/2 :: (ne_binary(), pid() | 'undefined') -> 'ok'.
-store_account_handler(AcctID, J5Pid) ->
+-spec store_account_handler/3 :: (ne_binary(), pid() | 'undefined', pid()) -> 'ok'.
+store_account_handler(AcctID, J5Pid) when is_pid(J5Pid) ->
{ok, Cache} = jonny5_sup:cache_proc(),
store_account_handler(AcctID, J5Pid, Cache).
-
--spec store_account_handler/3 :: (ne_binary(), pid() | 'undefined', pid()) -> 'ok'.
-store_account_handler(AcctID, undefined, Cache) ->
+store_account_handler(AcctID, undefined, Cache) when is_pid(Cache) ->
wh_cache:erase_local(Cache, cache_account_handler_key(AcctID));
-store_account_handler(AcctID, J5Pid, Cache) when is_pid(J5Pid) ->
+store_account_handler(AcctID, J5Pid, Cache) when is_pid(J5Pid), is_pid(Cache) ->
wh_cache:store_local(Cache, cache_account_handler_key(AcctID), J5Pid, infinity).
cache_account_handler_key(AcctID) ->

0 comments on commit e1ce493

Please sign in to comment.
Something went wrong with that request. Please try again.