diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 3632723249f2091c2c22783fa2b976d2a3acfcea..0cc5bf6fa500e4136e18044436c0dfac3aea9f57 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1172,11 +1172,14 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){ chat_msg->state=chatStatusSal2Linphone(status); linphone_chat_message_update_state(chat_msg); - if (chat_msg && chat_msg->cb) { + 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 %i",chat_msg->state); - chat_msg->cb(chat_msg - ,chat_msg->state - ,chat_msg->cb_ud); + 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); + } } 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 dc7598f030e9b8a77e7c6ef97671d50ba66e4348..6302af243220efabc872a49033756d49fb92776a 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -35,6 +35,139 @@ #define COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT 120 +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 +); + + +/** + * @addtogroup chatroom + * @{ + */ + +/** + * Acquire a reference to the LinphoneChatMessageCbs object. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The same LinphoneChatMessageCbs object. + */ +LinphoneChatMessageCbs * linphone_chat_message_cbs_ref(LinphoneChatMessageCbs *cbs) { + belle_sip_object_ref(cbs); + return cbs; +} + +/** + * Release reference to the LinphoneChatMessageCbs object. + * @param[in] cbs LinphoneChatMessageCbs object. + */ +void linphone_chat_message_cbs_unref(LinphoneChatMessageCbs *cbs) { + belle_sip_object_unref(cbs); +} + +/** + * Retrieve the user pointer associated with the LinphoneChatMessageCbs object. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The user pointer associated with the LinphoneChatMessageCbs object. + */ +void *linphone_chat_message_cbs_get_user_data(const LinphoneChatMessageCbs *cbs) { + return cbs->user_data; +} + +/** + * Assign a user pointer to the LinphoneChatMessageCbs object. + * @param[in] cbs LinphoneChatMessageCbs object. + * @param[in] ud The user pointer to associate with the LinphoneChatMessageCbs object. + */ +void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void *ud) { + cbs->user_data = ud; +} + +/** + * Get the message state changed callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The current message state changed callback. + */ +LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs) { + return cbs->msg_state_changed; +} + +/** + * Set the message state changed callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @param[in] cb The message state changed callback to be used. + */ +void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageMsgStateChangedCb cb) { + cbs->msg_state_changed = cb; +} + +/** + * Get the file transfer receive callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The current file transfer receive callback. + */ +LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs) { + return cbs->file_transfer_recv; +} + +/** + * Set the file transfer receive callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @param[in] cb The file transfer receive callback to be used. + */ +void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferRecvCb cb) { + cbs->file_transfer_recv = cb; +} + +/** + * Get the file transfer send callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The current file transfer send callback. + */ +LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs) { + return cbs->file_transfer_send; +} + +/** + * Set the file transfer send callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @param[in] cb The file transfer send callback to be used. + */ +void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferSendCb cb) { + cbs->file_transfer_send = cb; +} + +/** + * Get the file transfer progress indication callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @return The current file transfer progress indication callback. + */ +LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs) { + return cbs->file_transfer_progress_indication; +} + +/** + * Set the file transfer progress indication callback. + * @param[in] cbs LinphoneChatMessageCbs object. + * @param[in] cb The file transfer progress indication callback to be used. + */ +void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferProgressIndicationCb cb) { + cbs->file_transfer_progress_indication = cb; +} + +/** + * @} + */ + + + 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){ @@ -43,6 +176,9 @@ static void process_io_error_upload(void *data, const belle_sip_io_error_event_t if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateNotDelivered, 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, LinphoneChatMessageStateNotDelivered); + } } static void process_auth_requested_upload(void *data, belle_sip_auth_event_t *event){ LinphoneChatMessage* msg=(LinphoneChatMessage *)data; @@ -50,6 +186,9 @@ static void process_auth_requested_upload(void *data, belle_sip_auth_event_t *ev if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateNotDelivered, 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, LinphoneChatMessageStateNotDelivered); + } } static void process_io_error_download(void *data, const belle_sip_io_error_event_t *event){ @@ -58,6 +197,9 @@ static void process_io_error_download(void *data, const belle_sip_io_error_event if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateFileTransferError, 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, LinphoneChatMessageStateFileTransferError); + } } static void process_auth_requested_download(void *data, belle_sip_auth_event_t *event){ LinphoneChatMessage* msg=(LinphoneChatMessage *)data; @@ -65,6 +207,9 @@ static void process_auth_requested_download(void *data, belle_sip_auth_event_t * if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateFileTransferError, 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, LinphoneChatMessageStateFileTransferError); + } } /** @@ -73,10 +218,12 @@ static void process_auth_requested_download(void *data, belle_sip_auth_event_t * */ 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; - LinphoneCore *lc = chatMsg->chat_room->lc; - /* call back given by application level */ - linphone_core_notify_file_transfer_progress_indication(lc, chatMsg, chatMsg->file_transfer_information, offset, total); - 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); + } 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); + } } /** @@ -98,7 +245,12 @@ static int linphone_chat_message_file_transfer_on_send_body(belle_sip_user_body_ /* if we've not reach the end of file yet, ask for more data*/ if (offset<linphone_content_get_size(chatMsg->file_transfer_information)){ /* get data from call back */ - linphone_core_notify_file_transfer_send(lc, chatMsg, chatMsg->file_transfer_information, buf, size); + if (linphone_chat_message_cbs_get_file_transfer_send(chatMsg->callbacks)) { + linphone_chat_message_cbs_get_file_transfer_send(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, buf, size); + } else { + /* Legacy */ + linphone_core_notify_file_transfer_send(lc, chatMsg, chatMsg->file_transfer_information, buf, size); + } } return BELLE_SIP_CONTINUE; @@ -173,6 +325,9 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateFileTransferDone, 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, LinphoneChatMessageStateFileTransferDone); + } _linphone_chat_room_send_message(msg->chat_room, msg); } } @@ -736,6 +891,7 @@ const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) */ 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; @@ -762,6 +918,7 @@ LinphoneChatMessage* linphone_chat_room_create_message_2( 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; @@ -788,6 +945,7 @@ LinphoneChatMessage* linphone_chat_room_create_message_2( * @param msg #LinphoneChatMessage message to be sent * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when message is delivered or could not be delivered. May be NULL * @param ud user data for the status cb. + * @deprecated Use linphone_chat_room_send_chat_message() instead. * @note The LinphoneChatMessage must not be destroyed until the the callback is called. */ void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb, void* ud) { @@ -797,6 +955,18 @@ void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* _linphone_chat_room_send_message(cr, msg); } +/** + * Send a message to peer member of this chat room. + * @param[in] cr LinphoneChatRoom object + * @param[in] msg LinphoneChatMessage object + * The state of the message sending will be notified via the callbacks defined in the LinphoneChatMessageCbs object that can be obtained + * by calling linphone_chat_message_get_callbacks(). + */ +void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + msg->state = LinphoneChatMessageStateInProgress; + _linphone_chat_room_send_message(cr, msg); +} + static char * linphone_chat_room_create_is_composing_xml(LinphoneChatRoom *cr) { xmlBufferPtr buf; xmlTextWriterPtr writer; @@ -1034,8 +1204,12 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t if (chatMsg->http_request == NULL) { return; } - /* call back given by application level */ - linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); + if (linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)) { + linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); + } else { + /* Legacy: call back given by application level */ + linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); + } return; } @@ -1104,21 +1278,26 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; LinphoneCore *lc = chatMsg->chat_room->lc; /* file downloaded succesfully, call again the callback with size at zero */ - linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, NULL, 0); + if (linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)) { + linphone_chat_message_cbs_get_file_transfer_recv(chatMsg->callbacks)(chatMsg, chatMsg->file_transfer_information, NULL, 0); + } else { + linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, NULL, 0); + } if (chatMsg->cb) { chatMsg->cb(chatMsg, LinphoneChatMessageStateFileTransferDone, 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, LinphoneChatMessageStateFileTransferDone); + } } } } /** - * Start the download of the file from remote server - * - * @param message #LinphoneChatMessage - * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when file is downloaded or could not be downloaded + * Start the download of the file referenced in a LinphoneChatMessage from remote server. + * @param[in] message LinphoneChatMessage object. */ -void linphone_chat_message_start_file_download(LinphoneChatMessage *message, LinphoneChatMessageStateChangedCb status_cb, void *ud) { +void linphone_chat_message_download_file(LinphoneChatMessage *message) { belle_http_request_listener_callbacks_t cbs={0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; @@ -1142,12 +1321,23 @@ void linphone_chat_message_start_file_download(LinphoneChatMessage *message, Lin l=belle_http_request_listener_create_from_callbacks(&cbs, (void *)message); belle_sip_object_data_set(BELLE_SIP_OBJECT(req),"message",(void *)message,NULL); message->http_request = req; /* keep a reference on the request to be able to cancel the download */ - message->cb = status_cb; - message->cb_ud = ud; message->state = LinphoneChatMessageStateInProgress; /* start the download, status is In Progress */ belle_http_provider_send_request(message->chat_room->lc->http_provider,req,l); } +/** + * Start the download of the file from remote server + * + * @param message #LinphoneChatMessage + * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when file is downloaded or could not be downloaded + * @deprecated Use linphone_chat_message_download_file() instead. + */ +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); +} + /** * Cancel an ongoing file transfer attached to this message.(upload or download) * @param msg #LinphoneChatMessage @@ -1160,6 +1350,9 @@ void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { if (msg->cb) { msg->cb(msg, LinphoneChatMessageStateNotDelivered, 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, LinphoneChatMessageStateNotDelivered); + } } @@ -1339,6 +1532,7 @@ static void _linphone_chat_message_destroy(LinphoneChatMessage* msg) { if (msg->file_transfer_filepath != NULL) { ms_free(msg->file_transfer_filepath); } + linphone_chat_message_cbs_unref(msg->callbacks); ms_message("LinphoneChatMessage [%p] destroyed.",msg); } @@ -1396,6 +1590,15 @@ const char * linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessag return msg->file_transfer_filepath; } +/** + * Get the LinphoneChatMessageCbs object associated with the LinphoneChatMessage. + * @param[in] msg LinphoneChatMessage object + * @return The LinphoneChatMessageCbs object associated with the LinphoneChatMessage. + */ +LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg) { + return msg->callbacks; +} + /** * Create a message attached to a dedicated chat room with a particular content. Use #linphone_chat_room_send_message2 to initiate the transfer @@ -1406,6 +1609,7 @@ const char * linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessag LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, 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->file_transfer_information = linphone_content_copy(initial_content); diff --git a/coreapi/help/filetransfer.c b/coreapi/help/filetransfer.c index 205a51d31fdb53efd37b011ca9365aba999a7574..c592c501bdf9bcf0b73f0f3aebcad723cd4105b4 100644 --- a/coreapi/help/filetransfer.c +++ b/coreapi/help/filetransfer.c @@ -48,7 +48,7 @@ static void stop(int signum){ /** * function invoked to report file transfer progress. * */ -static void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) { +static void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) { 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); @@ -63,7 +63,7 @@ static void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMess /** * function invoked when a file transfer is received. **/ -static void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){ +static void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){ FILE* file=NULL; if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ @@ -92,7 +92,7 @@ char big_file [128000]; /* * function called when the file transfer is initiated. file content should be feed into object LinphoneContent * */ -static void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){ +static void file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){ int offset=-1; if (!linphone_chat_message_get_user_data(message)) { @@ -147,6 +147,7 @@ int main(int argc, char *argv[]){ LinphoneChatRoom* chat_room; LinphoneContent* content; LinphoneChatMessage* chat_message; + LinphoneChatMessageCbs *cbs; /*seting dummy file content to something*/ for (i=0;i<sizeof(big_file);i+=strlen(big_file_content)) @@ -160,15 +161,6 @@ int main(int argc, char *argv[]){ #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif - /* - Fill the LinphoneCoreVTable with application callbacks. - All are optional. Here we only use the file_transfer_received callback - in order to get notifications about incoming file receive, file_transfer_send to feed file to be transfered - and file_transfer_progress_indication to print progress. - */ - vtable.file_transfer_recv=file_transfer_received; - vtable.file_transfer_send=file_transfer_send; - vtable.file_transfer_progress_indication=file_transfer_progress_indication; vtable.message_received=message_received; @@ -201,8 +193,18 @@ int main(int argc, char *argv[]){ printf("returned message is null\n"); } + /** + * Fill the application callbacks. The file_transfer_received callback is used in order to get notifications + * about incoming file reception, file_transfer_send to feed file to be transfered and + * file_transfer_progress_indication to print progress. + */ + cbs = linphone_chat_message_get_callbacks(chat_message); + linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); + linphone_chat_message_cbs_set_file_transfer_send(cbs, file_transfer_send); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); + /*initiating file transfer*/ - linphone_chat_room_send_message2(chat_room, chat_message, linphone_file_transfer_state_changed, NULL); + linphone_chat_room_send_chat_message(chat_room, chat_message); /* main loop for receiving incoming messages and doing background linphone core work: */ while(running){ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index add43e4a09195955fc5a5c9d86d9d2198254d987..e3ad83ff7f249df1254d60ffeb2c066d1f627bdd 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1296,7 +1296,12 @@ struct _LinphoneChatRoom; */ /** - * A chat room message to old content to be sent. + * An object to handle the callbacks for the handling a LinphoneChatMessage objects. + */ +typedef struct _LinphoneChatMessageCbs LinphoneChatMessageCbs; + +/** + * A chat room message to hold content to be sent. * <br> Can be created by linphone_chat_room_create_message(). */ typedef struct _LinphoneChatMessage LinphoneChatMessage; @@ -1327,6 +1332,46 @@ typedef enum _LinphoneChatMessageState { */ typedef void (*LinphoneChatMessageStateChangedCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud); +/** + * Call back used to notify message delivery status + * @param msg #LinphoneChatMessage object + * @param status LinphoneChatMessageState + */ +typedef void (*LinphoneChatMessageMsgStateChangedCb)(LinphoneChatMessage* msg, LinphoneChatMessageState state); + +/** + * File transfer receive callback prototype. This function is called by the core upon an incoming File transfer is started. This function may be call several time for the same file in case of large file. + * + * @param message #LinphoneChatMessage message from which the body is received. + * @param content #LinphoneContent incoming content information + * @param buff pointer to the received data + * @param size number of bytes to be read from buff. 0 means end of file. + * + */ +typedef void (*LinphoneChatMessageFileTransferRecvCb)(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size); + +/** + * File transfer send callback prototype. This function is called by the core upon an outgoing File transfer is started. This function is called until size is set to 0. + * <br> a #LinphoneContent with a size equal zero + * + * @param message #LinphoneChatMessage message from which the body is received. + * @param content #LinphoneContent outgoing content + * @param buff pointer to the buffer where data chunk shall be written by the app + * @param size as input value, it represents the number of bytes expected by the framework. As output value, it means the number of bytes wrote by the application in the buffer. 0 means end of file. + * + */ +typedef void (*LinphoneChatMessageFileTransferSendCb)(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size); + +/** + * File transfer progress indication callback prototype. + * + * @param message #LinphoneChatMessage message from which the body is received. + * @param content #LinphoneContent incoming content information + * @param offset The number of bytes sent/received since the beginning of the transfer. + * @param total The total number of bytes to be sent/received. + */ +typedef void (*LinphoneChatMessageFileTransferProgressIndicationCb)(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total); + LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path); LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to); LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_get_or_create_chat_room(LinphoneCore *lc, const char *to); @@ -1377,6 +1422,7 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_file_transfer_mes LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr); LINPHONE_PUBLIC void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb,void* ud); +LINPHONE_PUBLIC void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); LINPHONE_PUBLIC void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg); LINPHONE_PUBLIC MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message); LINPHONE_PUBLIC void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr); @@ -1438,6 +1484,7 @@ LINPHONE_PUBLIC const char* linphone_chat_message_get_external_body_url(const Li LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url); LINPHONE_PUBLIC const LinphoneContent* linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessage* message, LinphoneChatMessageStateChangedCb status_cb, void* ud); +LINPHONE_PUBLIC void linphone_chat_message_download_file(LinphoneChatMessage *message); LINPHONE_PUBLIC void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage* msg); LINPHONE_PUBLIC const char* linphone_chat_message_get_appdata(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_set_appdata(LinphoneChatMessage* message, const char* data); @@ -1457,6 +1504,21 @@ LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason(LinphoneChatMess LINPHONE_PUBLIC const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg); LINPHONE_PUBLIC void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath); LINPHONE_PUBLIC const char * linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg); +LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg); + +LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_cbs_ref(LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_unref(LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void *linphone_chat_message_cbs_get_user_data(const LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void *ud); +LINPHONE_PUBLIC LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageMsgStateChangedCb cb); +LINPHONE_PUBLIC LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferRecvCb cb); +LINPHONE_PUBLIC LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferSendCb cb); +LINPHONE_PUBLIC LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs); +LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferProgressIndicationCb cb); + /** * @} */ @@ -1741,9 +1803,9 @@ typedef struct _LinphoneCoreVTable{ DisplayUrlCb display_url; /**< @deprecated */ ShowInterfaceCb show; /**< @deprecated Notifies the application that it should show up*/ LinphoneCoreTextMessageReceivedCb text_received; /**< @deprecated, use #message_received instead <br> A text message has been received */ - LinphoneCoreFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */ - LinphoneCoreFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */ - LinphoneCoreFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */ + LinphoneCoreFileTransferRecvCb file_transfer_recv; /**< @deprecated Callback to store file received attached to a #LinphoneChatMessage */ + LinphoneCoreFileTransferSendCb file_transfer_send; /**< @deprecated Callback to collect file chunk to be sent for a #LinphoneChatMessage */ + LinphoneCoreFileTransferProgressIndicationCb file_transfer_progress_indication; /**< @deprecated Callback to indicate file transfer progress */ LinphoneCoreNetworkReachableCb network_reachable; /**< Callback to report IP network status (I.E up/down )*/ LinphoneCoreLogCollectionUploadStateChangedCb log_collection_upload_state_changed; /**< Callback to upload collected logs */ LinphoneCoreLogCollectionUploadProgressIndicationCb log_collection_upload_progress_indication; /**< Callback to indicate log collection upload progress */ diff --git a/coreapi/private.h b/coreapi/private.h index 56f96fb2ee8fd700ed9fb2f30a10742ecea06386..d9d1eeb07a839a74b6129c58e5cb0ff4284e47ba 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -146,6 +146,17 @@ typedef struct _CallCallbackObj void * _user_data; }CallCallbackObj; +struct _LinphoneChatMessageCbs { + belle_sip_object_t base; + void *user_data; + LinphoneChatMessageMsgStateChangedCb msg_state_changed; + LinphoneChatMessageFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */ + LinphoneChatMessageFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */ + LinphoneChatMessageFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */ +}; + +BELLE_SIP_DECLARE_VPTR(LinphoneChatMessageCbs); + typedef enum _LinphoneChatMessageDir{ LinphoneChatMessageIncoming, LinphoneChatMessageOutgoing @@ -154,6 +165,7 @@ typedef enum _LinphoneChatMessageDir{ struct _LinphoneChatMessage { belle_sip_object_t base; LinphoneChatRoom* chat_room; + LinphoneChatMessageCbs *callbacks; LinphoneChatMessageDir dir; char* message; LinphoneChatMessageStateChangedCb cb; @@ -997,6 +1009,7 @@ BELLE_SIP_TYPE_ID(LinphoneCall), BELLE_SIP_TYPE_ID(LinphoneCallLog), BELLE_SIP_TYPE_ID(LinphoneCallParams), BELLE_SIP_TYPE_ID(LinphoneChatMessage), +BELLE_SIP_TYPE_ID(LinphoneChatMessageCbs), BELLE_SIP_TYPE_ID(LinphoneChatRoom), BELLE_SIP_TYPE_ID(LinphoneContent), BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider), diff --git a/gtk/chat.c b/gtk/chat.c index 94043795064057bdbb0a383d054f5757dbafd28d..c05f32e4a667d1967391e0d11b749a1b85108982 100644 --- a/gtk/chat.c +++ b/gtk/chat.c @@ -276,7 +276,7 @@ void update_chat_state_message(LinphoneChatMessageState state,LinphoneChatMessag } } -static void on_chat_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state, void *user_pointer){ +static void on_chat_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state){ update_chat_state_message(state,msg); } @@ -300,8 +300,11 @@ void linphone_gtk_send_text(){ entered=gtk_entry_get_text(GTK_ENTRY(entry)); if (strlen(entered)>0) { LinphoneChatMessage *msg; + LinphoneChatMessageCbs *cbs; msg=linphone_chat_room_create_message(cr,entered); - linphone_chat_room_send_message2(cr,msg,on_chat_state_changed,NULL); + cbs=linphone_chat_message_get_callbacks(msg); + linphone_chat_message_cbs_set_msg_state_changed(cbs,on_chat_state_changed); + linphone_chat_room_send_chat_message(cr,msg); linphone_gtk_push_text(w,linphone_chat_message_get_from(msg), TRUE,cr,msg,FALSE); diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 715d4c6f8db873259579da4f4ca2174594495642..d7f5c26cee3be605f069edbc26290fa02ab5598b 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -235,9 +235,9 @@ void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf); void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message); void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message); -void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size); -void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size); -void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total); +void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size); +void file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size); +void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total); void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room); void info_message_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg); void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url); @@ -269,6 +269,7 @@ LinphoneCoreManager *get_manager(LinphoneCore *lc); const char *liblinphone_tester_get_subscribe_content(void); const char *liblinphone_tester_get_notify_content(void); void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud); +void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state); void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee); void liblinphone_tester_clock_start(MSTimeSpec *start); bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms); diff --git a/tester/message_tester.c b/tester/message_tester.c index de6b90c0d14bf81e18776a669c1000b5f2ad1933..9d207d03477088dc2d6e64ed28ce41d2b3e995bd 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -62,9 +62,11 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess /** * function invoked when a file transfer is received. * */ -void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){ +void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){ FILE* file=NULL; char receive_file[256]; + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); + LinphoneCore *lc = linphone_chat_room_get_core(cr); snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", liblinphone_tester_writable_dir_prefix); if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ @@ -91,7 +93,7 @@ static char big_file [128000]; /* a buffer to simulate a big file for the file t /* * function called when the file transfer is initiated. file content should be feed into object LinphoneContent * */ -void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){ +void file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){ int offset=-1; if (!linphone_chat_message_get_user_data(message)) { @@ -116,7 +118,9 @@ void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const L /** * function invoked to report file transfer progress. * */ -void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) { +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); + 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); @@ -142,9 +146,14 @@ void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) { } void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud) { - LinphoneCore* lc=(LinphoneCore*)ud; + liblinphone_tester_chat_message_msg_state_changed(msg, state); +} + +void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state) { + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); + LinphoneCore *lc = linphone_chat_room_get_core(cr); stats* counters = get_stats(lc); - ms_message("Message [%s] [%s]",linphone_chat_message_get_text(msg),linphone_chat_message_state_to_string(state)); + ms_message("Message [%s] [%s]",linphone_chat_message_get_text(msg), linphone_chat_message_state_to_string(state)); switch (state) { case LinphoneChatMessageStateDelivered: counters->number_of_LinphoneMessageDelivered++; @@ -159,9 +168,8 @@ void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,Linph counters->number_of_LinphoneMessageNotDelivered++; break; default: - ms_error("Unexpected state [%s] for message [%p]",linphone_chat_message_state_to_string(state),msg); + ms_error("Unexpected state [%s] for message [%p]",linphone_chat_message_state_to_string(state), msg); } - } static void text_message(void) { @@ -340,13 +348,13 @@ static void text_message_with_ack(void) { char* to = linphone_address_as_string(marie->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - { - 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); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); + 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_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(chat_room,message); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); @@ -366,6 +374,7 @@ static void text_message_with_external_body(void) { char* to = linphone_address_as_string(marie->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); linphone_chat_message_set_external_body_url(message,message_external_body_url="http://www.linphone.org"); { int dummy=0; @@ -373,7 +382,8 @@ static void text_message_with_external_body(void) { 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_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(chat_room,message); /* check transient message list: the message should be in it, and should be the only one */ CU_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 1); @@ -396,6 +406,7 @@ static void file_transfer_message(void) { char* to; LinphoneChatRoom* chat_room; LinphoneChatMessage* message; + LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -423,16 +434,21 @@ static void file_transfer_message(void) { 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); + cbs = linphone_chat_message_get_callbacks(message); { 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_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(chat_room,message); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); if (marie->stat.last_received_chat_message ) { - linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change, marie->lc); + 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); + linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); + linphone_chat_message_download_file(marie->stat.last_received_chat_message); } CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1)); @@ -452,6 +468,7 @@ static void small_file_transfer_message(void) { char* to; LinphoneChatRoom* chat_room; LinphoneChatMessage* message; + LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -485,10 +502,15 @@ static void small_file_transfer_message(void) { reset_counters(&marie->stat); reset_counters(&pauline->stat); } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + cbs = linphone_chat_message_get_callbacks(message); + 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); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); if (marie->stat.last_received_chat_message ) { - linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change, marie->lc); + 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); + linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); + linphone_chat_message_download_file(marie->stat.last_received_chat_message); } CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1)); @@ -506,6 +528,7 @@ static void file_transfer_message_io_error_upload(void) { char* to; LinphoneChatRoom* chat_room; LinphoneChatMessage* message; + LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -540,7 +563,10 @@ static void file_transfer_message_io_error_upload(void) { reset_counters(&marie->stat); reset_counters(&pauline->stat); } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + cbs = linphone_chat_message_get_callbacks(message); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); + linphone_chat_room_send_chat_message(chat_room,message); /*wait for file to be 25% uploaded and simultate a network error*/ CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer,25)); @@ -632,6 +658,7 @@ static void file_transfer_message_upload_cancelled(void) { char* to; LinphoneChatRoom* chat_room; LinphoneChatMessage* message; + LinphoneChatMessageCbs *cbs; LinphoneContent* content; const char* big_file_content="big file"; /* setting dummy file content to something */ LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -666,7 +693,10 @@ static void file_transfer_message_upload_cancelled(void) { reset_counters(&marie->stat); reset_counters(&pauline->stat); } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + cbs = linphone_chat_message_get_callbacks(message); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); + linphone_chat_room_send_chat_message(chat_room,message); /*wait for file to be 50% uploaded and cancel the transfer */ CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer, 50)); @@ -753,6 +783,7 @@ static void text_message_with_send_error(void) { char* to = linphone_address_as_string(pauline->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(marie->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); reset_counters(&marie->stat); reset_counters(&pauline->stat); @@ -764,7 +795,8 @@ static void text_message_with_send_error(void) { reset_counters(&marie->stat); reset_counters(&pauline->stat); } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,marie->lc); + 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); /* check transient message list: the message should be in it, and should be the only one */ CU_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 1); @@ -789,6 +821,7 @@ static void text_message_denied(void) { char* to = linphone_address_as_string(pauline->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(marie->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); /*pauline doesn't want to be disturbed*/ linphone_core_disable_chat(pauline->lc,LinphoneReasonDoNotDisturb); @@ -798,7 +831,8 @@ static void text_message_denied(void) { reset_counters(&marie->stat); reset_counters(&pauline->stat); } - linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,marie->lc); + 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); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0); diff --git a/tester/tester.c b/tester/tester.c index 07ffa703a184298f61e71ec52a94ebf837df2fcf..971bf5d6397fe90ddc9e7866307fe0c794d0d93c 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -234,9 +234,6 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f mgr->v_table.call_state_changed=call_state_changed; mgr->v_table.text_received=text_message_received; mgr->v_table.message_received=message_received; - mgr->v_table.file_transfer_recv=file_transfer_received; - mgr->v_table.file_transfer_send=file_transfer_send; - mgr->v_table.file_transfer_progress_indication=file_transfer_progress_indication; mgr->v_table.is_composing_received=is_composing_received; mgr->v_table.new_subscription_requested=new_subscription_requested; mgr->v_table.notify_presence_received=notify_presence_received;