Skip to content

Commit

Permalink
[tm] fix format of trasaction identifier in t_reply MI cmd
Browse files Browse the repository at this point in the history
besides the old (almost obsolete) format provided by t_write_fifo(), we must also support the new format provided by $T_id
  • Loading branch information
bogdan-iancu committed Jan 14, 2025
1 parent cc76190 commit b8bb444
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions modules/tm/mi.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,17 +691,31 @@ mi_response_t *mi_tm_reply(const mi_params_t *params, str *new_hdrs, str *body)

tmp = trans_id;
p = memchr( tmp.s, ':', tmp.len);
if ( p==NULL)
return init_mi_error(400, MI_SSTR("Invalid trans_id"));

tmp.len = p-tmp.s;
if( str2int( &tmp, &hash_index)!=0 )
return init_mi_error(400, MI_SSTR("Invalid index in trans_id"));
if ( p ) {
/* old fashion ID hash:label, decimal */
tmp.len = p-tmp.s;
if( str2int( &tmp, &hash_index)!=0 )
return init_mi_error(400,MI_SSTR("Invalid index in old trans_id"));

tmp.s = p+1;
tmp.len = (trans_id.s+trans_id.len) - tmp.s;
if( str2int( &tmp, &hash_label)!=0 )
return init_mi_error(400,MI_SSTR("Invalid label in old trans_id"));
} else {
p = memchr( tmp.s, '.', tmp.len);
if ( p==NULL)
return init_mi_error(400, MI_SSTR("Invalid trans_id"));
/* new format ID label.hash, reversed hexa */
tmp.len = p-tmp.s;
if( reverse_hex2int( tmp.s, tmp.len, &hash_label)!=0 )
return init_mi_error(400, MI_SSTR("Invalid label in trans_id"));

tmp.s = p+1;
tmp.len = (trans_id.s+trans_id.len) - tmp.s;
if( reverse_hex2int( tmp.s, tmp.len, &hash_index)!=0 )
return init_mi_error(400,MI_SSTR("Invalid label in old trans_id"));
}

tmp.s = p+1;
tmp.len = (trans_id.s+trans_id.len) - tmp.s;
if( str2int( &tmp, &hash_label)!=0 )
return init_mi_error(400, MI_SSTR("Invalid label in trans_id"));

if( t_lookup_ident( &trans, hash_index, hash_label)<0 )
return init_mi_error(404, MI_SSTR("Transaction not found"));
Expand Down

0 comments on commit b8bb444

Please sign in to comment.