nsURLParsers.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/. */
  5. #ifndef nsURLParsers_h__
  6. #define nsURLParsers_h__
  7. #include "nsIURLParser.h"
  8. #include "mozilla/Attributes.h"
  9. //----------------------------------------------------------------------------
  10. // base class for url parsers
  11. //----------------------------------------------------------------------------
  12. class nsBaseURLParser : public nsIURLParser
  13. {
  14. public:
  15. NS_DECL_NSIURLPARSER
  16. nsBaseURLParser() { }
  17. protected:
  18. // implemented by subclasses
  19. virtual void ParseAfterScheme(const char *spec, int32_t specLen,
  20. uint32_t *authPos, int32_t *authLen,
  21. uint32_t *pathPos, int32_t *pathLen) = 0;
  22. };
  23. //----------------------------------------------------------------------------
  24. // an url parser for urls that do not have an authority section
  25. //
  26. // eg. file:foo/bar.txt
  27. // file:/foo/bar.txt (treated equivalently)
  28. // file:///foo/bar.txt
  29. //
  30. // eg. file:////foo/bar.txt (UNC-filepath = \\foo\bar.txt)
  31. //
  32. // XXX except in this case:
  33. // file://foo/bar.txt (the authority "foo" is ignored)
  34. //----------------------------------------------------------------------------
  35. class nsNoAuthURLParser final : public nsBaseURLParser
  36. {
  37. ~nsNoAuthURLParser() {}
  38. public:
  39. NS_DECL_THREADSAFE_ISUPPORTS
  40. #if defined(XP_WIN)
  41. NS_IMETHOD ParseFilePath(const char *, int32_t,
  42. uint32_t *, int32_t *,
  43. uint32_t *, int32_t *,
  44. uint32_t *, int32_t *) override;
  45. #endif
  46. NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
  47. uint32_t *usernamePos, int32_t *usernameLen,
  48. uint32_t *passwordPos, int32_t *passwordLen,
  49. uint32_t *hostnamePos, int32_t *hostnameLen,
  50. int32_t *port) override;
  51. void ParseAfterScheme(const char *spec, int32_t specLen,
  52. uint32_t *authPos, int32_t *authLen,
  53. uint32_t *pathPos, int32_t *pathLen) override;
  54. };
  55. //----------------------------------------------------------------------------
  56. // an url parser for urls that must have an authority section
  57. //
  58. // eg. http:www.foo.com/bar.html
  59. // http:/www.foo.com/bar.html
  60. // http://www.foo.com/bar.html (treated equivalently)
  61. // http:///www.foo.com/bar.html
  62. //----------------------------------------------------------------------------
  63. class nsAuthURLParser : public nsBaseURLParser
  64. {
  65. protected:
  66. virtual ~nsAuthURLParser() {}
  67. public:
  68. NS_DECL_THREADSAFE_ISUPPORTS
  69. NS_IMETHOD ParseAuthority(const char *auth, int32_t authLen,
  70. uint32_t *usernamePos, int32_t *usernameLen,
  71. uint32_t *passwordPos, int32_t *passwordLen,
  72. uint32_t *hostnamePos, int32_t *hostnameLen,
  73. int32_t *port) override;
  74. NS_IMETHOD ParseUserInfo(const char *userinfo, int32_t userinfoLen,
  75. uint32_t *usernamePos, int32_t *usernameLen,
  76. uint32_t *passwordPos, int32_t *passwordLen) override;
  77. NS_IMETHOD ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
  78. uint32_t *hostnamePos, int32_t *hostnameLen,
  79. int32_t *port) override;
  80. void ParseAfterScheme(const char *spec, int32_t specLen,
  81. uint32_t *authPos, int32_t *authLen,
  82. uint32_t *pathPos, int32_t *pathLen) override;
  83. };
  84. //----------------------------------------------------------------------------
  85. // an url parser for urls that may or may not have an authority section
  86. //
  87. // eg. http:www.foo.com (www.foo.com is authority)
  88. // http:www.foo.com/bar.html (www.foo.com is authority)
  89. // http:/www.foo.com/bar.html (www.foo.com is part of file path)
  90. // http://www.foo.com/bar.html (www.foo.com is authority)
  91. // http:///www.foo.com/bar.html (www.foo.com is part of file path)
  92. //----------------------------------------------------------------------------
  93. class nsStdURLParser : public nsAuthURLParser
  94. {
  95. virtual ~nsStdURLParser() {}
  96. public:
  97. void ParseAfterScheme(const char *spec, int32_t specLen,
  98. uint32_t *authPos, int32_t *authLen,
  99. uint32_t *pathPos, int32_t *pathLen);
  100. };
  101. #endif // nsURLParsers_h__