|
|
@ -232,6 +232,7 @@ func main() {
|
|
|
|
flagInteractive := getopt.BoolLong("interactive", 'i', "Interactive mode (for use with e.g. 'tail -f').")
|
|
|
|
flagInteractive := getopt.BoolLong("interactive", 'i', "Interactive mode (for use with e.g. 'tail -f').")
|
|
|
|
flagSkipVerify := getopt.BoolLong("no-tls-verify", 'n',
|
|
|
|
flagSkipVerify := getopt.BoolLong("no-tls-verify", 'n',
|
|
|
|
"Skip verification of TLS certificates (not recommended).")
|
|
|
|
"Skip verification of TLS certificates (not recommended).")
|
|
|
|
|
|
|
|
flagRaw := getopt.BoolLong("raw", 0, "Send raw XML.")
|
|
|
|
|
|
|
|
|
|
|
|
// Parse command line flags.
|
|
|
|
// Parse command line flags.
|
|
|
|
getopt.Parse()
|
|
|
|
getopt.Parse()
|
|
|
@ -243,8 +244,10 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read recipients from command line and quit if none are specified.
|
|
|
|
// Read recipients from command line and quit if none are specified.
|
|
|
|
|
|
|
|
// For sending raw XML it's not required to specify a recipient except
|
|
|
|
|
|
|
|
// for MUCs (go-sendxmpp will join the MUC automatically).
|
|
|
|
recipients := getopt.Args()
|
|
|
|
recipients := getopt.Args()
|
|
|
|
if len(recipients) == 0 {
|
|
|
|
if (len(recipients) == 0 && !*flagRaw) || (len(recipients) == 0 && *flagChatroom) {
|
|
|
|
log.Fatal("No recipient specified.")
|
|
|
|
log.Fatal("No recipient specified.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -389,6 +392,36 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send raw XML to chatroom
|
|
|
|
|
|
|
|
if *flagChatroom && *flagRaw {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Join the MUC.
|
|
|
|
|
|
|
|
_, err := client.JoinMUCNoHistory(recipients[0], *flagResource)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
// Try to nicely close connection,
|
|
|
|
|
|
|
|
// even if there was an error joining.
|
|
|
|
|
|
|
|
_ = client.Close()
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send raw XMP
|
|
|
|
|
|
|
|
_, err = client.SendOrg(message)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
// Try to nicely close connection,
|
|
|
|
|
|
|
|
// even if there was an error sending.
|
|
|
|
|
|
|
|
_ = client.Close()
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// After sending the message, leave the Muc
|
|
|
|
|
|
|
|
_, err = client.LeaveMUC(recipients[0])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for a short time as some messages are not delievered by the server
|
|
|
|
|
|
|
|
// if the connection is closed immediately after sending a message.
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send message to chatroom(s) if the flag is set.
|
|
|
|
// Send message to chatroom(s) if the flag is set.
|
|
|
|
if *flagChatroom {
|
|
|
|
if *flagChatroom {
|
|
|
|
|
|
|
|
|
|
|
@ -450,6 +483,21 @@ func main() {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// If the chatroom flag is not set, send message to contact(s).
|
|
|
|
// If the chatroom flag is not set, send message to contact(s).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send raw XML
|
|
|
|
|
|
|
|
if *flagRaw {
|
|
|
|
|
|
|
|
_, err = client.SendOrg(message)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
// Try to nicely close connection,
|
|
|
|
|
|
|
|
// even if there was an error sending.
|
|
|
|
|
|
|
|
_ = client.Close()
|
|
|
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for a short time as some messages are not delievered by the server
|
|
|
|
|
|
|
|
// if the connection is closed immediately after sending a message.
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send in endless loop (for usage with e.g. "tail -f").
|
|
|
|
// Send in endless loop (for usage with e.g. "tail -f").
|
|
|
|
if *flagInteractive {
|
|
|
|
if *flagInteractive {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|