Skip to content

Commit

Permalink
KAZOO-5197 handle mod_kazoo event-filter requests (2600hz#2827)
Browse files Browse the repository at this point in the history
* KAZOO-5197 handle mod_kazoo event-filter requests

* KAZOO-5197 PR comments

* KAZOO-5197 use ne_binary instead

* KAZOO-5197 make fs-headers

* KAZOO-5197 handle ne_binary_value in fs_prop_usage
  • Loading branch information
lazedo authored and fenollp committed Nov 26, 2016
1 parent 17d2e8b commit 2ec3254
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FMT = $(ROOT)/make/erlang-formatter-master/fmt.sh

KAZOODIRS = core/Makefile applications/Makefile

.PHONY: $(KAZOODIRS) deps core apps xref xref_release dialyze dialyze-it dialyze-apps dialyze-core dialyze-kazoo clean clean-test clean-release build-release build-ci-release tar-release release read-release-cookie elvis install ci diff fmt bump-copyright apis validate-swagger coverage-report
.PHONY: $(KAZOODIRS) deps core apps xref xref_release dialyze dialyze-it dialyze-apps dialyze-core dialyze-kazoo clean clean-test clean-release build-release build-ci-release tar-release release read-release-cookie elvis install ci diff fmt bump-copyright apis validate-swagger coverage-report fs-headers

all: compile rel/dev-vm.args

Expand Down Expand Up @@ -193,5 +193,8 @@ apis:
@$(ROOT)/scripts/format-json.sh applications/crossbar/priv/api/*.json
@ERL_LIBS=deps/:core/:applications/ $(ROOT)/scripts/generate-fs-headers-hrl.escript

fs-headers:
@ERL_LIBS=deps/:core/:applications/ $(ROOT)/scripts/generate-fs-headers-hrl.escript

validate-swagger:
$(ROOT)/scripts/validate-swagger.sh
7 changes: 7 additions & 0 deletions applications/ecallmgr/src/ecallmgr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
-include_lib("kazoo/include/kz_log.hrl").
-include_lib("kazoo_documents/include/kazoo_documents.hrl").

-include("fs_event_filters.hrl").

-define(ECALLMGR_UTIL_CACHE, 'ecallmgr_util_cache').
-define(ECALLMGR_AUTH_CACHE, 'ecallmgr_auth_cache').
-define(ECALLMGR_CALL_CACHE, 'ecallmgr_call_cache').
Expand Down Expand Up @@ -505,5 +507,10 @@
,{<<"Member-Ghost">>, fun kz_util:to_boolean/1}
]).

-define(FS_EVENT_FILTERS,
?FS_GENERATED_EVENT_FILTERS
++ ?CONFERENCE_VARS
).

-define(ECALLMGR_HRL, 'true').
-endif.
26 changes: 24 additions & 2 deletions applications/ecallmgr/src/ecallmgr_fs_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ handle_config_req(Node, Id, <<"sofia.conf">>, _Props) ->
handle_config_req(Node, Id, <<"conference.conf">>, Data) ->
kz_util:put_callid(Id),
fetch_conference_config(Node, Id, kzd_freeswitch:event_name(Data), Data);
handle_config_req(Node, Id, <<"kazoo.conf">> = Conf, _Data) ->
handle_config_req(Node, Id, <<"kazoo.conf">>, Data) ->
kz_util:put_callid(Id),
lager:debug("received configuration request for kazoo configuration ~p , ~p", [Node, Id]),
config_req_not_handled(Node, Id, Conf);
fetch_mod_kazoo_config(Node, Id, kzd_freeswitch:event_name(Data), Data);
handle_config_req(Node, Id, Conf, Data) ->
kz_util:put_callid(Id),
handle_config_req(Node, Id, Conf, Data, ecallmgr_config:get(<<"configuration_handlers">>)).
Expand Down Expand Up @@ -511,3 +511,25 @@ maybe_fetch_conference_profile(Node, Id, Profile) ->
send_conference_profile_xml(Node, Id, XmlResp) ->
lager:debug("sending conference profile XML to ~s: ~s", [Node, XmlResp]),
freeswitch:fetch_reply(Node, Id, 'configuration', iolist_to_binary(XmlResp)).


-spec fetch_mod_kazoo_config(atom(), ne_binary(), ne_binary(), kz_proplist()) -> fs_sendmsg_ret().
fetch_mod_kazoo_config(Node, Id, <<"COMMAND">>, _Data) ->
config_req_not_handled(Node, Id, <<"kazoo.conf">>);
fetch_mod_kazoo_config(Node, Id, <<"REQUEST_PARAMS">>, Data) ->
Action = props:get_ne_binary_value(<<"Action">>, Data),
fetch_mod_kazoo_config_action(Node, Id, Action, Data);
fetch_mod_kazoo_config(Node, Id, Event, _Data) ->
lager:debug("unhandled mod kazoo config event : ~p : ~p", [Node, Event]),
config_req_not_handled(Node, Id, <<"kazoo.conf">>).

-spec fetch_mod_kazoo_config_action(atom(), ne_binary(), api_ne_binary(), kz_proplist()) -> fs_sendmsg_ret().
fetch_mod_kazoo_config_action(Node, Id, <<"request-filter">>, _Data) ->
{'ok', Xml} = ecallmgr_fs_xml:event_filters_resp_xml(?FS_EVENT_FILTERS),
lager:debug("replying with xml response for request-filter params request"),
freeswitch:fetch_reply(Node, Id, 'configuration', iolist_to_binary(Xml));
fetch_mod_kazoo_config_action(Node, Id, 'undefined', _Data) ->
config_req_not_handled(Node, Id, <<"kazoo.conf">>);
fetch_mod_kazoo_config_action(Node, Id, Action, _Data) ->
lager:debug("unhandled mod kazoo config action : ~p : ~p", [Node, Action]),
config_req_not_handled(Node, Id, <<"kazoo.conf">>).
23 changes: 23 additions & 0 deletions applications/ecallmgr/src/ecallmgr_fs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
,sip_channel_xml/1
,escape/2
,conference_resp_xml/1
,event_filters_resp_xml/1
]).

-export([config_el/2, config_el/3]).
Expand Down Expand Up @@ -1103,3 +1104,25 @@ sofia_gateway_vars_xml_to_json([Var|Vars], JObj) ->
Key = kz_util:get_xml_value("/variable/@name", Var),
Value = kz_util:get_xml_value("/variable/@value", Var),
sofia_gateway_vars_xml_to_json(Vars, kz_json:set_value(Key, Value, JObj)).

-spec event_filters_resp_xml(ne_binaries()) -> {'ok', iolist()}.
event_filters_resp_xml(Headers) ->
EventFiltersEl = event_filters_xml(Headers),
ConfigurationEl = config_el(<<"kazoo.conf">>, <<"Built by Kazoo">>, [EventFiltersEl]),
SectionEl = section_el(<<"configuration">>, ConfigurationEl),
{'ok', xmerl:export([SectionEl], 'fs_xml')}.

event_filters_xml(Headers) ->
EventFiltersEls = [event_filter_el(Header) || Header <- Headers],
event_filters_el(EventFiltersEls).

event_filter_el(Header) ->
#xmlElement{name='header'
,attributes=[xml_attrib('name', Header)]
}.

event_filters_el(Filters) ->
#xmlElement{name='event-filter'
,content=Filters
,attributes=[xml_attrib('type', <<"whitelist">>)]
}.
11 changes: 6 additions & 5 deletions applications/ecallmgr/src/fs_event_filters.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-ifndef(FS_EVENT_FILTERS_HRL).
-include("fs_manual_event_filters.hrl").
-define(FS_EVENT_FITLERS
-ifndef(FS_GENERATED_EVENT_FILTERS_HRL).

-define(FS_GENERATED_EVENT_FILTERS
,[<<"Acquired-UUID">>
,<<"Action">>
,<<"Answer-State">>
Expand Down Expand Up @@ -185,7 +185,8 @@
,<<"variable_transfer_to">>
,<<"variable_user_name">>
,<<"variable_uuid">>
| ?FS_MANUAL_HEADERS
]).
-define(FS_EVENT_FILTERS_HRL, 'true').

-define(FS_GENERATED_EVENT_FILTERS_HRL, 'true').

-endif.
10 changes: 0 additions & 10 deletions applications/ecallmgr/src/fs_manual_event_filters.hrl

This file was deleted.

12 changes: 7 additions & 5 deletions core/kazoo_ast/src/fs_prop_usage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ write_usage_to_header(Usage, IO) ->
EventFilters = lists:foldl(fun write_mod_usage/2, sets:new(), Usage),
[First|Sorted] = lists:usort(lists:filter(fun ignored_headers/1, sets:to_list(EventFilters))),

'ok' = file:write(IO, "-ifndef(FS_EVENT_FILTERS_HRL).\n"),
'ok' = file:write(IO, "-include(\"fs_manual_event_filters.hrl\").\n"),
'ok' = file:write(IO, "-ifndef(FS_GENERATED_EVENT_FILTERS_HRL).\n\n"),

'ok' = file:write(IO, io_lib:format("-define(FS_EVENT_FITLERS~n ,[~p~n", [First])),
'ok' = file:write(IO, io_lib:format("-define(FS_GENERATED_EVENT_FILTERS~n ,[~p~n", [First])),
lists:foreach(fun(Filter) ->
file:write(IO, io_lib:format(" ,~p~n", [Filter]))
end
,Sorted
),
'ok' = file:write(IO, " | ?FS_MANUAL_HEADERS\n ]).\n"),
'ok' = file:write(IO, "-define(FS_EVENT_FILTERS_HRL, 'true').\n-endif.\n"),
'ok' = file:write(IO, " ]).\n\n"),
'ok' = file:write(IO, "-define(FS_GENERATED_EVENT_FILTERS_HRL, 'true').\n\n"),
'ok' = file:write(IO, "-endif.\n"),
'ok' = file:close(IO).

ignored_headers(<<"variable_ecallmgr", _/binary>>) -> 'false';
Expand All @@ -62,6 +62,8 @@ usage_keys({'props', 'get_integer_value', Key, _VarName, _Default}, Acc) ->
[Key |Acc];
usage_keys({'props', 'get_binary_value', Key, _VarName, _Default}, Acc) ->
[Key |Acc];
usage_keys({'props', 'get_ne_binary_value', Key, _VarName, _Default}, Acc) ->
[Key |Acc];
usage_keys({'props', 'get_is_true', Key, _VarName, _Default}, Acc) ->
[Key |Acc];
usage_keys({'props', 'is_true', Key, _VarName, _Default}, Acc) ->
Expand Down

0 comments on commit 2ec3254

Please sign in to comment.