📄 x5334.htm
字号:
<HTML
><HEAD
><TITLE
>The IQ Namespaces</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 Namespaces"
HREF="c5281.htm"><LINK
REL="PREVIOUS"
TITLE="Namespace usage"
HREF="x5295.htm"><LINK
REL="NEXT"
TITLE="The X Namespaces"
HREF="x6079.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="x5295.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5a. Jabber Namespaces</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x6079.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-5A-SECT-2"
>The IQ Namespaces</A
></H1
><P
>The namespaces that qualify attachments to
<TT
CLASS="LITERAL"
><iq/></TT
> elements are many and
varied. After all, you could say that the raison d'etre of this
request/response mechanism is to exchange structured information—and
what better way to define that information than with namespaces?</P
><P
>This section looks briefly at each of the IQ namespaces in turn. Some of them
will be covered in more detail in later Chapters, as they will be used
in examples that appear later in the book.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5A-SECT-2.1"
><TT
CLASS="LITERAL"
>jabber:iq:agent</TT
></A
></H2
><P
>The <TT
CLASS="LITERAL"
>jabber:iq:agent</TT
> namespace is used
to request and return information on an <I
CLASS="EMPHASIS"
>agent</I
>. An agent is a service
running on a Jabber server, and it has a JID. To find out what features
the particular agent offers, an info-request
(an <TT
CLASS="LITERAL"
><iq/></TT
> <TT
CLASS="LITERAL"
>get</TT
> request) can be made
using this namespace:</P
><P
><PRE
CLASS="SCREEN"
>SEND: <iq type='get' to='yak/groups'>
<query xmlns='<TT
CLASS="USERINPUT"
><B
>jabber:iq:agent</B
></TT
>'/>
</iq></PRE
></P
><P
>Here, a request for features is being made of the agent with the JID
<TT
CLASS="LITERAL"
>yak/groups</TT
>, which is the standard
name for the “Shared Groups” service. The JID here is composed of a hostname
(<TT
CLASS="LITERAL"
>yak</TT
>) and a resource
(<TT
CLASS="LITERAL"
>groups</TT
>).</P
><P
>The response looks like this:</P
><P
><PRE
CLASS="SCREEN"
>RECV: <iq type='result' to='dj@yak/Work' from='yak/groups'>
<query xmlns='<TT
CLASS="USERINPUT"
><B
>jabber:iq:agent</B
></TT
>'>
<name>Jabber Server at yak</name>
<url>http://yak</url>
<service>jabber</service>
<register/>
</query>
</iq></PRE
></P
><P
>In reality, although the agent or service itself is specified as the
recipient of the query, it is often a centralized mechanism
that responds on behalf of the agent if the agent itself doesn't or
can't respond.
<A
NAME="MODAGENTS"
HREF="#FTN.MODAGENTS"
>[1]</A
>
This means that the results of the query might not be
as helpful as you might expect. The only detail in the response shown
here that might be of some use is the <TT
CLASS="LITERAL"
><register/></TT
> tag, but that's actually misleading as it's picked up from the general
registration capabilities configuration and not anything particular to
the JUD.</P
><P
>The main reason for this is actually also the answer to a question you might
have right now: "How do I know which agent JIDs I can query on a particular
Jabber server?" Indeed. It's very hit and miss to pick agent JIDs at
random. The <TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> (plural)
namespace defines a <I
CLASS="EMPHASIS"
>list</I
> of agents. Usually what
happens is that a query is made using the
<TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> namespace, and then further
detail is requested with the <TT
CLASS="LITERAL"
>jabber:iq:agent</TT
>
for a particular agent. However:</P
><P
></P
><UL
><LI
><P
>The general information for both queries
comes from the same place in the Jabber server configuration.</P
></LI
><LI
><P
>That place is the <TT
CLASS="LITERAL"
><agents/></TT
>
tag inside the JSM custom configuration…and is deprecated in favor of
the <TT
CLASS="LITERAL"
><browse/></TT
> tag.</P
></LI
></UL
><P
>The <TT
CLASS="LITERAL"
>jabber:iq:agent</TT
>-based agent facility query is slowly but surely being replaced by the
more generic but more powerful
<TT
CLASS="LITERAL"
>jabber:iq:browse</TT
> mechanism (which is
directly related to the <TT
CLASS="LITERAL"
><browse/></TT
>
configuration area of the JSM). That said, it is still supported for
compatibility reasons; many Jabber clients still use the
<TT
CLASS="LITERAL"
>jabber:iq:agent</TT
>
and <TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> namespaces in calls to
discover services on the server. See
<A
HREF="x5334.htm#JABTDG-CH-5A-SECT-2.5"
>the section called <I
><TT
CLASS="LITERAL"
>jabber:iq:browse</TT
></I
></A
> for more details on the
<TT
CLASS="LITERAL"
>jabber:iq:browse</TT
> mechanism.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5A-SECT-2.2"
><TT
CLASS="LITERAL"
>jabber:iq:agents</TT
></A
></H2
><P
>The <TT
CLASS="LITERAL"
>jabber:iq:agent</TT
> namespace is used in a query of an
individual Jabber agent, or service.
Likewise, the <TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> namespace is used in a query to
retrieve a <I
CLASS="EMPHASIS"
>list</I
> of these agents.</P
><P
>As mentioned in the description for the
<TT
CLASS="LITERAL"
>jabber:iq:agent</TT
> namespace, the
Jabber server configuration (in the JSM custom configuration
section) in earlier releases contained an <TT
CLASS="LITERAL"
><agents/></TT
> tag, which was used to
list the agents that were available on the Jabber server. The listing
looked like this:</P
><P
><PRE
CLASS="SCREEN"
><agents>
<!-- Note: this <agents/> listing is not used in 1.4.1 -->
<agent jid='users.jabber.org'>
<name>Jabber User Directory</name>
<description>
You may register and create a public searchable profile,
and search for other registered Jabber users.
</description>
<service>jud</service>
<register/>
<search/>
</agent>
<agent jid='...'>
...
</agent>
...
</agents></PRE
></P
><P
>The <TT
CLASS="LITERAL"
><agents/></TT
> listing has now
been superseded by the <TT
CLASS="LITERAL"
><browse/></TT
>
tag. In fact, when responding to
<TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> <I
CLASS="EMPHASIS"
>and</I
>
<TT
CLASS="LITERAL"
>jabber:iq:browse</TT
> queries, the Jabber server
itself will refer to the same
<TT
CLASS="LITERAL"
><browse/></TT
> listing in both cases.
Here's an example of a response to a <TT
CLASS="LITERAL"
>jabber:iq:agents</TT
>
query:</P
><P
><PRE
CLASS="SCREEN"
>RECV: <iq type='result' to='dj@yak/laptop' from='yak' id='agents'>
<query xmlns='jabber:iq:agents'>
<agent jid='users.jabber.org'>
<name>Jabber User Directory</name>
<service>jud</service>
<register/>
<search/>
</agent>
</query>
</iq></PRE
></P
><P
>We can see that this response pretty much reflects the information in
the <TT
CLASS="LITERAL"
><agents/></TT
> configuration.</P
><P
>For more details on how this differs in response to a
<TT
CLASS="LITERAL"
>jabber:iq:browse</TT
> query,
see <A
HREF="x5334.htm#JABTDG-CH-5A-SECT-2.5"
>the section called <I
><TT
CLASS="LITERAL"
>jabber:iq:browse</TT
></I
></A
>.</P
><P
>Further examples of <TT
CLASS="LITERAL"
>jabber:iq:agents</TT
> usage can be
found in <A
HREF="x9016.htm"
>the section called <I
>RSS punter</I
> in Chapter 8</A
>.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5A-SECT-2.3"
><TT
CLASS="LITERAL"
>jabber:iq:auth</TT
></A
></H2
><P
>The <TT
CLASS="LITERAL"
>jabber:iq:auth</TT
> namespace is used to
qualify a structured authentication procedure between client and server.</P
><P
>Details of authentication are covered in <A
HREF="c6313.htm"
>Chapter 6</A
>;
however, here we will look at the simplest authentication conversation
between client and server. In this example, the client sends a username
and password, and the server responds by sending a “successful”
response, acknowledging the user's credentials, thus creating
a session for that user.</P
><P
><PRE
CLASS="SCREEN"
>SEND: <iq type='set' id='auth0'>
<query xmlns='<TT
CLASS="USERINPUT"
><B
>jabber:iq:auth</B
></TT
>'>
<username>sabine</username>
<password>geheimnis</password>
<resource>WinJab</resource>
</query>
</iq>
RECV: <iq type='result' id='auth0'/></PRE
></P
><P
>In this authentication procedure, the name of the query
subelement containing the <TT
CLASS="LITERAL"
>xmlns</TT
>
attribute <I
CLASS="EMPHASIS"
>must</I
> be <TT
CLASS="LITERAL"
>query</TT
>. This is an exception
to the rule mentioned in the previous section, which stated that the
name of the tag was irrelevant.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5A-SECT-2.4"
><TT
CLASS="LITERAL"
>jabber:iq:autoupdate</TT
></A
></H2
><P
>The “Update Info Request” configuration description in
<A
HREF="x1740.htm#JABTDG-CH-4-SECT-4.3.1.3.6"
>the section called <I
>Update Info Request</I
> in Chapter 4</A
>
describes a mechanism for Jabber servers
to query a software version information repository to find
out about new versions of the server.
<A
NAME="AEN5432"
HREF="#FTN.AEN5432"
>[2]</A
>
This version information repository that responds to queries
is also known as the “Auto-Update” service.</P
><P
>Not only can servers request software update information, but
clients can too. The procedure is the same in both cases, and
involves the <TT
CLASS="LITERAL"
>jabber:iq:autoupdate</TT
> and
<TT
CLASS="LITERAL"
>jabber:x:autoupdate</TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -