1111% % The Original Code is RabbitMQ.
1212% %
1313% % The Initial Developer of the Original Code is GoPivotal, Inc.
14- % % Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved.
14+ % % Copyright (c) 2007-2019 Pivotal Software, Inc. All rights reserved.
1515% %
1616
1717-module (rabbit_mqtt_processor ).
2121 close_connection /1 ]).
2222
2323% % for testing purposes
24- -export ([get_vhost_username /1 , get_vhost /3 , get_vhost_from_user_mapping /2 ]).
24+ -export ([get_vhost_username /1 , get_vhost /3 , get_vhost_from_user_mapping /2 ,
25+ add_client_id_to_adapter_info /2 ]).
2526
2627-include_lib (" amqp_client/include/amqp_client.hrl" ).
2728-include (" rabbit_mqtt_frame.hrl" ).
@@ -73,6 +74,22 @@ process_frame(Frame = #mqtt_frame{ fixed = #mqtt_frame_fixed{ type = Type }},
7374 Ret -> Ret
7475 end .
7576
77+ add_client_id_to_adapter_info (ClientId , # amqp_adapter_info {additional_info = AdditionalInfo0 } = AdapterInfo ) ->
78+ AdditionalInfo1 = [{variable_map , #{<<" client_id" >> => ClientId }}
79+ | AdditionalInfo0 ],
80+ ClientProperties = proplists :get_value (client_properties , AdditionalInfo1 , [])
81+ ++ [{client_id , longstr , ClientId }],
82+ AdditionalInfo2 = case lists :keysearch (client_properties , 1 , AdditionalInfo1 ) of
83+ {value , _ } ->
84+ lists :keyreplace (client_properties ,
85+ 1 ,
86+ AdditionalInfo1 ,
87+ {client_properties , ClientProperties });
88+ false ->
89+ [{client_properties , ClientProperties } | AdditionalInfo1 ]
90+ end ,
91+ AdapterInfo # amqp_adapter_info {additional_info = AdditionalInfo2 }.
92+
7693process_request (? CONNECT ,
7794 # mqtt_frame { variable = # mqtt_frame_connect {
7895 username = Username ,
@@ -83,14 +100,12 @@ process_request(?CONNECT,
83100 keep_alive = Keepalive } = Var },
84101 PState0 = # proc_state { ssl_login_name = SSLLoginName ,
85102 send_fun = SendFun ,
86- adapter_info = AdapterInfo = # amqp_adapter_info { additional_info = Extra } }) ->
103+ adapter_info = AdapterInfo }) ->
87104 ClientId = case ClientId0 of
88105 [] -> rabbit_mqtt_util :gen_client_id ();
89106 [_ |_ ] -> ClientId0
90107 end ,
91- AdapterInfo1 = AdapterInfo # amqp_adapter_info {additional_info = [
92- {variable_map , #{<<" client_id" >> => rabbit_data_coercion :to_binary (ClientId )}}
93- | Extra ]},
108+ AdapterInfo1 = add_client_id_to_adapter_info (rabbit_data_coercion :to_binary (ClientId ), AdapterInfo ),
94109 PState = PState0 # proc_state {adapter_info = AdapterInfo1 },
95110 {Return , PState1 } =
96111 case {lists :member (ProtoVersion , proplists :get_keys (? PROTOCOL_NAMES )),
0 commit comments