tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsURLParsers.h (4660B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef nsURLParsers_h__
      7 #define nsURLParsers_h__
      8 
      9 #include "nsIURLParser.h"
     10 
     11 //----------------------------------------------------------------------------
     12 // base class for url parsers
     13 //----------------------------------------------------------------------------
     14 
     15 class nsBaseURLParser : public nsIURLParser {
     16 public:
     17  NS_DECL_NSIURLPARSER
     18 
     19  nsBaseURLParser() = default;
     20 
     21 protected:
     22  // implemented by subclasses
     23  virtual void ParseAfterScheme(const char* spec, int32_t specLen,
     24                                uint32_t* authPos, int32_t* authLen,
     25                                uint32_t* pathPos, int32_t* pathLen) = 0;
     26 };
     27 
     28 //----------------------------------------------------------------------------
     29 // an url parser for urls that do not have an authority section
     30 //
     31 // eg. file:foo/bar.txt
     32 //     file:/foo/bar.txt      (treated equivalently)
     33 //     file:///foo/bar.txt
     34 //
     35 // eg. file:////foo/bar.txt   (UNC-filepath = \\foo\bar.txt)
     36 //
     37 // XXX except in this case:
     38 //     file://foo/bar.txt     (the authority "foo"  is ignored)
     39 //----------------------------------------------------------------------------
     40 
     41 class nsNoAuthURLParser final : public nsBaseURLParser {
     42  ~nsNoAuthURLParser() = default;
     43 
     44 public:
     45  NS_DECL_THREADSAFE_ISUPPORTS
     46 
     47 #if defined(XP_WIN)
     48  NS_IMETHOD ParseFilePath(const char*, int32_t, uint32_t*, int32_t*, uint32_t*,
     49                           int32_t*, uint32_t*, int32_t*) override;
     50 #endif
     51 
     52  NS_IMETHOD ParseAuthority(const char* auth, int32_t authLen,
     53                            uint32_t* usernamePos, int32_t* usernameLen,
     54                            uint32_t* passwordPos, int32_t* passwordLen,
     55                            uint32_t* hostnamePos, int32_t* hostnameLen,
     56                            int32_t* port) override;
     57 
     58  void ParseAfterScheme(const char* spec, int32_t specLen, uint32_t* authPos,
     59                        int32_t* authLen, uint32_t* pathPos,
     60                        int32_t* pathLen) override;
     61 };
     62 
     63 //----------------------------------------------------------------------------
     64 // an url parser for urls that must have an authority section
     65 //
     66 // eg. http:www.foo.com/bar.html
     67 //     http:/www.foo.com/bar.html
     68 //     http://www.foo.com/bar.html    (treated equivalently)
     69 //     http:///www.foo.com/bar.html
     70 //----------------------------------------------------------------------------
     71 
     72 class nsAuthURLParser : public nsBaseURLParser {
     73 protected:
     74  virtual ~nsAuthURLParser() = default;
     75 
     76 public:
     77  NS_DECL_THREADSAFE_ISUPPORTS
     78 
     79  NS_IMETHOD ParseAuthority(const char* auth, int32_t authLen,
     80                            uint32_t* usernamePos, int32_t* usernameLen,
     81                            uint32_t* passwordPos, int32_t* passwordLen,
     82                            uint32_t* hostnamePos, int32_t* hostnameLen,
     83                            int32_t* port) override;
     84 
     85  NS_IMETHOD ParseUserInfo(const char* userinfo, int32_t userinfoLen,
     86                           uint32_t* usernamePos, int32_t* usernameLen,
     87                           uint32_t* passwordPos,
     88                           int32_t* passwordLen) override;
     89 
     90  NS_IMETHOD ParseServerInfo(const char* serverinfo, int32_t serverinfoLen,
     91                             uint32_t* hostnamePos, int32_t* hostnameLen,
     92                             int32_t* port) override;
     93 
     94  void ParseAfterScheme(const char* spec, int32_t specLen, uint32_t* authPos,
     95                        int32_t* authLen, uint32_t* pathPos,
     96                        int32_t* pathLen) override;
     97 };
     98 
     99 //----------------------------------------------------------------------------
    100 // an url parser for urls that may or may not have an authority section
    101 //
    102 // eg. http:www.foo.com              (www.foo.com is authority)
    103 //     http:www.foo.com/bar.html     (www.foo.com is authority)
    104 //     http:/www.foo.com/bar.html    (www.foo.com is part of file path)
    105 //     http://www.foo.com/bar.html   (www.foo.com is authority)
    106 //     http:///www.foo.com/bar.html  (www.foo.com is part of file path)
    107 //----------------------------------------------------------------------------
    108 
    109 class nsStdURLParser : public nsAuthURLParser {
    110  virtual ~nsStdURLParser() = default;
    111 
    112 public:
    113  void ParseAfterScheme(const char* spec, int32_t specLen, uint32_t* authPos,
    114                        int32_t* authLen, uint32_t* pathPos,
    115                        int32_t* pathLen) override;
    116 };
    117 
    118 #endif  // nsURLParsers_h__