mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 19:18:06 +00:00
Reworked API for im encryption engine for file download + added test for file body handler
This commit is contained in:
parent
c284239d54
commit
127d52d72d
6 changed files with 37 additions and 69 deletions
|
|
@ -352,9 +352,9 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t
|
|||
imee = linphone_core_get_im_encryption_engine(lc);
|
||||
if (imee) {
|
||||
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
LinphoneImEncryptionEngineDownloadingFileBufferCb cb_process_downloading_file_buffer = linphone_im_encryption_engine_cbs_get_process_downloading_file_buffer(imee_cbs);
|
||||
if (cb_process_downloading_file_buffer) {
|
||||
retval = cb_process_downloading_file_buffer(lc, msg, (const char *)buffer, size, &decrypted_buffer);
|
||||
LinphoneImEncryptionEngineDownloadingFileCb cb_process_downloading_file = linphone_im_encryption_engine_cbs_get_process_downloading_file(imee_cbs);
|
||||
if (cb_process_downloading_file) {
|
||||
retval = cb_process_downloading_file(lc, msg, (const char *)buffer, size, &decrypted_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -453,30 +453,44 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle
|
|||
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(lc);
|
||||
if (imee) {
|
||||
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
|
||||
if (msg->file_transfer_filepath == NULL) {
|
||||
LinphoneImEncryptionEngineDownloadingFileBufferCb cb_process_downloading_file_buffer = linphone_im_encryption_engine_cbs_get_process_downloading_file_buffer(imee_cbs);
|
||||
if (cb_process_downloading_file_buffer) {
|
||||
retval = cb_process_downloading_file_buffer(lc, msg, NULL, 0, NULL);
|
||||
}
|
||||
} else {
|
||||
LinphoneImEncryptionEngineDownloadingFileCb cb_process_downloading_file = linphone_im_encryption_engine_cbs_get_process_downloading_file(imee_cbs);
|
||||
if (cb_process_downloading_file) {
|
||||
retval = cb_process_downloading_file(lc, msg, msg->file_transfer_filepath);
|
||||
LinphoneImEncryptionEngineDownloadingFileCb cb_process_downloading_file = linphone_im_encryption_engine_cbs_get_process_downloading_file(imee_cbs);
|
||||
if (cb_process_downloading_file) {
|
||||
if (msg->file_transfer_filepath == NULL) {
|
||||
retval = cb_process_downloading_file(lc, msg, NULL, 0, NULL);
|
||||
} else {
|
||||
bctbx_vfs_t *vfs = bctbx_vfs_get_default();
|
||||
bctbx_vfs_file_t *decrypted_file;
|
||||
bctbx_vfs_file_t *encrypted_file = bctbx_file_open(vfs, msg->file_transfer_filepath, "r");
|
||||
size_t encrypted_file_size = (size_t)bctbx_file_size(encrypted_file);
|
||||
char *encrypted_content = bctbx_malloc(encrypted_file_size);
|
||||
char *decrypted_content = bctbx_malloc(encrypted_file_size);
|
||||
retval = (int)bctbx_file_read(encrypted_file, encrypted_content, encrypted_file_size, 0);
|
||||
bctbx_file_close(encrypted_file);
|
||||
if (retval != BCTBX_VFS_ERROR && retval == (int)encrypted_file_size) {
|
||||
retval = cb_process_downloading_file(lc, msg, encrypted_content, encrypted_file_size, &decrypted_content);
|
||||
cb_process_downloading_file(lc, msg, NULL, 0, NULL);
|
||||
decrypted_file = bctbx_file_open(vfs, msg->file_transfer_filepath, "w");
|
||||
bctbx_file_write(decrypted_file, decrypted_content, encrypted_file_size, 0);
|
||||
bctbx_file_close(decrypted_file);
|
||||
} else {
|
||||
ms_error("file %s read failed: expected %d, got %d", msg->file_transfer_filepath, (int)encrypted_file_size, retval);
|
||||
retval = 500;
|
||||
}
|
||||
bctbx_free(encrypted_content);
|
||||
bctbx_free(decrypted_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (msg->file_transfer_filepath == NULL) {
|
||||
if (retval <= 0) {
|
||||
if (linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)) {
|
||||
LinphoneBuffer *lb = linphone_buffer_new();
|
||||
linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)(msg, msg->file_transfer_information, lb);
|
||||
linphone_buffer_unref(lb);
|
||||
} else {
|
||||
/* Legacy: call back given by application level */
|
||||
linphone_core_notify_file_transfer_recv(lc, msg, msg->file_transfer_information, NULL, 0);
|
||||
}
|
||||
} else {
|
||||
linphone_core_notify_file_transfer_recv(lc, msg, msg->file_transfer_information, NULL, 0);
|
||||
}
|
||||
|
||||
if (retval <= 0) {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
struct _LinphoneImEncryptionEngineCbs {
|
||||
void *user_data;
|
||||
LinphoneImEncryptionEngineIncomingMessageCb process_incoming_message;
|
||||
LinphoneImEncryptionEngineDownloadingFileBufferCb process_downlading_file_buffer;
|
||||
LinphoneImEncryptionEngineDownloadingFileCb process_downloading_file;
|
||||
LinphoneImEncryptionEngineDownloadingFileCb process_downlading_file;
|
||||
LinphoneImEncryptionEngineOutgoingMessageCb process_outgoing_message;
|
||||
};
|
||||
|
||||
|
|
@ -89,18 +88,10 @@ void linphone_im_encryption_engine_cbs_set_process_outgoing_message(LinphoneImEn
|
|||
cbs->process_outgoing_message = cb;
|
||||
}
|
||||
|
||||
LinphoneImEncryptionEngineDownloadingFileBufferCb linphone_im_encryption_engine_cbs_get_process_downloading_file_buffer(LinphoneImEncryptionEngineCbs *cbs) {
|
||||
return cbs->process_downlading_file_buffer;
|
||||
}
|
||||
|
||||
void linphone_im_encryption_engine_cbs_set_process_downloading_file_buffer(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineDownloadingFileBufferCb cb) {
|
||||
cbs->process_downlading_file_buffer = cb;
|
||||
}
|
||||
|
||||
LinphoneImEncryptionEngineDownloadingFileCb linphone_im_encryption_engine_cbs_get_process_downloading_file(LinphoneImEncryptionEngineCbs *cbs) {
|
||||
return cbs->process_downloading_file;
|
||||
return cbs->process_downlading_file;
|
||||
}
|
||||
|
||||
void linphone_im_encryption_engine_cbs_set_process_downloading_file(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineDownloadingFileCb cb) {
|
||||
cbs->process_downloading_file = cb;
|
||||
cbs->process_downlading_file = cb;
|
||||
}
|
||||
|
|
@ -30,9 +30,7 @@ typedef int (*LinphoneImEncryptionEngineIncomingMessageCb)(LinphoneCore* lc, bel
|
|||
|
||||
typedef int (*LinphoneImEncryptionEngineOutgoingMessageCb)(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length);
|
||||
|
||||
typedef int (*LinphoneImEncryptionEngineDownloadingFileBufferCb)(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer);
|
||||
|
||||
typedef int (*LinphoneImEncryptionEngineDownloadingFileCb)(LinphoneCore *lc, LinphoneChatMessage *msg, const char *path);
|
||||
typedef int (*LinphoneImEncryptionEngineDownloadingFileCb)(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer);
|
||||
|
||||
typedef struct _LinphoneImEncryptionEngineCbs LinphoneImEncryptionEngineCbs;
|
||||
|
||||
|
|
@ -64,10 +62,6 @@ LINPHONE_PUBLIC LinphoneImEncryptionEngineOutgoingMessageCb linphone_im_encrypti
|
|||
|
||||
LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_set_process_outgoing_message(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineOutgoingMessageCb cb);
|
||||
|
||||
LINPHONE_PUBLIC LinphoneImEncryptionEngineDownloadingFileBufferCb linphone_im_encryption_engine_cbs_get_process_downloading_file_buffer(LinphoneImEncryptionEngineCbs *cbs);
|
||||
|
||||
LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_set_process_downloading_file_buffer(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineDownloadingFileBufferCb cb);
|
||||
|
||||
LINPHONE_PUBLIC LinphoneImEncryptionEngineDownloadingFileCb linphone_im_encryption_engine_cbs_get_process_downloading_file(LinphoneImEncryptionEngineCbs *cbs);
|
||||
|
||||
LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_set_process_downloading_file(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineDownloadingFileCb cb);
|
||||
|
|
|
|||
|
|
@ -929,7 +929,7 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, bell
|
|||
return errcode;
|
||||
}
|
||||
|
||||
int lime_im_encryption_engine_process_downloading_file_buffer_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer) {
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer) {
|
||||
if (linphone_content_get_key(msg->file_transfer_information) == NULL) return -1;
|
||||
|
||||
if (buffer == NULL || size == 0) {
|
||||
|
|
@ -941,31 +941,6 @@ int lime_im_encryption_engine_process_downloading_file_buffer_cb(LinphoneCore *l
|
|||
(char *)buffer);
|
||||
}
|
||||
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *path) {
|
||||
if (linphone_content_get_key(msg->file_transfer_information) == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
bctbx_vfs_t *vfs = bctbx_vfs_get_default();
|
||||
bctbx_vfs_file_t *decrypted_file;
|
||||
bctbx_vfs_file_t *encrypted_file = bctbx_file_open(vfs, msg->file_transfer_filepath, "r");
|
||||
size_t encrypted_file_size = (size_t)bctbx_file_size(encrypted_file);
|
||||
char *encrypted_content = bctbx_malloc(encrypted_file_size);
|
||||
char *decrypted_content = bctbx_malloc(encrypted_file_size);
|
||||
bctbx_file_read(encrypted_file, encrypted_content, encrypted_file_size, 0);
|
||||
bctbx_file_close(encrypted_file);
|
||||
lime_decryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information),
|
||||
(unsigned char *)linphone_content_get_key(msg->file_transfer_information),
|
||||
encrypted_file_size, decrypted_content, encrypted_content);
|
||||
lime_decryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), NULL, 0, NULL, NULL);
|
||||
decrypted_file = bctbx_file_open(vfs, msg->file_transfer_filepath, "w");
|
||||
bctbx_file_write(decrypted_file, decrypted_content, encrypted_file_size, 0);
|
||||
bctbx_file_close(decrypted_file);
|
||||
bctbx_free(encrypted_content);
|
||||
bctbx_free(decrypted_content);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_LIME */
|
||||
|
||||
bool_t lime_is_available() { return FALSE; }
|
||||
|
|
@ -996,10 +971,7 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, bell
|
|||
int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length) {
|
||||
return 500;
|
||||
}
|
||||
int lime_im_encryption_engine_process_downloading_file_buffer_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer) {
|
||||
return 500;
|
||||
}
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *path) {
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer) {
|
||||
return 500;
|
||||
}
|
||||
#endif /* HAVE_LIME */
|
||||
|
|
|
|||
|
|
@ -209,8 +209,6 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, bell
|
|||
|
||||
int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length);
|
||||
|
||||
int lime_im_encryption_engine_process_downloading_file_buffer_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer);
|
||||
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *path);
|
||||
int lime_im_encryption_engine_process_downloading_file_cb(LinphoneCore *lc, LinphoneChatMessage *msg, const char *buffer, size_t size, char **decrypted_buffer);
|
||||
|
||||
#endif /* LIME_H */
|
||||
|
|
|
|||
|
|
@ -1956,7 +1956,6 @@ void linphone_core_enable_lime(LinphoneCore *lc, LinphoneLimeState val){
|
|||
LinphoneImEncryptionEngineCbs *cbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
linphone_im_encryption_engine_cbs_set_process_incoming_message(cbs, lime_im_encryption_engine_process_incoming_message_cb);
|
||||
linphone_im_encryption_engine_cbs_set_process_outgoing_message(cbs, lime_im_encryption_engine_process_outgoing_message_cb);
|
||||
linphone_im_encryption_engine_cbs_set_process_downloading_file_buffer(cbs, lime_im_encryption_engine_process_downloading_file_buffer_cb);
|
||||
linphone_im_encryption_engine_cbs_set_process_downloading_file(cbs, lime_im_encryption_engine_process_downloading_file_cb);
|
||||
lc->im_encryption_engine = imee;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue