netwerk/base/src/nsURLParsers.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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/. */
     6 #ifndef nsURLParsers_h__
     7 #define nsURLParsers_h__
     9 #include "nsIURLParser.h"
    10 #include "mozilla/Attributes.h"
    12 //----------------------------------------------------------------------------
    13 // base class for url parsers
    14 //----------------------------------------------------------------------------
    16 class nsBaseURLParser : public nsIURLParser
    17 {
    18 public:
    19     NS_DECL_NSIURLPARSER
    21     nsBaseURLParser() { }
    23 protected:
    24     // implemented by subclasses
    25     virtual void ParseAfterScheme(const char *spec, int32_t specLen,
    26                                   uint32_t *authPos, int32_t *authLen,
    27                                   uint32_t *pathPos, int32_t *pathLen) = 0;
    28 };
    30 //----------------------------------------------------------------------------
    31 // an url parser for urls that do not have an authority section
    32 //
    33 // eg. file:foo/bar.txt
    34 //     file:/foo/bar.txt      (treated equivalently)
    35 //     file:///foo/bar.txt
    36 //
    37 // eg. file:////foo/bar.txt   (UNC-filepath = \\foo\bar.txt)
    38 //
    39 // XXX except in this case:
    40 //     file://foo/bar.txt     (the authority "foo"  is ignored)
    41 //----------------------------------------------------------------------------
    43 class nsNoAuthURLParser MOZ_FINAL : public nsBaseURLParser
    44 {
    45 public:
    46     NS_DECL_THREADSAFE_ISUPPORTS
    48 #if defined(XP_WIN)
    49     NS_IMETHOD ParseFilePath(const char *, int32_t,
    50                              uint32_t *, int32_t *,
    51                              uint32_t *, int32_t *,
    52                              uint32_t *, int32_t *);
    53 #endif
    55     NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
    56                               uint32_t *usernamePos, int32_t *usernameLen,
    57                               uint32_t *passwordPos, int32_t *passwordLen,
    58                               uint32_t *hostnamePos, int32_t *hostnameLen,
    59                               int32_t *port);
    61     void ParseAfterScheme(const char *spec, int32_t specLen,
    62                           uint32_t *authPos, int32_t *authLen,
    63                           uint32_t *pathPos, int32_t *pathLen);
    64 };
    66 //----------------------------------------------------------------------------
    67 // an url parser for urls that must have an authority section
    68 //
    69 // eg. http:www.foo.com/bar.html
    70 //     http:/www.foo.com/bar.html
    71 //     http://www.foo.com/bar.html    (treated equivalently)
    72 //     http:///www.foo.com/bar.html
    73 //----------------------------------------------------------------------------
    75 class nsAuthURLParser : public nsBaseURLParser
    76 {
    77 public:
    78     NS_DECL_THREADSAFE_ISUPPORTS
    80     virtual ~nsAuthURLParser() {}
    82     NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
    83                               uint32_t *usernamePos, int32_t *usernameLen,
    84                               uint32_t *passwordPos, int32_t *passwordLen,
    85                               uint32_t *hostnamePos, int32_t *hostnameLen,
    86                               int32_t *port);
    88     NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen,
    89                              uint32_t *usernamePos, int32_t *usernameLen,
    90                              uint32_t *passwordPos, int32_t *passwordLen);
    92     NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
    93                                uint32_t *hostnamePos, int32_t *hostnameLen,
    94                                int32_t *port);
    96     void ParseAfterScheme(const char *spec, int32_t specLen,
    97                           uint32_t *authPos, int32_t *authLen,
    98                           uint32_t *pathPos, int32_t *pathLen);
    99 };
   101 //----------------------------------------------------------------------------
   102 // an url parser for urls that may or may not have an authority section
   103 //
   104 // eg. http:www.foo.com              (www.foo.com is authority)
   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 //     http://www.foo.com/bar.html   (www.foo.com is authority)
   108 //     http:///www.foo.com/bar.html  (www.foo.com is part of file path)
   109 //----------------------------------------------------------------------------
   111 class nsStdURLParser : public nsAuthURLParser
   112 {
   113 public: 
   114     void ParseAfterScheme(const char *spec, int32_t specLen,
   115                           uint32_t *authPos, int32_t *authLen,
   116                           uint32_t *pathPos, int32_t *pathLen);
   117 };
   119 #endif // nsURLParsers_h__

mercurial