Skip to content

Commit

Permalink
KAZOO-240: updated config lookup for conferences to ref profiles, rou…
Browse files Browse the repository at this point in the history
…ting key on profile name, etc
  • Loading branch information
James Aimonetti committed Apr 4, 2013
1 parent 64022d8 commit 00c7763
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
18 changes: 9 additions & 9 deletions ecallmgr/src/ecallmgr_fs_config.erl
Expand Up @@ -12,7 +12,7 @@
-behaviour(gen_server).

%% API
-export([start_link/1, start_link/2]).
-export([start_link/1, start_link/2]).
-export([handle_config_req/3, handle_config_req/4]).
-export([init/1
,handle_call/3
Expand Down Expand Up @@ -188,9 +188,9 @@ handle_config_req(Node, ID, _Conf) ->

handle_config_req(Node, ID, <<"conference.conf">>, Data) ->
put('callid', ID),
ConfConfig = props:get_value(<<"profile_name">>, Data, <<"default">>),
Cmd =
[{<<"Conference-Config">>, ConfConfig}
Profile = props:get_value(<<"profile_name">>, Data, <<"default">>),
Cmd =
[{<<"Profile">>, Profile}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
XmlResp = case wh_amqp_worker:call(?ECALLMGR_AMQP_POOL, Cmd
Expand All @@ -200,15 +200,15 @@ handle_config_req(Node, ID, <<"conference.conf">>, Data) ->
of
{'ok', Resp} ->
{'ok', Xml} = ecallmgr_fs_xml:conference_resp_xml(Resp),
lager:debug("conference config xml: ~s", [Xml]),
lager:debug("conference profile xml for ~s: ~s", [Profile, Xml]),
Xml;
{'error', 'timeout'} ->
lager:debug("timed out waiting for conference config for ~s", [ConfConfig]),
{'ok', Resp} = ecallmgr_fs_xml:not_found(),
lager:debug("timed out waiting for conference profile for ~s", [Profile]),
{'ok', Resp} = ecallmgr_fs_xml:not_found(),
Resp;
_Other ->
lager:debug("failed to lookup config: ~p", [_Other]),
{'ok', Resp} = ecallmgr_fs_xml:not_found(),
lager:debug("failed to lookup conference profile for ~s: ~p", [Profile, _Other]),
{'ok', Resp} = ecallmgr_fs_xml:not_found(),
Resp
end,
freeswitch:fetch_reply(Node, ID, iolist_to_binary(XmlResp));
Expand Down
66 changes: 36 additions & 30 deletions lib/whistle-1.0.0/src/api/wapi_conference.erl
Expand Up @@ -314,7 +314,7 @@
]).
-define(CONFERENCE_ERROR_TYPES, []).

-define(CONFIG_REQ_HEADERS, [<<"Conference-Config">>]).
-define(CONFIG_REQ_HEADERS, [<<"Profile">>]).
-define(OPTIONAL_CONFIG_REQ_HEADERS, []).
-define(CONFIG_REQ_VALUES, [{<<"Event-Category">>, <<"conference">>}
,{<<"Event-Name">>, <<"config_req">>}
Expand Down Expand Up @@ -885,28 +885,29 @@ config_resp_v(JObj) -> config_resp_v(wh_json:to_proplist(JObj)).
-spec bind_q(ne_binary(), wh_proplist()) -> 'ok'.
bind_q(Queue, Props) ->
amqp_util:conference_exchange(),
bind_to_q(Queue, props:get_value('restrict_to', Props)).
bind_to_q(Queue, props:get_value('restrict_to', Props), Props).

bind_to_q(Q, 'undefined') ->
bind_to_q(Q, 'undefined', _) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'discovery'),
'ok' = amqp_util:bind_q_to_conference(Q, 'command'),
amqp_util:bind_q_to_conference(Q, 'event');
bind_to_q(Q, ['discovery'|T]) ->
bind_to_q(Q, ['discovery'|T], Props) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'discovery'),
bind_to_q(Q, T);
bind_to_q(Q, ['command'|T]) ->
bind_to_q(Q, T, Props);
bind_to_q(Q, ['command'|T], Props) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'command'),
bind_to_q(Q, T);
bind_to_q(Q, ['event'|T]) ->
bind_to_q(Q, T, Props);
bind_to_q(Q, ['event'|T], Props) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'event'),
bind_to_q(Q, T);
bind_to_q(Q, ['config'|T]) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'config'),
bind_to_q(Q, T);
bind_to_q(Q, [{'conference', ConfId}|T]) ->
bind_to_q(Q, T, Props);
bind_to_q(Q, ['config'|T], Props) ->
Profile = props:get_value('profile', Props, <<"*">>),
'ok' = amqp_util:bind_q_to_conference(Q, 'config', Profile),
bind_to_q(Q, T, Props);
bind_to_q(Q, [{'conference', ConfId}|T], Props) ->
'ok' = amqp_util:bind_q_to_conference(Q, 'event', ConfId),
bind_to_q(Q, T);
bind_to_q(_Q, []) -> 'ok'.
bind_to_q(Q, T, Props);
bind_to_q(_Q, [], _) -> 'ok'.

