LCOV - code coverage report
Current view: top level - src - uri.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 36 50 72.0 %
Date: 2024-11-15 09:04:49 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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             : 
      22             : namespace jami {
      23             : 
      24       28891 : 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       28891 :     scheme_ = Uri::Scheme::JAMI;
      29       28891 :     auto posSep = uri.find(':');
      30       28889 :     if (posSep != std::string::npos) {
      31        4946 :         auto scheme_str = uri.substr(0, posSep);
      32        4948 :         if (scheme_str == "sip")
      33           0 :             scheme_ = Uri::Scheme::SIP;
      34        4946 :         else if (scheme_str == "swarm")
      35        1585 :             scheme_ = Uri::Scheme::SWARM;
      36        3360 :         else if (scheme_str == "jami")
      37           0 :             scheme_ = Uri::Scheme::JAMI;
      38        3360 :         else if (scheme_str == "data-transfer")
      39         208 :             scheme_ = Uri::Scheme::DATA_TRANSFER;
      40        3152 :         else if (scheme_str == "git")
      41         868 :             scheme_ = Uri::Scheme::GIT;
      42        2285 :         else if (scheme_str == "rdv")
      43           9 :             scheme_ = Uri::Scheme::RENDEZVOUS;
      44        2275 :         else if (scheme_str == "sync")
      45         216 :             scheme_ = Uri::Scheme::SYNC;
      46        2060 :         else if (scheme_str == "msg")
      47        2059 :             scheme_ = Uri::Scheme::MESSAGE;
      48             :         else
      49           1 :             scheme_ = Uri::Scheme::UNRECOGNIZED;
      50        4946 :         authority_ = uri.substr(posSep + 1);
      51             :     } else {
      52       23943 :         authority_ = uri;
      53             :     }
      54       28891 :     auto posParams = authority_.find(';');
      55       28890 :     if (posParams != std::string::npos) {
      56           1 :         authority_ = authority_.substr(0, posParams);
      57             :     }
      58       28890 : }
      59             : 
      60             : const std::string&
      61         332 : Uri::authority() const
      62             : {
      63         332 :     return authority_;
      64             : }
      65             : 
      66             : Uri::Scheme
      67       28989 : Uri::scheme() const
      68             : {
      69       28989 :     return scheme_;
      70             : }
      71             : 
      72             : std::string
      73         178 : Uri::toString() const
      74             : {
      75         534 :     return fmt::format(FMT_COMPILE("{}:{}"), schemeToString(), authority_);
      76             : }
      77             : 
      78             : constexpr std::string_view
      79         178 : Uri::schemeToString() const
      80             : {
      81         178 :     switch (scheme_) {
      82           0 :     case Uri::Scheme::SIP:
      83           0 :         return "sip"sv;
      84           0 :     case Uri::Scheme::SWARM:
      85           0 :         return "swarm"sv;
      86           0 :     case Uri::Scheme::RENDEZVOUS:
      87           0 :         return "rdv"sv;
      88           0 :     case Uri::Scheme::GIT:
      89           0 :         return "git"sv;
      90           0 :     case Uri::Scheme::SYNC:
      91           0 :         return "sync"sv;
      92           0 :     case Uri::Scheme::MESSAGE:
      93           0 :         return "msg"sv;
      94         178 :     case Uri::Scheme::JAMI:
      95             :     case Uri::Scheme::UNRECOGNIZED:
      96             :     default:
      97         178 :         return "jami"sv;
      98             :     }
      99             : }
     100             : 
     101             : } // namespace jami

Generated by: LCOV version 1.14