Fixe concurrent map read and map write for XMPP remote roster request.
This commit is contained in:
parent
7ad36a0321
commit
8a52613171
|
|
@ -34,7 +34,7 @@ type GatewayInfo struct {
|
||||||
XMPP_Out chan interface{}
|
XMPP_Out chan interface{}
|
||||||
xmpp_Connected_Client *XmppConnectedClient
|
xmpp_Connected_Client *XmppConnectedClient
|
||||||
DebugMessage bool
|
DebugMessage bool
|
||||||
XMPP_IQ_RemoteRoster_Request map[string]string
|
xmpp_IQ_RemoteRoster_Request *XmppRemoteRosterRequest
|
||||||
AllowEditRoster bool
|
AllowEditRoster bool
|
||||||
ChatstateNotificationData chan string
|
ChatstateNotificationData chan string
|
||||||
}
|
}
|
||||||
|
|
@ -49,6 +49,11 @@ type XmppConnectedClient struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type XmppRemoteRosterRequest struct {
|
||||||
|
request map[string]string
|
||||||
|
sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
type StatusSteamFriend struct {
|
type StatusSteamFriend struct {
|
||||||
XMPP_Status string
|
XMPP_Status string
|
||||||
XMPP_Type string
|
XMPP_Type string
|
||||||
|
|
@ -137,3 +142,25 @@ func (s *GatewayInfo) GetLenXmppConnectedClient() int {
|
||||||
defer s.xmpp_Connected_Client.RUnlock()
|
defer s.xmpp_Connected_Client.RUnlock()
|
||||||
return len(s.xmpp_Connected_Client.client)
|
return len(s.xmpp_Connected_Client.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) CreateXmppRemoteRosterRequest() {
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request = &XmppRemoteRosterRequest{request: make(map[string]string)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) SetXmppRemoteRosterRequest(iqId, value string) {
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.Lock()
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.request[iqId] = value
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) RemoveXmppRemoteRosterRequest(iqId string) {
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.Lock()
|
||||||
|
delete(s.xmpp_IQ_RemoteRoster_Request.request, iqId)
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) GetXmppRemoteRosterRequest(iqId string) string {
|
||||||
|
s.xmpp_IQ_RemoteRoster_Request.RLock()
|
||||||
|
defer s.xmpp_IQ_RemoteRoster_Request.RUnlock()
|
||||||
|
return s.xmpp_IQ_RemoteRoster_Request.request[iqId]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,9 @@ func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) {
|
||||||
|
|
||||||
func (g *GatewayInfo) ReceivedXMPP_IQ(iq *xmpp.IQ) bool {
|
func (g *GatewayInfo) ReceivedXMPP_IQ(iq *xmpp.IQ) bool {
|
||||||
ret := false
|
ret := false
|
||||||
if g.XMPP_IQ_RemoteRoster_Request[iq.ID] == RemoteRosterRequestPermission {
|
remoteRosterRequestValue := g.GetXmppRemoteRosterRequest(iq.ID)
|
||||||
delete(g.XMPP_IQ_RemoteRoster_Request, iq.ID)
|
if remoteRosterRequestValue == RemoteRosterRequestPermission {
|
||||||
|
g.RemoveXmppRemoteRosterRequest(iq.ID)
|
||||||
|
|
||||||
if iq.Type == xmpp.IQTypeError && iq.Error.Condition() == xmpp.ErrorForbidden {
|
if iq.Type == xmpp.IQTypeError && iq.Error.Condition() == xmpp.ErrorForbidden {
|
||||||
g.AllowEditRoster = false
|
g.AllowEditRoster = false
|
||||||
|
|
@ -160,15 +161,15 @@ func (g *GatewayInfo) ReceivedXMPP_IQ(iq *xmpp.IQ) bool {
|
||||||
logger.Info.Printf("Check roster edition authorisation by querying roster's user")
|
logger.Info.Printf("Check roster edition authorisation by querying roster's user")
|
||||||
// Remote roster namespace may not be supported (like prosody), so we send a roster query
|
// Remote roster namespace may not be supported (like prosody), so we send a roster query
|
||||||
iqId := NextIqId()
|
iqId := NextIqId()
|
||||||
g.XMPP_IQ_RemoteRoster_Request[iqId] = RemoteRosterRequestRoster
|
g.SetXmppRemoteRosterRequest(iqId, RemoteRosterRequestRoster)
|
||||||
iqSend := &xmpp.IQ{ID: iqId, Type: xmpp.IQTypeGet, From: iq.To, To: iq.From}
|
iqSend := &xmpp.IQ{ID: iqId, Type: xmpp.IQTypeGet, From: iq.To, To: iq.From}
|
||||||
iqSend.PayloadEncode(&xmpp.RosterQuery{})
|
iqSend.PayloadEncode(&xmpp.RosterQuery{})
|
||||||
g.XMPP_Out <- iqSend
|
g.XMPP_Out <- iqSend
|
||||||
}
|
}
|
||||||
ret = true
|
ret = true
|
||||||
|
|
||||||
} else if g.XMPP_IQ_RemoteRoster_Request[iq.ID] == RemoteRosterRequestRoster {
|
} else if remoteRosterRequestValue == RemoteRosterRequestRoster {
|
||||||
delete(g.XMPP_IQ_RemoteRoster_Request, iq.ID)
|
g.RemoveXmppRemoteRosterRequest(iq.ID)
|
||||||
if iq.Type == xmpp.IQTypeResult && iq.PayloadName().Space == xmpp.NSRoster {
|
if iq.Type == xmpp.IQTypeResult && iq.PayloadName().Space == xmpp.NSRoster {
|
||||||
g.AllowEditRoster = true
|
g.AllowEditRoster = true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ func AddNewUser(jidUser, steamLogin, steamPwd string, debugMessage bool) {
|
||||||
g.XMPP_Out = comp.Out
|
g.XMPP_Out = comp.Out
|
||||||
g.CreateXmppConnectedClient()
|
g.CreateXmppConnectedClient()
|
||||||
g.DebugMessage = debugMessage
|
g.DebugMessage = debugMessage
|
||||||
g.XMPP_IQ_RemoteRoster_Request = make(map[string]string)
|
g.CreateXmppRemoteRosterRequest()
|
||||||
g.AllowEditRoster = false
|
g.AllowEditRoster = false
|
||||||
|
|
||||||
MapGatewayInfo[jidUser] = g
|
MapGatewayInfo[jidUser] = g
|
||||||
|
|
@ -292,7 +292,7 @@ func AddNewUser(jidUser, steamLogin, steamPwd string, debugMessage bool) {
|
||||||
logger.Info.Printf("Check roster edition by asking with remote roster manager namespace")
|
logger.Info.Printf("Check roster edition by asking with remote roster manager namespace")
|
||||||
// Ask if remote roster is allow
|
// Ask if remote roster is allow
|
||||||
iqId := gateway.NextIqId()
|
iqId := gateway.NextIqId()
|
||||||
g.XMPP_IQ_RemoteRoster_Request[iqId] = gateway.RemoteRosterRequestPermission
|
g.SetXmppRemoteRosterRequest(iqId, gateway.RemoteRosterRequestPermission)
|
||||||
iq := xmpp.IQ{To: jidUser, From: jid.Domain, Type: xmpp.IQTypeGet, ID: iqId}
|
iq := xmpp.IQ{To: jidUser, From: jid.Domain, Type: xmpp.IQTypeGet, ID: iqId}
|
||||||
// iq.PayloadEncode(&xmpp.RosterQuery{})
|
// iq.PayloadEncode(&xmpp.RosterQuery{})
|
||||||
iq.PayloadEncode(&xmpp.RemoteRosterManagerQuery{Reason: "Manage contacts in the Steam contact list", Type: xmpp.RemoteRosterManagerTypeRequest})
|
iq.PayloadEncode(&xmpp.RemoteRosterManagerQuery{Reason: "Manage contacts in the Steam contact list", Type: xmpp.RemoteRosterManagerTypeRequest})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue