由于项目中需要改造openfire添加好友流程,所以梳理了一份报文和表字段流程关系:
从Presence的Type说起
unavailable, 下线
subscribe, 订阅
subscribed, 同意订阅
unsubscribe, 取消订阅
unsubscribed, 拒绝订阅
probe,探测
error;错误
说明:用户添加删除好友是发送Presence包
1.2 说说RosterItem中和订阅相关的枚举
SubType
-1:删除好友关系
0:没建立关系(可能存在没有接受的订阅)
1:有发送订阅,并且被同意订阅,单向好友关系,和to对应
2:有收到订阅,订阅同意了订阅,单向好友关系,和from对应
3:双方互为好友,双向互为好友
AskType
-1:没有发送订阅请求
0:发送订阅好友请求,等待对方接受请求
1:发送取消订阅好友请求
RecvType
-1:没有接受到订阅请求
1: 有接受到订阅请求,还没有接受
2: 有接受到取消订阅请求
Sub(订阅)
remove -1:发送删除用户请求
none 0:用户没有建立好友关系
to 1:发送订阅请求且请求被接受了
from 2:接受好友订阅的请求
both 3:双方互为好友
Ask(是否有发送订阅请求)
"" -1:没有发送好友请求
subscribe 0:发送了好友订阅请求但是没得到回复
unsubscribe 1:发送了取消订阅好友的请求
Rec(是否有接受订阅请求)
"" -1:没有收到好友订阅请求
sub 1:收到好友的订阅请求但没回复
unsub 2:收到好友的取消订阅请求
1.3 再说ofroster表(RosterItem对象对应)
一、单向添加好友:test10单向添加好友test07:
(1)test10发起添加test07的请求:
C2S - RECV (1110016): <iq id="eW4LV-73" type="set"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07"><group>Friends</group></item></query></iq>
C2S - SENT (1110016): <iq type="set" id="89-75" to="test10@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07" subscription="none"><group>Friends</group></item></query></iq>
C2S - SENT (1110016): <iq type="result" id="eW4LV-73" to="test10@cn.hopwow.com/Spark 2.6.3"/>
C2S - RECV (1110016): <presence id="eW4LV-74" to="test07@cn.hopwow.com" type="subscribe"></presence>
C2S - SENT (1110016): <iq type="set" id="826-76" to="test10@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07" ask="subscribe" subscription="none"><group>Friends</group></item></query></iq>
C2S - SENT (25130001): <presence id="eW4LV-74" to="test07@cn.hopwow.com" type="subscribe" from="test10@cn.hopwow.com"/>
(2)test07接受test10的请求但是不添加自己到test10的好友列表中:
C2S - RECV (25130001): <presence id="by51z-57" to="test10@cn.hopwow.com" type="subscribed"></presence>
C2S - SENT (1110016): <iq type="set" id="373-79" to="test10@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07" subscription="to"><group>Friends</group></item></query></iq>
告知test10,test10对应test07的好友请求状态变为to
C2S - SENT (1110016): <presence id="by51z-57" to="test10@cn.hopwow.com" type="subscribed" from="test07@cn.hopwow.com"/>
C2S - SENT (1110016): <presence id="by51z-8" from="test07@cn.hopwow.com/Spark 2.6.3" to="test10@cn.hopwow.com/Spark 2.6.3"><status>在线</status><priority>1</priority></presence>
C2S - SENT (25130001): <iq type="set" id="150-78" to="test07@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test10@cn.hopwow.com" name="" subscription="from"/></query></iq>
告知test07,test07对应test10的好友请求状态变为from
C2S - SENT (25130001): <presence id="eW4LV-11" from="test10@cn.hopwow.com/Spark 2.6.3" to="test07@cn.hopwow.com/Spark 2.6.3"><status>在线</status><priority>1</priority></presence>
(3)test07反向添加test10为好友:
C2S - RECV (25130001): <iq id="by51z-58" type="set"><query xmlns="jabber:iq:roster"><item jid="test10@cn.hopwow.com" name="test10"><group>Friends</group></item></query></iq>
C2S - SENT (25130001): <iq type="set" id="777-80" to="test07@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test10@cn.hopwow.com" name="test10" subscription="from"><group>Friends</group></item></query></iq>
告知test07,test07对应test10的好友请求状态为from
C2S - SENT (25130001): <iq type="result" id="by51z-58" to="test07@cn.hopwow.com/Spark 2.6.3"/>
C2S - RECV (25130001): <presence id="by51z-59" to="test10@cn.hopwow.com" type="subscribe"></presence> (服务器接收到test07发送给test10的presence,要求转发)
C2S - SENT (1110016): <iq type="set" id="975-82" to="test10@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07" subscription="to"><group>Friends</group></item></query></iq>
告知test10,test10对应test07的好友请求状态为to
C2S - SENT (25130001): <iq type="set" id="236-81" to="test07@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test10@cn.hopwow.com" name="test10" ask="subscribe" subscription="from"><group>Friends</group></item></query></iq>
告知test07,test07对应test10的好友请求状态为from
C2S - SENT (1110016): <presence id="by51z-59" to="test10@cn.hopwow.com" type="subscribe" from="test07@cn.hopwow.com"/> (服务器发送给test10的presence,响应上面要求转发的presence,触发test10发送给test07的presence)
C2S - RECV (1110016): <presence id="eW4LV-75" to="test07@cn.hopwow.com" type="subscribed"></presence> (服务器接收到test10发送给test07的presence要求转发,如果当前test10离线,服务器将接收不到此presence,也就不会触发下面变为both的报文)
C2S - SENT (25130001): <iq type="set" id="773-84" to="test07@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test10@cn.hopwow.com" name="test10" subscription="both"><group>Friends</group></item></query></iq>
告知test07,test07对应test10的好友请求状态为both
C2S - SENT (25130001): <presence id="eW4LV-75" to="test07@cn.hopwow.com" type="subscribed" from="test10@cn.hopwow.com"/>(服务器发送给test07的presence,响应上面要求转发的presence)
C2S - SENT (25130001): <presence id="eW4LV-11" from="test10@cn.hopwow.com/Spark 2.6.3" to="test07@cn.hopwow.com/Spark 2.6.3"><status>在线</status><priority>1</priority></presence>
C2S - SENT (1110016): <iq type="set" id="663-83" to="test10@cn.hopwow.com/Spark 2.6.3"><query xmlns="jabber:iq:roster"><item jid="test07@cn.hopwow.com" name="test07" subscription="both"><group>Friends</group></item></query></iq>
告知test10,test10对应test07的好友请求状态为both
C2S - SENT (1110016): <presence id="by51z-8" from="test07@cn.hopwow.com/Spark 2.6.3" to="test10@cn.hopwow.com/Spark 2.6.3"><status>在线</status><priority>1</priority></presence>
转载地址http://blog.sina.com.cn/s/blog_6bd8bbe001019fec.html