mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-18 21:25:31 +00:00
Make sending of OOB URLs more robust.
This commit is contained in:
parent
d481aa688c
commit
4fbd7efb91
@ -24,10 +24,10 @@ func validUTF8(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func validURI(s string) (string, error) {
|
||||
func validURI(s string) (*url.URL, error) {
|
||||
// Check if URI is valid
|
||||
_, err := url.ParseRequestURI(s)
|
||||
return s, err
|
||||
uri, err := url.ParseRequestURI(s)
|
||||
return uri, err
|
||||
}
|
||||
|
||||
func readFile(path string) (*bytes.Buffer, error) {
|
||||
|
15
main.go
15
main.go
@ -396,10 +396,11 @@ func main() {
|
||||
// Remove invalid UTF8 code points.
|
||||
message = validUTF8(*flagOOBFile)
|
||||
// Check if the URI is valid.
|
||||
_, err := validURI(message)
|
||||
uri, err := validURI(message)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
message = uri.String()
|
||||
}
|
||||
|
||||
var msgType string
|
||||
@ -545,13 +546,23 @@ func main() {
|
||||
break
|
||||
}
|
||||
switch {
|
||||
case *flagHTTPUpload != "" || *flagOOBFile != "":
|
||||
case *flagHTTPUpload != "":
|
||||
_, err = client.Send(xmpp.Chat{Remote: recipient.Jid,
|
||||
Type: msgType, Ooburl: message, Text: message})
|
||||
if err != nil {
|
||||
fmt.Println("Couldn't send message to",
|
||||
recipient.Jid)
|
||||
}
|
||||
// (Hopefully) temporary workaround due to go-xmpp choking on URL encoding.
|
||||
// Once this is fixed in the lib the http-upload case above can be reused.
|
||||
case *flagOOBFile != "":
|
||||
_, err = client.SendOrg("<message to='" + recipient.Jid + "' type='" +
|
||||
msgType + "'><body>" + message + "</body><x xmlns='jabber:x:oob'><url>" +
|
||||
message + "</url></x></message>")
|
||||
if err != nil {
|
||||
fmt.Println("Couldn't send message to",
|
||||
recipient.Jid)
|
||||
}
|
||||
case *flagOx:
|
||||
if recipient.OxKeyRing == nil {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user