LCOV - code coverage report
Current view: top level - edhttp - uri.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2022-03-15 17:12:29 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Snap Websites Server -- path canonicalization
       2             : // Copyright (c) 2011-2019  Made to Order Software Corp.  All Rights Reserved
       3             : //
       4             : // https://snapwebsites.org/
       5             : // contact@m2osw.com
       6             : //
       7             : // This program is free software; you can redistribute it and/or modify
       8             : // it under the terms of the GNU General Public License as published by
       9             : // the Free Software Foundation; either version 2 of the License, or
      10             : // (at your option) any later version.
      11             : //
      12             : // This program is distributed in the hope that it will be useful,
      13             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             : // GNU General Public License for more details.
      16             : //
      17             : // You should have received a copy of the GNU General Public License
      18             : // along with this program; if not, write to the Free Software
      19             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      20             : #pragma once
      21             : 
      22             : // self
      23             : //
      24             : #include    "edhttp/exception.h"
      25             : 
      26             : #include    "edhttp/names.h"
      27             : 
      28             : 
      29             : // libaddr
      30             : //
      31             : #include    <libaddr/addr_range.h>
      32             : 
      33             : 
      34             : // advgetopt
      35             : //
      36             : #include    <advgetopt/utils.h>
      37             : 
      38             : 
      39             : // C++
      40             : //
      41             : #include    <map>
      42             : 
      43             : 
      44             : 
      45             : namespace edhttp
      46             : {
      47             : 
      48             : 
      49             : 
      50             : // Helper class to handle URIs
      51             : // http://tools.ietf.org/html/rfc3986
      52           4 : class uri
      53             : {
      54             : public:
      55             :     // types used by this class
      56             :     typedef std::map<std::string, std::string>
      57             :                                 uri_options_t;
      58             : 
      59             :     // constructors
      60             :                                 uri();
      61             :                                 uri(std::string const & uri);
      62             : 
      63             :     // URI handling
      64             :     bool                        set_uri(std::string const & uri);
      65             :     std::string const &         get_original_uri() const;
      66             :     std::string                 get_uri(bool use_hash_bang = false) const;
      67             :     std::string                 get_website_uri(bool include_port = false) const;
      68             : 
      69             :     // get a part by name
      70             :     std::string                 get_part(std::string const & name, int part = -1) const;
      71             : 
      72             :     // protocol handling
      73             :     void                        set_protocol(std::string const & uri_protocol);
      74             :     std::string const &         protocol() const;
      75             : 
      76             :     // domain & sub-domains handling
      77             :     void                        set_domain(std::string const & full_domain_name);
      78             :     std::string                 full_domain() const;
      79             :     std::string const &         top_level_domain() const;
      80             :     std::string const &         domain() const;
      81             :     std::string                 sub_domains() const;
      82             :     int                         sub_domain_count() const;
      83             :     std::string                 sub_domain(int part) const;
      84             :     advgetopt::string_list_t const &
      85             :                                 sub_domains_list() const;
      86             :     addr::addr_range::vector_t const &
      87             :                                 address_ranges();
      88             : 
      89             :     // port handling
      90             :     void                        set_port(std::string const & port);
      91             :     void                        set_port(int port);
      92             :     int                         get_port() const;
      93             : 
      94             :     // path handling
      95             :     void                        set_path(std::string uri_path);
      96             :     std::string                 path(bool encoded = true) const;
      97             :     int                         path_count() const;
      98             :     std::string                 path_folder_name(int part) const;
      99             :     advgetopt::string_list_t const &
     100             :                                 path_list() const;
     101             : 
     102             :     // option handling
     103             :     void                        set_option(std::string const & name, std::string const & value);
     104             :     void                        unset_option(std::string const & name);
     105             :     std::string                 option(std::string const & name) const;
     106             :     int                         option_count() const;
     107             :     std::string                 option(int part, std::string & name) const;
     108             :     uri_options_t const &       options_list() const;
     109             : 
     110             :     // query string handling
     111             :     void                        set_query_option(std::string const & name, std::string const & value);
     112             :     void                        unset_query_option(std::string const & name);
     113             :     void                        set_query_string(std::string const & uri_query_string);
     114             :     std::string                 query_string() const;
     115             :     bool                        has_query_option(std::string const & name) const;
     116             :     void                        clear_query_options();
     117             :     std::string                 query_option(std::string const & name) const;
     118             :     int                         query_option_count() const;
     119             :     std::string                 query_option(int part, std::string & name) const;
     120             :     uri_options_t const &       query_string_list() const;
     121             : 
     122             :     // anchor handling (note: "#!" is not considered an anchor)
     123             :     void                        set_anchor(std::string const & uri_anchor);
     124             :     std::string const &         anchor() const;
     125             : 
     126             :     // operators
     127             :     bool                        operator == (uri const & rhs) const;
     128             :     bool                        operator != (uri const & rhs) const;
     129             :     bool                        operator <  (uri const & rhs) const;
     130             :     bool                        operator <= (uri const & rhs) const;
     131             :     bool                        operator >  (uri const & rhs) const;
     132             :     bool                        operator >= (uri const & rhs) const;
     133             : 
     134             :     static std::string          urlencode(std::string const & uri, char const * accepted = "");
     135             :     static std::string          urldecode(std::string const & uri, bool relax = false);
     136             :     static int                  protocol_to_port(std::string const & uri_protocol);
     137             : 
     138             : private:
     139             :     bool                        process_domain(std::string const & full_domain_name, advgetopt::string_list_t & sub_domain_names, std::string & domain_name, std::string & tld);
     140             : 
     141             :     // f_original is the unchanged source (from constructor or
     142             :     // last set_uri() call)
     143             :     std::string                 f_original = std::string();
     144             :     std::string                 f_protocol = std::string(g_name_edhttp_protocol_http);
     145             :     std::string                 f_username = std::string();
     146             :     std::string                 f_password = std::string();
     147             :     int                         f_port = 80;
     148             :     std::string                 f_domain = std::string();
     149             :     std::string                 f_top_level_domain = std::string();
     150             :     advgetopt::string_list_t    f_sub_domains = advgetopt::string_list_t();
     151             :     advgetopt::string_list_t    f_path = advgetopt::string_list_t();
     152             :     uri_options_t               f_options = uri_options_t();
     153             :     uri_options_t               f_query_strings = uri_options_t();
     154             :     std::string                 f_anchor = std::string();
     155             :     addr::addr_range::vector_t  f_address_ranges = addr::addr_range::vector_t();
     156             : };
     157             : 
     158             : 
     159             : 
     160             : } // namespace edhttp
     161             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13