netwerk/base/src/nsURLParsers.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/nsURLParsers.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsURLParsers_h__
    1.10 +#define nsURLParsers_h__
    1.11 +
    1.12 +#include "nsIURLParser.h"
    1.13 +#include "mozilla/Attributes.h"
    1.14 +
    1.15 +//----------------------------------------------------------------------------
    1.16 +// base class for url parsers
    1.17 +//----------------------------------------------------------------------------
    1.18 +
    1.19 +class nsBaseURLParser : public nsIURLParser
    1.20 +{
    1.21 +public:
    1.22 +    NS_DECL_NSIURLPARSER
    1.23 +
    1.24 +    nsBaseURLParser() { }
    1.25 +
    1.26 +protected:
    1.27 +    // implemented by subclasses
    1.28 +    virtual void ParseAfterScheme(const char *spec, int32_t specLen,
    1.29 +                                  uint32_t *authPos, int32_t *authLen,
    1.30 +                                  uint32_t *pathPos, int32_t *pathLen) = 0;
    1.31 +};
    1.32 +
    1.33 +//----------------------------------------------------------------------------
    1.34 +// an url parser for urls that do not have an authority section
    1.35 +//
    1.36 +// eg. file:foo/bar.txt
    1.37 +//     file:/foo/bar.txt      (treated equivalently)
    1.38 +//     file:///foo/bar.txt
    1.39 +//
    1.40 +// eg. file:////foo/bar.txt   (UNC-filepath = \\foo\bar.txt)
    1.41 +//
    1.42 +// XXX except in this case:
    1.43 +//     file://foo/bar.txt     (the authority "foo"  is ignored)
    1.44 +//----------------------------------------------------------------------------
    1.45 +
    1.46 +class nsNoAuthURLParser MOZ_FINAL : public nsBaseURLParser
    1.47 +{
    1.48 +public:
    1.49 +    NS_DECL_THREADSAFE_ISUPPORTS
    1.50 +
    1.51 +#if defined(XP_WIN)
    1.52 +    NS_IMETHOD ParseFilePath(const char *, int32_t,
    1.53 +                             uint32_t *, int32_t *,
    1.54 +                             uint32_t *, int32_t *,
    1.55 +                             uint32_t *, int32_t *);
    1.56 +#endif
    1.57 +
    1.58 +    NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
    1.59 +                              uint32_t *usernamePos, int32_t *usernameLen,
    1.60 +                              uint32_t *passwordPos, int32_t *passwordLen,
    1.61 +                              uint32_t *hostnamePos, int32_t *hostnameLen,
    1.62 +                              int32_t *port);
    1.63 +
    1.64 +    void ParseAfterScheme(const char *spec, int32_t specLen,
    1.65 +                          uint32_t *authPos, int32_t *authLen,
    1.66 +                          uint32_t *pathPos, int32_t *pathLen);
    1.67 +};
    1.68 +
    1.69 +//----------------------------------------------------------------------------
    1.70 +// an url parser for urls that must have an authority section
    1.71 +//
    1.72 +// eg. http:www.foo.com/bar.html
    1.73 +//     http:/www.foo.com/bar.html
    1.74 +//     http://www.foo.com/bar.html    (treated equivalently)
    1.75 +//     http:///www.foo.com/bar.html
    1.76 +//----------------------------------------------------------------------------
    1.77 +
    1.78 +class nsAuthURLParser : public nsBaseURLParser
    1.79 +{
    1.80 +public:
    1.81 +    NS_DECL_THREADSAFE_ISUPPORTS
    1.82 +
    1.83 +    virtual ~nsAuthURLParser() {}
    1.84 +
    1.85 +    NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
    1.86 +                              uint32_t *usernamePos, int32_t *usernameLen,
    1.87 +                              uint32_t *passwordPos, int32_t *passwordLen,
    1.88 +                              uint32_t *hostnamePos, int32_t *hostnameLen,
    1.89 +                              int32_t *port);
    1.90 +
    1.91 +    NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen,
    1.92 +                             uint32_t *usernamePos, int32_t *usernameLen,
    1.93 +                             uint32_t *passwordPos, int32_t *passwordLen);
    1.94 +
    1.95 +    NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
    1.96 +                               uint32_t *hostnamePos, int32_t *hostnameLen,
    1.97 +                               int32_t *port);
    1.98 +
    1.99 +    void ParseAfterScheme(const char *spec, int32_t specLen,
   1.100 +                          uint32_t *authPos, int32_t *authLen,
   1.101 +                          uint32_t *pathPos, int32_t *pathLen);
   1.102 +};
   1.103 +
   1.104 +//----------------------------------------------------------------------------
   1.105 +// an url parser for urls that may or may not have an authority section
   1.106 +//
   1.107 +// eg. http:www.foo.com              (www.foo.com is authority)
   1.108 +//     http:www.foo.com/bar.html     (www.foo.com is authority)
   1.109 +//     http:/www.foo.com/bar.html    (www.foo.com is part of file path)
   1.110 +//     http://www.foo.com/bar.html   (www.foo.com is authority)
   1.111 +//     http:///www.foo.com/bar.html  (www.foo.com is part of file path)
   1.112 +//----------------------------------------------------------------------------
   1.113 +
   1.114 +class nsStdURLParser : public nsAuthURLParser
   1.115 +{
   1.116 +public: 
   1.117 +    void ParseAfterScheme(const char *spec, int32_t specLen,
   1.118 +                          uint32_t *authPos, int32_t *authLen,
   1.119 +                          uint32_t *pathPos, int32_t *pathLen);
   1.120 +};
   1.121 +
   1.122 +#endif // nsURLParsers_h__

mercurial