Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into WHISTLE-1121
  • Loading branch information
James Aimonetti committed Apr 15, 2012
2 parents 232c83a + 5b2cc37 commit 2c8fd8b
Show file tree
Hide file tree
Showing 32 changed files with 1,490 additions and 2,088 deletions.
2 changes: 1 addition & 1 deletion ecallmgr/src/ecallmgr.erl
Expand Up @@ -47,5 +47,5 @@ stop() ->
-spec start_deps/0 :: () -> 'ok'.
start_deps() ->
lager:start(),
_ = [wh_util:ensure_started(App) || App <- [sasl, crypto, gproc, whistle_amqp, ibrowse]],
_ = [wh_util:ensure_started(App) || App <- [sasl, crypto, whistle_amqp, gproc, ibrowse]],
ok.
2 changes: 1 addition & 1 deletion ecallmgr/src/ecallmgr.hrl
Expand Up @@ -6,7 +6,7 @@
-include_lib("whistle/include/freeswitch_xml.hrl").
-include_lib("whistle/src/wh_api.hrl").

-define(AMQP_POOL_MGR, ecallmgr_amqp_pool).
-define(ECALLMGR_AMQP_POOL, ecallmgr_amqp_pool).

-type fs_api_ret() :: {'ok', binary()} | {'error', binary()} | 'timeout'.
-type fs_sendmsg_ret() :: 'ok' | {'error', binary()} | 'timeout'.
Expand Down
126 changes: 0 additions & 126 deletions ecallmgr/src/ecallmgr_amqp_pool.erl

This file was deleted.

27 changes: 11 additions & 16 deletions ecallmgr/src/ecallmgr_authz.erl
Expand Up @@ -62,23 +62,18 @@ authz_win(Pid) when is_pid(Pid) ->
init_authorize(Parent, FSID, CallID, FSData) ->
proc_lib:init_ack(Parent, {ok, self()}),
put(callid, CallID),

lager:debug("authorize started"),

ReqProp = request(FSID, CallID, FSData),

JObj = try
{ok, RespJObj} = ecallmgr_amqp_pool:authz_req(ReqProp, 2000),
true = wapi_authz:resp_v(RespJObj),
RespJObj
catch
_T:_R ->
lager:debug("authz request un-answered or improper"),
lager:debug("authz ~p: ~p", [_T, _R]),
default()
end,

authorize_loop(JObj).
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,request(FSID, CallID, FSData)
,fun wapi_authz:publish_req/1
,fun wapi_authz:is_authorized/1),
case ReqResp of
{error, _R} ->
lager:debug("authz request lookup failed: ~p", [_R]),
default();
{ok, RespJObj} ->
authorize_loop(RespJObj)
end.

-spec authorize_loop/1 :: (wh_json:json_object()) -> no_return().
authorize_loop(JObj) ->
Expand Down
2 changes: 1 addition & 1 deletion ecallmgr/src/ecallmgr_call_events.erl
Expand Up @@ -356,7 +356,7 @@ publish_event(Props) ->
ApplicationData = props:get_value(<<"Raw-Application-Data">>, Props, <<>>),
lager:debug("publishing call event ~s '~s(~s)'", [EventName, ApplicationName, ApplicationData])
end,
wapi_call:publish_event(CallId, Props).
wh_amqp_worker:cast(?ECALLMGR_AMQP_POOL, Props, fun(P) -> wapi_call:publish_event(CallId, P) end).

-spec is_masquerade/1 :: (proplist()) -> boolean().
is_masquerade(Props) ->
Expand Down
32 changes: 19 additions & 13 deletions ecallmgr/src/ecallmgr_config.erl
Expand Up @@ -48,10 +48,15 @@ get(Key0, Default, Node0) ->
V =/= undefined],

lager:debug("looking up ~s from sysconf", [Key]),

case ecallmgr_amqp_pool:get_req(Req) of
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,Req
,fun wapi_sysconf:publish_get_req/1
,fun wapi_sysconf:get_resp_v/1),
case ReqResp of
{error, _R} ->
lager:debug("unable to get config for key '~s' failed: ~p", [Key0, _R]),
Default;
{ok, RespJObj} ->
true = wapi_sysconf:get_resp_v(RespJObj),
V = case wh_json:get_value(<<"Value">>, RespJObj) of
undefined -> Default;
null -> Default;
Expand All @@ -61,8 +66,7 @@ get(Key0, Default, Node0) ->
wh_cache:store_local(Cache, cache_key(Key, Node), Value),
Value
end,
V;
{error, timeout} -> Default
V
end
end.

