[WIP] Fix ban by software version, some other under-hood changes
- Use updated version of upstream go-xmpp + fixes on client-side - Introduce golangci-lint v2 + fixes - Move especially noisy debugging stuff to separate config handles to be able to switch them off - Add a bit debug to ban by software path
This commit is contained in:
66
vendor/github.com/eleksir/go-xmpp/.golangci.yml
generated
vendored
66
vendor/github.com/eleksir/go-xmpp/.golangci.yml
generated
vendored
@@ -1,66 +0,0 @@
|
||||
run:
|
||||
tests: false
|
||||
skip-dirs:
|
||||
- _example
|
||||
modules-download-mode: readonly
|
||||
allow-parallel-runners: true
|
||||
go: '1.21'
|
||||
output:
|
||||
sort-results: true
|
||||
linters-settings:
|
||||
gosec:
|
||||
excludes:
|
||||
# Оно не используется для повышения безопасности или каких-то таких секъюрых вещей, оно используется для выборки
|
||||
# произвольного элемента из массива, так что ИДИ НАХУЙ с этой проверкой и не еби мозги липовой безопасностью.
|
||||
- G404 # Insecure random number source (rand)
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
- asasalint
|
||||
- asciicheck
|
||||
- bodyclose
|
||||
- containedctx
|
||||
- contextcheck
|
||||
- decorder
|
||||
- durationcheck
|
||||
- errchkjson
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- gci
|
||||
- ginkgolinter
|
||||
- gocheckcompilerdirectives
|
||||
- gocritic
|
||||
- godot
|
||||
- gofmt
|
||||
- goimports
|
||||
- gosec
|
||||
- gosmopolitan
|
||||
- grouper
|
||||
- importas
|
||||
- ireturn
|
||||
- makezero
|
||||
- mirror
|
||||
- nakedret
|
||||
- nilerr
|
||||
- nilnil
|
||||
- nlreturn
|
||||
- noctx
|
||||
- nolintlint
|
||||
- nonamedreturns
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- stylecheck
|
||||
- unconvert
|
||||
- wastedassign
|
||||
- whitespace
|
||||
- wsl
|
||||
14
vendor/github.com/eleksir/go-xmpp/README.md
generated
vendored
14
vendor/github.com/eleksir/go-xmpp/README.md
generated
vendored
@@ -1,14 +0,0 @@
|
||||
go-xmpp
|
||||
=======
|
||||
|
||||
go xmpp library.
|
||||
|
||||
[Original](https://github.com/rsc/rsc/blob/master/xmpp/xmpp.go) work done by [Russ Cox](https://github.com/rsc),
|
||||
then [Yasuhiro Matsumoto](https://github.com/mattn) fork it and continue to improve it.
|
||||
|
||||
Since both of them have almost zero interest to continue develop this lib, I decide to fork it.
|
||||
|
||||
Documentation can be found at [godoc project](https://godoc.org/github.com/eleksir/go-xmpp)
|
||||
|
||||
This fork maintains my needs for xmpp protocol. Feel free to contribute via PR-s if you find it interesting too and feel
|
||||
that it needs more love than it already has. And of course fell free to for it if needed.
|
||||
1805
vendor/github.com/eleksir/go-xmpp/xmpp.go
generated
vendored
1805
vendor/github.com/eleksir/go-xmpp/xmpp.go
generated
vendored
File diff suppressed because it is too large
Load Diff
125
vendor/github.com/eleksir/go-xmpp/xmpp_information_query.go
generated
vendored
125
vendor/github.com/eleksir/go-xmpp/xmpp_information_query.go
generated
vendored
@@ -1,125 +0,0 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const IQTypeGet = "get"
|
||||
const IQTypeSet = "set"
|
||||
const IQTypeResult = "result"
|
||||
const IQTypeError = "error"
|
||||
|
||||
func (c *Client) Discovery() (string, error) {
|
||||
// use getCookie for a pseudo random id.
|
||||
reqID := strconv.FormatUint(uint64(getCookie()), 10)
|
||||
|
||||
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
|
||||
}
|
||||
|
||||
// DiscoverNodeInfo discovers information about a node. Empty node queries info about server itself.
|
||||
func (c *Client) DiscoverNodeInfo(node string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s' node='%s'/>", XMPPNS_DISCO_INFO, node)
|
||||
|
||||
return c.RawInformation(c.jid, c.domain, "info3", IQTypeGet, query)
|
||||
}
|
||||
|
||||
// DiscoverInfo discovers information about given item from given jid.
|
||||
func (c *Client) DiscoverInfo(from string, to string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_INFO)
|
||||
|
||||
return c.RawInformation(from, to, "info3", IQTypeGet, query)
|
||||
}
|
||||
|
||||
// DiscoverServerItems discover items that the server exposes.
|
||||
func (c *Client) DiscoverServerItems() (string, error) {
|
||||
return c.DiscoverEntityItems(c.domain)
|
||||
}
|
||||
|
||||
// DiscoverEntityItems discovers items that an entity exposes.
|
||||
func (c *Client) DiscoverEntityItems(jid string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_ITEMS)
|
||||
|
||||
return c.RawInformation(c.jid, jid, "info1", IQTypeGet, query)
|
||||
}
|
||||
|
||||
// RawInformationQuery sends an information query request to the server.
|
||||
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>"
|
||||
_, err := fmt.Fprintf(StanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
||||
|
||||
return id, err
|
||||
}
|
||||
|
||||
// RawInformation sends a IQ request with the payload body to the server.
|
||||
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>"
|
||||
_, err := fmt.Fprintf(StanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
||||
|
||||
return id, err
|
||||
}
|
||||
|
||||
// IqVersionResponse responding with software version, according to xep-0092.
|
||||
func (c *Client) IqVersionResponse(v IQ, name, version, os string) (string, error) {
|
||||
if name == "" {
|
||||
name = "go-xmpp"
|
||||
}
|
||||
|
||||
if version == "" {
|
||||
version = "undefined"
|
||||
}
|
||||
|
||||
query := "<query xmlns=\"jabber:iq:version\">"
|
||||
query += fmt.Sprintf("<name>%s</name>", name)
|
||||
query += fmt.Sprintf("<version>%s</version>", version)
|
||||
|
||||
if os != "" {
|
||||
query += fmt.Sprintf("<os>%s</os>", os)
|
||||
}
|
||||
|
||||
query += "</query>"
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// JabberIqLastResponse responding with relative time since last activity.
|
||||
// Here lastActivity is unix time stamp when last activity took place since.
|
||||
func (c *Client) JabberIqLastResponse(v IQ, lastActivity int64) (string, error) {
|
||||
query := fmt.Sprintf(
|
||||
"<query xmlns=\"jabber:iq:last\" seconds=\"%d\" />",
|
||||
time.Now().Unix()-lastActivity,
|
||||
)
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// UrnXMPPTimeResponse implements response to query entity's current time (xep-0202).
|
||||
// TimezoneOffset have format +HH:MM or -HH:MM.
|
||||
func (c *Client) UrnXMPPTimeResponse(v IQ, timezoneOffset string) (string, error) {
|
||||
query := fmt.Sprintf(
|
||||
"<time xmlns=\"urn:xmpp:time\"><tzo>%s</tzo><utc>%s</utc></time>",
|
||||
timezoneOffset,
|
||||
time.Now().UTC().Format(time.RFC3339),
|
||||
)
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
140
vendor/github.com/eleksir/go-xmpp/xmpp_muc.go
generated
vendored
140
vendor/github.com/eleksir/go-xmpp/xmpp_muc.go
generated
vendored
@@ -1,140 +0,0 @@
|
||||
// Copyright 2013 Flo Lauber <dev@qatfy.at>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// TODO(flo):
|
||||
// - cleanup signatures of join/leave functions
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
nsMUC = "http://jabber.org/protocol/muc"
|
||||
nsMUCUser = "http://jabber.org/protocol/muc#user"
|
||||
NoHistory = 0
|
||||
CharHistory = 1
|
||||
StanzaHistory = 2
|
||||
SecondsHistory = 3
|
||||
SinceHistory = 4
|
||||
)
|
||||
|
||||
// SendTopic sends room topic wrapped inside an XMPP message stanza body.
|
||||
func (c *Client) SendTopic(chat Chat) (int, error) {
|
||||
return fmt.Fprintf(StanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||
}
|
||||
|
||||
// JoinMUCNoHistory joins room and instructs server that no history data required.
|
||||
func (c *Client) JoinMUCNoHistory(jid, nick string) (int, error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history maxchars='0'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||
}
|
||||
|
||||
// JoinMUC joins room, xep-0045 7.2.
|
||||
func (c *Client) JoinMUC(jid, nick string, historyType, history int, historyDate *time.Time) (int, error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
|
||||
switch historyType {
|
||||
case NoHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s' />\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||
case CharHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<history maxchars='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||
case StanzaHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<history maxstanzas='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||
case SecondsHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<history seconds='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||
case SinceHistory:
|
||||
if historyDate != nil {
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<history since='%s'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, historyDate.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
|
||||
return 0, errors.New("unknown history option")
|
||||
}
|
||||
|
||||
// JoinProtectedMUC joins password protected room, xep-0045 7.2.6.
|
||||
func (c *Client) JoinProtectedMUC(jid, nick string, password string, historyType, history int, historyDate *time.Time) (int, error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
|
||||
switch historyType {
|
||||
case NoHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<password>%s</password>"+
|
||||
"</x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
||||
case CharHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<password>%s</password>\n"+
|
||||
"<history maxchars='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||
case StanzaHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<password>%s</password>\n"+
|
||||
"<history maxstanzas='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||
case SecondsHistory:
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<password>%s</password>\n"+
|
||||
"<history seconds='%d'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||
case SinceHistory:
|
||||
if historyDate != nil {
|
||||
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+
|
||||
"<x xmlns='%s'>\n"+
|
||||
"<password>%s</password>\n"+
|
||||
"<history since='%s'/></x>\n"+
|
||||
"</presence>",
|
||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), historyDate.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
|
||||
return 0, errors.New("unknown history option")
|
||||
}
|
||||
|
||||
// LeaveMUC quits from room xep-0045 7.14.
|
||||
func (c *Client) LeaveMUC(jid string) (int, error) {
|
||||
return fmt.Fprintf(StanzaWriter, "<presence from='%s' to='%s' type='unavailable' />",
|
||||
c.jid, xmlEscape(jid))
|
||||
}
|
||||
49
vendor/github.com/eleksir/go-xmpp/xmpp_ping.go
generated
vendored
49
vendor/github.com/eleksir/go-xmpp/xmpp_ping.go
generated
vendored
@@ -1,49 +0,0 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (c *Client) PingC2S(jid, server string) error {
|
||||
if jid == "" {
|
||||
jid = c.jid
|
||||
}
|
||||
|
||||
if server == "" {
|
||||
server = c.domain
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+
|
||||
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
||||
"</iq>",
|
||||
xmlEscape(jid), xmlEscape(server))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) PingS2S(fromServer, toServer string) error {
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>\n"+
|
||||
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
||||
"</iq>",
|
||||
xmlEscape(fromServer), xmlEscape(toServer))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) SendResultPing(id, toServer string) error {
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<iq type='result' to='%s' id='%s'/>",
|
||||
xmlEscape(toServer), xmlEscape(id))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// PingResponse responding to ping query according to xep-0199.
|
||||
func (c *Client) PingResponse(v IQ) (string, error) {
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
"",
|
||||
)
|
||||
}
|
||||
33
vendor/github.com/eleksir/go-xmpp/xmpp_subscription.go
generated
vendored
33
vendor/github.com/eleksir/go-xmpp/xmpp_subscription.go
generated
vendored
@@ -1,33 +0,0 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (c *Client) ApproveSubscription(jid string) error {
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<presence to='%s' type='subscribed'/>",
|
||||
xmlEscape(jid))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) RevokeSubscription(jid string) error {
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<presence to='%s' type='unsubscribed'/>",
|
||||
xmlEscape(jid))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) RetrieveSubscription(jid string) error {
|
||||
_, err := fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>",
|
||||
xmlEscape(jid))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) RequestSubscription(jid string) error {
|
||||
_, err := fmt.Fprintf(StanzaWriter, "<presence to='%s' type='subscribe'/>",
|
||||
xmlEscape(jid))
|
||||
|
||||
return err
|
||||
}
|
||||
5
vendor/github.com/xmppo/go-xmpp/.travis.yml
generated
vendored
Normal file
5
vendor/github.com/xmppo/go-xmpp/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
language: go
|
||||
go:
|
||||
- tip
|
||||
script:
|
||||
- go test
|
||||
3
vendor/github.com/eleksir/go-xmpp/LICENSE → vendor/github.com/xmppo/go-xmpp/LICENSE
generated
vendored
3
vendor/github.com/eleksir/go-xmpp/LICENSE → vendor/github.com/xmppo/go-xmpp/LICENSE
generated
vendored
@@ -1,7 +1,4 @@
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
Copyright (c) 2012 Russ Cox <rsc@swtch.com>
|
||||
Copyright (c) 2023 Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
Copyright (c) 2023 Sergei Fedosoff <eleksir@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
6
vendor/github.com/xmppo/go-xmpp/README.md
generated
vendored
Normal file
6
vendor/github.com/xmppo/go-xmpp/README.md
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
go-xmpp
|
||||
=======
|
||||
|
||||
go xmpp library (original was written by russ cox )
|
||||
|
||||
[Documentation](https://godoc.org/github.com/xmppo/go-xmpp)
|
||||
51
vendor/github.com/xmppo/go-xmpp/const.go
generated
vendored
Normal file
51
vendor/github.com/xmppo/go-xmpp/const.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
package xmpp
|
||||
|
||||
const (
|
||||
Version = "0.3.1"
|
||||
// FAST Mechanisms
|
||||
HT_SHA_256_ENDP = "HT-SHA-256-ENDP"
|
||||
HT_SHA_256_EXPR = "HT-SHA-256-EXPR"
|
||||
HT_SHA_256_NONE = "HT-SHA-256-NONE"
|
||||
HT_SHA_256_UNIQ = "HT-SHA-256-UNIQ"
|
||||
// IQ Types
|
||||
IQTypeError = "error"
|
||||
IQTypeGet = "get"
|
||||
IQTypeResult = "result"
|
||||
IQTypeSet = "set"
|
||||
// SCRAM Mechanisms
|
||||
SCRAM_SHA_1_PLUS = "SCRAM-SHA-1-PLUS"
|
||||
SCRAM_SHA_1 = "SCRAM-SHA-1"
|
||||
SCRAM_SHA_256_PLUS = "SCRAM-SHA-256-PLUS"
|
||||
SCRAM_SHA_256 = "SCRAM-SHA-256"
|
||||
SCRAM_SHA_512_PLUS = "SCRAM-SHA-512-PLUS"
|
||||
SCRAM_SHA_512 = "SCRAM-SHA-512"
|
||||
UPGR_SCRAM_SHA_256 = "UPGR-SCRAM-SHA-256"
|
||||
UPGR_SCRAM_SHA_512 = "UPGR-SCRAM-SHA-512"
|
||||
// XMPP Namespaces
|
||||
XMPPNS_AVATAR_PEP_DATA = "urn:xmpp:avatar:data"
|
||||
XMPPNS_AVATAR_PEP_METADATA = "urn:xmpp:avatar:metadata"
|
||||
XMPPNS_BIND_0 = "urn:xmpp:bind:0"
|
||||
XMPPNS_CLIENT = "jabber:client"
|
||||
XMPPNS_DISCO_INFO = "http://jabber.org/protocol/disco#info"
|
||||
XMPPNS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"
|
||||
XMPPNS_FAST_0 = "urn:xmpp:fast:0"
|
||||
XMPPNS_HTTP_UPLOAD_0 = "urn:xmpp:http:upload:0"
|
||||
XMPPNS_IQ_VERSION = "jabber:iq:version"
|
||||
XMPPNS_MUC = "http://jabber.org/protocol/muc"
|
||||
XMPPNS_MUC_USER = "http://jabber.org/protocol/muc#user"
|
||||
XMPPNS_PING = "urn:xmpp:ping"
|
||||
XMPPNS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event"
|
||||
XMPPNS_PUBSUB = "http://jabber.org/protocol/pubsub"
|
||||
XMPPNS_SASL_2 = "urn:xmpp:sasl:2"
|
||||
XMPPNS_SASL_CB_0 = "urn:xmpp:sasl-cb:0"
|
||||
XMPPNS_SASL_UPGRADE_0 = "urn:xmpp:sasl:upgrade:0"
|
||||
XMPPNS_XMPP_SASL = "urn:ietf:params:xml:ns:xmpp-sasl"
|
||||
XMPPNS_SCRAM_UPGRADE_0 = "urn:xmpp:scram-upgrade:0"
|
||||
XMPPNS_SID_0 = "urn:xmpp:sid:0"
|
||||
XMPPNS_STREAM = "http://etherx.jabber.org/streams"
|
||||
XMPPNS_STREAM_LIMITS_0 = "urn:xmpp:stream-limits:0"
|
||||
XMPPNS_TIME = "urn:xmpp:time"
|
||||
XMPPNS_XMPP_TLS = "urn:ietf:params:xml:ns:xmpp-tls"
|
||||
XMPPNS_XMPP_BIND = "urn:ietf:params:xml:ns:xmpp-bind"
|
||||
XMPPNS_XMPP_SESSION = "urn:ietf:params:xml:ns:xmpp-session"
|
||||
)
|
||||
2460
vendor/github.com/xmppo/go-xmpp/xmpp.go
generated
vendored
Normal file
2460
vendor/github.com/xmppo/go-xmpp/xmpp.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"crypto/sha1" //nolint:gosec // go fuck yourself, gosec. You don't even fucking read rfc. So shout the fuck up.
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/xml"
|
||||
@@ -9,11 +9,6 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
XMPPNS_AVATAR_PEP_DATA = "urn:xmpp:avatar:data" //nocritic:revive
|
||||
XMPPNS_AVATAR_PEP_METADATA = "urn:xmpp:avatar:metadata" //nocritic:revive
|
||||
)
|
||||
|
||||
type clientAvatarData struct {
|
||||
XMLName xml.Name `xml:"data"`
|
||||
Data []byte `xml:",innerxml"`
|
||||
@@ -52,8 +47,8 @@ type AvatarMetadata struct {
|
||||
|
||||
func handleAvatarData(itemsBody []byte, from, id string) (AvatarData, error) {
|
||||
var data clientAvatarData
|
||||
|
||||
if err := xml.Unmarshal(itemsBody, &data); err != nil {
|
||||
err := xml.Unmarshal(itemsBody, &data)
|
||||
if err != nil {
|
||||
return AvatarData{}, err
|
||||
}
|
||||
|
||||
@@ -64,9 +59,8 @@ func handleAvatarData(itemsBody []byte, from, id string) (AvatarData, error) {
|
||||
return AvatarData{}, err
|
||||
}
|
||||
|
||||
hash := sha1.Sum(dataRaw) //nolint:gosec // go fuck yourself, gosec. This exact mechanics described in standard.
|
||||
hash := sha1.Sum(dataRaw) //nolint: gosec,G401 // It is not about security.
|
||||
hashStr := hex.EncodeToString(hash[:])
|
||||
|
||||
if hashStr != id {
|
||||
return AvatarData{}, errors.New("SHA1 hashes do not match")
|
||||
}
|
||||
@@ -78,12 +72,9 @@ func handleAvatarData(itemsBody []byte, from, id string) (AvatarData, error) {
|
||||
}
|
||||
|
||||
func handleAvatarMetadata(body []byte, from string) (AvatarMetadata, error) {
|
||||
var (
|
||||
meta clientAvatarMetadata
|
||||
err error
|
||||
)
|
||||
|
||||
if err = xml.Unmarshal(body, &meta); err != nil {
|
||||
var meta clientAvatarMetadata
|
||||
err := xml.Unmarshal(body, &meta)
|
||||
if err != nil {
|
||||
return AvatarMetadata{}, err
|
||||
}
|
||||
|
||||
@@ -95,10 +86,10 @@ func handleAvatarMetadata(body []byte, from string) (AvatarMetadata, error) {
|
||||
ID: meta.Info.ID,
|
||||
Type: meta.Info.Type,
|
||||
URL: meta.Info.URL,
|
||||
}, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
// atoiw is a wrapper for atoi which just returns -1 if an error occurs.
|
||||
// A wrapper for atoi which just returns -1 if an error occurs
|
||||
func atoiw(str string) int {
|
||||
i, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
@@ -108,22 +99,22 @@ func atoiw(str string) int {
|
||||
return i
|
||||
}
|
||||
|
||||
func (c *Client) AvatarSubscribeMetadata(jid string) (string, error) {
|
||||
func (c *Client) AvatarSubscribeMetadata(jid string) error {
|
||||
return c.PubsubSubscribeNode(XMPPNS_AVATAR_PEP_METADATA, jid)
|
||||
}
|
||||
|
||||
func (c *Client) AvatarUnsubscribeMetadata(jid string) (string, error) {
|
||||
func (c *Client) AvatarUnsubscribeMetadata(jid string) error {
|
||||
return c.PubsubUnsubscribeNode(XMPPNS_AVATAR_PEP_METADATA, jid)
|
||||
}
|
||||
|
||||
func (c *Client) AvatarRequestData(jid string) (string, error) {
|
||||
func (c *Client) AvatarRequestData(jid string) error {
|
||||
return c.PubsubRequestLastItems(XMPPNS_AVATAR_PEP_DATA, jid)
|
||||
}
|
||||
|
||||
func (c *Client) AvatarRequestDataByID(jid, id string) (string, error) {
|
||||
func (c *Client) AvatarRequestDataByID(jid, id string) error {
|
||||
return c.PubsubRequestItem(XMPPNS_AVATAR_PEP_DATA, jid, id)
|
||||
}
|
||||
|
||||
func (c *Client) AvatarRequestMetadata(jid string) (string, error) {
|
||||
func (c *Client) AvatarRequestMetadata(jid string) error {
|
||||
return c.PubsubRequestLastItems(XMPPNS_AVATAR_PEP_METADATA, jid)
|
||||
}
|
||||
@@ -4,11 +4,6 @@ import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
const (
|
||||
XMPPNS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items" //nocritic:revive
|
||||
XMPPNS_DISCO_INFO = "http://jabber.org/protocol/disco#info" //nocritic:revive
|
||||
)
|
||||
|
||||
type clientDiscoFeature struct {
|
||||
XMLName xml.Name `xml:"feature"`
|
||||
Var string `xml:"var,attr"`
|
||||
@@ -25,6 +20,7 @@ type clientDiscoQuery struct {
|
||||
XMLName xml.Name `xml:"query"`
|
||||
Features []clientDiscoFeature `xml:"feature"`
|
||||
Identities []clientDiscoIdentity `xml:"identity"`
|
||||
X []DiscoX `xml:"x"`
|
||||
}
|
||||
|
||||
type clientDiscoItem struct {
|
||||
@@ -57,6 +53,18 @@ type DiscoResult struct {
|
||||
To string
|
||||
Features []string
|
||||
Identities []DiscoIdentity
|
||||
X []DiscoX
|
||||
}
|
||||
|
||||
type DiscoX struct {
|
||||
XMLName xml.Name `xml:"x"`
|
||||
Field []DiscoXField `xml:"field"`
|
||||
}
|
||||
|
||||
type DiscoXField struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Var string `xml:"var,attr"`
|
||||
Value []string `xml:"value"`
|
||||
}
|
||||
|
||||
type DiscoItems struct {
|
||||
@@ -90,7 +98,6 @@ func clientIdentitiesToReturn(identities []clientDiscoIdentity) []DiscoIdentity
|
||||
|
||||
func clientDiscoItemsToReturn(items []clientDiscoItem) []DiscoItem {
|
||||
var ret []DiscoItem
|
||||
|
||||
for _, item := range items {
|
||||
ret = append(ret, DiscoItem{
|
||||
Jid: item.Jid,
|
||||
@@ -4,23 +4,23 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrorServiceUnavailable implements error response about feature that is not available. Currently implemented for
|
||||
// ErrorServiceUnavailable implements error response about a feature that is not available. Currently implemented for
|
||||
// xep-0030.
|
||||
// QueryXmlns is about incoming xmlns attribute in query tag.
|
||||
// Node is about incoming node attribute in query tag (looks like it used only in disco#commands).
|
||||
//
|
||||
// If queried feature is not here on purpose, standards suggest answer with this stanza.
|
||||
// If queried feature is not here on purpose, standards suggest to answer with this stanza.
|
||||
func (c *Client) ErrorServiceUnavailable(v IQ, queryXmlns, node string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns=\"%s\" ", queryXmlns)
|
||||
query := fmt.Sprintf("<query xmlns='%s' ", queryXmlns)
|
||||
|
||||
if node != "" {
|
||||
query += fmt.Sprintf("node=\"%s\" />", node)
|
||||
query += fmt.Sprintf("node='%s' />", node)
|
||||
} else {
|
||||
query += "/>"
|
||||
}
|
||||
|
||||
query += "<error type=\"cancel\">"
|
||||
query += "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\" />"
|
||||
query += "<error type='cancel'>"
|
||||
query += "<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />"
|
||||
query += "</error>"
|
||||
|
||||
return c.RawInformation(
|
||||
@@ -32,16 +32,16 @@ func (c *Client) ErrorServiceUnavailable(v IQ, queryXmlns, node string) (string,
|
||||
)
|
||||
}
|
||||
|
||||
// ErrorNotImplemented implements error response about feature that is not (yet?) implemented.
|
||||
// ErrorNotImplemented implements error response about a feature that is not (yet?) implemented.
|
||||
// Xmlns is about not implemented feature.
|
||||
//
|
||||
// If queried feature is not here because of it under development or for similar reasons, standards suggest answer with
|
||||
// If queried feature is not here because of it under development or for similar reasons, standards suggest to answer with
|
||||
// this stanza.
|
||||
func (c *Client) ErrorNotImplemented(v IQ, xmlns, feature string) (string, error) {
|
||||
query := "<error type=\"cancel\">"
|
||||
query += "<feature-not-implemented xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\" />"
|
||||
query := "<error type='cancel'>"
|
||||
query += "<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />"
|
||||
query += fmt.Sprintf(
|
||||
"<unsupported xmlns=\"%s\" feature=\"%s\" />",
|
||||
"<unsupported xmlns='%s' feature='%s' />",
|
||||
xmlns,
|
||||
feature,
|
||||
)
|
||||
38
vendor/github.com/xmppo/go-xmpp/xmpp_http_upload.go
generated
vendored
Normal file
38
vendor/github.com/xmppo/go-xmpp/xmpp_http_upload.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type Slot struct {
|
||||
// TODO: Maybe this doesn't belong here
|
||||
ID string
|
||||
XMLName xml.Name `xml:"slot"`
|
||||
Put Put
|
||||
Get Get
|
||||
}
|
||||
|
||||
type Put struct {
|
||||
XMLName xml.Name `xml:"put"`
|
||||
Url string `xml:"url,attr"`
|
||||
Headers []Header `xml:"header"`
|
||||
}
|
||||
|
||||
type Get struct {
|
||||
XMLName xml.Name `xml:"get"`
|
||||
Url string `xml:"url,attr"`
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
XMLName xml.Name `xml:"header"`
|
||||
Name string `xml:"name,attr"`
|
||||
Value string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
// Oob is an out-of-band url/description, used in file uploads.
|
||||
// See https://xmpp.org/extensions/xep-0066.html
|
||||
type Oob struct {
|
||||
XMLName xml.Name `xml:"x,xmlns:jabber:x:oob"`
|
||||
Url string `xml:"url"`
|
||||
Desc string `xml:"desc"`
|
||||
}
|
||||
97
vendor/github.com/xmppo/go-xmpp/xmpp_information_query.go
generated
vendored
Normal file
97
vendor/github.com/xmppo/go-xmpp/xmpp_information_query.go
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Client) Discovery() (string, error) {
|
||||
// use UUIDv4 for a pseudo random id.
|
||||
reqID := getUUID()
|
||||
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
|
||||
}
|
||||
|
||||
// Discover information about a node. Empty node queries info about server itself.
|
||||
func (c *Client) DiscoverNodeInfo(node string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s' node='%s'/>", XMPPNS_DISCO_INFO, node)
|
||||
return c.RawInformation(c.jid, c.domain, getUUID(), IQTypeGet, query)
|
||||
}
|
||||
|
||||
// Discover information about given item from given jid.
|
||||
func (c *Client) DiscoverInfo(to string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_INFO)
|
||||
return c.RawInformation(c.jid, to, getUUID(), IQTypeGet, query)
|
||||
}
|
||||
|
||||
// Discover items that the server exposes
|
||||
func (c *Client) DiscoverServerItems() (string, error) {
|
||||
return c.DiscoverEntityItems(c.domain)
|
||||
}
|
||||
|
||||
// Discover items that an entity exposes
|
||||
func (c *Client) DiscoverEntityItems(jid string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_ITEMS)
|
||||
return c.RawInformation(c.jid, jid, getUUID(), IQTypeGet, query)
|
||||
}
|
||||
|
||||
// RawInformationQuery sends an information query request to the server.
|
||||
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>\n"
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
||||
return id, err
|
||||
}
|
||||
|
||||
// rawInformation send a IQ request with the payload body to the server
|
||||
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>\n"
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
||||
return id, err
|
||||
}
|
||||
|
||||
// UrnXMPPTimeResponse implements response to query entity's current time (xep-0202).
|
||||
func (c *Client) UrnXMPPTimeResponse(v IQ, timezoneOffset string) (string, error) {
|
||||
query := fmt.Sprintf(
|
||||
"<time xmlns=\"%s\"><tzo>%s</tzo><utc>%s</utc></time>",
|
||||
XMPPNS_TIME,
|
||||
timezoneOffset,
|
||||
time.Now().UTC().Format(time.RFC3339),
|
||||
)
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// IqVersionResponse responding with software version, according to xep-0092.
|
||||
func (c *Client) IqVersionResponse(v IQ, name string, version string, os string) (string, error) {
|
||||
if name == "" {
|
||||
name = "go-xmpp"
|
||||
version = Version
|
||||
}
|
||||
|
||||
if version == "" {
|
||||
version = "undefined"
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("<query xmlns=\"%s\">", XMPPNS_IQ_VERSION)
|
||||
query += fmt.Sprintf("<name>%s</name>", name)
|
||||
query += fmt.Sprintf("<version>%s</version>", version)
|
||||
|
||||
if os != "" {
|
||||
query += fmt.Sprintf("<os>%s</os>", os)
|
||||
}
|
||||
|
||||
query += "</query>"
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
133
vendor/github.com/xmppo/go-xmpp/xmpp_muc.go
generated
vendored
Normal file
133
vendor/github.com/xmppo/go-xmpp/xmpp_muc.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright 2013 Flo Lauber <dev@qatfy.at>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// TODO(flo):
|
||||
// - support password protected MUC rooms
|
||||
// - cleanup signatures of join/leave functions
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
NoHistory = 0
|
||||
CharHistory = 1
|
||||
StanzaHistory = 2
|
||||
SecondsHistory = 3
|
||||
SinceHistory = 4
|
||||
)
|
||||
|
||||
// Send sends room topic wrapped inside an XMPP message stanza body.
|
||||
func (c *Client) SendTopic(chat Chat) (n int, err error) {
|
||||
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))
|
||||
}
|
||||
|
||||
func (c *Client) JoinMUCNoHistory(jid, nick string) (n int, err error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history maxchars='0'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC)
|
||||
}
|
||||
|
||||
// xep-0045 7.2
|
||||
func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
switch history_type {
|
||||
case NoHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s' />"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC)
|
||||
case CharHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history maxchars='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, history)
|
||||
case StanzaHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history maxstanzas='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, history)
|
||||
case SecondsHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history seconds='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, history)
|
||||
case SinceHistory:
|
||||
if history_date != nil {
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<history since='%s'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, history_date.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
return 0, errors.New("unknown history option")
|
||||
}
|
||||
|
||||
// xep-0045 7.2.6
|
||||
func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||
if nick == "" {
|
||||
nick = c.jid
|
||||
}
|
||||
switch history_type {
|
||||
case NoHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<password>%s</password>"+
|
||||
"</x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, xmlEscape(password))
|
||||
case CharHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<password>%s</password>"+
|
||||
"<history maxchars='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, xmlEscape(password), history)
|
||||
case StanzaHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<password>%s</password>"+
|
||||
"<history maxstanzas='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, xmlEscape(password), history)
|
||||
case SecondsHistory:
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<password>%s</password>"+
|
||||
"<history seconds='%d'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, xmlEscape(password), history)
|
||||
case SinceHistory:
|
||||
if history_date != nil {
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||
"<x xmlns='%s'>"+
|
||||
"<password>%s</password>"+
|
||||
"<history since='%s'/></x>"+
|
||||
"</presence>\n",
|
||||
xmlEscape(jid), xmlEscape(nick), XMPPNS_MUC, xmlEscape(password), history_date.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
return 0, errors.New("unknown history option")
|
||||
}
|
||||
|
||||
// xep-0045 7.14
|
||||
func (c *Client) LeaveMUC(jid string) (n int, err error) {
|
||||
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />\n",
|
||||
c.jid, xmlEscape(jid))
|
||||
}
|
||||
57
vendor/github.com/xmppo/go-xmpp/xmpp_ping.go
generated
vendored
Normal file
57
vendor/github.com/xmppo/go-xmpp/xmpp_ping.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Client) PingC2S(jid, server string) error {
|
||||
if jid == "" {
|
||||
jid = c.jid
|
||||
}
|
||||
if server == "" {
|
||||
server = c.domain
|
||||
}
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='%s' type='get'>"+
|
||||
"<ping xmlns='urn:xmpp:ping'/>"+
|
||||
"</iq>\n",
|
||||
xmlEscape(jid), xmlEscape(server), getUUID())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) PingS2S(fromServer, toServer string) error {
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='%s' type='get'>"+
|
||||
"<ping xmlns='urn:xmpp:ping'/>"+
|
||||
"</iq>\n",
|
||||
xmlEscape(fromServer), xmlEscape(toServer), getUUID())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) SendResultPing(id, toServer string) error {
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>\n",
|
||||
xmlEscape(toServer), xmlEscape(id))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) sendPeriodicPings() {
|
||||
for range c.periodicPingTicker.C {
|
||||
// Reset ticker for periodic pings if configured.
|
||||
if c.periodicPings {
|
||||
c.periodicPingTicker.Reset(c.periodicPingPeriod)
|
||||
}
|
||||
c.periodicPingID = getUUID()
|
||||
c.periodicPingReply = false
|
||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='%s' type='get'>"+
|
||||
"<ping xmlns='urn:xmpp:ping'/></iq>\n",
|
||||
xmlEscape(c.jid), xmlEscape(c.domain), c.periodicPingID)
|
||||
if err != nil {
|
||||
c.Close()
|
||||
}
|
||||
time.Sleep(c.periodicPingTimeout)
|
||||
if !c.periodicPingReply {
|
||||
c.shutdown = true
|
||||
fmt.Fprintf(c.stanzaWriter, "</stream:stream>\n")
|
||||
c.conn.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,6 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
XMPPNS_PUBSUB = "http://jabber.org/protocol/pubsub" //nolint:revive
|
||||
XMPPNS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event" //nolint:revive
|
||||
)
|
||||
|
||||
type clientPubsubItem struct {
|
||||
XMLName xml.Name `xml:"item"`
|
||||
ID string `xml:"id,attr"`
|
||||
@@ -22,11 +17,6 @@ type clientPubsubItems struct {
|
||||
Items []clientPubsubItem `xml:"item"`
|
||||
}
|
||||
|
||||
type clientPubsub struct {
|
||||
XMLName xml.Name `xml:"pubsub"`
|
||||
Items clientPubsubItems `xml:"items"`
|
||||
}
|
||||
|
||||
type clientPubsubEvent struct {
|
||||
XMLName xml.Name `xml:"event"`
|
||||
XMLNS string `xml:"xmlns,attr"`
|
||||
@@ -67,7 +57,7 @@ type PubsubItems struct {
|
||||
Items []PubsubItem
|
||||
}
|
||||
|
||||
// Converts []clientPubsubItem to []PubsubItem.
|
||||
// Converts []clientPubsubItem to []PubsubItem
|
||||
func pubsubItemsToReturn(items []clientPubsubItem) []PubsubItem {
|
||||
var tmp []PubsubItem
|
||||
for _, i := range items {
|
||||
@@ -96,7 +86,6 @@ func pubsubSubscriptionStanza(node, jid string) string {
|
||||
body := fmt.Sprintf("<subscribe node='%s' jid='%s'/>",
|
||||
xmlEscape(node),
|
||||
xmlEscape(jid))
|
||||
|
||||
return pubsubStanza(body)
|
||||
}
|
||||
|
||||
@@ -104,34 +93,43 @@ func pubsubUnsubscriptionStanza(node, jid string) string {
|
||||
body := fmt.Sprintf("<unsubscribe node='%s' jid='%s'/>",
|
||||
xmlEscape(node),
|
||||
xmlEscape(jid))
|
||||
|
||||
return pubsubStanza(body)
|
||||
}
|
||||
|
||||
func (c *Client) PubsubSubscribeNode(node, jid string) (string, error) {
|
||||
return c.RawInformation(c.jid,
|
||||
func (c *Client) PubsubSubscribeNode(node, jid string) error {
|
||||
id := getUUID()
|
||||
c.subIDs = append(c.subIDs, id)
|
||||
_, err := c.RawInformation(c.jid,
|
||||
jid,
|
||||
"sub1",
|
||||
id,
|
||||
"set",
|
||||
pubsubSubscriptionStanza(node, c.jid))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) PubsubUnsubscribeNode(node, jid string) (string, error) {
|
||||
return c.RawInformation(c.jid,
|
||||
func (c *Client) PubsubUnsubscribeNode(node, jid string) error {
|
||||
id := getUUID()
|
||||
c.unsubIDs = append(c.unsubIDs, id)
|
||||
_, err := c.RawInformation(c.jid,
|
||||
jid,
|
||||
"unsub1",
|
||||
id,
|
||||
"set",
|
||||
pubsubUnsubscriptionStanza(node, c.jid))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) PubsubRequestLastItems(node, jid string) (string, error) {
|
||||
func (c *Client) PubsubRequestLastItems(node, jid string) error {
|
||||
id := getUUID()
|
||||
c.itemsIDs = append(c.itemsIDs, id)
|
||||
body := fmt.Sprintf("<items node='%s'/>", node)
|
||||
|
||||
return c.RawInformation(c.jid, jid, "items1", "get", pubsubStanza(body))
|
||||
_, err := c.RawInformation(c.jid, jid, id, "get", pubsubStanza(body))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) PubsubRequestItem(node, jid, id string) (string, error) {
|
||||
func (c *Client) PubsubRequestItem(node, jid, id string) error {
|
||||
stanzaID := getUUID()
|
||||
c.itemsIDs = append(c.itemsIDs, stanzaID)
|
||||
body := fmt.Sprintf("<items node='%s'><item id='%s'/></items>", node, id)
|
||||
|
||||
return c.RawInformation(c.jid, jid, "items3", "get", pubsubStanza(body))
|
||||
_, err := c.RawInformation(c.jid, jid, stanzaID, "get", pubsubStanza(body))
|
||||
return err
|
||||
}
|
||||
30
vendor/github.com/xmppo/go-xmpp/xmpp_subscription.go
generated
vendored
Normal file
30
vendor/github.com/xmppo/go-xmpp/xmpp_subscription.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (c *Client) ApproveSubscription(jid string) {
|
||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>\n",
|
||||
xmlEscape(jid))
|
||||
}
|
||||
|
||||
func (c *Client) RevokeSubscription(jid string) {
|
||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>\n",
|
||||
xmlEscape(jid))
|
||||
}
|
||||
|
||||
// Deprecated: Use RevertSubscription instead.
|
||||
func (c *Client) RetrieveSubscription(jid string) {
|
||||
c.RevertSubscription(jid)
|
||||
}
|
||||
|
||||
func (c *Client) RevertSubscription(jid string) {
|
||||
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>\n",
|
||||
xmlEscape(jid))
|
||||
}
|
||||
|
||||
func (c *Client) RequestSubscription(jid string) {
|
||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>\n",
|
||||
xmlEscape(jid))
|
||||
}
|
||||
Reference in New Issue
Block a user