|
|
|
@ -28,6 +28,7 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
) (string, error) {
|
|
|
|
|
var uploadComponent string
|
|
|
|
|
var maxFileSize int64
|
|
|
|
|
var iqDiscoItemsXMLQuery, iqDiscoInfoXMLQuery *etree.Element
|
|
|
|
|
|
|
|
|
|
// Get file size
|
|
|
|
|
fileInfo, err := os.Stat(filePath)
|
|
|
|
@ -65,7 +66,7 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
iqDiscoItemsXMLQuery := iqDiscoItemsXML.SelectElement("query")
|
|
|
|
|
iqDiscoItemsXMLQuery = iqDiscoItemsXML.SelectElement("query")
|
|
|
|
|
if iqDiscoItemsXMLQuery == nil {
|
|
|
|
|
return "", errors.New("http-upload: no query element in disco items reply")
|
|
|
|
|
}
|
|
|
|
@ -94,7 +95,7 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
iqDiscoInfoXMLQuery := iqDiscoInfoXML.SelectElement("query")
|
|
|
|
|
iqDiscoInfoXMLQuery = iqDiscoInfoXML.SelectElement("query")
|
|
|
|
|
if iqDiscoInfoXMLQuery == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -113,12 +114,13 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
if iqDiscoInfoXMLType.Value == "file" &&
|
|
|
|
|
iqDiscoInfoXMLCategory.Value == "store" {
|
|
|
|
|
uploadComponent = jid.Value
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if uploadComponent == "" {
|
|
|
|
|
return "", errors.New("http-upload: no http upload component found.")
|
|
|
|
|
}
|
|
|
|
|
iqDiscoInfoXMLX := iqDiscoItemsXMLQuery.SelectElements("X")
|
|
|
|
|
iqDiscoInfoXMLX := iqDiscoInfoXMLQuery.SelectElements("x")
|
|
|
|
|
for _, r := range iqDiscoInfoXMLX {
|
|
|
|
|
field := r.SelectElements("field")
|
|
|
|
|
for i, t := range field {
|
|
|
|
@ -126,18 +128,20 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
if varAttr == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
prevFieldVal := field[i-1].SelectElement("value")
|
|
|
|
|
if prevFieldVal == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
curFieldVal := t.SelectElement("value")
|
|
|
|
|
if curFieldVal == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if varAttr.Value == "max-file-size" && prevFieldVal.Text() == nsHTTPUpload {
|
|
|
|
|
maxFileSize, err = strconv.ParseInt(curFieldVal.Text(), 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.New("http-upload: error while checking server maximum http upload file size.")
|
|
|
|
|
if varAttr.Value == "max-file-size" {
|
|
|
|
|
prevFieldVal := field[i-1].SelectElement("value")
|
|
|
|
|
if prevFieldVal == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if prevFieldVal.Text() == nsHTTPUpload {
|
|
|
|
|
maxFileSize, err = strconv.ParseInt(curFieldVal.Text(), 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.New("http-upload: error while checking server maximum http upload file size.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -244,7 +248,7 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
|
|
|
|
|
}
|
|
|
|
|
err = resp.Body.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("error while closing http request body:", err)
|
|
|
|
|
fmt.Println("http-upload: error while closing http request body:", err)
|
|
|
|
|
}
|
|
|
|
|
return iqHTTPUploadSlotXMLGetURL.Value, nil
|
|
|
|
|
}
|
|
|
|
|