Expand All @@ -73,10 +77,8 @@ set(Key, Value) ->
set(Key0, Value, Node0) ->
Key = wh_util:to_binary(Key0),
Node = wh_util:to_binary(Node0),

{ok, Cache} = ecallmgr_util_sup:cache_proc(),
wh_cache:store_local(Cache, cache_key(Key, Node), Value),

Req = [KV ||
{_, V} = KV <- [{<<"Category">>, <<"ecallmgr">>}
,{<<"Key">>, Key}
Expand All @@ -85,12 +87,16 @@ set(Key0, Value, Node0) ->
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
V =/= undefined],
case catch ecallmgr_amqp_pool:set_req(Req) of
{'EXIT', _} ->
lager:debug("failed to recv resp for setting ~s to ~p", [Key, Value]);
_ ->
lager:debug("recv resp for setting ~s to ~p", [Key, Value])
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,Req
,fun wapi_sysconf:publish_set_req/1
,fun wh_amqp_worker:any_resp/1),
case ReqResp of
{error, _R} ->
lager:debug("set config for key '~s' failed: ~p", [Key0, _R]);
{ok, _} ->
lager:debug("set config for key '~s' to new value: ~p", [Key0, Value])
end.

cache_key(K, Node) ->
{?MODULE, K, Node}.
38 changes: 18 additions & 20 deletions ecallmgr/src/ecallmgr_fs_auth.erl
Expand Up @@ -128,7 +128,7 @@ handle_info({fetch, directory, <<"domain">>, <<"name">>, _Value, ID, [undefined
case {props:get_value(<<"Event-Name">>, Data), props:get_value(<<"action">>, Data)} of
{<<"REQUEST_PARAMS">>, <<"sip_auth">>} ->
%% TODO: move this to a supervisor somewhere....
lookup_user(Node, ID, Data),
proc_lib:spawn(?MODULE, lookup_user, [Node, ID, Data]),
{noreply, State, hibernate};
_Other ->
_ = freeswitch:fetch_reply(Node, ID, ?EMPTYRESPONSE),
Expand Down Expand Up @@ -176,33 +176,31 @@ code_change(_OldVsn, State, _Extra) ->
lookup_user(Node, ID, Data) ->
spawn(fun() ->
put(callid, ID),

%% build req for rabbit
AuthRealm = props:get_value(<<"domain">>, Data, props:get_value(<<"Auth-Realm">>, Data)),
AuthUser = props:get_value(<<"user">>, Data, props:get_value(<<"Auth-User">>, Data)),

AuthReq = [{<<"Msg-ID">>, ID}
,{<<"To">>, ecallmgr_util:get_sip_to(Data)}
,{<<"From">>, ecallmgr_util:get_sip_from(Data)}
,{<<"Orig-IP">>, ecallmgr_util:get_orig_ip(Data)}
,{<<"Method">>, props:get_value(<<"sip_auth_method">>, Data)}
,{<<"Auth-User">>, AuthUser}
,{<<"Auth-Realm">>, AuthRealm}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],

lager:debug("looking up credentials of ~s@~s for a ~s", [AuthUser, AuthRealm, props:get_value(<<"Method">>, AuthReq)]),

case ecallmgr_amqp_pool:authn_req(AuthReq) of
Method = props:get_value(<<"sip_auth_method">>, Data),
lager:debug("looking up credentials of ~s@~s for a ~s", [AuthUser, AuthRealm, Method]),
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,[{<<"Msg-ID">>, ID}
,{<<"To">>, ecallmgr_util:get_sip_to(Data)}
,{<<"From">>, ecallmgr_util:get_sip_from(Data)}
,{<<"Orig-IP">>, ecallmgr_util:get_orig_ip(Data)}
,{<<"Method">>, Method}
,{<<"Auth-User">>, AuthUser}
,{<<"Auth-Realm">>, AuthRealm}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
]
,fun wapi_authn:publish_req/1
,fun wapi_authn:resp_v/1),
case ReqResp of
{error, _R} ->
lager:debug("authn request lookup failed: ~p", [_R]),
freeswitch:fetch_reply(Node, ID, ?ROUTE_NOT_FOUND_RESPONSE);
{ok, AuthResp} ->
true = wapi_authn:resp_v(AuthResp),
lager:debug("received authn_resp"),
{ok, RespJObj} ->
{ok, Xml} = ecallmgr_fs_xml:authn_resp_xml(
wh_json:set_value(<<"Auth-Realm">>, AuthRealm
,wh_json:set_value(<<"Auth-User">>, AuthUser, AuthResp))
,wh_json:set_value(<<"Auth-User">>, AuthUser, RespJObj))
),
lager:debug("sending XML to ~w: ~s", [Node, Xml]),
freeswitch:fetch_reply(Node, ID, Xml)
Expand Down
1 change: 0 additions & 1 deletion ecallmgr/src/ecallmgr_fs_node.erl
Expand Up @@ -168,7 +168,6 @@ init([Node, Options]) ->
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
-spec handle_call/3 :: ('node', {pid(), reference()}, #state{}) -> {'reply', atom(), #state{}}.
handle_call(node, _From, #state{node=Node}=State) ->
{reply, Node, State}.

Expand Down
11 changes: 7 additions & 4 deletions ecallmgr/src/ecallmgr_fs_route.erl
Expand Up @@ -194,12 +194,15 @@ authorize_and_route(Node, FSID, CallID, FSData, DefProp) ->
-spec route/5 :: (atom(), ne_binary(), ne_binary(), proplist(), pid() | 'undefined') -> 'ok'.
route(Node, FSID, CallID, DefProp, AuthZPid) ->
lager:debug("starting route request from node ~s", [Node]),
case ecallmgr_amqp_pool:route_req(DefProp) of
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,DefProp
,fun wapi_route:publish_req/1
,fun wapi_route:is_actionable_resp/1),
case ReqResp of
{error, _R} -> lager:debug("did not receive route response: ~p", [_R]);
{ok, RespJObj} ->
RouteCCV = wh_json:get_value(<<"Custom-Channel-Vars">>, RespJObj, wh_json:new()),
authorize(Node, FSID, CallID, RespJObj, AuthZPid, RouteCCV);
_Else ->
lager:debug("did not receive route response: ~p", [_Else])
authorize(Node, FSID, CallID, RespJObj, AuthZPid, RouteCCV)
end.

-spec authorize/6 :: (atom(), ne_binary(), ne_binary(), wh_json:json_object(), pid() | 'undefined', wh_json:json_object()) -> 'ok'.
Expand Down
20 changes: 11 additions & 9 deletions ecallmgr/src/ecallmgr_media_registry.erl
Expand Up @@ -255,15 +255,17 @@ lookup_remote(MediaName, new, CallID) ->

-spec lookup_remote/2 :: (ne_binary(), proplist()) -> {'ok', ne_binary()} | {'error', 'not_local'}.
lookup_remote(MediaName, Request) ->
try
{ok, MediaResp} = ecallmgr_amqp_pool:media_req(Request, 2000),
true = wapi_media:resp_v(MediaResp),
MediaName = wh_json:get_value(<<"Media-Name">>, MediaResp),

{ok, wh_json:get_value(<<"Stream-URL">>, MediaResp, <<>>)}
catch
_:B ->
{error, B}
ReqResp = wh_amqp_worker:call(?ECALLMGR_AMQP_POOL
,Request
,fun wapi_media:publish_req/1
,fun wapi_media:resp_v/1),
case ReqResp of
{error, _R}=E ->
lager:debug("media lookup for '~s' failed: ~p", [MediaName, _R]),
E;
{ok, MediaResp} ->
MediaName = wh_json:get_value(<<"Media-Name">>, MediaResp),
{ok, wh_json:get_value(<<"Stream-URL">>, MediaResp, <<>>)}
end.

wait_for_fs_media({Path,_}, RecvSrv, FromPid) ->
Expand Down

0 comments on commit 2c8fd8b

Please sign in to comment.