You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-sendxmpp/iqhandling.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
}
}
}
}