diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmessage/llinstantmessage.cpp | 318 |
1 files changed, 318 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llinstantmessage.cpp b/linden/indra/llmessage/llinstantmessage.cpp new file mode 100644 index 0000000..f1f4514 --- /dev/null +++ b/linden/indra/llmessage/llinstantmessage.cpp | |||
@@ -0,0 +1,318 @@ | |||
1 | /** | ||
2 | * @file llinstantmessage.cpp | ||
3 | * @author Phoenix | ||
4 | * @date 2005-08-29 | ||
5 | * @brief Constants and functions used in IM. | ||
6 | * | ||
7 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | |||
32 | #include "lldbstrings.h" | ||
33 | #include "llinstantmessage.h" | ||
34 | #include "llhost.h" | ||
35 | #include "lluuid.h" | ||
36 | #include "llsd.h" | ||
37 | #include "llsdserialize.h" | ||
38 | #include "llmemory.h" | ||
39 | #include "message.h" | ||
40 | |||
41 | #include "message.h" | ||
42 | |||
43 | const U8 IM_ONLINE = 0; | ||
44 | const U8 IM_OFFLINE = 1; | ||
45 | |||
46 | const S32 VOTE_YES = 1; | ||
47 | const S32 VOTE_NO = 0; | ||
48 | const S32 VOTE_ABSTAIN = -1; | ||
49 | |||
50 | const S32 VOTE_MAJORITY = 0; | ||
51 | const S32 VOTE_SUPER_MAJORITY = 1; | ||
52 | const S32 VOTE_UNANIMOUS = 2; | ||
53 | |||
54 | const char EMPTY_BINARY_BUCKET[] = ""; | ||
55 | const S32 EMPTY_BINARY_BUCKET_SIZE = 1; | ||
56 | const U32 NO_TIMESTAMP = 0; | ||
57 | const char SYSTEM_FROM[] = "Second Life"; | ||
58 | const S32 IM_TTL = 1; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * LLIMInfo | ||
63 | */ | ||
64 | LLIMInfo::LLIMInfo() : | ||
65 | mParentEstateID(0), | ||
66 | mOffline(0), | ||
67 | mViewerThinksToIsOnline(false), | ||
68 | mTimeStamp(0), | ||
69 | mSource(IM_FROM_SIM), | ||
70 | mTTL(IM_TTL) | ||
71 | { | ||
72 | } | ||
73 | |||
74 | LLIMInfo::LLIMInfo( | ||
75 | const LLUUID& from_id, | ||
76 | BOOL from_group, | ||
77 | const LLUUID& to_id, | ||
78 | EInstantMessage im_type, | ||
79 | const std::string& name, | ||
80 | const std::string& message, | ||
81 | const LLUUID& id, | ||
82 | U32 parent_estate_id, | ||
83 | const LLUUID& region_id, | ||
84 | const LLVector3& position, | ||
85 | LLSD data, | ||
86 | U8 offline, | ||
87 | U32 timestamp, | ||
88 | EIMSource source, | ||
89 | S32 ttl) : | ||
90 | mFromID(from_id), | ||
91 | mFromGroup(from_group), | ||
92 | mToID(to_id), | ||
93 | mParentEstateID(0), | ||
94 | mRegionID(region_id), | ||
95 | mPosition(position), | ||
96 | mOffline(offline), | ||
97 | mViewerThinksToIsOnline(false), | ||
98 | mIMType(im_type), | ||
99 | mID(id), | ||
100 | mTimeStamp(timestamp), | ||
101 | mName(name), | ||
102 | mMessage(message), | ||
103 | mData(data), | ||
104 | mSource(source), | ||
105 | mTTL(ttl) | ||
106 | { | ||
107 | } | ||
108 | |||
109 | LLIMInfo::LLIMInfo(LLMessageSystem* msg, EIMSource source, S32 ttl) : | ||
110 | mViewerThinksToIsOnline(false), | ||
111 | mSource(source), | ||
112 | mTTL(ttl) | ||
113 | { | ||
114 | unpackMessageBlock(msg); | ||
115 | } | ||
116 | |||
117 | LLIMInfo::~LLIMInfo() | ||
118 | { | ||
119 | } | ||
120 | |||
121 | void LLIMInfo::packInstantMessage(LLMessageSystem* msg) const | ||
122 | { | ||
123 | lldebugs << "LLIMInfo::packInstantMessage()" << llendl; | ||
124 | msg->newMessageFast(_PREHASH_ImprovedInstantMessage); | ||
125 | packMessageBlock(msg); | ||
126 | } | ||
127 | |||
128 | void LLIMInfo::packMessageBlock(LLMessageSystem* msg) const | ||
129 | { | ||
130 | // Construct binary bucket | ||
131 | std::vector<U8> bucket; | ||
132 | if (mData.has("binary_bucket")) | ||
133 | { | ||
134 | bucket = mData["binary_bucket"].asBinary(); | ||
135 | } | ||
136 | pack_instant_message_block( | ||
137 | msg, | ||
138 | mFromID, | ||
139 | mFromGroup, | ||
140 | LLUUID::null, | ||
141 | mToID, | ||
142 | mName.c_str(), | ||
143 | mMessage.c_str(), | ||
144 | mOffline, | ||
145 | mIMType, | ||
146 | mID, | ||
147 | mParentEstateID, | ||
148 | mRegionID, | ||
149 | mPosition, | ||
150 | mTimeStamp, | ||
151 | &bucket[0], | ||
152 | bucket.size()); | ||
153 | } | ||
154 | |||
155 | void pack_instant_message( | ||
156 | LLMessageSystem* msg, | ||
157 | const LLUUID& from_id, | ||
158 | BOOL from_group, | ||
159 | const LLUUID& session_id, | ||
160 | const LLUUID& to_id, | ||
161 | const char* name, | ||
162 | const char* message, | ||
163 | U8 offline, | ||
164 | EInstantMessage dialog, | ||
165 | const LLUUID& id, | ||
166 | U32 parent_estate_id, | ||
167 | const LLUUID& region_id, | ||
168 | const LLVector3& position, | ||
169 | U32 timestamp, | ||
170 | const U8* binary_bucket, | ||
171 | S32 binary_bucket_size) | ||
172 | { | ||
173 | lldebugs << "pack_instant_message()" << llendl; | ||
174 | msg->newMessageFast(_PREHASH_ImprovedInstantMessage); | ||
175 | pack_instant_message_block( | ||
176 | msg, | ||
177 | from_id, | ||
178 | from_group, | ||
179 | session_id, | ||
180 | to_id, | ||
181 | name, | ||
182 | message, | ||
183 | offline, | ||
184 | dialog, | ||
185 | id, | ||
186 | parent_estate_id, | ||
187 | region_id, | ||
188 | position, | ||
189 | timestamp, | ||
190 | binary_bucket, | ||
191 | binary_bucket_size); | ||
192 | } | ||
193 | |||
194 | void pack_instant_message_block( | ||
195 | LLMessageSystem* msg, | ||
196 | const LLUUID& from_id, | ||
197 | BOOL from_group, | ||
198 | const LLUUID& session_id, | ||
199 | const LLUUID& to_id, | ||
200 | const char* name, | ||
201 | const char* message, | ||
202 | U8 offline, | ||
203 | EInstantMessage dialog, | ||
204 | const LLUUID& id, | ||
205 | U32 parent_estate_id, | ||
206 | const LLUUID& region_id, | ||
207 | const LLVector3& position, | ||
208 | U32 timestamp, | ||
209 | const U8* binary_bucket, | ||
210 | S32 binary_bucket_size) | ||
211 | { | ||
212 | msg->nextBlockFast(_PREHASH_AgentData); | ||
213 | msg->addUUIDFast(_PREHASH_AgentID, from_id); | ||
214 | msg->addUUIDFast(_PREHASH_SessionID, session_id); | ||
215 | msg->nextBlockFast(_PREHASH_MessageBlock); | ||
216 | msg->addBOOLFast(_PREHASH_FromGroup, from_group); | ||
217 | msg->addUUIDFast(_PREHASH_ToAgentID, to_id); | ||
218 | msg->addU32Fast(_PREHASH_ParentEstateID, parent_estate_id); | ||
219 | msg->addUUIDFast(_PREHASH_RegionID, region_id); | ||
220 | msg->addVector3Fast(_PREHASH_Position, position); | ||
221 | msg->addU8Fast(_PREHASH_Offline, offline); | ||
222 | msg->addU8Fast(_PREHASH_Dialog, (U8) dialog); | ||
223 | msg->addUUIDFast(_PREHASH_ID, id); | ||
224 | msg->addU32Fast(_PREHASH_Timestamp, timestamp); | ||
225 | msg->addStringFast(_PREHASH_FromAgentName, name); | ||
226 | S32 bytes_left = MTUBYTES; | ||
227 | if(message) | ||
228 | { | ||
229 | char buffer[MTUBYTES]; | ||
230 | bytes_left -= snprintf(buffer, MTUBYTES, "%s", message); | ||
231 | bytes_left = llmax(0, bytes_left); | ||
232 | msg->addStringFast(_PREHASH_Message, buffer); | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | msg->addStringFast(_PREHASH_Message, NULL); | ||
237 | } | ||
238 | const U8* bb; | ||
239 | if(binary_bucket) | ||
240 | { | ||
241 | bb = binary_bucket; | ||
242 | binary_bucket_size = llmin(bytes_left, binary_bucket_size); | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | bb = (const U8*)EMPTY_BINARY_BUCKET; | ||
247 | binary_bucket_size = EMPTY_BINARY_BUCKET_SIZE; | ||
248 | } | ||
249 | msg->addBinaryDataFast(_PREHASH_BinaryBucket, bb, binary_bucket_size); | ||
250 | } | ||
251 | |||
252 | void LLIMInfo::unpackMessageBlock(LLMessageSystem* msg) | ||
253 | { | ||
254 | msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, mFromID); | ||
255 | msg->getBOOLFast(_PREHASH_MessageBlock, _PREHASH_FromGroup, mFromGroup); | ||
256 | msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ToAgentID, mToID); | ||
257 | msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, mParentEstateID); | ||
258 | msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_RegionID, mRegionID); | ||
259 | msg->getVector3Fast(_PREHASH_MessageBlock, _PREHASH_Position, mPosition); | ||
260 | msg->getU8Fast(_PREHASH_MessageBlock, _PREHASH_Offline, mOffline); | ||
261 | U8 dialog; | ||
262 | msg->getU8Fast(_PREHASH_MessageBlock, _PREHASH_Dialog, dialog); | ||
263 | mIMType = (EInstantMessage) dialog; | ||
264 | msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ID, mID); | ||
265 | msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_Timestamp, mTimeStamp); | ||
266 | char name[DB_FULL_NAME_BUF_SIZE]; | ||
267 | msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, DB_FULL_NAME_BUF_SIZE, name); | ||
268 | mName.assign(name); | ||
269 | |||
270 | char message[DB_IM_MSG_BUF_SIZE]; | ||
271 | msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message, DB_IM_MSG_BUF_SIZE, message); | ||
272 | mMessage.assign(message); | ||
273 | |||
274 | S32 binary_bucket_size = llmin( | ||
275 | MTUBYTES, | ||
276 | msg->getSizeFast( | ||
277 | _PREHASH_MessageBlock, | ||
278 | _PREHASH_BinaryBucket)); | ||
279 | if(binary_bucket_size > 0) | ||
280 | { | ||
281 | std::vector<U8> bucket; | ||
282 | bucket.resize(binary_bucket_size); | ||
283 | |||
284 | msg->getBinaryDataFast( | ||
285 | _PREHASH_MessageBlock, | ||
286 | _PREHASH_BinaryBucket, | ||
287 | &bucket[0], | ||
288 | 0, | ||
289 | 0, | ||
290 | binary_bucket_size); | ||
291 | mData["binary_bucket"] = bucket; | ||
292 | } | ||
293 | else | ||
294 | { | ||
295 | mData.clear(); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | LLPointer<LLIMInfo> LLIMInfo::clone() | ||
300 | { | ||
301 | return new LLIMInfo( | ||
302 | mFromID, | ||
303 | mFromGroup, | ||
304 | mToID, | ||
305 | mIMType, | ||
306 | mName, | ||
307 | mMessage, | ||
308 | mID, | ||
309 | mParentEstateID, | ||
310 | mRegionID, | ||
311 | mPosition, | ||
312 | mData, | ||
313 | mOffline, | ||
314 | mTimeStamp, | ||
315 | mSource, | ||
316 | mTTL); | ||
317 | } | ||
318 | |||