Line data Source code
1 : /* 2 : * Copyright (C) 2021-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program; if not, write to the Free Software 18 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 : */ 20 : #include "uri.h" 21 : 22 : namespace jami { 23 : 24 42197 : Uri::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 42197 : scheme_ = Uri::Scheme::JAMI; 29 42197 : auto posSep = uri.find(':'); 30 42193 : if (posSep != std::string::npos) { 31 2854 : auto scheme_str = uri.substr(0, posSep); 32 2854 : if (scheme_str == "sip") 33 0 : scheme_ = Uri::Scheme::SIP; 34 2853 : else if (scheme_str == "swarm") 35 1594 : scheme_ = Uri::Scheme::SWARM; 36 1260 : else if (scheme_str == "jami") 37 0 : scheme_ = Uri::Scheme::JAMI; 38 1260 : else if (scheme_str == "data-transfer") 39 187 : scheme_ = Uri::Scheme::DATA_TRANSFER; 40 1073 : else if (scheme_str == "git") 41 850 : scheme_ = Uri::Scheme::GIT; 42 223 : else if (scheme_str == "rdv") 43 9 : scheme_ = Uri::Scheme::RENDEZVOUS; 44 214 : else if (scheme_str == "sync") 45 213 : scheme_ = Uri::Scheme::SYNC; 46 : else 47 1 : scheme_ = Uri::Scheme::UNRECOGNIZED; 48 2854 : authority_ = uri.substr(posSep + 1); 49 : } else { 50 39339 : authority_ = uri; 51 : } 52 42193 : auto posParams = authority_.find(';'); 53 42190 : if (posParams != std::string::npos) { 54 1 : authority_ = authority_.substr(0, posParams); 55 : } 56 42190 : } 57 : 58 : const std::string& 59 354 : Uri::authority() const 60 : { 61 354 : return authority_; 62 : } 63 : 64 : Uri::Scheme 65 42289 : Uri::scheme() const 66 : { 67 42289 : return scheme_; 68 : } 69 : 70 : std::string 71 222 : Uri::toString() const 72 : { 73 444 : return schemeToString() + ":" + authority_; 74 : } 75 : 76 : std::string 77 222 : Uri::schemeToString() const 78 : { 79 222 : switch (scheme_) { 80 0 : case Uri::Scheme::SIP: 81 0 : return "sip"; 82 26 : case Uri::Scheme::SWARM: 83 26 : return "swarm"; 84 18 : case Uri::Scheme::RENDEZVOUS: 85 18 : return "rdv"; 86 0 : case Uri::Scheme::GIT: 87 0 : return "git"; 88 0 : case Uri::Scheme::SYNC: 89 0 : return "sync"; 90 178 : case Uri::Scheme::JAMI: 91 : case Uri::Scheme::UNRECOGNIZED: 92 : default: 93 178 : return "jami"; 94 : } 95 : } 96 : 97 : } // namespace jami