From 158d95e6b8575be8983ae6024ffa85c639ecdfda Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 26 Aug 2012 02:55:41 +0200 Subject: Make service_info behave with nested item lists and non-atoms --- lib/diameter/src/base/diameter_service.erl | 41 ++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'lib/diameter/src/base') diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl index ad5a853a0d..6aff03ec1d 100644 --- a/lib/diameter/src/base/diameter_service.erl +++ b/lib/diameter/src/base/diameter_service.erl @@ -2812,14 +2812,33 @@ transports(#state{peerT = PeerT}) -> peers, statistics]). -service_info(Items, S) - when is_list(Items) -> - [{complete(I), service_info(I,S)} || I <- Items]; service_info(Item, S) when is_atom(Item) -> - service_info(Item, S, true). + case tagged_info(Item, S) of + {_, T} -> T; + undefined = No -> No + end; + +service_info(Items, S) -> + tagged_info(Items, S). + +tagged_info(Item, S) + when is_atom(Item) -> + case complete(Item) of + {value, I} -> + {I, complete_info(I,S)}; + false -> + undefined + end; + +tagged_info(Items, S) + when is_list(Items) -> + [T || I <- Items, T <- [tagged_info(I,S)], T /= undefined, T /= []]; + +tagged_info(_, _) -> + undefined. -service_info(Item, #state{service = Svc} = S, Complete) -> +complete_info(Item, #state{service = Svc} = S) -> case Item of name -> S#state.service_name; @@ -2867,18 +2886,20 @@ service_info(Item, #state{service = Svc} = S, Complete) -> all -> service_info(?ALL_INFO, S); statistics -> info_stats(S); connections -> info_connections(S); - peers -> info_peers(S); - _ when Complete -> service_info(complete(Item), S, false); - _ -> undefined + peers -> info_peers(S) end. +complete(I) + when I == keys; + I == all -> + {value, I}; complete(Pre) -> P = atom_to_list(Pre), case [I || I <- ?ALL_INFO ++ ?CAP_INFO ++ ?OTHER_INFO, lists:prefix(P, atom_to_list(I))] of - [I] -> I; - _ -> Pre + [I] -> {value, I}; + _ -> false end. %% info_stats/1 -- cgit v1.2.3