Class: Blather::JID
Overview
Jabber ID or JID
See [RFC 3920 Section 3 - Addressing](xmpp.org/rfcs/rfc3920.html#addressing)
An entity is anything that can be considered a network endpoint (i.e., an ID on the network) and that can communicate using XMPP. All such entities are uniquely addressable in a form that is consistent with RFC 2396 [URI]. For historical reasons, the address of an XMPP entity is called a Jabber Identifier or JID. A valid JID contains a set of ordered elements formed of a domain identifier, node identifier, and resource identifier.
The syntax for a JID is defined below using the Augmented Backus-Naur Form as defined in [ABNF]. (The IPv4address and IPv6address rules are defined in Appendix B of [IPv6]; the allowable character sequences that conform to the node rule are defined by the Nodeprep profile of [STRINGPREP] as documented in Appendix A of this memo; the allowable character sequences that conform to the resource rule are defined by the Resourceprep profile of [STRINGPREP] as documented in Appendix B of this memo; and the sub-domain rule makes reference to the concept of an internationalized domain label as described in [IDNA].)
jid = [ node "@" ] domain [ "/" resource ]
domain = fqdn / address-literal
fqdn = (sub-domain 1*("." sub-domain))
sub-domain = (internationalized domain label)
address-literal = IPv4address / IPv6address
All JIDs are based on the foregoing structure. The most common use of this structure is to identify an instant messaging user, the server to which the user connects, and the user’s connected resource (e.g., a specific client) in the form of <user@host/resource>. However, node types other than clients are possible; for example, a specific chat room offered by a multi-user chat service could be addressed as <room@service> (where “room” is the name of the chat room and “service” is the hostname of the multi-user chat service) and a specific occupant of such a room could be addressed as <room@service/nick> (where “nick” is the occupant’s room nickname). Many other JID types are possible (e.g., <domain/resource> could be a server-side script or service).
Each allowable portion of a JID (node identifier, domain identifier, and resource identifier) MUST NOT be more than 1023 bytes in length, resulting in a maximum total size (including the ‘@’ and ‘/’ separators) of 3071 bytes.
Constant Summary collapse
- PATTERN =
/^(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?$/.freeze
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Fixnum<-1, 0, 1>
Compare two JIDs, helpful for sorting etc.
-
#initialize(node, domain = nil, resource = nil) ⇒ Blather::JID
constructor
Create a new JID object.
-
#strip! ⇒ Blather::JID
Removes the resource (sets it to nil).
-
#stripped ⇒ Blather::JID
Returns a new JID with resource removed.
-
#stripped? ⇒ true, false
Test if JID is stripped.
-
#to_s ⇒ String
Turn the JID into a string.
Constructor Details
#initialize(jid) ⇒ Blather::JID #initialize(jid) ⇒ Blather::JID #initialize(node, domain = nil, resource = nil) ⇒ Blather::JID
Create a new JID object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/blather/jid.rb', line 75 def initialize(node, domain = nil, resource = nil) @resource = resource @domain = domain @node = node if @domain.nil? && @resource.nil? @node, @domain, @resource = @node.to_s.scan(PATTERN).first end @node.downcase! if @node @domain.downcase! if @domain raise ArgumentError, 'Node too long' if (@node || '').length > 1023 raise ArgumentError, 'Domain too long' if (@domain || '').length > 1023 raise ArgumentError, 'Resource too long' if (@resource || '').length > 1023 end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
51 52 53 |
# File 'lib/blather/jid.rb', line 51 def domain @domain end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
51 52 53 |
# File 'lib/blather/jid.rb', line 51 def node @node end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
51 52 53 |
# File 'lib/blather/jid.rb', line 51 def resource @resource end |
Class Method Details
.new(node, domain = nil, resource = nil) ⇒ Object
55 56 57 |
# File 'lib/blather/jid.rb', line 55 def self.new(node, domain = nil, resource = nil) node.is_a?(JID) ? node : super end |
Instance Method Details
#<=>(other) ⇒ Fixnum<-1, 0, 1>
Compare two JIDs, helpful for sorting etc.
String representations are compared, see JID#to_s
129 130 131 |
# File 'lib/blather/jid.rb', line 129 def <=>(other) to_s <=> other.to_s end |
#strip! ⇒ Blather::JID
Removes the resource (sets it to nil)
118 119 120 121 |
# File 'lib/blather/jid.rb', line 118 def strip! @resource = nil self end |
#stripped ⇒ Blather::JID
Returns a new JID with resource removed.
111 112 113 |
# File 'lib/blather/jid.rb', line 111 def stripped dup.strip! end |
#stripped? ⇒ true, false
Test if JID is stripped
137 138 139 |
# File 'lib/blather/jid.rb', line 137 def stripped? @resource.nil? end |
#to_s ⇒ String
Turn the JID into a string
-
“”
-
“domain”
-
“node@domain”
-
“domain/resource”
-
“node@domain/resource”
101 102 103 104 105 106 |
# File 'lib/blather/jid.rb', line 101 def to_s s = @domain s = "#{@node}@#{s}" if @node s = "#{s}/#{@resource}" if @resource s end |