LCOV - code coverage report
Current view: top level - src - uri.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 69.7 % 66 46
Test Date: 2026-09-13 09:08:58 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /*
       2              :  *  Copyright (C) 2004-2026 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        24338 : 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        24310 :     scheme_ = Uri::Scheme::JAMI;
      29        24310 :     auto posSep = uri.find(':');
      30        24329 :     if (posSep != std::string::npos) {
      31        11036 :         auto scheme_str = uri.substr(0, posSep);
      32        11040 :         if (scheme_str == "sip")
      33            0 :             scheme_ = Uri::Scheme::SIP;
      34        11034 :         else if (scheme_str == "swarm")
      35         1634 :             scheme_ = Uri::Scheme::SWARM;
      36         9402 :         else if (scheme_str == "jami")
      37            0 :             scheme_ = Uri::Scheme::JAMI;
      38         9402 :         else if (scheme_str == "data-transfer")
      39          250 :             scheme_ = Uri::Scheme::DATA_TRANSFER;
      40         9151 :         else if (scheme_str == "git")
      41         1083 :             scheme_ = Uri::Scheme::GIT;
      42         8068 :         else if (scheme_str == "ydoc")
      43           23 :             scheme_ = Uri::Scheme::YDOC;
      44         8048 :         else if (scheme_str == "rdv")
      45            9 :             scheme_ = Uri::Scheme::RENDEZVOUS;
      46         8037 :         else if (scheme_str == "sync")
      47          210 :             scheme_ = Uri::Scheme::SYNC;
      48         7833 :         else if (scheme_str == "msg")
      49         3908 :             scheme_ = Uri::Scheme::MESSAGE;
      50         3926 :         else if (scheme_str == "auth")
      51            4 :             scheme_ = Uri::Scheme::AUTH;
      52         3920 :         else if (scheme_str == "svcdisc")
      53         3916 :             scheme_ = Uri::Scheme::SVC_DISCOVERY;
      54            6 :         else if (scheme_str == "svc")
      55            5 :             scheme_ = Uri::Scheme::SVC_TUNNEL;
      56              :         else
      57            1 :             scheme_ = Uri::Scheme::UNRECOGNIZED;
      58        11043 :         authority_ = uri.substr(posSep + 1);
      59              :     } else {
      60        13293 :         authority_ = uri;
      61              :     }
      62        24303 :     auto posParams = authority_.find(';');
      63        24319 :     if (posParams != std::string::npos) {
      64            1 :         authority_ = authority_.substr(0, posParams);
      65              :     }
      66        24319 : }
      67              : 
      68              : const std::string&
      69          335 : Uri::authority() const
      70              : {
      71          335 :     return authority_;
      72              : }
      73              : 
      74              : Uri::Scheme
      75        24433 : Uri::scheme() const
      76              : {
      77        24433 :     return scheme_;
      78              : }
      79              : 
      80              : std::string
      81          179 : Uri::toString() const
      82              : {
      83          716 :     return fmt::format(FMT_COMPILE("{}:{}"), schemeToString(), authority_);
      84              : }
      85              : 
      86              : constexpr std::string_view
      87          179 : Uri::schemeToString() const
      88              : {
      89          179 :     switch (scheme_) {
      90            0 :     case Uri::Scheme::SIP:
      91            0 :         return "sip"sv;
      92            0 :     case Uri::Scheme::SWARM:
      93            0 :         return "swarm"sv;
      94            0 :     case Uri::Scheme::RENDEZVOUS:
      95            0 :         return "rdv"sv;
      96            0 :     case Uri::Scheme::GIT:
      97            0 :         return "git"sv;
      98            0 :     case Uri::Scheme::YDOC:
      99            0 :         return "ydoc"sv;
     100            0 :     case Uri::Scheme::SYNC:
     101            0 :         return "sync"sv;
     102            0 :     case Uri::Scheme::MESSAGE:
     103            0 :         return "msg"sv;
     104            0 :     case Uri::Scheme::AUTH:
     105            0 :         return "auth"sv;
     106            0 :     case Uri::Scheme::SVC_DISCOVERY:
     107            0 :         return "svcdisc"sv;
     108            1 :     case Uri::Scheme::SVC_TUNNEL:
     109            1 :         return "svc"sv;
     110          178 :     case Uri::Scheme::JAMI:
     111              :     case Uri::Scheme::UNRECOGNIZED:
     112              :     default:
     113          178 :         return "jami"sv;
     114              :     }
     115              : }
     116              : 
     117              : } // namespace jami
        

Generated by: LCOV version 2.0-1