llmessagetemplate.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**
  2. * @file llmessagetemplate.cpp
  3. * @brief Implementation of message template classes.
  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. #include "linden_common.h"
  33. #include "llmessagetemplate.h"
  34. #include "llmessage.h"
  35. void LLMsgVarData::addData(const void* data, S32 size, EMsgVariableType type,
  36. S32 data_size)
  37. {
  38. mSize = size;
  39. mDataSize = data_size;
  40. if (type != MVT_VARIABLE && type != MVT_FIXED && mType != MVT_VARIABLE &&
  41. mType != MVT_FIXED)
  42. {
  43. if (mType != type)
  44. {
  45. llwarns << "Type mismatch for " << mName << " - Expected type: "
  46. << variableTypeToString(mType) << " - Passed type: "
  47. << variableTypeToString(type) << llendl;
  48. }
  49. }
  50. if (size)
  51. {
  52. delete[] mData; // Delete it if it already exists
  53. mData = new U8[size];
  54. htonmemcpy(mData, data, mType, size);
  55. }
  56. }
  57. void LLMsgData::addDataFast(char* blockname, char* varname, const void* data,
  58. S32 size, EMsgVariableType type, S32 data_size)
  59. {
  60. // remember that if the blocknumber is > 0 then the number is appended to
  61. // the name
  62. char* namep = (char*)blockname;
  63. LLMsgBlkData* block_data = mMemberBlocks[namep];
  64. if (block_data->mBlockNumber)
  65. {
  66. namep += block_data->mBlockNumber;
  67. block_data->addData(varname, data, size, type, data_size);
  68. }
  69. else
  70. {
  71. block_data->addData(varname, data, size, type, data_size);
  72. }
  73. }
  74. //static
  75. std::string LLMsgVarData::variableTypeToString(EMsgVariableType type)
  76. {
  77. #define RTNENUM(E) case E: return #E
  78. switch (type)
  79. {
  80. RTNENUM(MVT_NULL);
  81. RTNENUM(MVT_FIXED);
  82. RTNENUM(MVT_VARIABLE);
  83. RTNENUM(MVT_U8);
  84. RTNENUM(MVT_U16);
  85. RTNENUM(MVT_U32);
  86. RTNENUM(MVT_U64);
  87. RTNENUM(MVT_S8);
  88. RTNENUM(MVT_S16);
  89. RTNENUM(MVT_S32);
  90. RTNENUM(MVT_S64);
  91. RTNENUM(MVT_F32);
  92. RTNENUM(MVT_F64);
  93. RTNENUM(MVT_LLVector3);
  94. RTNENUM(MVT_LLVector3d);
  95. RTNENUM(MVT_LLVector4);
  96. RTNENUM(MVT_LLQuaternion);
  97. RTNENUM(MVT_LLUUID);
  98. RTNENUM(MVT_BOOL);
  99. RTNENUM(MVT_IP_ADDR);
  100. RTNENUM(MVT_IP_PORT);
  101. RTNENUM(MVT_U16Vec3);
  102. RTNENUM(MVT_U16Quat);
  103. RTNENUM(MVT_S16Array);
  104. default:
  105. return llformat("%d", (S32)type);
  106. }
  107. #undef RTNENUM
  108. }
  109. // LLMessageVariable functions and friends
  110. std::ostream& operator<<(std::ostream& s, LLMessageVariable& msg)
  111. {
  112. s << "\t\t" << msg.mName << " (";
  113. switch (msg.mType)
  114. {
  115. case MVT_FIXED:
  116. s << "Fixed, " << msg.mSize << " bytes total)\n";
  117. break;
  118. case MVT_VARIABLE:
  119. s << "Variable, " << msg.mSize << " bytes of size info)\n";
  120. break;
  121. default:
  122. s << "Unknown\n";
  123. break;
  124. }
  125. return s;
  126. }
  127. // LLMessageBlock functions and friends
  128. std::ostream& operator<<(std::ostream& s, LLMessageBlock& msg)
  129. {
  130. s << "\t" << msg.mName << " (";
  131. switch (msg.mType)
  132. {
  133. case MBT_SINGLE:
  134. s << "Fixed";
  135. break;
  136. case MBT_MULTIPLE:
  137. s << "Multiple - " << msg.mNumber << " copies";
  138. break;
  139. case MBT_VARIABLE:
  140. s << "Variable";
  141. break;
  142. default:
  143. s << "Unknown";
  144. break;
  145. }
  146. if (msg.mTotalSize != -1)
  147. {
  148. s << ", " << msg.mTotalSize << " bytes each, "
  149. << msg.mNumber * msg.mTotalSize << " bytes total)\n";
  150. }
  151. else
  152. {
  153. s << ")\n";
  154. }
  155. for (LLMessageBlock::message_variable_map_t::iterator
  156. iter = msg.mMemberVariables.begin(),
  157. end = msg.mMemberVariables.end();
  158. iter != end; ++iter)
  159. {
  160. LLMessageVariable& ci = *(*iter);
  161. s << ci;
  162. }
  163. return s;
  164. }
  165. // LLMessageTemplate functions and friends
  166. std::ostream& operator<<(std::ostream& s, LLMessageTemplate& msg)
  167. {
  168. switch (msg.mFrequency)
  169. {
  170. case MFT_HIGH:
  171. s << "========================================\n" << "Message #"
  172. << msg.mMessageNumber << "\n" << msg.mName << " (";
  173. s << "High";
  174. break;
  175. case MFT_MEDIUM:
  176. s << "========================================\n" << "Message #";
  177. s << (msg.mMessageNumber & 0xFF) << "\n" << msg.mName << " (";
  178. s << "Medium";
  179. break;
  180. case MFT_LOW:
  181. s << "========================================\n" << "Message #";
  182. s << (msg.mMessageNumber & 0xFFFF) << "\n" << msg.mName << " (";
  183. s << "Low";
  184. break;
  185. default:
  186. s << "Unknown";
  187. break;
  188. }
  189. if (msg.mTotalSize != -1)
  190. {
  191. s << ", " << msg.mTotalSize << " bytes total)\n";
  192. }
  193. else
  194. {
  195. s << ")\n";
  196. }
  197. for (LLMessageTemplate::message_block_map_t::iterator
  198. iter = msg.mMemberBlocks.begin(), end = msg.mMemberBlocks.end();
  199. iter != end; ++iter)
  200. {
  201. LLMessageBlock* ci = *iter;
  202. s << *ci;
  203. }
  204. return s;
  205. }
  206. void LLMessageTemplate::banUdp()
  207. {
  208. static const char* deprecation[] = {
  209. "NotDeprecated",
  210. "Deprecated",
  211. "UDPDeprecated",
  212. "UDPBlackListed"
  213. };
  214. if (mDeprecation != MD_DEPRECATED)
  215. {
  216. llinfos << "Setting " << mName << " to UDPBlackListed was "
  217. << deprecation[mDeprecation] << llendl;
  218. mDeprecation = MD_UDPBLACKLISTED;
  219. }
  220. else
  221. {
  222. llinfos << mName << " is already more deprecated than UDPBlackListed"
  223. << llendl;
  224. }
  225. }