|
|
@ -90,8 +90,9 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
|
|
|
|
|
|
|
|
|
|
|
|
var iqDiscoItemsXML IQDiscoItemsType
|
|
|
|
var iqDiscoItemsXML IQDiscoItemsType
|
|
|
|
var iqDiscoInfoXML IQDiscoInfoType
|
|
|
|
var iqDiscoInfoXML IQDiscoInfoType
|
|
|
|
var uploadComponent string
|
|
|
|
|
|
|
|
var iqHttpUploadSlotXML IQHttpUploadSlot
|
|
|
|
var iqHttpUploadSlotXML IQHttpUploadSlot
|
|
|
|
|
|
|
|
var uploadComponent string
|
|
|
|
|
|
|
|
var maxFileSize int64
|
|
|
|
|
|
|
|
|
|
|
|
// Get file size
|
|
|
|
// Get file size
|
|
|
|
fileInfo, err := os.Stat(filePath)
|
|
|
|
fileInfo, err := os.Stat(filePath)
|
|
|
@ -158,19 +159,29 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if uploadComponent == "" {
|
|
|
|
if uploadComponent == "" {
|
|
|
|
log.Fatal("No http upload component found.")
|
|
|
|
log.Fatal("No http upload component found.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxFileSize, err := strconv.ParseInt(iqDiscoInfoXML.X[1].Field[1].Value, 10, 64)
|
|
|
|
for _, r := range iqDiscoInfoXML.X {
|
|
|
|
|
|
|
|
for _, t := range r.Field {
|
|
|
|
|
|
|
|
if t.Var == "max-file-size" {
|
|
|
|
|
|
|
|
maxFileSize, err = strconv.ParseInt(t.Value, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error while checking server maximum http upload file size.")
|
|
|
|
log.Fatal("Error while checking server maximum http upload file size.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the file size doesn't exceed the maximum file size of the http upload
|
|
|
|
|
|
|
|
// component if a maximum file size is reported, if not just continue and hope for
|
|
|
|
|
|
|
|
// the best.
|
|
|
|
|
|
|
|
if maxFileSize != 0 {
|
|
|
|
if fileSize > maxFileSize {
|
|
|
|
if fileSize > maxFileSize {
|
|
|
|
log.Fatal("File size " + strconv.FormatInt(fileSize/1024/1024, 10) +
|
|
|
|
log.Fatal("File size " + strconv.FormatInt(fileSize/1024/1024, 10) +
|
|
|
|
" MB is larger than the maximum file size allowed (" +
|
|
|
|
" MB is larger than the maximum file size allowed (" +
|
|
|
|
strconv.FormatInt(maxFileSize/1024/1024, 10) + " MB).")
|
|
|
|
strconv.FormatInt(maxFileSize/1024/1024, 10) + " MB).")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Request http upload slot
|
|
|
|
// Request http upload slot
|
|
|
|
id = getID()
|
|
|
|
id = getID()
|
|
|
|