Commit 88fe8d00 authored by jehan's avatar jehan
Browse files

make sure IP encryption Engine API can be used without needing to include any private headers

parent 76472182
......@@ -1609,6 +1609,17 @@ const char *linphone_chat_message_get_text(const LinphoneChatMessage *msg) {
return msg->message;
}
int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text) {
if (msg->message)
ms_free(msg->message);
if (text)
msg->message = ms_strdup(text);
else
msg->message = NULL;
return 0;
}
void linphone_chat_message_add_custom_header(LinphoneChatMessage *msg, const char *header_name,
const char *header_value) {
msg->custom_headers = sal_custom_header_append(msg->custom_headers, header_name, header_value);
......
......@@ -66,10 +66,10 @@ void linphone_im_encryption_engine_cbs_set_user_data(LinphoneImEncryptionEngineC
cbs->user_data = data;
}
LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(LinphoneCore *lc) {
LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(void) {
LinphoneImEncryptionEngine *imee = belle_sip_object_new(LinphoneImEncryptionEngine);
belle_sip_object_ref(imee);
imee->lc = lc;
imee->lc = NULL;
imee->callbacks = linphone_im_encryption_engine_cbs_new();
return imee;
}
......
......@@ -2410,7 +2410,7 @@ bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
}
void linphone_core_enable_lime(LinphoneCore *lc, LinphoneLimeState val){
LinphoneImEncryptionEngine *imee = linphone_im_encryption_engine_new(lc);
LinphoneImEncryptionEngine *imee = linphone_im_encryption_engine_new();
LinphoneImEncryptionEngineCbs *cbs = linphone_im_encryption_engine_get_callbacks(imee);
if(lime_is_available()){
......@@ -7259,6 +7259,7 @@ void linphone_core_set_im_encryption_engine(LinphoneCore *lc, LinphoneImEncrypti
lc->im_encryption_engine = NULL;
}
if (imee) {
imee->lc = lc;
lc->im_encryption_engine = linphone_im_encryption_engine_ref(imee);
}
}
......
......@@ -1753,8 +1753,6 @@ struct _LinphoneImEncryptionEngine {
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneImEncryptionEngine);
LINPHONE_PUBLIC LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(LinphoneCore *lc);
struct _LinphoneRange {
belle_sip_object_t base;
void *user_data;
......
......@@ -183,6 +183,19 @@ LINPHONE_PUBLIC LinphoneImEncryptionEngineCbsGenerateFileTransferKeyCb linphone_
*/
LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_set_generate_file_transfer_key(LinphoneImEncryptionEngineCbs *cbs, LinphoneImEncryptionEngineCbsGenerateFileTransferKeyCb cb);
/** Set a chat message text to be sent by #linphone_chat_room_send_message
* @param[in] msg LinphoneChatMessage
* @param[in] text Const char *
* @returns 0 if succeed.
*/
LINPHONE_PUBLIC int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text);
/**
* Create the IM encryption engine
* @return The created the IM encryption engine
*/
LINPHONE_PUBLIC LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(void);
/**
* @}
*/
......
......@@ -2298,19 +2298,19 @@ void text_message_with_custom_content_type_and_lime(void) {
static int im_encryption_engine_process_incoming_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
if (msg->content_type) {
if (strcmp(msg->content_type, "cipher/b64") == 0) {
if (linphone_chat_message_get_content_type(msg)) {
if (strcmp(linphone_chat_message_get_content_type(msg), "cipher/b64") == 0) {
size_t b64Size = 0;
unsigned char *output;
bctbx_base64_decode(NULL, &b64Size, (unsigned char *)msg->message, strlen(msg->message));
bctbx_base64_decode(NULL, &b64Size, (unsigned char *)linphone_chat_message_get_text(msg), strlen(linphone_chat_message_get_text(msg)));
output = (unsigned char *)ms_malloc(b64Size+1),
bctbx_base64_decode(output, &b64Size, (unsigned char *)msg->message, strlen(msg->message));
ms_free (msg->message);
bctbx_base64_decode(output, &b64Size, (unsigned char *)linphone_chat_message_get_text(msg), strlen(linphone_chat_message_get_text(msg)));
output[b64Size] = '\0';
msg->message = (char *)output;
linphone_chat_message_set_text(msg, (char *)output);
ms_free(output);
linphone_chat_message_set_content_type(msg, "text/plain");
return 0;
} else if (strcmp(msg->content_type, "text/plain") == 0) {
} else if (strcmp(linphone_chat_message_get_content_type(msg), "text/plain") == 0) {
return -1; // Not encrypted, nothing to do
} else {
return 488; // Not acceptable
......@@ -2320,15 +2320,15 @@ static int im_encryption_engine_process_incoming_message_cb(LinphoneImEncryption
}
static int im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
if (strcmp(msg->content_type,"text/plain") == 0) {
if (strcmp(linphone_chat_message_get_content_type(msg),"text/plain") == 0) {
size_t b64Size = 0;
unsigned char *output;
bctbx_base64_encode(NULL, &b64Size, (unsigned char *)msg->message, strlen(msg->message));
bctbx_base64_encode(NULL, &b64Size, (unsigned char *)linphone_chat_message_get_text(msg), strlen(linphone_chat_message_get_text(msg)));
output = (unsigned char *)ms_malloc0(b64Size+1),
bctbx_base64_encode(output, &b64Size, (unsigned char *)msg->message, strlen(msg->message));
ms_free (msg->message);
bctbx_base64_encode(output, &b64Size, (unsigned char *)linphone_chat_message_get_text(msg), strlen(linphone_chat_message_get_text(msg)));
output[b64Size] = '\0';
msg->message = (char *)output;
linphone_chat_message_set_text(msg,(const char*)output);
ms_free(output);
linphone_chat_message_set_content_type(msg, "cipher/b64");
return 0;
}
......@@ -2339,10 +2339,10 @@ void im_encryption_engine_b64(void) {
LinphoneChatMessage *chat_msg = NULL;
LinphoneChatRoom* chat_room = NULL;
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneImEncryptionEngine *marie_imee = linphone_im_encryption_engine_new(marie->lc);
LinphoneImEncryptionEngine *marie_imee = linphone_im_encryption_engine_new();
LinphoneImEncryptionEngineCbs *marie_cbs = linphone_im_encryption_engine_get_callbacks(marie_imee);
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
LinphoneImEncryptionEngine *pauline_imee = linphone_im_encryption_engine_new(pauline->lc);
LinphoneImEncryptionEngine *pauline_imee = linphone_im_encryption_engine_new();
LinphoneImEncryptionEngineCbs *pauline_cbs = linphone_im_encryption_engine_get_callbacks(pauline_imee);
linphone_im_encryption_engine_cbs_set_process_incoming_message(marie_cbs, im_encryption_engine_process_incoming_message_cb);
......
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