~singpolyma/biboumi

de7b3503a47ea7d5a6177359f6c799c2dd5e586e — Florent Le Coz 10 years ago b71547a
Jidprep also handles the resource part
2 files changed, 24 insertions(+), 4 deletions(-)

M src/test.cpp
M src/xmpp/jid.cpp
M src/test.cpp => src/test.cpp +8 -3
@@ 161,10 161,15 @@ int main()
  assert(jid2.domain == "ツ.coucou");
  assert(jid2.resource == "coucou@coucou/coucou");

  // Nodeprep
  const std::string& badjid("~louiz@EpiK-7D9D1FDE.poez.io");
  // Jidprep
  const std::string& badjid("~zigougou@EpiK-7D9D1FDE.poez.io/Boujour/coucou/slt");
  const std::string correctjid = jidprep(badjid);
  assert(correctjid == "~louiz@epik-7d9d1fde.poez.io");
  assert(correctjid == "~zigougou@epik-7d9d1fde.poez.io/Boujour/coucou/slt");

  const std::string& badjid2("Zigougou@poez.io");
  const std::string correctjid2 = jidprep(badjid2);
  std::cout << correctjid2 << std::endl;
  assert(correctjid2 == "zigougou@poez.io");

  /**
   * Config

M src/xmpp/jid.cpp => src/xmpp/jid.cpp +16 -1
@@ 59,7 59,22 @@ std::string jidprep(const std::string& original)
    return "";
  }

  return std::string(local) + "@" + domain;
  // If there is no resource, stop here
  if (jid.resource.empty())
    return std::string(local) + "@" + domain;

  // Otherwise, also process the resource part
  char resource[max_jid_part_len] = {};
  memcpy(resource, jid.resource.data(), jid.resource.size());
  rc = static_cast<Stringprep_rc>(::stringprep(resource, max_jid_part_len,
       static_cast<Stringprep_profile_flags>(0), stringprep_xmpp_resourceprep));
  if (rc != STRINGPREP_OK)
    {
      log_error(error_msg + stringprep_strerror(rc));
      return "";
    }
  return std::string(local) + "@" + domain + "/" + resource;

#else
  (void)original;
  return "";