mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
feat(Core): use chat room api from new core
This commit is contained in:
parent
2243783c16
commit
34b2882e38
29 changed files with 359 additions and 279 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
100
coreapi/chat.c
100
coreapi/chat.c
|
|
@ -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;
|
||||
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)));
|
||||
}
|
||||
|
||||
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_create_client_group_chat_room (LinphoneCore *lc, const char *subject) {
|
||||
return L_GET_C_BACK_PTR(lc->cppCore->createClientGroupChatRoom(L_C_TO_STRING(subject)));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,41 +42,83 @@ 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);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
shared_ptr<ChatRoom> Core::createClientGroupChatRoom (const string &subject) {
|
||||
// TODO.
|
||||
return shared_ptr<ChatRoom>();
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> Core::getOrCreateChatRoom (const string &peerAddress, bool isRtt) const {
|
||||
return shared_ptr<ChatRoom>();
|
||||
}
|
||||
|
||||
const list<shared_ptr<ChatRoom>> &Core::getChatRooms () const {
|
||||
L_D();
|
||||
return d->chatRooms;
|
||||
}
|
||||
// Paths.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
string Core::getDataPath() const {
|
||||
L_D();
|
||||
|
|
@ -85,6 +130,78 @@ string Core::getConfigPath() const {
|
|||
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;
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> Core::findChatRoom (const Address &peerAddress) const {
|
||||
L_D();
|
||||
auto it = d->chatRoomsByUri.find(getCleanedPeerAddress(peerAddress).asStringUriOnly());
|
||||
return it == d->chatRoomsByUri.cend() ? shared_ptr<ChatRoom>() : it->second;
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> Core::createClientGroupChatRoom (const string &subject) {
|
||||
L_D();
|
||||
|
||||
const char *factoryUri = linphone_core_get_conference_factory_uri(d->cCore);
|
||||
if (!factoryUri)
|
||||
return nullptr;
|
||||
|
||||
return L_GET_CPP_PTR_FROM_C_OBJECT(
|
||||
_linphone_client_group_chat_room_new(d->cCore, factoryUri, L_STRING_TO_C(subject))
|
||||
);
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> Core::getOrCreateBasicChatRoom (const Address &peerAddress, bool isRtt) {
|
||||
L_D();
|
||||
|
||||
if (!peerAddress.isValid()) {
|
||||
lWarning() << "Cannot find get or create chat room with invalid peer address.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> chatRoom = findChatRoom(peerAddress);
|
||||
if (chatRoom)
|
||||
return chatRoom;
|
||||
|
||||
if (isRtt)
|
||||
chatRoom = ObjectFactory::create<RealTimeTextChatRoom>(d->cCore, peerAddress);
|
||||
else
|
||||
chatRoom = ObjectFactory::create<BasicChatRoom>(d->cCore, peerAddress);
|
||||
|
||||
chatRoom->getPrivate()->setState(ChatRoom::State::Instantiated);
|
||||
chatRoom->getPrivate()->setState(ChatRoom::State::Created);
|
||||
|
||||
d->insertChatRoomWithDb(chatRoom);
|
||||
|
||||
return chatRoom;
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> Core::getOrCreateBasicChatRoom (const string &peerAddress, bool isRtt) {
|
||||
L_D();
|
||||
|
||||
LinphoneAddress *address = linphone_core_interpret_url(d->cCore, L_STRING_TO_C(peerAddress));
|
||||
if (!address) {
|
||||
lError() << "Cannot make a valid address with: `" << peerAddress << "`.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<ChatRoom> chatRoom = getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(address), isRtt);
|
||||
linphone_address_unref(address);
|
||||
return chatRoom;
|
||||
}
|
||||
|
||||
void Core::deleteChatRoom (const shared_ptr<const ChatRoom> &chatRoom) {
|
||||
CorePrivate *d = chatRoom->getCore()->cppCore->getPrivate();
|
||||
string peerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly();
|
||||
d->deleteChatRoomWithDb(peerAddress);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -30,21 +30,36 @@ L_DECL_C_STRUCT(LinphoneCore);
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class Address;
|
||||
class ChatRoom;
|
||||
class CorePrivate;
|
||||
|
||||
class LINPHONE_PUBLIC Core : public Object {
|
||||
friend class ClientGroupChatRoom;
|
||||
friend class ClientGroupChatRoom;
|
||||
|
||||
public:
|
||||
L_OVERRIDE_SHARED_FROM_THIS(Core);
|
||||
|
||||
Core (LinphoneCore *cCore);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Paths.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
std::string getDataPath() const;
|
||||
std::string getConfigPath() const;
|
||||
|
||||
const std::list<std::shared_ptr<ChatRoom>> &getChatRooms () const;
|
||||
// ---------------------------------------------------------------------------
|
||||
// ChatRoom.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const std::list<std::shared_ptr<ChatRoom>> &getChatRooms () const;
|
||||
std::shared_ptr<ChatRoom> findChatRoom (const Address &peerAddress) const;
|
||||
std::shared_ptr<ChatRoom> createClientGroupChatRoom (const std::string &subject);
|
||||
std::shared_ptr<ChatRoom> getOrCreateChatRoom (const std::string &peerAddress, bool isRtt = false) const;
|
||||
std::shared_ptr<ChatRoom> getOrCreateBasicChatRoom (const Address &peerAddress, bool isRtt = false);
|
||||
std::shared_ptr<ChatRoom> getOrCreateBasicChatRoom (const std::string &peerAddress, bool isRtt = false);
|
||||
|
||||
static void deleteChatRoom (const std::shared_ptr<const ChatRoom> &chatRoom);
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Core);
|
||||
|
|
|
|||
|
|
@ -19,26 +19,27 @@
|
|||
|
||||
#include <jni.h>
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
#include "linphone/utils/utils.h"
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
|
||||
#include "paths-android.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
std::string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
|
||||
if (!platformHelper) {
|
||||
return Utils::getEmptyConstRefObject<std::string>();
|
||||
}
|
||||
string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
|
||||
if (!platformHelper)
|
||||
return Utils::getEmptyConstRefObject<string>();
|
||||
return platformHelper->getDataPath();
|
||||
}
|
||||
|
||||
std::string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
|
||||
if (!platformHelper) {
|
||||
return Utils::getEmptyConstRefObject<std::string>();
|
||||
}
|
||||
string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
|
||||
if (!platformHelper)
|
||||
return Utils::getEmptyConstRefObject<string>();
|
||||
return platformHelper->getConfigPath();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class PlatformHelpers;
|
||||
|
||||
namespace SysPaths {
|
||||
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
|
||||
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class PlatformHelpers;
|
||||
|
||||
namespace SysPaths {
|
||||
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
|
||||
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
|
||||
|
|
|
|||
|
|
@ -17,23 +17,37 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
#include "linphone/utils/utils.h"
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
#include "logger/logger.h"
|
||||
|
||||
#include "paths-linux.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
static std::string dataPath = "~/.local/share/linphone";
|
||||
static std::string configPath = "~/.config/linphone";
|
||||
static string getBaseDirectory () {
|
||||
static string base;
|
||||
if (base.empty()) {
|
||||
char *dir = getenv("HOME");
|
||||
if (!dir)
|
||||
lFatal() << "Unable to get home directory.";
|
||||
base = dir;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
std::string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
|
||||
string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
|
||||
static string dataPath = getBaseDirectory() + "/.local/share/linphone";
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
std::string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
|
||||
string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
|
||||
static string configPath = getBaseDirectory() + "/.config/linphone";
|
||||
return configPath;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class PlatformHelpers;
|
||||
|
||||
namespace SysPaths {
|
||||
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
|
||||
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@
|
|||
*/
|
||||
|
||||
#include <stream>
|
||||
|
||||
#include "shlobj.h"
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
#include "linphone/utils/utils.h"
|
||||
|
||||
#include "core/platform-helpers/platform-helpers.h"
|
||||
|
||||
#include "paths-windows.h"
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -46,7 +48,7 @@ string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
|
|||
}
|
||||
|
||||
string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
|
||||
// seems to be the same directory
|
||||
// Seems to be the same directory.
|
||||
return getDataPath(platformHelper);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class PlatformHelpers;
|
||||
|
||||
namespace SysPaths {
|
||||
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
|
||||
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
|
||||
|
|
|
|||
|
|
@ -21,16 +21,16 @@
|
|||
#include "paths.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "paths-apple.h"
|
||||
#include "paths-apple.h"
|
||||
#elif defined(__ANDROID__)
|
||||
#include "paths-android.h"
|
||||
#include "paths-android.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "paths-windows.h"
|
||||
#include "paths-windows.h"
|
||||
#elif defined(__linux)
|
||||
#include "paths-linux.h"
|
||||
#include "paths-linux.h"
|
||||
#else
|
||||
#error "Unsupported system"
|
||||
#endif
|
||||
#error "Unsupported system."
|
||||
#endif // ifdef __APPLE__
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -43,9 +43,11 @@ string Paths::getPath (Paths::Type type, PlatformHelpers *platformHelper) {
|
|||
case Data:
|
||||
return SysPaths::getDataPath(platformHelper);
|
||||
case Config:
|
||||
default:
|
||||
return SysPaths::getConfigPath(platformHelper);
|
||||
}
|
||||
|
||||
L_ASSERT(false);
|
||||
return "";
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Paths {
|
|||
Config
|
||||
};
|
||||
|
||||
LINPHONE_PUBLIC std::string getPath(Type type, PlatformHelpers *platformHelper);
|
||||
LINPHONE_PUBLIC std::string getPath (Type type, PlatformHelpers *platformHelper);
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
StubbedPlatformHelpers::StubbedPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc) {}
|
||||
|
|
@ -39,11 +41,11 @@ void StubbedPlatformHelpers::acquireCpuLock () {}
|
|||
|
||||
void StubbedPlatformHelpers::releaseCpuLock () {}
|
||||
|
||||
std::string StubbedPlatformHelpers::getDataPath () {
|
||||
string StubbedPlatformHelpers::getDataPath () {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string StubbedPlatformHelpers::getConfigPath () {
|
||||
string StubbedPlatformHelpers::getConfigPath () {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,8 @@ private:
|
|||
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
|
||||
Core *core;
|
||||
|
||||
L_DECLARE_PUBLIC(MainDb);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,10 @@
|
|||
#include "conference/participant.h"
|
||||
#include "content/content-type.h"
|
||||
#include "content/content.h"
|
||||
#include "core/core.h"
|
||||
#include "db/session/db-session-provider.h"
|
||||
#include "event-log/events.h"
|
||||
#include "event-log/event-log-p.h"
|
||||
#include "event-log/events.h"
|
||||
#include "logger/logger.h"
|
||||
#include "main-db-p.h"
|
||||
|
||||
|
|
@ -44,7 +45,10 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
||||
MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
|
||||
L_D();
|
||||
d->core = core;
|
||||
}
|
||||
|
||||
#ifdef SOCI_ENABLED
|
||||
|
||||
|
|
@ -1003,53 +1007,72 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
list<shared_ptr<ChatRoom>> MainDb::getChatRooms () const {
|
||||
static const string query = "SELECT value, creation_date, last_update_date, capabilities, subject, last_notify_id"
|
||||
" FROM chat_room, sip_address"
|
||||
" WHERE peer_sip_address_id = id";
|
||||
list<shared_ptr<ChatRoom>> MainDb::getChatRooms () const {
|
||||
static const string query = "SELECT value, creation_date, last_update_date, capabilities, subject, last_notify_id"
|
||||
" FROM chat_room, sip_address"
|
||||
" WHERE peer_sip_address_id = id";
|
||||
|
||||
L_D();
|
||||
L_D();
|
||||
|
||||
list<shared_ptr<ChatRoom>> chatRooms;
|
||||
list<shared_ptr<ChatRoom>> chatRooms;
|
||||
|
||||
L_BEGIN_LOG_EXCEPTION
|
||||
L_BEGIN_LOG_EXCEPTION
|
||||
|
||||
soci::session *session = d->dbSession.getBackendSession<soci::session>();
|
||||
soci::session *session = d->dbSession.getBackendSession<soci::session>();
|
||||
|
||||
soci::rowset<soci::row> rows = (session->prepare << query);
|
||||
for (const auto &row : rows) {
|
||||
string sipAddress = row.get<string>(0);
|
||||
tm creationDate = row.get<tm>(1);
|
||||
tm lastUpdateDate = row.get<tm>(2);
|
||||
int capabilities = row.get<int>(3);
|
||||
string subject = row.get<string>(4);
|
||||
unsigned int lastNotifyId = row.get<unsigned int>(5);
|
||||
soci::rowset<soci::row> rows = (session->prepare << query);
|
||||
for (const auto &row : rows) {
|
||||
string sipAddress = row.get<string>(0);
|
||||
tm creationDate = row.get<tm>(1);
|
||||
tm lastUpdateDate = row.get<tm>(2);
|
||||
int capabilities = row.get<int>(3);
|
||||
string subject = row.get<string>(4);
|
||||
unsigned int lastNotifyId = row.get<unsigned int>(5);
|
||||
|
||||
(void)sipAddress;
|
||||
(void)creationDate;
|
||||
(void)lastUpdateDate;
|
||||
(void)capabilities;
|
||||
(void)subject;
|
||||
(void)lastNotifyId;
|
||||
// TODO: Use me.
|
||||
(void)creationDate;
|
||||
(void)lastUpdateDate;
|
||||
(void)subject;
|
||||
(void)lastNotifyId;
|
||||
|
||||
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Basic)) {
|
||||
if (capabilities & static_cast<int>(ChatRoom::Capabilities::RealTimeText)) {
|
||||
// TODO.
|
||||
continue;
|
||||
shared_ptr<ChatRoom> chatRoom;
|
||||
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Basic)) {
|
||||
chatRoom = d->core ? d->core->getOrCreateBasicChatRoom(
|
||||
Address(sipAddress),
|
||||
capabilities & static_cast<int>(ChatRoom::Capabilities::RealTimeText)
|
||||
) : nullptr;
|
||||
} else if (capabilities & static_cast<int>(ChatRoom::Capabilities::Conference)) {
|
||||
// TODO: Set sip address and participants.
|
||||
}
|
||||
// TODO.
|
||||
continue;
|
||||
|
||||
if (!chatRoom)
|
||||
continue; // Not fetched.
|
||||
|
||||
chatRooms.push_back(chatRoom);
|
||||
}
|
||||
|
||||
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Conference)) {
|
||||
// TODO.
|
||||
}
|
||||
L_END_LOG_EXCEPTION
|
||||
|
||||
return chatRooms;
|
||||
}
|
||||
|
||||
L_END_LOG_EXCEPTION
|
||||
void MainDb::insertChatRoom (const string &peerAddress, int capabilities) {
|
||||
L_D();
|
||||
d->insertChatRoom(d->insertSipAddress(peerAddress), capabilities, Utils::getLongAsTm(0));
|
||||
}
|
||||
|
||||
return chatRooms;
|
||||
}
|
||||
void MainDb::deleteChatRoom (const std::string &peerAddress) {
|
||||
L_D();
|
||||
|
||||
L_BEGIN_LOG_EXCEPTION
|
||||
|
||||
soci::session *session = d->dbSession.getBackendSession<soci::session>();
|
||||
*session << "DELETE FROM chat_room WHERE peer_sip_address_id IN ("
|
||||
" SELECT id FROM sip_address WHERE value = :peerAddress"
|
||||
")", soci::use(peerAddress);
|
||||
|
||||
L_END_LOG_EXCEPTION
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ChatRoom;
|
||||
class Core;
|
||||
class EventLog;
|
||||
class MainDbPrivate;
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ public:
|
|||
|
||||
typedef int FilterMask;
|
||||
|
||||
MainDb ();
|
||||
MainDb (Core *core);
|
||||
|
||||
// Generic.
|
||||
bool addEvent (const std::shared_ptr<EventLog> &eventLog);
|
||||
|
|
@ -71,6 +72,8 @@ public:
|
|||
|
||||
// ChatRooms.
|
||||
std::list<std::shared_ptr<ChatRoom>> getChatRooms () const;
|
||||
void insertChatRoom (const std::string &peerAddress, int capabilities);
|
||||
void deleteChatRoom (const std::string &peerAddress);
|
||||
|
||||
// Import legacy messages from old db.
|
||||
bool import (Backend backend, const std::string ¶meters) override;
|
||||
|
|
|
|||
|
|
@ -178,4 +178,8 @@ tm Utils::getLongAsTm (long time) {
|
|||
return *gmtime_r(&static_cast<time_t &>(time), &result);
|
||||
}
|
||||
|
||||
long Utils::getTmAsLong (const tm &time) {
|
||||
return timegm(&const_cast<tm &>(time));
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@ static const string getDatabasePath () {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
static void open_database () {
|
||||
MainDb mainDb;
|
||||
MainDb mainDb(nullptr);
|
||||
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
|
||||
}
|
||||
|
||||
static void get_events_count () {
|
||||
MainDb mainDb;
|
||||
MainDb mainDb(nullptr);
|
||||
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
|
||||
BC_ASSERT_EQUAL(mainDb.getEventsCount(), 4976, int, "%d");
|
||||
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceCallFilter), 0, int, "%d");
|
||||
|
|
@ -51,21 +51,21 @@ static void get_events_count () {
|
|||
}
|
||||
|
||||
static void get_messages_count () {
|
||||
MainDb mainDb;
|
||||
MainDb mainDb(nullptr);
|
||||
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
|
||||
BC_ASSERT_EQUAL(mainDb.getMessagesCount(), 4976, int, "%d");
|
||||
BC_ASSERT_EQUAL(mainDb.getMessagesCount("sip:test-39@sip.linphone.org"), 3, int, "%d");
|
||||
}
|
||||
|
||||
static void get_unread_messages_count () {
|
||||
MainDb mainDb;
|
||||
MainDb mainDb(nullptr);
|
||||
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
|
||||
BC_ASSERT_EQUAL(mainDb.getUnreadMessagesCount(), 2, int, "%d");
|
||||
BC_ASSERT_EQUAL(mainDb.getUnreadMessagesCount("sip:test-39@sip.linphone.org"), 0, int, "%d");
|
||||
}
|
||||
|
||||
static void get_history () {
|
||||
MainDb mainDb;
|
||||
MainDb mainDb(nullptr);
|
||||
BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
|
||||
BC_ASSERT_EQUAL(
|
||||
mainDb.getHistoryRange("sip:test-39@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue