Skip to content

Commit

Permalink
Merge pull request 2600hz#16 from 2600hz/KAZOO-240
Browse files Browse the repository at this point in the history
Kazoo 240
  • Loading branch information
k-anderson committed Apr 6, 2013
2 parents 000f665 + 482936b commit 1911d98
Show file tree
Hide file tree
Showing 290 changed files with 13,171 additions and 7,669 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/ebin/*.app
ecallmgr/test
whistle_apps/apps/*/test
lib/*/test
lib/*/test/*.beam
lib/*/test/*.app
lib/*/ebin/*.beam
lib/*/ebin/*.app
lib/*/priv/*.so
Expand All @@ -22,6 +23,7 @@ whistle_apps/lib/*/c_src/*.o
whistle_apps/lib/*/c_src/*/*.o
whistle_apps/lib/*/deps/*/ebin/*.beam
whistle_apps/lib/*/deps/*/ebin/*.app
whistle_apps/lib/*/test/*
whistle_apps/lib/*/dist/*
whistle_apps/lib/erlydtl-0.7.0/src/erlydtl_parser.erl
*/deps/*/ebin/*.beam
Expand All @@ -31,9 +33,6 @@ whistle_apps/lib/erlydtl-0.7.0/src/erlydtl_parser.erl
ecallmgr/priv/startup.config
ecallmgr/deps/lager-1.0.0/ebin/*
ecallmgr/*crash.dump
ecallmgr/test
whistle_apps/test
lib/*/test
whistle_apps/priv/startup.config
whistle_apps/apps/*/ebin/*.beam
whistle_apps/apps/*/ebin/*.app
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ eunit :

build-plt :
@$(DIALYZER) --build_plt --output_plt $(ROOT)/.platform_dialyzer.plt \
--apps erts kernel stdlib sasl inets crypto public_key ssl
--apps erts kernel stdlib crypto public_key ssl

dialyze :
@$(DIALYZER) $(foreach DIR,$(DIRS),$(DIR)/ebin) \
Expand Down
15 changes: 6 additions & 9 deletions ecallmgr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PROJECT = ecallmgr
ROOT = ..
DIALYZER = dialyzer

MODULES = $(shell ls src/*.erl | sed 's/src\///;s/\.erl/,/' | sed '$$s/.$$//')

LIB_EBINS = $(shell find $(ROOT)/lib -maxdepth 2 -name ebin -print)
PA = $(foreach LIB_EBIN,$(LIB_EBINS),-pa $(LIB_EBIN))

Expand All @@ -16,8 +18,6 @@ DIRS = . \

all: compile

MODULES = $(shell ls src/*.erl | sed 's/src\///;s/\.erl/,/' | sed '$$s/.$$//')

compile: ebin/$(PROJECT).app
@cat src/$(PROJECT).app.src \
| sed 's/{modules, \[\]}/{modules, \[$(MODULES)\]}/' \
Expand All @@ -36,22 +36,19 @@ compile-test: test/$(PROJECT).app

test/$(PROJECT).app: src/*.erl
@mkdir -p test/
erlc -v $(ERLC_OPTS) -o test/ -pa test/ $?
erlc -v $(ERLC_OPTS) -DTEST -o test/ -pa test/ -pa $(ROOT)/lib $?

clean:
rm -f ebin/*
rm -f test/*.beam
rm -f test/*.*
rm -f erl_crash.dump


test: clean compile-test eunit

eunit: compile-test
erl -noshell -pa test $(PA) -eval "eunit:test([$(MODULES)], [verbose])" -s init stop

build-plt:
@$(DIALYZER) --build_plt --output_plt $(ROOT)/.platform_dialyzer.plt \
--apps kernel stdlib sasl inets crypto public_key ssl
erl -noshell $(PA) \
-pa test -eval "eunit:test([$(MODULES)], [verbose])" -s init stop

dialyze:
@$(DIALYZER) $(foreach DIR,$(DIRS),$(DIR)/ebin) $(PA) \
Expand Down
92 changes: 63 additions & 29 deletions ecallmgr/src/ecallmgr_call_command.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ exec_cmd(Node, UUID, JObj, ControlPID) ->
case DestID =:= UUID of
'true' ->
case get_fs_app(Node, UUID, JObj, App) of
{'error', Msg} ->
throw({'msg', Msg});
{'return', Result} ->
Result;
{'error', Msg} -> throw({'msg', Msg});
{'return', Result} -> Result;
{AppName, 'noop'} ->
ecallmgr_call_control:event_execute_complete(ControlPID, UUID, AppName);
{AppName, AppData} ->
Expand Down Expand Up @@ -79,6 +77,8 @@ get_fs_app(Node, UUID, JObj, <<"tts">>) ->
case wapi_dialplan:tts_v(JObj) of
'false' -> {'error', <<"tts failed to execute as JObj didn't validate">>};
'true' ->
'ok' = set_terminators(Node, UUID, wh_json:get_value(<<"Terminators">>, JObj)),

case wh_json:get_value(<<"Engine">>, JObj, <<"flite">>) of
<<"flite">> -> tts_flite(Node, UUID, JObj);
_E ->
Expand Down Expand Up @@ -145,8 +145,7 @@ get_fs_app(Node, UUID, JObj, <<"record">>) ->
,fun(V) ->
case get_terminators(JObj) of
'undefined' -> V;
Terminators ->
[Terminators|V]
Terminators -> [Terminators|V]
end
end
],
Expand Down Expand Up @@ -176,13 +175,12 @@ get_fs_app(Node, UUID, JObj, <<"record_call">>) ->
,fun(V) ->
case get_terminators(JObj) of
'undefined' -> V;
Terminators ->
[Terminators|V]
Terminators -> [Terminators|V]
end
end
,fun(V) -> [{<<"RECORD_APPEND">>, <<"true">>}
,{<<"enable_file_write_buffering">>, <<"false">>}
|V
| V
]
end
],
Expand Down Expand Up @@ -218,16 +216,16 @@ get_fs_app(Node, UUID, JObj, <<"store">>) ->
%% stream file over HTTP PUT
lager:debug("stream ~s via HTTP PUT", [RecordingName]),
stream_over_http(Node, UUID, RecordingName, put, store, JObj),
{<<"store">>, noop};
{<<"store">>, 'noop'};
<<"post">> ->
%% stream file over HTTP POST
lager:debug("stream ~s via HTTP POST", [RecordingName]),
stream_over_http(Node, UUID, RecordingName, post, store, JObj),
{<<"store">>, noop};
{<<"store">>, 'noop'};
_Method ->
%% unhandled method
lager:debug("unhandled stream method ~s", [_Method]),
{return, error}
{'return', 'error'}
end
end;

Expand All @@ -240,7 +238,7 @@ get_fs_app(Node, UUID, JObj, <<"store_fax">> = App) ->
case wh_json:get_value(<<"Media-Transfer-Method">>, JObj) of
<<"put">> ->
stream_over_http(Node, UUID, File, put, fax, JObj),
{App, noop};
{App, 'noop'};
_Method ->
lager:debug("invalid media transfer method for storing fax: ~s", [_Method]),
{'error', <<"invalid media transfer method">>}
Expand Down Expand Up @@ -446,7 +444,7 @@ get_fs_app(Node, UUID, JObj, <<"call_pickup">>) ->
'true' = ecallmgr_fs_channel:move(Target, OtherNode, Node),
get_call_pickup_app(Node, UUID, JObj, Target)
end;
{'error', not_found} ->
{'error', 'not_found'} ->
lager:debug("failed to find target callid ~s", [Target]),
{'error', <<"failed to find target callid ", Target/binary>>}
end
Expand Down Expand Up @@ -511,7 +509,7 @@ get_fs_app(Node, UUID, JObj, <<"set_terminators">>) ->
'false' -> {'error', <<"set_terminators failed to execute as JObj did not validate">>};
'true' ->
'ok' = set_terminators(Node, UUID, wh_json:get_value(<<"Terminators">>, JObj)),
{<<"set">>, noop}
{<<"set">>, 'noop'}
end;

get_fs_app(Node, UUID, JObj, <<"set">>) ->
Expand All @@ -524,7 +522,7 @@ get_fs_app(Node, UUID, JObj, <<"set">>) ->
CallVars = wh_json:to_proplist(wh_json:get_value(<<"Custom-Call-Vars">>, JObj, wh_json:new())),
_ = ecallmgr_util:export(Node, UUID, CallVars),

{<<"set">>, noop}
{<<"set">>, 'noop'}
end;

get_fs_app(_Node, _UUID, JObj, <<"respond">>) ->
Expand Down Expand Up @@ -553,7 +551,7 @@ get_fs_app(Node, UUID, JObj, <<"fetch">>) ->
spawn(fun() ->
send_fetch_call_event(Node, UUID, JObj)
end),
{<<"fetch">>, noop};
{<<"fetch">>, 'noop'};

get_fs_app(Node, UUID, JObj, <<"conference">>) ->
case wapi_dialplan:conference_v(JObj) of
Expand Down Expand Up @@ -603,7 +601,7 @@ get_call_pickup_app(Node, UUID, JObj, Target) ->
%%--------------------------------------------------------------------
get_conference_app(ChanNode, UUID, JObj, 'true') ->
ConfName = wh_json:get_value(<<"Conference-ID">>, JObj),
ConferenceConfig = wh_json:get_value(<<"Conference-Config">>, JObj, <<"default">>),
ConferenceConfig = wh_json:get_value(<<"Profile">>, JObj, <<"default">>),
Cmd = list_to_binary([ConfName, "@", ConferenceConfig, get_conference_flags(JObj)]),

case ecallmgr_fs_conferences:node(ConfName) of
Expand Down Expand Up @@ -633,7 +631,8 @@ get_conference_app(ChanNode, UUID, JObj, 'true') ->
end;
get_conference_app(_ChanNode, _UUID, JObj, 'false') ->
ConfName = wh_json:get_value(<<"Conference-ID">>, JObj),
{<<"conference">>, list_to_binary([ConfName, "@default", get_conference_flags(JObj)])}.
ConferenceConfig = wh_json:get_value(<<"Profile">>, JObj, <<"default">>),
{<<"conference">>, list_to_binary([ConfName, "@", ConferenceConfig, get_conference_flags(JObj)])}.

%% [{FreeSWITCH-Flag-Name, Kazoo-Flag-Name}]
%% Conference-related entry flags
Expand All @@ -645,14 +644,24 @@ get_conference_app(_ChanNode, _UUID, JObj, 'false') ->

-spec get_conference_flags(wh_json:object()) -> binary().
get_conference_flags(JObj) ->
Flags = wh_json:foldl(fun(K, V, Acc) ->
case lists:keyfind(K, 2, ?CONFERENCE_FLAGS) of
'false' -> Acc;
{FSFlag, _} when V =:= 'true' -> [<<",">>, FSFlag | Acc];
_ -> Acc
end
end, [], JObj),
<<"+flags{", (iolist_to_binary(lists:reverse(Flags)))/binary, "}">>.
case wh_json:to_proplist(JObj) of
[] -> <<>>;
[{_Key,_Val}=KV|L] ->
Flags = lists:foldl(fun maybe_add_conference_flag/2, [<<>>], L),
All = case maybe_add_conference_flag(KV, []) of
[] -> tl(Flags);
[<<",">> | T] -> T ++ Flags;
Fs -> Fs ++ Flags
end,
<<"+flags{", (iolist_to_binary(All))/binary, "}">>
end.

maybe_add_conference_flag({K, V}, Acc) ->
case lists:keyfind(K, 2, ?CONFERENCE_FLAGS) of
'false' -> Acc;
{FSFlag, _} when V =:= 'true' -> [<<",">>, FSFlag | Acc];
_ -> Acc
end.

wait_for_conference(ConfName) ->
case ecallmgr_fs_conferences:node(ConfName) of
Expand Down Expand Up @@ -1097,8 +1106,7 @@ tts_flite_voice(JObj) ->
-spec get_terminators(api_binary() | ne_binaries() | wh_json:object()) ->
{ne_binary(), ne_binary()}.
get_terminators('undefined') -> 'undefined';
get_terminators(Ts) when is_binary(Ts) ->
get_terminators([Ts]);
get_terminators(Ts) when is_binary(Ts) -> get_terminators([Ts]);
get_terminators([_|_]=Ts) ->
case Ts =:= get('$prior_terminators') of
'true' -> 'undefined';
Expand All @@ -1118,3 +1126,29 @@ set_terminators(Node, UUID, Ts) ->
'undefined' -> 'ok';
{K, V} -> ecallmgr_util:set(Node, UUID, <<K/binary, "=", V/binary>>)
end.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

all_conference_flags_test() ->
JObj = wh_json:from_list([{<<"Mute">>, 'true'}
,{<<"Deaf">>, 'true'}
,{<<"Moderator">>, 'true'}
]),
?assertEqual(<<"+flags{mute,moderator,deaf}">>, get_conference_flags(JObj)).

two_conference_flags_test() ->
JObj = wh_json:from_list([{<<"Mute">>, 'true'}
,{<<"Moderator">>, 'true'}
]),
?assertEqual(<<"+flags{mute,moderator}">>, get_conference_flags(JObj)).

one_conference_flag_test() ->
JObj = wh_json:from_list([{<<"Mute">>, 'true'}]),
?assertEqual(<<"+flags{mute}">>, get_conference_flags(JObj)).

no_conference_flags_test() ->
JObj = wh_json:new(),
?assertEqual(<<>>, get_conference_flags(JObj)).

-endif.
12 changes: 9 additions & 3 deletions ecallmgr/src/ecallmgr_call_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ event_specific(<<"RECORD_STOP">>, _, Prop) ->
,{<<"Application-Response">>, props:get_value(<<"Record-File-Path">>, Prop, props:get_value(<<"whistle_application_response">>, Prop))}
,{<<"Terminator">>, props:get_value(<<"variable_playback_terminator_used">>, Prop)}
,{<<"Length">>, props:get_value(<<"variable_record_ms">>, Prop)}
,{<<"Silence-Terminated">>, silence_terminated(props:get_integer_value(<<"variable_silence_hits_left">>, Prop))}
,{<<"Silence-Terminated">>, silence_terminated(Prop)}
];
event_specific(<<"DETECTED_TONE">>, _, Prop) ->
[{<<"Detected-Tone">>, props:get_value(<<"Detected-Tone">>, Prop)}];
Expand Down Expand Up @@ -638,9 +638,15 @@ conference_specific(Prop) ->
end
end.

-spec silence_terminated('undefined' | integer()) -> 'undefined' | boolean().
-spec silence_terminated('undefined' | integer() | wh_proplist() | boolean()) -> 'undefined' | boolean().
silence_terminated('undefined') -> 'undefined';
silence_terminated(Hits) when is_integer(Hits) -> Hits =:= 0.
silence_terminated(B) when is_boolean(B) -> B;
silence_terminated(Hits) when is_integer(Hits) -> Hits =:= 0;
silence_terminated(Prop) when is_list(Prop) ->
case props:get_value(<<"variable_silence_hits_exhausted">>, Prop) of
'undefined' -> silence_terminated(props:get_integer_value(<<"variable_record_silence_hits">>, Prop));
Ex -> wh_util:is_true(Ex)
end.

-spec get_fs_var(atom(), ne_binary(), ne_binary(), binary()) -> binary().
get_fs_var(Node, CallId, Var, Default) ->
Expand Down
3 changes: 2 additions & 1 deletion ecallmgr/src/ecallmgr_fs_authn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ publish_register_event(Props, Node) ->
,[{<<"Event-Timestamp">>, round(wh_util:current_tstamp())}
,{<<"Call-ID">>, get('callid')}
,{<<"FreeSWITCH-Nodename">>, wh_util:to_binary(Node)}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)]
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
]
,wapi_registration:success_keys()),
lager:debug("sending successful registration"),
wh_amqp_worker:cast(?ECALLMGR_AMQP_POOL
Expand Down
2 changes: 2 additions & 0 deletions ecallmgr/src/ecallmgr_fs_conferences.erl
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,14 @@ handle_search_req(JObj, _Props) ->
Error = [{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj, <<>>)}
,{<<"Error-Message">>, <<"Conference ", ConferenceId/binary, " not found">>}
,{<<"Request">>, JObj}
,{<<"Conference-ID">>, ConferenceId}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
wapi_conference:publish_error(wh_json:get_value(<<"Server-ID">>, JObj), Error);
{'ok', Conference} ->
lager:debug("sending affirmative search response for conference ~s", [ConferenceId]),
Resp = wh_json:set_values([{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj, <<>>)}
,{<<"Conference-ID">>, ConferenceId}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
], Conference),
wapi_conference:publish_search_resp(wh_json:get_value(<<"Server-ID">>, JObj), Resp)
Expand Down
Loading

0 comments on commit 1911d98

Please sign in to comment.