Make sending of OOB URLs more robust.

singlequotes
Martin Dosch 1 year ago
parent d481aa688c
commit 4fbd7efb91
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -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) {

@ -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…
Cancel
Save