LCOV - code coverage report
Current view: top level - foo/src - uri.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 38 54 70.4 %
Date: 2025-08-24 09:11:10 Functions: 6 6 100.0 %

          Line data    Source code
       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             : 
      22             : namespace jami {
      23             : 
      24       18280 : 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       18280 :     scheme_ = Uri::Scheme::JAMI;
      29       18280 :     auto posSep = uri.find(':');
      30       18280 :     if (posSep != std::string::npos) {
      31        3961 :         auto scheme_str = uri.substr(0, posSep);
      32        3961 :         if (scheme_str == "sip")
      33           0 :             scheme_ = Uri::Scheme::SIP;
      34        3961 :         else if (scheme_str == "swarm")
      35         954 :             scheme_ = Uri::Scheme::SWARM;
      36        3007 :         else if (scheme_str == "jami")
      37           0 :             scheme_ = Uri::Scheme::JAMI;
      38        3007 :         else if (scheme_str == "data-transfer")
      39         162 :             scheme_ = Uri::Scheme::DATA_TRANSFER;
      40        2845 :         else if (scheme_str == "git")
      41         803 :             scheme_ = Uri::Scheme::GIT;
      42        2042 :         else if (scheme_str == "rdv")
      43           9 :             scheme_ = Uri::Scheme::RENDEZVOUS;
      44        2033 :         else if (scheme_str == "sync")
      45         162 :             scheme_ = Uri::Scheme::SYNC;
      46        1871 :         else if (scheme_str == "msg")
      47        1866 :             scheme_ = Uri::Scheme::MESSAGE;
      48           5 :         else if (scheme_str == "auth")
      49           4 :             scheme_ = Uri::Scheme::AUTH;
      50             :         else
      51           1 :             scheme_ = Uri::Scheme::UNRECOGNIZED;
      52        3961 :         authority_ = uri.substr(posSep + 1);
      53             :     } else {
      54       14319 :         authority_ = uri;
      55             :     }
      56       18280 :     auto posParams = authority_.find(';');
      57       18280 :     if (posParams != std::string::npos) {
      58           1 :         authority_ = authority_.substr(0, posParams);
      59             :     }
      60       18280 : }
      61             : 
      62             : const std::string&
      63         326 : Uri::authority() const
      64             : {
      65         326 :     return authority_;
      66             : }
      67             : 
      68             : Uri::Scheme
      69       18378 : Uri::scheme() const
      70             : {
      71       18378 :     return scheme_;
      72             : }
      73             : 
      74             : std::string
      75         178 : Uri::toString() const
      76             : {
      77         534 :     return fmt::format(FMT_COMPILE("{}:{}"), schemeToString(), authority_);
      78             : }
      79             : 
      80             : constexpr std::string_view
      81         178 : Uri::schemeToString() const
      82             : {
      83         178 :     switch (scheme_) {
      84           0 :     case Uri::Scheme::SIP:
      85           0 :         return "sip"sv;
      86           0 :     case Uri::Scheme::SWARM:
      87           0 :         return "swarm"sv;
      88           0 :     case Uri::Scheme::RENDEZVOUS:
      89           0 :         return "rdv"sv;
      90           0 :     case Uri::Scheme::GIT:
      91           0 :         return "git"sv;
      92           0 :     case Uri::Scheme::SYNC:
      93           0 :         return "sync"sv;
      94           0 :     case Uri::Scheme::MESSAGE:
      95           0 :         return "msg"sv;
      96           0 :     case Uri::Scheme::AUTH:
      97           0 :         return "auth"sv;
      98         178 :     case Uri::Scheme::JAMI:
      99             :     case Uri::Scheme::UNRECOGNIZED:
     100             :     default:
     101         178 :         return "jami"sv;
     102             :     }
     103             : }
     104             : 
     105             : } // namespace jami

Generated by: LCOV version 1.14