llinstantmessage.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @file llinstantmessage.cpp
  3. * @author Phoenix
  4. * @date 2005-08-29
  5. * @brief Constants and functions used in IM.
  6. *
  7. * $LicenseInfo:firstyear=2005&license=viewergpl$
  8. *
  9. * Copyright (c) 2005-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #include "linden_common.h"
  35. #include "llinstantmessage.h"
  36. #include "llmessage.h"
  37. const char EMPTY_BINARY_BUCKET[] = "";
  38. const std::string SYSTEM_FROM("Second Life");
  39. const std::string INCOMING_IM("Incoming IM");
  40. const std::string INTERACTIVE_SYSTEM_FROM("F387446C-37C4-45f2-A438-D99CBDBB563B");
  41. void pack_instant_message(const LLUUID& from_id, bool from_group,
  42. const LLUUID& session_id, const LLUUID& to_id,
  43. const std::string& name, const std::string& message,
  44. U8 offline, EInstantMessage dialog, const LLUUID& id,
  45. U32 parent_estate_id, const LLUUID& region_id,
  46. const LLVector3& position, U32 timestamp,
  47. const U8* binary_bucket, S32 binary_bucket_size)
  48. {
  49. LLMessageSystem* msg = gMessageSystemp;
  50. if (!msg) return;
  51. msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
  52. msg->nextBlockFast(_PREHASH_AgentData);
  53. msg->addUUIDFast(_PREHASH_AgentID, from_id);
  54. msg->addUUIDFast(_PREHASH_SessionID, session_id);
  55. msg->nextBlockFast(_PREHASH_MessageBlock);
  56. msg->addBoolFast(_PREHASH_FromGroup, from_group);
  57. msg->addUUIDFast(_PREHASH_ToAgentID, to_id);
  58. msg->addU32Fast(_PREHASH_ParentEstateID, parent_estate_id);
  59. msg->addUUIDFast(_PREHASH_RegionID, region_id);
  60. msg->addVector3Fast(_PREHASH_Position, position);
  61. msg->addU8Fast(_PREHASH_Offline, offline);
  62. msg->addU8Fast(_PREHASH_Dialog, (U8) dialog);
  63. msg->addUUIDFast(_PREHASH_ID, id);
  64. msg->addU32Fast(_PREHASH_Timestamp, timestamp);
  65. msg->addStringFast(_PREHASH_FromAgentName, name);
  66. S32 bytes_left = MTUBYTES;
  67. if (!message.empty())
  68. {
  69. char buffer[MTUBYTES];
  70. int num_written = snprintf(buffer, MTUBYTES, "%s", message.c_str());
  71. // snprintf returns number of bytes that would have been written had
  72. // the output not being truncated. In that case, it will return either
  73. // -1 or value >= passed in size value . So a check needs to be added
  74. // to detect truncation, and if there is any, only account for the
  75. // actual number of bytes written..and not what could have been
  76. // written.
  77. if (num_written < 0 || num_written >= MTUBYTES)
  78. {
  79. num_written = MTUBYTES - 1;
  80. llwarns << "message truncated: " << message << llendl;
  81. }
  82. bytes_left -= num_written;
  83. bytes_left = llmax(0, bytes_left);
  84. msg->addStringFast(_PREHASH_Message, buffer);
  85. }
  86. else
  87. {
  88. msg->addStringFast(_PREHASH_Message, NULL);
  89. }
  90. const U8* bb;
  91. if (binary_bucket)
  92. {
  93. bb = binary_bucket;
  94. binary_bucket_size = llmin(bytes_left, binary_bucket_size);
  95. }
  96. else
  97. {
  98. bb = (const U8*)EMPTY_BINARY_BUCKET;
  99. binary_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
  100. }
  101. msg->addBinaryDataFast(_PREHASH_BinaryBucket, bb, binary_bucket_size);
  102. }
  103. std::string im_status_to_string(EInstantMessage status)
  104. {
  105. std::string result = "UNKNOWN";
  106. // Prevent copy-paste errors when updating this list...
  107. #define CASE(x) case x: result = #x; break
  108. switch (status)
  109. {
  110. CASE(IM_NOTHING_SPECIAL);
  111. CASE(IM_MESSAGEBOX);
  112. CASE(IM_GROUP_INVITATION);
  113. CASE(IM_INVENTORY_OFFERED);
  114. CASE(IM_INVENTORY_ACCEPTED);
  115. CASE(IM_INVENTORY_DECLINED);
  116. CASE(IM_GROUP_VOTE);
  117. CASE(IM_GROUP_MESSAGE_DEPRECATED);
  118. CASE(IM_TASK_INVENTORY_OFFERED);
  119. CASE(IM_TASK_INVENTORY_ACCEPTED);
  120. CASE(IM_TASK_INVENTORY_DECLINED);
  121. CASE(IM_NEW_USER_DEFAULT);
  122. CASE(IM_SESSION_INVITE);
  123. CASE(IM_SESSION_P2P_INVITE);
  124. CASE(IM_SESSION_GROUP_START);
  125. CASE(IM_SESSION_CONFERENCE_START);
  126. CASE(IM_SESSION_SEND);
  127. CASE(IM_SESSION_LEAVE);
  128. CASE(IM_FROM_TASK);
  129. CASE(IM_BUSY_AUTO_RESPONSE);
  130. CASE(IM_CONSOLE_AND_CHAT_HISTORY);
  131. CASE(IM_LURE_USER);
  132. CASE(IM_LURE_ACCEPTED);
  133. CASE(IM_LURE_DECLINED);
  134. CASE(IM_GODLIKE_LURE_USER);
  135. CASE(IM_TELEPORT_REQUEST);
  136. CASE(IM_GROUP_ELECTION_DEPRECATED);
  137. CASE(IM_GOTO_URL);
  138. CASE(IM_FROM_TASK_AS_ALERT);
  139. CASE(IM_GROUP_NOTICE);
  140. CASE(IM_GROUP_NOTICE_INVENTORY_ACCEPTED);
  141. CASE(IM_GROUP_NOTICE_INVENTORY_DECLINED);
  142. CASE(IM_GROUP_INVITATION_ACCEPT);
  143. CASE(IM_GROUP_INVITATION_DECLINE);
  144. CASE(IM_GROUP_NOTICE_REQUESTED);
  145. CASE(IM_FRIENDSHIP_OFFERED);
  146. CASE(IM_FRIENDSHIP_ACCEPTED);
  147. CASE(IM_FRIENDSHIP_DECLINED_DEPRECATED);
  148. CASE(IM_TYPING_START);
  149. CASE(IM_TYPING_STOP);
  150. default:
  151. break;
  152. }
  153. #undef CASE
  154. return result;
  155. }