5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-26 06:15:40 +00:00

Update go-xmpp dependency (#2151)

This commit is contained in:
Wim 2024-05-24 01:28:32 +02:00 committed by GitHub
parent a89267943c
commit 65d78e38af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 1080 additions and 275 deletions

View File

@ -12,7 +12,7 @@ jobs:
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v3
with: with:
version: latest version: latest
args: "-v --new-from-rev HEAD~5" args: "-v --new-from-rev HEAD~5 --timeout=5m"
test-build-upload: test-build-upload:
strategy: strategy:
matrix: matrix:

6
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/labstack/echo/v4 v4.12.0 github.com/labstack/echo/v4 v4.12.0
github.com/lrstanley/girc v0.0.0-20240519163535-a518c5b87a79 github.com/lrstanley/girc v0.0.0-20240519163535-a518c5b87a79
github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696 github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696
github.com/matterbridge/go-xmpp v0.0.0-20211030125215-791a06c5f1be github.com/matterbridge/go-xmpp v0.0.0-20240523230155-7154bfeb76e8
github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27 github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27
github.com/matterbridge/gozulipbot v0.0.0-20211023205727-a19d6c1f3b75 github.com/matterbridge/gozulipbot v0.0.0-20211023205727-a19d6c1f3b75
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba
@ -150,6 +150,4 @@ require (
//replace github.com/matrix-org/gomatrix => github.com/matterbridge/gomatrix v0.0.0-20220205235239-607eb9ee6419 //replace github.com/matrix-org/gomatrix => github.com/matterbridge/gomatrix v0.0.0-20220205235239-607eb9ee6419
go 1.21 go 1.22.0
toolchain go1.22.3

4
go.sum
View File

@ -968,8 +968,8 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696 h1:pmPKkN3RJM9wVMZidR99epzK0+gatQiqVtvP1FacZcQ= github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696 h1:pmPKkN3RJM9wVMZidR99epzK0+gatQiqVtvP1FacZcQ=
github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696/go.mod h1:c6MxwqHD+0HvtAJjsHMIdPCiAwGiQwPRPTp69ACMg8A= github.com/matterbridge/Rocket.Chat.Go.SDK v0.0.0-20211016222428-79310a412696/go.mod h1:c6MxwqHD+0HvtAJjsHMIdPCiAwGiQwPRPTp69ACMg8A=
github.com/matterbridge/go-xmpp v0.0.0-20211030125215-791a06c5f1be h1:zlirT+LngOJ60G6FVzI87DljGZLUnfNzmXja61EjtYM= github.com/matterbridge/go-xmpp v0.0.0-20240523230155-7154bfeb76e8 h1:UkpezVlW6/j4qB2FSsz4na2FfZUbIDMAblpjw0Cgqcg=
github.com/matterbridge/go-xmpp v0.0.0-20211030125215-791a06c5f1be/go.mod h1:ECDRehsR9TYTKCAsRS8/wLeOk6UUqDydw47ln7wG41Q= github.com/matterbridge/go-xmpp v0.0.0-20240523230155-7154bfeb76e8/go.mod h1:Vl95jJ8rOBCHUR++A1n6nM5sMk1oHcwInsaxRTR9NM4=
github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27 h1:9XSppnbvvReVom+wphkeF4lbhuT6vCYIdyzpwFtW89c= github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27 h1:9XSppnbvvReVom+wphkeF4lbhuT6vCYIdyzpwFtW89c=
github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27/go.mod h1:/x38AoZf70fK9yZ5gs3BNCaF7/J4QEo4ZpwtLjX95eQ= github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27/go.mod h1:/x38AoZf70fK9yZ5gs3BNCaF7/J4QEo4ZpwtLjX95eQ=
github.com/matterbridge/gozulipbot v0.0.0-20211023205727-a19d6c1f3b75 h1:GslZKF7lW7oSisycGLpxPO+TnKJuA4VZuTWIfYZrClc= github.com/matterbridge/gozulipbot v0.0.0-20211023205727-a19d6c1f3b75 h1:GslZKF7lW7oSisycGLpxPO+TnKJuA4VZuTWIfYZrClc=

View File

@ -3,4 +3,4 @@ go-xmpp
go xmpp library (original was written by russ cox ) go xmpp library (original was written by russ cox )
[Documentation](https://godoc.org/github.com/mattn/go-xmpp) [Documentation](https://godoc.org/github.com/xmppo/go-xmpp)

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,14 @@ import (
"strconv" "strconv"
) )
const IQTypeGet = "get" const (
const IQTypeSet = "set" IQTypeGet = "get"
const IQTypeResult = "result" IQTypeSet = "set"
IQTypeResult = "result"
)
func (c *Client) Discovery() (string, error) { func (c *Client) Discovery() (string, error) {
// use getCookie for a pseudo random id. // use UUIDv4 for a pseudo random id.
reqID := strconv.FormatUint(uint64(getCookie()), 10) reqID := strconv.FormatUint(uint64(getCookie()), 10)
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "") return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
} }
@ -34,14 +36,14 @@ func (c *Client) DiscoverEntityItems(jid string) (string, error) {
// RawInformationQuery sends an information query request to the server. // RawInformationQuery sends an information query request to the server.
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) { func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>" const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>\n"
_, err := fmt.Fprintf(c.conn, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body) _, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
return id, err return id, err
} }
// rawInformation send a IQ request with the payload body to the server // rawInformation send a IQ request with the payload body to the server
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) { func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>" const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>\n"
_, err := fmt.Fprintf(c.conn, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body) _, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
return id, err return id, err
} }

