三、Jabber核心协议(XMPP Core :RFC3920)
1、 /XML Stanza
XML Stream
Stream :以
<stream>
开始,至
</stream>
结束,在整个生命周期中,可以包含任意数量的
XML
元素
Stanza
:
Stream
中结构化的
XML
片断
整个流看起来大致如下:
|--------------------|
| <stream> |
|--------------------|
| <presence> |
| <show/> |
| </presence> |
|--------------------|
| <message to='foo'> |
| <body/> |
| </message> |
|--------------------|
| <iq to='bar'> |
| <query/> |
| </iq> |
|--------------------|
| ... |
|--------------------|
| </stream> |
|--------------------|
| <body/> |
| </message> |
|--------------------|
| <iq to='bar'> |
| <query/> |
| </iq> |
|--------------------|
| ... |
|--------------------|
| </stream> |
|--------------------|
2、
Stream Attributes
to :用于发起方stream 中(
initial stream),表明接收者,响应Stream不能包含to,如果有则被忽略;
from :用于响应Stream中(
response stream),表明接收者,发起方Stream不能包含from,如果有则被忽略;
id
:用于响应
Stream
中,唯一性标识,出于安全性考虑,建议随机生成;
xml:lang
:缺省语言
version
:版本号,通常为
1.0
3、
Stream Error:
当遇到有stream级别的错误时,需要发送一个<error/>tag,具体语法如下:
<stream:error>
<defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'
xml:lang='langcode'>
OPTIONAL descriptive text
</text>
[OPTIONAL application-specific condition element]
</stream:error>
defined-condition举例:
<xml-not-well-formed/>
、
<not-authorized/>
、
<bad-format/>
、
<host-unknown/>
等
当一个Stream被发起以后,需要通过TLS来保证连接的安全性,下面是一个从客户端到服务器的例子。
Step 1: Client initiates stream to server:
<stream:stream
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'
to='example.com'
version='1.0'>
Step 2: Server responds by sending a stream tag to client:
<stream:stream
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'
id='c2s_123'
from='example.com'
version='1.0'>
Step 3: Server sends the STARTTLS extension to client along with authentication me