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-08-23 08:52:56 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        24316 : 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        24290 :     scheme_ = Uri::Scheme::JAMI;
      29        24290 :     auto posSep = uri.find(':');
      30        24293 :     if (posSep != std::string::npos) {
      31        10789 :         auto scheme_str = uri.substr(0, posSep);
      32        10794 :         if (scheme_str == "sip")
      33            0 :             scheme_ = Uri::Scheme::SIP;
      34        10793 :         else if (scheme_str == "swarm")
      35         1766 :             scheme_ = Uri::Scheme::SWARM;
      36         9024 :         else if (scheme_str == "jami")
      37            0 :             scheme_ = Uri::Scheme::JAMI;
      38         9030 :         else if (scheme_str == "data-transfer")
      39          190 :             scheme_ = Uri::Scheme::DATA_TRANSFER;
      40         8840 :         else if (scheme_str == "git")
      41         1071 :             scheme_ = Uri::Scheme::GIT;
      42         7768 :         else if (scheme_str == "ydoc")
      43           23 :             scheme_ = Uri::Scheme::YDOC;
      44         7746 :         else if (scheme_str == "rdv")
      45            9 :             scheme_ = Uri::Scheme::RENDEZVOUS;
      46         7741 :         else if (scheme_str == "sync")
      47          207 :             scheme_ = Uri::Scheme::SYNC;
      48         7530 :         else if (scheme_str == "msg")
      49         3769 :             scheme_ = Uri::Scheme::MESSAGE;
      50         3767 :         else if (scheme_str == "auth")
      51            4 :             scheme_ = Uri::Scheme::AUTH;
      52         3764 :         else if (scheme_str == "svcdisc")
      53         3756 :             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        10801 :         authority_ = uri.substr(posSep + 1);
      59              :     } else {
      60        13504 :         authority_ = uri;
      61              :     }
      62        24285 :     auto posParams = authority_.find(';');
      63        24290 :     if (posParams != std::string::npos) {
      64            1 :         authority_ = authority_.substr(0, posParams);
      65              :     }
      66        24290 : }
      67              : 
      68              : const std::string&
      69          335 : Uri::authority() const
      70              : {
      71          335 :     return authority_;
      72              : }
      73              : 
      74              : Uri::Scheme
      75        24406 : Uri::scheme() const
      76              : {
      77        24406 :     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