File: tester_utils.cpp

package info (click to toggle)
linphone 5.3.105-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 57,048 kB
  • sloc: cpp: 166,867; ansic: 102,939; python: 8,280; java: 4,406; sh: 1,040; xml: 1,023; makefile: 777; perl: 377; objc: 190; php: 88; javascript: 38; cs: 38
file content (332 lines) | stat: -rw-r--r-- 12,254 bytes parent folder | download | duplicates (2)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
 * 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/>.
 */

#ifdef WIN32
#pragma push_macro("_WINSOCKAPI_")
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif // _WINSOCKAPI_
#include <windows.h>
#include <winsock2.h>
#endif
#include "private.h"
#include "tester_utils.h"

#include "c-wrapper/c-wrapper.h"
#include "call/call.h"
#include "chat/chat-room/chat-room-p.h"
#include "chat/chat-room/client-group-chat-room-p.h"
#include "chat/encryption/encryption-engine.h"
#include "conference/session/media-session-p.h"
#include "core/core-p.h"
#include "event-log/conference/conference-chat-message-event.h"
#include "mediastreamer2/msanalysedisplay.h"

using namespace std;

using namespace LinphonePrivate;

LinphoneVcardContext *linphone_core_get_vcard_context(const LinphoneCore *lc) {
	return lc->vcard_context;
}

void linphone_core_set_zrtp_not_available_simulation(LinphoneCore *lc, bool_t enabled) {
	lc->zrtp_not_available_simulation = enabled;
}

void linphone_core_lime_x3dh_set_test_decryption_failure_flag(const LinphoneCore *lc, bool_t flag) {
	L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getEncryptionEngine()->setTestForceDecryptionFailureFlag((flag == TRUE));
}

belle_http_provider_t *linphone_core_get_http_provider(const LinphoneCore *lc) {
	return lc->http_provider;
}

void linphone_core_enable_send_call_stats_periodical_updates(LinphoneCore *lc, bool_t enabled) {
	lc->send_call_stats_periodical_updates = enabled;
}

void linphone_core_set_zrtp_cache_db(LinphoneCore *lc, sqlite3 *cache_db) {
	lc->zrtp_cache_db = cache_db;
}

LinphoneCoreCbs *linphone_core_get_first_callbacks(const LinphoneCore *lc) {
	return ((VTableReference *)lc->vtable_refs->data)->cbs;
}

bctbx_list_t **linphone_core_get_call_logs_attribute(LinphoneCore *lc) {
	return &lc->call_logs;
}

void linphone_core_cbs_set_auth_info_requested(LinphoneCoreCbs *cbs, LinphoneCoreAuthInfoRequestedCb cb) {
	cbs->vtable->auth_info_requested = cb;
}

reporting_session_report_t **linphone_quality_reporting_get_reports(LinphoneQualityReporting *qreporting) {
	return &qreporting->reports[0];
}

const bctbx_list_t *linphone_friend_get_insubs(const LinphoneFriend *fr) {
	return fr->insubs;
}

int linphone_friend_list_get_expected_notification_version(const LinphoneFriendList *list) {
	return list->expected_notification_version;
}

unsigned int linphone_friend_list_get_storage_id(const LinphoneFriendList *list) {
	return list->storage_id;
}

unsigned int linphone_friend_get_storage_id(const LinphoneFriend *lf) {
	return lf->storage_id;
}

void linphone_friend_set_core(LinphoneFriend *lf, LinphoneCore *lc) {
	lf->lc = lc;
}

LinphoneFriendList *linphone_friend_get_friend_list(const LinphoneFriend *lf) {
	return lf->friend_list;
}

bctbx_list_t **linphone_friend_list_get_friends_attribute(LinphoneFriendList *lfl) {
	return &lfl->friends;
}

const bctbx_list_t *linphone_friend_list_get_dirty_friends_to_update(const LinphoneFriendList *lfl) {
	return lfl->dirty_friends_to_update;
}

int linphone_friend_list_get_revision(const LinphoneFriendList *lfl) {
	return lfl->revision;
}

unsigned int _linphone_call_get_nb_audio_starts(const LinphoneCall *call) {
	const LinphoneStreamInternalStats *st = _linphone_call_get_stream_internal_stats(call, LinphoneStreamTypeAudio);
	return st ? st->number_of_starts : 0;
}

