Ring Daemon 16.0.0
Loading...
Searching...
No Matches
configurationmanager.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
23#include "account_schema.h"
24#include "manager.h"
25#include "logger.h"
26#include "fileutils.h"
27#include "archiver.h"
28#include "sip/sipaccount.h"
29#include "jamidht/jamiaccount.h"
32#include "audio/audiolayer.h"
34#include "account_const.h"
35#include "client/ring_signal.h"
38
39#include <dhtnet/ip_utils.h>
40#include <dhtnet/upnp/upnp_context.h>
41#include <dhtnet/certstore.h>
42
43#include <regex>
44
45#ifdef __APPLE__
46#include <TargetConditionals.h>
47#endif
48
49#ifdef _MSC_VER
50#include "windirent.h"
51#else
52#include <dirent.h>
53#endif
54
55#include <cerrno>
56#include <cstring>
57#include <sstream>
58
59#ifdef _WIN32
60#undef interface
61#endif
62
63#include <string_view>
64
65namespace libjami {
66
67constexpr unsigned CODECS_NOT_LOADED = 0x1000;
73
74void
75registerConfHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers)
76{
77 registerSignalHandlers(handlers);
78}
79
80std::map<std::string, std::string>
81getAccountDetails(const std::string& accountId)
82{
84}
85
86std::map<std::string, std::string>
87getVolatileAccountDetails(const std::string& accountId)
88{
90}
91
92std::map<std::string, std::string>
93validateCertificate(const std::string& accountId, const std::string& certificate)
94{
95 try {
96 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
97 return TlsValidator {acc->certStore(), acc->certStore().getCertificate(certificate)}
98 .getSerializedChecks();
99 } catch (const std::runtime_error& e) {
100 JAMI_WARN("Certificate loading failed: %s", e.what());
101 }
103}
104
105std::map<std::string, std::string>
106validateCertificatePath(const std::string& accountId,
107 const std::string& certificate,
108 const std::string& privateKey,
109 const std::string& privateKeyPass,
110 const std::string& caList)
111{
112 try {
113 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
114 return TlsValidator {acc->certStore(), certificate, privateKey, privateKeyPass, caList}
116 } catch (const std::runtime_error& e) {
117 JAMI_WARN("Certificate loading failed: %s", e.what());
119 }
120 return {};
121}
122
123std::map<std::string, std::string>
124getCertificateDetails(const std::string& accountId, const std::string& certificate)
125{
126 try {
127 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
128 return TlsValidator {acc->certStore(), acc->certStore().getCertificate(certificate)}
129 .getSerializedDetails();
130 } catch (const std::runtime_error& e) {
131 JAMI_WARN("Certificate loading failed: %s", e.what());
132 }
133 return {};
134}
135
136std::map<std::string, std::string>
137getCertificateDetailsPath(const std::string& accountId,
138 const std::string& certificate,
139 const std::string& privateKey,
140 const std::string& privateKeyPassword)
141{
142 try {
143 auto crt = std::make_shared<dht::crypto::Certificate>(
144 jami::fileutils::loadFile(certificate));
145 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
146 TlsValidator validator {acc->certStore(), certificate, privateKey, privateKeyPassword};
147 acc->certStore().pinCertificate(validator.getCertificate(), false);
148 return validator.getSerializedDetails();
149 }
150 } catch (const std::runtime_error& e) {
151 JAMI_WARN("Certificate loading failed: %s", e.what());
152 }
153 return {};
154}
155
156std::vector<std::string>
157getPinnedCertificates(const std::string& accountId)
158{
159 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
160 return acc->certStore().getPinnedCertificates();
161 return {};
162}
163
164std::vector<std::string>
165pinCertificate(const std::string& accountId, const std::vector<uint8_t>& certificate, bool local)
166{
167 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
168 return acc->certStore().pinCertificate(certificate, local);
169 return {};
170}
171
172void
173pinCertificatePath(const std::string& accountId, const std::string& path)
174{
175 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
176 acc->certStore().pinCertificatePath(path);
177}
178
179bool
180unpinCertificate(const std::string& accountId, const std::string& certId)
181{
182 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
183 return acc->certStore().unpinCertificate(certId);
184 return {};
185}
186
187unsigned
188unpinCertificatePath(const std::string& accountId, const std::string& path)
189{
190 if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
191 return acc->certStore().unpinCertificatePath(path);
192 return {};
193}
194
195bool
196pinRemoteCertificate(const std::string& accountId, const std::string& certId)
197{
198 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
199 acc->dht()->findCertificate(dht::InfoHash(certId),
200 [](const std::shared_ptr<dht::crypto::Certificate>& crt) {});
201 return true;
202 }
203 return false;
204}
205
206bool
207setCertificateStatus(const std::string& accountId,
208 const std::string& certId,
209 const std::string& ststr)
210{
211 try {
212 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
213 auto status = dhtnet::tls::TrustStore::statusFromStr(ststr.c_str());
214 return acc->setCertificateStatus(certId, status);
215 }
216 } catch (const std::out_of_range&) {
217 }
218 return false;
219}
220
221std::vector<std::string>
222getCertificatesByStatus(const std::string& accountId, const std::string& ststr)
223{
224 auto status = dhtnet::tls::TrustStore::statusFromStr(ststr.c_str());
225 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
226 return acc->getCertificatesByStatus(status);
227 return {};
228}
229
230void
231setAccountDetails(const std::string& accountId, const std::map<std::string, std::string>& details)
232{
233 jami::Manager::instance().setAccountDetails(accountId, details);
234}
235
236void
237setAccountActive(const std::string& accountId, bool enable, bool shutdownConnections)
238{
239 jami::Manager::instance().setAccountActive(accountId, enable, shutdownConnections);
240}
241
242void
243loadAccountAndConversation(const std::string& accountId, bool loadAll, const std::string& convId)
244{
245 jami::Manager::instance().loadAccountAndConversation(accountId, loadAll, convId);
246}
247
248void
249sendRegister(const std::string& accountId, bool enable)
250{
251 jami::Manager::instance().sendRegister(accountId, enable);
252}
253
254bool
255isPasswordValid(const std::string& accountId, const std::string& password)
256{
257 if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountId))
258 return acc->isPasswordValid(password);
259 return false;
260}
261
262std::vector<uint8_t>
263getPasswordKey(const std::string& accountID, const std::string& password)
264{
265 if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountID))
266 return acc->getPasswordKey(password);
267 return {};
268}
269
270void
275
276uint64_t
277sendAccountTextMessage(const std::string& accountId,
278 const std::string& to,
279 const std::map<std::string, std::string>& payloads,
280 int32_t flags)
281{
282 bool onlyConnected = flags & 0x1;
283 return jami::Manager::instance().sendTextMessage(accountId, to, payloads, onlyConnected);
284}
285
286std::vector<Message>
287getLastMessages(const std::string& accountId, const uint64_t& base_timestamp)
288{
289 if (const auto acc = jami::Manager::instance().getAccount(accountId))
290 return acc->getLastMessages(base_timestamp);
291 return {};
292}
293
294std::map<std::string, std::string>
295getNearbyPeers(const std::string& accountId)
296{
297 return jami::Manager::instance().getNearbyPeers(accountId);
298}
299
300void
301updateProfile(const std::string& accountId,
302 const std::string& displayName,
303 const std::string& avatar,
304 const std::string& fileType,
305 int32_t flag)
306{
307 if (const auto acc = jami::Manager::instance().getAccount(accountId)) {
308 acc->updateProfile(displayName, avatar, fileType, flag);
309 }
310}
311
312int
313getMessageStatus(uint64_t messageId)
314{
315 return jami::Manager::instance().getMessageStatus(messageId);
316}
317
318int
319getMessageStatus(const std::string& accountId, uint64_t messageId)
320{
321 return jami::Manager::instance().getMessageStatus(accountId, messageId);
322}
323
324bool
325cancelMessage(const std::string& accountId, uint64_t messageId)
326{
327 return {};
328}
329
330void
331setIsComposing(const std::string& accountId, const std::string& conversationUri, bool isWriting)
332{
333 if (const auto acc = jami::Manager::instance().getAccount(accountId))
334 acc->setIsComposing(conversationUri, isWriting);
335}
336
337bool
338setMessageDisplayed(const std::string& accountId,
339 const std::string& conversationUri,
340 const std::string& messageId,
341 int status)
342{
343 if (const auto acc = jami::Manager::instance().getAccount(accountId))
344 return acc->setMessageDisplayed(conversationUri, messageId, status);
345 return false;
346}
347
348int32_t
349addDevice(const std::string& accountId, const std::string& uri)
350{
351 JAMI_DEBUG("[LinkDevice {}] exportToPeer called.", accountId);
352 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
353 return account->addDevice(uri);
354 }
355 return static_cast<int32_t>(jami::AccountManager::AddDeviceError::GENERIC);
356}
357
358bool
359confirmAddDevice(const std::string& accountId, uint32_t op_id)
360{
361 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
362 return account->confirmAddDevice(op_id);
363 }
364 return false;
365}
366
367bool
368cancelAddDevice(const std::string& accountId, uint32_t op_id)
369{
370 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
371 return account->cancelAddDevice(op_id);
372 }
373 return false;
374}
375
376bool
377provideAccountAuthentication(const std::string& accountId,
378 const std::string& credentialsFromUser,
379 const std::string& scheme)
380{
381 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
382 // send the password to the channel for communicationg with the old device
383 account->provideAccountAuthentication(credentialsFromUser, scheme);
384 return true;
385 }
386 return false;
387}
388
389bool
390exportToFile(const std::string& accountId,
391 const std::string& destinationPath,
392 const std::string& scheme,
393 const std::string& password)
394{
395 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
396 return account->exportArchive(destinationPath, scheme, password);
397 }
398 return false;
399}
400
401bool
402revokeDevice(const std::string& accountId,
403 const std::string& deviceId,
404 const std::string& scheme,
405 const std::string& password)
406{
407 if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
408 return account->revokeDevice(deviceId, scheme, password);
409 }
410 return false;
411}
412
413std::map<std::string, std::string>
414getKnownRingDevices(const std::string& accountId)
415{
416 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
417 return acc->getKnownDevices();
418 return {};
419}
420
421bool
422changeAccountPassword(const std::string& accountId,
423 const std::string& password_old,
424 const std::string& password_new)
425{
426 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
427 return acc->changeArchivePassword(password_old, password_new);
428 return false;
429}
430
431/* contacts */
432
433void
434addContact(const std::string& accountId, const std::string& uri)
435{
436 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
437 return acc->addContact(uri);
438}
439
440void
441removeContact(const std::string& accountId, const std::string& uri, bool ban)
442{
443 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
444 return acc->removeContact(uri, ban);
445}
446
447std::map<std::string, std::string>
448getContactDetails(const std::string& accountId, const std::string& uri)
449{
450 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
451 return acc->getContactDetails(uri);
452 return {};
453}
454
455std::vector<std::map<std::string, std::string>>
456getContacts(const std::string& accountId)
457{
458 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
459 return acc->getContacts();
460 return {};
461}
462
463/* contact requests */
464std::vector<std::map<std::string, std::string>>
465getTrustRequests(const std::string& accountId)
466{
467 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
468 return acc->getTrustRequests();
469 return {};
470}
471
472bool
473acceptTrustRequest(const std::string& accountId, const std::string& from)
474{
475 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
476 return acc->acceptTrustRequest(from);
477 return false;
478}
479
480bool
481discardTrustRequest(const std::string& accountId, const std::string& from)
482{
483 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
484 return acc->discardTrustRequest(from);
485 return false;
486}
487
488void
489sendTrustRequest(const std::string& accountId,
490 const std::string& to,
491 const std::vector<uint8_t>& payload)
492{
493 if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
494 acc->sendTrustRequest(to, payload);
495}
496
498std::map<std::string, std::string>
499getAccountTemplate(const std::string& accountType)
500{
501 if (accountType == Account::ProtocolNames::RING)
503 else if (accountType == Account::ProtocolNames::SIP)
504 return jami::SipAccountConfig().toMap();
505 return {};
506}
507
508std::string
509addAccount(const std::map<std::string, std::string>& details, const std::string& accountId)
510{
511 return jami::Manager::instance().addAccount(details, accountId);
512}
513
514void
515monitor(bool continuous)
516{
517 return jami::Manager::instance().monitor(continuous);
518}
519
520std::vector<std::map<std::string, std::string>>
521getConnectionList(const std::string& accountId, const std::string& conversationId)
522{
523 return jami::Manager::instance().getConnectionList(accountId, conversationId);
524}
525
526std::vector<std::map<std::string, std::string>>
527getChannelList(const std::string& accountId, const std::string& connectionId)
528{
529 return jami::Manager::instance().getChannelList(accountId, connectionId);
530}
531
532void
533removeAccount(const std::string& accountId)
534{
535 return jami::Manager::instance().removeAccount(accountId, true); // with 'flush' enabled
536}
537
538std::vector<std::string>
543
548std::vector<unsigned>
550{
551 std::vector<unsigned> list {
552 jami::getSystemCodecContainer()->getSystemCodecInfoIdList(jami::MEDIA_ALL)};
553 if (list.empty())
555 return list;
556}
557
558std::vector<std::string>
563
564std::vector<std::string>
565getSupportedCiphers(const std::string& accountId)
566{
567 if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId))
569 JAMI_ERR("SIP account %s doesn't exist", accountId.c_str());
570 return {};
571}
572
573bool
574setCodecDetails(const std::string& accountId,
575 const unsigned& codecId,
576 const std::map<std::string, std::string>& details)
577{
578 auto acc = jami::Manager::instance().getAccount(accountId);
579 if (!acc) {
580 JAMI_ERR("Unable to find account %s. Unable to set codec details", accountId.c_str());
581 return false;
582 }
583
584 auto codec = acc->searchCodecById(codecId, jami::MEDIA_ALL);
585 if (!codec) {
586 JAMI_ERR("Unable to find codec %d", codecId);
587 return false;
588 }
589 try {
590 if (codec->mediaType & jami::MEDIA_AUDIO) {
591 if (auto foundCodec = std::static_pointer_cast<jami::SystemAudioCodecInfo>(codec)) {
592 foundCodec->setCodecSpecifications(details);
594 return true;
595 }
596 }
597
598 if (codec->mediaType & jami::MEDIA_VIDEO) {
599 if (auto foundCodec = std::static_pointer_cast<jami::SystemVideoCodecInfo>(codec)) {
600 foundCodec->setCodecSpecifications(details);
601 JAMI_WARN("parameters for %s changed ", foundCodec->name.c_str());
602 if (auto call = jami::Manager::instance().getCurrentCall()) {
603 if (call->getVideoCodec() == foundCodec) {
604 JAMI_WARN("%s running. Need to restart encoding", foundCodec->name.c_str());
605 call->restartMediaSender();
606 }
607 }
609 return true;
610 }
611 }
612 } catch (const std::exception& e) {
613 JAMI_ERR("Unable to set codec specifications: %s", e.what());
614 }
615
616 return false;
617}
618
619std::map<std::string, std::string>
620getCodecDetails(const std::string& accountId, const unsigned& codecId)
621{
622 auto acc = jami::Manager::instance().getAccount(accountId);
623 if (!acc) {
624 JAMI_ERR("Unable to find account %s return default codec details", accountId.c_str());
626 }
627
628 auto codec = acc->searchCodecById(codecId, jami::MEDIA_ALL);
629 if (!codec) {
631 return {};
632 }
633
634 if (codec->mediaType & jami::MEDIA_AUDIO)
635 if (auto foundCodec = std::static_pointer_cast<jami::SystemAudioCodecInfo>(codec))
636 return foundCodec->getCodecSpecifications();
637
638 if (codec->mediaType & jami::MEDIA_VIDEO)
639 if (auto foundCodec = std::static_pointer_cast<jami::SystemVideoCodecInfo>(codec))
640 return foundCodec->getCodecSpecifications();
641
643 return {};
644}
645
646std::vector<unsigned>
647getActiveCodecList(const std::string& accountId)
648{
649 if (auto acc = jami::Manager::instance().getAccount(accountId))
650 return acc->getActiveCodecs();
651 JAMI_ERR("Unable to find account %s, returning default", accountId.c_str());
653}
654
655void
656setActiveCodecList(const std::string& accountId, const std::vector<unsigned>& list)
657{
658 if (auto acc = jami::Manager::instance().getAccount(accountId)) {
659 acc->setActiveCodecs(list);
661 } else {
662 JAMI_ERR("Unable to find account %s", accountId.c_str());
663 }
664}
665
666std::vector<std::string>
671
672void
673setAudioPlugin(const std::string& audioPlugin)
674{
675 return jami::Manager::instance().setAudioPlugin(audioPlugin);
676}
677
678std::vector<std::string>
683
684std::vector<std::string>
689
690void
692{
693 return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::PLAYBACK);
694}
695
696void
698{
699 return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::CAPTURE);
700}
701
702void
707
708void
710{
711 return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::RINGTONE);
712}
713
714std::vector<std::string>
719
720int32_t
721getAudioInputDeviceIndex(const std::string& name)
722{
724}
725
726int32_t
727getAudioOutputDeviceIndex(const std::string& name)
728{
730}
731
732std::string
734{
736 JAMI_DBG("Get audio plugin %s", plugin.c_str());
737 return plugin;
738}
739
740std::string
745
746void
747setNoiseSuppressState(const std::string& state)
748{
750}
751
752bool
757
758void
759setAgcState(bool enabled)
760{
762}
763
764std::string
769
770void
771setRecordPath(const std::string& recPath)
772{
774}
775
776bool
781
782void
787
788bool
790{
791#ifdef ENABLE_VIDEO
792 return jami::Manager::instance().videoPreferences.getRecordPreview();
793#else
794 return false;
795#endif
796}
797
798void
800{
801#ifdef ENABLE_VIDEO
802 jami::Manager::instance().videoPreferences.setRecordPreview(rec);
804#endif
805}
806
807int32_t
809{
810#ifdef ENABLE_VIDEO
811 return jami::Manager::instance().videoPreferences.getRecordQuality();
812#else
813 return 0;
814#endif
815}
816
817void
818setRecordQuality(int32_t quality)
819{
820#ifdef ENABLE_VIDEO
821 jami::Manager::instance().videoPreferences.setRecordQuality(quality);
823#endif
824}
825
826int32_t
831
832void
833setHistoryLimit(int32_t days)
834{
836}
837
838int32_t
843
844void
845setRingingTimeout(int32_t timeout)
846{
848}
849
850std::vector<std::string>
855
856bool
857setAudioManager(const std::string& api)
858{
860}
861
862std::string
867
868void
869setVolume(const std::string& device, double value)
870{
871 if (auto audiolayer = jami::Manager::instance().getAudioDriver()) {
872 JAMI_DBG("set volume for %s: %f", device.c_str(), value);
873
874 if (device == "speaker")
875 audiolayer->setPlaybackGain(value);
876 else if (device == "mic")
877 audiolayer->setCaptureGain(value);
878
880 } else {
881 JAMI_ERR("Audio layer not valid while updating volume");
882 }
883}
884
885double
886getVolume(const std::string& device)
887{
888 if (auto audiolayer = jami::Manager::instance().getAudioDriver()) {
889 if (device == "speaker")
890 return audiolayer->getPlaybackGain();
891 if (device == "mic")
892 return audiolayer->getCaptureGain();
893 }
894
895 JAMI_ERR("Audio layer not valid while updating volume");
896 return 0.0;
897}
898
899// FIXME: we should store "muteDtmf" instead of "playDtmf"
900// in config and avoid negating like this
901bool
906
907void
908muteDtmf(bool mute)
909{
911}
912
913bool
915{
916 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
917 return audiolayer->isCaptureMuted();
918
919 JAMI_ERR("Audio layer not valid");
920 return false;
921}
922
923void
924muteCapture(bool mute)
925{
926 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
927 return audiolayer->muteCapture(mute);
928
929 JAMI_ERR("Audio layer not valid");
930 return;
931}
932
933bool
935{
936 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
937 return audiolayer->isPlaybackMuted();
938
939 JAMI_ERR("Audio layer not valid");
940 return false;
941}
942
943void
944mutePlayback(bool mute)
945{
946 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
947 return audiolayer->mutePlayback(mute);
948
949 JAMI_ERR("Audio layer not valid");
950 return;
951}
952
953bool
955{
956 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
957 return audiolayer->isRingtoneMuted();
958
959 JAMI_ERR("Audio layer not valid");
960 return false;
961}
962
963void
964muteRingtone(bool mute)
965{
966 if (auto audiolayer = jami::Manager::instance().getAudioDriver())
967 return audiolayer->muteRingtone(mute);
968
969 JAMI_ERR("Audio layer not valid");
970 return;
971}
972
973void
974setAccountsOrder(const std::string& order)
975{
977}
978
979std::string
980getAddrFromInterfaceName(const std::string& interface)
981{
982 return dhtnet::ip_utils::getInterfaceAddr(interface, AF_INET);
983}
984
985std::vector<std::string>
987{
988 return dhtnet::ip_utils::getAllIpInterface();
989}
990
991std::vector<std::string>
993{
994 return dhtnet::ip_utils::getAllIpInterfaceByName();
995}
996
997std::vector<std::map<std::string, std::string>>
998getCredentials(const std::string& accountId)
999{
1000 if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId))
1001 return sipaccount->getCredentials();
1002 return {};
1003}
1004
1005void
1006setCredentials(const std::string& accountId,
1007 const std::vector<std::map<std::string, std::string>>& details)
1008{
1009 if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId)) {
1010 sipaccount->doUnregister();
1011 sipaccount->editConfig(
1012 [&](jami::SipAccountConfig& config) { config.setCredentials(details); });
1013 sipaccount->loadConfig();
1014 if (sipaccount->isEnabled())
1015 sipaccount->doRegister();
1016 jami::Manager::instance().saveConfig(sipaccount);
1017 }
1018}
1019
1020void
1022{
1023 JAMI_WARN("received connectivity changed - attempting to re-connect enabled accounts");
1024
1025 // reset the UPnP context
1026#if !(defined(TARGET_OS_IOS) && TARGET_OS_IOS)
1027 try {
1028 jami::Manager::instance().upnpContext()->connectivityChanged();
1029 } catch (std::runtime_error& e) {
1030 JAMI_ERR("UPnP context error: %s", e.what());
1031 }
1032#endif
1033
1034 for (const auto& account : jami::Manager::instance().getAllAccounts()) {
1035 account->connectivityChanged();
1036 }
1037}
1038
1039bool
1040lookupName(const std::string& account, const std::string& nameserver, const std::string& name)
1041{
1042#if HAVE_RINGNS
1043 if (account.empty()) {
1044 auto cb = [name](const std::string& regName,
1045 const std::string& address,
1048 name,
1049 (int) response,
1050 address,
1051 regName);
1052 };
1053 if (nameserver.empty())
1054 jami::NameDirectory::lookupUri(name, "", cb);
1055 else
1056 jami::NameDirectory::instance(nameserver).lookupName(name, cb);
1057 return true;
1058 } else if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
1059 acc->lookupName(name);
1060 return true;
1061 }
1062#endif
1063 return false;
1064}
1065
1066bool
1067lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address)
1068{
1069#if HAVE_RINGNS
1070 if (account.empty()) {
1072 .lookupAddress(address,
1073 [address](const std::string& regName,
1074 const std::string& addr,
1077 "", address, (int) response, addr, regName);
1078 });
1079 return true;
1080 } else if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
1081 acc->lookupAddress(address);
1082 return true;
1083 }
1084#endif
1085 return false;
1086}
1087
1088bool
1089searchUser(const std::string& account, const std::string& query)
1090{
1091 if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
1092 return acc->searchUser(query);
1093 }
1094 return false;
1095}
1096
1097bool
1098registerName(const std::string& account,
1099 const std::string& name,
1100 const std::string& scheme,
1101 const std::string& password)
1102{
1103#if HAVE_RINGNS
1104 if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
1105 acc->registerName(name, scheme, password);
1106 return true;
1107 }
1108#endif
1109 return false;
1110}
1111
1112void
1113setPushNotificationToken(const std::string& token)
1114{
1115 for (const auto& account : jami::Manager::instance().getAllAccounts()) {
1116 account->setPushNotificationToken(token);
1117 }
1118}
1119
1120void
1121setPushNotificationTopic(const std::string& topic)
1122{
1123 for (const auto& account : jami::Manager::instance().getAllAccounts()) {
1124 account->setPushNotificationTopic(topic);
1125 }
1126}
1127
1128void
1129setPushNotificationConfig(const std::map<std::string, std::string>& data)
1130{
1131 for (const auto& account : jami::Manager::instance().getAllAccounts()) {
1132 account->setPushNotificationConfig(data);
1133 }
1134}
1135
1136void
1137pushNotificationReceived(const std::string& from, const std::map<std::string, std::string>& data)
1138{
1139 try {
1140 auto it = data.find("to");
1141 if (it != data.end()) {
1142 if (auto account = jami::Manager::instance().getAccount<JamiAccount>(it->second))
1143 account->pushNotificationReceived(from, data);
1144 }
1145#if defined(__ANDROID__) || defined(ANDROID) || defined(__Apple__)
1146 else {
1147 for (const auto& sipAccount : jami::Manager::instance().getAllAccounts<SIPAccount>()) {
1148 sipAccount->pushNotificationReceived(from, data);
1149 }
1150 }
1151#endif
1152 } catch (const std::exception& e) {
1153 JAMI_ERR("Error processing push notification: %s", e.what());
1154 }
1155}
1156
1157bool
1158isAudioMeterActive(const std::string& id)
1159{
1161}
1162
1163void
1164setAudioMeterState(const std::string& id, bool state)
1165{
1167}
1168
1169void
1170setDefaultModerator(const std::string& accountId, const std::string& peerURI, bool state)
1171{
1172 jami::Manager::instance().setDefaultModerator(accountId, peerURI, state);
1173}
1174
1175std::vector<std::string>
1176getDefaultModerators(const std::string& accountId)
1177{
1179}
1180
1181void
1182enableLocalModerators(const std::string& accountId, bool isModEnabled)
1183{
1184 jami::Manager::instance().enableLocalModerators(accountId, isModEnabled);
1185}
1186
1187bool
1188isLocalModeratorsEnabled(const std::string& accountId)
1189{
1191}
1192
1193void
1194setAllModerators(const std::string& accountId, bool allModerators)
1195{
1196 jami::Manager::instance().setAllModerators(accountId, allModerators);
1197}
1198
1199bool
1200isAllModerators(const std::string& accountId)
1201{
1202 return jami::Manager::instance().isAllModerators(accountId);
1203}
1204
1205void
1206setResourceDirPath(const std::string& resourceDir)
1207{
1209}
1210
1211} // namespace libjami
Account specific keys/constants that must be shared in daemon and clients.
Main sound class.
#define PCM_DMIX_DSNOOP
Definition audiolayer.h:51
#define PCM_DEFAULT
Definition audiolayer.h:49
static std::vector< unsigned > getDefaultCodecsId()
Definition account.cpp:264
static std::map< std::string, std::string > getDefaultCodecDetails(const unsigned &codecId)
Definition account.cpp:270
bool setRecordPath(const std::string &r)
static std::vector< std::string > getSupportedAudioManagers()
const std::string & getRecordPath() const
Ring Account is build on top of SIPAccountBase and uses DHT to handle call connectivity.
Definition jamiaccount.h:96
void setRingingTimeout(int timeout)
Set ringing timeout (number of seconds after which a call will enter BUSY state if not answered).
Definition manager.cpp:2373
void setAudioDevice(int index, AudioDeviceType streamType)
Set audio device.
Definition manager.cpp:2180
std::map< std::string, std::string > getAccountDetails(const std::string &accountID) const
Retrieve details about a given account.
Definition manager.cpp:2680
void enableLocalModerators(const std::string &accountID, bool state)
Definition manager.cpp:3251
void loadAccountAndConversation(const std::string &accountId, bool loadAll, const std::string &convId)
Definition manager.cpp:2994
std::vector< std::shared_ptr< T > > getAllAccounts() const
Get a list of account pointers of type T (baseclass Account)
Definition manager.h:731
std::vector< std::string > getDefaultModerators(const std::string &accountID)
Definition manager.cpp:3238
std::vector< std::string > getAccountList() const
Get account list.
Definition manager.cpp:2667
bool isLocalModeratorsEnabled(const std::string &accountID)
Definition manager.cpp:3259
void setAccountsOrder(const std::string &order)
Set the account order in the config file.
Definition manager.cpp:2658
void setAllModerators(const std::string &accountID, bool allModerators)
Definition manager.cpp:3270
std::vector< std::map< std::string, std::string > > getConnectionList(const std::string &accountId, const std::string &conversationId)
Definition manager.cpp:958
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:676
void setAccountActive(const std::string &accountID, bool active, bool shutdownConnections)
Definition manager.cpp:2976
void registerAccounts()
Send registration for all enabled accounts.
Definition manager.cpp:2912
std::shared_ptr< dhtnet::upnp::UPnPContext > upnpContext() const
Definition manager.cpp:1718
void setHistoryLimit(int days)
Set the maximum number of days to keep in the history.
Definition manager.cpp:2359
void startAudio()
Definition manager.cpp:2251
std::map< std::string, std::string > getVolatileAccountDetails(const std::string &accountID) const
Retrieve volatile details such as recent registration errors.
Definition manager.cpp:2694
std::shared_ptr< T > getAccount(std::string_view accountId) const
Get an account pointer, looks for account of type T.
Definition manager.h:721
std::vector< std::string > getAudioOutputDeviceList()
Get list of supported audio output device.
Definition manager.cpp:2205
bool getIsAlwaysRecording() const
Get is always recording functionality.
Definition manager.cpp:2286
void setAccountDetails(const std::string &accountID, const std::map< std::string, std::string > &details)
Save the details of an existing account, given the account ID This will load the configuration map wi...
Definition manager.cpp:2708
std::string addAccount(const std::map< std::string, std::string > &details, const std::string &accountId={})
Add a new account, and give it a new account ID automatically.
Definition manager.cpp:2754
void saveConfig()
Save config to file.
Definition manager.cpp:1751
void setNoiseSuppressState(const std::string &state)
Set the noise reduction engine state in the current audio layer.
Definition manager.cpp:2459
std::vector< std::map< std::string, std::string > > getChannelList(const std::string &accountId, const std::string &connectionId)
Definition manager.cpp:985
std::string getAudioManager() const
Get the audio manager.
Definition manager.cpp:2415
void setAudioPlugin(const std::string &audioPlugin)
Set input audio plugin.
Definition manager.cpp:2164
void setDefaultModerator(const std::string &accountID, const std::string &peerURI, bool state)
Definition manager.cpp:3222
std::map< std::string, std::string > getNearbyPeers(const std::string &accountID)
Definition manager.cpp:3214
bool setAudioManager(const std::string &api)
Set the audio manager.
Definition manager.cpp:2387
RingBufferPool & getRingBufferPool()
Return a pointer to the instance of the RingBufferPool.
Definition manager.cpp:3157
int getRingingTimeout() const
Get ringing timeout (number of seconds after which a call will enter BUSY state if not answered).
Definition manager.cpp:2381
int getAudioInputDeviceIndex(const std::string &name)
Get index of an audio device.
Definition manager.cpp:2421
VoipPreference voipPreferences
Voip related preferences.
Definition manager.h:85
void monitor(bool continuous)
Definition manager.cpp:931
uint64_t sendTextMessage(const std::string &accountID, const std::string &to, const std::map< std::string, std::string > &payloads, bool fromPlugin=false, bool onlyConnected=false)
Definition manager.cpp:2937
int getHistoryLimit() const
Get the maximum number of days to keep in the history.
Definition manager.cpp:2367
bool isAllModerators(const std::string &accountID)
Definition manager.cpp:3277
std::string getCurrentAudioOutputPlugin() const
Get current alsa plugin.
Definition manager.cpp:2447
void setIsAlwaysRecording(bool isAlwaysRec)
Set is always recording functionality, every calls will then be set in RECORDING mode once answered.
Definition manager.cpp:2292
std::string getNoiseSuppressState() const
Get the noise reduction engine state from the current audio layer.
Definition manager.cpp:2453
void removeAccount(const std::string &accountID, bool flush=false)
Delete an existing account, unregister VoIPLink associated, and purge from configuration.
Definition manager.cpp:2790
bool isAGCEnabled() const
Definition manager.cpp:2465
void setAGCState(bool enabled)
Definition manager.cpp:2471
void sendRegister(const std::string &accountId, bool enable)
ConfigurationManager - Send registration request.
Definition manager.cpp:2921
std::vector< std::string > getAudioInputDeviceList()
Get list of supported audio input device.
Definition manager.cpp:2221
AudioPreference audioPreference
Audio preferences.
Definition manager.h:90
int getAudioOutputDeviceIndex(const std::string &name)
Definition manager.cpp:2434
int getMessageStatus(uint64_t id) const
Definition manager.cpp:2962
std::vector< std::string > getCurrentAudioDevicesIndex()
Get string array representing integer indexes of output, input, and ringtone device.
Definition manager.cpp:2237
void lookupName(const std::string &name, LookupCallback cb)
void lookupAddress(const std::string &addr, LookupCallback cb)
static void lookupUri(std::string_view uri, const std::string &default_server, LookupCallback cb)
static NameDirectory & instance()
void setAudioMeterState(const std::string &id, bool state)
bool isAudioMeterActive(const std::string &id)
static const std::vector< std::string > & getSupportedTlsCiphers()
static const std::vector< std::string > & getSupportedTlsProtocols()
void setPlayDtmf(bool dtmf)
bool getPlayDtmf() const
std::shared_ptr< dht::crypto::Certificate > getCertificate() const
std::map< std::string, std::string > getSerializedChecks()
Convert all checks results into a string map.
std::map< std::string, std::string > getSerializedDetails()
Get a map with all common certificate details.
#define JAMI_ERR(...)
Definition logger.h:218
#define JAMI_DBG(...)
Definition logger.h:216
#define JAMI_DEBUG(formatstr,...)
Definition logger.h:226
#define JAMI_WARN(...)
Definition logger.h:217
void set_resource_dir_path(const std::filesystem::path &resourceDirPath)
Set the program's resource directory path.
std::vector< uint8_t > loadFile(const std::filesystem::path &path, const std::filesystem::path &default_dir)
Read the full content of a file at path.
decltype(getGlobalInstance< SystemCodecContainer >) & getSystemCodecContainer
void emitSignal(Args... args)
Definition ring_signal.h:64
@ MEDIA_AUDIO
Definition media_codec.h:47
@ MEDIA_ALL
Definition media_codec.h:49
@ MEDIA_VIDEO
Definition media_codec.h:48
AudioDeviceType
Definition audiolayer.h:58
static constexpr const char RING[]
static constexpr const char SIP[]
static constexpr char EXIST[]
std::vector< std::string > getDefaultModerators(const std::string &accountId)
Get default moderators for an account.
bool unpinCertificate(const std::string &accountId, const std::string &certId)
bool cancelMessage(const std::string &accountId, uint64_t messageId)
void setRingingTimeout(int32_t timeout)
void muteRingtone(bool mute)
std::vector< std::string > pinCertificate(const std::string &accountId, const std::vector< uint8_t > &certificate, bool local)
std::vector< Message > getLastMessages(const std::string &accountId, const uint64_t &base_timestamp)
void setAudioPlugin(const std::string &audioPlugin)
void setActiveCodecList(const std::string &accountId, const std::vector< unsigned > &list)
void setAccountDetails(const std::string &accountId, const std::map< std::string, std::string > &details)
void setHistoryLimit(int32_t days)
void setAccountsOrder(const std::string &order)
void setVolume(const std::string &device, double value)
std::vector< std::map< std::string, std::string > > getChannelList(const std::string &accountId, const std::string &connectionId)
std::vector< unsigned > getCodecList()
Send the list of all codecs loaded to the client through DBus.
bool isLocalModeratorsEnabled(const std::string &accountId)
Get local moderators state.
void setRecordPath(const std::string &recPath)
bool setCertificateStatus(const std::string &accountId, const std::string &certId, const std::string &ststr)
bool setAudioManager(const std::string &api)
uint64_t sendAccountTextMessage(const std::string &accountId, const std::string &to, const std::map< std::string, std::string > &payloads, int32_t flags)
void setAudioRingtoneDevice(int32_t index)
std::string getAddrFromInterfaceName(const std::string &interface)
bool lookupName(const std::string &account, const std::string &nameserver, const std::string &name)
int32_t getRecordQuality()
std::vector< std::string > getAudioPluginList()
void loadAccountAndConversation(const std::string &accountId, bool loadAll, const std::string &convId)
bool searchUser(const std::string &account, const std::string &query)
int32_t getAudioOutputDeviceIndex(const std::string &name)
void setPushNotificationToken(const std::string &token)
Set the device push notification token (for all accounts).
void setAudioMeterState(const std::string &id, bool state)
Enables/disables an audio meter for the specified @id.
bool confirmAddDevice(const std::string &accountId, uint32_t op_id)
void setIsAlwaysRecording(bool rec)
int32_t getRingingTimeout()
bool setCodecDetails(const std::string &accountId, const unsigned &codecId, const std::map< std::string, std::string > &details)
void mutePlayback(bool mute)
void sendTrustRequest(const std::string &accountId, const std::string &to, const std::vector< uint8_t > &payload)
void pushNotificationReceived(const std::string &from, const std::map< std::string, std::string > &data)
To be called by clients with relevant data when a push notification is received.
void registerConfHandlers(const std::map< std::string, std::shared_ptr< CallbackWrapperBase > > &handlers)
std::vector< std::string > getPinnedCertificates(const std::string &accountId)
std::map< std::string, std::string > getCertificateDetailsPath(const std::string &accountId, const std::string &certificate, const std::string &privateKey, const std::string &privateKeyPassword)
std::vector< std::string > getAccountList()
bool isAllModerators(const std::string &accountId)
Get all moderators state.
std::vector< unsigned > getActiveCodecList(const std::string &accountId)
std::vector< std::string > getSupportedAudioManagers()
std::map< std::string, std::string > getContactDetails(const std::string &accountId, const std::string &uri)
int32_t getAudioInputDeviceIndex(const std::string &name)
void updateProfile(const std::string &accountId, const std::string &displayName, const std::string &avatar, const std::string &fileType, int32_t flag)
void setAccountActive(const std::string &accountId, bool enable, bool shutdownConnections)
std::map< std::string, std::string > getCodecDetails(const std::string &accountId, const unsigned &codecId)
std::string addAccount(const std::map< std::string, std::string > &details, const std::string &accountId)
int32_t addDevice(const std::string &accountId, const std::string &uri)
bool acceptTrustRequest(const std::string &accountId, const std::string &from)
void setIsComposing(const std::string &accountId, const std::string &conversationUri, bool isWriting)
void setRecordPreview(bool rec)
void muteCapture(bool mute)
bool revokeDevice(const std::string &accountId, const std::string &deviceId, const std::string &scheme, const std::string &password)
bool changeAccountPassword(const std::string &accountId, const std::string &password_old, const std::string &password_new)
void setResourceDirPath(const std::string &resourceDir)
Set the resource directory path.
void setAudioInputDevice(int32_t index)
std::string getCurrentAudioOutputPlugin()
std::vector< std::string > getAllIpInterface()
bool pinRemoteCertificate(const std::string &accountId, const std::string &certId)
void setPushNotificationTopic(const std::string &topic)
Set the topic for ios bundle_id for ios 14.5 and higher bundle_id.voip for ios prior 14....
double getVolume(const std::string &device)
void setAudioOutputDevice(int32_t index)
std::vector< std::string > getCertificatesByStatus(const std::string &accountId, const std::string &ststr)
void muteDtmf(bool mute)
void registerSignalHandlers(const std::map< std::string, std::shared_ptr< CallbackWrapperBase > > &handlers)
std::map< std::string, std::string > getCertificateDetails(const std::string &accountId, const std::string &certificate)
std::vector< std::map< std::string, std::string > > getCredentials(const std::string &accountId)
constexpr unsigned CODECS_NOT_LOADED
std::string getRecordPath()
bool isAudioMeterActive(const std::string &id)
Returns whether or not the audio meter is enabled for ring buffer @id.
bool getIsAlwaysRecording()
std::vector< std::string > getAllIpInterfaceByName()
void sendRegister(const std::string &accountId, bool enable)
std::string getNoiseSuppressState()
bool exportToFile(const std::string &accountId, const std::string &destinationPath, const std::string &scheme, const std::string &password)
int32_t getHistoryLimit()
void setNoiseSuppressState(const std::string &state)
bool lookupAddress(const std::string &account, const std::string &nameserver, const std::string &address)
std::vector< std::map< std::string, std::string > > getConnectionList(const std::string &accountId, const std::string &conversationId)
bool registerName(const std::string &account, const std::string &name, const std::string &scheme, const std::string &password)
std::vector< std::string > getAudioInputDeviceList()
bool isPasswordValid(const std::string &accountId, const std::string &password)
std::vector< uint8_t > getPasswordKey(const std::string &accountID, const std::string &password)
std::vector< std::string > getCurrentAudioDevicesIndex()
std::vector< std::map< std::string, std::string > > getTrustRequests(const std::string &accountId)
void setAgcState(bool enabled)
void enableLocalModerators(const std::string &accountId, bool isModEnabled)
Enable/disable local moderators for conferences.
void addContact(const std::string &accountId, const std::string &uri)
std::map< std::string, std::string > getKnownRingDevices(const std::string &accountId)
void removeAccount(const std::string &accountId)
void setRecordQuality(int32_t quality)
std::map< std::string, std::string > getAccountDetails(const std::string &accountId)
bool provideAccountAuthentication(const std::string &accountId, const std::string &credentialsFromUser, const std::string &scheme)
std::vector< std::string > getSupportedTlsMethod()
bool discardTrustRequest(const std::string &accountId, const std::string &from)
void setAllModerators(const std::string &accountId, bool allModerators)
Enable/disable all moderators for conferences.
int getMessageStatus(uint64_t messageId)
std::vector< std::string > getAudioOutputDeviceList()
std::map< std::string, std::string > getVolatileAccountDetails(const std::string &accountId)
void setCredentials(const std::string &accountId, const std::vector< std::map< std::string, std::string > > &details)
bool setMessageDisplayed(const std::string &accountId, const std::string &conversationUri, const std::string &messageId, int status)
void pinCertificatePath(const std::string &accountId, const std::string &path)
std::map< std::string, std::string > getAccountTemplate(const std::string &accountType)
This function is used as a base for new accounts for clients that support it.
void removeContact(const std::string &accountId, const std::string &uri, bool ban)
std::map< std::string, std::string > validateCertificate(const std::string &accountId, const std::string &certificate)
std::map< std::string, std::string > getNearbyPeers(const std::string &accountId)
bool cancelAddDevice(const std::string &accountId, uint32_t op_id)
std::vector< std::map< std::string, std::string > > getContacts(const std::string &accountId)
void setPushNotificationConfig(const std::map< std::string, std::string > &data)
void monitor(bool continuous)
unsigned unpinCertificatePath(const std::string &accountId, const std::string &path)
std::vector< std::string > getSupportedCiphers(const std::string &accountId)
void setDefaultModerator(const std::string &accountId, const std::string &peerURI, bool state)
Add/remove default moderator for conferences.
std::map< std::string, std::string > validateCertificatePath(const std::string &accountId, const std::string &certificate, const std::string &privateKey, const std::string &privateKeyPass, const std::string &caList)
std::string getAudioManager()
A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
std::map< std::string, std::string > toMap() const override
std::map< std::string, std::string > toMap() const override
void setCredentials(const std::vector< std::map< std::string, std::string > > &creds)