aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lldispatcher.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lldispatcher.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmessage/lldispatcher.cpp')
-rw-r--r--linden/indra/llmessage/lldispatcher.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lldispatcher.cpp b/linden/indra/llmessage/lldispatcher.cpp
new file mode 100644
index 0000000..cf83079
--- /dev/null
+++ b/linden/indra/llmessage/lldispatcher.cpp
@@ -0,0 +1,145 @@
1/**
2 * @file lldispatcher.cpp
3 * @brief Implementation of the dispatcher object.
4 *
5 * Copyright (c) 2004-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29
30#include "lldispatcher.h"
31
32#include <algorithm>
33#include "llstl.h"
34#include "message.h"
35
36///----------------------------------------------------------------------------
37/// Class lldispatcher
38///----------------------------------------------------------------------------
39
40
41LLDispatcher::LLDispatcher()
42{
43}
44
45LLDispatcher::~LLDispatcher()
46{
47}
48
49bool LLDispatcher::isHandlerPresent(const key_t& name) const
50{
51 if(mHandlers.find(name) != mHandlers.end())
52 {
53 return true;
54 }
55 return false;
56}
57
58void LLDispatcher::copyAllHandlerNames(keys_t& names) const
59{
60 // copy the names onto the vector we are given
61 std::transform(
62 mHandlers.begin(),
63 mHandlers.end(),
64 std::back_insert_iterator<keys_t>(names),
65 llselect1st<dispatch_map_t::value_type>());
66}
67
68bool LLDispatcher::dispatch(
69 const key_t& name,
70 const LLUUID& invoice,
71 const sparam_t& strings) const
72{
73 dispatch_map_t::const_iterator it = mHandlers.find(name);
74 if(it != mHandlers.end())
75 {
76 LLDispatchHandler* func = (*it).second;
77 return (*func)(this, name, invoice, strings);
78 }
79 return false;
80}
81
82LLDispatchHandler* LLDispatcher::addHandler(
83 const key_t& name, LLDispatchHandler* func)
84{
85 dispatch_map_t::iterator it = mHandlers.find(name);
86 LLDispatchHandler* old_handler = NULL;
87 if(it != mHandlers.end())
88 {
89 old_handler = (*it).second;
90 mHandlers.erase(it);
91 }
92 if(func)
93 {
94 // only non-null handlers so that we don't have to worry about
95 // it later.
96 mHandlers.insert(dispatch_map_t::value_type(name, func));
97 }
98 return old_handler;
99}
100
101// static
102bool LLDispatcher::unpackMessage(
103 LLMessageSystem* msg,
104 LLDispatcher::key_t& method,
105 LLUUID& invoice,
106 LLDispatcher::sparam_t& parameters)
107{
108 char buf[MAX_STRING]; /*Flawfinder: ignore*/
109 msg->getStringFast(_PREHASH_MethodData, _PREHASH_Method, MAX_STRING, buf);
110 method.assign(buf);
111 msg->getUUIDFast(_PREHASH_MethodData, _PREHASH_Invoice, invoice);
112 S32 size;
113 S32 count = msg->getNumberOfBlocksFast(_PREHASH_ParamList);
114 for (S32 i = 0; i < count; ++i)
115 {
116 // we treat the SParam as binary data (since it might be an
117 // LLUUID in compressed form which may have embedded \0's,)
118 size = msg->getSizeFast(_PREHASH_ParamList, i, _PREHASH_Parameter);
119 msg->getBinaryDataFast(
120 _PREHASH_ParamList, _PREHASH_Parameter,
121 buf, size, i, MAX_STRING-1);
122
123 // If the last byte of the data is 0x0, this is either a normally
124 // packed string, or a binary packed UUID (which for these messages
125 // are packed with a 17th byte 0x0). Unpack into a std::string
126 // without the trailing \0, so "abc\0" becomes std::string("abc", 3)
127 // which matches const char* "abc".
128 if (size > 0
129 && buf[size-1] == 0x0)
130 {
131 // special char*/size constructor because UUIDs may have embedded
132 // 0x0 bytes.
133 std::string binary_data(buf, size-1);
134 parameters.push_back(binary_data);
135 }
136 else
137 {
138 // This is either a NULL string, or a string that was packed
139 // incorrectly as binary data, without the usual trailing '\0'.
140 std::string string_data(buf, size);
141 parameters.push_back(string_data);
142 }
143 }
144 return true;
145}