llcorehttppolicyglobal.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @file llcorehttppolicyglobal.cpp
  3. * @brief Definitions for internal class defining global policy option.
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2012, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llcorehttppolicyglobal.h"
  28. #include "llcorehttpinternal.h"
  29. namespace LLCore
  30. {
  31. HttpPolicyGlobal::HttpPolicyGlobal()
  32. : mConnectionLimit(HTTP_CONNECTION_LIMIT_DEFAULT),
  33. mTrace(HTTP_TRACE_OFF),
  34. mUseLLProxy(0)
  35. {
  36. }
  37. HttpPolicyGlobal& HttpPolicyGlobal::operator=(const HttpPolicyGlobal& other)
  38. {
  39. if (this != &other)
  40. {
  41. mConnectionLimit = other.mConnectionLimit;
  42. mCAPath = other.mCAPath;
  43. mCAFile = other.mCAFile;
  44. mHttpProxy = other.mHttpProxy;
  45. mTrace = other.mTrace;
  46. mUseLLProxy = other.mUseLLProxy;
  47. }
  48. return *this;
  49. }
  50. HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt, long value)
  51. {
  52. switch (opt)
  53. {
  54. case HttpRequest::PO_CONNECTION_LIMIT:
  55. mConnectionLimit = llclamp(value, long(HTTP_CONNECTION_LIMIT_MIN),
  56. long(HTTP_CONNECTION_LIMIT_MAX));
  57. break;
  58. case HttpRequest::PO_TRACE:
  59. mTrace = llclamp(value, long(HTTP_TRACE_MIN), long(HTTP_TRACE_MAX));
  60. break;
  61. case HttpRequest::PO_LLPROXY:
  62. mUseLLProxy = llclamp(value, 0L, 1L);
  63. break;
  64. default:
  65. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  66. }
  67. return HttpStatus();
  68. }
  69. HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt,
  70. const std::string& value)
  71. {
  72. switch (opt)
  73. {
  74. case HttpRequest::PO_CA_PATH:
  75. mCAPath = value;
  76. break;
  77. case HttpRequest::PO_CA_FILE:
  78. mCAFile = value;
  79. break;
  80. case HttpRequest::PO_HTTP_PROXY:
  81. mCAFile = value;
  82. break;
  83. default:
  84. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  85. }
  86. return HttpStatus();
  87. }
  88. HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt,
  89. HttpRequest::policyCallback_t value)
  90. {
  91. switch (opt)
  92. {
  93. case HttpRequest::PO_SSL_VERIFY_CALLBACK:
  94. mSslCtxCallback = value;
  95. break;
  96. default:
  97. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  98. }
  99. return HttpStatus();
  100. }
  101. HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt,
  102. long* value) const
  103. {
  104. switch (opt)
  105. {
  106. case HttpRequest::PO_CONNECTION_LIMIT:
  107. *value = mConnectionLimit;
  108. break;
  109. case HttpRequest::PO_TRACE:
  110. *value = mTrace;
  111. break;
  112. case HttpRequest::PO_LLPROXY:
  113. *value = mUseLLProxy;
  114. break;
  115. default:
  116. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  117. }
  118. return HttpStatus();
  119. }
  120. HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt,
  121. std::string* value) const
  122. {
  123. switch (opt)
  124. {
  125. case HttpRequest::PO_CA_PATH:
  126. *value = mCAPath;
  127. break;
  128. case HttpRequest::PO_CA_FILE:
  129. *value = mCAFile;
  130. break;
  131. case HttpRequest::PO_HTTP_PROXY:
  132. *value = mHttpProxy;
  133. break;
  134. default:
  135. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  136. }
  137. return HttpStatus();
  138. }
  139. HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt,
  140. HttpRequest::policyCallback_t* value) const
  141. {
  142. switch (opt)
  143. {
  144. case HttpRequest::PO_SSL_VERIFY_CALLBACK:
  145. *value = mSslCtxCallback;
  146. break;
  147. default:
  148. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  149. }
  150. return HttpStatus();
  151. }
  152. } // End namespace LLCore