Commit 0babed04 authored by Ghislain MARY's avatar Ghislain MARY Committed by Ronan

Use ChatRoom C++ class.

parent 95c781ec
This diff is collapsed.
......@@ -26,8 +26,12 @@
#include "private.h"
#include "ortp/b64.h"
#include "chat/chat-room.h"
extern LinphonePrivate::ChatRoom& linphone_chat_room_get_cpp_obj(LinphoneChatRoom *cr);
static bool_t file_transfer_in_progress_and_valid(LinphoneChatMessage* msg) {
return (msg->chat_room && msg->chat_room->lc && msg->http_request && !belle_http_request_is_cancelled(msg->http_request));
return (msg->chat_room && linphone_chat_room_get_core(msg->chat_room) && msg->http_request && !belle_http_request_is_cancelled(msg->http_request));
}
static void _release_http_request(LinphoneChatMessage* msg) {
......@@ -88,7 +92,7 @@ static void linphone_chat_message_file_transfer_on_progress(belle_sip_body_handl
msg, msg->file_transfer_information, offset, total);
} else {
/* Legacy: call back given by application level */
linphone_core_notify_file_transfer_progress_indication(msg->chat_room->lc, msg, msg->file_transfer_information,
linphone_core_notify_file_transfer_progress_indication(linphone_chat_room_get_core(msg->chat_room), msg, msg->file_transfer_information,
offset, total);
}
}
......@@ -108,7 +112,7 @@ static int on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *
return BELLE_SIP_STOP;
}
lc = msg->chat_room->lc;
lc = linphone_chat_room_get_core(msg->chat_room);
/* if we've not reach the end of file yet, ask for more data */
/* in case of file body handler, won't be called */
if (msg->file_transfer_filepath == NULL && offset < linphone_content_get_size(msg->file_transfer_information)) {
......@@ -153,7 +157,7 @@ static int on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *
static void on_send_end(belle_sip_user_body_handler_t *bh, void *data) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
LinphoneCore *lc = msg->chat_room->lc;
LinphoneCore *lc = linphone_chat_room_get_core(msg->chat_room);
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(lc);
if (imee) {
......@@ -185,8 +189,7 @@ static void file_upload_begin_background_task(LinphoneChatMessage *obj){
}
}
static void linphone_chat_message_process_response_from_post_file(void *data,
const belle_http_response_event_t *event) {
static void linphone_chat_message_process_response_from_post_file(void *data, const belle_http_response_event_t *event) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
if (msg->http_request && !file_transfer_in_progress_and_valid(msg)) {
......@@ -205,7 +208,7 @@ static void linphone_chat_message_process_response_from_post_file(void *data,
belle_sip_body_handler_t *first_part_bh;
bool_t is_file_encryption_enabled = FALSE;
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(msg->chat_room->lc);
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(linphone_chat_room_get_core(msg->chat_room));
if (imee) {
LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee);
LinphoneImEncryptionEngineCbsIsEncryptionEnabledForFileTransferCb is_encryption_enabled_for_file_transfer_cb =
......@@ -339,7 +342,7 @@ static void linphone_chat_message_process_response_from_post_file(void *data,
linphone_chat_message_ref(msg);
linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferDone);
_release_http_request(msg);
_linphone_chat_room_send_message(msg->chat_room, msg);
linphone_chat_room_get_cpp_obj(msg->chat_room).sendMessage(msg);
file_upload_end_background_task(msg);
linphone_chat_message_unref(msg);
} else {
......@@ -374,7 +377,7 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t
linphone_chat_message_cancel_file_transfer(msg);
return;
}
lc = msg->chat_room->lc;
lc = linphone_chat_room_get_core(msg->chat_room);
if (lc == NULL){
return; /*might happen during linphone_core_destroy()*/
......@@ -425,7 +428,7 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t
static void on_recv_end(belle_sip_user_body_handler_t *bh, void *data) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)data;
LinphoneCore *lc = msg->chat_room->lc;
LinphoneCore *lc = linphone_chat_room_get_core(msg->chat_room);
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(lc);
int retval = -1;
......@@ -536,7 +539,7 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle
int _linphone_chat_room_start_http_transfer(LinphoneChatMessage *msg, const char* url, const char* action, const belle_http_request_listener_callbacks_t *cbs) {
belle_generic_uri_t *uri = NULL;
const char* ua = linphone_core_get_user_agent(msg->chat_room->lc);
const char* ua = linphone_core_get_user_agent(linphone_chat_room_get_core(msg->chat_room));
if (url == NULL) {
ms_warning("Cannot process file transfer msg: no file remote URI configured.");
......@@ -559,7 +562,7 @@ int _linphone_chat_room_start_http_transfer(LinphoneChatMessage *msg, const char
/* give msg to listener to be able to start the actual file upload when server answer a 204 No content */
msg->http_listener = belle_http_request_listener_create_from_callbacks(cbs, linphone_chat_message_ref(msg));
belle_http_provider_send_request(msg->chat_room->lc->http_provider, msg->http_request, msg->http_listener);
belle_http_provider_send_request(linphone_chat_room_get_core(msg->chat_room)->http_provider, msg->http_request, msg->http_listener);
return 0;
error:
if (uri) {
......@@ -580,7 +583,7 @@ int linphone_chat_room_upload_file(LinphoneChatMessage *msg) {
cbs.process_response = linphone_chat_message_process_response_from_post_file;
cbs.process_io_error = linphone_chat_message_process_io_error_upload;
cbs.process_auth_requested = linphone_chat_message_process_auth_requested_upload;
err = _linphone_chat_room_start_http_transfer(msg, linphone_core_get_file_transfer_server(msg->chat_room->lc), "POST", &cbs);
err = _linphone_chat_room_start_http_transfer(msg, linphone_core_get_file_transfer_server(linphone_chat_room_get_core(msg->chat_room)), "POST", &cbs);
if (err == -1){
linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered);
}
......@@ -621,10 +624,10 @@ void _linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg, bool_
if (!belle_http_request_is_cancelled(msg->http_request)) {
if (msg->chat_room) {
ms_message("Canceling 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->external_body_url == NULL) ? linphone_core_get_file_transfer_server(linphone_chat_room_get_core(msg->chat_room)) : msg->external_body_url
, msg
, msg->chat_room);
belle_http_provider_cancel_request(msg->chat_room->lc->http_provider, msg->http_request);
belle_http_provider_cancel_request(linphone_chat_room_get_core(msg->chat_room)->http_provider, msg->http_request);
if ((msg->dir == LinphoneChatMessageOutgoing) && unref) {
// must release it
linphone_chat_message_unref(msg);
......@@ -654,20 +657,6 @@ const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage
return msg->file_transfer_filepath;
}
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->file_transfer_information = linphone_content_copy(initial_content);
msg->dir = LinphoneChatMessageOutgoing;
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
msg->from = linphone_address_new(linphone_core_get_identity(cr->lc)); /*direct assignment*/
/* 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->content_type = NULL;
/* this will store the http request during file upload to the server */
msg->http_request = NULL;
msg->time = ms_time(0);
return msg;
LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) {
return linphone_chat_room_get_cpp_obj(cr).createFileTransferMessage(initial_content);
}
......@@ -749,11 +749,11 @@ error:
bool_t linphone_chat_room_lime_available(LinphoneChatRoom *cr) {
if (cr) {
switch (linphone_core_lime_enabled(cr->lc)) {
switch (linphone_core_lime_enabled(linphone_chat_room_get_core(cr))) {
case LinphoneLimeDisabled: return FALSE;
case LinphoneLimeMandatory:
case LinphoneLimePreferred: {
void *zrtp_cache_db = linphone_core_get_zrtp_cache_db(cr->lc);
void *zrtp_cache_db = linphone_core_get_zrtp_cache_db(linphone_chat_room_get_core(cr));
if (zrtp_cache_db != NULL) {
bool_t res;
limeURIKeys_t associatedKeys;
......@@ -832,7 +832,7 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEn
LinphoneCore *lc = linphone_im_encryption_engine_get_core(engine);
int errcode = -1;
const char *new_content_type = "xml/cipher";
if(linphone_core_lime_enabled(room->lc)) {
if(linphone_core_lime_enabled(linphone_chat_room_get_core(room))) {
if (linphone_chat_room_lime_available(room)) {
void *zrtp_cache_db = NULL; /* use a void * instead of sqlite3 * to avoid problems and ifdef when SQLITE is not available(the get function shall return NULL in that case) */
if (msg->content_type) {
......@@ -862,7 +862,7 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEn
retval = lime_createMultipartMessage(zrtp_cache_db, msg->content_type, (uint8_t *)msg->message, selfUri, peerUri, &crypted_body);
if (retval != 0) { /* fail to encrypt */
ms_warning("Unable to encrypt message for %s : %s", room->peer, lime_error_code_to_string(retval));
ms_warning("Unable to encrypt message for %s : %s", peerUri, lime_error_code_to_string(retval));
if (crypted_body) ms_free(crypted_body);
errcode = 488;
} else { /* encryption ok, swap plain text message body by encrypted one */
......
......@@ -1719,7 +1719,7 @@ static void linphone_call_set_terminated(LinphoneCall *call){
call->ringing_beep=FALSE;
}
if (call->chat_room){
call->chat_room->call = NULL;
linphone_chat_room_set_call(call->chat_room, NULL);
}
if (lc->calls == NULL){
ms_bandwidth_controller_reset_state(lc->bw_controller);
......
This diff is collapsed.
......@@ -180,6 +180,12 @@ struct _LinphoneCallParams{
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneCallParams);
typedef enum _ImdnType {
ImdnTypeDelivery,
ImdnTypeDisplay
} ImdnType;
struct _LinphoneQualityReporting{
reporting_session_report_t * reports[3]; /**Store information on audio and video media streams (RFC 6035) */
bool_t was_video_running; /*Keep video state since last check in order to detect its (de)activation*/
......@@ -279,11 +285,6 @@ struct _LinphoneChatMessage {
#endif
};
/*
*Gets a Message with a given message id and direction.
*/
LINPHONE_PUBLIC LinphoneChatMessage * linphone_chat_room_find_message_with_dir(LinphoneChatRoom *cr, const char *message_id,LinphoneChatMessageDir dir);
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatMessage);
typedef struct StunCandidate{
......@@ -594,7 +595,7 @@ LINPHONE_PUBLIC void linphone_core_get_local_ip(LinphoneCore *lc, int af, const
LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore *lc, int index);
void linphone_proxy_config_write_to_config_file(LinphoneConfig* config,LinphoneProxyConfig *obj, int index);
LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *msg);
int linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *msg);
void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call);
void linphone_call_init_stats(LinphoneCallStats *stats, LinphoneStreamType type);
......@@ -650,7 +651,8 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
/*chat*/
void linphone_chat_room_release(LinphoneChatRoom *cr);
void linphone_chat_room_add_weak_message(LinphoneChatRoom *cr, LinphoneChatMessage *cm);
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call);
bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr);
void linphone_chat_message_destroy(LinphoneChatMessage* msg);
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state);
void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state);
......@@ -659,11 +661,14 @@ void linphone_chat_message_send_delivery_notification(LinphoneChatMessage *cm, L
void linphone_chat_message_send_display_notification(LinphoneChatMessage *cm);
void _linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg, bool_t unref);
int linphone_chat_room_upload_file(LinphoneChatMessage *msg);
void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void);
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call);
void linphone_chat_room_add_transient_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
void linphone_chat_room_remove_transient_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
void linphone_chat_message_deactivate(LinphoneChatMessage *msg);
void linphone_chat_message_release(LinphoneChatMessage *msg);
void create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(LinphoneChatMessage *msg);
void linphone_chat_message_fetch_content_from_database(sqlite3 *db, LinphoneChatMessage *message, int content_id);
void linphone_chat_message_send_imdn(LinphoneChatMessage *cm, ImdnType imdn_type, LinphoneReason reason);
/**/
struct _LinphoneProxyConfig
......@@ -740,33 +745,11 @@ typedef enum _LinphoneIsComposingState {
LinphoneIsComposingActive
} LinphoneIsComposingState;
struct _LinphoneChatRoom{
belle_sip_object_t base;
void *user_data;
struct _LinphoneCore *lc;
char *peer;
LinphoneAddress *peer_url;
MSList *messages_hist;
MSList *transient_messages;
bctbx_list_t *weak_messages;
int unread_count;
LinphoneIsComposingState remote_is_composing;
LinphoneIsComposingState is_composing;
belle_sip_source_t *remote_composing_refresh_timer;
belle_sip_source_t *composing_idle_timer;
belle_sip_source_t *composing_refresh_timer;
LinphoneCall *call;
LinphoneChatMessage *pending_message;
MSList *received_rtt_characters;
};
typedef struct _LinphoneChatMessageCharacter {
uint32_t value;
bool_t has_been_read;
} LinphoneChatMessageCharacter;
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatRoom);
typedef struct _LinphoneFriendPresence {
char *uri_or_tel;
......
......@@ -55,7 +55,11 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
object/object-p.h
object/object.h
object/singleton.h
<<<<<<< HEAD
utils/enum-generator.h
=======
utils/content-type.h
>>>>>>> b7c744ef8... Use ChatRoom C++ class.
utils/general.h
utils/magic-macros.h
utils/utils.h
......@@ -84,6 +88,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
message/message.cpp
object/clonable-object.cpp
object/object.cpp
utils/content-type.cpp
utils/general.cpp
utils/utils.cpp
)
......
/*
* chat-room-p.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHAT_ROOM_P_H_
#define _CHAT_ROOM_P_H_
#include <list>
#include "object/object-p.h"
#include "chat-room.h"
#include "private.h"
#include <belle-sip/belle-sip.h>
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ChatRoomPrivate : public ObjectPrivate {
public:
virtual ~ChatRoomPrivate ();
private:
static int refreshComposing (void *data, unsigned int revents);
static int remoteRefreshComposing (void *data, unsigned int revents);
static int stopComposing (void *data, unsigned int revents);
static int createChatMessageFromDb (void *data, int argc, char **argv, char **colName);
static void onWeakMessageDestroyed (void *obj, belle_sip_object_t *messageBeingDestroyed);
public:
void addTransientMessage (LinphoneChatMessage *msg);
void addWeakMessage (LinphoneChatMessage *msg);
std::list<LinphoneChatMessage *> getTransientMessages () const {
return transientMessages;
}
void moveTransientMessageToWeakMessages (LinphoneChatMessage *msg);
void removeTransientMessage (LinphoneChatMessage *msg);
void release ();
void sendImdn (const std::string &content, LinphoneReason reason);
int getMessagesCount (bool unreadOnly);
void setCBackPointer (LinphoneChatRoom *cr) {
this->cBackPointer = cr;
}
void setCall (LinphoneCall *call) {
this->call = call;
}
private:
std::string createIsComposingXml () const;
void deleteComposingIdleTimer ();
void deleteComposingRefreshTimer ();
void deleteRemoteComposingRefreshTimer ();
int refreshComposing (unsigned int revents);
int remoteRefreshComposing (unsigned int revents);
void sendIsComposingNotification ();
int stopComposing (unsigned int revents);
void processImdn (xmlparsing_context_t *xmlCtx);
void processIsComposingNotification (xmlparsing_context_t *xmlCtx);
int createChatMessageFromDb (int argc, char **argv, char **colName);
void onWeakMessageDestroyed (LinphoneChatMessage *messageBeingDestroyed);
LinphoneChatMessage *getTransientMessage (unsigned int storageId) const;
LinphoneChatMessage *getWeakMessage (unsigned int storageId) const;
int sqlRequest (sqlite3 *db, const std::string &stmt);
void sqlRequestMessage (sqlite3 *db, const std::string &stmt);
std::list<LinphoneChatMessage *> findMessages (const std::string &messageId);
LinphoneChatMessage *findMessageWithDirection (const std::string &messageId, LinphoneChatMessageDir direction);
void storeOrUpdateMessage (LinphoneChatMessage *msg);
public:
LinphoneReason messageReceived (SalOp *op, const SalMessage *msg);
void realtimeTextReceived (uint32_t character, LinphoneCall *call);
private:
void chatMessageReceived (LinphoneChatMessage *msg);
void imdnReceived (const std::string &text);
void isComposingReceived (const std::string &text);
public:
static const int composingDefaultIdleTimeout = 15;
static const int composingDefaultRefreshTimeout = 60;
static const int composingDefaultRemoteRefreshTimeout = 120;
static const std::string imdnPrefix;
static const std::string isComposingPrefix;
LinphoneChatRoom *cBackPointer = nullptr;
LinphoneCore *core = nullptr;
LinphoneCall *call = nullptr;
LinphoneAddress *peerAddress = nullptr;
std::string peer;
int unreadCount = -1;
bool isComposing = false;
bool remoteIsComposing = false;
belle_sip_source_t *remoteComposingRefreshTimer = nullptr;
belle_sip_source_t *composingIdleTimer = nullptr;
belle_sip_source_t *composingRefreshTimer = nullptr;
std::list<LinphoneChatMessage *> messages;
std::list<LinphoneChatMessage *> transientMessages;
std::list<LinphoneChatMessage *> weakMessages;
std::list<LinphoneChatMessageCharacter *> receivedRttCharacters;
LinphoneChatMessage *pendingMessage = nullptr;
public:
L_DECLARE_PUBLIC(ChatRoom);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _CHAT_ROOM_P_H_
This diff is collapsed.
/*
* chat-room.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHAT_ROOM_H_
#define _CHAT_ROOM_H_
#include <list>
#include <string>
#include "object/object.h"
#include "linphone/types.h"
#include "sal/sal.h"
#include "private.h"
#include <bctoolbox/port.h>
extern "C" {
LinphoneChatRoom *_linphone_core_create_chat_room_base (LinphoneCore *lc, LinphoneAddress *addr);
int linphone_core_message_received (LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg);
void linphone_core_real_time_text_received (LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call);
bctbx_list_t *linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr);
void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call);
void linphone_chat_room_release (LinphoneChatRoom *cr);
void linphone_chat_message_send_imdn (LinphoneChatMessage *cm, ImdnType imdn_type, LinphoneReason reason);
void linphone_chat_message_update_state (LinphoneChatMessage *msg, LinphoneChatMessageState new_state);
}
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ChatRoomPrivate;
class ChatRoom : public Object {
friend LinphoneChatRoom *::_linphone_core_create_chat_room_base (LinphoneCore *lc, LinphoneAddress *addr);
friend int ::linphone_core_message_received(LinphoneCore * lc, SalOp * op, const SalMessage * sal_msg);
friend void ::linphone_core_real_time_text_received(LinphoneCore * lc, LinphoneChatRoom * cr, uint32_t character, LinphoneCall * call);
friend bctbx_list_t *::linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr);
friend void ::linphone_chat_room_remove_transient_message(LinphoneChatRoom * cr, LinphoneChatMessage * msg);
friend void ::linphone_chat_room_set_call(LinphoneChatRoom * cr, LinphoneCall * call);
friend void ::linphone_chat_room_release(LinphoneChatRoom * cr);
friend void ::linphone_chat_message_send_imdn(LinphoneChatMessage * cm, ImdnType imdn_type, LinphoneReason reason);
friend void ::linphone_chat_message_update_state(LinphoneChatMessage * msg, LinphoneChatMessageState new_state);
public:
ChatRoom (LinphoneCore *core, LinphoneAddress *peerAddress);
virtual ~ChatRoom () = default;
void compose ();
LinphoneChatMessage *createFileTransferMessage (const LinphoneContent *initialContent);
LinphoneChatMessage *createMessage (const std::string &msg);
void deleteHistory ();
void deleteMessage (LinphoneChatMessage *msg);
LinphoneChatMessage *findMessage (const std::string &messageId);
uint32_t getChar () const;
std::list<LinphoneChatMessage *> getHistory (int nbMessages);
int getHistorySize ();
std::list<LinphoneChatMessage *> getHistoryRange (int startm, int endm);
int getUnreadMessagesCount ();
bool isRemoteComposing () const;
void markAsRead ();
void sendMessage (LinphoneChatMessage *msg);
LinphoneCall *getCall () const;
LinphoneCore *getCore () const;
const LinphoneAddress *getPeerAddress () const;
private:
L_DECLARE_PRIVATE(ChatRoom);
L_DISABLE_COPY(ChatRoom);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _CHAT_ROOM_H_
/*
* content-type.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "content-type.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
bool ContentType::isFileTransfer (const string &contentType) {
return "application/vnd.gsma.rcs-ft-http+xml" == contentType;
}
bool ContentType::isImIsComposing (const string &contentType) {
return "application/im-iscomposing+xml" == contentType;
}
bool ContentType::isImdn (const string &contentType) {
return "message/imdn+xml" == contentType;
}
bool ContentType::isText (const string &contentType) {
return "text/plain" == contentType;
}
LINPHONE_END_NAMESPACE
/*
* content-type.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CONTENT_TYPE_H_
#define _CONTENT_TYPE_H_
#include <string>
#include "general.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
namespace ContentType {
bool isFileTransfer (const std::string &contentType);
bool isImIsComposing (const std::string &contentType);
bool isImdn (const std::string &contentType);
bool isText (const std::string &contentType);
}
LINPHONE_END_NAMESPACE
#endif // ifndef _CONTENT_TYPE_H_
......@@ -18,6 +18,8 @@
#include <cstdlib>
#include <bctoolbox/port.h>
#include "utils.h"
// =============================================================================
......@@ -60,4 +62,30 @@ int Utils::stoi (const string &str, size_t *idx, int base) {
return v;
}
char *Utils::utf8ToChar (uint32_t ic) {
char *result = new char[5];
int size = 0;
if (ic < 0x80) {
result[0] = ic;
size = 1;
} else if (ic < 0x800) {
result[1] = 0x80 + ((ic & 0x3F));
result[0] = 0xC0 + ((ic >> 6) & 0x1F);
size = 2;
} else if (ic < 0x100000) {
result[2] = 0x80 + (ic & 0x3F);
result[1] = 0x80 + ((ic >> 6) & 0x3F);
result[0] = 0xE0 + ((ic >> 12) & 0xF);
size = 3;
} else if (ic < 0x110000) {
result[3] = 0x80 + (ic & 0x3F);
result[2] = 0x80 + ((ic >> 6) & 0x3F);
result[1] = 0x80 + ((ic >> 12) & 0x3F);
result[0] = 0xF0 + ((ic >> 18) & 0x7);
size = 4;
}
result[size] = '\0';
return result;
}
LINPHONE_END_NAMESPACE
......@@ -38,6 +38,9 @@ namespace Utils {
}
LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10);
// Return a buffer allocated with new.
LINPHONE_PUBLIC char *utf8ToChar (uint32_t ic);
}
LINPHONE_END_NAMESPACE
......
......@@ -161,7 +161,7 @@ void file_transfer_progress_indication(LinphoneChatMessage *msg, const LinphoneC
void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
stats *counters = get_stats(lc);
if (room->remote_is_composing == LinphoneIsComposingActive) {
if (linphone_chat_room_is_remote_composing(room)) {
counters->number_of_LinphoneIsComposingActiveReceived++;
} else {
counters->number_of_LinphoneIsComposingIdleReceived++;
......@@ -236,7 +236,7 @@ LinphoneChatMessage* create_message_from_sintel_trailer(LinphoneChatRoom *chat_r
file_size = ftell(file_to_send);
fseek(file_to_send, 0, SEEK_SET);
content = linphone_core_create_content(chat_room->lc);
content = linphone_core_create_content(linphone_chat_room_get_core(chat_room));
belle_sip_object_set_name(&content->base, "sintel trailer content");
linphone_content_set_type(content,"video");
linphone_content_set_subtype(content,"mkv");
......@@ -262,7 +262,7 @@ LinphoneChatMessage* create_file_transfer_message_from_sintel_trailer(LinphoneCh
LinphoneChatMessage* msg;
char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
content = linphone_core_create_content(chat_room->lc);
content = linphone_core_create_content(linphone_chat_room_get_core(chat_room));
belle_sip_object_set_name(&content->base, "sintel trailer content");
linphone_content_set_type(content,"video");
linphone_content_set_subtype(content,"mkv");
......@@ -413,15 +413,15 @@ static void text_message_with_send_error(void) {
linphone_chat_room_send_chat_message(chat_room,msg);
/* check transient msg list: the msg should be in it, and should be the only one */
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(chat_room->transient_messages), 1, unsigned int, "%u");
BC_ASSERT_PTR_EQUAL(bctbx_list_nth_data(chat_room->transient_messages,0), msg);
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_chat_room_get_transient_messages(chat_room)), 1, unsigned int, "%u");
BC_ASSERT_PTR_EQUAL(bctbx_list_nth_data(linphone_chat_room_get_transient_messages(chat_room),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 msg should have been discarded from transient list after an error */
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(chat_room->transient_messages), 0, unsigned int, "%u");
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_chat_room_get_transient_messages(chat_room)), 0, unsigned int, "%u");
sal_set_send_error(marie->lc->sal, 0);
......@@ -446,8 +446,8 @@ static void text_message_with_external_body(void) {
linphone_chat_room_send_chat_message(chat_room,msg);
/* check transient msg list: the msg should be in it, and should be the only one */
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(chat_room->transient_messages), 1, unsigned int, "%u");
BC_ASSERT_PTR_EQUAL(bctbx_list_nth_data(chat_room->transient_messages,0), msg);
BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_chat_room_get_transient_messages(chat_room)), 1, unsigned int, "%u");
BC_ASSERT_PTR_EQUAL(bctbx_list_nth_data(linphone_chat_room_get_transient_messages(chat_room),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));
......@@ -455,7 +455,7 @@ static void text_message_with_external_body(void) {
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d");
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1, int, "%d");