服务器IP检查

该规范定义了一个XMPP扩展, 让客户端能够发现其自己的外部IP地址.

Ejabberd实现模块: mod_sic

首先客户端发送一个IQ-get给服务器:

1
<iq type='get'
    from='root@x.hezhiqiang.info'
    id='id-1431053085377'
    xmlns='jabber:client'>
  <address xmlns='urn:xmpp:sic:0'/>
</iq>

服务器端响应一个IQ-resultXML片段, 包含一个<address>元素, 其中包含客户端的外部IP地址<ip>, 以及一个可选的<port>元素表示客户端外部IP所对应的端口

1
<iq from='root@x.hezhiqiang.info'
    to='root@x.hezhiqiang.info/1964144757143129898889436'
    id='id-1431053085377'
    type='result'>
  <address xmlns='urn:xmpp:sic:0'>192.168.8.104</address>
</iq>

判断XMPP服务器是否支持该协议扩展

1
<!--请求-->
<iq type='get' id='id-1431052837499'
    to='x.hezhiqiang.info'
    from='root@x.hezhiqiang.info'
    xml:lang='zh'
    xmlns='jabber:client'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
<!--响应-->
<iq from='x.hezhiqiang.info'
    to='root@x.hezhiqiang.info/1964144757143129898889436'
    id='id-1431052837499'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity category='pubsub' type='pep'/>
    <identity category='server' type='im' name='ejabberd'/>
    <x xmlns='jabber:x:data' type='result'>
      <field var='FORM_TYPE' type='hidden'>
        <value>http://jabber.org/network/serverinfo</value>
      </field>
    </x>
    <feature var='http://jabber.org/protocol/commands'/>
    <feature var='http://jabber.org/protocol/disco#info'/>
    <feature var='http://jabber.org/protocol/disco#items'/>
    <feature var='http://jabber.org/protocol/pubsub'/>
    <feature var='http://jabber.org/protocol/pubsub#access-authorize'/>
    <feature var='http://jabber.org/protocol/pubsub#access-open'/>
    <feature var='http://jabber.org/protocol/pubsub#access-presence'/>
    <feature var='http://jabber.org/protocol/pubsub#access-whitelist'/>
    <feature var='http://jabber.org/protocol/pubsub#auto-create'/>
    <feature var='http://jabber.org/protocol/pubsub#auto-subscribe'/>
    <feature var='http://jabber.org/protocol/pubsub#collections'/>
    <feature var='http://jabber.org/protocol/pubsub#config-node'/>
    <feature var='http://jabber.org/protocol/pubsub#create-and-configure'/>
    <feature var='http://jabber.org/protocol/pubsub#create-nodes'/>
    <feature var='http://jabber.org/protocol/pubsub#delete-items'/>
    <feature var='http://jabber.org/protocol/pubsub#delete-nodes'/>
    <feature var='http://jabber.org/protocol/pubsub#filtered-notifications'/>
    <feature var='http://jabber.org/protocol/pubsub#get-pending'/>
    <feature var='http://jabber.org/protocol/pubsub#instant-nodes'/>
    <feature var='http://jabber.org/protocol/pubsub#item-ids'/>
    <feature var='http://jabber.org/protocol/pubsub#last-published'/>
    <feature var='http://jabber.org/protocol/pubsub#manage-subscriptions'/>
    <feature var='http://jabber.org/protocol/pubsub#member-affiliation'/>
    <feature var='http://jabber.org/protocol/pubsub#modify-affiliations'/>
    <feature var='http://jabber.org/protocol/pubsub#multi-subscribe'/>
    <feature var='http://jabber.org/protocol/pubsub#outcast-affiliation'/>
    <feature var='http://jabber.org/protocol/pubsub#persistent-items'/>
    <feature var='http://jabber.org/protocol/pubsub#presence-notifications'/>
    <feature var='http://jabber.org/protocol/pubsub#presence-subscribe'/>
    <feature var='http://jabber.org/protocol/pubsub#publish'/>
    <feature var='http://jabber.org/protocol/pubsub#publish-only-affiliation'/>
    <feature var='http://jabber.org/protocol/pubsub#publisher-affiliation'/>
    <feature var='http://jabber.org/protocol/pubsub#purge-nodes'/>
    <feature var='http://jabber.org/protocol/pubsub#retract-items'/>
    <feature var='http://jabber.org/protocol/pubsub#retrieve-affiliations'/>
    <feature var='http://jabber.org/protocol/pubsub#retrieve-default'/>
    <feature var='http://jabber.org/protocol/pubsub#retrieve-items'/>
    <feature var='http://jabber.org/protocol/pubsub#retrieve-subscriptions'/>
    <feature var='http://jabber.org/protocol/pubsub#shim'/>
    <feature var='http://jabber.org/protocol/pubsub#subscribe'/>
    <feature var='http://jabber.org/protocol/pubsub#subscription-notifications'/>
    <feature var='http://jabber.org/protocol/pubsub#subscription-options'/>
    <feature var='http://jabber.org/protocol/stats'/>
    <feature var='iq'/>
    <feature var='jabber:iq:last'/>
    <feature var='jabber:iq:privacy'/>
    <feature var='jabber:iq:private'/>
    <feature var='jabber:iq:register'/>
    <feature var='jabber:iq:roster'/>
    <feature var='jabber:iq:time'/>
    <feature var='jabber:iq:version'/>
    <feature var='msgoffline'/>
    <feature var='presence'/>
    <feature var='urn:xmpp:blocking'/>
    <feature var='urn:xmpp:carbons:1'/>
    <feature var='urn:xmpp:carbons:2'/>
    <feature var='urn:xmpp:ping'/>
    <feature var='urn:xmpp:sic:0'/>
    <feature var='urn:xmpp:time'/>
    <feature var='vcard-temp'/>
  </query>
</iq>

上述结果79行包含一个<feature var='urn:xmpp:sic:0'/>, 表示服务器支持该协议扩展, 我们需要解析上述服务器响应来判断是否包含<feature var='urn:xmpp:sic:0'/>元素,如果包含标识服务器支持. 否则不支持.