%%--------------------------------------------------------------------
%% @doc
Expand All @@ -916,28 +917,29 @@ bind_to_q(_Q, []) -> 'ok'.
-spec unbind_q(ne_binary(), wh_proplist()) -> 'ok'.
unbind_q(Queue, Props) ->
amqp_util:conference_exchange(),
unbind_from_q(Queue, props:get_value('restrict_to', Props)).
unbind_from_q(Queue, props:get_value('restrict_to', Props), Props).

unbind_from_q(Q, 'undefined') ->
unbind_from_q(Q, 'undefined', _) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'discovery'),
'ok' = amqp_util:unbind_q_from_conference(Q, 'command'),
amqp_util:unbind_q_from_conference(Q, 'event');
unbind_from_q(Q, ['discovery'|T]) ->
unbind_from_q(Q, ['discovery'|T], Props) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'discovery'),
unbind_from_q(Q, T);
unbind_from_q(Q, ['command'|T]) ->
unbind_from_q(Q, T, Props);
unbind_from_q(Q, ['command'|T], Props) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'command'),
unbind_from_q(Q, T);
unbind_from_q(Q, ['event'|T]) ->
unbind_from_q(Q, T, Props);
unbind_from_q(Q, ['event'|T], Props) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'event'),
unbind_from_q(Q, T);
unbind_from_q(Q, [{'conference', ConfId}|T]) ->
unbind_from_q(Q, T, Props);
unbind_from_q(Q, [{'conference', ConfId}|T], Props) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'event', ConfId),
unbind_from_q(Q, T);
unbind_from_q(Q, ['config'|T]) ->
'ok' = amqp_util:unbind_q_from_conference(Q, 'config'),
bind_to_q(Q, T);
unbind_from_q(_Q, []) -> 'ok'.
unbind_from_q(Q, T, Props);
unbind_from_q(Q, ['config'|T], Props) ->
Profile = props:get_value('profile', Props, <<"*">>),
'ok' = amqp_util:unbind_q_from_conference(Q, 'config', Profile),
unbind_from_q(Q, T, Props);
unbind_from_q(_Q, [], _) -> 'ok'.

%%--------------------------------------------------------------------
%% @doc
Expand Down Expand Up @@ -1298,8 +1300,12 @@ publish_targeted_command(Focus, Req, ContentType) ->
publish_config_req(JObj) ->
publish_config_req(JObj, ?DEFAULT_CONTENT_TYPE).
publish_config_req(Req, ContentType) ->
Profile = profile(Req),
{'ok', Payload} = wh_api:prepare_api_payload(Req, ?CONFIG_REQ_VALUES, fun ?MODULE:config_req/1),
amqp_util:conference_publish(Payload, 'config', <<"*">>, [], ContentType).
amqp_util:conference_publish(Payload, 'config', Profile, [], ContentType).

profile(Props) when is_list(Props) -> props:get_value(<<"Profile">>, Props);
profile(JObj) -> wh_json:get_value(<<"Profile">>, JObj).

%%--------------------------------------------------------------------
%% @doc
Expand Down
38 changes: 17 additions & 21 deletions lib/whistle_amqp-1.0.0/src/amqp_util.erl
Expand Up @@ -313,8 +313,8 @@ conference_publish(Payload, 'command', ConfId, Options) ->

conference_publish(Payload, 'discovery', _, Options, ContentType) ->
basic_publish(?EXCHANGE_CONFERENCE, ?KEY_CONFERENCE_DISCOVERY, Payload, ContentType, Options);
conference_publish(Payload, 'config', _, Options, ContentType) ->
basic_publish(?EXCHANGE_CONFERENCE, ?KEY_CONFERENCE_CONFIG, Payload, ContentType, Options);
conference_publish(Payload, 'config', ConfProfile, Options, ContentType) ->
basic_publish(?EXCHANGE_CONFERENCE, <<?KEY_CONFERENCE_CONFIG/binary, ConfProfile/binary>>, Payload, ContentType, Options);
conference_publish(Payload, 'event', ConfId, Options, ContentType) ->
basic_publish(?EXCHANGE_CONFERENCE, <<?KEY_CONFERENCE_EVENT/binary, ConfId/binary>>, Payload, ContentType, Options);
conference_publish(Payload, 'command', ConfId, Options, ContentType) ->
Expand Down Expand Up @@ -723,8 +723,8 @@ bind_q_to_conference(Queue, 'event', ConfId) ->
bind_q_to_exchange(Queue, <<?KEY_CONFERENCE_EVENT/binary, ConfId/binary>>, ?EXCHANGE_CONFERENCE);
bind_q_to_conference(Queue, 'command', ConfId) ->
bind_q_to_exchange(Queue, <<?KEY_CONFERENCE_COMMAND/binary, ConfId/binary>>, ?EXCHANGE_CONFERENCE);
bind_q_to_conference(Queue, 'config', _) ->
bind_q_to_exchange(Queue, ?KEY_CONFERENCE_CONFIG, ?EXCHANGE_CONFERENCE).
bind_q_to_conference(Queue, 'config', ConfProfile) ->
bind_q_to_exchange(Queue, <<?KEY_CONFERENCE_CONFIG/binary, ConfProfile/binary>>, ?EXCHANGE_CONFERENCE).

-spec bind_q_to_exchange(ne_binary(), ne_binary(), ne_binary()) -> 'ok'.
-spec bind_q_to_exchange(ne_binary(), ne_binary(), ne_binary(), wh_proplist()) -> 'ok'.
Expand Down Expand Up @@ -784,8 +784,8 @@ unbind_q_from_conference(Queue, 'discovery', _) ->
unbind_q_from_exchange(Queue, ?KEY_CONFERENCE_DISCOVERY, ?EXCHANGE_CONFERENCE);
unbind_q_from_conference(Queue, 'event', ConfId) ->
unbind_q_from_exchange(Queue, <<?KEY_CONFERENCE_EVENT/binary, ConfId/binary>>, ?EXCHANGE_CONFERENCE);
unbind_q_from_conference(Queue, 'config', _) ->
unbind_q_from_exchange(Queue, ?KEY_CONFERENCE_CONFIG, ?EXCHANGE_CONFERENCE);
unbind_q_from_conference(Queue, 'config', ConfProfile) ->
unbind_q_from_exchange(Queue, <<?KEY_CONFERENCE_CONFIG/binary, ConfProfile/binary>>, ?EXCHANGE_CONFERENCE);
unbind_q_from_conference(Queue, 'command', ConfId) ->
unbind_q_from_exchange(Queue, <<?KEY_CONFERENCE_COMMAND/binary, ConfId/binary>>, ?EXCHANGE_CONFERENCE).

Expand Down Expand Up @@ -869,13 +869,13 @@ basic_cancel() -> wh_amqp_channel:command(#'basic.cancel'{}).
access_request() -> access_request([]).
access_request(Options) ->
#'access.request'{
realm = props:get_value('realm', Options, <<"/data">>)
,exclusive = props:get_value('exclusive', Options, 'false')
,passive = props:get_value(passive, Options, 'true')
,active = props:get_value(active, Options, 'true')
,write = props:get_value(write, Options, 'true')
,read = props:get_value(read, Options, 'true')
}.
realm = props:get_value('realm', Options, <<"/data">>)
,exclusive = props:get_value('exclusive', Options, 'false')
,passive = props:get_value('passive', Options, 'true')
,active = props:get_value('active', Options, 'true')
,write = props:get_value('write', Options, 'true')
,read = props:get_value('read', Options, 'true')
}.

%%------------------------------------------------------------------------------
%% @public
Expand All @@ -894,10 +894,8 @@ is_json(#'P_basic'{content_type=CT}) -> CT =:= ?DEFAULT_CONTENT_TYPE.
%% @end
%%------------------------------------------------------------------------------
-spec basic_ack(integer() | #'basic.deliver'{}) -> 'ok'.
basic_ack(#'basic.deliver'{delivery_tag=DTag}) ->
basic_ack(DTag);
basic_ack(DTag) ->
wh_amqp_channel:command(#'basic.ack'{delivery_tag=DTag}).
basic_ack(#'basic.deliver'{delivery_tag=DTag}) -> basic_ack(DTag);
basic_ack(DTag) -> wh_amqp_channel:command(#'basic.ack'{delivery_tag=DTag}).

%%------------------------------------------------------------------------------
%% @public
Expand All @@ -907,10 +905,8 @@ basic_ack(DTag) ->
%% @end
%%------------------------------------------------------------------------------
-spec basic_nack(integer() | #'basic.deliver'{}) -> 'ok'.
basic_nack(#'basic.deliver'{delivery_tag=DTag}) ->
basic_nack(DTag);
basic_nack(DTag) ->
wh_amqp_channel:command(#'basic.nack'{delivery_tag=DTag}).
basic_nack(#'basic.deliver'{delivery_tag=DTag}) -> basic_nack(DTag);
basic_nack(DTag) -> wh_amqp_channel:command(#'basic.nack'{delivery_tag=DTag}).

%%------------------------------------------------------------------------------
%% @public
Expand Down

0 comments on commit 00c7763

Please sign in to comment.