llcorehttpopsetget.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * @file llcorehttpopsetget.cpp
  3. * @brief Definitions for internal class HttpOpSetGet
  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 "llcorehttpopsetget.h"
  28. #include "llcorehttpcommon.h"
  29. #include "llcorehttppolicy.h"
  30. #include "llcorehttpservice.h"
  31. namespace LLCore
  32. {
  33. // ==================================
  34. // HttpOpSetget
  35. // ==================================
  36. HttpOpSetGet::HttpOpSetGet()
  37. : HttpOperation(),
  38. mReqOption(HttpRequest::PO_CONNECTION_LIMIT),
  39. mReqClass(HttpRequest::INVALID_POLICY_ID),
  40. mReqDoSet(false),
  41. mReqLongValue(0L),
  42. mReplyLongValue(0L)
  43. {
  44. }
  45. HttpStatus HttpOpSetGet::setupGet(HttpRequest::EPolicyOption opt,
  46. HttpRequest::policy_t pclass)
  47. {
  48. HttpStatus status;
  49. mReqOption = opt;
  50. mReqClass = pclass;
  51. return status;
  52. }
  53. HttpStatus HttpOpSetGet::setupSet(HttpRequest::EPolicyOption opt,
  54. HttpRequest::policy_t pclass, long value)
  55. {
  56. HttpStatus status;
  57. if (!HttpService::sOptionDesc[opt].mIsLong)
  58. {
  59. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  60. }
  61. if (!HttpService::sOptionDesc[opt].mIsDynamic)
  62. {
  63. return HttpStatus(HttpStatus::LLCORE, HE_OPT_NOT_DYNAMIC);
  64. }
  65. mReqOption = opt;
  66. mReqClass = pclass;
  67. mReqDoSet = true;
  68. mReqLongValue = value;
  69. return status;
  70. }
  71. HttpStatus HttpOpSetGet::setupSet(HttpRequest::EPolicyOption opt,
  72. HttpRequest::policy_t pclass,
  73. const std::string& value)
  74. {
  75. HttpStatus status;
  76. if (HttpService::sOptionDesc[opt].mIsLong)
  77. {
  78. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  79. }
  80. if (!HttpService::sOptionDesc[opt].mIsDynamic)
  81. {
  82. return HttpStatus(HttpStatus::LLCORE, HE_OPT_NOT_DYNAMIC);
  83. }
  84. mReqOption = opt;
  85. mReqClass = pclass;
  86. mReqDoSet = true;
  87. mReqStrValue = value;
  88. return status;
  89. }
  90. void HttpOpSetGet::stageFromRequest(HttpService* service)
  91. {
  92. if (mReqDoSet)
  93. {
  94. if (HttpService::sOptionDesc[mReqOption].mIsLong)
  95. {
  96. mStatus = service->setPolicyOption(mReqOption, mReqClass,
  97. mReqLongValue,
  98. &mReplyLongValue);
  99. }
  100. else
  101. {
  102. mStatus = service->setPolicyOption(mReqOption, mReqClass,
  103. mReqStrValue, &mReplyStrValue);
  104. }
  105. }
  106. else
  107. {
  108. if (HttpService::sOptionDesc[mReqOption].mIsLong)
  109. {
  110. mStatus = service->getPolicyOption(mReqOption, mReqClass,
  111. &mReplyLongValue);
  112. }
  113. else
  114. {
  115. mStatus = service->getPolicyOption(mReqOption, mReqClass,
  116. &mReplyStrValue);
  117. }
  118. }
  119. addAsReply();
  120. }
  121. } // End namespace LLCore