# HG changeset patch # User Matthew Wild # Date 1663861431 -3600 # Node ID 023f21bfcc08d267ea119b0c4d2dc0bfb70e66c0 # Parent 904dde7be981602c7916e0d5696d5ff549d577af mod_sasl2_bind2: Generate resource from client tag if provided This follows the updated advice in the latest XEP-0386 proposal. diff -r 904dde7be981 -r 023f21bfcc08 mod_sasl2_bind2/mod_sasl2_bind2.lua --- a/mod_sasl2_bind2/mod_sasl2_bind2.lua Thu Sep 22 16:37:59 2022 +0100 +++ b/mod_sasl2_bind2/mod_sasl2_bind2.lua Thu Sep 22 16:43:51 2022 +0100 @@ -1,4 +1,5 @@ local base64 = require "util.encodings".base64; +local id = require "util.id"; local sha1 = require "util.hashes".sha1; local st = require "util.stanza"; @@ -23,11 +24,11 @@ local function do_bind(session, bind_request) local resource; - local client_id_tag = bind_request:get_child("client-id"); - local client_id = client_id_tag and client_id_tag:get_text() or session.client_id; - if client_id and client_id ~= "" then - local tag = client_id_tag and client_id_tag.attr.tag or "client"; - resource = ("%s~%s"):format(tag, base64.encode(sha1(client_id):sub(1, 9))); + local client_name_tag = bind_request:get_child_text("tag"); + if client_name_tag then + local client_id = session.client_id; + local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium(); + resource = ("%s~%s"):format(client_name_tag, tag_suffix); end local success, err_type, err, err_msg = sm_bind_resource(session, resource);