📄 x3625.htm
字号:
<HTML
><HEAD
><TITLE
>Jabber Identifiers</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Jabber Technology Basics"
HREF="c3612.htm"><LINK
REL="PREVIOUS"
TITLE="Jabber Technology Basics"
HREF="c3612.htm"><LINK
REL="NEXT"
TITLE="Resources and Priority"
HREF="x3795.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c3612.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Jabber Technology Basics</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x3795.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-5-SECT-5.1"
>Jabber Identifiers</A
></H1
><P
>An entity is anything that can be addressed in Jabber. A server, a component,
a user connected with a client—these are all addressable entities.
Every entity is identifiable by a <I
CLASS="EMPHASIS"
>Jabber ID</I
>, or JID. These JIDs
give these entities their <I
CLASS="EMPHASIS"
>addressability</I
>.
This is what a typical JID looks like:</P
><P
><PRE
CLASS="SCREEN"
>qmacro@jabber.org/Laptop</PRE
></P
><P
>This JID represents a user, connected to Jabber on a particular client.
We can look at this JID in a more abstract way, by identifying its component parts:</P
><P
><PRE
CLASS="SCREEN"
>username@hostname/resource</PRE
></P
><P
>The <TT
CLASS="LITERAL"
>username</TT
> is separated from the
<TT
CLASS="LITERAL"
>hostname</TT
> with an <TT
CLASS="LITERAL"
>@</TT
> symbol, and the
<TT
CLASS="LITERAL"
>resource</TT
> is separated from the
<TT
CLASS="LITERAL"
>hostname</TT
> with a slash (<TT
CLASS="LITERAL"
>/</TT
>).</P
><P
>It's quite likely that the JIDs that you may have encountered so far are those
representing users' connections, such as the
<TT
CLASS="LITERAL"
>qmacro@jabber.org/Laptop</TT
> example above. This is not the
only sort of entity that JIDs are used to represent. As a Uniform Resource
Locator (URL) is fundamental to the HyperText Transport Protocol (HTTP), so
a JID is fundamental in Jabber. JIDs are used to represent not only users
connected to Jabber via their clients, but every single entity in the Jabber
universe that is to be addressed—in other words, that is to be the
potential recipient of a message. Before looking at the restrictions that
govern how a JID might be constructed (these restrictions are described in
<A
HREF="x3625.htm#JABTDG-CH-5-SECT-5.1.1"
>the section called <I
>Rules and Regulations</I
></A
>), let's first have a look at some
examples where a JID is employed to give entities their addressability:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>A Jabber server</DT
><DD
><P
>A Jabber server is identified by a JID which doesn't contain a
<TT
CLASS="LITERAL"
>username</TT
>. For basic addressing,
the JID is simply the <TT
CLASS="LITERAL"
>hostname</TT
>:</P
><P
><PRE
CLASS="SCREEN"
>jabber.org</PRE
></P
><P
>To address specific features of the server,
a <TT
CLASS="LITERAL"
>resource</TT
> is often specified and reflects
the feature being addressed:</P
><P
><PRE
CLASS="SCREEN"
>jabber.org/admin</PRE
></P
><P
>The JID <TT
CLASS="LITERAL"
>jabber.org/admin</TT
> is used by
server administrators at <I
CLASS="EMPHASIS"
>jabber.org</I
> to obtain a list of online users.</P
><P
>Administrators can send an announcement to all online users on the Jabber
server <TT
CLASS="LITERAL"
>yak</TT
> by sending a message to the
JID <TT
CLASS="LITERAL"
>yak/announce/online</TT
>.</P
><P
><PRE
CLASS="SCREEN"
>yak/announce/online</PRE
></P
><P
>In
this case, the resource is <TT
CLASS="LITERAL"
>announce/online</TT
>. The first slash in the JID is interpreted as the <I
CLASS="EMPHASIS"
>separator</I
>; the second slash is simply part of the <I
CLASS="EMPHASIS"
>resource name</I
>.</P
></DD
><DT
>Unique identification of Jabber software</DT
><DD
><P
>Jabber clients can make a request for information on new versions of
themselves by sending a special packet to an update server which
manages a software version database. The packet they send is a presence
packet (see later in this Chapter for an explanation of packet types) to a JID that takes this form:</P
><P
><PRE
CLASS="SCREEN"
>959967024@update.jabber.org/1.6.0.3</PRE
></P
><P
>In this case, the important part of the JID is the hostname—<TT
CLASS="LITERAL"
>update.jabber.org</TT
>—which is the Jabber server
where the presence packet is destined. The username
(<TT
CLASS="LITERAL"
>95996702</TT
>) is used to represent
the unique identification of the client software requesting version
information, and the resource
(<TT
CLASS="LITERAL"
>1.6.0.3</TT
>) is set to be the current
version of the client software.</P
></DD
><DT
>A conference room</DT
><DD
><P
>Jabber has a conferencing component that provides group chat facilities
akin to IRC. Where IRC has channels, the conferencing component offers
<I
CLASS="EMPHASIS"
>rooms</I
>. These rooms are addressed with JIDs in this
form:</P
><P
><PRE
CLASS="SCREEN"
>jdev@conference.jabber.org</PRE
></P
><P
>The room name is specified in the <TT
CLASS="LITERAL"
>username</TT
>
portion of the JID, and the <TT
CLASS="LITERAL"
>hostname</TT
>
reflects the address of the conference component.</P
></DD
><DT
>Browsing entities</DT
><DD
><P
>Browsing is a powerful <I
CLASS="EMPHASIS"
>hierarchical navigation</I
> feature in
Jabber. When a browse request is sent to an entity, that entity
may return various pieces of information which reflects its component
parts—how it's made up, what services it offers, what features it has,
and so on.</P
><P
>The browse request is addressed to the entity via its JID, and the component parts
that are returned in response are all identified with JIDs too. If we address a
browse request to the JID
<TT
CLASS="LITERAL"
>yak/admin</TT
>, we receive a list of online users. This is shown in
<A
HREF="x3625.htm#JABTDG-CH-5-EX-IQADMIN"
>Example 5-1</A
>.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-5-EX-IQADMIN"
></A
><P
><B
>Example 5-1. Querying the server <TT
CLASS="LITERAL"
>yak</TT
> for online users</B
></P
><P
><PRE
CLASS="SCREEN"
>SEND: <iq type='get' to='<TT
CLASS="USERINPUT"
><B
>yak/admin</B
></TT
>'>
<query xmlns='jabber:iq:browse'/>
</iq>
RECV: <iq type='result' to='dj@yak/console' from='<TT
CLASS="USERINPUT"
><B
>yak/admin</B
></TT
>'>
<item name='Online Users (seconds, sent, received)'
xmlns='jabber:iq:browse' jid='<TT
CLASS="USERINPUT"
><B
>yak/admin</B
></TT
>'>
<user name='dj (548, 18, 15)' jid='<TT
CLASS="USERINPUT"
><B
>dj@yak</B
></TT
>'/>
<user name='john (535, 11, 13)' jid='<TT
CLASS="USERINPUT"
><B
>john@yak</B
></TT
>'/>
<user name='jim (488, 15, 17)' jid='<TT
CLASS="USERINPUT"
><B
>jim@yak</B
></TT
>'/>
</item>
</iq></PRE
></P
></DIV
><P
>The JID <TT
CLASS="LITERAL"
>yak/admin</TT
> represents an administrative function in the
Jabber server <TT
CLASS="LITERAL"
>yak</TT
>; it <I
CLASS="EMPHASIS"
>identifies</I
> the
place—the service entry point—by Jabber address, where this
information can be retrieved.</P
><P
><A
HREF="x3625.htm#JABTDG-CH-5-EX-IQADMIN"
>Example 5-1</A
> shows how pervasive the JID is as a
mechanism for identification within
Jabber. How we might use the information returned to us is not relevant at this point;
the key thing to note is that the hooks used in conversations to jump from one point
to another, to refer
to other entities—services, users, transports, call-hooks into a server to
obtain specific information—take the form of JIDs. Each one of the highlighted
attribute values in the example is a JID.
<A
NAME="AEN3715"
HREF="#FTN.AEN3715"
>[1]</A
></P
><P
>Taking another example from the conferencing area, JIDs are used to
represent those present in a room in an abstracted way. Each room
participant has an identity specific to that room:</P
><P
><PRE
CLASS="SCREEN"
>jdev@conference.jabber.org/bd9505f766f98bd559d4c2d8a9d5ae78e3a7bbf5</PRE
></P
><P
>As before, the room itself is represented by the
<TT
CLASS="LITERAL"
>username@hostname</TT
> parts of the JID—in this case it's the Jabber Developers room hosted on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -