lltemplatemessagereader.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * @file lltemplatemessagereader.h
  3. * @brief Declaration of LLTemplateMessageReader class.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLTEMPLATEMESSAGEREADER_H
  33. #define LL_LLTEMPLATEMESSAGEREADER_H
  34. #include "hbfastmap.h"
  35. #include "llmessagereader.h"
  36. class LLMessageTemplate;
  37. class LLMsgData;
  38. class LLTemplateMessageReader final : public LLMessageReader
  39. {
  40. protected:
  41. LOG_CLASS(LLTemplateMessageReader);
  42. public:
  43. typedef fast_hmap<U32, LLMessageTemplate*> template_number_map_t;
  44. LLTemplateMessageReader(template_number_map_t&);
  45. ~LLTemplateMessageReader() override;
  46. // All get* methods expect pointers to canonical strings
  47. void getBinaryData(const char* blockname, const char* varname, void* datap,
  48. S32 size, S32 blocknum = 0,
  49. S32 max_size = S32_MAX) override;
  50. void getBool(const char* block, const char* var, bool& data,
  51. S32 blocknum = 0) override;
  52. void getS8(const char* block, const char* var, S8& data,
  53. S32 blocknum = 0) override;
  54. void getU8(const char* block, const char* var, U8& data,
  55. S32 blocknum = 0) override;
  56. void getS16(const char* block, const char* var, S16& data,
  57. S32 blocknum = 0) override;
  58. void getU16(const char* block, const char* var, U16& data,
  59. S32 blocknum = 0) override;
  60. void getS32(const char* block, const char* var, S32& data,
  61. S32 blocknum = 0) override;
  62. void getF32(const char* block, const char* var, F32& data,
  63. S32 blocknum = 0) override;
  64. void getU32(const char* block, const char* var, U32& data,
  65. S32 blocknum = 0) override;
  66. void getU64(const char* block, const char* var, U64& data,
  67. S32 blocknum = 0) override;
  68. void getF64(const char* block, const char* var, F64& data,
  69. S32 blocknum = 0) override;
  70. void getVector3(const char* block, const char* var, LLVector3& vec,
  71. S32 blocknum = 0) override;
  72. void getVector4(const char* block, const char* var, LLVector4& vec,
  73. S32 blocknum = 0) override;
  74. void getVector3d(const char* block, const char* var, LLVector3d& vec,
  75. S32 blocknum = 0) override;
  76. void getQuat(const char* block, const char* var, LLQuaternion& q,
  77. S32 blocknum = 0) override;
  78. void getUUID(const char* block, const char* var, LLUUID& uuid,
  79. S32 blocknum = 0) override;
  80. void getIPAddr(const char* block, const char* var, U32& ip,
  81. S32 blocknum = 0) override;
  82. void getIPPort(const char* block, const char* var, U16& port,
  83. S32 blocknum = 0) override;
  84. void getString(const char* block, const char* var, S32 buffer_size,
  85. char* buffer, S32 blocknum = 0) override;
  86. void getString(const char* block, const char* var, std::string& outstr,
  87. S32 blocknum = 0) override;
  88. S32 getNumberOfBlocks(const char* blockname) override;
  89. S32 getSize(const char* blockname, const char* varname) override;
  90. S32 getSize(const char* blockname, S32 blocknum,
  91. const char* varname) override;
  92. void clearMessage() override;
  93. const char* getMessageName() const override;
  94. S32 getMessageSize() const override;
  95. void copyToBuilder(LLMessageBuilder&) const override;
  96. bool validateMessage(const U8* buffer, S32 buffer_size,
  97. const LLHost& sender, bool trusted = false);
  98. bool readMessage(const U8* buffer, const LLHost& sender);
  99. bool isTrusted() const;
  100. bool isBanned(bool trusted_source) const;
  101. bool isUdpBanned() const;
  102. private:
  103. void getData(const char* blockname, const char* varname, void* datap,
  104. S32 size = 0, S32 blocknum = 0, S32 max_size = S32_MAX);
  105. bool decodeTemplate(const U8* buffer, S32 buffer_size, // inputs
  106. LLMessageTemplate** msg_template); // outputs
  107. void logRanOffEndOfPacket(const LLHost& host, S32 where, S32 wanted);
  108. bool decodeData(const U8* buffer, const LLHost& sender);
  109. private:
  110. S32 mReceiveSize;
  111. LLMessageTemplate* mCurrentRMessageTemplate;
  112. LLMsgData* mCurrentRMessageData;
  113. template_number_map_t& mMessageNumbers;
  114. };
  115. #endif // LL_LLTEMPLATEMESSAGEREADER_H