1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of Liblinphone
* (see https://gitlab.linphone.org/BC/public/liblinphone).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bctoolbox/defs.h"
#include "belle-sip/belle-sip.h"
#include "linphone/core.h"
#include "linphone/lpconfig.h"
#include "linphone/wrapper_utils.h"
#include "private.h"
#include <linphone/utils/utils.h>
#include "c-wrapper/c-wrapper.h"
#include "call/call.h"
#include "chat/chat-room/abstract-chat-room-p.h"
#include "chat/chat-room/basic-chat-room.h"
#include "chat/chat-room/chat-room-params.h"
#ifdef HAVE_ADVANCED_IM
#include "chat/chat-room/client-group-chat-room.h"
#include "chat/chat-room/client-group-to-basic-chat-room.h"
#endif
#include "content/content-type.h"
#include "core/core-p.h"
#include "linphone/api/c-chat-room-params.h"
using namespace std;
void linphone_core_disable_chat(LinphoneCore *lc, LinphoneReason deny_reason) {
lc->chat_deny_code = deny_reason;
}
void linphone_core_enable_chat(LinphoneCore *lc) {
lc->chat_deny_code = LinphoneReasonNone;
}
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) {
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(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getChatRooms());
return lc->chat_rooms;
}
LinphoneChatRoom *linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject, bool_t fallback) {
return linphone_core_create_client_group_chat_room_2(lc, subject, fallback, FALSE);
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_client_group_chat_room_2(LinphoneCore *lc,
const char *subject,
bool_t fallback,
bool_t encrypted) {
return L_GET_C_BACK_PTR(
L_GET_PRIVATE_FROM_C_OBJECT(lc)->createClientGroupChatRoom(L_C_TO_STRING(subject), !!fallback, !!encrypted));
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room(LinphoneCore *lc,
const LinphoneChatRoomParams *params,
const LinphoneAddress *localAddr,
const char *subject,
const bctbx_list_t *participants) {
LinphoneChatRoomParams *params2 = linphone_chat_room_params_clone(params);
linphone_chat_room_params_set_subject(params2, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params2, localAddr, participants);
linphone_chat_room_params_unref(params2);
return result;
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_2(LinphoneCore *lc,
const LinphoneChatRoomParams *params,
const char *subject,
const bctbx_list_t *participants) {
LinphoneChatRoomParams *params2 = linphone_chat_room_params_clone(params);
linphone_chat_room_params_set_subject(params2, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params2, NULL, participants);
linphone_chat_room_params_unref(params2);
return result;
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *
linphone_core_create_chat_room_3(LinphoneCore *lc, const char *subject, const bctbx_list_t *participants) {
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
linphone_chat_room_params_set_subject(params, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, NULL, participants);
linphone_chat_room_params_unref(params);
return result;
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_4(LinphoneCore *lc,
const LinphoneChatRoomParams *params,
const LinphoneAddress *localAddr,
const LinphoneAddress *participant) {
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, localAddr, paricipants);
bctbx_list_free(paricipants);
return result;
}
// Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_5(LinphoneCore *lc, const LinphoneAddress *participant) {
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant);
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, NULL, paricipants);
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
LinphoneChatRoom *linphone_core_create_chat_room_6(LinphoneCore *lc,
const LinphoneChatRoomParams *params,
const LinphoneAddress *localAddr,
const bctbx_list_t *participants) {
shared_ptr<LinphonePrivate::ChatRoomParams> chatRoomParams =
params ? LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr() : nullptr;
// If a participant has an invalid address, the pointer to its address is NULL.
// For the purpose of building an std::list from a bctbx_list_t, replace it by an empty Address (that is invalid)
const list<std::shared_ptr<LinphonePrivate::Address>> participantsList =
LinphonePrivate::Address::getCppListFromCList(participants);
bool withGruu = chatRoomParams ? chatRoomParams->getChatRoomBackend() ==
LinphonePrivate::ChatRoomParams::ChatRoomBackend::FlexisipChat
: false;
shared_ptr<const LinphonePrivate::Address> identityAddress =
localAddr ? LinphonePrivate::Address::toCpp(localAddr)->getSharedFromThis()
: L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
shared_ptr<LinphonePrivate::AbstractChatRoom> room =
L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(chatRoomParams, identityAddress, participantsList);
if (room) {
auto cRoom = L_GET_C_BACK_PTR(room);
linphone_chat_room_ref(cRoom);
return cRoom;
}
return NULL;
}
LinphoneChatRoom *linphone_core_search_chat_room(const LinphoneCore *lc,
const LinphoneChatRoomParams *params,
const LinphoneAddress *localAddr,
const LinphoneAddress *remoteAddr,
const bctbx_list_t *participants) {
shared_ptr<LinphonePrivate::ChatRoomParams> chatRoomParams =
params ? LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr() : nullptr;
const list<std::shared_ptr<LinphonePrivate::Address>> participantsList =
LinphonePrivate::Address::getCppListFromCList(participants);
bool withGruu = chatRoomParams ? chatRoomParams->getChatRoomBackend() ==
LinphonePrivate::ChatRoomParams::ChatRoomBackend::FlexisipChat
: false;
shared_ptr<const LinphonePrivate::Address> identityAddress =
localAddr ? LinphonePrivate::Address::toCpp(localAddr)->getSharedFromThis()
: L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
shared_ptr<const LinphonePrivate::Address> remoteAddress =
remoteAddr ? LinphonePrivate::Address::toCpp(remoteAddr)->getSharedFromThis() : nullptr;
shared_ptr<LinphonePrivate::AbstractChatRoom> room = L_GET_PRIVATE_FROM_C_OBJECT(lc)->searchChatRoom(
chatRoomParams, identityAddress, remoteAddress, participantsList);
if (room) return L_GET_C_BACK_PTR(room);
return NULL;
}
LinphoneChatRoomParams *linphone_core_create_default_chat_room_params(LinphoneCore *lc) {
auto params = LinphonePrivate::ChatRoomParams::getDefaults(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getSharedFromThis());
params->ref();
return params->toC();
}
static LinphoneChatRoomParams *_linphone_core_create_default_chat_room_params() {
auto params = LinphonePrivate::ChatRoomParams::getDefaults();
params->ref();
return params->toC();
}
LinphoneChatRoom *_linphone_core_create_server_group_chat_room(LinphoneCore *lc, LinphonePrivate::SalCallOp *op) {
return _linphone_server_group_chat_room_new(lc, op);
}
void linphone_core_delete_chat_room(LinphoneCore *, LinphoneChatRoom *cr) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->deleteFromDb();
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *peerAddr) {
return linphone_core_get_chat_room_2(lc, peerAddr, NULL);
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *
linphone_core_get_chat_room_2(LinphoneCore *lc, const LinphoneAddress *peer_addr, const LinphoneAddress *local_addr) {
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, NULL, local_addr, peer_addr, NULL);
if (result == NULL) {
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)peer_addr);
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendBasic);
linphone_chat_room_params_enable_group(params, FALSE);
result = linphone_core_create_chat_room_6(lc, params, local_addr, paricipants);
if (result) linphone_chat_room_unref(result);
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
}
return result;
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
LinphoneAddress *addr = linphone_core_interpret_url(lc, to);
LinphoneChatRoom *room = linphone_core_get_chat_room(lc, addr);
if (addr) linphone_address_unref(addr);
return room;
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_chat_room(const LinphoneCore *lc,
const LinphoneAddress *peer_addr,
const LinphoneAddress *local_addr) {
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, NULL, local_addr, peer_addr, NULL);
return result;
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_one_to_one_chat_room(const LinphoneCore *lc,
const LinphoneAddress *local_addr,
const LinphoneAddress *participant_addr) {
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant_addr);
LinphoneChatRoomParams *params = _linphone_core_create_default_chat_room_params();
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendFlexisipChat);
linphone_chat_room_params_enable_group(params, FALSE);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, params, local_addr, NULL, paricipants);
if (!result) {
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendBasic);
result = linphone_core_search_chat_room(lc, params, local_addr, participant_addr, NULL);
}
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
// Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_one_to_one_chat_room_2(const LinphoneCore *lc,
const LinphoneAddress *local_addr,
const LinphoneAddress *participant_addr,
bool_t encrypted) {
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant_addr);
LinphoneChatRoomParams *params = _linphone_core_create_default_chat_room_params();
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendFlexisipChat);
linphone_chat_room_params_enable_group(params, FALSE);
linphone_chat_room_params_enable_encryption(params, encrypted);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, params, local_addr, NULL, paricipants);
if (!result && !encrypted) {
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendBasic);
result = linphone_core_search_chat_room(lc, params, local_addr, participant_addr, NULL);
}
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
LinphoneReason linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(lc)->onSipMessageReceived(op, sal_msg);
}
unsigned int linphone_chat_message_store(BCTBX_UNUSED(LinphoneChatMessage *msg)) {
// DO nothing, just for old JNI compat...
return 1;
}
|