mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-12 13:10:25 +00:00
45 lines
796 B
Go
45 lines
796 B
Go
// Copyright 2020 - 2021 Martin Dosch.
|
|
// Use of this source code is governed by the BSD-2-clause
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/mattn/go-xmpp" // BSD-3-Clause
|
|
)
|
|
|
|
func sendIQ(client *xmpp.Client, target string, iQtype string,
|
|
content string) (xmpp.IQ, error) {
|
|
var iq xmpp.IQ
|
|
id := getID()
|
|
c := make(chan xmpp.IQ)
|
|
go getIQ(client, id, c)
|
|
_, err := client.RawInformation(client.JID(), target, id,
|
|
iQtype, content)
|
|
if err != nil {
|
|
return iq, err
|
|
}
|
|
iq = <-c
|
|
close(c)
|
|
return iq, nil
|
|
}
|
|
|
|
func getIQ(client *xmpp.Client, id string, c chan xmpp.IQ) {
|
|
for {
|
|
msg, err := client.Recv()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
switch v := msg.(type) {
|
|
case xmpp.IQ:
|
|
if v.ID == id {
|
|
c <- v
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|