From 1c3a50e7b75ad5d036814fc7a5e0c8517ceb4420 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 22 Jul 2013 19:55:00 +0100 Subject: [PATCH 1/2] add amqp_rpc_{client,server}:start_link functions --- src/amqp_rpc_client.erl | 14 +++++++++++++- src/amqp_rpc_server.erl | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/amqp_rpc_client.erl b/src/amqp_rpc_client.erl index 9d1b8161..9b9d0ee8 100644 --- a/src/amqp_rpc_client.erl +++ b/src/amqp_rpc_client.erl @@ -25,7 +25,7 @@ -behaviour(gen_server). --export([start/2, stop/1]). +-export([start/2, start_link/2, stop/1]). -export([call/2]). -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). @@ -53,6 +53,18 @@ start(Connection, Queue) -> {ok, Pid} = gen_server:start(?MODULE, [Connection, Queue], []), Pid. +%% @spec (Connection, Queue) -> RpcClient +%% where +%% Connection = pid() +%% Queue = binary() +%% RpcClient = pid() +%% @doc Starts, and links to, a new RPC client instance that sends requests +%% to a specified queue. This function returns the pid of the RPC client +%% process that can be used to invoke RPCs and stop the client. +start_link(Connection, Queue) -> + {ok, Pid} = gen_server:start_link(?MODULE, [Connection, Queue], []), + Pid. + %% @spec (RpcClient) -> ok %% where %% RpcClient = pid() diff --git a/src/amqp_rpc_server.erl b/src/amqp_rpc_server.erl index 38141a7d..79f30657 100644 --- a/src/amqp_rpc_server.erl +++ b/src/amqp_rpc_server.erl @@ -27,7 +27,7 @@ -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). --export([start/3]). +-export([start/3, start_link/3]). -export([stop/1]). -record(state, {channel, @@ -51,6 +51,20 @@ start(Connection, Queue, Fun) -> {ok, Pid} = gen_server:start(?MODULE, [Connection, Queue, Fun], []), Pid. +%% @spec (Connection, Queue, RpcHandler) -> RpcServer +%% where +%% Connection = pid() +%% Queue = binary() +%% RpcHandler = function() +%% RpcServer = pid() +%% @doc Starts, and links to, a new RPC server instance that receives +%% requests via a specified queue and dispatches them to a specified +%% handler function. This function returns the pid of the RPC server that +%% can be used to stop the server. +start_link(Connection, Queue, Fun) -> + {ok, Pid} = gen_server:start_link(?MODULE, [Connection, Queue, Fun], []), + Pid. + %% @spec (RpcServer) -> ok %% where %% RpcServer = pid() From 91e7fc548076841d571a49b167e97063e2911848 Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Tue, 30 Jul 2013 11:41:22 +0100 Subject: [PATCH 2/2] Don't reject connection.secure, and add an implementation of cr-demo for (manual) testing. --- src/amqp_auth_mechanisms.erl | 10 +++++++++- src/amqp_network_connection.erl | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/amqp_auth_mechanisms.erl b/src/amqp_auth_mechanisms.erl index 761ca27e..a1d14f23 100644 --- a/src/amqp_auth_mechanisms.erl +++ b/src/amqp_auth_mechanisms.erl @@ -19,7 +19,7 @@ -include("amqp_client.hrl"). --export([plain/3, amqplain/3, external/3]). +-export([plain/3, amqplain/3, external/3, crdemo/3]). %%--------------------------------------------------------------------------- @@ -41,3 +41,11 @@ external(none, _, init) -> {<<"EXTERNAL">>, []}; external(none, _, _State) -> {<<"">>, _State}. + +crdemo(none, _, init) -> + {<<"RABBIT-CR-DEMO">>, 0}; +crdemo(none, #amqp_params_network{username = Username}, 0) -> + {Username, 1}; +crdemo(<<"Please tell me your password">>, + #amqp_params_network{password = Password}, 1) -> + {<<"My password is ", Password/binary>>, 2}. diff --git a/src/amqp_network_connection.erl b/src/amqp_network_connection.erl index 214ce19d..7d7f012e 100644 --- a/src/amqp_network_connection.erl +++ b/src/amqp_network_connection.erl @@ -289,6 +289,8 @@ handshake_recv(Expecting) -> case {Expecting, element(1, Method)} of {E, M} when E =:= M -> Method; + {'connection.tune', 'connection.secure'} -> + Method; {'connection.open_ok', _} -> {closing, #amqp_error{name = command_invalid,