aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llinstantmessage.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llinstantmessage.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/linden/indra/llmessage/llinstantmessage.cpp b/linden/indra/llmessage/llinstantmessage.cpp
index 6f6e022..0ba7629 100644
--- a/linden/indra/llmessage/llinstantmessage.cpp
+++ b/linden/indra/llmessage/llinstantmessage.cpp
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (c) 2005-2007, Linden Research, Inc. 7 * Copyright (c) 2005-2007, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0 11 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -35,6 +36,7 @@
35#include "lluuid.h" 36#include "lluuid.h"
36#include "llsd.h" 37#include "llsd.h"
37#include "llsdserialize.h" 38#include "llsdserialize.h"
39#include "llsdutil.h"
38#include "llmemory.h" 40#include "llmemory.h"
39#include "message.h" 41#include "message.h"
40 42
@@ -226,8 +228,21 @@ void pack_instant_message_block(
226 S32 bytes_left = MTUBYTES; 228 S32 bytes_left = MTUBYTES;
227 if(message) 229 if(message)
228 { 230 {
229 char buffer[MTUBYTES]; /*Flawfinder: ignore*/ 231 char buffer[MTUBYTES];
230 bytes_left -= snprintf(buffer, MTUBYTES, "%s", message); /*Flawfinder: ignore*/ 232 int num_written = snprintf(buffer, MTUBYTES, "%s", message); /* Flawfinder: ignore */
233 // snprintf returns number of bytes that would have been written
234 // had the output not being truncated. In that case, it will
235 // return either -1 or value >= passed in size value . So a check needs to be added
236 // to detect truncation, and if there is any, only account for the
237 // actual number of bytes written..and not what could have been
238 // written.
239 if (num_written < 0 || num_written >= MTUBYTES)
240 {
241 num_written = MTUBYTES - 1;
242 llwarns << "pack_instant_message_block: message truncated: " << message << llendl;
243 }
244
245 bytes_left -= num_written;
231 bytes_left = llmax(0, bytes_left); 246 bytes_left = llmax(0, bytes_left);
232 msg->addStringFast(_PREHASH_Message, buffer); 247 msg->addStringFast(_PREHASH_Message, buffer);
233 } 248 }
@@ -296,6 +311,35 @@ void LLIMInfo::unpackMessageBlock(LLMessageSystem* msg)
296 } 311 }
297} 312}
298 313
314LLSD im_info_to_llsd(LLPointer<LLIMInfo> im_info)
315{
316 LLSD param_version;
317 param_version["version"] = 1;
318 LLSD param_message;
319 param_message["from_id"] = im_info->mFromID;
320 param_message["from_group"] = im_info->mFromGroup;
321 param_message["to_id"] = im_info->mToID;
322 param_message["from_name"] = im_info->mName;
323 param_message["message"] = im_info->mMessage;
324 param_message["type"] = (S32)im_info->mIMType;
325 param_message["id"] = im_info->mID;
326 param_message["timestamp"] = (S32)im_info->mTimeStamp;
327 param_message["offline"] = (S32)im_info->mOffline;
328 param_message["parent_estate_id"] = (S32)im_info->mParentEstateID;
329 param_message["region_id"] = im_info->mRegionID;
330 param_message["position"] = ll_sd_from_vector3(im_info->mPosition);
331 if (im_info->mData) param_message["data"] = im_info->mData;
332 LLSD param_agent;
333 param_agent["agent_id"] = im_info->mFromID;
334
335 LLSD params;
336 params.append(param_version);
337 params.append(param_message);
338 params.append(param_agent);
339
340 return params;
341}
342
299LLPointer<LLIMInfo> LLIMInfo::clone() 343LLPointer<LLIMInfo> LLIMInfo::clone()
300{ 344{
301 return new LLIMInfo( 345 return new LLIMInfo(