unsigned int _linphone_call_get_nb_audio_stops(const LinphoneCall *call) {
	const LinphoneStreamInternalStats *st = _linphone_call_get_stream_internal_stats(call, LinphoneStreamTypeAudio);
	return st ? st->number_of_stops : 0;
}

unsigned int _linphone_call_get_nb_video_starts(const LinphoneCall *call) {
	const LinphoneStreamInternalStats *st = _linphone_call_get_stream_internal_stats(call, LinphoneStreamTypeVideo);
	return st ? st->number_of_starts : 0;
}

unsigned int _linphone_call_get_nb_text_starts(const LinphoneCall *call) {
	const LinphoneStreamInternalStats *st = _linphone_call_get_stream_internal_stats(call, LinphoneStreamTypeText);
	return st ? st->number_of_starts : 0;
}

const LinphoneStreamInternalStats *_linphone_call_get_stream_internal_stats(const LinphoneCall *call,
                                                                            LinphoneStreamType stream_type) {
	return Call::toCpp(call)->getStreamInternalStats(stream_type);
}

belle_sip_source_t *_linphone_call_get_dtmf_timer(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->getDtmfTimer();
}

bool_t _linphone_call_has_dtmf_sequence(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	               ->getDtmfSequence()
	               .empty()
	           ? FALSE
	           : TRUE;
}

SalMediaDescription *_linphone_call_get_local_desc(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->getLocalDesc()
	    .get();
}

SalMediaDescription *_linphone_call_get_remote_desc(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->getRemoteDesc()
	    .get();
}

SalMediaDescription *_linphone_call_get_result_desc(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->getResultDesc()
	    .get();
}

MSWebCam *_linphone_call_get_video_device(const LinphoneCall *call) {
	return L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->getVideoDevice();
}

void _linphone_call_add_local_desc_changed_flag(LinphoneCall *call, int flag) {
	L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::MediaSession>(Call::toCpp(call)->getActiveSession()))
	    ->addLocalDescChangedFlag(flag);
}

int _linphone_call_get_main_audio_stream_index(const LinphoneCall *call) {
	return Call::toCpp(call)->getMediaStreamIndex(LinphoneStreamTypeAudio);
}

int _linphone_call_get_main_text_stream_index(const LinphoneCall *call) {
	return Call::toCpp(call)->getMediaStreamIndex(LinphoneStreamTypeText);
}

int _linphone_call_get_main_video_stream_index(const LinphoneCall *call) {
	return Call::toCpp(call)->getMediaStreamIndex(LinphoneStreamTypeVideo);
}

void _linphone_chat_room_enable_migration(LinphoneChatRoom *cr, bool_t enable) {
	shared_ptr<AbstractChatRoom> acr = L_GET_CPP_PTR_FROM_C_OBJECT(cr);
	L_GET_PRIVATE(acr->getCore())->mainDb->enableChatRoomMigration(acr->getConferenceId(), !!enable);
}

