Jabber Identifier
Serves as a unique address for each user. Structurally similar to an email address, a JID comprises a username and a domain, separated by an "@" symbol—for example, vsevolod@dosy.app. This format ensures that every user on the XMPP network can be uniquely identified and contacted using their JID.
Understanding JID usage in the Whixp package
Using the Whixp package, you can easily generate a Jabber ID (JID) in Dart. For example:
final vsevolod = JabberID('vsevolod@dosy.app');
This creates a JabberID instance with the given Jabber address. The JabberID class also offers several built-in getters to access various parts of the JID, such as the node (user), domain, and resource. These methods make it easy to parse and utilize individual components of the JID in your projects.
Punycode and IDNA
Punycode is an encoding method used to convert Unicode characters into a format that can be represented using the ASCII character set. This is particularly useful for internationalized domain names (IDNs), which may contain non-ASCII characters. When a JID includes such characters, it must be converted to Punycode for proper handling in the protocol.
Internationalized Domain Name (IDNA) is the specification that allows the use of non-ASCII characters in domain names. When preparing a JID, any domain part containing non-ASCII characters should be converted to its Punycode representation to ensure seamless communication.
String preparation
String preparation involves several steps to ensure that the JID conforms to XMPP standards:
- Normalization: Normalize the string to a consistent format, which may include converting it to lowercase and removing any extraneous whitespace.
- Trimming: Remove any leading or trailing spaces from the JID components.
- Encoding: Encode special characters according to XMPP specifications, which may involve using UTF-8 encoding.
In the codebase of Whixp, there is a comprehensive list of characters that are explicitly prohibited in the domain part of a JID. Here's a breakdown of the types of characters included:
-
Control characters:
- ASCII characters ranging from
\x00to\x1Fare control characters that are not visible and serve special functions (e.g., line breaks, tabs). These characters should never appear in a domain name as they can interfere with proper parsing and communication. - The DEL character (
\x7F) is also excluded for similar reasons.
- ASCII characters ranging from
-
Whitespace characters:
- Specific whitespace characters such as tabs (
\t), new lines (\n), and carriage returns (\r) are forbidden in the domain part of a JID. The presence of these characters can cause issues in processing and interpreting the JID.
- Specific whitespace characters such as tabs (
-
Special Characters:
- The string includes various special characters such as spaces, punctuation marks, and symbols:
!"#$%&'()\*+,-./:;<=>?@[\]^\_{|}~ - These characters are typically reserved for specific syntactical functions in various contexts and may lead to ambiguities if included in a domain name.
- The string includes various special characters such as spaces, punctuation marks, and symbols:
The following profiles are recognized within the string preparation process:
- nodeprep
- nameprep
- resourceprep
- saslprep
- nodeprep-prohibit
These preparations map characters and disallow character categories according to RFC 3454.
JID Components
A JID consists of three main components:
- Node: The username or identifier before the "@" symbol (e.g., "vsevolod" in "vsevolod@dosy.app")
- Domain: The server domain after the "@" symbol (e.g., "dosy.app")
- Resource: An optional identifier after the "/" symbol that distinguishes multiple connections from the same user (e.g., "desktop" in "vsevolod@dosy.app/desktop")
Accessing JID Components
The JabberID class provides convenient getters to access these components:
final jid = JabberID('vsevolod@dosy.app/desktop');
print(jid.username); // "vsevolod"
print(jid.domain); // "dosy.app"
print(jid.resource); // "desktop"
print(jid.bare); // "vsevolod@dosy.app" (without resource)
print(jid.toString()); // "vsevolod@dosy.app/desktop" (full JID)
Bare JID vs Full JID
- Bare JID: Contains only the node and domain (e.g., "vsevolod@dosy.app"). Used to identify a user account.
- Full JID: Includes the resource identifier (e.g., "vsevolod@dosy.app/desktop"). Used to identify a specific connection or session.
When sending messages or presence updates, you typically use bare JIDs to address a user, while full JIDs are used to identify specific connections or resources.
JID Validation
Whixp automatically validates and normalizes JIDs according to XMPP specifications. Invalid characters are removed or transformed, and the JID is prepared according to the appropriate stringprep profiles. This ensures compatibility with XMPP servers and other clients.