12
12
size /1 ,
13
13
x_header /2 ,
14
14
routing_headers /2 ,
15
- convert_to /2 ,
16
- convert_from /2 ,
15
+ convert_to /3 ,
16
+ convert_from /3 ,
17
17
protocol_state /2 ,
18
18
property /2 ,
19
19
set_property /3 ,
@@ -54,7 +54,7 @@ init(#content{} = Content0) ->
54
54
Anns = essential_properties (Content ),
55
55
{strip_header (Content , ? DELETED_HEADER ), Anns }.
56
56
57
- convert_from (mc_amqp , Sections ) ->
57
+ convert_from (mc_amqp , Sections , _Env ) ->
58
58
{H , MAnn , Prop , AProp , BodyRev } =
59
59
lists :foldl (
60
60
fun
@@ -144,15 +144,17 @@ convert_from(mc_amqp, Sections) ->
144
144
end ,
145
145
146
146
Headers0 = [to_091 (K , V ) || {{utf8 , K }, V } <- AP ,
147
- byte_size (K ) =< ? AMQP_LEGACY_FIELD_NAME_MAX_LEN ],
148
- % % Add remaining message annotations as headers?
147
+ ? IS_SHORTSTR_LEN (K )],
148
+ % % Add remaining x- message annotations as headers
149
149
XHeaders = lists :filtermap (fun ({{symbol , <<" x-cc" >>}, V }) ->
150
150
{true , to_091 (<<" CC" >>, V )};
151
- ({{symbol , K }, V })
152
- when byte_size (K ) =< ? AMQP_LEGACY_FIELD_NAME_MAX_LEN ->
151
+ ({{symbol , << " x- " , _ / binary >> = K }, V })
152
+ when ? IS_SHORTSTR_LEN (K ) ->
153
153
case is_internal_header (K ) of
154
- false -> {true , to_091 (K , V )};
155
- true -> false
154
+ false ->
155
+ {true , to_091 (K , V )};
156
+ true ->
157
+ false
156
158
end ;
157
159
(_ ) ->
158
160
false
@@ -161,6 +163,8 @@ convert_from(mc_amqp, Sections) ->
161
163
{Headers , CorrId091 } = message_id (CorrId , <<" x-correlation-id" >>, Headers1 ),
162
164
163
165
UserId1 = unwrap (UserId0 ),
166
+ % % user-id is a binary type so we need to validate
167
+ % % if we can use it as is
164
168
UserId = case mc_util :is_valid_shortstr (UserId1 ) of
165
169
true ->
166
170
UserId1 ;
@@ -177,9 +181,9 @@ convert_from(mc_amqp, Sections) ->
177
181
[] -> undefined ;
178
182
AllHeaders -> AllHeaders
179
183
end ,
180
- reply_to = unwrap (ReplyTo0 ),
184
+ reply_to = unwrap_shortstr (ReplyTo0 ),
181
185
type = Type ,
182
- app_id = unwrap (GroupId ),
186
+ app_id = unwrap_shortstr (GroupId ),
183
187
priority = Priority ,
184
188
correlation_id = CorrId091 ,
185
189
content_type = unwrap (ContentType ),
@@ -190,7 +194,7 @@ convert_from(mc_amqp, Sections) ->
190
194
properties = BP ,
191
195
properties_bin = none ,
192
196
payload_fragments_rev = PayloadRev };
193
- convert_from (_SourceProto , _ ) ->
197
+ convert_from (_SourceProto , _ , _ ) ->
194
198
not_implemented .
195
199
196
200
size (# content {properties_bin = PropsBin ,
@@ -263,11 +267,11 @@ prepare(store, Content) ->
263
267
rabbit_binary_parser :clear_decoded_content (
264
268
rabbit_binary_generator :ensure_content_encoded (Content , ? PROTOMOD )).
265
269
266
- convert_to (? MODULE , Content ) ->
270
+ convert_to (? MODULE , Content , _Env ) ->
267
271
Content ;
268
- convert_to (mc_amqp , # content {payload_fragments_rev = Payload } = Content ) ->
272
+ convert_to (mc_amqp , # content {payload_fragments_rev = Payload } = Content , Env ) ->
269
273
# content {properties = Props } = prepare (read , Content ),
270
- # 'P_basic' {message_id = MsgId ,
274
+ # 'P_basic' {message_id = MsgId0 ,
271
275
expiration = Expiration ,
272
276
delivery_mode = DelMode ,
273
277
headers = Headers0 ,
@@ -276,7 +280,7 @@ convert_to(mc_amqp, #content{payload_fragments_rev = Payload} = Content) ->
276
280
type = Type ,
277
281
priority = Priority ,
278
282
app_id = AppId ,
279
- correlation_id = CorrId ,
283
+ correlation_id = CorrId0 ,
280
284
content_type = ContentType ,
281
285
content_encoding = ContentEncoding ,
282
286
timestamp = Timestamp } = Props ,
@@ -297,21 +301,34 @@ convert_to(mc_amqp, #content{payload_fragments_rev = Payload} = Content) ->
297
301
undefined ->
298
302
undefined ;
299
303
_ ->
304
+ % % Channel already checked for valid integer.
300
305
binary_to_integer (Expiration )
301
306
end ,
302
307
303
308
H = # 'v1_0.header' {durable = DelMode =:= 2 ,
304
309
ttl = wrap (uint , Ttl ),
305
310
% % TODO: check Priority is a ubyte?
306
311
priority = wrap (ubyte , Priority )},
312
+ CorrId = case mc_util :urn_string_to_uuid (CorrId0 ) of
313
+ {ok , CorrUUID } ->
314
+ {uuid , CorrUUID };
315
+ _ ->
316
+ wrap (utf8 , CorrId0 )
317
+ end ,
318
+ MsgId = case mc_util :urn_string_to_uuid (MsgId0 ) of
319
+ {ok , MsgUUID } ->
320
+ {uuid , MsgUUID };
321
+ _ ->
322
+ wrap (utf8 , MsgId0 )
323
+ end ,
307
324
P = case amqp10_section_header (? AMQP10_PROPERTIES_HEADER , Headers ) of
308
325
undefined ->
309
- # 'v1_0.properties' {message_id = wrap ( utf8 , MsgId ) ,
326
+ # 'v1_0.properties' {message_id = MsgId ,
310
327
user_id = wrap (binary , UserId ),
311
328
to = undefined ,
312
329
% subject = wrap(utf8, RKey),
313
330
reply_to = wrap (utf8 , ReplyTo ),
314
- correlation_id = wrap ( utf8 , CorrId ) ,
331
+ correlation_id = CorrId ,
315
332
content_type = wrap (symbol , ContentType ),
316
333
content_encoding = wrap (symbol , ContentEncoding ),
317
334
creation_time = wrap (timestamp , ConvertedTs ),
@@ -367,8 +384,8 @@ convert_to(mc_amqp, #content{payload_fragments_rev = Payload} = Content) ->
367
384
end ,
368
385
369
386
Sections = [H , MA , P , AP | BodySections ],
370
- mc_amqp :convert_from (mc_amqp , Sections );
371
- convert_to (_TargetProto , _Content ) ->
387
+ mc_amqp :convert_from (mc_amqp , Sections , Env );
388
+ convert_to (_TargetProto , _Content , _Env ) ->
372
389
not_implemented .
373
390
374
391
protocol_state (# content {properties = # 'P_basic' {headers = H00 } = B0 } = C ,
@@ -606,7 +623,15 @@ unwrap({timestamp, V}) ->
606
623
unwrap ({_Type , V }) ->
607
624
V .
608
625
609
- to_091 (Key , {utf8 , V }) when is_binary (V ) -> {Key , longstr , V };
626
+ unwrap_shortstr ({utf8 , V })
627
+ when is_binary (V ) andalso
628
+ ? IS_SHORTSTR_LEN (V ) ->
629
+ V ;
630
+ unwrap_shortstr (_ ) ->
631
+ undefined .
632
+
633
+ to_091 (Key , {utf8 , V }) -> {Key , longstr , V };
634
+ to_091 (Key , {symbol , V }) -> {Key , longstr , V };
610
635
to_091 (Key , {long , V }) -> {Key , long , V };
611
636
to_091 (Key , {ulong , V }) -> {Key , long , V }; % % TODO: we could try to constrain this
612
637
to_091 (Key , {byte , V }) -> {Key , byte , V };
@@ -630,6 +655,7 @@ to_091(Key, {map, M}) ->
630
655
{Key , table , [to_091 (unwrap (K ), V ) || {K , V } <- M ]}.
631
656
632
657
to_091 ({utf8 , V }) -> {longstr , V };
658
+ to_091 ({symbol , V }) -> {longstr , V };
633
659
to_091 ({long , V }) -> {long , V };
634
660
to_091 ({byte , V }) -> {byte , V };
635
661
to_091 ({ubyte , V }) -> {unsignedbyte , V };
@@ -652,17 +678,17 @@ to_091({map, M}) ->
652
678
{table , [to_091 (unwrap (K ), V ) || {K , V } <- M ]}.
653
679
654
680
message_id ({uuid , UUID }, _HKey , H0 ) ->
655
- {H0 , mc_util :uuid_to_string (UUID )};
681
+ {H0 , mc_util :uuid_to_urn_string (UUID )};
656
682
message_id ({ulong , N }, _HKey , H0 ) ->
657
683
{H0 , erlang :integer_to_binary (N )};
658
684
message_id ({binary , B }, HKey , H0 ) ->
659
- {[{HKey , longstr , B } | H0 ], undefined };
685
+ {[{HKey , binary , B } | H0 ], undefined };
660
686
message_id ({utf8 , S }, HKey , H0 ) ->
661
- case byte_size (S ) > 255 of
687
+ case ? IS_SHORTSTR_LEN (S ) of
662
688
true ->
663
- {[{ HKey , longstr , S } | H0 ], undefined };
689
+ {H0 , S };
664
690
false ->
665
- {H0 , S }
691
+ {[{ HKey , longstr , S } | H0 ], undefined }
666
692
end ;
667
693
message_id (undefined , _HKey , H ) ->
668
694
{H , undefined }.
0 commit comments