diff options
author | Anders Svensson <[email protected]> | 2014-05-24 12:13:04 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2014-05-26 13:52:06 +0200 |
commit | 2d5e6f4d438db1a480e44c539155e334c11851bc (patch) | |
tree | 3599559e28c8c1d7a603c96b8e20048909297111 /lib/diameter | |
parent | 11e3a1b7f21fbb4419043b36ea9cf8c2d53aa7b5 (diff) | |
download | otp-2d5e6f4d438db1a480e44c539155e334c11851bc.tar.gz otp-2d5e6f4d438db1a480e44c539155e334c11851bc.tar.bz2 otp-2d5e6f4d438db1a480e44c539155e334c11851bc.zip |
Simplify example server
In particular, remove the unnecessary list-or-record answer.
Diffstat (limited to 'lib/diameter')
-rw-r--r-- | lib/diameter/examples/code/server_cb.erl | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/lib/diameter/examples/code/server_cb.erl b/lib/diameter/examples/code/server_cb.erl index 76d922c112..9d8d395d06 100644 --- a/lib/diameter/examples/code/server_cb.erl +++ b/lib/diameter/examples/code/server_cb.erl @@ -66,10 +66,13 @@ handle_request(#diameter_packet{msg = Req, errors = []}, _SvcName, {_, Caps}) origin_realm = {OR,_}} = Caps, #diameter_base_RAR{'Session-Id' = Id, - 'Re-Auth-Request-Type' = RT} + 'Re-Auth-Request-Type' = Type} = Req, - {reply, answer(RT, Id, OH, OR)}; + {reply, #diameter_base_RAA{'Result-Code' = rc(Type), + 'Origin-Host' = OH, + 'Origin-Realm' = OR, + 'Session-Id' = Id}}; %% ... or one that wasn't. 3xxx errors are answered by diameter itself %% but these are 5xxx errors for which we must contruct a reply. @@ -82,31 +85,18 @@ handle_request(#diameter_packet{msg = Req}, _SvcName, {_, Caps}) #diameter_base_RAR{'Session-Id' = Id} = Req, - Ans = #diameter_base_RAA{'Origin-Host' = OH, - 'Origin-Realm' = OR, - 'Session-Id' = Id}, - - {reply, Ans}; + {reply, #diameter_base_RAA{'Origin-Host' = OH, + 'Origin-Realm' = OR, + 'Session-Id' = Id}}; %% Answer that any other message is unsupported. handle_request(#diameter_packet{}, _SvcName, _) -> {answer_message, 3001}. %% DIAMETER_COMMAND_UNSUPPORTED -%% --------------------------------------------------------------------------- - -%% Answer using the record or list encoding depending on -%% Re-Auth-Request-Type. This is just as an example. You would -%% typically just choose one, and this has nothing to do with how -%% client.erl sends. - -answer(0, Id, OH, OR) -> - #diameter_base_RAA{'Result-Code' = 2001, %% DIAMETER_SUCCESS - 'Origin-Host' = OH, - 'Origin-Realm' = OR, - 'Session-Id' = Id}; +%% Map Re-Auth-Request-Type to Result-Code just for the purpose of +%% generating different answers. -answer(_, Id, OH, OR) -> - ['RAA', {'Result-Code', 5012}, %% DIAMETER_UNABLE_TO_COMPLY - {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Session-Id', Id}]. +rc(0) -> + 2001; %% DIAMETER_SUCCESS +rc(_) -> + 5012. %% DIAMETER_UNABLE_TO_COMPLY |