Blame netwerk/base/nsURLParsers.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#ifndef nsURLParsers_h__
Packit f0b94e
#define nsURLParsers_h__
Packit f0b94e
Packit f0b94e
#include "nsIURLParser.h"
Packit f0b94e
#include "mozilla/Attributes.h"
Packit f0b94e
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
// base class for url parsers
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
Packit f0b94e
class nsBaseURLParser : public nsIURLParser {
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_NSIURLPARSER
Packit f0b94e
Packit f0b94e
  nsBaseURLParser() {}
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  // implemented by subclasses
Packit f0b94e
  virtual void ParseAfterScheme(const char *spec, int32_t specLen,
Packit f0b94e
                                uint32_t *authPos, int32_t *authLen,
Packit f0b94e
                                uint32_t *pathPos, int32_t *pathLen) = 0;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
// an url parser for urls that do not have an authority section
Packit f0b94e
//
Packit f0b94e
// eg. file:foo/bar.txt
Packit f0b94e
//     file:/foo/bar.txt      (treated equivalently)
Packit f0b94e
//     file:///foo/bar.txt
Packit f0b94e
//
Packit f0b94e
// eg. file:////foo/bar.txt   (UNC-filepath = \\foo\bar.txt)
Packit f0b94e
//
Packit f0b94e
// XXX except in this case:
Packit f0b94e
//     file://foo/bar.txt     (the authority "foo"  is ignored)
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
Packit f0b94e
class nsNoAuthURLParser final : public nsBaseURLParser {
Packit f0b94e
  ~nsNoAuthURLParser() {}
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_THREADSAFE_ISUPPORTS
Packit f0b94e
Packit f0b94e
#if defined(XP_WIN)
Packit f0b94e
  NS_IMETHOD ParseFilePath(const char *, int32_t, uint32_t *, int32_t *,
Packit f0b94e
                           uint32_t *, int32_t *, uint32_t *,
Packit f0b94e
                           int32_t *) override;
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
  NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
Packit f0b94e
                            uint32_t *usernamePos, int32_t *usernameLen,
Packit f0b94e
                            uint32_t *passwordPos, int32_t *passwordLen,
Packit f0b94e
                            uint32_t *hostnamePos, int32_t *hostnameLen,
Packit f0b94e
                            int32_t *port) override;
Packit f0b94e
Packit f0b94e
  void ParseAfterScheme(const char *spec, int32_t specLen, uint32_t *authPos,
Packit f0b94e
                        int32_t *authLen, uint32_t *pathPos,
Packit f0b94e
                        int32_t *pathLen) override;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
// an url parser for urls that must have an authority section
Packit f0b94e
//
Packit f0b94e
// eg. http:www.foo.com/bar.html
Packit f0b94e
//     http:/www.foo.com/bar.html
Packit f0b94e
//     http://www.foo.com/bar.html    (treated equivalently)
Packit f0b94e
//     http:///www.foo.com/bar.html
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
Packit f0b94e
class nsAuthURLParser : public nsBaseURLParser {
Packit f0b94e
 protected:
Packit f0b94e
  virtual ~nsAuthURLParser() {}
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_THREADSAFE_ISUPPORTS
Packit f0b94e
Packit f0b94e
  NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
Packit f0b94e
                            uint32_t *usernamePos, int32_t *usernameLen,
Packit f0b94e
                            uint32_t *passwordPos, int32_t *passwordLen,
Packit f0b94e
                            uint32_t *hostnamePos, int32_t *hostnameLen,
Packit f0b94e
                            int32_t *port) override;
Packit f0b94e
Packit f0b94e
  NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen,
Packit f0b94e
                           uint32_t *usernamePos, int32_t *usernameLen,
Packit f0b94e
                           uint32_t *passwordPos,
Packit f0b94e
                           int32_t *passwordLen) override;
Packit f0b94e
Packit f0b94e
  NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
Packit f0b94e
                             uint32_t *hostnamePos, int32_t *hostnameLen,
Packit f0b94e
                             int32_t *port) override;
Packit f0b94e
Packit f0b94e
  void ParseAfterScheme(const char *spec, int32_t specLen, uint32_t *authPos,
Packit f0b94e
                        int32_t *authLen, uint32_t *pathPos,
Packit f0b94e
                        int32_t *pathLen) override;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
// an url parser for urls that may or may not have an authority section
Packit f0b94e
//
Packit f0b94e
// eg. http:www.foo.com              (www.foo.com is authority)
Packit f0b94e
//     http:www.foo.com/bar.html     (www.foo.com is authority)
Packit f0b94e
//     http:/www.foo.com/bar.html    (www.foo.com is part of file path)
Packit f0b94e
//     http://www.foo.com/bar.html   (www.foo.com is authority)
Packit f0b94e
//     http:///www.foo.com/bar.html  (www.foo.com is part of file path)
Packit f0b94e
//----------------------------------------------------------------------------
Packit f0b94e
Packit f0b94e
class nsStdURLParser : public nsAuthURLParser {
Packit f0b94e
  virtual ~nsStdURLParser() {}
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  void ParseAfterScheme(const char *spec, int32_t specLen, uint32_t *authPos,
Packit f0b94e
                        int32_t *authLen, uint32_t *pathPos,
Packit f0b94e
                        int32_t *pathLen) override;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
#endif  // nsURLParsers_h__