View File

@ -25,7 +25,7 @@ const (
// Send sends room topic wrapped inside an XMPP message stanza body. // Send sends room topic wrapped inside an XMPP message stanza body.
func (c *Client) SendTopic(chat Chat) (n int, err error) { func (c *Client) SendTopic(chat Chat) (n int, err error) {
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>", return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>\n",
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
} }
@ -33,10 +33,10 @@ func (c *Client) JoinMUCNoHistory(jid, nick string) (n int, err error) {
if nick == "" { if nick == "" {
nick = c.jid nick = c.jid
} }
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>"+ "<x xmlns='%s'>"+
"<history maxchars='0'/></x>\n"+ "<history maxchars='0'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC) xmlEscape(jid), xmlEscape(nick), nsMUC)
} }
@ -47,34 +47,34 @@ func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_da
} }
switch history_type { switch history_type {
case NoHistory: case NoHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s' />\n"+ "<x xmlns='%s' />"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC) xmlEscape(jid), xmlEscape(nick), nsMUC)
case CharHistory: case CharHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case SinceHistory: case SinceHistory:
if history_date != nil { if history_date != nil {
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<history since='%s'/></x>\n"+ "<history since='%s'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339)) xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
} }
} }
@ -88,40 +88,40 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
} }
switch history_type { switch history_type {
case NoHistory: case NoHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<password>%s</password>"+ "<password>%s</password>"+
"</x>\n"+ "</x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password)) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
case CharHistory: case CharHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<password>%s</password>\n"+ "<password>%s</password>"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<password>%s</password>\n"+ "<password>%s</password>"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<password>%s</password>\n"+ "<password>%s</password>"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case SinceHistory: case SinceHistory:
if history_date != nil { if history_date != nil {
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>"+
"<password>%s</password>\n"+ "<password>%s</password>"+
"<history since='%s'/></x>\n"+ "<history since='%s'/></x>"+
"</presence>", "</presence>\n",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339)) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
} }
} }
@ -130,6 +130,6 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
// xep-0045 7.14 // xep-0045 7.14
func (c *Client) LeaveMUC(jid string) (n int, err error) { func (c *Client) LeaveMUC(jid string) (n int, err error) {
return fmt.Fprintf(c.conn, "<presence from='%s' to='%s' type='unavailable' />", return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />\n",
c.jid, xmlEscape(jid)) c.jid, xmlEscape(jid))
} }

View File

@ -11,23 +11,23 @@ func (c *Client) PingC2S(jid, server string) error {
if server == "" { if server == "" {
server = c.domain server = c.domain
} }
_, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+ _, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>"+
"<ping xmlns='urn:xmpp:ping'/>\n"+ "<ping xmlns='urn:xmpp:ping'/>"+
"</iq>", "</iq>\n",
xmlEscape(jid), xmlEscape(server)) xmlEscape(jid), xmlEscape(server))
return err return err
} }
func (c *Client) PingS2S(fromServer, toServer string) error { func (c *Client) PingS2S(fromServer, toServer string) error {
_, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='s2s1' type='get'>\n"+ _, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>"+
"<ping xmlns='urn:xmpp:ping'/>\n"+ "<ping xmlns='urn:xmpp:ping'/>"+
"</iq>", "</iq>\n",
xmlEscape(fromServer), xmlEscape(toServer)) xmlEscape(fromServer), xmlEscape(toServer))
return err return err
} }
func (c *Client) SendResultPing(id, toServer string) error { func (c *Client) SendResultPing(id, toServer string) error {
_, err := fmt.Fprintf(c.conn, "<iq type='result' to='%s' id='%s'/>", _, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>\n",
xmlEscape(toServer), xmlEscape(id)) xmlEscape(toServer), xmlEscape(id))
return err return err
} }

View File

@ -22,11 +22,6 @@ type clientPubsubItems struct {
Items []clientPubsubItem `xml:"item"` Items []clientPubsubItem `xml:"item"`
} }
type clientPubsub struct {
XMLName xml.Name `xml:"pubsub"`
Items clientPubsubItems `xml:"items"`
}
type clientPubsubEvent struct { type clientPubsubEvent struct {
XMLName xml.Name `xml:"event"` XMLName xml.Name `xml:"event"`
XMLNS string `xml:"xmlns,attr"` XMLNS string `xml:"xmlns,attr"`

View File

@ -5,16 +5,21 @@ import (
) )
func (c *Client) ApproveSubscription(jid string) { func (c *Client) ApproveSubscription(jid string) {
fmt.Fprintf(c.conn, "<presence to='%s' type='subscribed'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>\n",
xmlEscape(jid)) xmlEscape(jid))
} }
func (c *Client) RevokeSubscription(jid string) { func (c *Client) RevokeSubscription(jid string) {
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribed'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>\n",
xmlEscape(jid))
}
func (c *Client) RetrieveSubscription(jid string) {
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>\n",
xmlEscape(jid)) xmlEscape(jid))
} }
func (c *Client) RequestSubscription(jid string) { func (c *Client) RequestSubscription(jid string) {
fmt.Fprintf(c.conn, "<presence to='%s' type='subscribe'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>\n",
xmlEscape(jid)) xmlEscape(jid))
} }

4
vendor/modules.txt vendored
View File

@ -209,8 +209,8 @@ github.com/magiconair/properties
github.com/matterbridge/Rocket.Chat.Go.SDK/models github.com/matterbridge/Rocket.Chat.Go.SDK/models
github.com/matterbridge/Rocket.Chat.Go.SDK/realtime github.com/matterbridge/Rocket.Chat.Go.SDK/realtime
github.com/matterbridge/Rocket.Chat.Go.SDK/rest github.com/matterbridge/Rocket.Chat.Go.SDK/rest
# github.com/matterbridge/go-xmpp v0.0.0-20211030125215-791a06c5f1be # github.com/matterbridge/go-xmpp v0.0.0-20240523230155-7154bfeb76e8
## explicit ## explicit; go 1.21.5
github.com/matterbridge/go-xmpp github.com/matterbridge/go-xmpp
# github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27 # github.com/matterbridge/gomatrix v0.0.0-20220411225302-271e5088ea27
## explicit; go 1.17 ## explicit; go 1.17