Datasheet
10
CHAPTER 1 GettinG to Know XMPP
Common Attributes
All three stanzas support a set of common attributes. Whether they are attributes of <presence>,
<message>, or <iq> elements, the following attributes all mean the same thing.
from
Stanzas almost always have a from attribute. This attribute identifies the JID of the stanza’s origin.
Setting the
from attribute on outgoing stanzas is not recommended; the server adds the correct from
attribute to all stanzas as they pass through, and if you set the
from attribute incorrectly, the server
may reject your stanza altogether.
If the
from attribute is missing on a received stanza in a client-to-server stream, this is interpreted
to mean that the stanza originated from the server itself. In the server-to-server protocol, a missing
from attribute is an error.
Note that the example stanzas in this book often include the
from attribute. This is done for clarity
and disambiguation.
to
XMPP servers route your stanzas to the JID supplied in the to attribute. Similarly to the from attri-
bute, if the
to attribute is missing in a client-to-server stream, the server assumes it is a message
intended for the server itself. It is recommended that you omit the
to attribute when you address the
server itself.
If the JID specified in the
to attribute is a user, the server potentially handles the stanza on the user’s
behalf. If the destination is a bare JID, the server handles the stanza. This behavior is different for the
three stanza types, and is explained alongside each type. If a full JID is specified as the destination,
the server routes the stanza directly to the user.
type
The type attribute specifies the specific kind of <presence>, <message>, or <iq> stanza. Each of
the three basic stanzas has several possible values for the
type attribute, and these are explained
when each stanza is covered in detail.
All three stanzas may have their
type attribute set to a value of error. This indicates that the stanza
is an error response to a received stanza of the same kind. You must not respond to a stanza with an
error type, to avoid feedback loops on the network.
id
Stanzas may be given an id attribute to aid in identifying responses. For <iq> stanzas, this attribute
is required, but for the other two it is optional. If a stanza is generated in reply to a stanza with an
id attribute, the reply stanza must contain an id attribute with the same value.
The
id attribute needs to be unique enough that the stanza’s sender can use it to disambiguate
responses. Often, it is easiest just to make these unique in a given stream to avoid any ambiguity.
Reply stanzas for
<message> and <presence> stanzas are generally limited to reporting errors. Reply
stanzas for
<iq> can signal successful operations, acknowledge a command, or return requested
40718c01.indd 10 11/30/09 8:23:49 PM