Skip to content

Commit

Permalink
updated for outbound and flags
Browse files Browse the repository at this point in the history
  • Loading branch information
James Aimonetti committed Oct 29, 2010
1 parent fa2dfd8 commit 7d8ce61
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 71 deletions.
Binary file modified applications/trunkstore/ebin/ts_auth.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_carrier.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_couch.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_credit.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_e911.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_route.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_t38.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/ts_util.beam
Binary file not shown.
Binary file modified applications/trunkstore/ebin/whistle_api.beam
Binary file not shown.
15 changes: 7 additions & 8 deletions applications/trunkstore/src/ts.hrl
Expand Up @@ -22,17 +22,16 @@
,to_domain = <<>> :: binary()
,from_user = <<>> :: binary()
,from_domain = <<>> :: binary()
,auth_user = <<>> :: binary() % what username did we authenticate with
,direction = <<>> :: binary() % what direction is the call (relative to client)
,server_id = <<>> :: binary() % Server of the DID
,credit_available = 0.0 :: float() % How much credit is left on the account/server/DID
,failover = [] :: proplist() % Failover information
,payphone = false :: boolean()
,callerid = {} :: tuple() % Name and Number for Caller ID
,callerid_e911 = {} :: tuple() % CallerID for E911 calls
,callerid_default = {} :: tuple() % Override Name and Number for Caller ID
,fax = [] :: proplist() % Fax properties
,flat_rate_enabled = false :: boolean() % is this a flat-rate eligible call
,auth_options = [] :: proplist() % server auth creds
,failover = {} :: tuple() % Failover information {type, uri}
,allow_payphone = false :: boolean()
,caller_id = {} :: tuple() % Name and Number for Caller ID - check DID, then server, then account, then what we got from ecallmgr
,caller_id_e911 = {} :: tuple() % CallerID for E911 calls - Check DID, then server, then account
,trunks = 0 :: integer() % Trunks available
,flat_rate_enabled = false :: boolean() % is this a flat-rate eligible call - only if trunks are available
,inbound_format = <<>> :: binary() % how does the server want the number? "E.164" | "NPANXXXXXX" | "1NPANXXXXXX"
,codecs = [] :: list() % what codecs to use (t38, g729, g711, etc...)
,inbound_rate = 0.0 :: float() % rate for the inbound leg
Expand Down
6 changes: 5 additions & 1 deletion applications/trunkstore/src/ts_auth.erl
Expand Up @@ -46,7 +46,11 @@ handle_req(Prop) ->
end,

Defaults = [{<<"Msg-ID">>, get_value(<<"Msg-ID">>, Prop)}
,{<<"Custom-Channel-Vars">>, {struct, [{<<"Direction">>, Direction}]}}
,{<<"Custom-Channel-Vars">>, {struct, [
{<<"Direction">>, Direction}
,{<<"Auth-User">>, AuthU}
]
}}
| whistle_api:default_headers(<<>> % serverID is not important, though we may want to define it eventually
,get_value(<<"Event-Category">>, Prop)
,<<"auth_resp">>
Expand Down
19 changes: 12 additions & 7 deletions applications/trunkstore/src/ts_carrier.erl
Expand Up @@ -21,6 +21,7 @@

-define(SERVER, ?MODULE).
-define(REFRESH_RATE, 43200000). % 1000ms * 60s * 60m * 12h = Every twelve hours
-define(DEFAULT_PROGRESS_TIMEOUT, 6). % seconds to timeout if no progress

-import(logger, [format_log/3]).
-import(props, [get_value/2, get_value/3]).
Expand Down Expand Up @@ -160,16 +161,19 @@ get_current_carriers() ->
{error, "No matching carriers"};
Carriers when is_list(Carriers) ->
format_log(info, "TS_CARRIER(~p): Carriers pulled. Rev: ~p~n", [self(), get_value(<<"_rev">>, Carriers)]),
{ok, lists:map(fun process_carriers/1, Carriers)};
{ok, lists:map(fun process_carriers/1, lists:filter(fun active_carriers/1, Carriers))};
Other ->
format_log(error, "TS_CARRIER(~p): Unexpected error ~p~n", [self(), Other]),
{error, "Unexpected error"}
end.

process_carriers({<<"_id">>, _}=ID) ->
ID;
process_carriers({<<"_rev">>, _}=Rev) ->
Rev;
active_carriers({<<"_id">>, _}) ->
false;
active_carriers({<<"_rev">>, _}) ->
false;
active_carriers({_CarrierName, {CarrierOptions}}) ->
get_value(<<"enabled">>, CarrierOptions) =:= <<"1">>.

process_carriers({CarrierName, {CarrierOptions}}) ->
RoutesRegexStrs = get_value(<<"routes">>, CarrierOptions, []),
RouteRegexs = lists:map(fun(Str) -> {ok, R} = re:compile(Str), R end, RoutesRegexStrs),
Expand Down Expand Up @@ -208,7 +212,7 @@ sort_carriers({_CarrierAName, CarrierAData}, {_CarrierBName, CarrierBData}) ->
%% transform Carriers proplist() into a list of Routes for the API
-spec(create_routes/2 :: (Flags :: tuple(), Carriers :: proplist()) -> {ok, proplist()} | {error, string()}).
create_routes(Flags, Carriers) ->
CallerID = case Flags#route_flags.callerid of
CallerID = case Flags#route_flags.caller_id of
{} -> [];
{Name, Number} -> [{<<"Caller-ID-Name">>, Name} ,{<<"Caller-ID-Number">>, Number}]
end,
Expand Down Expand Up @@ -240,7 +244,7 @@ carrier_to_routes({_CarrierName, CarrierData}, {Routes, User, CallerID}) ->
{GatewayRoutes, User, CallerID}.

gateway_to_route(Gateway, {CRs, Regexed, BaseRouteData}=Acc) ->
case get_value(<<"enabled">>, Gateway, <<"1">>) of
case get_value(<<"enabled">>, Gateway, <<"0">>) of
<<"1">> ->
Dialstring = list_to_binary([<<"sip:">>
,get_value(<<"prefix">>, Gateway)
Expand All @@ -254,6 +258,7 @@ gateway_to_route(Gateway, {CRs, Regexed, BaseRouteData}=Acc) ->
,{<<"Auth-User">>, get_value(<<"username">>, Gateway)}
,{<<"Auth-Password">>, get_value(<<"password">>, Gateway)}
,{<<"Codecs">>, get_value(<<"codecs">>, Gateway, [])}
,{<<"Progress-Timeout">>, get_value(<<"progress_timer">>, Gateway, ?DEFAULT_PROGRESS_TIMEOUT)}
| BaseRouteData ],
case whistle_api:route_resp_route_v(R) of
true -> {[{struct, R} | CRs], Regexed, BaseRouteData};
Expand Down
9 changes: 7 additions & 2 deletions applications/trunkstore/src/ts_couch.erl
Expand Up @@ -147,8 +147,13 @@ handle_call({open_doc, DbName, DocId, Options}, _From, #state{connection={_Host,
{{error, _Err}=E, _DBs} ->
{reply, E, State};
{Db, DBs1} ->
{ok, {Doc}} = couchbeam:open_doc(Db, DocId, Options),
{reply, Doc, State#state{dbs=DBs1}}
case couchbeam:open_doc(Db, DocId, Options) of
{ok, {Doc}} ->
{reply, Doc, State#state{dbs=DBs1}};
Other ->
format_log(error, "TS_COUCH(~p): Failed to find ~p: ~p~n", [self(), DocId, Other]),
{reply, {error, not_found}, State}
end
end;
handle_call({save_doc, DbName, Doc}, _From, #state{connection={_Host, Conn}, dbs=DBs}=State) ->
case get_db(DbName, Conn, DBs) of
Expand Down
4 changes: 3 additions & 1 deletion applications/trunkstore/src/ts_credit.erl
Expand Up @@ -205,12 +205,14 @@ set_rate_flags(Flags, Rates) ->
format_log(info, "TS_CREDIT(~p): Rate to use ~p~n", [self(), RateName]),

%% trunks available in flags (flat_rate_enabled) and the carrier has flatrate available as well
UseFlatRate = Flags#route_flags.flat_rate_enabled andalso get_value(<<"flatrate">>, RateData, false),
UseFlatRate = Flags#route_flags.trunks > 0 andalso get_value(<<"flatrate">>, RateData, false),

case UseFlatRate of
true ->
format_log(info, "TS_CREDIT(~p): Use flat rate for ~p~n", [self(), Dir]),
{ok, set_flat_flags(Flags, Dir)};
false ->
format_log(info, "TS_CREDIT(~p): Use rate data for ~p: ~p~n", [self(), Dir, RateData]),
Flags0 = set_rate_flags(Flags, Dir, RateData),
case has_credit(Flags0, Dir) of
true ->
Expand Down
6 changes: 3 additions & 3 deletions applications/trunkstore/src/ts_e911.erl
Expand Up @@ -19,10 +19,10 @@
%% - Resort to Server-wide E911
%% - Resort to DID CallerID
%% - Resort to Server CallerID
process_flags(#route_flags{to_user = <<"911">>, callerid_e911={}}=Flags) ->
process_flags(#route_flags{to_user = <<"911">>, caller_id_e911={}}=Flags) ->
Flags;
process_flags(#route_flags{to_user = <<"911">>, callerid_e911=E911}=Flags) ->
Flags#route_flags{callerid=E911};
process_flags(#route_flags{to_user = <<"911">>, caller_id_e911=E911}=Flags) ->
Flags#route_flags{caller_id=E911};
%% Not a 911 Call
process_flags(Flags) ->
Flags.

0 comments on commit 7d8ce61

Please sign in to comment.