From 83a33726ce33e700257f406a8bb0b28bb553b790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Tue, 1 Jul 2008 09:12:59 +0000 Subject: [PATCH] Add function short_bare_jid/1. SVN Revision: 1395 --- ChangeLog | 2 ++ src/jlib.erl | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e6197bc00..54deda3d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ exmpp_iq:error_without_original/2 and the new exmpp_jid:make_bare_jid/1. + * src/jlib.erl: Add function short_bare_jid/1. + 2008-06-30 Jean-Sébastien Pédron * src/Makefile.in: Remove the -I flag for exmpp includes; the diff --git a/src/jlib.erl b/src/jlib.erl index d6938c799..4a0fbcbfa 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -63,7 +63,8 @@ ip_to_list/1, from_old_jid/1, to_old_jid/1, - short_jid/1]). + short_jid/1, + short_bare_jid/1]). -include("jlib.hrl"). @@ -699,14 +700,14 @@ ip_to_list({A,B,C,D}) -> %% Empty fields are set to `undefined', not the empty string. from_old_jid(#jid{user = Node, resource = Resource, - luser = LNode, lresource = LResource} = JID) -> + luser = LNode, lresource = LResource} = JID) -> {Node1, LNode1} = case Node of - "" -> {undefined, undefined}; - _ -> {Node, LNode} + "" -> {undefined, undefined}; + _ -> {Node, LNode} end, {Resource1, LResource1} = case Resource of - "" -> {undefined, undefined}; - _ -> {Resource, LResource} + "" -> {undefined, undefined}; + _ -> {Resource, LResource} end, JID#jid{user = Node1, resource = Resource1, luser = LNode1, lresource = LResource1}. @@ -719,18 +720,22 @@ from_old_jid(#jid{user = Node, resource = Resource, %% Empty fields are set to the empty string, not `undefined'. to_old_jid(#jid{user = Node, resource = Resource, - luser = LNode, lresource = LResource} = JID) -> + luser = LNode, lresource = LResource} = JID) -> {Node1, LNode1} = case Node of - undefined -> {"", ""}; - _ -> {Node, LNode} + undefined -> {"", ""}; + _ -> {Node, LNode} end, {Resource1, LResource1} = case Resource of - undefined -> {"", ""}; - _ -> {Resource, LResource} + undefined -> {"", ""}; + _ -> {Resource, LResource} end, JID#jid{user = Node1, resource = Resource1, luser = LNode1, lresource = LResource1}. -short_jid(JID0) -> - JID = to_old_jid(JID0), - {JID#jid.luser, JID#jid.lserver, JID#jid.lresource}. +short_jid(JID) -> + JID1 = to_old_jid(JID), + {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource}. + +short_bare_jid(JID) -> + JID1 = to_old_jid(exmpp_jid:jid_to_bare_jid(JID)), + {JID1#jid.luser, JID1#jid.lserver, JID1#jid.lresource}.