diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index f58c2a77f..a26e39403 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1252,18 +1252,7 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){ } // check that the message does not belong to an already destroyed chat room - if so, do not invoke callbacks if (chat_msg->chat_room != NULL) { - chat_msg->state=chatStatusSal2Linphone(status); - linphone_chat_message_update_state(chat_msg); - - if (chat_msg && (chat_msg->cb || (chat_msg->callbacks && linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)))) { - ms_message("Notifying text delivery with status %s",linphone_chat_message_state_to_string(chat_msg->state)); - if (chat_msg->callbacks && linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)(chat_msg, chat_msg->state); - } else { - /* Legacy */ - chat_msg->cb(chat_msg,chat_msg->state,chat_msg->cb_ud); - } - } + linphone_chat_message_update_state(chat_msg, chatStatusSal2Linphone(status)); } if (status != SalTextDeliveryInProgress) { /*only release op if not in progress*/ linphone_chat_message_destroy(chat_msg); diff --git a/coreapi/chat.c b/coreapi/chat.c index 767433e4a..73f01f374 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -39,23 +39,35 @@ #define FILE_TRANSFER_KEY_SIZE 32 - static void linphone_chat_message_release(LinphoneChatMessage *msg); -static LinphoneChatMessageCbs * linphone_chat_message_cbs_new(void) { +static LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void) { return belle_sip_object_new(LinphoneChatMessageCbs); } BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatMessageCbs); BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatMessageCbs, belle_sip_object_t, - NULL, // destroy - NULL, // clone - NULL, // marshal - FALSE -); + NULL, // destroy + NULL, // clone + NULL, // marshal + FALSE); -LinphoneChatMessageCbs * linphone_chat_message_cbs_ref(LinphoneChatMessageCbs *cbs) { +static void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state) { + if (state != msg->state) { + ms_message("Chat message %p: moving from state %s to %s", msg, linphone_chat_message_state_to_string(msg->state), + linphone_chat_message_state_to_string(state)); + msg->state = state; + if (msg->message_state_changed_cb) { + msg->message_state_changed_cb(msg, msg->state, msg->message_state_changed_user_data); + } + if (linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)) { + linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)(msg, msg->state); + } + } +} + +LinphoneChatMessageCbs *linphone_chat_message_cbs_ref(LinphoneChatMessageCbs *cbs) { belle_sip_object_ref(cbs); return cbs; } @@ -72,133 +84,142 @@ void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void * cbs->user_data = ud; } -LinphoneChatMessageCbsMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs) { +LinphoneChatMessageCbsMsgStateChangedCb +linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs) { return cbs->msg_state_changed; } -void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsMsgStateChangedCb cb) { +void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, + LinphoneChatMessageCbsMsgStateChangedCb cb) { cbs->msg_state_changed = cb; } -LinphoneChatMessageCbsFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs) { +LinphoneChatMessageCbsFileTransferRecvCb +linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs) { return cbs->file_transfer_recv; } -void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferRecvCb cb) { +void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, + LinphoneChatMessageCbsFileTransferRecvCb cb) { cbs->file_transfer_recv = cb; } -LinphoneChatMessageCbsFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs) { +LinphoneChatMessageCbsFileTransferSendCb +linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs) { return cbs->file_transfer_send; } -void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferSendCb cb) { +void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, + LinphoneChatMessageCbsFileTransferSendCb cb) { cbs->file_transfer_send = cb; } -LinphoneChatMessageCbsFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs) { +LinphoneChatMessageCbsFileTransferProgressIndicationCb +linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs) { return cbs->file_transfer_progress_indication; } -void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferProgressIndicationCb cb) { +void linphone_chat_message_cbs_set_file_transfer_progress_indication( + LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferProgressIndicationCb cb) { cbs->file_transfer_progress_indication = cb; } +static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); -static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg); - -static void process_io_error_upload(void *data, const belle_sip_io_error_event_t *event){ - LinphoneChatMessage* msg=(LinphoneChatMessage *)data; - ms_error("I/O Error during file upload to %s - msg [%p] chat room[%p]", linphone_core_get_file_transfer_server(msg->chat_room->lc), msg, msg->chat_room); +static void process_io_error_upload(void *data, const belle_sip_io_error_event_t *event) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + ms_error("I/O Error during file upload to %s - msg [%p] chat room[%p]", + linphone_core_get_file_transfer_server(msg->chat_room->lc), msg, msg->chat_room); linphone_chat_message_cancel_file_transfer(msg); } -static void process_auth_requested_upload(void *data, belle_sip_auth_event_t *event){ - LinphoneChatMessage* msg=(LinphoneChatMessage *)data; - ms_error("Error during file upload: auth requested to connect %s - msg [%p] chat room[%p]", linphone_core_get_file_transfer_server(msg->chat_room->lc), msg, msg->chat_room); +static void process_auth_requested_upload(void *data, belle_sip_auth_event_t *event) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + ms_error("Error during file upload: auth requested to connect %s - msg [%p] chat room[%p]", + linphone_core_get_file_transfer_server(msg->chat_room->lc), msg, msg->chat_room); linphone_chat_message_cancel_file_transfer(msg); } -static void process_io_error_download(void *data, const belle_sip_io_error_event_t *event){ - LinphoneChatMessage* msg=(LinphoneChatMessage *)data; +static void process_io_error_download(void *data, const belle_sip_io_error_event_t *event) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; ms_error("I/O Error during file download %s - msg [%p] chat room[%p]", msg->external_body_url, msg, msg->chat_room); - msg->state = LinphoneChatMessageStateFileTransferError; - if (msg->cb) { - msg->cb(msg, msg->state, msg->cb_ud); - } - if (linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)(msg, msg->state); - } + linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferError); } -static void process_auth_requested_download(void *data, belle_sip_auth_event_t *event){ - LinphoneChatMessage* msg=(LinphoneChatMessage *)data; - msg->state = LinphoneChatMessageStateFileTransferError; - ms_error("Error during file download : auth requested to get %s - msg [%p] chat room[%p]", msg->external_body_url, msg, msg->chat_room); - if (msg->cb) { - msg->cb(msg, msg->state, msg->cb_ud); - } - if (linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)(msg, msg->state); - } +static void process_auth_requested_download(void *data, belle_sip_auth_event_t *event) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferError); + ms_error("Error during file download : auth requested to get %s - msg [%p] chat room[%p]", msg->external_body_url, + msg, msg->chat_room); } -static void linphone_chat_message_file_transfer_on_progress(belle_sip_body_handler_t *bh, belle_sip_message_t *msg, void *data, size_t offset, size_t total){ - LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; - if (!chatMsg->http_request || belle_http_request_is_cancelled(chatMsg->http_request)) { - ms_warning("Cancelled request for msg [%p], ignoring %s", chatMsg, __FUNCTION__); +static void linphone_chat_message_file_transfer_on_progress(belle_sip_body_handler_t *bh, belle_sip_message_t *m, + void *data, size_t offset, size_t total) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + if (!msg->http_request || belle_http_request_is_cancelled(msg->http_request)) { + ms_warning("Cancelled request for msg [%p], ignoring %s", msg, __FUNCTION__); return; } - if (linphone_chat_message_cbs_get_file_transfer_progress_indication(chatMsg->callbacks)) { - linphone_chat_message_cbs_get_file_transfer_progress_indication(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, offset, total); + if (linphone_chat_message_cbs_get_file_transfer_progress_indication(msg->callbacks)) { + linphone_chat_message_cbs_get_file_transfer_progress_indication(msg->callbacks)( + msg, msg->file_transfer_information, offset, total); } else { /* Legacy: call back given by application level */ - linphone_core_notify_file_transfer_progress_indication(chatMsg->chat_room->lc, chatMsg, chatMsg->file_transfer_information, offset, total); + linphone_core_notify_file_transfer_progress_indication(msg->chat_room->lc, msg, msg->file_transfer_information, + offset, total); } } -static int linphone_chat_message_file_transfer_on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *msg, void *data, size_t offset, uint8_t *buffer, size_t *size){ - LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; - LinphoneCore *lc = chatMsg->chat_room->lc; +static int linphone_chat_message_file_transfer_on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, + void *data, size_t offset, uint8_t *buffer, size_t *size) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + LinphoneCore *lc = msg->chat_room->lc; char *buf = (char *)buffer; - if (!chatMsg->http_request || belle_http_request_is_cancelled(chatMsg->http_request)) { - ms_warning("Cancelled request for msg [%p], ignoring %s", chatMsg, __FUNCTION__); + if (!msg->http_request || belle_http_request_is_cancelled(msg->http_request)) { + ms_warning("Cancelled request for msg [%p], ignoring %s", msg, __FUNCTION__); return BELLE_SIP_STOP; } /* if we've not reach the end of file yet, ask for more data*/ - if (offsetfile_transfer_information)){ + if (offset < linphone_content_get_size(msg->file_transfer_information)) { char *plainBuffer = NULL; - if (linphone_content_get_key(chatMsg->file_transfer_information) != NULL) { /* if we have a key to cipher the message, use it! */ + if (linphone_content_get_key(msg->file_transfer_information) != + NULL) { /* if we have a key to cipher the msg, use it! */ /* if this chunk is not the last one, the lenght must be a multiple of block cipher size(16 bytes)*/ - if (offset+*size < linphone_content_get_size(chatMsg->file_transfer_information)) { - *size -=(*size%16); + if (offset + *size < linphone_content_get_size(msg->file_transfer_information)) { + *size -= (*size % 16); } plainBuffer = (char *)malloc(*size); } /* get data from call back */ - if (linphone_chat_message_cbs_get_file_transfer_send(chatMsg->callbacks)) { - LinphoneBuffer *lb = linphone_chat_message_cbs_get_file_transfer_send(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, offset, *size); + if (linphone_chat_message_cbs_get_file_transfer_send(msg->callbacks)) { + LinphoneBuffer *lb = linphone_chat_message_cbs_get_file_transfer_send(msg->callbacks)( + msg, msg->file_transfer_information, offset, *size); if (lb == NULL) { *size = 0; } else { *size = linphone_buffer_get_size(lb); - memcpy(plainBuffer?plainBuffer:buf, linphone_buffer_get_content(lb), *size); + memcpy(plainBuffer ? plainBuffer : buf, linphone_buffer_get_content(lb), *size); linphone_buffer_unref(lb); } } else { /* Legacy */ - linphone_core_notify_file_transfer_send(lc, chatMsg, chatMsg->file_transfer_information, plainBuffer?plainBuffer:buf, size); + linphone_core_notify_file_transfer_send(lc, msg, msg->file_transfer_information, + plainBuffer ? plainBuffer : buf, size); } - if (linphone_content_get_key(chatMsg->file_transfer_information) != NULL) { /* if we have a key to cipher the message, use it! */ - lime_encryptFile(linphone_content_get_cryptoContext_address(chatMsg->file_transfer_information), (unsigned char *)linphone_content_get_key(chatMsg->file_transfer_information), *size, plainBuffer, (char*)buffer); + if (linphone_content_get_key(msg->file_transfer_information) != + NULL) { /* if we have a key to cipher the msg, use it! */ + lime_encryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), + (unsigned char *)linphone_content_get_key(msg->file_transfer_information), *size, + plainBuffer, (char *)buffer); free(plainBuffer); /* check if we reach the end of file */ - if (offset+*size >= linphone_content_get_size(chatMsg->file_transfer_information)) { + if (offset + *size >= linphone_content_get_size(msg->file_transfer_information)) { /* conclude file ciphering by calling it context with a zero size */ - lime_encryptFile(linphone_content_get_cryptoContext_address(chatMsg->file_transfer_information), NULL, 0, NULL, NULL); + lime_encryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), NULL, 0, + NULL, NULL); } } } @@ -206,96 +227,120 @@ static int linphone_chat_message_file_transfer_on_send_body(belle_sip_user_body_ return BELLE_SIP_CONTINUE; } -static void linphone_chat_message_process_response_from_post_file(void *data, const belle_http_response_event_t *event){ - LinphoneChatMessage* msg=(LinphoneChatMessage *)data; +static void linphone_chat_message_process_response_from_post_file(void *data, + const belle_http_response_event_t *event) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; /* check the answer code */ - if (event->response){ - int code=belle_http_response_get_status_code(event->response); - if (code == 204) { /* this is the reply to the first post to the server - an empty message */ + if (event->response) { + int code = belle_http_response_get_status_code(event->response); + if (code == 204) { /* this is the reply to the first post to the server - an empty msg */ /* start uploading the file */ - belle_http_request_listener_callbacks_t cbs={0}; + belle_http_request_listener_callbacks_t cbs = {0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; belle_sip_multipart_body_handler_t *bh; - char* ua; + char *ua; char *first_part_header; belle_sip_body_handler_t *first_part_bh; /* shall we encrypt the file */ if (linphone_core_lime_for_file_sharing_enabled(msg->chat_room->lc)) { - char keyBuffer[FILE_TRANSFER_KEY_SIZE]; /* temporary storage of generated key: 192 bits of key + 64 bits of initial vector */ - /* generate a random 192 bits key + 64 bits of initial vector and store it into the file_transfer_information->key field of the message */ + char keyBuffer + [FILE_TRANSFER_KEY_SIZE]; /* temporary storage of generated key: 192 bits of key + 64 bits of + initial vector */ + /* generate a random 192 bits key + 64 bits of initial vector and store it into the + * file_transfer_information->key field of the msg */ sal_get_random_bytes((unsigned char *)keyBuffer, FILE_TRANSFER_KEY_SIZE); - linphone_content_set_key(msg->file_transfer_information, keyBuffer, FILE_TRANSFER_KEY_SIZE); /* key is duplicated in the content private structure */ + linphone_content_set_key( + msg->file_transfer_information, keyBuffer, + FILE_TRANSFER_KEY_SIZE); /* key is duplicated in the content private structure */ /* temporary storage for the Content-disposition header value : use a generic filename to not leak it - * Actual filename stored in msg->file_transfer_information->name will be set in encrypted message sended to the */ + * Actual filename stored in msg->file_transfer_information->name will be set in encrypted msg + * sended to the */ first_part_header = belle_sip_strdup_printf("form-data; name=\"File\"; filename=\"filename.txt\""); } else { /* temporary storage for the Content-disposition header value */ - first_part_header = belle_sip_strdup_printf("form-data; name=\"File\"; filename=\"%s\"", linphone_content_get_name(msg->file_transfer_information)); + first_part_header = belle_sip_strdup_printf("form-data; name=\"File\"; filename=\"%s\"", + linphone_content_get_name(msg->file_transfer_information)); } - /* create a user body handler to take care of the file and add the content disposition and content-type headers */ + /* create a user body handler to take care of the file and add the content disposition and content-type + * headers */ if (msg->file_transfer_filepath != NULL) { - first_part_bh=(belle_sip_body_handler_t *)belle_sip_file_body_handler_new(msg->file_transfer_filepath,NULL,msg); + first_part_bh = + (belle_sip_body_handler_t *)belle_sip_file_body_handler_new(msg->file_transfer_filepath, NULL, msg); } else if (linphone_content_get_buffer(msg->file_transfer_information) != NULL) { - first_part_bh=(belle_sip_body_handler_t *)belle_sip_memory_body_handler_new_from_buffer( + first_part_bh = (belle_sip_body_handler_t *)belle_sip_memory_body_handler_new_from_buffer( linphone_content_get_buffer(msg->file_transfer_information), - linphone_content_get_size(msg->file_transfer_information), - NULL,msg); + linphone_content_get_size(msg->file_transfer_information), NULL, msg); } else { - first_part_bh=(belle_sip_body_handler_t *)belle_sip_user_body_handler_new(linphone_content_get_size(msg->file_transfer_information),NULL,NULL,linphone_chat_message_file_transfer_on_send_body,msg); + first_part_bh = (belle_sip_body_handler_t *)belle_sip_user_body_handler_new( + linphone_content_get_size(msg->file_transfer_information), NULL, NULL, + linphone_chat_message_file_transfer_on_send_body, msg); } - belle_sip_body_handler_add_header(first_part_bh, belle_sip_header_create("Content-disposition", first_part_header)); + belle_sip_body_handler_add_header(first_part_bh, + belle_sip_header_create("Content-disposition", first_part_header)); belle_sip_free(first_part_header); - belle_sip_body_handler_add_header(first_part_bh, (belle_sip_header_t *)belle_sip_header_content_type_create(linphone_content_get_type(msg->file_transfer_information), linphone_content_get_subtype(msg->file_transfer_information))); + belle_sip_body_handler_add_header(first_part_bh, + (belle_sip_header_t *)belle_sip_header_content_type_create( + linphone_content_get_type(msg->file_transfer_information), + linphone_content_get_subtype(msg->file_transfer_information))); - /* insert it in a multipart body handler which will manage the boundaries of multipart message */ - bh=belle_sip_multipart_body_handler_new(linphone_chat_message_file_transfer_on_progress, msg, first_part_bh); + /* insert it in a multipart body handler which will manage the boundaries of multipart msg */ + bh = belle_sip_multipart_body_handler_new(linphone_chat_message_file_transfer_on_progress, msg, + first_part_bh); - /* create the http request: do not include the message header at this point, it is done by bellesip when setting the multipart body handler in the message */ + /* create the http request: do not include the msg header at this point, it is done by bellesip when + * setting the multipart body handler in the msg */ ua = ms_strdup_printf("%s/%s", linphone_core_get_user_agent_name(), linphone_core_get_user_agent_version()); - uri=belle_generic_uri_parse(linphone_core_get_file_transfer_server(msg->chat_room->lc)); - if (msg->http_request) belle_sip_object_unref(msg->http_request); - msg->http_request=belle_http_request_create("POST", - uri, - belle_sip_header_create("User-Agent",ua), - NULL); - belle_sip_object_ref(msg->http_request); /* keep a reference to the http request to be able to cancel it during upload */ + uri = belle_generic_uri_parse(linphone_core_get_file_transfer_server(msg->chat_room->lc)); + if (msg->http_request) + belle_sip_object_unref(msg->http_request); + msg->http_request = belle_http_request_create("POST", uri, belle_sip_header_create("User-Agent", ua), NULL); + belle_sip_object_ref( + msg->http_request); /* keep a reference to the http request to be able to cancel it during upload */ ms_free(ua); - belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(msg->http_request),BELLE_SIP_BODY_HANDLER(bh)); - cbs.process_response=linphone_chat_message_process_response_from_post_file; - cbs.process_io_error=process_io_error_upload; - cbs.process_auth_requested=process_auth_requested_upload; - l=belle_http_request_listener_create_from_callbacks(&cbs,msg); - belle_http_provider_send_request(msg->chat_room->lc->http_provider,msg->http_request,l); + belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(msg->http_request), BELLE_SIP_BODY_HANDLER(bh)); + cbs.process_response = linphone_chat_message_process_response_from_post_file; + cbs.process_io_error = process_io_error_upload; + cbs.process_auth_requested = process_auth_requested_upload; + l = belle_http_request_listener_create_from_callbacks(&cbs, msg); + belle_http_provider_send_request(msg->chat_room->lc->http_provider, msg->http_request, l); } - if (code == 200 ) { /* file has been uplaoded correctly, get server reply and send it */ + if (code == 200) { /* file has been uplaoded correctly, get server reply and send it */ const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response); belle_sip_object_unref(msg->http_request); msg->http_request = NULL; - /* if we have an encryption key for the file, we must insert it into the message and restore the correct filename */ + /* if we have an encryption key for the file, we must insert it into the msg and restore the correct + * filename */ if (linphone_content_get_key(msg->file_transfer_information) != NULL) { - /* parse the message body */ + /* parse the msg body */ xmlDocPtr xmlMessageBody = xmlParseDoc((const xmlChar *)body); xmlNodePtr cur = xmlDocGetRootElement(xmlMessageBody); if (cur != NULL) { cur = cur->xmlChildrenNode; - while (cur!=NULL) { - if (!xmlStrcmp(cur->name, (const xmlChar *)"file-info")) { /* we found a file info node, check it has a type="file" attribute */ + while (cur != NULL) { + if (!xmlStrcmp(cur->name, (const xmlChar *)"file-info")) { /* we found a file info node, check + it has a type="file" attribute */ xmlChar *typeAttribute = xmlGetProp(cur, (const xmlChar *)"type"); - if(!xmlStrcmp(typeAttribute, (const xmlChar *)"file")) { /* this is the node we are looking for : add a file-key children node */ - xmlNodePtr fileInfoNodeChildren = cur->xmlChildrenNode; /* need to parse the children node to update the file-name one */ + if (!xmlStrcmp(typeAttribute, + (const xmlChar *)"file")) { /* this is the node we are looking for : add a + file-key children node */ + xmlNodePtr fileInfoNodeChildren = + cur + ->xmlChildrenNode; /* need to parse the children node to update the file-name + one */ /* convert key to base64 */ - int b64Size = b64_encode(NULL, FILE_TRANSFER_KEY_SIZE, NULL, 0); - char *keyb64 = (char *)malloc(b64Size+1); + int b64Size = b64_encode(NULL, FILE_TRANSFER_KEY_SIZE, NULL, 0); + char *keyb64 = (char *)malloc(b64Size + 1); int xmlStringLength; - b64Size = b64_encode(linphone_content_get_key(msg->file_transfer_information), FILE_TRANSFER_KEY_SIZE, keyb64, b64Size); + b64Size = b64_encode(linphone_content_get_key(msg->file_transfer_information), + FILE_TRANSFER_KEY_SIZE, keyb64, b64Size); keyb64[b64Size] = '\0'; /* libxml need a null terminated string */ /* add the node containing the key to the file-info node */ @@ -304,18 +349,23 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co free(keyb64); /* look for the file-name node and update its content */ - while (fileInfoNodeChildren!=NULL) { - if (!xmlStrcmp(fileInfoNodeChildren->name, (const xmlChar *)"file-name")) { /* we found a the file-name node, update its content with the real filename */ + while (fileInfoNodeChildren != NULL) { + if (!xmlStrcmp( + fileInfoNodeChildren->name, + (const xmlChar *)"file-name")) { /* we found a the file-name node, update + its content with the real filename */ /* update node content */ - xmlNodeSetContent(fileInfoNodeChildren, (const xmlChar *)(linphone_content_get_name(msg->file_transfer_information))); + xmlNodeSetContent(fileInfoNodeChildren, + (const xmlChar *)(linphone_content_get_name( + msg->file_transfer_information))); break; } fileInfoNodeChildren = fileInfoNodeChildren->next; } - /* dump the xml into msg->message */ - xmlDocDumpFormatMemoryEnc(xmlMessageBody, (xmlChar **)&msg->message, &xmlStringLength, "UTF-8", 0); + xmlDocDumpFormatMemoryEnc(xmlMessageBody, (xmlChar **)&msg->message, &xmlStringLength, + "UTF-8", 0); break; } @@ -326,53 +376,45 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co } xmlFreeDoc(xmlMessageBody); - } else { /* no encryption key, transfer in plain, just copy the message sent by server */ + } else { /* no encryption key, transfer in plain, just copy the msg sent by server */ msg->message = ms_strdup(body); } msg->content_type = ms_strdup("application/vnd.gsma.rcs-ft-http+xml"); - msg->state = LinphoneChatMessageStateFileTransferDone; - if (msg->cb) { - msg->cb(msg, msg->state, msg->cb_ud); - } - if (linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)(msg, msg->state); - } + linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferDone); _linphone_chat_room_send_message(msg->chat_room, msg); } } } - -static void _linphone_chat_message_destroy(LinphoneChatMessage* msg); +static void _linphone_chat_message_destroy(LinphoneChatMessage *msg); BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatMessage); -BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatMessage,belle_sip_object_t, - (belle_sip_object_destroy_t)_linphone_chat_message_destroy, - NULL, // clone - NULL, // marshal - FALSE -); +BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatMessage, belle_sip_object_t, + (belle_sip_object_destroy_t)_linphone_chat_message_destroy, + NULL, // clone + NULL, // marshal + FALSE); -void linphone_core_disable_chat(LinphoneCore *lc, LinphoneReason deny_reason){ - lc->chat_deny_code=deny_reason; +void linphone_core_disable_chat(LinphoneCore *lc, LinphoneReason deny_reason) { + lc->chat_deny_code = deny_reason; } -void linphone_core_enable_chat(LinphoneCore *lc){ - lc->chat_deny_code=LinphoneReasonNone; +void linphone_core_enable_chat(LinphoneCore *lc) { + lc->chat_deny_code = LinphoneReasonNone; } -bool_t linphone_core_chat_enabled(const LinphoneCore *lc){ - return lc->chat_deny_code!=LinphoneReasonNone; +bool_t linphone_core_chat_enabled(const LinphoneCore *lc) { + return lc->chat_deny_code != LinphoneReasonNone; } -const MSList* linphone_core_get_chat_rooms(LinphoneCore *lc) { +const MSList *linphone_core_get_chat_rooms(LinphoneCore *lc) { return lc->chatrooms; } -static bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from){ - return linphone_address_weak_equal(cr->peer_url,from); +static bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from) { + return linphone_address_weak_equal(cr->peer_url, from); } static void _linphone_chat_room_destroy(LinphoneChatRoom *obj); @@ -380,13 +422,12 @@ static void _linphone_chat_room_destroy(LinphoneChatRoom *obj); BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatRoom); BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatRoom, belle_sip_object_t, - (belle_sip_object_destroy_t)_linphone_chat_room_destroy, - NULL, // clone - NULL, // marshal - FALSE -); + (belle_sip_object_destroy_t)_linphone_chat_room_destroy, + NULL, // clone + NULL, // marshal + FALSE); -static LinphoneChatRoom * _linphone_core_create_chat_room(LinphoneCore *lc, LinphoneAddress *addr) { +static LinphoneChatRoom *_linphone_core_create_chat_room(LinphoneCore *lc, LinphoneAddress *addr) { LinphoneChatRoom *cr = belle_sip_object_new(LinphoneChatRoom); cr->lc = lc; cr->peer = linphone_address_as_string(addr); @@ -396,7 +437,7 @@ static LinphoneChatRoom * _linphone_core_create_chat_room(LinphoneCore *lc, Linp return cr; } -static LinphoneChatRoom * _linphone_core_create_chat_room_from_url(LinphoneCore *lc, const char *to) { +static LinphoneChatRoom *_linphone_core_create_chat_room_from_url(LinphoneCore *lc, const char *to) { LinphoneAddress *parsed_url = NULL; if ((parsed_url = linphone_core_interpret_url(lc, to)) != NULL) { return _linphone_core_create_chat_room(lc, parsed_url); @@ -404,36 +445,36 @@ static LinphoneChatRoom * _linphone_core_create_chat_room_from_url(LinphoneCore return NULL; } -LinphoneChatRoom * _linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr){ - LinphoneChatRoom *cr=NULL; +LinphoneChatRoom *_linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) { + LinphoneChatRoom *cr = NULL; MSList *elem; - for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){ - cr=(LinphoneChatRoom*)elem->data; - if (linphone_chat_room_matches(cr,addr)){ + for (elem = lc->chatrooms; elem != NULL; elem = ms_list_next(elem)) { + cr = (LinphoneChatRoom *)elem->data; + if (linphone_chat_room_matches(cr, addr)) { break; } - cr=NULL; + cr = NULL; } return cr; } -static LinphoneChatRoom * _linphone_core_get_or_create_chat_room(LinphoneCore* lc, const char* to) { - LinphoneAddress *to_addr=linphone_core_interpret_url(lc,to); +static LinphoneChatRoom *_linphone_core_get_or_create_chat_room(LinphoneCore *lc, const char *to) { + LinphoneAddress *to_addr = linphone_core_interpret_url(lc, to); LinphoneChatRoom *ret; - if (to_addr==NULL){ - ms_error("linphone_core_get_or_create_chat_room(): Cannot make a valid address with %s",to); + if (to_addr == NULL) { + ms_error("linphone_core_get_or_create_chat_room(): Cannot make a valid address with %s", to); return NULL; } - ret=_linphone_core_get_chat_room(lc,to_addr); + ret = _linphone_core_get_chat_room(lc, to_addr); linphone_address_destroy(to_addr); - if (!ret){ - ret=_linphone_core_create_chat_room_from_url(lc,to); + if (!ret) { + ret = _linphone_core_create_chat_room_from_url(lc, to); } return ret; } -LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr){ +LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) { LinphoneChatRoom *ret = _linphone_core_get_chat_room(lc, addr); if (!ret) { ret = _linphone_core_create_chat_room(lc, linphone_address_clone(addr)); @@ -441,25 +482,23 @@ LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAd return ret; } -void linphone_core_delete_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr){ - if (ms_list_find(lc->chatrooms, cr)){ +void linphone_core_delete_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr) { + if (ms_list_find(lc->chatrooms, cr)) { lc->chatrooms = ms_list_remove(cr->lc->chatrooms, cr); linphone_chat_room_delete_history(cr); linphone_chat_room_unref(cr); - }else{ - ms_error("linphone_core_delete_chat_room(): chatroom [%p] isn't part of LinphoneCore.", - cr); + } else { + ms_error("linphone_core_delete_chat_room(): chatroom [%p] isn't part of LinphoneCore.", cr); } - } -LinphoneChatRoom * linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) { +LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) { return _linphone_core_get_or_create_chat_room(lc, to); } static void linphone_chat_room_delete_composing_idle_timer(LinphoneChatRoom *cr) { if (cr->composing_idle_timer) { - if(cr-> lc && cr->lc->sal) + if (cr->lc && cr->lc->sal) sal_cancel_timer(cr->lc->sal, cr->composing_idle_timer); belle_sip_object_unref(cr->composing_idle_timer); cr->composing_idle_timer = NULL; @@ -468,7 +507,7 @@ static void linphone_chat_room_delete_composing_idle_timer(LinphoneChatRoom *cr) static void linphone_chat_room_delete_composing_refresh_timer(LinphoneChatRoom *cr) { if (cr->composing_refresh_timer) { - if(cr->lc && cr->lc->sal) + if (cr->lc && cr->lc->sal) sal_cancel_timer(cr->lc->sal, cr->composing_refresh_timer); belle_sip_object_unref(cr->composing_refresh_timer); cr->composing_refresh_timer = NULL; @@ -477,25 +516,26 @@ static void linphone_chat_room_delete_composing_refresh_timer(LinphoneChatRoom * static void linphone_chat_room_delete_remote_composing_refresh_timer(LinphoneChatRoom *cr) { if (cr->remote_composing_refresh_timer) { - if(cr->lc && cr->lc->sal) + if (cr->lc && cr->lc->sal) sal_cancel_timer(cr->lc->sal, cr->remote_composing_refresh_timer); belle_sip_object_unref(cr->remote_composing_refresh_timer); cr->remote_composing_refresh_timer = NULL; } } -static void _linphone_chat_room_destroy(LinphoneChatRoom *cr){ - ms_list_free_with_data(cr->transient_messages, (void (*)(void*))linphone_chat_message_release); +static void _linphone_chat_room_destroy(LinphoneChatRoom *cr) { + ms_list_free_with_data(cr->transient_messages, (void (*)(void *))linphone_chat_message_release); linphone_chat_room_delete_composing_idle_timer(cr); linphone_chat_room_delete_composing_refresh_timer(cr); linphone_chat_room_delete_remote_composing_refresh_timer(cr); if (cr->lc != NULL) { - if (ms_list_find(cr->lc->chatrooms, cr)){ + if (ms_list_find(cr->lc->chatrooms, cr)) { ms_error("LinphoneChatRoom[%p] is destroyed while still being used by the LinphoneCore. This is abnormal." - " linphone_core_get_chat_room() doesn't give a reference, there is no need to call linphone_chat_room_unref(). " - "In order to remove a chat room from the core, use linphone_core_delete_chat_room().", - cr); - cr->lc->chatrooms=ms_list_remove(cr->lc->chatrooms, cr); + " linphone_core_get_chat_room() doesn't give a reference, there is no need to call " + "linphone_chat_room_unref(). " + "In order to remove a chat room from the core, use linphone_core_delete_chat_room().", + cr); + cr->lc->chatrooms = ms_list_remove(cr->lc->chatrooms, cr); } } linphone_address_destroy(cr->peer_url); @@ -511,7 +551,7 @@ void linphone_chat_room_release(LinphoneChatRoom *cr) { linphone_chat_room_unref(cr); } -LinphoneChatRoom * linphone_chat_room_ref(LinphoneChatRoom *cr) { +LinphoneChatRoom *linphone_chat_room_ref(LinphoneChatRoom *cr) { belle_sip_object_ref(cr); return cr; } @@ -520,7 +560,7 @@ void linphone_chat_room_unref(LinphoneChatRoom *cr) { belle_sip_object_unref(cr); } -void * linphone_chat_room_get_user_data(const LinphoneChatRoom *cr) { +void *linphone_chat_room_get_user_data(const LinphoneChatRoom *cr) { return cr->user_data; } @@ -528,81 +568,80 @@ void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void *ud) { cr->user_data = ud; } - -static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage* msg){ - SalOp *op=NULL; +static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + SalOp *op = NULL; LinphoneCall *call; - char* content_type; - const char *identity=NULL; - time_t t=time(NULL); + char *content_type; + const char *identity = NULL; + time_t t = time(NULL); linphone_chat_message_ref(msg); /* Check if we shall upload a file to a server */ if (msg->file_transfer_information != NULL && msg->content_type == NULL) { /* open a transaction with the server and send an empty request(RCS5.1 section 3.5.4.8.3.1) */ - belle_http_request_listener_callbacks_t cbs={0}; + belle_http_request_listener_callbacks_t cbs = {0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; const char *transfer_server = linphone_core_get_file_transfer_server(cr->lc); if (transfer_server == NULL) { - ms_warning("Cannot send file transfer message: no file transfer server configured."); + ms_warning("Cannot send file transfer msg: no file transfer server configured."); return; } - uri=belle_generic_uri_parse(transfer_server); + uri = belle_generic_uri_parse(transfer_server); - msg->http_request=belle_http_request_create("POST", - uri, - NULL, - NULL, - NULL); - belle_sip_object_ref(msg->http_request); /* keep a reference on the request to be able to cancel it */ - cbs.process_response=linphone_chat_message_process_response_from_post_file; - cbs.process_io_error=process_io_error_upload; - cbs.process_auth_requested=process_auth_requested_upload; - l=belle_http_request_listener_create_from_callbacks(&cbs,msg); /* give msg to listener to be able to start the actual file upload when server answer a 204 No content */ - belle_http_provider_send_request(cr->lc->http_provider,msg->http_request,l); + msg->http_request = belle_http_request_create("POST", uri, NULL, NULL, NULL); + belle_sip_object_ref(msg->http_request); /* keep a reference on the request to be able to cancel it */ + cbs.process_response = linphone_chat_message_process_response_from_post_file; + cbs.process_io_error = process_io_error_upload; + cbs.process_auth_requested = process_auth_requested_upload; + l = belle_http_request_listener_create_from_callbacks( + &cbs, msg); /* give msg to listener to be able to start the actual file upload when server answer a 204 No + content */ + belle_http_provider_send_request(cr->lc->http_provider, msg->http_request, l); linphone_chat_message_unref(msg); return; } - if (lp_config_get_int(cr->lc->config,"sip","chat_use_call_dialogs",0)){ - if((call = linphone_core_get_call_by_remote_address(cr->lc,cr->peer))!=NULL){ - if (call->state==LinphoneCallConnected || - call->state==LinphoneCallStreamsRunning || - call->state==LinphoneCallPaused || - call->state==LinphoneCallPausing || - call->state==LinphoneCallPausedByRemote){ - ms_message("send SIP message through the existing call."); + if (lp_config_get_int(cr->lc->config, "sip", "chat_use_call_dialogs", 0)) { + if ((call = linphone_core_get_call_by_remote_address(cr->lc, cr->peer)) != NULL) { + if (call->state == LinphoneCallConnected || call->state == LinphoneCallStreamsRunning || + call->state == LinphoneCallPaused || call->state == LinphoneCallPausing || + call->state == LinphoneCallPausedByRemote) { + ms_message("send SIP msg through the existing call."); op = call->op; - identity=linphone_core_find_best_identity(cr->lc,linphone_call_get_remote_address(call)); + identity = linphone_core_find_best_identity(cr->lc, linphone_call_get_remote_address(call)); } } } - msg->time=t; - if (op==NULL){ - LinphoneProxyConfig *proxy=linphone_core_lookup_known_proxy(cr->lc,cr->peer_url); - if (proxy){ - identity=linphone_proxy_config_get_identity(proxy); - }else identity=linphone_core_get_primary_contact(cr->lc); + msg->time = t; + if (op == NULL) { + LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url); + if (proxy) { + identity = linphone_proxy_config_get_identity(proxy); + } else + identity = linphone_core_get_primary_contact(cr->lc); /*sending out of calls*/ msg->op = op = sal_op_new(cr->lc->sal); - linphone_configure_op(cr->lc,op,cr->peer_url,msg->custom_headers,lp_config_get_int(cr->lc->config,"sip","chat_msg_with_contact",0)); + linphone_configure_op(cr->lc, op, cr->peer_url, msg->custom_headers, + lp_config_get_int(cr->lc->config, "sip", "chat_msg_with_contact", 0)); sal_op_set_user_pointer(op, msg); /*if out of call, directly store msg*/ } - if (msg->external_body_url) { - content_type=ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"",msg->external_body_url); - sal_message_send(op,identity,cr->peer,content_type, NULL, NULL); + content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", msg->external_body_url); + sal_message_send(op, identity, cr->peer, content_type, NULL, NULL); ms_free(content_type); } else { char *peer_uri = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); - const char * content_type; + const char *content_type; if (linphone_core_lime_enabled(cr->lc)) { - linphone_chat_message_ref(msg); /* ref the message or it may be destroyed by callback if the encryption failed */ + linphone_chat_message_ref( + msg); /* ref the msg or it may be destroyed by callback if the encryption failed */ if (msg->content_type && strcmp(msg->content_type, "application/vnd.gsma.rcs-ft-http+xml") == 0) { - content_type = "application/cipher.vnd.gsma.rcs-ft-http+xml"; /* it's a file transfer, content type shall be set to application/cipher.vnd.gsma.rcs-ft-http+xml*/ + content_type = + "application/cipher.vnd.gsma.rcs-ft-http+xml"; /* it's a file transfer, content type shall be set to + application/cipher.vnd.gsma.rcs-ft-http+xml*/ } else { content_type = "xml/cipher"; } @@ -611,18 +650,19 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM } if (content_type == NULL) { - sal_text_send(op, identity, cr->peer,msg->message); + sal_text_send(op, identity, cr->peer, msg->message); } else { sal_message_send(op, identity, cr->peer, content_type, msg->message, peer_uri); } ms_free(peer_uri); } - msg->dir=LinphoneChatMessageOutgoing; - msg->from=linphone_address_new(identity); - msg->storage_id=linphone_chat_message_store(msg); + msg->dir = LinphoneChatMessageOutgoing; + msg->from = linphone_address_new(identity); + msg->storage_id = linphone_chat_message_store(msg); - if(cr->unread_count >= 0 && !msg->is_read) cr->unread_count++; + if (cr->unread_count >= 0 && !msg->is_read) + cr->unread_count++; // add to transient list cr->transient_messages = ms_list_append(cr->transient_messages, linphone_chat_message_ref(msg)); @@ -635,87 +675,95 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM linphone_chat_message_unref(msg); } -void linphone_chat_message_update_state(LinphoneChatMessage* chat_msg ) { - linphone_chat_message_store_state(chat_msg); +void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) { + linphone_chat_message_set_state(msg, new_state); + linphone_chat_message_store_state(msg); - if( chat_msg->state == LinphoneChatMessageStateDelivered - || chat_msg->state == LinphoneChatMessageStateNotDelivered ){ - // message is not transient anymore, we can remove it from our transient list and unref it : - chat_msg->chat_room->transient_messages = ms_list_remove(chat_msg->chat_room->transient_messages, chat_msg); - linphone_chat_message_unref(chat_msg); + if (msg->state == LinphoneChatMessageStateDelivered || msg->state == LinphoneChatMessageStateNotDelivered) { + // msg is not transient anymore, we can remove it from our transient list and unref it : + msg->chat_room->transient_messages = ms_list_remove(msg->chat_room->transient_messages, msg); + linphone_chat_message_unref(msg); } } /** - * Send a message to peer member of this chat room. - * @deprecated linphone_chat_room_send_message2() gives more control on the message expedition. + * Send a msg to peer member of this chat room. + * @deprecated linphone_chat_room_send_message2() gives more control on the msg expedition. * @param cr #LinphoneChatRoom object - * @param msg message to be sent + * @param msg msg to be sent */ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) { - _linphone_chat_room_send_message(cr,linphone_chat_room_create_message(cr,msg)); + _linphone_chat_room_send_message(cr, linphone_chat_room_create_message(cr, msg)); } -void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, LinphoneChatMessage *msg){ - if (msg->message){ +void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, LinphoneChatMessage *msg) { + if (msg->message) { /*legacy API*/ linphone_core_notify_text_message_received(lc, cr, msg->from, msg->message); } - linphone_core_notify_message_received(lc, cr,msg); + linphone_core_notify_message_received(lc, cr, msg); cr->remote_is_composing = LinphoneIsComposingIdle; linphone_core_notify_is_composing_received(cr->lc, cr); } -void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){ - LinphoneChatRoom *cr=NULL; +void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg) { + LinphoneChatRoom *cr = NULL; LinphoneAddress *addr; - LinphoneChatMessage* msg; + LinphoneChatMessage *msg; const SalCustomHeader *ch; - addr=linphone_address_new(sal_msg->from); + addr = linphone_address_new(sal_msg->from); linphone_address_clean(addr); - cr=linphone_core_get_chat_room(lc,addr); + cr = linphone_core_get_chat_room(lc, addr); - if (sal_msg->content_type != NULL) { /* content_type field is, for now, used only for rcs file transfer but we shall strcmp it with "application/vnd.gsma.rcs-ft-http+xml" */ + if (sal_msg->content_type != + NULL) { /* content_type field is, for now, used only for rcs file transfer but we shall strcmp it with + "application/vnd.gsma.rcs-ft-http+xml" */ xmlChar *file_url = NULL; xmlDocPtr xmlMessageBody; xmlNodePtr cur; - msg = linphone_chat_room_create_message(cr, NULL); /* create a message with empty body */ - msg->content_type = ms_strdup(sal_msg->content_type); /* add the content_type "application/vnd.gsma.rcs-ft-http+xml" */ + msg = linphone_chat_room_create_message(cr, NULL); /* create a msg with empty body */ + msg->content_type = + ms_strdup(sal_msg->content_type); /* add the content_type "application/vnd.gsma.rcs-ft-http+xml" */ msg->file_transfer_information = linphone_content_new(); - /* parse the message body to get all informations from it */ + /* parse the msg body to get all informations from it */ xmlMessageBody = xmlParseDoc((const xmlChar *)sal_msg->text); cur = xmlDocGetRootElement(xmlMessageBody); if (cur != NULL) { cur = cur->xmlChildrenNode; - while (cur!=NULL) { - if (!xmlStrcmp(cur->name, (const xmlChar *)"file-info")) { /* we found a file info node, check it has a type="file" attribute */ + while (cur != NULL) { + if (!xmlStrcmp( + cur->name, (const xmlChar *)"file-info")) { /* we found a file info node, check it has a + type="file" attribute */ xmlChar *typeAttribute = xmlGetProp(cur, (const xmlChar *)"type"); - if(!xmlStrcmp(typeAttribute, (const xmlChar *)"file")) { /* this is the node we are looking for */ + if (!xmlStrcmp(typeAttribute, (const xmlChar *)"file")) { /* this is the node we are looking for */ cur = cur->xmlChildrenNode; /* now loop on the content of the file-info node */ - while (cur!=NULL) { + while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"file-size")) { xmlChar *fileSizeString = xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1); - linphone_content_set_size(msg->file_transfer_information, strtol((const char*)fileSizeString, NULL, 10)); + linphone_content_set_size(msg->file_transfer_information, + strtol((const char *)fileSizeString, NULL, 10)); xmlFree(fileSizeString); } if (!xmlStrcmp(cur->name, (const xmlChar *)"file-name")) { - linphone_content_set_name(msg->file_transfer_information, (const char *)xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1)); + linphone_content_set_name( + msg->file_transfer_information, + (const char *)xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1)); } if (!xmlStrcmp(cur->name, (const xmlChar *)"content-type")) { xmlChar *contentType = xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1); int contentTypeIndex = 0; char *type; char *subtype; - while (contentType[contentTypeIndex]!='/' && contentType[contentTypeIndex]!='\0') { + while (contentType[contentTypeIndex] != '/' && contentType[contentTypeIndex] != '\0') { contentTypeIndex++; } type = ms_strndup((char *)contentType, contentTypeIndex); - subtype = ms_strdup(((char *)contentType+contentTypeIndex+1)); + subtype = ms_strdup(((char *)contentType + contentTypeIndex + 1)); linphone_content_set_type(msg->file_transfer_information, type); linphone_content_set_subtype(msg->file_transfer_information, subtype); ms_free(subtype); @@ -723,22 +771,26 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag xmlFree(contentType); } if (!xmlStrcmp(cur->name, (const xmlChar *)"data")) { - file_url = xmlGetProp(cur, (const xmlChar *)"url"); + file_url = xmlGetProp(cur, (const xmlChar *)"url"); } - if (!xmlStrcmp(cur->name, (const xmlChar *)"file-key")) { /* there is a key in the message: file has been encrypted */ + if (!xmlStrcmp(cur->name, + (const xmlChar *)"file-key")) { /* there is a key in the msg: file has + been encrypted */ /* convert the key from base 64 */ xmlChar *keyb64 = xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1); int keyLength = b64_decode((char *)keyb64, strlen((char *)keyb64), NULL, 0); uint8_t *keyBuffer = (uint8_t *)malloc(keyLength); /* decode the key into local key buffer */ b64_decode((char *)keyb64, strlen((char *)keyb64), keyBuffer, keyLength); - linphone_content_set_key(msg->file_transfer_information, (char *)keyBuffer, keyLength); /* duplicate key value into the linphone content private structure */ + linphone_content_set_key( + msg->file_transfer_information, (char *)keyBuffer, + keyLength); /* duplicate key value into the linphone content private structure */ xmlFree(keyb64); free(keyBuffer); } - cur=cur->next; + cur = cur->next; } xmlFree(typeAttribute); break; @@ -752,35 +804,39 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag linphone_chat_message_set_external_body_url(msg, (const char *)file_url); xmlFree(file_url); - } else { /* message is not rcs file transfer, create it with provided sal_msg->text as ->message */ + } else { /* msg is not rcs file transfer, create it with provided sal_msg->text as ->msg */ msg = linphone_chat_room_create_message(cr, sal_msg->text); } linphone_chat_message_set_from(msg, cr->peer_url); { LinphoneAddress *to; - to=sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) : linphone_address_new(linphone_core_get_identity(lc)); - msg->to=to; + to = sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) + : linphone_address_new(linphone_core_get_identity(lc)); + msg->to = to; } - msg->time=sal_msg->time; - msg->state=LinphoneChatMessageStateDelivered; - msg->is_read=FALSE; - msg->dir=LinphoneChatMessageIncoming; - ch=sal_op_get_recv_custom_header(op); - if (ch) msg->custom_headers=sal_custom_header_clone(ch); + msg->time = sal_msg->time; + linphone_chat_message_set_state(msg, LinphoneChatMessageStateDelivered); + msg->is_read = FALSE; + msg->dir = LinphoneChatMessageIncoming; + ch = sal_op_get_recv_custom_header(op); + if (ch) + msg->custom_headers = sal_custom_header_clone(ch); if (sal_msg->url) { linphone_chat_message_set_external_body_url(msg, sal_msg->url); } linphone_address_destroy(addr); - msg->storage_id=linphone_chat_message_store(msg); + msg->storage_id = linphone_chat_message_store(msg); - if(cr->unread_count < 0) cr->unread_count = 1; - else cr->unread_count++; + if (cr->unread_count < 0) + cr->unread_count = 1; + else + cr->unread_count++; - linphone_chat_room_message_received(cr,lc,msg); + linphone_chat_room_message_received(cr, lc, msg); linphone_chat_message_unref(msg); } @@ -800,20 +856,24 @@ static void process_im_is_composing_notification(LinphoneChatRoom *cr, xmlparsin xmlXPathObjectPtr iscomposing_object; const char *state_str = NULL; const char *refresh_str = NULL; - int refresh_duration = lp_config_get_int(cr->lc->config, "sip", "composing_remote_refresh_timeout", COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT); + int refresh_duration = lp_config_get_int(cr->lc->config, "sip", "composing_remote_refresh_timeout", + COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT); int i; LinphoneIsComposingState state = LinphoneIsComposingIdle; - if (linphone_create_xml_xpath_context(xml_ctx) < 0) return; + if (linphone_create_xml_xpath_context(xml_ctx) < 0) + return; - xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar *)"xsi", (const xmlChar *)"urn:ietf:params:xml:ns:im-iscomposing"); + xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar *)"xsi", + (const xmlChar *)"urn:ietf:params:xml:ns:im-iscomposing"); iscomposing_object = linphone_get_xml_xpath_object_for_node_list(xml_ctx, iscomposing_prefix); - if (iscomposing_object != NULL){ - if(iscomposing_object->nodesetval != NULL) { + if (iscomposing_object != NULL) { + if (iscomposing_object->nodesetval != NULL) { for (i = 1; i <= iscomposing_object->nodesetval->nodeNr; i++) { snprintf(xpath_str, sizeof(xpath_str), "%s[%i]/xsi:state", iscomposing_prefix, i); state_str = linphone_get_xml_text_content(xml_ctx, xpath_str); - if (state_str == NULL) continue; + if (state_str == NULL) + continue; snprintf(xpath_str, sizeof(xpath_str), "%s[%i]/xsi:refresh", iscomposing_prefix, i); refresh_str = linphone_get_xml_text_content(xml_ctx, xpath_str); } @@ -828,7 +888,9 @@ static void process_im_is_composing_notification(LinphoneChatRoom *cr, xmlparsin refresh_duration = atoi(refresh_str); } if (!cr->remote_composing_refresh_timer) { - cr->remote_composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_remote_refresh_composing_expired, cr, refresh_duration * 1000, "composing remote refresh timeout"); + cr->remote_composing_refresh_timer = + sal_create_timer(cr->lc->sal, linphone_chat_room_remote_refresh_composing_expired, cr, + refresh_duration * 1000, "composing remote refresh timeout"); } else { belle_sip_source_set_timeout(cr->remote_composing_refresh_timer, refresh_duration * 1000); } @@ -848,7 +910,7 @@ static void process_im_is_composing_notification(LinphoneChatRoom *cr, xmlparsin static void linphone_chat_room_notify_is_composing(LinphoneChatRoom *cr, const char *text) { xmlparsing_context_t *xml_ctx = linphone_xmlparsing_context_new(); xmlSetGenericErrorFunc(xml_ctx, linphone_xmlparsing_genericxml_error); - xml_ctx->doc = xmlReadDoc((const unsigned char*)text, 0, NULL, 0); + xml_ctx->doc = xmlReadDoc((const unsigned char *)text, 0, NULL, 0); if (xml_ctx->doc != NULL) { process_im_is_composing_notification(cr, xml_ctx); } else { @@ -870,70 +932,71 @@ bool_t linphone_chat_room_is_remote_composing(const LinphoneChatRoom *cr) { return (cr->remote_is_composing == LinphoneIsComposingActive) ? TRUE : FALSE; } -LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr){ +LinphoneCore *linphone_chat_room_get_lc(LinphoneChatRoom *cr) { return cr->lc; } -LinphoneCore* linphone_chat_room_get_core(LinphoneChatRoom *cr){ +LinphoneCore *linphone_chat_room_get_core(LinphoneChatRoom *cr) { return cr->lc; } -const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) { +const LinphoneAddress *linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) { return cr->peer_url; } -LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, const char* message) { - LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage); - msg->callbacks=linphone_chat_message_cbs_new(); - msg->chat_room=(LinphoneChatRoom*)cr; - msg->message=message?ms_strdup(message):NULL; - msg->is_read=TRUE; - msg->content_type = NULL; /* this property is used only when transfering file */ +LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message) { + LinphoneChatMessage *msg = belle_sip_object_new(LinphoneChatMessage); + msg->callbacks = linphone_chat_message_cbs_new(); + msg->chat_room = (LinphoneChatRoom *)cr; + msg->message = message ? ms_strdup(message) : NULL; + msg->is_read = TRUE; + msg->content_type = NULL; /* this property is used only when transfering file */ msg->file_transfer_information = NULL; /* this property is used only when transfering file */ msg->http_request = NULL; return msg; } -LinphoneChatMessage* linphone_chat_room_create_message_2( - LinphoneChatRoom *cr, const char* message, const char* external_body_url, - LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming) { - LinphoneCore *lc=linphone_chat_room_get_lc(cr); +LinphoneChatMessage *linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char *message, + const char *external_body_url, LinphoneChatMessageState state, + time_t time, bool_t is_read, bool_t is_incoming) { + LinphoneCore *lc = linphone_chat_room_get_lc(cr); - LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage); - msg->callbacks=linphone_chat_message_cbs_new(); - msg->chat_room=(LinphoneChatRoom*)cr; - msg->message=message?ms_strdup(message):NULL; - msg->external_body_url=external_body_url?ms_strdup(external_body_url):NULL; - msg->time=time; - msg->state=state; - msg->is_read=is_read; - msg->content_type = NULL; /* this property is used only when transfering file */ + LinphoneChatMessage *msg = belle_sip_object_new(LinphoneChatMessage); + msg->callbacks = linphone_chat_message_cbs_new(); + msg->chat_room = (LinphoneChatRoom *)cr; + msg->message = message ? ms_strdup(message) : NULL; + msg->external_body_url = external_body_url ? ms_strdup(external_body_url) : NULL; + msg->time = time; + linphone_chat_message_set_state(msg, state); + msg->is_read = is_read; + msg->content_type = NULL; /* this property is used only when transfering file */ msg->file_transfer_information = NULL; /* this property is used only when transfering file */ if (is_incoming) { - msg->dir=LinphoneChatMessageIncoming; + msg->dir = LinphoneChatMessageIncoming; linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_to(msg, linphone_address_new(linphone_core_get_identity(lc))); } else { - msg->dir=LinphoneChatMessageOutgoing; + msg->dir = LinphoneChatMessageOutgoing; linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(lc))); } return msg; } -void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb, void* ud) { - msg->cb=status_cb; - msg->cb_ud=ud; - msg->state=LinphoneChatMessageStateInProgress; +void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage *msg, + LinphoneChatMessageStateChangedCb status_cb, void *ud) { + msg->message_state_changed_cb = status_cb; + msg->message_state_changed_user_data = ud; + linphone_chat_message_set_state(msg, LinphoneChatMessageStateInProgress); _linphone_chat_room_send_message(cr, msg); } void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { - msg->state = LinphoneChatMessageStateInProgress; + linphone_chat_message_set_state(msg, LinphoneChatMessageStateInProgress); _linphone_chat_room_send_message(cr, msg); } -static char * linphone_chat_room_create_is_composing_xml(LinphoneChatRoom *cr) { +static char *linphone_chat_room_create_is_composing_xml(LinphoneChatRoom *cr) { xmlBufferPtr buf; xmlTextWriterPtr writer; int err; @@ -952,23 +1015,26 @@ static char * linphone_chat_room_create_is_composing_xml(LinphoneChatRoom *cr) { err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); if (err >= 0) { - err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"isComposing", (const xmlChar *)"urn:ietf:params:xml:ns:im-iscomposing"); + err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"isComposing", + (const xmlChar *)"urn:ietf:params:xml:ns:im-iscomposing"); } if (err >= 0) { - err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi", - NULL, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); + err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi", NULL, + (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); } if (err >= 0) { - err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xsi", (const xmlChar *)"schemaLocation", - NULL, (const xmlChar *)"urn:ietf:params:xml:ns:im-composing iscomposing.xsd"); + err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xsi", (const xmlChar *)"schemaLocation", NULL, + (const xmlChar *)"urn:ietf:params:xml:ns:im-composing iscomposing.xsd"); } if (err >= 0) { err = xmlTextWriterWriteElement(writer, (const xmlChar *)"state", - (cr->is_composing == LinphoneIsComposingActive) ? (const xmlChar *)"active" : (const xmlChar *)"idle"); + (cr->is_composing == LinphoneIsComposingActive) ? (const xmlChar *)"active" + : (const xmlChar *)"idle"); } if ((err >= 0) && (cr->is_composing == LinphoneIsComposingActive)) { - char refresh_str[4] = { 0 }; - int refresh_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT); + char refresh_str[4] = {0}; + int refresh_timeout = + lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT); snprintf(refresh_str, sizeof(refresh_str), "%u", refresh_timeout); err = xmlTextWriterWriteElement(writer, (const xmlChar *)"refresh", (const xmlChar *)refresh_str); } @@ -999,7 +1065,8 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * identity = linphone_core_get_primary_contact(cr->lc); /*sending out of calls*/ op = sal_op_new(cr->lc->sal); - linphone_configure_op(cr->lc, op, cr->peer_url, NULL, lp_config_get_int(cr->lc->config, "sip", "chat_msg_with_contact", 0)); + linphone_configure_op(cr->lc, op, cr->peer_url, NULL, + lp_config_get_int(cr->lc->config, "sip", "chat_msg_with_contact", 0)); content = linphone_chat_room_create_is_composing_xml(cr); if (content != NULL) { @@ -1026,85 +1093,95 @@ static int linphone_chat_room_refresh_composing(void *data, unsigned int revents } void linphone_chat_room_compose(LinphoneChatRoom *cr) { - int idle_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_idle_timeout", COMPOSING_DEFAULT_IDLE_TIMEOUT); - int refresh_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT); + int idle_timeout = + lp_config_get_int(cr->lc->config, "sip", "composing_idle_timeout", COMPOSING_DEFAULT_IDLE_TIMEOUT); + int refresh_timeout = + lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT); if (cr->is_composing == LinphoneIsComposingIdle) { cr->is_composing = LinphoneIsComposingActive; linphone_chat_room_send_is_composing_notification(cr); if (!cr->composing_refresh_timer) { - cr->composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_refresh_composing, cr, refresh_timeout * 1000, "composing refresh timeout"); + cr->composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_refresh_composing, cr, + refresh_timeout * 1000, "composing refresh timeout"); } else { belle_sip_source_set_timeout(cr->composing_refresh_timer, refresh_timeout * 1000); } if (!cr->composing_idle_timer) { - cr->composing_idle_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_stop_composing, cr, idle_timeout * 1000, "composing idle timeout"); + cr->composing_idle_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_stop_composing, cr, + idle_timeout * 1000, "composing idle timeout"); } } belle_sip_source_set_timeout(cr->composing_idle_timer, idle_timeout * 1000); } -const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state) { +const char *linphone_chat_message_state_to_string(const LinphoneChatMessageState state) { switch (state) { - case LinphoneChatMessageStateIdle:return "LinphoneChatMessageStateIdle"; - case LinphoneChatMessageStateInProgress:return "LinphoneChatMessageStateInProgress"; - case LinphoneChatMessageStateDelivered:return "LinphoneChatMessageStateDelivered"; - case LinphoneChatMessageStateNotDelivered:return "LinphoneChatMessageStateNotDelivered"; - case LinphoneChatMessageStateFileTransferError:return "LinphoneChatMessageStateFileTransferError"; - case LinphoneChatMessageStateFileTransferDone: return "LinphoneChatMessageStateFileTransferDone "; + case LinphoneChatMessageStateIdle: + return "LinphoneChatMessageStateIdle"; + case LinphoneChatMessageStateInProgress: + return "LinphoneChatMessageStateInProgress"; + case LinphoneChatMessageStateDelivered: + return "LinphoneChatMessageStateDelivered"; + case LinphoneChatMessageStateNotDelivered: + return "LinphoneChatMessageStateNotDelivered"; + case LinphoneChatMessageStateFileTransferError: + return "LinphoneChatMessageStateFileTransferError"; + case LinphoneChatMessageStateFileTransferDone: + return "LinphoneChatMessageStateFileTransferDone "; } return NULL; } -LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg){ +LinphoneChatRoom *linphone_chat_message_get_chat_room(LinphoneChatMessage *msg) { return msg->chat_room; } -const LinphoneAddress* linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) { +const LinphoneAddress *linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) { return linphone_chat_room_get_peer_address(msg->chat_room); } -void linphone_chat_message_set_user_data(LinphoneChatMessage* message,void* ud) { - message->message_userdata=ud; +void linphone_chat_message_set_user_data(LinphoneChatMessage *msg, void *ud) { + msg->message_userdata = ud; } -void* linphone_chat_message_get_user_data(const LinphoneChatMessage* message) { - return message->message_userdata; +void *linphone_chat_message_get_user_data(const LinphoneChatMessage *msg) { + return msg->message_userdata; } -const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message) { - return message->external_body_url; +const char *linphone_chat_message_get_external_body_url(const LinphoneChatMessage *msg) { + return msg->external_body_url; } -void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message, const char* url) { - if (message->external_body_url) { - ms_free(message->external_body_url); +void linphone_chat_message_set_external_body_url(LinphoneChatMessage *msg, const char *url) { + if (msg->external_body_url) { + ms_free(msg->external_body_url); } - message->external_body_url=url?ms_strdup(url):NULL; + msg->external_body_url = url ? ms_strdup(url) : NULL; } -const char* linphone_chat_message_get_appdata(const LinphoneChatMessage* message){ - return message->appdata; +const char *linphone_chat_message_get_appdata(const LinphoneChatMessage *msg) { + return msg->appdata; } -void linphone_chat_message_set_appdata(LinphoneChatMessage* message, const char* data){ - if ( message->appdata ){ - ms_free(message->appdata); +void linphone_chat_message_set_appdata(LinphoneChatMessage *msg, const char *data) { + if (msg->appdata) { + ms_free(msg->appdata); } - message->appdata = data? ms_strdup(data) : NULL; - linphone_chat_message_store_appdata(message); + msg->appdata = data ? ms_strdup(data) : NULL; + linphone_chat_message_store_appdata(msg); } - -const LinphoneContent *linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage*message) { - return message->file_transfer_information; +const LinphoneContent *linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage *msg) { + return msg->file_transfer_information; } -static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *msg, void *data, size_t offset, const uint8_t *buffer, size_t size){ - LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; - LinphoneCore *lc = chatMsg->chat_room->lc; +static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, void *data, size_t offset, + const uint8_t *buffer, size_t size) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + LinphoneCore *lc = msg->chat_room->lc; - if (!chatMsg->http_request || belle_http_request_is_cancelled(chatMsg->http_request)) { - ms_warning("Cancelled request for msg [%p], ignoring %s", chatMsg, __FUNCTION__); + if (!msg->http_request || belle_http_request_is_cancelled(msg->http_request)) { + ms_warning("Cancelled request for msg [%p], ignoring %s", msg, __FUNCTION__); return; } @@ -1113,52 +1190,58 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t return; } - if (linphone_content_get_key(chatMsg->file_transfer_information) != NULL) { /* we have a key, we must decrypt the file */ + if (linphone_content_get_key(msg->file_transfer_information) != + NULL) { /* we have a key, we must decrypt the file */ /* get data from callback to a plainBuffer */ char *plainBuffer = (char *)malloc(size); - lime_decryptFile(linphone_content_get_cryptoContext_address(chatMsg->file_transfer_information), (unsigned char *)linphone_content_get_key(chatMsg->file_transfer_information), size, plainBuffer, (char *)buffer); - if (linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)) { + lime_decryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), + (unsigned char *)linphone_content_get_key(msg->file_transfer_information), size, plainBuffer, + (char *)buffer); + if (linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)) { LinphoneBuffer *lb = linphone_buffer_new_from_data((unsigned char *)plainBuffer, size); - linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, lb); + 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, chatMsg, chatMsg->file_transfer_information, plainBuffer, size); + linphone_core_notify_file_transfer_recv(lc, msg, msg->file_transfer_information, plainBuffer, size); } free(plainBuffer); } else { /* regular file, no deciphering */ - if (linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)) { + if (linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)) { LinphoneBuffer *lb = linphone_buffer_new_from_data(buffer, size); - linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, lb); + 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, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); + linphone_core_notify_file_transfer_recv(lc, msg, msg->file_transfer_information, (char *)buffer, size); } } return; } - -static LinphoneContent* linphone_chat_create_file_transfer_information_from_headers(const belle_sip_message_t* message ){ +static LinphoneContent *linphone_chat_create_file_transfer_information_from_headers(const belle_sip_message_t *m) { LinphoneContent *content = linphone_content_new(); - belle_sip_header_content_length_t* content_length_hdr = BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(message, "Content-Length")); - belle_sip_header_content_type_t* content_type_hdr = BELLE_SIP_HEADER_CONTENT_TYPE(belle_sip_message_get_header(message, "Content-Type")); - const char* type = NULL,*subtype = NULL; + belle_sip_header_content_length_t *content_length_hdr = + BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(m, "Content-Length")); + belle_sip_header_content_type_t *content_type_hdr = + BELLE_SIP_HEADER_CONTENT_TYPE(belle_sip_message_get_header(m, "Content-Type")); + const char *type = NULL, *subtype = NULL; linphone_content_set_name(content, ""); - if( content_type_hdr ){ + if (content_type_hdr) { type = belle_sip_header_content_type_get_type(content_type_hdr); subtype = belle_sip_header_content_type_get_subtype(content_type_hdr); - ms_message("Extracted content type %s / %s from header", type?type:"", subtype?subtype:""); - if( type ) linphone_content_set_type(content, type); - if( subtype ) linphone_content_set_subtype(content, subtype); + ms_message("Extracted content type %s / %s from header", type ? type : "", subtype ? subtype : ""); + if (type) + linphone_content_set_type(content, type); + if (subtype) + linphone_content_set_subtype(content, subtype); } - if( content_length_hdr ){ + if (content_length_hdr) { linphone_content_set_size(content, belle_sip_header_content_length_get_content_length(content_length_hdr)); ms_message("Extracted content length %i from header", (int)linphone_content_get_size(content)); } @@ -1166,32 +1249,35 @@ static LinphoneContent* linphone_chat_create_file_transfer_information_from_head return content; } -static void linphone_chat_process_response_headers_from_get_file(void *data, const belle_http_response_event_t *event){ - if (event->response){ +static void linphone_chat_process_response_headers_from_get_file(void *data, const belle_http_response_event_t *event) { + if (event->response) { /*we are receiving a response, set a specific body handler to acquire the response. * if not done, belle-sip will create a memory body handler, the default*/ - LinphoneChatMessage *message=(LinphoneChatMessage *)belle_sip_object_data_get(BELLE_SIP_OBJECT(event->request),"message"); - belle_sip_message_t* response = BELLE_SIP_MESSAGE(event->response); + LinphoneChatMessage *msg = + (LinphoneChatMessage *)belle_sip_object_data_get(BELLE_SIP_OBJECT(event->request), "msg"); + belle_sip_message_t *response = BELLE_SIP_MESSAGE(event->response); size_t body_size = 0; - if( message->file_transfer_information == NULL ){ - ms_warning("No file transfer information for message %p: creating...", message); - message->file_transfer_information = linphone_chat_create_file_transfer_information_from_headers(response); + if (msg->file_transfer_information == NULL) { + ms_warning("No file transfer information for msg %p: creating...", msg); + msg->file_transfer_information = linphone_chat_create_file_transfer_information_from_headers(response); } - if( message->file_transfer_information ){ - body_size = linphone_content_get_size(message->file_transfer_information); + if (msg->file_transfer_information) { + body_size = linphone_content_get_size(msg->file_transfer_information); } - if (message->file_transfer_filepath == NULL) { + if (msg->file_transfer_filepath == NULL) { belle_sip_message_set_body_handler( - (belle_sip_message_t*)event->response, - (belle_sip_body_handler_t*)belle_sip_user_body_handler_new(body_size, linphone_chat_message_file_transfer_on_progress,on_recv_body,NULL,message) - ); + (belle_sip_message_t *)event->response, + (belle_sip_body_handler_t *)belle_sip_user_body_handler_new( + body_size, linphone_chat_message_file_transfer_on_progress, on_recv_body, NULL, msg)); } else { - belle_sip_body_handler_t *bh = (belle_sip_body_handler_t *)belle_sip_file_body_handler_new(message->file_transfer_filepath, linphone_chat_message_file_transfer_on_progress, message); + belle_sip_body_handler_t *bh = (belle_sip_body_handler_t *)belle_sip_file_body_handler_new( + msg->file_transfer_filepath, linphone_chat_message_file_transfer_on_progress, msg); if (belle_sip_body_handler_get_size(bh) == 0) { - /* If the size of the body has not been initialized from the file stat, use the one from the file_transfer_information. */ + /* If the size of the body has not been initialized from the file stat, use the one from the + * file_transfer_information. */ belle_sip_body_handler_set_size(bh, body_size); } belle_sip_message_set_body_handler((belle_sip_message_t *)event->response, bh); @@ -1199,156 +1285,150 @@ static void linphone_chat_process_response_headers_from_get_file(void *data, con } } -static void linphone_chat_process_response_from_get_file(void *data, const belle_http_response_event_t *event){ +static void linphone_chat_process_response_from_get_file(void *data, const belle_http_response_event_t *event) { /* check the answer code */ - if (event->response){ - int code=belle_http_response_get_status_code(event->response); - if (code==200) { - LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; - LinphoneCore *lc = chatMsg->chat_room->lc; + if (event->response) { + int code = belle_http_response_get_status_code(event->response); + if (code == 200) { + LinphoneChatMessage *msg = (LinphoneChatMessage *)data; + LinphoneCore *lc = msg->chat_room->lc; /* if the file was encrypted, finish the decryption and free context */ - if (linphone_content_get_key(chatMsg->file_transfer_information) != NULL) { - lime_decryptFile(linphone_content_get_cryptoContext_address(chatMsg->file_transfer_information), NULL, 0, NULL, NULL); + if (linphone_content_get_key(msg->file_transfer_information) != NULL) { + lime_decryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), NULL, 0, + NULL, NULL); } /* file downloaded succesfully, call again the callback with size at zero */ - if (linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)) { + if (linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)) { LinphoneBuffer *lb = linphone_buffer_new(); - linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, lb); + linphone_chat_message_cbs_get_file_transfer_recv(msg->callbacks)(msg, msg->file_transfer_information, + lb); linphone_buffer_unref(lb); } else { - linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, NULL, 0); - } - chatMsg->state = LinphoneChatMessageStateFileTransferDone; - if (chatMsg->cb) { - chatMsg->cb(chatMsg, chatMsg->state, chatMsg->cb_ud); - } - if (linphone_chat_message_cbs_get_msg_state_changed(chatMsg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(chatMsg->callbacks)(chatMsg, chatMsg->state); + linphone_core_notify_file_transfer_recv(lc, msg, msg->file_transfer_information, NULL, 0); } + linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferDone); } } } -void linphone_chat_message_download_file(LinphoneChatMessage *message) { - belle_http_request_listener_callbacks_t cbs={0}; +void linphone_chat_message_download_file(LinphoneChatMessage *msg) { + belle_http_request_listener_callbacks_t cbs = {0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; - const char *url=message->external_body_url; - char* ua; + const char *url = msg->external_body_url; + char *ua; if (url == NULL) { - ms_error("Cannot download file from chat message [%p] because url is NULL",message); + ms_error("Cannot download file from chat msg [%p] because url is NULL", msg); return; } ua = ms_strdup_printf("%s/%s", linphone_core_get_user_agent_name(), linphone_core_get_user_agent_version()); - uri=belle_generic_uri_parse(url); + uri = belle_generic_uri_parse(url); - message->http_request=belle_http_request_create("GET", - uri, - belle_sip_header_create("User-Agent",ua), - NULL); - belle_sip_object_ref(message->http_request); /* keep a reference on the request to be able to cancel the download */ + msg->http_request = belle_http_request_create("GET", uri, belle_sip_header_create("User-Agent", ua), NULL); + belle_sip_object_ref(msg->http_request); /* keep a reference on the request to be able to cancel the download */ ms_free(ua); - cbs.process_response_headers=linphone_chat_process_response_headers_from_get_file; - cbs.process_response=linphone_chat_process_response_from_get_file; - cbs.process_io_error=process_io_error_download; - cbs.process_auth_requested=process_auth_requested_download; - l=belle_http_request_listener_create_from_callbacks(&cbs, (void *)message); - belle_sip_object_data_set(BELLE_SIP_OBJECT(message->http_request),"message",(void *)message,NULL); - message->state = LinphoneChatMessageStateInProgress; /* start the download, status is In Progress */ - belle_http_provider_send_request(message->chat_room->lc->http_provider,message->http_request,l); + cbs.process_response_headers = linphone_chat_process_response_headers_from_get_file; + cbs.process_response = linphone_chat_process_response_from_get_file; + cbs.process_io_error = process_io_error_download; + cbs.process_auth_requested = process_auth_requested_download; + l = belle_http_request_listener_create_from_callbacks(&cbs, (void *)msg); + belle_sip_object_data_set(BELLE_SIP_OBJECT(msg->http_request), "msg", (void *)msg, NULL); + linphone_chat_message_set_state(msg, LinphoneChatMessageStateInProgress); /* start the download, status is In Progress */ + belle_http_provider_send_request(msg->chat_room->lc->http_provider, msg->http_request, l); } -void linphone_chat_message_start_file_download(LinphoneChatMessage *message, LinphoneChatMessageStateChangedCb status_cb, void *ud) { - message->cb = status_cb; - message->cb_ud = ud; - linphone_chat_message_download_file(message); +void linphone_chat_message_start_file_download(LinphoneChatMessage *msg, + LinphoneChatMessageStateChangedCb status_cb, void *ud) { + msg->message_state_changed_cb = status_cb; + msg->message_state_changed_user_data = ud; + linphone_chat_message_download_file(msg); } void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { if (msg->http_request) { if (!belle_http_request_is_cancelled(msg->http_request)) { - ms_message("Cancelling file transfer %s - msg [%p] chat room[%p]", (msg->external_body_url==NULL)?linphone_core_get_file_transfer_server(msg->chat_room->lc):msg->external_body_url, msg, msg->chat_room); + ms_message("Cancelling file transfer %s - msg [%p] chat room[%p]", + (msg->external_body_url == NULL) ? linphone_core_get_file_transfer_server(msg->chat_room->lc) + : msg->external_body_url, + msg, msg->chat_room); belle_http_provider_cancel_request(msg->chat_room->lc->http_provider, msg->http_request); belle_sip_object_unref(msg->http_request); msg->http_request = NULL; - msg->state = LinphoneChatMessageStateNotDelivered; - if (msg->cb) { - msg->cb(msg, msg->state, msg->cb_ud); - } - if (linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)) { - linphone_chat_message_cbs_get_msg_state_changed(msg->callbacks)(msg, msg->state); - } + linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered); } } else { ms_message("No existing file transfer - nothing to cancel"); } } - -void linphone_chat_message_set_from_address(LinphoneChatMessage* message, const LinphoneAddress* from) { - if(message->from) linphone_address_destroy(message->from); - message->from=linphone_address_clone(from); +void linphone_chat_message_set_from_address(LinphoneChatMessage *msg, const LinphoneAddress *from) { + if (msg->from) + linphone_address_destroy(msg->from); + msg->from = linphone_address_clone(from); } -const LinphoneAddress* linphone_chat_message_get_from_address(const LinphoneChatMessage* message) { - return message->from; +const LinphoneAddress *linphone_chat_message_get_from_address(const LinphoneChatMessage *msg) { + return msg->from; } -void linphone_chat_message_set_to_address(LinphoneChatMessage* message, const LinphoneAddress* to) { - if(message->to) linphone_address_destroy(message->to); - message->to=linphone_address_clone(to); +void linphone_chat_message_set_to_address(LinphoneChatMessage *msg, const LinphoneAddress *to) { + if (msg->to) + linphone_address_destroy(msg->to); + msg->to = linphone_address_clone(to); } -const LinphoneAddress* linphone_chat_message_get_to_address(const LinphoneChatMessage* message){ - if (message->to) return message->to; - if (message->dir==LinphoneChatMessageOutgoing){ - return message->chat_room->peer_url; +const LinphoneAddress *linphone_chat_message_get_to_address(const LinphoneChatMessage *msg) { + if (msg->to) + return msg->to; + if (msg->dir == LinphoneChatMessageOutgoing) { + return msg->chat_room->peer_url; } return NULL; } -LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage* message){ - return message->dir==LinphoneChatMessageOutgoing ? message->from : message->to; +LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage *msg) { + return msg->dir == LinphoneChatMessageOutgoing ? msg->from : msg->to; } -time_t linphone_chat_message_get_time(const LinphoneChatMessage* message) { - return message->time; +time_t linphone_chat_message_get_time(const LinphoneChatMessage *msg) { + return msg->time; } -LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage* message) { - return message->state; +LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage *msg) { + return msg->state; } -const char * linphone_chat_message_get_text(const LinphoneChatMessage* message) { - return message->message; +const char *linphone_chat_message_get_text(const LinphoneChatMessage *msg) { + return msg->message; } -void linphone_chat_message_add_custom_header(LinphoneChatMessage* message, const char *header_name, const char *header_value){ - message->custom_headers=sal_custom_header_append(message->custom_headers,header_name,header_value); +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); } -const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name){ - return sal_custom_header_find(message->custom_headers,header_name); +const char *linphone_chat_message_get_custom_header(LinphoneChatMessage *msg, const char *header_name) { + return sal_custom_header_find(msg->custom_headers, header_name); } -bool_t linphone_chat_message_is_read(LinphoneChatMessage* message) { - return message->is_read; +bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) { + return msg->is_read; } -bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message) { - return message->dir == LinphoneChatMessageOutgoing; +bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage *msg) { + return msg->dir == LinphoneChatMessageOutgoing; } -unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage* message) { - return message->storage_id; +unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage *msg) { + return msg->storage_id; } -LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) { +LinphoneChatMessage *linphone_chat_message_clone(const LinphoneChatMessage *msg) { /*struct _LinphoneChatMessage { - char* message; + char* msg; LinphoneChatRoom* chat_room; LinphoneChatMessageStateChangeCb cb; void* cb_ud; @@ -1359,35 +1439,47 @@ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) SalCustomHeader *custom_headers; LinphoneChatMessageState state; };*/ - LinphoneChatMessage* new_message = linphone_chat_room_create_message(msg->chat_room,msg->message); - if (msg->external_body_url) new_message->external_body_url=ms_strdup(msg->external_body_url); - if (msg->appdata) new_message->appdata = ms_strdup(msg->appdata); - new_message->cb=msg->cb; - new_message->cb_ud=msg->cb_ud; - new_message->message_userdata=msg->message_userdata; - new_message->cb=msg->cb; - new_message->time=msg->time; - new_message->state=msg->state; - new_message->storage_id=msg->storage_id; - if (msg->from) new_message->from=linphone_address_clone(msg->from); - if (msg->file_transfer_filepath) new_message->file_transfer_filepath=ms_strdup(msg->file_transfer_filepath); - if (msg->file_transfer_information) new_message->file_transfer_information=linphone_content_copy(msg->file_transfer_information); + LinphoneChatMessage *new_message = linphone_chat_room_create_message(msg->chat_room, msg->message); + if (msg->external_body_url) + new_message->external_body_url = ms_strdup(msg->external_body_url); + if (msg->appdata) + new_message->appdata = ms_strdup(msg->appdata); + new_message->message_state_changed_cb = msg->message_state_changed_cb; + new_message->message_state_changed_user_data = msg->message_state_changed_user_data; + new_message->message_userdata = msg->message_userdata; + new_message->time = msg->time; + new_message->state = msg->state; + new_message->storage_id = msg->storage_id; + if (msg->from) + new_message->from = linphone_address_clone(msg->from); + if (msg->file_transfer_filepath) + new_message->file_transfer_filepath = ms_strdup(msg->file_transfer_filepath); + if (msg->file_transfer_information) + new_message->file_transfer_information = linphone_content_copy(msg->file_transfer_information); return new_message; } -void linphone_chat_message_destroy(LinphoneChatMessage* msg){ +void linphone_chat_message_destroy(LinphoneChatMessage *msg) { belle_sip_object_unref(msg); } -static void _linphone_chat_message_destroy(LinphoneChatMessage* msg) { - if (msg->op) sal_op_release(msg->op); - if (msg->message) ms_free(msg->message); - if (msg->external_body_url) ms_free(msg->external_body_url); - if (msg->appdata) ms_free(msg->appdata); - if (msg->from) linphone_address_destroy(msg->from); - if (msg->to) linphone_address_destroy(msg->to); - if (msg->custom_headers) sal_custom_header_free(msg->custom_headers); - if (msg->content_type) ms_free(msg->content_type); +static void _linphone_chat_message_destroy(LinphoneChatMessage *msg) { + if (msg->op) + sal_op_release(msg->op); + if (msg->message) + ms_free(msg->message); + if (msg->external_body_url) + ms_free(msg->external_body_url); + if (msg->appdata) + ms_free(msg->appdata); + if (msg->from) + linphone_address_destroy(msg->from); + if (msg->to) + linphone_address_destroy(msg->to); + if (msg->custom_headers) + sal_custom_header_free(msg->custom_headers); + if (msg->content_type) + ms_free(msg->content_type); if (msg->file_transfer_information) { linphone_content_unref(msg->file_transfer_information); } @@ -1397,30 +1489,29 @@ static void _linphone_chat_message_destroy(LinphoneChatMessage* msg) { linphone_chat_message_cbs_unref(msg->callbacks); } -LinphoneChatMessage * linphone_chat_message_ref(LinphoneChatMessage *msg){ +LinphoneChatMessage *linphone_chat_message_ref(LinphoneChatMessage *msg) { belle_sip_object_ref(msg); return msg; } -void linphone_chat_message_unref(LinphoneChatMessage *msg){ +void linphone_chat_message_unref(LinphoneChatMessage *msg) { belle_sip_object_unref(msg); } -static void linphone_chat_message_release(LinphoneChatMessage *msg){ - /*mark the chat message as orphan (it has no chat room anymore), and unref it*/ +static void linphone_chat_message_release(LinphoneChatMessage *msg) { + /*mark the chat msg as orphan (it has no chat room anymore), and unref it*/ msg->chat_room = NULL; linphone_chat_message_unref(msg); } -const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg){ +const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg) { return linphone_error_info_from_sal_op(msg->op); } -LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage* msg) { +LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage *msg) { return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg)); } - void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath) { if (msg->file_transfer_filepath != NULL) { ms_free(msg->file_transfer_filepath); @@ -1428,25 +1519,28 @@ void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, msg->file_transfer_filepath = ms_strdup(filepath); } -const char * linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg) { +const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg) { return msg->file_transfer_filepath; } -LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg) { +LinphoneChatMessageCbs *linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg) { return msg->callbacks; } -LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent* initial_content) { - LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage); - msg->callbacks=linphone_chat_message_cbs_new(); - msg->chat_room=(LinphoneChatRoom*)cr; +LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, + const LinphoneContent *initial_content) { + LinphoneChatMessage *msg = belle_sip_object_new(LinphoneChatMessage); + msg->callbacks = linphone_chat_message_cbs_new(); + msg->chat_room = (LinphoneChatRoom *)cr; msg->message = NULL; - msg->is_read=TRUE; + msg->is_read = TRUE; msg->file_transfer_information = linphone_content_copy(initial_content); - msg->dir=LinphoneChatMessageOutgoing; + msg->dir = LinphoneChatMessageOutgoing; linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(cr->lc))); - msg->content_type=NULL; /* this will be set to application/vnd.gsma.rcs-ft-http+xml when we will transfer the xml reply from server to the peers */ - msg->http_request=NULL; /* this will store the http request during file upload to the server */ + msg->content_type = + NULL; /* this will be set to application/vnd.gsma.rcs-ft-http+xml when we will transfer the xml reply from + server to the peers */ + msg->http_request = NULL; /* this will store the http request during file upload to the server */ return msg; } diff --git a/coreapi/private.h b/coreapi/private.h index 21a1d8b36..62741a1cb 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -205,8 +205,8 @@ struct _LinphoneChatMessage { LinphoneChatMessageCbs *callbacks; LinphoneChatMessageDir dir; char* message; - LinphoneChatMessageStateChangedCb cb; - void* cb_ud; + LinphoneChatMessageStateChangedCb message_state_changed_cb; + void* message_state_changed_user_data; void* message_userdata; char* appdata; char* external_body_url; @@ -501,7 +501,7 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj); /*chat*/ void linphone_chat_room_release(LinphoneChatRoom *cr); void linphone_chat_message_destroy(LinphoneChatMessage* msg); -void linphone_chat_message_update_state(LinphoneChatMessage* chat_msg ); +void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state); /**/ struct _LinphoneProxyConfig diff --git a/tester/CMakeLists.txt b/tester/CMakeLists.txt index 2b02ff6c0..a5cdf648e 100644 --- a/tester/CMakeLists.txt +++ b/tester/CMakeLists.txt @@ -45,37 +45,33 @@ set(SOURCE_FILES tunnel_tester.c upnp_tester.c video_tester.c -) + ) add_definitions(-DBC_CONFIG_FILE="config.h") if(IOS) - -add_library(linphonetester STATIC ${SOURCE_FILES}) -target_include_directories(linphonetester PUBLIC ${CUNIT_INCLUDE_DIRS} PRIVATE common) -target_link_libraries(linphonetester linphone ${CUNIT_LIBRARIES}) -install(TARGETS linphonetester - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE -) -install(FILES "liblinphone_tester.h" "common/bc_tester_utils.h" - DESTINATION include/linphone - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ -) - + add_library(linphonetester STATIC ${SOURCE_FILES}) + target_include_directories(linphonetester PUBLIC ${CUNIT_INCLUDE_DIRS} PRIVATE common) + target_link_libraries(linphonetester linphone ${CUNIT_LIBRARIES}) + install(TARGETS linphonetester + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + ) + install(FILES "liblinphone_tester.h" "common/bc_tester_utils.h" + DESTINATION include/linphone + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) else() - -add_executable(liblinphone_tester ${SOURCE_FILES}) -set_target_properties(liblinphone_tester PROPERTIES LINKER_LANGUAGE CXX) -target_include_directories(liblinphone_tester PUBLIC ${CUNIT_INCLUDE_DIRS} PRIVATE common) -target_link_libraries(liblinphone_tester linphone ${CUNIT_LIBRARIES}) -if (GTK2_FOUND) - target_compile_definitions(liblinphone_tester PRIVATE HAVE_GTK) - target_include_directories(liblinphone_tester PUBLIC ${GTK2_INCLUDE_DIRS}) - target_link_libraries(liblinphone_tester linphone ${GTK2_LIBRARIES}) -endif() - + add_executable(liblinphone_tester ${SOURCE_FILES}) + set_target_properties(liblinphone_tester PROPERTIES LINKER_LANGUAGE CXX) + target_include_directories(liblinphone_tester PUBLIC ${CUNIT_INCLUDE_DIRS} PRIVATE common) + target_link_libraries(liblinphone_tester linphone ${CUNIT_LIBRARIES}) + if (GTK2_FOUND) + target_compile_definitions(liblinphone_tester PRIVATE HAVE_GTK) + target_include_directories(liblinphone_tester PUBLIC ${GTK2_INCLUDE_DIRS}) + target_link_libraries(liblinphone_tester linphone ${GTK2_LIBRARIES}) + endif() endif() diff --git a/tester/flexisip_tester.c b/tester/flexisip_tester.c index c2bb8b780..758bab93e 100644 --- a/tester/flexisip_tester.c +++ b/tester/flexisip_tester.c @@ -784,7 +784,7 @@ static void file_transfer_message_rcs_to_external_body_client(void) { BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d"); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d"); BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1, int, "%d"); - BC_ASSERT_TRUE(compare_files(send_filepath, receive_filepath)); + compare_files(send_filepath, receive_filepath); linphone_content_unref(content); linphone_core_manager_destroy(marie); diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 264ddf580..1f885449f 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -318,7 +318,7 @@ void call_base_with_configfile(LinphoneMediaEncryption mode, bool_t enable_video void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy,bool_t enable_tunnel); bool_t call_with_caller_params(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr, const LinphoneCallParams *params); bool_t pause_call_1(LinphoneCoreManager* mgr_1,LinphoneCall* call_1,LinphoneCoreManager* mgr_2,LinphoneCall* call_2); -bool_t compare_files(const char *path1, const char *path2); +void compare_files(const char *path1, const char *path2); void check_media_direction(LinphoneCoreManager* mgr, LinphoneCall *call, MSList* lcs,LinphoneMediaDirection audio_dir, LinphoneMediaDirection video_dir); extern const MSAudioDiffParams audio_cmp_params; diff --git a/tester/message_tester.c b/tester/message_tester.c index f2e663483..c94bfae40 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -30,16 +30,16 @@ static char* message_external_body_url=NULL; -void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message) { +void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *msg) { stats* counters = get_stats(lc); counters->number_of_LinphoneMessageReceivedLegacy++; } -void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message) { - char* from=linphone_address_as_string(linphone_chat_message_get_from(message)); +void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* msg) { + char* from=linphone_address_as_string(linphone_chat_message_get_from(msg)); stats* counters; - const char *text=linphone_chat_message_get_text(message); - const char *external_body_url=linphone_chat_message_get_external_body_url(message); + const char *text=linphone_chat_message_get_text(msg); + const char *external_body_url=linphone_chat_message_get_external_body_url(msg); ms_message("Message from [%s] is [%s] , external URL [%s]",from?from:"" ,text?text:"" ,external_body_url?external_body_url:""); @@ -47,13 +47,13 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess counters = get_stats(lc); counters->number_of_LinphoneMessageReceived++; if (counters->last_received_chat_message) linphone_chat_message_unref(counters->last_received_chat_message); - counters->last_received_chat_message=linphone_chat_message_ref(message); - if (linphone_chat_message_get_file_transfer_information(message)) { + counters->last_received_chat_message=linphone_chat_message_ref(msg); + if (linphone_chat_message_get_file_transfer_information(msg)) { counters->number_of_LinphoneMessageReceivedWithFile++; - } else if (linphone_chat_message_get_external_body_url(message)) { + } else if (linphone_chat_message_get_external_body_url(msg)) { counters->number_of_LinphoneMessageExtBodyReceived++; if (message_external_body_url) { - BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(message),message_external_body_url); + BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(msg),message_external_body_url); message_external_body_url=NULL; } } @@ -62,18 +62,18 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess /** * function invoked when a file transfer is received. * */ -void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer){ +void file_transfer_received(LinphoneChatMessage *msg, const LinphoneContent* content, const LinphoneBuffer *buffer){ FILE* file=NULL; char *receive_file = bc_tester_file("receive_file.dump"); - LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); LinphoneCore *lc = linphone_chat_room_get_core(cr); - if (!linphone_chat_message_get_user_data(message)) { + if (!linphone_chat_message_get_user_data(msg)) { /*first chunk, creating file*/ file = fopen(receive_file,"wb"); - linphone_chat_message_set_user_data(message,(void*)file); /*store fd for next chunks*/ + linphone_chat_message_set_user_data(msg,(void*)file); /*store fd for next chunks*/ } ms_free(receive_file); - file = (FILE*)linphone_chat_message_get_user_data(message); + file = (FILE*)linphone_chat_message_get_user_data(msg); if (linphone_buffer_is_empty(buffer)) { /* tranfer complete */ stats* counters = get_stats(lc); @@ -86,33 +86,32 @@ void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* } } -char big_file[128000]; /* a buffer to simulate a big file for the file transfer message test */ +char big_file[128000]; /* a buffer to simulate a big file for the file transfer msg test */ /* * function called when the file transfer is initiated. file content should be feed into object LinphoneContent * */ -LinphoneBuffer * tester_file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t size){ +LinphoneBuffer * tester_file_transfer_send(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t size){ LinphoneBuffer *lb; size_t file_size; size_t size_to_send; - FILE *file_to_send; uint8_t *buf; - - file_to_send = linphone_chat_message_get_user_data(message); + FILE *file_to_send = linphone_chat_message_get_user_data(msg); fseek(file_to_send, 0, SEEK_END); file_size = ftell(file_to_send); fseek(file_to_send, offset, SEEK_SET); size_to_send = MIN(size, file_size - offset); buf = ms_malloc(size_to_send); if (fread(buf, size_to_send, 1, file_to_send)!=size_to_send){ - // reaching end of file + // reaching end of file, close it + fclose(file_to_send); } lb = linphone_buffer_new_from_data(buf, size_to_send); ms_free(buf); return lb; } -LinphoneBuffer * tester_memory_file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t size){ +LinphoneBuffer * tester_memory_file_transfer_send(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t size){ size_t size_to_send = MIN(size, sizeof(big_file) - offset); return linphone_buffer_new_from_data((uint8_t *)big_file + offset, size_to_send); } @@ -120,19 +119,19 @@ LinphoneBuffer * tester_memory_file_transfer_send(LinphoneChatMessage *message, /** * function invoked to report file transfer progress. * */ -void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) { - LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); +void file_transfer_progress_indication(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t total) { + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); LinphoneCore *lc = linphone_chat_room_get_core(cr); - const LinphoneAddress* from_address = linphone_chat_message_get_from(message); - const LinphoneAddress* to_address = linphone_chat_message_get_to(message); - char *address = linphone_chat_message_is_outgoing(message)?linphone_address_as_string(to_address):linphone_address_as_string(from_address); + const LinphoneAddress* from_address = linphone_chat_message_get_from(msg); + const LinphoneAddress* to_address = linphone_chat_message_get_to(msg); + char *address = linphone_chat_message_is_outgoing(msg)?linphone_address_as_string(to_address):linphone_address_as_string(from_address); stats* counters = get_stats(lc); int progress = (int)((offset * 100)/total); ms_message(" File transfer [%d%%] %s of type [%s/%s] %s [%s] \n", progress - ,(linphone_chat_message_is_outgoing(message)?"sent":"received") + ,(linphone_chat_message_is_outgoing(msg)?"sent":"received") , linphone_content_get_type(content) , linphone_content_get_subtype(content) - ,(linphone_chat_message_is_outgoing(message)?"to":"from") + ,(linphone_chat_message_is_outgoing(msg)?"to":"from") , address); counters->progress_of_LinphoneFileTransfer = progress; free(address); @@ -155,9 +154,6 @@ void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); LinphoneCore *lc = linphone_chat_room_get_core(cr); stats* counters = get_stats(lc); - const char *text = linphone_chat_message_get_text(msg); - if (!text) text = ""; - ms_message("Message [%s] [%s]",text, linphone_chat_message_state_to_string(state)); switch (state) { case LinphoneChatMessageStateIdle: return; @@ -177,7 +173,7 @@ void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, counters->number_of_LinphoneMessageFileTransferDone++; return; } - ms_error("Unexpected state [%s] for message [%p]",linphone_chat_message_state_to_string(state), msg); + ms_error("Unexpected state [%s] for msg [%p]",linphone_chat_message_state_to_string(state), msg); } static void text_message(void) { @@ -188,7 +184,7 @@ static void text_message(void) { chat_room = linphone_core_get_chat_room(pauline->lc,marie->identity); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -212,7 +208,7 @@ static void text_message_within_dialog(void) { chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -251,7 +247,7 @@ static void text_message_with_credential_from_auth_cb(void) { chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -281,7 +277,7 @@ static void text_message_with_privacy(void) { BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity)); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -326,7 +322,7 @@ static void text_message_compatibility_mode(void) { chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -351,14 +347,14 @@ static void text_message_with_ack(void) { { LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); + LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d"); @@ -376,23 +372,24 @@ static void text_message_with_external_body(void) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); + LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); - linphone_chat_message_set_external_body_url(message,message_external_body_url="http://www.linphone.org"); + message_external_body_url="http://www.linphone.org"; + linphone_chat_message_set_external_body_url(msg,message_external_body_url); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); - /* check transient message list: the message should be in it, and should be the only one */ + /* check transient msg list: the msg should be in it, and should be the only one */ BC_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 1, int, "%d"); - BC_ASSERT_PTR_EQUAL(ms_list_nth_data(chat_room->transient_messages,0), message); + BC_ASSERT_PTR_EQUAL(ms_list_nth_data(chat_room->transient_messages,0), msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); @@ -406,8 +403,7 @@ static void text_message_with_external_body(void) { linphone_core_manager_destroy(pauline); } -bool_t compare_files(const char *path1, const char *path2) { - bool_t res; +void compare_files(const char *path1, const char *path2) { size_t size1; size_t size2; uint8_t *buf1; @@ -415,58 +411,73 @@ bool_t compare_files(const char *path1, const char *path2) { buf1 = (uint8_t*)ms_load_path_content(path1, &size1); buf2 = (uint8_t*)ms_load_path_content(path2, &size2); - res = buf1 && buf2 && (size1 == size2) && (memcmp(buf1, buf2, size1) == 0); + BC_ASSERT_PTR_NOT_NULL(buf1); + BC_ASSERT_PTR_NOT_NULL(buf2); + BC_ASSERT_EQUAL(size1, size2, uint8_t, "%u"); + BC_ASSERT_EQUAL(memcmp(buf1, buf2, size1), 0, int, "%d"); ms_free(buf1); ms_free(buf2); - return res; +} + +LinphoneChatMessage* create_message_from_nowebcam(LinphoneChatRoom *chat_room) { + FILE *file_to_send = NULL; + LinphoneChatMessageCbs *cbs; + LinphoneContent* content; + LinphoneChatMessage* msg; + size_t file_size; + char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg"); + file_to_send = fopen(send_filepath, "rb"); + fseek(file_to_send, 0, SEEK_END); + file_size = ftell(file_to_send); + fseek(file_to_send, 0, SEEK_SET); + + content = linphone_core_create_content(chat_room->lc); + linphone_content_set_type(content,"image"); + linphone_content_set_subtype(content,"jpeg"); + linphone_content_set_size(content,file_size); /*total size to be transfered*/ + linphone_content_set_name(content,"nowebcamCIF.jpg"); + + + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); + cbs = linphone_chat_message_get_callbacks(msg); + linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send); + linphone_chat_message_set_user_data(msg, file_to_send); + + linphone_content_unref(content); + + return msg; } static void file_transfer_message(void) { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; - LinphoneChatMessageCbs *cbs; - LinphoneContent* content; - FILE *file_to_send = NULL; - size_t file_size; char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg"); + LinphoneChatMessage* msg; + LinphoneChatMessageCbs *cbs; char *receive_filepath = bc_tester_file("receive_file.dump"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); - file_to_send = fopen(send_filepath, "rb"); - fseek(file_to_send, 0, SEEK_END); - file_size = ftell(file_to_send); - fseek(file_to_send, 0, SEEK_SET); - /* Globally configure an http file transfer server. */ linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php"); /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ - content = linphone_core_create_content(pauline->lc); - linphone_content_set_type(content,"image"); - linphone_content_set_subtype(content,"jpeg"); - linphone_content_set_size(content,file_size); /*total size to be transfered*/ - linphone_content_set_name(content,"nowebcamCIF.jpg"); - message = linphone_chat_room_create_file_transfer_message(chat_room, content); - linphone_chat_message_set_user_data(message, file_to_send); - cbs = linphone_chat_message_get_callbacks(message); + /* create a file transfer msg */ + msg = create_message_from_nowebcam(chat_room); + cbs = linphone_chat_message_get_callbacks(msg); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - fclose(file_to_send); if (marie->stat.last_received_chat_message ) { cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); @@ -475,12 +486,11 @@ static void file_transfer_message(void) { } BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1)); - BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d"); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); //sent twice because of file transfer BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d"); BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1, int, "%d"); - BC_ASSERT_TRUE(compare_files(send_filepath, receive_filepath)); + compare_files(send_filepath, receive_filepath); - linphone_content_unref(content); linphone_core_manager_destroy(pauline); ms_free(send_filepath); ms_free(receive_filepath); @@ -495,7 +505,7 @@ static void small_file_transfer_message(void) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); int i; LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; + LinphoneChatMessage* msg; LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ @@ -514,23 +524,23 @@ static void small_file_transfer_message(void) { /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ + /* create a file transfer msg */ content = linphone_core_create_content(pauline->lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,SMALL_FILE_SIZE); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); - message = linphone_chat_room_create_file_transfer_message(chat_room, content); + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_memory_file_transfer_send); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); if (marie->stat.last_received_chat_message ) { cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message); @@ -540,7 +550,7 @@ static void small_file_transfer_message(void) { } BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1)); - BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d"); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d"); BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1, int, "%d"); @@ -565,7 +575,7 @@ static void lime_file_transfer_message_base(bool_t encrypt_file) { LinphoneCoreManager *marie, *pauline; LinphoneChatRoom *chat_room; LinphoneContent *content; - LinphoneChatMessage *message; + LinphoneChatMessage *msg; LinphoneChatMessageCbs *cbs; char *pauline_id, *marie_id; char *filepath; @@ -617,25 +627,25 @@ static void lime_file_transfer_message_base(bool_t encrypt_file) { /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ + /* create a file transfer msg */ content = linphone_core_create_content(pauline->lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"big_file.txt"); - message = linphone_chat_room_create_file_transfer_message(chat_room, content); + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_memory_file_transfer_send); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); if (marie->stat.last_received_chat_message ) { cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message); @@ -676,7 +686,7 @@ static void printHex(char *title, uint8_t *data, uint32_t length) { ms_message("%s", debug_string_buffer); } -#define PLAIN_TEXT_TEST_MESSAGE "Ceci est un fabuleux message de test à encrypter" +#define PLAIN_TEXT_TEST_MESSAGE "Ceci est un fabuleux msg de test à encrypter" static void lime_unit(void) { int retval; size_t size; @@ -738,7 +748,7 @@ static void lime_unit(void) { printHex("sessionID", associatedKey.sessionId, 32); ms_message("session index %d\n", associatedKey.sessionIndex); - /* encrypt/decrypt a message */ + /* encrypt/decrypt a msg */ lime_encryptMessage(associatedKeys.peerKeys[0], (uint8_t *)PLAIN_TEXT_TEST_MESSAGE, strlen(PLAIN_TEXT_TEST_MESSAGE), senderZID, encryptedMessage); printHex("Ciphered", encryptedMessage, strlen((char *)encryptedMessage)); /* invert sender and receiverZID to decrypt/authenticate */ @@ -776,7 +786,7 @@ static void lime_unit(void) { fclose(CACHE); xmlFreeDoc(cacheBuffer); - /**** Higher level tests using 2 caches to encrypt/decrypt a message ****/ + /**** Higher level tests using 2 caches to encrypt/decrypt a msg ****/ /* Create Alice cache file and then load it */ CACHE = fopen_from_write_dir("ZIDCacheAlice.xml", "wb"); fprintf(CACHE, "\nef7692d0792a67491ae2d44e005dbe0399643d953a2202dd9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899sip:pauline@sip.example.org9111ebeb52e50edcc6fcb3eea1a2d3ae3c2c75d3668923e83c59d0f47245515060f020a3fe11dc2cc0e1e8ed9341b4cd14944db806ca4fc95456bbe45d95c43a5f9aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193bcffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b7719300000080000001cf011234567889643d953a2202ee9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899sip:pauline@sip.example.org72d80ab1cad243cf45634980c1d02cfb2df81ce0dd5dfcf1ebeacfc5345a917625d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193f69aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b7719322ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b771930000000f00000000"); @@ -803,21 +813,21 @@ static void lime_unit(void) { - /* encrypt a message */ + /* encrypt a msg */ retval = lime_createMultipartMessage(cacheBufferAlice, (uint8_t *)PLAIN_TEXT_TEST_MESSAGE, (uint8_t *)"sip:pauline@sip.example.org", &multipartMessage); BC_ASSERT_EQUAL_FATAL(retval, 0, int, "%d"); if (retval == 0) { - ms_message("Encrypted message created is %s", multipartMessage); + ms_message("Encrypted msg created is %s", multipartMessage); } - /* decrypt the multipart message */ + /* decrypt the multipart msg */ retval = lime_decryptMultipartMessage(cacheBufferBob, multipartMessage, &decryptedMessage); BC_ASSERT_EQUAL_FATAL(retval, 0, int, "%d"); if (retval == 0) { BC_ASSERT_STRING_EQUAL((char *)decryptedMessage, (char *)PLAIN_TEXT_TEST_MESSAGE); - ms_message("Succesfully decrypted message is %s", decryptedMessage); + ms_message("Succesfully decrypted msg is %s", decryptedMessage); } free(multipartMessage); free(decryptedMessage); @@ -877,7 +887,7 @@ static void lime_text_message(void) { BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedLegacy,1)); BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity)); - /* TODO : check the message arrived correctly deciphered */ + /* TODO : check the msg arrived correctly deciphered */ linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); @@ -889,7 +899,7 @@ static void file_transfer_message_io_error_upload(void) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); int i; LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; + LinphoneChatMessage* msg; LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ @@ -911,24 +921,24 @@ static void file_transfer_message_io_error_upload(void) { /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ + /* create a file transfer msg */ content = linphone_core_create_content(pauline->lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); - message = linphone_chat_room_create_file_transfer_message(chat_room, content); + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_memory_file_transfer_send); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); /*wait for file to be 25% uploaded and simultate a network error*/ BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer,25)); @@ -950,64 +960,38 @@ static void file_transfer_message_io_error_upload(void) { } } - -#ifdef TEST_IS_BUGGED_NO_CALL_TO_IO_ERROR_CALLBACK static void file_transfer_message_io_error_download(void) { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); - int i; LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; - LinphoneContent content; - const char* big_file_content="big file"; /* setting dummy file content to something */ + LinphoneChatMessage* msg; LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); - - reset_counters(&marie->stat); - reset_counters(&pauline->stat); - - /* setting dummy file content to something */ - for (i=0;ilc,"https://www.linphone.org:444/lft.php"); /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); + msg = create_message_from_nowebcam(chat_room); - /* create a file transfer message */ - memset(&content,0,sizeof(content)); - content.type="text"; - content.subtype="plain"; - content.size=sizeof(big_file); /*total size to be transfered*/ - content.name = "bigfile.txt"; - message = linphone_chat_room_create_file_transfer_message(chat_room, &content); - { - int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ - reset_counters(&marie->stat); - reset_counters(&pauline->stat); - } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + linphone_chat_room_send_message2(chat_room,msg,liblinphone_tester_chat_message_state_change,pauline->lc); - /* wait for marie to receive pauline's message */ + /* wait for marie to receive pauline's msg */ + BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageFileTransferDone,1)); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - - if (marie->stat.last_received_chat_message ) { /* get last message and use it to download file */ + /* get last msg and use it to download file */ + if (marie->stat.last_received_chat_message ) { + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change, marie->lc); /* wait for file to be 50% downloaded */ BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50)); /* and simulate network error */ sal_set_recv_error(marie->lc->sal, -1); } - - BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d"); + BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneMessageNotDelivered,1, 10000)); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d"); - BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageNotDelivered,1, int, "%d"); BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,0, int, "%d"); sal_set_recv_error(marie->lc->sal, 0); @@ -1015,14 +999,13 @@ static void file_transfer_message_io_error_download(void) { linphone_core_manager_destroy(marie); } } -#endif static void file_transfer_message_upload_cancelled(void) { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); int i; LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; + LinphoneChatMessage* msg; LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ @@ -1044,28 +1027,28 @@ static void file_transfer_message_upload_cancelled(void) { /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ + /* create a file transfer msg */ content = linphone_core_create_content(pauline->lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); - message = linphone_chat_room_create_file_transfer_message(chat_room, content); + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_memory_file_transfer_send); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); /*wait for file to be 50% uploaded and cancel the transfer */ BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer, 50)); - linphone_chat_message_cancel_file_transfer(message); + linphone_chat_message_cancel_file_transfer(msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageNotDelivered,1)); @@ -1079,53 +1062,27 @@ static void file_transfer_message_upload_cancelled(void) { } static void file_transfer_message_download_cancelled(void) { -#if 0 - int i; - char* to; LinphoneChatRoom* chat_room; - LinphoneChatMessage* message; - LinphoneContent content; - const char* big_file_content="big file"; /* setting dummy file content to something */ + LinphoneChatMessage* msg; LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); - /* setting dummy file content to something */ - for (i=0;ilc,"https://www.linphone.org:444/lft.php"); /* create a chatroom on pauline's side */ - to = linphone_address_as_string(marie->identity); - chat_room = linphone_core_create_chat_room(pauline->lc,to); + chat_room = linphone_core_get_chat_room(pauline->lc,marie->identity); + msg = create_message_from_nowebcam(chat_room); + linphone_chat_room_send_message2(chat_room,msg,liblinphone_tester_chat_message_state_change,pauline->lc); - /* create a file transfer message */ - memset(&content,0,sizeof(content)); - content.type="text"; - content.subtype="plain"; - content.size=sizeof(big_file); /*total size to be transfered*/ - content.name = "bigfile.txt"; - message = linphone_chat_room_create_file_transfer_message(chat_room, &content); - { - int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ - reset_counters(&marie->stat); - reset_counters(&pauline->stat); - } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); - - /* wait for marie to receive pauline's message */ + /* wait for marie to receive pauline's msg */ BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - if (marie->stat.last_received_chat_message ) { /* get last message and use it to download file */ + if (marie->stat.last_received_chat_message ) { /* get last msg and use it to download file */ linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change, marie->lc); /* wait for file to be 50% downloaded */ BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50)); @@ -1140,8 +1097,6 @@ static void file_transfer_message_download_cancelled(void) { linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); -#endif - ms_error("Test skipped"); } static void file_transfer_using_external_body_url(void) { @@ -1149,7 +1104,7 @@ static void file_transfer_using_external_body_url(void) { LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); LinphoneChatMessageCbs *cbs; LinphoneChatRoom *chat_room; - LinphoneChatMessage *message; + LinphoneChatMessage *msg; LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); @@ -1161,13 +1116,13 @@ static void file_transfer_using_external_body_url(void) { /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - message = linphone_chat_room_create_message(chat_room, NULL); + msg = linphone_chat_room_create_message(chat_room, NULL); - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_message_set_external_body_url(message, "https://www.linphone.org:444//tmp/54ec58280ace9_c30709218df8eaba61d1.jpg"); - linphone_chat_room_send_chat_message(chat_room, message); + linphone_chat_message_set_external_body_url(msg, "https://www.linphone.org:444//tmp/54ec58280ace9_c30709218df8eaba61d1.jpg"); + linphone_chat_room_send_chat_message(chat_room, msg); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); if (marie->stat.last_received_chat_message) { @@ -1184,12 +1139,9 @@ static void file_transfer_2_messages_simultaneously() { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneChatRoom* pauline_room; - LinphoneChatMessage* message; - LinphoneChatMessage* message2; + LinphoneChatMessage* msg; + LinphoneChatMessage* msg2; LinphoneChatMessageCbs *cbs; - LinphoneContent* content; - FILE *file_to_send = NULL; - size_t file_size; char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg"); char *receive_filepath = bc_tester_file("receive_file.dump"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); @@ -1197,53 +1149,34 @@ static void file_transfer_2_messages_simultaneously() { reset_counters(&marie->stat); reset_counters(&pauline->stat); - file_to_send = fopen(send_filepath, "rb"); - fseek(file_to_send, 0, SEEK_END); - file_size = ftell(file_to_send); - fseek(file_to_send, 0, SEEK_SET); - /* Globally configure an http file transfer server. */ linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php"); /* create a chatroom on pauline's side */ pauline_room = linphone_core_get_chat_room(pauline->lc, marie->identity); - /* create a file transfer message */ - content = linphone_core_create_content(pauline->lc); - linphone_content_set_type(content,"image"); - linphone_content_set_subtype(content,"jpeg"); - linphone_content_set_size(content,file_size); /*total size to be transfered*/ - linphone_content_set_name(content,"nowebcamCIF.jpg"); - message = linphone_chat_room_create_file_transfer_message(pauline_room, content); - linphone_chat_message_set_user_data(message, file_to_send); - message2 = linphone_chat_room_create_file_transfer_message(pauline_room, content); - linphone_chat_message_set_user_data(message2, file_to_send); - linphone_content_unref(content); - - + msg = create_message_from_nowebcam(pauline_room); + msg2 = create_message_from_nowebcam(pauline_room); { - /*just to have time to purge message stored in the server*/ + /*just to have time to purge msg stored in the server*/ int dummy=0; wait_for_until(marie->lc,pauline->lc,&dummy,1,100); reset_counters(&marie->stat); reset_counters(&pauline->stat); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send); - cbs = linphone_chat_message_get_callbacks(message2); + cbs = linphone_chat_message_get_callbacks(msg2); linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send); BC_ASSERT_EQUAL(ms_list_size(linphone_core_get_chat_rooms(marie->lc)), 0, int, "%d"); - linphone_chat_room_send_chat_message(pauline_room,message); - linphone_chat_room_send_chat_message(pauline_room,message2); + linphone_chat_room_send_chat_message(pauline_room,msg); + linphone_chat_room_send_chat_message(pauline_room,msg2); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - message = linphone_chat_message_clone(marie->stat.last_received_chat_message); + msg = linphone_chat_message_clone(marie->stat.last_received_chat_message); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,2)); - message2 = marie->stat.last_received_chat_message; - fclose(file_to_send); + msg2 = marie->stat.last_received_chat_message; BC_ASSERT_EQUAL(ms_list_size(linphone_core_get_chat_rooms(marie->lc)), 1, int, "%d"); if (ms_list_size(linphone_core_get_chat_rooms(marie->lc)) != 1) { char * buf = ms_strdup_printf("Found %d rooms instead of 1: ", ms_list_size(linphone_core_get_chat_rooms(marie->lc))); @@ -1256,23 +1189,23 @@ static void file_transfer_2_messages_simultaneously() { ms_error("%s", buf); } - cbs = linphone_chat_message_get_callbacks(message); + cbs = linphone_chat_message_get_callbacks(msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); - linphone_chat_message_download_file(message); + linphone_chat_message_download_file(msg); - cbs = linphone_chat_message_get_callbacks(message2); + cbs = linphone_chat_message_get_callbacks(msg2); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); - linphone_chat_message_download_file(message2); + linphone_chat_message_download_file(msg2); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,2)); - BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,4, int, "%d"); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,2, int, "%d"); - BC_ASSERT_TRUE(compare_files(send_filepath, receive_filepath)); + compare_files(send_filepath, receive_filepath); - linphone_chat_message_unref(message); + linphone_chat_message_unref(msg); linphone_core_manager_destroy(pauline); ms_free(send_filepath); ms_free(receive_filepath); @@ -1285,8 +1218,8 @@ static void text_message_with_send_error(void) { LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); - LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); + LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); reset_counters(&marie->stat); reset_counters(&pauline->stat); @@ -1294,23 +1227,23 @@ static void text_message_with_send_error(void) { sal_set_send_error(marie->lc->sal, -1); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); - /* check transient message list: the message should be in it, and should be the only one */ + /* check transient msg list: the msg should be in it, and should be the only one */ BC_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 1, int, "%d"); - BC_ASSERT_PTR_EQUAL(ms_list_nth_data(chat_room->transient_messages,0), message); + BC_ASSERT_PTR_EQUAL(ms_list_nth_data(chat_room->transient_messages,0), msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1)); /*BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageInProgress,1, int, "%d");*/ BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0, int, "%d"); - /* the message should have been discarded from transient list after an error */ + /* the msg should have been discarded from transient list after an error */ BC_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 0, int, "%d"); sal_set_send_error(marie->lc->sal, 0); @@ -1327,19 +1260,19 @@ static void text_message_denied(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); - LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); + LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); /*pauline doesn't want to be disturbed*/ linphone_core_disable_chat(pauline->lc,LinphoneReasonDoNotDisturb); { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); - linphone_chat_room_send_chat_message(chat_room,message); + linphone_chat_room_send_chat_message(chat_room,msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1)); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0, int, "%d"); @@ -1383,7 +1316,7 @@ static void info_message_with_args(bool_t with_content) { } { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } @@ -1434,13 +1367,13 @@ static void is_composing_notification(void) { linphone_core_get_chat_room(marie->lc, pauline->identity); /*make marie create the chatroom with pauline, which is necessary for receiving the is-composing*/ { int dummy=0; - wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ + wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_room_compose(chat_room); wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /*just to sleep while iterating*/ - linphone_chat_room_send_message(chat_room, "Composing a message"); + linphone_chat_room_send_message(chat_room, "Composing a msg"); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1)); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 2)); linphone_core_manager_destroy(marie); @@ -1609,11 +1542,11 @@ static void history_messages_count() { messages=linphone_chat_room_get_history(chatroom,0); BC_ASSERT_EQUAL(linphone_chat_room_get_history_size(chatroom), 1270, int, "%d"); BC_ASSERT_EQUAL(ms_list_size(messages), 1270, int, "%d"); - /*check the second most recent message*/ + /*check the second most recent msg*/ BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text((LinphoneChatMessage *)messages->next->data), "Fore and aft follow each other."); ms_list_free_with_data(messages, (void (*)(void*))linphone_chat_message_unref); - /*test offset+limit: retrieve the 42th latest message only and check its content*/ + /*test offset+limit: retrieve the 42th latest msg only and check its content*/ messages=linphone_chat_room_get_history_range(chatroom, 42, 42); BC_ASSERT_EQUAL(ms_list_size(messages), 1, int, "%d"); BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text((LinphoneChatMessage *)messages->data), "If you open yourself to the Tao is intangible and evasive, yet prefers to keep us at the mercy of the kingdom, then all of the streams of hundreds of valleys because of its limitless possibilities."); @@ -1647,46 +1580,82 @@ static void history_messages_count() { static void text_status_after_destroying_chat_room() { LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); LinphoneChatRoom *chatroom = linphone_core_get_chat_room_from_uri(marie->lc, ""); - LinphoneChatMessage *message = linphone_chat_room_create_message(chatroom, "hello"); - linphone_chat_room_send_chat_message(chatroom, message); - linphone_chat_room_unref(chatroom); + LinphoneChatMessage *msg = linphone_chat_room_create_message(chatroom, "hello"); + linphone_chat_room_send_chat_message(chatroom, msg); + linphone_core_delete_chat_room(marie->lc, chatroom); wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000); linphone_core_manager_destroy(marie); } +void file_transfer_io_error(char *server_url, bool_t destroy_room) { + LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); + LinphoneChatRoom *chatroom = linphone_core_get_chat_room_from_uri(marie->lc, ""); + LinphoneChatMessage *msg = create_message_from_nowebcam(chatroom); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); + linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); + linphone_core_set_file_transfer_server(marie->lc, server_url); + linphone_chat_room_send_chat_message(chatroom, msg); + BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageInProgress, 1, 1000)); + if (destroy_room) { + linphone_core_delete_chat_room(marie->lc, chatroom); + } + BC_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneMessageNotDelivered, 1, 1000)); + linphone_core_manager_destroy(marie); +} + +static void file_transfer_not_sent_if_invalid_url() { + file_transfer_io_error("INVALID URL", FALSE); +} + +static void file_transfer_not_sent_if_host_not_found() { + file_transfer_io_error("https://not_existing_url.com", FALSE); +} + +static void file_transfer_not_sent_if_url_moved_permanently() { + file_transfer_io_error("http://linphone.org/toto.php", FALSE); +} + +static void file_transfer_io_error_after_destroying_chatroom() { + file_transfer_io_error("https://www.linphone.org:444/lft.php", TRUE); +} + test_t message_tests[] = { - { "Text message", text_message }, - { "Text message within call's dialog", text_message_within_dialog}, - { "Text message with credentials from auth info cb", text_message_with_credential_from_auth_cb}, - { "Text message with privacy", text_message_with_privacy }, - { "Text message compatibility mode", text_message_compatibility_mode }, - { "Text message with ack", text_message_with_ack }, - { "Text message with send error", text_message_with_send_error }, - { "Text message with external body", text_message_with_external_body }, - { "File transfer message", file_transfer_message }, - { "Small File transfer message", small_file_transfer_message}, - { "File transfer message with io error at upload", file_transfer_message_io_error_upload }, -/* { "File transfer message with io error at download", file_transfer_message_io_error_download },*/ - { "File transfer message upload cancelled", file_transfer_message_upload_cancelled }, - { "File transfer message download cancelled", file_transfer_message_download_cancelled }, - { "File transfer message using external body url", file_transfer_using_external_body_url }, - { "File transfer 2 messages simultaneously", file_transfer_2_messages_simultaneously }, - { "Text message denied", text_message_denied }, - { "Info message", info_message }, - { "Info message with body", info_message_with_body }, - { "IsComposing notification", is_composing_notification } + {"Text message", text_message} + ,{"Text message within call's dialog", text_message_within_dialog} + ,{"Text message with credentials from auth info cb", text_message_with_credential_from_auth_cb} + ,{"Text message with privacy", text_message_with_privacy} + ,{"Text message compatibility mode", text_message_compatibility_mode} + ,{"Text message with ack", text_message_with_ack} + ,{"Text message with send error", text_message_with_send_error} + ,{"Text message with external body", text_message_with_external_body} + ,{"File transfer message", file_transfer_message} + ,{"Small File transfer message", small_file_transfer_message} + ,{"File transfer message with io error at upload", file_transfer_message_io_error_upload} + ,{"File transfer message with io error at download", file_transfer_message_io_error_download} + ,{"File transfer message upload cancelled", file_transfer_message_upload_cancelled} + ,{"File transfer message download cancelled", file_transfer_message_download_cancelled} + ,{"File transfer message using external body url", file_transfer_using_external_body_url} + ,{"File transfer 2 messages simultaneously", file_transfer_2_messages_simultaneously} + ,{"Text message denied", text_message_denied} + ,{"Info message", info_message} + ,{"Info message with body", info_message_with_body} + ,{"IsComposing notification", is_composing_notification} #ifdef HAVE_LIME - ,{ "Lime Text Message", lime_text_message } - ,{ "Lime File transfer message", lime_file_transfer_message } - ,{ "Lime File transfer message encryption only", lime_file_transfer_message_without_encryption} - ,{ "Lime Unitary", lime_unit } + ,{"Lime Text message", lime_text_message} + ,{"Lime File transfer message", lime_file_transfer_message} + ,{"Lime File transfer message encryption only", lime_file_transfer_message_without_encryption} + ,{"Lime Unitary", lime_unit} #endif /* HAVE_LIME */ #ifdef MSG_STORAGE_ENABLED - ,{ "Database migration", message_storage_migration } - ,{ "History count", history_messages_count } - ,{ "History range", history_range_full_test } + ,{"Database migration", message_storage_migration} + ,{"History count", history_messages_count} + ,{"History range", history_range_full_test} #endif - ,{ "Text status after destroying chat room", text_status_after_destroying_chat_room }, + ,{"Text status after destroying chat room", text_status_after_destroying_chat_room} + ,{"file transfer not sent if invalid url", file_transfer_not_sent_if_invalid_url} + ,{"file transfer not sent if host not found", file_transfer_not_sent_if_host_not_found} + ,{"file transfer not sent if url moved permanently", file_transfer_not_sent_if_url_moved_permanently} + ,{"file transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom} }; test_suite_t message_test_suite = { diff --git a/tester/tester.c b/tester/tester.c index c7a6db8bf..19af06aa7 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -115,7 +115,9 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, c if (file){ filepath = ms_strdup_printf("%s/%s", path, file); - BC_ASSERT_EQUAL_FATAL(ortp_file_exist(filepath),0,int, "%d"); + if (ortp_file_exist(filepath) != 0) { + ms_fatal("Could not find file %s in path %s, did you configured resources directory correctly?", file, path); + } config = lp_config_new_with_factory(NULL,filepath); }