2022-04-09 02:52:14 +00:00
|
|
|
// 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 (
|
|
|
|
"github.com/mattn/go-xmpp" // BSD-3-Clause
|
|
|
|
)
|
|
|
|
|
2022-05-03 10:25:43 +00:00
|
|
|
func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string,
|
|
|
|
iQtype string, content string) (xmpp.IQ, error) {
|
2022-04-09 02:52:14 +00:00
|
|
|
var iq xmpp.IQ
|
|
|
|
id := getID()
|
|
|
|
c := make(chan xmpp.IQ)
|
2022-05-03 10:25:43 +00:00
|
|
|
go getIQ(client, id, c, iqc)
|
2022-04-09 02:52:14 +00:00
|
|
|
_, err := client.RawInformation(client.JID(), target, id,
|
|
|
|
iQtype, content)
|
|
|
|
if err != nil {
|
|
|
|
return iq, err
|
|
|
|
}
|
|
|
|
iq = <-c
|
|
|
|
return iq, nil
|
|
|
|
}
|
|
|
|
|
2022-05-03 10:25:43 +00:00
|
|
|
func getIQ(client *xmpp.Client, id string, c chan xmpp.IQ,
|
|
|
|
iqc chan xmpp.IQ) {
|
2022-04-09 02:52:14 +00:00
|
|
|
for {
|
2022-05-03 10:25:43 +00:00
|
|
|
iq := <-iqc
|
|
|
|
if iq.ID == id {
|
|
|
|
c <- iq
|
|
|
|
return
|
2022-04-09 02:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|