Commit 34b2882e authored by Ronan's avatar Ronan

feat(Core): use chat room api from new core

parent 2243783c
......@@ -45,6 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "conference/session/call-session.h"
#include "conference/session/media-session-p.h"
#include "conference/session/media-session.h"
#include "core/core-p.h"
using namespace LinphonePrivate;
......@@ -724,7 +725,7 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
LinphoneCore *lc = reinterpret_cast<LinphoneCore *>(op->get_sal()->get_user_pointer());
if (addr.hasUriParam("method") && (addr.getUriParamValue("method") == "BYE")) {
// The server asks a participant to leave a chat room
LinphoneChatRoom *cr = _linphone_core_find_group_chat_room(lc, addr.asStringUriOnly().c_str());
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(addr));
if (cr) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->leave();
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
......@@ -732,7 +733,7 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
}
static_cast<SalReferOp *>(op)->reply(SalReasonDeclined);
} else if (addr.hasParam("admin")) {
LinphoneChatRoom *cr = _linphone_core_find_group_chat_room(lc, op->get_to());
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(Address(op->get_to())));
if (cr) {
Address fromAddr(op->get_from());
std::shared_ptr<Participant> participant = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findParticipant(fromAddr);
......@@ -749,11 +750,12 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
return;
}
} else {
LinphoneChatRoom *cr = _linphone_core_join_client_group_chat_room(lc, addr);
if (cr) {
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
return;
}
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, addr.asString().c_str(), nullptr);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->join();
L_GET_PRIVATE(lc->cppCore)->insertChatRoomWithDb(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
return;
}
}
}
......
......@@ -38,9 +38,10 @@
#include "c-wrapper/c-wrapper.h"
#include "chat/chat-room/basic-chat-room.h"
#include "chat/chat-room/client-group-chat-room.h"
#include "chat/chat-room/real-time-text-chat-room.h"
#include "chat/chat-room/real-time-text-chat-room-p.h"
#include "chat/chat-room/real-time-text-chat-room.h"
#include "content/content-type.h"
#include "core/core.h"
using namespace std;
......@@ -56,14 +57,11 @@ bool_t linphone_core_chat_enabled(const LinphoneCore *lc) {
return lc->chat_deny_code != LinphoneReasonNone;
}
const bctbx_list_t *linphone_core_get_chat_rooms(LinphoneCore *lc) {
return lc->chatrooms;
}
static LinphoneChatRoom *_linphone_core_create_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) {
LinphoneChatRoom *cr = linphone_chat_room_new(lc, addr);
lc->chatrooms = bctbx_list_append(lc->chatrooms, (void *)cr);
return cr;
const bctbx_list_t *linphone_core_get_chat_rooms (LinphoneCore *lc) {
if (lc->chat_rooms)
bctbx_list_free_with_data(lc->chat_rooms, (bctbx_list_free_func)linphone_chat_room_unref);
lc->chat_rooms = L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(lc->cppCore->getChatRooms());
return lc->chat_rooms;
}
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call){
......@@ -73,91 +71,25 @@ LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call){
return cr;
}
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);
}
return NULL;
}
static bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from) {
LinphoneAddress *addr = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asString().c_str());
bool_t result = linphone_address_weak_equal(addr, from);
linphone_address_unref(addr);
return result;
LinphoneChatRoom *linphone_core_get_chat_room (LinphoneCore *lc, const LinphoneAddress *addr) {
return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(addr)));
}
LinphoneChatRoom *_linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) {
LinphoneChatRoom *cr = NULL;
bctbx_list_t *elem;
for (elem = lc->chatrooms; elem != NULL; elem = bctbx_list_next(elem)) {
cr = (LinphoneChatRoom *)elem->data;
if (linphone_chat_room_matches(cr, addr)) {
break;
}
cr = NULL;
}
return cr;
LinphoneChatRoom *linphone_core_create_client_group_chat_room (LinphoneCore *lc, const char *subject) {
return L_GET_C_BACK_PTR(lc->cppCore->createClientGroupChatRoom(L_C_TO_STRING(subject)));
}
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);
return NULL;
}
ret = _linphone_core_get_chat_room(lc, to_addr);
linphone_address_unref(to_addr);
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 *ret = _linphone_core_get_chat_room(lc, addr);
if (!ret) {
ret = _linphone_core_create_chat_room(lc, addr);
}
return ret;
}
LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject) {
const char *factoryUri = linphone_core_get_conference_factory_uri(lc);
if (!factoryUri)
return nullptr;
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, factoryUri, subject);
lc->chatrooms = bctbx_list_append(lc->chatrooms, cr);
return cr;
}
LinphoneChatRoom *_linphone_core_join_client_group_chat_room (LinphoneCore *lc, const LinphonePrivate::Address &addr) {
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, addr.asString().c_str(), nullptr);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->join();
lc->chatrooms = bctbx_list_append(lc->chatrooms, cr);
return cr;
}
void linphone_core_delete_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr) {
if (bctbx_list_find(lc->chatrooms, cr)) {
lc->chatrooms = bctbx_list_remove(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);
}
void linphone_core_delete_chat_room (LinphoneCore *, LinphoneChatRoom *cr) {
LinphonePrivate::Core::deleteChatRoom(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
}
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
return _linphone_core_get_or_create_chat_room(lc, to);
return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoom(L_C_TO_STRING(to)));
}
int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
LinphoneReason reason = LinphoneReasonNotAcceptable;
LinphoneChatRoom *cr = _linphone_core_find_group_chat_room(lc, op->get_from());
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(LinphonePrivate::Address(op->get_from())));
if (cr)
reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
else {
......@@ -171,8 +103,6 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op,
return reason;
}
void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call) {
if (linphone_core_realtime_text_enabled(lc)) {
shared_ptr<LinphonePrivate::RealTimeTextChatRoom> rttcr =
......
......@@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <mediastreamer2/zrtp.h>
#include <mediastreamer2/dtls_srtp.h>
#include <bctoolbox/defs.h>
#include "mediastreamer2/dtmfgen.h"
#include "mediastreamer2/mediastream.h"
#include "mediastreamer2/msequalizer.h"
......@@ -45,8 +46,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "mediastreamer2/msjpegwriter.h"
#include "mediastreamer2/msogl.h"
#include "mediastreamer2/msvolume.h"
#include "chat/chat-room/client-group-chat-room-p.h"
#include "conference/remote-conference-event-handler.h"
#include "core/core.h"
// For migration purpose.
#include "address/address-p.h"
......@@ -2128,9 +2131,7 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve
}
} else if (strcmp(notified_event, "conference") == 0) {
const LinphoneAddress *resource = linphone_event_get_resource(lev);
char *resourceUri = linphone_address_as_string_uri_only(resource);
LinphoneChatRoom *cr = _linphone_core_find_group_chat_room(lc, resourceUri);
bctbx_free(resourceUri);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)));
if (cr)
L_GET_PRIVATE_FROM_C_OBJECT(cr, ClientGroupChatRoom)->notifyReceived(linphone_content_get_string_buffer(body));
}
......@@ -2234,7 +2235,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
lc->sal->set_user_pointer(lc);
lc->sal->set_callbacks(&linphone_sal_callbacks);
new(&lc->cppCore) Core(lc);
new(&lc->cppCore) std::shared_ptr<Core>();
lc->cppCore = ObjectFactory::create<Core>(lc);
#ifdef TUNNEL_ENABLED
lc->tunnel=linphone_core_tunnel_new(lc);
......@@ -2266,7 +2268,6 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
linphone_configuring_terminated(lc, LinphoneConfiguringSkipped, NULL);
} // else linphone_core_start will be called after the remote provisioning (see linphone_core_iterate)
lc->bw_controller = ms_bandwidth_controller_new();
lc->group_chat_rooms = bctbx_mmap_cchar_new();
}
#ifdef __ANDROID__
......@@ -2280,7 +2281,7 @@ static void _linphone_core_set_system_context(LinphoneCore *lc, void *system_con
}
#else
static void _linphone_core_set_system_context(LinphoneCore *lc, void *system_context){
}
#endif
......@@ -5873,7 +5874,7 @@ void sip_config_uninit(LinphoneCore *lc)
delete lc->sal;
lc->sal=NULL;
lc->cppCore.~Core();
lc->cppCore.~shared_ptr<Core>();
if (lc->sip_conf.guessed_contact)
ms_free(lc->sip_conf.guessed_contact);
......@@ -6043,9 +6044,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
ms_usleep(10000);
}
lc->chatrooms = bctbx_list_free_with_data(lc->chatrooms, (MSIterateFunc)linphone_chat_room_release);
if (lc->group_chat_rooms)
bctbx_mmap_cchar_delete_with_data(lc->group_chat_rooms, (void (*)(void *))linphone_chat_room_unref);
lc->chat_rooms = bctbx_list_free_with_data(lc->chat_rooms, (bctbx_list_free_func)linphone_chat_room_unref);
linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
#ifdef VIDEO_ENABLED
......@@ -6143,11 +6142,11 @@ static void set_sip_network_reachable(LinphoneCore* lc,bool_t is_sip_reachable,
if (lc->sip_network_reachable==is_sip_reachable) return; // no change, ignore.
lc->network_reachable_to_be_notified=TRUE;
if (is_sip_reachable){
getPlatformHelpers(lc)->setDnsServers();
}
ms_message("SIP network reachability state is now [%s]",is_sip_reachable?"UP":"DOWN");
for(elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
......@@ -7149,53 +7148,6 @@ const char * linphone_core_get_conference_factory_uri(const LinphoneCore *lc) {
return lp_config_get_string(linphone_core_get_config(lc), "misc", "conference_factory_uri", nullptr);
}
bool_t _linphone_core_has_group_chat_room(const LinphoneCore *lc, const char *id) {
bool_t result;
bctbx_iterator_t *it = bctbx_map_cchar_find_key(lc->group_chat_rooms, id);
bctbx_iterator_t *endit = bctbx_map_cchar_end(lc->group_chat_rooms);
result = !bctbx_iterator_cchar_equals(it, endit);
bctbx_iterator_cchar_delete(endit);
bctbx_iterator_cchar_delete(it);
return result;
}
void _linphone_core_add_group_chat_room(LinphoneCore *lc, const LinphonePrivate::Address &addr, LinphoneChatRoom *cr) {
Address cleanedAddr(addr);
cleanedAddr.clean();
cleanedAddr.setPort(0);
bctbx_pair_t *pair = reinterpret_cast<bctbx_pair_t *>(bctbx_pair_cchar_new(cleanedAddr.asStringUriOnly().c_str(), linphone_chat_room_ref(cr)));
bctbx_map_cchar_insert_and_delete(lc->group_chat_rooms, pair);
}
void _linphone_core_remove_group_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr) {
const LinphoneAddress *confAddr = linphone_chat_room_get_conference_address(cr);
Address cleanedAddr(*L_GET_CPP_PTR_FROM_C_OBJECT(confAddr));
cleanedAddr.clean();
cleanedAddr.setPort(0);
bctbx_iterator_t *it = bctbx_map_cchar_find_key(lc->group_chat_rooms, cleanedAddr.asStringUriOnly().c_str());
bctbx_iterator_t *endit = bctbx_map_cchar_end(lc->group_chat_rooms);
if (!bctbx_iterator_cchar_equals(it, endit)) {
bctbx_map_cchar_erase(lc->group_chat_rooms, it);
linphone_chat_room_unref(cr);
}
bctbx_iterator_cchar_delete(endit);
bctbx_iterator_cchar_delete(it);
}
LinphoneChatRoom *_linphone_core_find_group_chat_room(const LinphoneCore *lc, const char *id) {
LinphoneChatRoom *result = nullptr;
Address cleanedAddr(id);
cleanedAddr.clean();
cleanedAddr.setPort(0);
bctbx_iterator_t *it = bctbx_map_cchar_find_key(lc->group_chat_rooms, cleanedAddr.asStringUriOnly().c_str());
bctbx_iterator_t *endit = bctbx_map_cchar_end(lc->group_chat_rooms);
if (!bctbx_iterator_cchar_equals(it, endit))
result = reinterpret_cast<LinphoneChatRoom *>(bctbx_pair_cchar_get_second(bctbx_iterator_cchar_get_pair(it)));
bctbx_iterator_cchar_delete(endit);
bctbx_iterator_cchar_delete(it);
return result;
}
void linphone_core_set_tls_cert(LinphoneCore *lc, const char *tls_cert) {
if (lc->tls_cert) {
ms_free(lc->tls_cert);
......
......@@ -25,6 +25,8 @@
#ifndef _PRIVATE_H
#define _PRIVATE_H
#include <memory>
#include "linphone/core.h"
#include "linphone/friend.h"
#include "linphone/friendlist.h"
......@@ -34,7 +36,6 @@
#include "address/address.h"
#include "c-wrapper/internal/c-sal.h"
#include "core/core.h"
#include "sal/call-op.h"
#include "sal/event-op.h"
#include "sal/message-op.h"
......@@ -456,9 +457,6 @@ bool_t linphone_core_incompatible_security(LinphoneCore *lc, SalMediaDescription
extern LinphonePrivate::Sal::Callbacks linphone_sal_callbacks;
LINPHONE_PUBLIC bool_t linphone_core_rtcp_enabled(const LinphoneCore *lc);
LINPHONE_PUBLIC bool_t linphone_core_symmetric_rtp_enabled(LinphoneCore*lc);
bool_t _linphone_core_has_group_chat_room (const LinphoneCore *lc, const char *id);
void _linphone_core_add_group_chat_room (LinphoneCore *lc, const LinphonePrivate::Address &addr, LinphoneChatRoom *cr);
void _linphone_core_remove_group_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr);
void linphone_core_queue_task(LinphoneCore *lc, belle_sip_source_func_t task_fun, void *data, const char *task_description);
......@@ -473,7 +471,6 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
/*chat*/
LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddress *addr);
LinphoneChatRoom *_linphone_core_join_client_group_chat_room (LinphoneCore *core, const LinphonePrivate::Address &addr);
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject);
void linphone_chat_room_release(LinphoneChatRoom *cr);
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call);
......@@ -810,6 +807,10 @@ typedef struct _LCCallbackObj {
void *_user_data;
} LCCallbackObj;
namespace LinphonePrivate {
class Core;
};
struct _LinphoneCore
{
belle_sip_object_t base;
......@@ -819,7 +820,7 @@ struct _LinphoneCore
LinphonePrivate::Sal *sal;
// For migration purposes
LinphonePrivate::Core cppCore;
std::shared_ptr<LinphonePrivate::Core> cppCore;
void *platform_helper; /*is a LinphonePrivate::PlatformHelpers but cannot be used as is because private.h is compiled as C in testers.*/
......@@ -847,8 +848,6 @@ struct _LinphoneCore
MSList *calls; /* all the processed calls */
MSList *queued_calls; /* used by the autoreplier */
MSList *call_logs;
MSList *chatrooms;
bctbx_map_t *group_chat_rooms;
int max_call_logs;
int missed_calls;
VideoPreview *previewstream;
......@@ -941,6 +940,9 @@ struct _LinphoneCore
LinphoneImEncryptionEngine *im_encryption_engine;
struct _LinphoneAccountCreatorService *default_ac_service;
MSBandwidthController *bw_controller;
// For migration purpose.
bctbx_list_t *chat_rooms;
};
#ifdef __cplusplus
......
......@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/core.h"
#include "linphone/tunnel.h"
#include "c-wrapper/internal/c-sal.h"
#include <sqlite3.h>
#include <sqlite3.h>
#include "quality_reporting.h"
#include "vcard_private.h"
......@@ -94,7 +94,6 @@ LINPHONE_PUBLIC mblk_t *_linphone_call_stats_get_received_rtcp (const LinphoneCa
LINPHONE_PUBLIC LinphoneQualityReporting *linphone_call_log_get_quality_reporting(LinphoneCallLog *call_log);
LINPHONE_PUBLIC reporting_session_report_t **linphone_quality_reporting_get_reports(LinphoneQualityReporting *qreporting);
LINPHONE_PUBLIC LinphoneChatRoom *_linphone_core_find_group_chat_room(const LinphoneCore *lc, const char *id);
LINPHONE_PUBLIC bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr);
LINPHONE_PUBLIC MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc, LinphoneFriendList *list);
......
......@@ -106,6 +106,7 @@ namespace Utils {
}
LINPHONE_PUBLIC std::tm getLongAsTm (long time);
LINPHONE_PUBLIC long getTmAsLong (const std::tm &time);
}
LINPHONE_END_NAMESPACE
......
......@@ -205,7 +205,7 @@ bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_messa
bctbx_list_t *linphone_chat_room_get_history_events (LinphoneChatRoom *cr, int nb_events) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore()->cppCore)->mainDb.getHistory(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore()->cppCore)->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
nb_events
)
......@@ -214,7 +214,7 @@ bctbx_list_t *linphone_chat_room_get_history_events (LinphoneChatRoom *cr, int n
bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr, int begin, int end) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore()->cppCore)->mainDb.getHistory(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore()->cppCore)->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
begin,
end
......@@ -330,14 +330,10 @@ void linphone_chat_room_set_user_data (LinphoneChatRoom *cr, void *ud) {
// =============================================================================
LinphoneChatRoom *linphone_chat_room_new (LinphoneCore *core, const LinphoneAddress *addr) {
LinphoneChatRoom *cr = L_INIT(ChatRoom);
if (linphone_core_realtime_text_enabled(core))
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::RealTimeTextChatRoom>(core, *L_GET_CPP_PTR_FROM_C_OBJECT(addr)));
else
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::BasicChatRoom>(core, *L_GET_CPP_PTR_FROM_C_OBJECT(addr)));
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Created);
return cr;
return L_GET_C_BACK_PTR(core->cppCore->getOrCreateBasicChatRoom(
*L_GET_CPP_PTR_FROM_C_OBJECT(addr),
linphone_core_realtime_text_enabled(core)
));
}
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject) {
......
......@@ -35,7 +35,8 @@ BasicChatRoomPrivate::BasicChatRoomPrivate (LinphoneCore *core, const Address &p
// =============================================================================
BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new BasicChatRoomPrivate(core, peerAddress)) {}
BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) :
ChatRoom(*new BasicChatRoomPrivate(core, peerAddress)) {}
// -----------------------------------------------------------------------------
......
......@@ -30,6 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
class ChatRoomPrivate;
class LINPHONE_PUBLIC ChatRoom : public Object, public ConferenceInterface {
friend class Core;
friend class ChatMessage;
friend class ChatMessagePrivate;
......
......@@ -251,7 +251,7 @@ void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
dConference->conferenceAddress = addr;
d->peerAddress = addr;
d->setState(ChatRoom::State::Created);
_linphone_core_add_group_chat_room(d->core, addr, L_GET_C_BACK_PTR(this));
d->core->cppCore->getPrivate()->insertChatRoomWithDb(getSharedFromThis());
}
void ClientGroupChatRoom::onConferenceTerminated (const Address &addr) {
......@@ -283,7 +283,7 @@ void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) {
dConference->eventHandler->getLastNotify(),
addr
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......@@ -308,7 +308,7 @@ void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr)
dConference->eventHandler->getLastNotify(),
addr
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......@@ -339,7 +339,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr,
dConference->eventHandler->getLastNotify(),
addr
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......@@ -357,7 +357,7 @@ void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subjec
dConference->eventHandler->getLastNotify(),
subject
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......@@ -386,7 +386,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &ad
addr,
gruu
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......@@ -415,7 +415,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &
addr,
gruu
);
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
Conference::getCore()->cppCore->getPrivate()->mainDb->addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(event));
......
......@@ -69,7 +69,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
pendingMessage->setToAddress(
Address(
linphone_call_get_dest_proxy(call)
? linphone_address_as_string(linphone_call_get_dest_proxy(call)->identity_address)
? linphone_address_as_string(linphone_call_get_dest_proxy(call)->identity_address)
: linphone_core_get_identity(core)
)
);
......@@ -106,7 +106,8 @@ void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr<ChatMessage
// =============================================================================
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) :
ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
int RealTimeTextChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic) | static_cast<int>(Capabilities::RealTimeText);
......
......@@ -30,12 +30,18 @@ LINPHONE_BEGIN_NAMESPACE
class CorePrivate : public ObjectPrivate {
public:
MainDb mainDb;
LinphoneCore *cCore;
std::unique_ptr<MainDb> mainDb;
LinphoneCore *cCore = nullptr;
void insertChatRoomWithDb (const std::shared_ptr<ChatRoom> &chatRoom);
void deleteChatRoomWithDb (const std::string &peerAddress);
private:
void insertChatRoom (const std::shared_ptr<ChatRoom> &chatRoom);
void deleteChatRoom (const std::string &peerAddress);
std::list<std::shared_ptr<ChatRoom>> chatRooms;
std::unordered_map<std::string, std::shared_ptr<ChatRoom>> chatRoomsMap;
std::unordered_map<std::string, std::shared_ptr<ChatRoom>> chatRoomsByUri;
L_DECLARE_PUBLIC(Core);
};
......
......@@ -21,6 +21,8 @@
#include <sstream>
#include "chat/chat-room/basic-chat-room.h"
#include "chat/chat-room/chat-room-p.h"
#include "chat/chat-room/real-time-text-chat-room.h"
#include "core-p.h"
#include "db/main-db.h"
#include "logger/logger.h"
......@@ -28,6 +30,7 @@
#include "paths/paths.h"
// TODO: Remove me later.
#include "c-wrapper/c-wrapper.h"
#include "private.h"
#define LINPHONE_DB "linphone.db"
......@@ -39,50 +42,164 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
// Helpers.
// -----------------------------------------------------------------------------
static inline Address getCleanedPeerAddress (const Address &peerAddress) {
Address cleanedAddress = peerAddress;
cleanedAddress.clean();
cleanedAddress.setPort(0);
return cleanedAddress;
}
// -----------------------------------------------------------------------------
// CorePrivate: ChatRoom.
// -----------------------------------------------------------------------------
void CorePrivate::insertChatRoom (const shared_ptr<ChatRoom> &chatRoom) {
L_ASSERT(chatRoom);
L_ASSERT(chatRoom->getState() == ChatRoom::State::Created);
string peerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly();
deleteChatRoom(peerAddress);
chatRooms.push_back(chatRoom);
chatRoomsByUri[peerAddress] = chatRoom;
}
void CorePrivate::deleteChatRoom (const string &peerAddress) {
auto it = chatRoomsByUri.find(peerAddress);
if (it != chatRoomsByUri.end())
chatRooms.erase(
find_if(chatRooms.begin(), chatRooms.end(), [&peerAddress](const shared_ptr<const ChatRoom> &chatRoom) {
return peerAddress == chatRoom->getPeerAddress().asStringUriOnly();
})
);
}
void CorePrivate::insertChatRoomWithDb (const shared_ptr<ChatRoom> &chatRoom) {
insertChatRoom(chatRoom);
mainDb->insertChatRoom(
getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly(),
chatRoom->getCapabilities()
);
}
void CorePrivate::deleteChatRoomWithDb (const string &peerAddress) {
deleteChatRoom(peerAddress);
mainDb->deleteChatRoom(peerAddress);
}
// =============================================================================
Core::Core (LinphoneCore *cCore) : Object(*new CorePrivate) {
L_D();
d->cCore = cCore;
const char *uri = lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_uri", NULL);
if (uri) {
AbstractDb::Backend backend =
strcmp(lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_backend", NULL), "mysql") == 0
d->mainDb.reset(new MainDb(this));
AbstractDb::Backend backend;
string uri = L_C_TO_STRING(lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_uri", NULL));
if (!uri.empty())
backend = strcmp(lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_backend", NULL), "mysql") == 0
? MainDb::Mysql
: MainDb::Sqlite3;
lInfo() << "Creating " LINPHONE_DB " at: " << uri;
d->mainDb.connect(backend, uri);
return;
else {
backend = AbstractDb::Sqlite3;
uri = getDataPath() + "/" LINPHONE_DB;
}
static string path = getDataPath() + "/" LINPHONE_DB;
lInfo() << "Creating " LINPHONE_DB " at: " << path;
d->mainDb.connect(MainDb::Sqlite3, path);
lInfo() << "Opening " LINPHONE_DB " at: " << uri;
if (!d->mainDb->connect(backend, uri))
lFatal() << "Unable to open linphone database.";
for (auto &chatRoom : d->mainDb->getChatRooms())
d->insertChatRoom(chatRoom);
}
// -----------------------------------------------------------------------------
// Paths.
// -----------------------------------------------------------------------------
shared_ptr<ChatRoom> Core::createClientGroupChatRoom (const string &subject) {
// TODO.
return shared_ptr<ChatRoom>();
string Core::getDataPath() const {
L_D();
return Paths::getPath(Paths::Data, static_cast<PlatformHelpers *>(d->cCore->platform_helper));
}
shared_ptr<ChatRoom> Core::getOrCreateChatRoom (const string &peerAddress, bool isRtt) const {
return shared_ptr<ChatRoom>();
string Core::getConfigPath() const {
L_D();
return Paths::getPath(Paths::Config, static_cast<PlatformHelpers *>(d->cCore->platform_helper));
}
// -----------------------------------------------------------------------------
// ChatRoom.
// -----------------------------------------------------------------------------
const list<shared_ptr<ChatRoom>> &Core::getChatRooms () const {
L_D();
return d->chatRooms;
}
string Core::getDataPath() const {