int _linphone_chat_room_get_transient_message_count(const LinphoneChatRoom *cr) {
	shared_ptr<const ChatRoom> chatRoom = static_pointer_cast<const ChatRoom>(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
	return (int)L_GET_PRIVATE(chatRoom)->transientEvents.size();
}

LinphoneChatMessage *_linphone_chat_room_get_first_transient_message(const LinphoneChatRoom *cr) {
	shared_ptr<const ChatRoom> chatRoom = static_pointer_cast<const ChatRoom>(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
	if (L_GET_PRIVATE(chatRoom)->transientEvents.empty()) return nullptr;
	shared_ptr<ConferenceChatMessageEvent> event =
	    static_pointer_cast<ConferenceChatMessageEvent>(L_GET_PRIVATE(chatRoom)->transientEvents.front());
	return L_GET_C_BACK_PTR(event->getChatMessage());
}

char *linphone_core_get_device_identity(LinphoneCore *lc) {
	char *identity = NULL;
	LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(lc);
	if (proxy) {
		const LinphoneAddress *contactAddr = linphone_proxy_config_get_contact(proxy);
		if (contactAddr) identity = linphone_address_as_string(contactAddr);
		else identity = bctbx_strdup(linphone_proxy_config_get_identity(proxy));
	} else {
		identity = bctbx_strdup(linphone_core_get_primary_contact(lc));
	}
	return identity;
}

const LinphoneCoreToneManagerStats *linphone_core_get_tone_manager_stats(LinphoneCore *lc) {
	return L_GET_PRIVATE_FROM_C_OBJECT(lc)->getToneManager().getStats();
}

void linphone_core_reset_tone_manager_stats(LinphoneCore *lc) {
	L_GET_PRIVATE_FROM_C_OBJECT(lc)->getToneManager().resetStats();
}

const char *linphone_core_get_tone_file(LinphoneCore *lc, LinphoneToneID id) {
	LinphoneToneDescription *tone = L_GET_PRIVATE_FROM_C_OBJECT(lc)->getToneManager().getTone(id);
	return tone ? tone->audiofile : NULL;
}

void linphone_core_reset_shared_core_state(LinphoneCore *lc) {
	static_cast<PlatformHelpers *>(lc->platform_helper)->getSharedCoreHelpers()->resetSharedCoreState();
}

char *linphone_core_get_download_path(LinphoneCore *lc) {
	return bctbx_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getDownloadPath().c_str());
}

size_t linphone_chat_room_get_previouses_conference_ids_count(LinphoneChatRoom *cr) {
	auto abstract = L_GET_CPP_PTR_FROM_C_OBJECT(cr);

	return L_GET_PRIVATE(static_pointer_cast<ClientGroupChatRoom>(abstract))->getPreviousConferenceIds().size();
}

bool_t linphone_call_check_rtp_sessions(LinphoneCall *call) {
	std::shared_ptr<LinphonePrivate::MediaSession> ms = Call::toCpp(call)->getMediaSession();
	if (ms) {
		StreamsGroup &sg = L_GET_PRIVATE(ms)->getStreamsGroup();
		for (auto &stream : sg.getStreams()) {
			if (!stream) continue;
			MS2Stream *s = dynamic_cast<MS2Stream *>(stream.get());
			if (stream->getType() == SalVideo) {
				MediaStream *ms = s->getMediaStream();
				RtpSession *rtp_session = ms->sessions.rtp_session;
				if (!rtp_session) {
					lInfo() << "checkRtpSession(): session empty";
					return false;
				}
				const rtp_stats_t *rtps = rtp_session_get_stats(rtp_session);
				switch (media_stream_get_direction(ms)) {
					case MediaStreamRecvOnly:
						// Can be 0 if it's not attached with filter
						break;
					case MediaStreamSendOnly:
						if (rtps->packet_sent < 5) {
							return false;
						}
						break;
					case MediaStreamSendRecv:
						if (rtps->packet_recv < 5 || rtps->packet_sent < 5) {
							return false;
						}
						break;
					default:
						break;
				}
			}
		}
		return true;
	}
	return false;
}

void linphone_core_set_answer_with_own_numbering_policy(LinphoneCore *lc, bool_t value) {
	auto sal = lc->sal;
	sal->getOfferAnswerEngine().setAnswerWithOwnNumberingPolicy(!!value);
}

#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif // _MSC_VER
bool_t linphone_call_compare_video_color(LinphoneCall *call, MSMireControl cl, MediaStreamDir dir, const char *label) {
#ifdef VIDEO_ENABLED
	auto lambda = [](Stream *s, MediaStreamDir dir, const string &label, MSMireControl cl) {
		if (s->getType() == SalVideo && (label.empty() || label.compare(s->getLabel()) == 0)) {
			MS2VideoStream *vs = dynamic_cast<MS2VideoStream *>(s);
			if (vs && media_stream_get_direction(vs->getMediaStream()) == dir && vs->getVideoStream()->output &&
			    ms_filter_get_id(vs->getVideoStream()->output) == MS_ANALYSE_DISPLAY_ID) {
				return ms_filter_call_method(vs->getVideoStream()->output, MS_ANALYSE_DISPLAY_COMPARE_COLOR, &cl) == 0;
			}
		}
		return false;
	};
	std::shared_ptr<LinphonePrivate::MediaSession> ms = Call::toCpp(call)->getMediaSession();
	if (ms) {
		StreamsGroup &sg = L_GET_PRIVATE(ms)->getStreamsGroup();
		if (sg.lookupStream(lambda, dir, label, cl)) return true;
	}
#endif
	return false;
}
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif // _MSC_VER

int linphone_core_get_number_of_duplicated_messages(const LinphoneCore *core) {
	return core->number_of_duplicated_messages;
}