Permalink
Browse files

WHISTLE-1678: add support to force t38_gateway

  • Loading branch information...
1 parent 927e2d2 commit 0ec723ac2850b30ef67ca8014b76bc78dd99c1e3 @k-anderson k-anderson committed Oct 3, 2012
View
8 ecallmgr/src/ecallmgr_call_command.erl
@@ -430,6 +430,14 @@ get_fs_app(Node, UUID, JObj, <<"bridge">>) ->
end
end
,fun(DP) ->
+ case wh_json:find(<<"Force-Fax">>, Endpoints, wh_json:get_value(<<"Force-Fax">>, JObj)) of
+ undefined -> DP;
+ Direction ->
+ Args = <<Direction/binary, " nocng">>,
+ [{"application", wh_util:to_list(<<"t38_gateway ", Args/binary>>)}|DP]
+ end
+ end
+ ,fun(DP) ->
[{"application", "set failure_causes=NORMAL_CLEARING,ORIGINATOR_CANCEL,CRASH"}
,{"application", "set continue_on_fail=true"}
|DP
View
6 lib/whistle-1.0.0/src/api/wapi_dialplan.hrl
@@ -28,14 +28,15 @@
,<<"Callee-ID-Name">>, <<"Callee-ID-Number">>
,<<"Ringback">>, <<"Dial-Endpoint-Method">>, <<"Insert-At">>
,<<"Media">>, <<"Hold-Media">>, <<"SIP-Headers">>, <<"Custom-Channel-Vars">>
- ,<<"SIP-Transport">>, <<"Secure-RTP">>
+ ,<<"SIP-Transport">>, <<"Secure-RTP">>, <<"Force-Fax">>
]).
-define(BRIDGE_REQ_VALUES, [{<<"Event-Category">>, <<"call">>}
,{<<"Event-Name">>, <<"command">>}
,{<<"Application-Name">>, <<"bridge">>}
,{<<"Dial-Endpoint-Method">>, [?DIAL_METHOD_SINGLE, ?DIAL_METHOD_SIMUL]}
,{<<"Media">>, [<<"process">>, <<"bypass">>, <<"auto">>]}
,{<<"SIP-Transport">>, [<<"udp">>, <<"tcp">>, <<"tls">>]}
+ ,{<<"Force-Fax">>, [<<"self">>, <<"peer">>]}
,?INSERT_AT_TUPLE
]).
-define(BRIDGE_REQ_TYPES, [{<<"Endpoints">>, fun is_list/1}
@@ -56,10 +57,11 @@
,<<"Endpoint-Timeout">>, <<"Endpoint-Progress-Timeout">>
,<<"Endpoint-Delay">>, <<"Codecs">>, <<"SIP-Headers">>, <<"Presence-ID">>
,<<"Custom-Channel-Vars">>, <<"Auth-User">>, <<"Auth-Password">>
- ,<<"Endpoint-Type">>, <<"Endpoint-Options">>
+ ,<<"Endpoint-Type">>, <<"Endpoint-Options">>, <<"Force-Fax">>
]).
-define(BRIDGE_REQ_ENDPOINT_VALUES, [?INVITE_FORMAT_TUPLE
,{<<"Endpoint-Type">>, [<<"sip">>, <<"freetdm">>]}
+ ,{<<"Force-Fax">>, [<<"self">>, <<"peer">>]}
]).
-define(BRIDGE_REQ_ENDPOINT_TYPES, [{<<"SIP-Headers">>, fun wh_json:is_json_object/1}
,{<<"Custom-Channel-Vars">>, fun wh_json:is_json_object/1}
View
3 lib/whistle-1.0.0/src/api/wapi_offnet_resource.erl
@@ -28,7 +28,7 @@
,<<"Ringback">>, <<"SIP-Headers">>, <<"Custom-Channel-Vars">>
,<<"Hold-Media">>, <<"Presence-ID">>, <<"Account-Realm">>
,<<"Control-Queue">>, <<"Call-ID">>, <<"Application-Data">>
- ,<<"Account-ID">>, <<"Outbound-Call-ID">>
+ ,<<"Account-ID">>, <<"Outbound-Call-ID">>, <<"Force-Fax">>
]).
-define(OFFNET_RESOURCE_REQ_VALUES, [{<<"Event-Category">>, <<"resource">>}
,{<<"Event-Name">>, <<"offnet_req">>}
@@ -43,6 +43,7 @@
,{<<"SIP-Headers">>, fun wh_json:is_json_object/1}
,{<<"Custom-Channel-Vars">>, fun wh_json:is_json_object/1}
,{<<"Flags">>, fun is_list/1}
+ ,{<<"Force-Fax">>, fun wh_util:is_boolean/1}
]).
%% Offnet Resource Response
View
31 whistle_apps/apps/callflow/src/cf_endpoint.erl
@@ -10,9 +10,9 @@
-include("callflow.hrl").
--export([build/2, build/3
- ,get/2, flush/2
- ]).
+-export([build/2, build/3]).
+-export([get/1, get/2]).
+-export([flush/2]).
-define(NON_DIRECT_MODULES, [cf_ring_group, acdc_util]).
@@ -124,9 +124,16 @@ create_endpoints(Endpoint, Properties, Call) ->
%% Fetches a endpoint defintion from the database or cache
%% @end
%%--------------------------------------------------------------------
+-spec get/1 :: (whapps_call:call()) ->
+ {'ok', wh_json:json_object()} |
+ {'error', term()}.
-spec get/2 :: ('undefined' | ne_binary(), ne_binary() | whapps_call:call()) ->
{'ok', wh_json:json_object()} |
{'error', term()}.
+
+get(Call) ->
+ get(whapps_call:authorizing_id(Call), Call).
+
get(undefined, _Call) ->
{error, invalid_endpoint_id};
get(EndpointId, AccountDb) when is_binary(AccountDb) ->
@@ -176,6 +183,11 @@ create_sip_endpoint(Endpoint, Properties, Call) ->
{AltCIDNum, AltCIDName} -> {AltCIDNum, AltCIDName}
end,
+ ForceFax = case wh_json:is_true([<<"media">>, <<"fax_option">>],Endpoint) of
+ false -> undefined;
+ true -> <<"peer">>
+ end,
+
Prop = [{<<"Invite-Format">>, wh_json:get_value([<<"sip">>, <<"invite_format">>], Endpoint, <<"username">>)}
,{<<"To-User">>, wh_json:get_value([<<"sip">>, <<"username">>], Endpoint)}
,{<<"To-Realm">>, cf_util:get_sip_realm(Endpoint, whapps_call:account_id(Call))}
@@ -196,6 +208,7 @@ create_sip_endpoint(Endpoint, Properties, Call) ->
,{<<"SIP-Headers">>, generate_sip_headers(Endpoint, Call)}
,{<<"Custom-Channel-Vars">>, generate_ccvs(Endpoint, Call)}
,{<<"Flags">>, wh_json:get_value(<<"outbound_flags">>, Endpoint)}
+ ,{<<"Force-Fax">>, ForceFax}
],
wh_json:from_list(props:filter_undefined(Prop)).
@@ -281,7 +294,7 @@ generate_ccvs(Endpoint, Call, CallFwd) ->
case wh_json:is_true(<<"keep_caller_id">>, CallFwd) of
false -> J;
true ->
- lager:debug("call forwarding configured to keep the caller id"),
+ lager:debug("call forwarding configured to keep the caller id"),
wh_json:set_value(<<"Retain-CID">>, <<"true">>, J)
end
end
@@ -328,11 +341,11 @@ generate_ccvs(Endpoint, Call, CallFwd) ->
end
end
,fun(J) ->
- case wh_json:is_false([<<"media">>, <<"fax">>, <<"option">>], Endpoint) of
- true -> J;
- false -> wh_json:set_value(<<"Fax-Enabled">>, <<"true">>, J)
- end
- end
+ case wh_json:is_false([<<"media">>, <<"fax">>, <<"option">>], Endpoint) of
+ true -> J;
+ false -> wh_json:set_value(<<"Fax-Enabled">>, <<"true">>, J)
+ end
+ end
,fun(J) ->
case wh_json:get_value(<<"pvt_type">>, Endpoint) of
<<"device">> ->
View
27 whistle_apps/apps/callflow/src/module/cf_offnet.erl
@@ -48,10 +48,10 @@ offnet_req(Data, Call) ->
DynamicCID -> DynamicCID
end,
- Flags = find_flags(whapps_call:account_db(Call)
- ,whapps_call:from_user(Call)
- ,wh_json:get_value(<<"flags">>, Data)
- ),
+ Endpoint = case cf_endpoint:get(Call) of
+ {ok, JObj} -> JObj;
+ {error, _} -> wh_json:new()
+ end,
Req = [{<<"Call-ID">>, cf_exe:callid(Call)}
,{<<"Msg-ID">>, wh_util:rand_hex_binary(6)}
@@ -61,7 +61,8 @@ offnet_req(Data, Call) ->
,{<<"Account-Realm">>, whapps_call:from_realm(Call)}
,{<<"Control-Queue">>, cf_exe:control_queue(Call)}
,{<<"Application-Name">>, <<"bridge">>}
- ,{<<"Flags">>, Flags}
+ ,{<<"Flags">>, wh_json:get_value(<<"outbound_flags">>, Endpoint
+ ,wh_json:get_value(<<"outbound_flags">>, Data))}
,{<<"Timeout">>, wh_json:get_value(<<"timeout">>, Data)}
,{<<"Ignore-Early-Media">>, wh_json:get_value(<<"ignore_early_media">>, Data)}
,{<<"Emergency-Caller-ID-Name">>, ECIDName}
@@ -72,6 +73,7 @@ offnet_req(Data, Call) ->
,{<<"Ringback">>, wh_json:get_value(<<"ringback">>, Data)}
,{<<"SIP-Headers">>, build_sip_headers(Data, Call)}
,{<<"Media">>, wh_json:get_value(<<"Media">>, Data)}
+ ,{<<"Force-Fax">>, wh_json:is_true([<<"media">>, <<"fax_option">>], Endpoint)}
| wh_api:default_headers(cf_exe:queue_name(Call), ?APP_NAME, ?APP_VERSION)
],
wapi_offnet_resource:publish_req(props:filter_undefined(Req)).
@@ -141,18 +143,3 @@ build_sip_headers(Data, Call) ->
true -> undefined;
false -> JObj
end.
-
--spec find_flags/3 :: (ne_binary(), ne_binary(), Default) -> Default | [ne_binary(),...] | [].
-find_flags(Db, FromUser, Default) ->
- case couch_mgr:get_results(Db, <<"devices/sip_credentials">>, [{key, FromUser}]) of
- {ok, []} -> Default;
- {ok, [U]} ->
- case cf_endpoint:get(wh_json:get_value(<<"id">>, U), Db) of
- {ok, EP} ->
- lager:debug("call from device '~s', checking flags", [wh_json:get_value(<<"id">>, U)]),
- wh_json:get_value(<<"outbound_flags">>, EP, Default);
- _ -> Default
- end;
- _ -> Default
- end.
-
View
9 whistle_apps/apps/callflow/src/module/cf_resources.erl
@@ -96,6 +96,14 @@ create_endpoint(DestNum, JObj, Call) ->
,(wh_json:get_value(<<"suffix">>, JObj, <<>>))/binary
,$@ ,(wh_json:get_value(<<"server">>, JObj))/binary>>,
lager:debug("attempting resource ~s", [Rule]),
+ Endpoint = case cf_endpoint:get(Call) of
+ {ok, JObj} -> JObj;
+ {error, _} -> wh_json:new()
+ end,
+ ForceFax = case wh_json:is_true([<<"media">>, <<"fax_option">>], Endpoint) of
+ false -> undefined;
+ true -> <<"self">>
+ end,
AccountId = whapps_call:account_id(Call),
CCVs = [{<<"Account-ID">>, AccountId}
,{<<"Reseller-ID">>, wh_services:find_reseller_id(AccountId)}
@@ -111,6 +119,7 @@ create_endpoint(DestNum, JObj, Call) ->
,{<<"Endpoint-Progress-Timeout">>, wh_json:get_value(<<"progress_timeout">>, JObj, <<"6">>)}
,{<<"Codecs">>, wh_json:get_value(<<"codecs">>, JObj)}
,{<<"Custom-Channel-Vars">>, wh_json:from_list(props:filter_undefined(CCVs))}
+ ,{<<"Force-Fax">>, ForceFax}
],
wh_json:from_list(props:filter_undefined(Endpoint)).
View
12 whistle_apps/apps/stepswitch/src/stepswitch_outbound.erl
@@ -120,9 +120,7 @@ bridge_to_endpoints(Endpoints, IsEmergency, CtrlQ, JObj) ->
{CIDNum, CIDName} = case IsEmergency of
'true' ->
lager:debug("outbound call is using an emergency route, attempting to set CID accordingly"),
- get_emergency_cid_number(JObj),
- {wh_json:get_ne_value(<<"Emergency-Caller-ID-Number">>, JObj,
- wh_json:get_ne_value(<<"Outgoing-Caller-ID-Number">>, JObj))
+ {get_emergency_cid_number(JObj)
,wh_json:get_ne_value(<<"Emergency-Caller-ID-Name">>, JObj,
wh_json:get_ne_value(<<"Outgoing-Caller-ID-Name">>, JObj))};
'false' ->
@@ -154,6 +152,11 @@ bridge_to_endpoints(Endpoints, IsEmergency, CtrlQ, JObj) ->
CCVs = wh_json:set_values(props:filter_undefined(Updates)
,wh_json:get_value(<<"Custom-Channel-Vars">>, JObj, wh_json:new())),
+ ForceFax = case wh_json:is_true(<<"Force-Fax">>, JObj) of
+ false -> undefined;
+ true -> <<"self">>
+ end,
+
Command = [{<<"Application-Name">>, <<"bridge">>}
,{<<"Endpoints">>, Endpoints}
,{<<"Timeout">>, wh_json:get_value(<<"Timeout">>, JObj)}
@@ -168,10 +171,11 @@ bridge_to_endpoints(Endpoints, IsEmergency, CtrlQ, JObj) ->
,{<<"Continue-On-Fail">>, <<"true">>}
,{<<"SIP-Headers">>, wh_json:get_value(<<"SIP-Headers">>, JObj)}
,{<<"Custom-Channel-Vars">>, CCVs}
+ ,{<<"Force-Fax">>, ForceFax}
,{<<"Call-ID">>, wh_json:get_value(<<"Call-ID">>, JObj)}
| wh_api:default_headers(Q, <<"call">>, <<"command">>, ?APP_NAME, ?APP_VERSION)
],
- wapi_dialplan:publish_command(CtrlQ, Command),
+ wapi_dialplan:publish_command(CtrlQ, props:filter_undefined(Command)),
wait_for_bridge(whapps_config:get_integer(<<"stepswitch">>, <<"bridge_timeout">>, 30000)).
%%--------------------------------------------------------------------

0 comments on commit 0ec723a

Please sign in to comment.