Skip to content

Commit

Permalink
routing inbound to a user
Browse files Browse the repository at this point in the history
  • Loading branch information
James Aimonetti committed Oct 31, 2010
1 parent c722522 commit c2bf233
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 16 deletions.
Binary file modified applications/trunkstore/ebin/ts_route.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/whistle_api.beam
Binary file not shown.
7 changes: 1 addition & 6 deletions applications/trunkstore/src/ts_route.erl
Expand Up @@ -142,12 +142,7 @@ find_route(Flags, ApiProp, ServerID) ->
-spec(inbound_route/1 :: (Flags :: tuple()) -> tuple(ok | error, proplist() | string())).
inbound_route(Flags) ->
format_log(info, "TS_ROUTE(~p): Inbound route flags: ~p~n", [self(), Flags]),
%User = case Flags#route_flags.inbound_format of
% <<"E.164">> -> ts_util:to_e164(Flags#route_flags.to_user);
% <<"1NPANXXXXXX">> -> ts_util:to_1npanxxxxxx(Flags#route_flags.to_user);
% _NPANXXXXXX -> ts_util:to_npanxxxxxx(Flags#route_flags.to_user)
% end,
Dialstring = list_to_binary(["${sofia_contact(", Flags#route_flags.auth_user, "@$${domain})}"]),
Dialstring = list_to_binary(["user:", Flags#route_flags.auth_user]),
Route = [{<<"Route">>, Dialstring}
,{<<"Weight-Cost">>, 1}
,{<<"Weight-Location">>, 1}
Expand Down
Binary file modified ecallmgr/ebin/ecallmgr_call_events.beam
Binary file not shown.
Binary file modified ecallmgr/ebin/ecallmgr_fs_auth.beam
Binary file not shown.
Binary file modified ecallmgr/ebin/ecallmgr_fs_handler.beam
Binary file not shown.
Binary file modified ecallmgr/ebin/ecallmgr_fs_route.beam
Binary file not shown.
Binary file modified ecallmgr/ebin/ecallmgr_util.beam
Binary file not shown.
Binary file modified ecallmgr/ebin/whistle_api.beam
Binary file not shown.
16 changes: 9 additions & 7 deletions ecallmgr/src/ecallmgr_fs_route.erl
Expand Up @@ -133,7 +133,7 @@ lookup_route(Node, #handler_state{amqp_host=Host, app_vsn=Vsn}=HState, ID, UUID,
{ok, JSON} ->
format_log(info, "L/U.route(~p): Sending RouteReq JSON to Host(~p)~n", [self(), Host]),
send_request(Host, JSON),
Result = handle_response(ID, UUID, EvtQ, CtlQ, HState, FetchPid),
Result = handle_response(ID, UUID, EvtQ, CtlQ, HState, FetchPid, Data),
amqp_util:queue_delete(Host, Q),
Result;
{error, _Msg} ->
Expand Down Expand Up @@ -213,11 +213,11 @@ send_control_queue(Host, CtlProp, AppQ) ->
end.

%% Prop = Route Response
generate_xml(<<"bridge">>, Routes, _Prop) ->
generate_xml(<<"bridge">>, Routes, _Prop, Domain) ->
format_log(info, "L/U.route(~p): BRIDGEXML: Routes:~n~p~n", [self(), Routes]),
%% format the Route based on protocol
{_Idx, Extensions} = lists:foldl(fun({struct, RouteProp}, {Idx, Acc}) ->
Route = get_value(<<"Route">>, RouteProp), %% translate Route to FS-encoded URI
Route = ecallmgr_util:route_to_dialstring(get_value(<<"Route">>, RouteProp), Domain),

BypassMedia = case get_value(<<"Media">>, RouteProp) of
<<"bypass">> -> "true";
Expand All @@ -238,9 +238,9 @@ generate_xml(<<"bridge">>, Routes, _Prop) ->
end, {1, ""}, lists:reverse(Routes)),
format_log(info, "L/U.route(~p): RoutesXML: ~s~n", [self(), Extensions]),
lists:flatten(io_lib:format(?ROUTE_BRIDGE_RESPONSE, [Extensions]));
generate_xml(<<"park">>, _Routes, _Prop) ->
generate_xml(<<"park">>, _Routes, _Prop, _Domain) ->
?ROUTE_PARK_RESPONSE;
generate_xml(<<"error">>, _Routes, Prop) ->
generate_xml(<<"error">>, _Routes, Prop, _Domain) ->
ErrCode = get_value(<<"Route-Error-Code">>, Prop),
ErrMsg = list_to_binary([" ", get_value(<<"Route-Error-Message">>, Prop, <<"">>)]),
format_log(info, "L/U.route(~p): ErrorXML: ~s ~s~n", [self(), ErrCode, ErrMsg]),
Expand Down Expand Up @@ -274,7 +274,7 @@ get_channel_vars({_K, _V}, Vars) ->
format_log(info, "L/U.route(~p): Unknown channel var ~p::~p~n", [self(), _K, _V]),
Vars.

handle_response(ID, UUID, EvtQ, CtlQ, #handler_state{amqp_host=Host, app_vsn=Vsn}, FetchPid) ->
handle_response(ID, UUID, EvtQ, CtlQ, #handler_state{amqp_host=Host, app_vsn=Vsn}, FetchPid, Data) ->
T1 = erlang:now(),
case recv_response(ID) of
shutdown ->
Expand All @@ -287,7 +287,9 @@ handle_response(ID, UUID, EvtQ, CtlQ, #handler_state{amqp_host=Host, app_vsn=Vsn
FetchPid ! {xml_response, ID, ?ROUTE_NOT_FOUND_RESPONSE},
failed;
Prop ->
Xml = generate_xml(get_value(<<"Method">>, Prop), get_value(<<"Routes">>, Prop), Prop),
io:format("D: ~p~n", [Data]),
Domain = get_value(<<"domain">>, Data, <<"$${domain}">>),
Xml = generate_xml(get_value(<<"Method">>, Prop), get_value(<<"Routes">>, Prop), Prop, Domain),
format_log(info, "L/U.route(~p): Sending XML to FS(~p) took ~pms ~n", [self(), ID, timer:now_diff(erlang:now(), T1) div 1000]),
FetchPid ! {xml_response, ID, Xml},

Expand Down
7 changes: 6 additions & 1 deletion ecallmgr/src/ecallmgr_util.erl
@@ -1,7 +1,7 @@
-module(ecallmgr_util).

-export([get_sip_to/1, get_sip_from/1, get_orig_ip/1, custom_channel_vars/1]).
-export([to_hex/1]).
-export([to_hex/1, route_to_dialstring/2]).

-import(proplists, [get_value/2, get_value/3]).

Expand Down Expand Up @@ -39,3 +39,8 @@ to_hex(Bin) when is_binary(Bin) ->
to_hex(binary_to_list(Bin));
to_hex(L) when is_list(L) ->
string:to_lower(lists:flatten([io_lib:format("~2.16.0B", [H]) || H <- L])).

route_to_dialstring(<<"sip:", _Rest/binary>>=DS, _Domain) -> DS;
route_to_dialstring(<<"user:", User/binary>>, Domain) ->
list_to_binary(["${regex(${sofia_contact(sipinterface_1/", User, "@", Domain, ")}|^[^\@]+(.*)|%1)}"]);
route_to_dialstring(DS, _Domain) -> DS.
1 change: 0 additions & 1 deletion src/freeswitch_xml.hrl
Expand Up @@ -56,7 +56,6 @@
<action application=\"set\" data=\"bypass_media=~s\"/>
<action application=\"set\" data=\"hangup_after_bridge=true\"/>
<action application=\"set\" data=\"failure_causes=NORMAL_CLEARING,ORIGINATOR_CANCEL,CRASH\"/>
<action application=\"set\" data=\"continue_on_fail=CALL_REJECTED,NORMAL_TEMPORARY_FAILURE,INCOMPATIBLE_DESTINATION,NO_ROUTE_DESTINATION,INVALID_NUMBER_FORMAT,NO_USER_RESPONSE,USER_BUSY,NETWORK_OUT_OF_ORDER\"/>
<action application=\"bridge\" data=\"~ssofia/sipinterface_1/~s\" />
</condition>
</extension>").
Expand Down
7 changes: 6 additions & 1 deletion src/whistle_api.hrl
Expand Up @@ -133,7 +133,12 @@
,<<"Caller-ID-Name">>, <<"Caller-ID-Number">>, <<"Caller-ID-Type">>
]).
-define(ROUTE_RESP_ROUTE_VALUES, [{<<"Media">>, [<<"process">>, <<"bypass">>, <<"auto">>]}]).
-define(ROUTE_RESP_ROUTE_TYPES, [{<<"Codecs">>, fun is_list/1}]).
-define(ROUTE_RESP_ROUTE_TYPES, [{<<"Codecs">>, fun is_list/1}
,{<<"Route">>, fun(<<"sip:", _/binary>>) -> true;
(<<"user:", _/binary>>) -> true;
(_) -> false
end}
]).

%% Route Responses - http://corp.switchfreedom.com/mediawiki/index.php/Resource_Control_%28Call_Setup_/_Teardown%29
-define(ROUTE_RESP_HEADERS, [<<"Msg-ID">>, <<"Routes">>, <<"Method">>]).
Expand Down

0 comments on commit c2bf233

Please sign in to comment.