Commit c6894b4c authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixed file transfer

parent 1fa52f70
......@@ -225,10 +225,7 @@ void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_co
content.setBody(linphone_content_get_string_buffer(c_content));
}
content.setContentDisposition(linphone_content_get_name(c_content));
// This is a ugly workaround required to be able to get the total size of the file in the content
vector<char> empty(linphone_content_get_size(c_content));
content.setBody(empty);
content.setExpectedSize(linphone_content_get_size(c_content));
q->addContent(content);
}
......@@ -423,7 +420,7 @@ int ChatMessagePrivate::onSendBody (
// if we've not reach the end of file yet, ask for more data
// in case of file body handler, won't be called
if (fileTransferFilePath.empty() && offset < currentFileTransferContent->getSize()) {
if (fileTransferFilePath.empty() && offset < currentFileTransferContent->getExpectedSize()) {
// get data from call back
LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
LinphoneChatMessageCbsFileTransferSendCb file_transfer_send_cb =
......@@ -696,7 +693,7 @@ void ChatMessagePrivate::processResponseFromPostFile (const belle_http_response_
}
// create a user body handler to take care of the file and add the content disposition and content-type headers
first_part_bh = (belle_sip_body_handler_t *)belle_sip_user_body_handler_new(currentFileTransferContent->getSize(),
first_part_bh = (belle_sip_body_handler_t *)belle_sip_user_body_handler_new(currentFileTransferContent->getExpectedSize(),
_chat_message_file_transfer_on_progress, nullptr, nullptr,
_chat_message_on_send_body, _chat_message_on_send_end, this);
if (!fileTransferFilePath.empty()) {
......@@ -829,10 +826,8 @@ static Content createFileTransferInformationFromHeaders (const belle_sip_message
ContentType contentType(type, subtype);
}
if (content_length_hdr) {
// This is a ugly workaround required to be able to get the total size of the file in the content
vector<char> empty(belle_sip_header_content_length_get_content_length(content_length_hdr));
content.setBody(empty);
lInfo() << "Extracted content length " << content.getSize() << " from header";
content.setExpectedSize(belle_sip_header_content_length_get_content_length(content_length_hdr));
lInfo() << "Extracted content length " << content.getExpectedSize() << " from header";
}
return content;
......@@ -854,14 +849,12 @@ void ChatMessagePrivate::processResponseHeadersFromGetFile (const belle_http_res
q->addContent(content);
} else {
belle_sip_header_content_length_t *content_length_hdr = BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(response, "Content-Length"));
// This is a ugly workaround required to be able to get the total size of the file in the content
vector<char> empty(belle_sip_header_content_length_get_content_length(content_length_hdr));
currentFileTransferContent->setBody(empty);
lInfo() << "Extracted content length " << currentFileTransferContent->getSize() << " from header";
currentFileTransferContent->setExpectedSize(belle_sip_header_content_length_get_content_length(content_length_hdr));
lInfo() << "Extracted content length " << currentFileTransferContent->getExpectedSize() << " from header";
}
if (q->hasFileTransferContent()) {
body_size = q->getFileTransferContent().getSize();
body_size = q->getFileTransferContent().getExpectedSize();
}
body_handler = (belle_sip_body_handler_t *)belle_sip_user_body_handler_new(body_size, _chat_message_file_transfer_on_progress,
......@@ -1037,9 +1030,7 @@ void ChatMessagePrivate::createFileTransferInformationsFromVndGsmaRcsFtHttpXml (
if (!xmlStrcmp(cur->name, (const xmlChar *)"file-size")) {
xmlChar *fileSizeString = xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1);
size_t size = (size_t)strtol((const char *)fileSizeString, nullptr, 10);
// This is a ugly workaround required to be able to get the total size of the file in the content
vector<char> empty(size);
content.setBody(empty);
content.setExpectedSize(size);
xmlFree(fileSizeString);
}
......
......@@ -34,6 +34,7 @@ public:
vector<char> body;
ContentType contentType;
string contentDisposition;
size_t expectedSize;
};
const Content Content::Empty;
......@@ -47,6 +48,7 @@ Content::Content (const Content &src) : ClonableObject(*new ContentPrivate), App
d->body = src.getBody();
d->contentType = src.getContentType();
d->contentDisposition = src.getContentDisposition();
d->expectedSize = src.getExpectedSize();
}
Content::Content (Content &&src) : ClonableObject(*new ContentPrivate), AppDataContainer(move(src)) {
......@@ -54,6 +56,7 @@ Content::Content (Content &&src) : ClonableObject(*new ContentPrivate), AppDataC
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
d->contentDisposition = move(src.getPrivate()->contentDisposition);
d->expectedSize = move(src.getExpectedSize());
}
Content &Content::operator= (const Content &src) {
......@@ -62,6 +65,7 @@ Content &Content::operator= (const Content &src) {
d->body = src.getBody();
d->contentType = src.getContentType();
d->contentDisposition = src.getContentDisposition();
d->expectedSize = src.getExpectedSize();
AppDataContainer::operator=(src);
}
......@@ -73,6 +77,7 @@ Content &Content::operator= (Content &&src) {
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
d->contentDisposition = move(src.getPrivate()->contentDisposition);
d->expectedSize = move(src.getExpectedSize());
AppDataContainer::operator=(move(src));
return *this;
}
......@@ -145,6 +150,16 @@ size_t Content::getSize () const {
return d->body.size();
}
void Content::setExpectedSize(size_t expectedSize) {
L_D();
d->expectedSize = expectedSize;
}
size_t Content::getExpectedSize() const {
L_D();
return d->expectedSize;
}
bool Content::isEmpty () const {
return getSize() == 0;
}
......@@ -159,7 +174,7 @@ LinphoneContent * Content::toLinphoneContent() const {
content = linphone_core_create_content(NULL);
linphone_content_set_type(content, getContentType().getType().c_str());
linphone_content_set_subtype(content, getContentType().getSubType().c_str());
linphone_content_set_size(content, getSize());
linphone_content_set_size(content, getExpectedSize());
linphone_content_set_name(content, getContentDisposition().c_str());
return content;
}
......
......@@ -60,6 +60,9 @@ public:
size_t getSize () const;
void setExpectedSize(size_t expectedSize);
size_t getExpectedSize() const;
bool isValid() const;
bool isEmpty () const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment