Use xml.Marshal to safely build HTTP Upload <request>

Am I doing this Go thing correctly?
v0.1
Kim Alvefur 3 years ago committed by Martin Dosch
parent 02137f4327
commit c43fdc3066

@ -70,6 +70,14 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
} `xml:"x"`
}
type IQHttpUploadSlotRequest struct {
XMLName xml.Name `xml:"request"`
Xmlns string `xml:"xmlns,attr"`
FileName string `xml:"filename,attr"`
FileType string `xml:"mime-type,attr"`
FileSize int64 `xml:"size,attr"`
}
// Created with https://github.com/miku/zek
type IQHttpUploadSlot struct {
XMLName xml.Name `xml:"slot"`
@ -194,14 +202,22 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
}
}
var request IQHttpUploadSlotRequest
request.Xmlns = "urn:xmpp:http:upload:0"
request.FileName = fileName
request.FileSize = fileSize
request.FileType = mimeType
r, err := xml.Marshal(request)
if err != nil {
log.Fatal(err)
}
// Request http upload slot
id = getID()
c = make(chan xmpp.IQ)
go getIQ(client, id, c)
_, err = client.RawInformation(client.JID(), uploadComponent, id, "get",
"<request xmlns='urn:xmpp:http:upload:0' filename='"+
fileNameEscaped.String()+"' size='"+strconv.FormatInt(fileSize, 10)+
"' content-type='"+mimeTypeEscaped.String()+"' />")
_, err = client.RawInformation(client.JID(), uploadComponent, id, "get", string(r))
if err != nil {
log.Fatal(err)
}

Loading…
Cancel
Save