Exampple.Xmpp.Jid (exampple v0.10.6)
JID stands for Jabber Identification. This is de Identification the XMPP network provide for all of the users, servers and components which can be connected and reachable inside of the XMPP protocol.
This module is a facility to handle JID data helping to parse it and
convert it again to string. Provides the ~j
sigil which help us to
define JIDs in the way ~j[user@domain/res]
and be converted into a
JID structure.
Link to this section Summary
Types
JID.t
represents the structure in use to handle the identification
for a user, component or server inside of a XMPP network. It is formed
by the node
, server
and resource
.
Functions
A boolean function to determine if the jid
passed as parameter is
a full JID or not. The parameter could be in binary format or as
a JID structure.
Creates a new JID passing node
, server
and resource
data.
Parse a binary to a jid
struct.
This sigil help us to define JIDs using a simple format and get
their struct representation from binary
.
Converts jid
to a bare JID in binary format.
Link to this section Types
Link to this section Functions
is_full?(jid)
Specs
A boolean function to determine if the jid
passed as parameter is
a full JID or not. The parameter could be in binary format or as
a JID structure.
Remember that a full JID is a JID which has node, domain and resource. Actually is enough if the node is missing, but the resource should appears.
Examples:
iex> Exampple.Xmpp.Jid.is_full?("alice@example.com")
false
iex> Exampple.Xmpp.Jid.is_full?("comp.example.com/data")
true
iex> Exampple.Xmpp.Jid.is_full?("bob@example.com/res")
true
iex> Exampple.Xmpp.Jid.is_full?("/abc/xyz")
{:error, :enojid}
new(node, server, resource)
Specs
Creates a new JID passing node
, server
and resource
data.
Note that XMPP standard says the JID is case insensitive therefore, and to make easier the handle of comparisons, we put everything in downcase mode.
Examples:
iex> Exampple.Xmpp.Jid.new("foo", "bar", "baz")
%Exampple.Xmpp.Jid{node: "foo", server: "bar", resource: "baz", original: "foo@bar/baz"}
iex> Exampple.Xmpp.Jid.new("FOO", "BAR", "BAZ")
%Exampple.Xmpp.Jid{node: "foo", server: "bar", resource: "BAZ", original: "FOO@BAR/BAZ"}
parse(jid)
Specs
Parse a binary to a jid
struct.
Examples:
iex> Exampple.Xmpp.Jid.parse("alice@example.com/resource")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "resource", original: "alice@example.com/resource"}
iex> Exampple.Xmpp.Jid.parse("AlicE@Example.Com/Resource")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "Resource", original: "AlicE@Example.Com/Resource"}
iex> Exampple.Xmpp.Jid.parse("alice@example.com")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", original: "alice@example.com"}
iex> Exampple.Xmpp.Jid.parse("AlicE@Example.Com")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", original: "AlicE@Example.Com"}
iex> Exampple.Xmpp.Jid.parse("example.com/resource")
%Exampple.Xmpp.Jid{server: "example.com", resource: "resource", original: "example.com/resource"}
iex> Exampple.Xmpp.Jid.parse("Example.Com/Resource")
%Exampple.Xmpp.Jid{server: "example.com", resource: "Resource", original: "Example.Com/Resource"}
iex> Exampple.Xmpp.Jid.parse("example.com")
%Exampple.Xmpp.Jid{server: "example.com", original: "example.com"}
iex> Exampple.Xmpp.Jid.parse("Example.Com")
%Exampple.Xmpp.Jid{server: "example.com", original: "Example.Com"}
iex> Exampple.Xmpp.Jid.parse(nil)
nil
iex> Exampple.Xmpp.Jid.parse("")
""
iex> Exampple.Xmpp.Jid.parse("/example.com/resource")
{:error, :enojid}
sigil_j(binary, opts)
This sigil help us to define JIDs using a simple format and get
their struct representation from binary
.
Examples:
iex> import Exampple.Xmpp.Jid
iex> ~j[alice@example.com/ios]
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "ios", original: "alice@example.com/ios"}
to_bare(jid)
Specs
Converts jid
to a bare JID in binary format.
Examples: iex> Exampple.Xmpp.Jid.to_bare("alice@example.com") "alice@example.com"
iex> Exampple.Xmpp.Jid.to_bare("alice@example.com/resource") "alice@example.com"
iex> Exampple.Xmpp.Jid.to_bare("example.com") "example.com"
iex> Exampple.Xmpp.Jid.to_bare("example.com/resource") "example.com"