Ring Daemon 16.0.0
Loading...
Searching...
No Matches
uri.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#include "uri.h"
18
19#include <fmt/format.h>
20#include <fmt/compile.h>
21
22namespace jami {
23
24Uri::Uri(std::string_view uri)
25{
26 // TODO better handling of Uri, for now it's only used for
27 // setMessageDisplayed to differentiate swarm:xxx
28 scheme_ = Uri::Scheme::JAMI;
29 auto posSep = uri.find(':');
30 if (posSep != std::string::npos) {
31 auto scheme_str = uri.substr(0, posSep);
32 if (scheme_str == "sip")
33 scheme_ = Uri::Scheme::SIP;
34 else if (scheme_str == "swarm")
35 scheme_ = Uri::Scheme::SWARM;
36 else if (scheme_str == "jami")
37 scheme_ = Uri::Scheme::JAMI;
38 else if (scheme_str == "data-transfer")
40 else if (scheme_str == "git")
41 scheme_ = Uri::Scheme::GIT;
42 else if (scheme_str == "rdv")
44 else if (scheme_str == "sync")
45 scheme_ = Uri::Scheme::SYNC;
46 else if (scheme_str == "msg")
47 scheme_ = Uri::Scheme::MESSAGE;
48 else if (scheme_str == "auth")
49 scheme_ = Uri::Scheme::AUTH;
50 else
52 authority_ = uri.substr(posSep + 1);
53 } else {
54 authority_ = uri;
55 }
56 auto posParams = authority_.find(';');
57 if (posParams != std::string::npos) {
58 authority_ = authority_.substr(0, posParams);
59 }
60}
61
62const std::string&
64{
65 return authority_;
66}
67
70{
71 return scheme_;
72}
73
74std::string
76{
77 return fmt::format(FMT_COMPILE("{}:{}"), schemeToString(), authority_);
78}
79
80constexpr std::string_view
81Uri::schemeToString() const
82{
83 switch (scheme_) {
85 return "sip"sv;
87 return "swarm"sv;
89 return "rdv"sv;
91 return "git"sv;
93 return "sync"sv;
95 return "msg"sv;
97 return "auth"sv;
100 default:
101 return "jami"sv;
102 }
103}
104
105} // namespace jami
Uri(std::string_view uri)
Definition uri.cpp:24
const std::string & authority() const
Definition uri.cpp:63
Scheme scheme() const
Definition uri.cpp:69
std::string toString() const
Definition uri.cpp:75
Scheme
Definition uri.h:31
void emitSignal(Args... args)
Definition ring_signal.h:64