nsProxyInfo.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 sts=2 et cindent: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsProxyInfo.h"
  7. #include "nsCOMPtr.h"
  8. namespace mozilla {
  9. namespace net {
  10. // Yes, we support QI to nsProxyInfo
  11. NS_IMPL_ISUPPORTS(nsProxyInfo, nsProxyInfo, nsIProxyInfo)
  12. NS_IMETHODIMP
  13. nsProxyInfo::GetHost(nsACString &result)
  14. {
  15. result = mHost;
  16. return NS_OK;
  17. }
  18. NS_IMETHODIMP
  19. nsProxyInfo::GetPort(int32_t *result)
  20. {
  21. *result = mPort;
  22. return NS_OK;
  23. }
  24. NS_IMETHODIMP
  25. nsProxyInfo::GetType(nsACString &result)
  26. {
  27. result = mType;
  28. return NS_OK;
  29. }
  30. NS_IMETHODIMP
  31. nsProxyInfo::GetFlags(uint32_t *result)
  32. {
  33. *result = mFlags;
  34. return NS_OK;
  35. }
  36. NS_IMETHODIMP
  37. nsProxyInfo::GetResolveFlags(uint32_t *result)
  38. {
  39. *result = mResolveFlags;
  40. return NS_OK;
  41. }
  42. NS_IMETHODIMP
  43. nsProxyInfo::GetUsername(nsACString &result)
  44. {
  45. result = mUsername;
  46. return NS_OK;
  47. }
  48. NS_IMETHODIMP
  49. nsProxyInfo::GetPassword(nsACString &result)
  50. {
  51. result = mPassword;
  52. return NS_OK;
  53. }
  54. NS_IMETHODIMP
  55. nsProxyInfo::GetFailoverTimeout(uint32_t *result)
  56. {
  57. *result = mTimeout;
  58. return NS_OK;
  59. }
  60. NS_IMETHODIMP
  61. nsProxyInfo::GetFailoverProxy(nsIProxyInfo **result)
  62. {
  63. NS_IF_ADDREF(*result = mNext);
  64. return NS_OK;
  65. }
  66. NS_IMETHODIMP
  67. nsProxyInfo::SetFailoverProxy(nsIProxyInfo *proxy)
  68. {
  69. nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(proxy);
  70. NS_ENSURE_ARG(pi);
  71. pi.swap(mNext);
  72. return NS_OK;
  73. }
  74. // These pointers are declared in nsProtocolProxyService.cpp and
  75. // comparison of mType by string pointer is valid within necko
  76. extern const char kProxyType_HTTP[];
  77. extern const char kProxyType_HTTPS[];
  78. extern const char kProxyType_SOCKS[];
  79. extern const char kProxyType_SOCKS4[];
  80. extern const char kProxyType_SOCKS5[];
  81. extern const char kProxyType_DIRECT[];
  82. bool
  83. nsProxyInfo::IsDirect()
  84. {
  85. if (!mType)
  86. return true;
  87. return mType == kProxyType_DIRECT;
  88. }
  89. bool
  90. nsProxyInfo::IsHTTP()
  91. {
  92. return mType == kProxyType_HTTP;
  93. }
  94. bool
  95. nsProxyInfo::IsHTTPS()
  96. {
  97. return mType == kProxyType_HTTPS;
  98. }
  99. bool
  100. nsProxyInfo::IsSOCKS()
  101. {
  102. return mType == kProxyType_SOCKS ||
  103. mType == kProxyType_SOCKS4 || mType == kProxyType_SOCKS5;
  104. }
  105. } // namespace net
  106. } // namespace mozilla