aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/message.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/message.h')
-rw-r--r--linden/indra/llmessage/message.h571
1 files changed, 113 insertions, 458 deletions
diff --git a/linden/indra/llmessage/message.h b/linden/indra/llmessage/message.h
index 5cc3ec1..0a55485 100644
--- a/linden/indra/llmessage/message.h
+++ b/linden/indra/llmessage/message.h
@@ -1,9 +1,10 @@
1/** 1/**
2 * @file message.h 2 * @FILE message.h
3 * @brief LLMessageSystem class header file 3 * @brief LLMessageSystem class header file
4 * 4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc. 5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 * 6 *
7 * Second Life Viewer Source Code
7 * The source code in this file ("Source Code") is provided by Linden Lab 8 * 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 * 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 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -45,16 +46,15 @@
45#include "llerror.h" 46#include "llerror.h"
46#include "net.h" 47#include "net.h"
47#include "string_table.h" 48#include "string_table.h"
48#include "llptrskipmap.h"
49#include "llcircuit.h" 49#include "llcircuit.h"
50#include "lltimer.h" 50#include "lltimer.h"
51#include "llpacketring.h" 51#include "llpacketring.h"
52#include "llhost.h" 52#include "llhost.h"
53#include "llhttpnode.h"
53#include "llpacketack.h" 54#include "llpacketack.h"
54#include "doublelinkedlist.h"
55#include "message_prehash.h" 55#include "message_prehash.h"
56#include "llstl.h" 56#include "llstl.h"
57#include "lldarray.h" 57#include "llmsgvariabletype.h"
58 58
59const U32 MESSAGE_MAX_STRINGS_LENGTH = 64; 59const U32 MESSAGE_MAX_STRINGS_LENGTH = 64;
60const U32 MESSAGE_NUMBER_OF_HASH_BUCKETS = 8192; 60const U32 MESSAGE_NUMBER_OF_HASH_BUCKETS = 8192;
@@ -153,39 +153,10 @@ class LLQuaternion;
153class LLSD; 153class LLSD;
154class LLUUID; 154class LLUUID;
155class LLMessageSystem; 155class LLMessageSystem;
156class LLPumpIO;
156 157
157// message data pieces are used to collect the data called for by the message template 158// message data pieces are used to collect the data called for by the message template
158 159
159// iterator typedefs precede each class as needed
160typedef enum e_message_variable_type
161{
162 MVT_NULL,
163 MVT_FIXED,
164 MVT_VARIABLE,
165 MVT_U8,
166 MVT_U16,
167 MVT_U32,
168 MVT_U64,
169 MVT_S8,
170 MVT_S16,
171 MVT_S32,
172 MVT_S64,
173 MVT_F32,
174 MVT_F64,
175 MVT_LLVector3,
176 MVT_LLVector3d,
177 MVT_LLVector4,
178 MVT_LLQuaternion,
179 MVT_LLUUID,
180 MVT_BOOL,
181 MVT_IP_ADDR,
182 MVT_IP_PORT,
183 MVT_U16Vec3,
184 MVT_U16Quat,
185 MVT_S16Array,
186 MVT_EOL
187} EMsgVariableType;
188
189// message system exceptional condition handlers. 160// message system exceptional condition handlers.
190enum EMessageException 161enum EMessageException
191{ 162{
@@ -197,25 +168,34 @@ enum EMessageException
197typedef void (*msg_exception_callback)(LLMessageSystem*,void*,EMessageException); 168typedef void (*msg_exception_callback)(LLMessageSystem*,void*,EMessageException);
198 169
199 170
200
201class LLMsgData; 171class LLMsgData;
202class LLMsgBlkData; 172class LLMsgBlkData;
203class LLMessageTemplate; 173class LLMessageTemplate;
204 174
205class LLMessagePollInfo; 175class LLMessagePollInfo;
176class LLMessageBuilder;
177class LLTemplateMessageBuilder;
178class LLSDMessageBuilder;
179class LLMessageReader;
180class LLTemplateMessageReader;
181class LLSDMessageReader;
206 182
207class LLMessageSystem 183class LLUseCircuitCodeResponder
208{ 184{
209 LOG_CLASS(LLMessageSystem); 185 LOG_CLASS(LLMessageSystem);
210 186
211public: 187public:
188 virtual ~LLUseCircuitCodeResponder();
189 virtual void complete(const LLHost& host, const LLUUID& agent) const = 0;
190};
191
192class LLMessageSystem
193{
194 private:
212 U8 mSendBuffer[MAX_BUFFER_SIZE]; 195 U8 mSendBuffer[MAX_BUFFER_SIZE];
213 // Encoded send buffer needs to be slightly larger since the zero
214 // coding can potentially increase the size of the send data.
215 U8 mEncodedSendBuffer[2 * MAX_BUFFER_SIZE];
216 S32 mSendSize; 196 S32 mSendSize;
217 S32 mCurrentSendTotal;
218 197
198 public:
219 LLPacketRing mPacketRing; 199 LLPacketRing mPacketRing;
220 LLReliablePacketParams mReliablePacketParams; 200 LLReliablePacketParams mReliablePacketParams;
221 201
@@ -294,12 +274,7 @@ public:
294 LLMessageSystem(const char *filename, U32 port, S32 version_major, 274 LLMessageSystem(const char *filename, U32 port, S32 version_major,
295 S32 version_minor, S32 version_patch); 275 S32 version_minor, S32 version_patch);
296 276
297public: 277 ~LLMessageSystem();
298 // Subclass use.
299 LLMessageSystem();
300
301public:
302 virtual ~LLMessageSystem();
303 278
304 BOOL isOK() const { return !mbError; } 279 BOOL isOK() const { return !mbError; }
305 S32 getErrorCode() const { return mErrorCode; } 280 S32 getErrorCode() const { return mErrorCode; }
@@ -317,15 +292,26 @@ public:
317 setHandlerFuncFast(gMessageStringTable.getString(name), handler_func, user_data); 292 setHandlerFuncFast(gMessageStringTable.getString(name), handler_func, user_data);
318 } 293 }
319 294
320 bool callHandler(const char *name, bool trustedSource,
321 LLMessageSystem* msg);
322
323 // Set a callback function for a message system exception. 295 // Set a callback function for a message system exception.
324 void setExceptionFunc(EMessageException exception, msg_exception_callback func, void* data = NULL); 296 void setExceptionFunc(EMessageException exception, msg_exception_callback func, void* data = NULL);
325 // Call the specified exception func, and return TRUE if a 297 // Call the specified exception func, and return TRUE if a
326 // function was found and called. Otherwise return FALSE. 298 // function was found and called. Otherwise return FALSE.
327 BOOL callExceptionFunc(EMessageException exception); 299 BOOL callExceptionFunc(EMessageException exception);
328 300
301 // Set a function that will be called once per packet processed with the
302 // hashed message name and the time spent in the processing handler function
303 // measured in seconds. JC
304 typedef void (*msg_timing_callback)(const char* hashed_name, F32 time, void* data);
305 void setTimingFunc(msg_timing_callback func, void* data = NULL);
306 msg_timing_callback getTimingCallback()
307 {
308 return mTimingCallback;
309 }
310 void* getTimingCallbackData()
311 {
312 return mTimingCallbackData;
313 }
314
329 // This method returns true if the code is in the circuit codes map. 315 // This method returns true if the code is in the circuit codes map.
330 BOOL isCircuitCodeKnown(U32 code) const; 316 BOOL isCircuitCodeKnown(U32 code) const;
331 317
@@ -364,42 +350,21 @@ public:
364 void setMySessionID(const LLUUID& session_id) { mSessionID = session_id; } 350 void setMySessionID(const LLUUID& session_id) { mSessionID = session_id; }
365 const LLUUID& getMySessionID() { return mSessionID; } 351 const LLUUID& getMySessionID() { return mSessionID; }
366 352
367 virtual void newMessageFast(const char *name); 353 void newMessageFast(const char *name);
368 void newMessage(const char *name) 354 void newMessage(const char *name);
369 {
370 newMessageFast(gMessageStringTable.getString(name));
371 }
372 355
373 void copyMessageRtoS(); 356 void copyMessageRtoS();
374 void clearMessage(); 357 void clearMessage();
375 358
376 virtual void nextBlockFast(const char *blockname); 359 void nextBlockFast(const char *blockname);
377 void nextBlock(const char *blockname) 360 void nextBlock(const char *blockname)
378 { 361 {
379 nextBlockFast(gMessageStringTable.getString(blockname)); 362 nextBlockFast(gMessageStringTable.getString(blockname));
380 } 363 }
381private:
382 void addDataFast(const char *varname, const void *data, EMsgVariableType type, S32 size); // Use only for types not in system already
383 void addData(const char *varname, const void *data, EMsgVariableType type, S32 size)
384 {
385 addDataFast(gMessageStringTable.getString(varname), data, type, size);
386 }
387 364
388
389 void addDataFast(const char *varname, const void *data, EMsgVariableType type); // DEPRECATED - not typed, doesn't check storage space
390 void addData(const char *varname, const void *data, EMsgVariableType type)
391 {
392 addDataFast(gMessageStringTable.getString(varname), data, type);
393 }
394public: 365public:
395 void addBinaryDataFast(const char *varname, const void *data, S32 size) 366 void addBinaryDataFast(const char *varname, const void *data, S32 size);
396 { 367 void addBinaryData(const char *varname, const void *data, S32 size);
397 addDataFast(varname, data, MVT_FIXED, size);
398 }
399 void addBinaryData(const char *varname, const void *data, S32 size)
400 {
401 addDataFast(gMessageStringTable.getString(varname), data, MVT_FIXED, size);
402 }
403 368
404 void addBOOLFast( const char* varname, BOOL b); // typed, checks storage space 369 void addBOOLFast( const char* varname, BOOL b); // typed, checks storage space
405 void addBOOL( const char* varname, BOOL b); // typed, checks storage space 370 void addBOOL( const char* varname, BOOL b); // typed, checks storage space
@@ -415,7 +380,7 @@ public:
415 void addF32( const char *varname, F32 f); // typed, checks storage space 380 void addF32( const char *varname, F32 f); // typed, checks storage space
416 void addS32Fast( const char *varname, S32 s); // typed, checks storage space 381 void addS32Fast( const char *varname, S32 s); // typed, checks storage space
417 void addS32( const char *varname, S32 s); // typed, checks storage space 382 void addS32( const char *varname, S32 s); // typed, checks storage space
418 virtual void addU32Fast( const char *varname, U32 u); // typed, checks storage space 383 void addU32Fast( const char *varname, U32 u); // typed, checks storage space
419 void addU32( const char *varname, U32 u); // typed, checks storage space 384 void addU32( const char *varname, U32 u); // typed, checks storage space
420 void addU64Fast( const char *varname, U64 lu); // typed, checks storage space 385 void addU64Fast( const char *varname, U64 lu); // typed, checks storage space
421 void addU64( const char *varname, U64 lu); // typed, checks storage space 386 void addU64( const char *varname, U64 lu); // typed, checks storage space
@@ -429,7 +394,7 @@ public:
429 void addVector3d( const char *varname, const LLVector3d& vec); // typed, checks storage space 394 void addVector3d( const char *varname, const LLVector3d& vec); // typed, checks storage space
430 void addQuatFast( const char *varname, const LLQuaternion& quat); // typed, checks storage space 395 void addQuatFast( const char *varname, const LLQuaternion& quat); // typed, checks storage space
431 void addQuat( const char *varname, const LLQuaternion& quat); // typed, checks storage space 396 void addQuat( const char *varname, const LLQuaternion& quat); // typed, checks storage space
432 virtual void addUUIDFast( const char *varname, const LLUUID& uuid); // typed, checks storage space 397 void addUUIDFast( const char *varname, const LLUUID& uuid); // typed, checks storage space
433 void addUUID( const char *varname, const LLUUID& uuid); // typed, checks storage space 398 void addUUID( const char *varname, const LLUUID& uuid); // typed, checks storage space
434 void addIPAddrFast( const char *varname, const U32 ip); // typed, checks storage space 399 void addIPAddrFast( const char *varname, const U32 ip); // typed, checks storage space
435 void addIPAddr( const char *varname, const U32 ip); // typed, checks storage space 400 void addIPAddr( const char *varname, const U32 ip); // typed, checks storage space
@@ -440,8 +405,8 @@ public:
440 void addStringFast( const char* varname, const std::string& s); // typed, checks storage space 405 void addStringFast( const char* varname, const std::string& s); // typed, checks storage space
441 void addString( const char* varname, const std::string& s); // typed, checks storage space 406 void addString( const char* varname, const std::string& s); // typed, checks storage space
442 407
408 S32 getCurrentSendTotal() const;
443 TPACKETID getCurrentRecvPacketID() { return mCurrentRecvPacketID; } 409 TPACKETID getCurrentRecvPacketID() { return mCurrentRecvPacketID; }
444 S32 getCurrentSendTotal() const { return mCurrentSendTotal; }
445 410
446 // This method checks for current send total and returns true if 411 // This method checks for current send total and returns true if
447 // you need to go to the next block type or need to start a new 412 // you need to go to the next block type or need to start a new
@@ -450,16 +415,16 @@ public:
450 BOOL isSendFull(const char* blockname = NULL); 415 BOOL isSendFull(const char* blockname = NULL);
451 BOOL isSendFullFast(const char* blockname = NULL); 416 BOOL isSendFullFast(const char* blockname = NULL);
452 417
453 BOOL removeLastBlock(); 418 BOOL removeLastBlock();
454 419
455 void buildMessage(); 420 //void buildMessage();
456 421
457 S32 zeroCode(U8 **data, S32 *data_size); 422 S32 zeroCode(U8 **data, S32 *data_size);
458 S32 zeroCodeExpand(U8 **data, S32 *data_size); 423 S32 zeroCodeExpand(U8 **data, S32 *data_size);
459 S32 zeroCodeAdjustCurrentSendTotal(); 424 S32 zeroCodeAdjustCurrentSendTotal();
460 425
461 // Uses ping-based retry 426 // Uses ping-based retry
462 virtual S32 sendReliable(const LLHost &host); 427 S32 sendReliable(const LLHost &host);
463 428
464 // Uses ping-based retry 429 // Uses ping-based retry
465 S32 sendReliable(const U32 circuit) { return sendReliable(findHost(circuit)); } 430 S32 sendReliable(const U32 circuit) { return sendReliable(findHost(circuit)); }
@@ -488,28 +453,10 @@ public:
488 S32 sendMessage(const LLHost &host); 453 S32 sendMessage(const LLHost &host);
489 S32 sendMessage(const U32 circuit); 454 S32 sendMessage(const U32 circuit);
490 455
491 BOOL decodeData(const U8 *buffer, const LLHost &host); 456 // BOOL decodeData(const U8 *buffer, const LLHost &host);
492
493 // TODO: Consolide these functions
494 // TODO: Make these private, force use of typed functions.
495 // If size is not 0, an error is generated if size doesn't exactly match the size of the data.
496 // At all times, the number if bytes written to *datap is <= max_size.
497private:
498 void getDataFast(const char *blockname, const char *varname, void *datap, S32 size = 0, S32 blocknum = 0, S32 max_size = S32_MAX);
499 void getData(const char *blockname, const char *varname, void *datap, S32 size = 0, S32 blocknum = 0, S32 max_size = S32_MAX)
500 {
501 getDataFast(gMessageStringTable.getString(blockname), gMessageStringTable.getString(varname), datap, size, blocknum, max_size);
502 }
503public:
504 void getBinaryDataFast(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX)
505 {
506 getDataFast(blockname, varname, datap, size, blocknum, max_size);
507 }
508 void getBinaryData(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX)
509 {
510 getDataFast(gMessageStringTable.getString(blockname), gMessageStringTable.getString(varname), datap, size, blocknum, max_size);
511 }
512 457
458 void getBinaryDataFast(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
459 void getBinaryData(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
513 void getBOOLFast( const char *block, const char *var, BOOL &data, S32 blocknum = 0); 460 void getBOOLFast( const char *block, const char *var, BOOL &data, S32 blocknum = 0);
514 void getBOOL( const char *block, const char *var, BOOL &data, S32 blocknum = 0); 461 void getBOOL( const char *block, const char *var, BOOL &data, S32 blocknum = 0);
515 void getS8Fast( const char *block, const char *var, S8 &data, S32 blocknum = 0); 462 void getS8Fast( const char *block, const char *var, S8 &data, S32 blocknum = 0);
@@ -524,9 +471,9 @@ public:
524 void getS32( const char *block, const char *var, S32 &data, S32 blocknum = 0); 471 void getS32( const char *block, const char *var, S32 &data, S32 blocknum = 0);
525 void getF32Fast( const char *block, const char *var, F32 &data, S32 blocknum = 0); 472 void getF32Fast( const char *block, const char *var, F32 &data, S32 blocknum = 0);
526 void getF32( const char *block, const char *var, F32 &data, S32 blocknum = 0); 473 void getF32( const char *block, const char *var, F32 &data, S32 blocknum = 0);
527 virtual void getU32Fast( const char *block, const char *var, U32 &data, S32 blocknum = 0); 474 void getU32Fast( const char *block, const char *var, U32 &data, S32 blocknum = 0);
528 void getU32( const char *block, const char *var, U32 &data, S32 blocknum = 0); 475 void getU32( const char *block, const char *var, U32 &data, S32 blocknum = 0);
529 virtual void getU64Fast( const char *block, const char *var, U64 &data, S32 blocknum = 0); 476 void getU64Fast( const char *block, const char *var, U64 &data, S32 blocknum = 0);
530 void getU64( const char *block, const char *var, U64 &data, S32 blocknum = 0); 477 void getU64( const char *block, const char *var, U64 &data, S32 blocknum = 0);
531 void getF64Fast( const char *block, const char *var, F64 &data, S32 blocknum = 0); 478 void getF64Fast( const char *block, const char *var, F64 &data, S32 blocknum = 0);
532 void getF64( const char *block, const char *var, F64 &data, S32 blocknum = 0); 479 void getF64( const char *block, const char *var, F64 &data, S32 blocknum = 0);
@@ -538,13 +485,13 @@ public:
538 void getVector3d(const char *block, const char *var, LLVector3d &vec, S32 blocknum = 0); 485 void getVector3d(const char *block, const char *var, LLVector3d &vec, S32 blocknum = 0);
539 void getQuatFast( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0); 486 void getQuatFast( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0);
540 void getQuat( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0); 487 void getQuat( const char *block, const char *var, LLQuaternion &q, S32 blocknum = 0);
541 virtual void getUUIDFast( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0); 488 void getUUIDFast( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0);
542 void getUUID( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0); 489 void getUUID( const char *block, const char *var, LLUUID &uuid, S32 blocknum = 0);
543 virtual void getIPAddrFast( const char *block, const char *var, U32 &ip, S32 blocknum = 0); 490 void getIPAddrFast( const char *block, const char *var, U32 &ip, S32 blocknum = 0);
544 void getIPAddr( const char *block, const char *var, U32 &ip, S32 blocknum = 0); 491 void getIPAddr( const char *block, const char *var, U32 &ip, S32 blocknum = 0);
545 virtual void getIPPortFast( const char *block, const char *var, U16 &port, S32 blocknum = 0); 492 void getIPPortFast( const char *block, const char *var, U16 &port, S32 blocknum = 0);
546 void getIPPort( const char *block, const char *var, U16 &port, S32 blocknum = 0); 493 void getIPPort( const char *block, const char *var, U16 &port, S32 blocknum = 0);
547 virtual void getStringFast( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0); 494 void getStringFast( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
548 void getString( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0); 495 void getString( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
549 496
550 497
@@ -566,7 +513,7 @@ public:
566 void showCircuitInfo(); 513 void showCircuitInfo();
567 LLString getCircuitInfoString(); 514 LLString getCircuitInfoString();
568 515
569 virtual U32 getOurCircuitCode(); 516 U32 getOurCircuitCode();
570 517
571 void enableCircuit(const LLHost &host, BOOL trusted); 518 void enableCircuit(const LLHost &host, BOOL trusted);
572 void disableCircuit(const LLHost &host); 519 void disableCircuit(const LLHost &host);
@@ -612,20 +559,12 @@ public:
612 void sanityCheck(); 559 void sanityCheck();
613 560
614 S32 getNumberOfBlocksFast(const char *blockname); 561 S32 getNumberOfBlocksFast(const char *blockname);
615 S32 getNumberOfBlocks(const char *blockname) 562 S32 getNumberOfBlocks(const char *blockname);
616 {
617 return getNumberOfBlocksFast(gMessageStringTable.getString(blockname));
618 }
619 S32 getSizeFast(const char *blockname, const char *varname); 563 S32 getSizeFast(const char *blockname, const char *varname);
620 S32 getSize(const char *blockname, const char *varname) 564 S32 getSize(const char *blockname, const char *varname);
621 { 565 S32 getSizeFast(const char *blockname, S32 blocknum,
622 return getSizeFast(gMessageStringTable.getString(blockname), gMessageStringTable.getString(varname)); 566 const char *varname); // size in bytes of data
623 } 567 S32 getSize(const char *blockname, S32 blocknum, const char *varname);
624 S32 getSizeFast(const char *blockname, S32 blocknum, const char *varname); // size in bytes of variable length data
625 S32 getSize(const char *blockname, S32 blocknum, const char *varname)
626 {
627 return getSizeFast(gMessageStringTable.getString(blockname), blocknum, gMessageStringTable.getString(varname));
628 }
629 568
630 void resetReceiveCounts(); // resets receive counts for all message types to 0 569 void resetReceiveCounts(); // resets receive counts for all message types to 0
631 void dumpReceiveCounts(); // dumps receive count for each message type to llinfos 570 void dumpReceiveCounts(); // dumps receive count for each message type to llinfos
@@ -640,14 +579,14 @@ public:
640 void stopLogging(); // flush and close file 579 void stopLogging(); // flush and close file
641 void summarizeLogs(std::ostream& str); // log statistics 580 void summarizeLogs(std::ostream& str); // log statistics
642 581
643 S32 getReceiveSize() const { return mReceiveSize; } 582 S32 getReceiveSize() const;
644 S32 getReceiveCompressedSize() const { return mIncomingCompressedSize; } 583 S32 getReceiveCompressedSize() const { return mIncomingCompressedSize; }
645 S32 getReceiveBytes() const; 584 S32 getReceiveBytes() const;
646 585
647 S32 getUnackedListSize() const { return mUnackedListSize; } 586 S32 getUnackedListSize() const { return mUnackedListSize; }
648 587
649 const char* getCurrentSMessageName() const { return mCurrentSMessageName; } 588 //const char* getCurrentSMessageName() const { return mCurrentSMessageName; }
650 const char* getCurrentSBlockName() const { return mCurrentSBlockName; } 589 //const char* getCurrentSBlockName() const { return mCurrentSBlockName; }
651 590
652 // friends 591 // friends
653 friend std::ostream& operator<<(std::ostream& s, LLMessageSystem &msg); 592 friend std::ostream& operator<<(std::ostream& s, LLMessageSystem &msg);
@@ -656,25 +595,41 @@ public:
656 void setMaxMessageCounts(const S32 num); // Max number of messages before dumping (neg to disable) 595 void setMaxMessageCounts(const S32 num); // Max number of messages before dumping (neg to disable)
657 596
658 // statics 597 // statics
659public: 598 static BOOL isTemplateConfirmed();
599 static BOOL doesTemplateMatch();
600 static void sendMessageTemplateChecksum(const LLHost&);
601 static void processMessageTemplateChecksumReply(LLMessageSystem *msg,
602 void** user_data);
603 static void sendSecureMessageTemplateChecksum(const LLHost&);
604 static void processSecureTemplateChecksumReply(LLMessageSystem *msg,
605 void** user_data);
660 static U64 getMessageTimeUsecs(const BOOL update = FALSE); // Get the current message system time in microseconds 606 static U64 getMessageTimeUsecs(const BOOL update = FALSE); // Get the current message system time in microseconds
661 static F64 getMessageTimeSeconds(const BOOL update = FALSE); // Get the current message system time in seconds 607 static F64 getMessageTimeSeconds(const BOOL update = FALSE); // Get the current message system time in seconds
662 608
663 static void setTimeDecodes( BOOL b ) 609 static void setTimeDecodes(BOOL b);
664 { LLMessageSystem::mTimeDecodes = b; } 610 static void setTimeDecodesSpamThreshold(F32 seconds);
665
666 static void setTimeDecodesSpamThreshold( F32 seconds )
667 { LLMessageSystem::mTimeDecodesSpamThreshold = seconds; }
668 611
669 // message handlers internal to the message systesm 612 // message handlers internal to the message systesm
670 //static void processAssignCircuitCode(LLMessageSystem* msg, void**); 613 //static void processAssignCircuitCode(LLMessageSystem* msg, void**);
671 static void processAddCircuitCode(LLMessageSystem* msg, void**); 614 static void processAddCircuitCode(LLMessageSystem* msg, void**);
672 static void processUseCircuitCode(LLMessageSystem* msg, void**); 615 static void processUseCircuitCode(LLMessageSystem* msg, void**);
673 616
617 // dispatch llsd message to http node tree
618 static void dispatch(const std::string& msg_name,
619 const LLSD& message);
620 static void dispatch(const std::string& msg_name,
621 const LLSD& message,
622 LLHTTPNode::ResponsePtr responsep);
623
674 void setMessageBans(const LLSD& trusted, const LLSD& untrusted); 624 void setMessageBans(const LLSD& trusted, const LLSD& untrusted);
625
626 // Check UDP messages and pump http_pump to receive HTTP messages.
627 bool checkAllMessages(S64 frame_count, LLPumpIO* http_pump);
675 628
676private: 629private:
677 // data used in those internal handlers 630 // data used in those internal handlers
631 BOOL mTemplateConfirmed;
632 BOOL mTemplateMatches;
678 633
679 // The mCircuitCodes is a map from circuit codes to session 634 // The mCircuitCodes is a map from circuit codes to session
680 // ids. This allows us to verify sessions on connect. 635 // ids. This allows us to verify sessions on connect.
@@ -685,7 +640,6 @@ private:
685 // that no one gives them a bad circuit code. 640 // that no one gives them a bad circuit code.
686 LLUUID mSessionID; 641 LLUUID mSessionID;
687 642
688private:
689 void addTemplate(LLMessageTemplate *templatep); 643 void addTemplate(LLMessageTemplate *templatep);
690 void clearReceiveState(); 644 void clearReceiveState();
691 BOOL decodeTemplate( const U8* buffer, S32 buffer_size, LLMessageTemplate** msg_template ); 645 BOOL decodeTemplate( const U8* buffer, S32 buffer_size, LLMessageTemplate** msg_template );
@@ -695,7 +649,6 @@ private:
695 void logValidMsg(LLCircuitData *cdp, const LLHost& sender, BOOL recv_reliable, BOOL recv_resent, BOOL recv_acks ); 649 void logValidMsg(LLCircuitData *cdp, const LLHost& sender, BOOL recv_reliable, BOOL recv_resent, BOOL recv_acks );
696 void logRanOffEndOfPacket( const LLHost& sender ); 650 void logRanOffEndOfPacket( const LLHost& sender );
697 651
698private:
699 class LLMessageCountInfo 652 class LLMessageCountInfo
700 { 653 {
701 public: 654 public:
@@ -711,26 +664,10 @@ private:
711 S32 mTrueReceiveSize; 664 S32 mTrueReceiveSize;
712 665
713 // Must be valid during decode 666 // Must be valid during decode
714 S32 mReceiveSize; 667
715 TPACKETID mCurrentRecvPacketID; // packet ID of current receive packet (for reporting)
716 LLMessageTemplate *mCurrentRMessageTemplate;
717 LLMsgData *mCurrentRMessageData;
718 S32 mIncomingCompressedSize; // original size of compressed msg (0 if uncomp.)
719 LLHost mLastSender;
720
721 // send message storage
722 LLMsgData *mCurrentSMessageData;
723 LLMessageTemplate *mCurrentSMessageTemplate;
724 LLMsgBlkData *mCurrentSDataBlock;
725 char *mCurrentSMessageName;
726 char *mCurrentSBlockName;
727
728 BOOL mbError; 668 BOOL mbError;
729 S32 mErrorCode; 669 S32 mErrorCode;
730 670
731 BOOL mbSBuilt; // is send message built?
732 BOOL mbSClear; // is the send message clear?
733
734 F64 mResendDumpTime; // The last time we dumped resends 671 F64 mResendDumpTime; // The last time we dumped resends
735 672
736 LLMessageCountInfo mMessageCountList[MAX_MESSAGE_COUNT_NUM]; 673 LLMessageCountInfo mMessageCountList[MAX_MESSAGE_COUNT_NUM];
@@ -753,16 +690,31 @@ private:
753 static F32 mTimeDecodesSpamThreshold; // If mTimeDecodes is on, all this many seconds for each msg decode before spamming 690 static F32 mTimeDecodesSpamThreshold; // If mTimeDecodes is on, all this many seconds for each msg decode before spamming
754 static BOOL mTimeDecodes; // Measure time for all message decodes if TRUE; 691 static BOOL mTimeDecodes; // Measure time for all message decodes if TRUE;
755 692
693 msg_timing_callback mTimingCallback;
694 void* mTimingCallbackData;
695
756 void init(); // ctor shared initialisation. 696 void init(); // ctor shared initialisation.
697
698 LLHost mLastSender;
699 S32 mIncomingCompressedSize; // original size of compressed msg (0 if uncomp.)
700 TPACKETID mCurrentRecvPacketID; // packet ID of current receive packet (for reporting)
701
702 LLMessageBuilder* mMessageBuilder;
703 LLTemplateMessageBuilder* mTemplateMessageBuilder;
704 LLSDMessageBuilder* mLLSDMessageBuilder;
705 LLMessageReader* mMessageReader;
706 LLTemplateMessageReader* mTemplateMessageReader;
707 LLSDMessageReader* mLLSDMessageReader;
708
709 friend class LLMessageHandlerBridge;
710
711 bool callHandler(const char *name, bool trustedSource,
712 LLMessageSystem* msg);
757}; 713};
758 714
759 715
760// external hook into messaging system 716// external hook into messaging system
761extern LLMessageSystem *gMessageSystem; 717extern LLMessageSystem *gMessageSystem;
762//extern const char* MESSAGE_LOG_FILENAME;
763
764void encrypt_template(const char *src_name, const char *dest_name);
765BOOL decrypt_template(const char *src_name, const char *dest_name);
766 718
767// Must specific overall system version, which is used to determine 719// Must specific overall system version, which is used to determine
768// if a patch is available in the message template checksum verification. 720// if a patch is available in the message template checksum verification.
@@ -774,7 +726,8 @@ BOOL start_messaging_system(
774 S32 version_minor, 726 S32 version_minor,
775 S32 version_patch, 727 S32 version_patch,
776 BOOL b_dump_prehash_file, 728 BOOL b_dump_prehash_file,
777 const std::string& secret); 729 const std::string& secret,
730 const LLUseCircuitCodeResponder* responder = NULL);
778 731
779void end_messaging_system(); 732void end_messaging_system();
780 733
@@ -950,12 +903,9 @@ inline void *ntohmemcpy(void *s, const void *ct, EMsgVariableType type, size_t n
950} 903}
951 904
952 905
953inline const LLHost& LLMessageSystem::getSender() const 906inline const LLHost& LLMessageSystem::getSender() const {return mLastSender;}
954{
955 return mLastSender;
956}
957 907
958inline U32 LLMessageSystem::getSenderIP() const 908inline U32 LLMessageSystem::getSenderIP() const
959{ 909{
960 return mLastSender.getAddress(); 910 return mLastSender.getAddress();
961} 911}
@@ -965,308 +915,13 @@ inline U32 LLMessageSystem::getSenderPort() const
965 return mLastSender.getPort(); 915 return mLastSender.getPort();
966} 916}
967 917
968inline void LLMessageSystem::addS8Fast(const char *varname, S8 s)
969{
970 addDataFast(varname, &s, MVT_S8, sizeof(s));
971}
972
973inline void LLMessageSystem::addS8(const char *varname, S8 s)
974{
975 addDataFast(gMessageStringTable.getString(varname), &s, MVT_S8, sizeof(s));
976}
977
978inline void LLMessageSystem::addU8Fast(const char *varname, U8 u)
979{
980 addDataFast(varname, &u, MVT_U8, sizeof(u));
981}
982
983inline void LLMessageSystem::addU8(const char *varname, U8 u)
984{
985 addDataFast(gMessageStringTable.getString(varname), &u, MVT_U8, sizeof(u));
986}
987
988inline void LLMessageSystem::addS16Fast(const char *varname, S16 i)
989{
990 addDataFast(varname, &i, MVT_S16, sizeof(i));
991}
992
993inline void LLMessageSystem::addS16(const char *varname, S16 i)
994{
995 addDataFast(gMessageStringTable.getString(varname), &i, MVT_S16, sizeof(i));
996}
997
998inline void LLMessageSystem::addU16Fast(const char *varname, U16 i)
999{
1000 addDataFast(varname, &i, MVT_U16, sizeof(i));
1001}
1002
1003inline void LLMessageSystem::addU16(const char *varname, U16 i)
1004{
1005 addDataFast(gMessageStringTable.getString(varname), &i, MVT_U16, sizeof(i));
1006}
1007
1008inline void LLMessageSystem::addF32Fast(const char *varname, F32 f)
1009{
1010 addDataFast(varname, &f, MVT_F32, sizeof(f));
1011}
1012
1013inline void LLMessageSystem::addF32(const char *varname, F32 f)
1014{
1015 addDataFast(gMessageStringTable.getString(varname), &f, MVT_F32, sizeof(f));
1016}
1017
1018inline void LLMessageSystem::addS32Fast(const char *varname, S32 s)
1019{
1020 addDataFast(varname, &s, MVT_S32, sizeof(s));
1021}
1022
1023inline void LLMessageSystem::addS32(const char *varname, S32 s)
1024{
1025 addDataFast(gMessageStringTable.getString(varname), &s, MVT_S32, sizeof(s));
1026}
1027
1028inline void LLMessageSystem::addU32Fast(const char *varname, U32 u)
1029{
1030 addDataFast(varname, &u, MVT_U32, sizeof(u));
1031}
1032
1033inline void LLMessageSystem::addU32(const char *varname, U32 u)
1034{
1035 addDataFast(gMessageStringTable.getString(varname), &u, MVT_U32, sizeof(u));
1036}
1037
1038inline void LLMessageSystem::addU64Fast(const char *varname, U64 lu)
1039{
1040 addDataFast(varname, &lu, MVT_U64, sizeof(lu));
1041}
1042
1043inline void LLMessageSystem::addU64(const char *varname, U64 lu)
1044{
1045 addDataFast(gMessageStringTable.getString(varname), &lu, MVT_U64, sizeof(lu));
1046}
1047
1048inline void LLMessageSystem::addF64Fast(const char *varname, F64 d)
1049{
1050 addDataFast(varname, &d, MVT_F64, sizeof(d));
1051}
1052
1053inline void LLMessageSystem::addF64(const char *varname, F64 d)
1054{
1055 addDataFast(gMessageStringTable.getString(varname), &d, MVT_F64, sizeof(d));
1056}
1057
1058inline void LLMessageSystem::addIPAddrFast(const char *varname, U32 u)
1059{
1060 addDataFast(varname, &u, MVT_IP_ADDR, sizeof(u));
1061}
1062
1063inline void LLMessageSystem::addIPAddr(const char *varname, U32 u)
1064{
1065 addDataFast(gMessageStringTable.getString(varname), &u, MVT_IP_ADDR, sizeof(u));
1066}
1067
1068inline void LLMessageSystem::addIPPortFast(const char *varname, U16 u)
1069{
1070 u = htons(u);
1071 addDataFast(varname, &u, MVT_IP_PORT, sizeof(u));
1072}
1073
1074inline void LLMessageSystem::addIPPort(const char *varname, U16 u)
1075{
1076 u = htons(u);
1077 addDataFast(gMessageStringTable.getString(varname), &u, MVT_IP_PORT, sizeof(u));
1078}
1079
1080inline void LLMessageSystem::addBOOLFast(const char* varname, BOOL b)
1081{
1082 // Can't just cast a BOOL (actually a U32) to a U8.
1083 // In some cases the low order bits will be zero.
1084 U8 temp = (b != 0);
1085 addDataFast(varname, &temp, MVT_BOOL, sizeof(temp));
1086}
1087
1088inline void LLMessageSystem::addBOOL(const char* varname, BOOL b)
1089{
1090 // Can't just cast a BOOL (actually a U32) to a U8.
1091 // In some cases the low order bits will be zero.
1092 U8 temp = (b != 0);
1093 addDataFast(gMessageStringTable.getString(varname), &temp, MVT_BOOL, sizeof(temp));
1094}
1095
1096inline void LLMessageSystem::addStringFast(const char* varname, const char* s)
1097{
1098 if (s)
1099 addDataFast( varname, (void *)s, MVT_VARIABLE, (S32)strlen(s) + 1); /* Flawfinder: ignore */
1100 else
1101 addDataFast( varname, NULL, MVT_VARIABLE, 0);
1102}
1103
1104inline void LLMessageSystem::addString(const char* varname, const char* s)
1105{
1106 if (s)
1107 addDataFast( gMessageStringTable.getString(varname), (void *)s, MVT_VARIABLE, (S32)strlen(s) + 1); /* Flawfinder: ignore */
1108 else
1109 addDataFast( gMessageStringTable.getString(varname), NULL, MVT_VARIABLE, 0);
1110}
1111
1112inline void LLMessageSystem::addStringFast(const char* varname, const std::string& s)
1113{
1114 if (s.size())
1115 addDataFast( varname, (void *)s.c_str(), MVT_VARIABLE, (S32)(s.size()) + 1);
1116 else
1117 addDataFast( varname, NULL, MVT_VARIABLE, 0);
1118}
1119
1120inline void LLMessageSystem::addString(const char* varname, const std::string& s)
1121{
1122 if (s.size())
1123 addDataFast( gMessageStringTable.getString(varname), (void *)s.c_str(), MVT_VARIABLE, (S32)(s.size()) + 1);
1124 else
1125 addDataFast( gMessageStringTable.getString(varname), NULL, MVT_VARIABLE, 0);
1126}
1127
1128
1129//-----------------------------------------------------------------------------
1130// Retrieval aliases
1131//-----------------------------------------------------------------------------
1132inline void LLMessageSystem::getS8Fast(const char *block, const char *var, S8 &u, S32 blocknum)
1133{
1134 getDataFast(block, var, &u, sizeof(S8), blocknum);
1135}
1136
1137inline void LLMessageSystem::getS8(const char *block, const char *var, S8 &u, S32 blocknum)
1138{
1139 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &u, sizeof(S8), blocknum);
1140}
1141
1142inline void LLMessageSystem::getU8Fast(const char *block, const char *var, U8 &u, S32 blocknum)
1143{
1144 getDataFast(block, var, &u, sizeof(U8), blocknum);
1145}
1146
1147inline void LLMessageSystem::getU8(const char *block, const char *var, U8 &u, S32 blocknum)
1148{
1149 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &u, sizeof(U8), blocknum);
1150}
1151
1152inline void LLMessageSystem::getBOOLFast(const char *block, const char *var, BOOL &b, S32 blocknum )
1153{
1154 U8 value;
1155 getDataFast(block, var, &value, sizeof(U8), blocknum);
1156 b = (BOOL) value;
1157}
1158
1159inline void LLMessageSystem::getBOOL(const char *block, const char *var, BOOL &b, S32 blocknum )
1160{
1161 U8 value;
1162 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &value, sizeof(U8), blocknum);
1163 b = (BOOL) value;
1164}
1165
1166inline void LLMessageSystem::getS16Fast(const char *block, const char *var, S16 &d, S32 blocknum)
1167{
1168 getDataFast(block, var, &d, sizeof(S16), blocknum);
1169}
1170
1171inline void LLMessageSystem::getS16(const char *block, const char *var, S16 &d, S32 blocknum)
1172{
1173 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &d, sizeof(S16), blocknum);
1174}
1175
1176inline void LLMessageSystem::getU16Fast(const char *block, const char *var, U16 &d, S32 blocknum)
1177{
1178 getDataFast(block, var, &d, sizeof(U16), blocknum);
1179}
1180
1181inline void LLMessageSystem::getU16(const char *block, const char *var, U16 &d, S32 blocknum)
1182{
1183 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &d, sizeof(U16), blocknum);
1184}
1185
1186inline void LLMessageSystem::getS32Fast(const char *block, const char *var, S32 &d, S32 blocknum)
1187{
1188 getDataFast(block, var, &d, sizeof(S32), blocknum);
1189}
1190
1191inline void LLMessageSystem::getS32(const char *block, const char *var, S32 &d, S32 blocknum)
1192{
1193 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &d, sizeof(S32), blocknum);
1194}
1195
1196inline void LLMessageSystem::getU32Fast(const char *block, const char *var, U32 &d, S32 blocknum)
1197{
1198 getDataFast(block, var, &d, sizeof(U32), blocknum);
1199}
1200
1201inline void LLMessageSystem::getU32(const char *block, const char *var, U32 &d, S32 blocknum)
1202{
1203 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &d, sizeof(U32), blocknum);
1204}
1205
1206inline void LLMessageSystem::getU64Fast(const char *block, const char *var, U64 &d, S32 blocknum)
1207{
1208 getDataFast(block, var, &d, sizeof(U64), blocknum);
1209}
1210
1211inline void LLMessageSystem::getU64(const char *block, const char *var, U64 &d, S32 blocknum)
1212{
1213 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &d, sizeof(U64), blocknum);
1214}
1215
1216
1217inline void LLMessageSystem::getIPAddrFast(const char *block, const char *var, U32 &u, S32 blocknum)
1218{
1219 getDataFast(block, var, &u, sizeof(U32), blocknum);
1220}
1221
1222inline void LLMessageSystem::getIPAddr(const char *block, const char *var, U32 &u, S32 blocknum)
1223{
1224 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &u, sizeof(U32), blocknum);
1225}
1226
1227inline void LLMessageSystem::getIPPortFast(const char *block, const char *var, U16 &u, S32 blocknum)
1228{
1229 getDataFast(block, var, &u, sizeof(U16), blocknum);
1230 u = ntohs(u);
1231}
1232
1233inline void LLMessageSystem::getIPPort(const char *block, const char *var, U16 &u, S32 blocknum)
1234{
1235 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), &u, sizeof(U16), blocknum);
1236 u = ntohs(u);
1237}
1238
1239
1240inline void LLMessageSystem::getStringFast(const char *block, const char *var, S32 buffer_size, char *s, S32 blocknum )
1241{
1242 s[0] = '\0';
1243 getDataFast(block, var, s, 0, blocknum, buffer_size);
1244 s[buffer_size - 1] = '\0';
1245}
1246
1247inline void LLMessageSystem::getString(const char *block, const char *var, S32 buffer_size, char *s, S32 blocknum )
1248{
1249 s[0] = '\0';
1250 getDataFast(gMessageStringTable.getString(block), gMessageStringTable.getString(var), s, 0, blocknum, buffer_size);
1251 s[buffer_size - 1] = '\0';
1252}
1253
1254//----------------------------------------------------------------------------- 918//-----------------------------------------------------------------------------
1255// Transmission aliases 919// Transmission aliases
1256//----------------------------------------------------------------------------- 920//-----------------------------------------------------------------------------
1257//inline S32 LLMessageSystem::sendMessage(U32 ip, U32 port, BOOL zero_code)
1258//{
1259// return sendMessage(LLHost(ip, port), zero_code);
1260//}
1261
1262//inline S32 LLMessageSystem::sendMessage(const char *ip_str, U32 port, BOOL zero_code)
1263//{
1264// return sendMessage(LLHost(ip_str, port), zero_code);
1265//}
1266 921
1267inline S32 LLMessageSystem::sendMessage(const U32 circuit)//, BOOL zero_code) 922inline S32 LLMessageSystem::sendMessage(const U32 circuit)
1268{ 923{
1269 return sendMessage(findHost(circuit));//, zero_code); 924 return sendMessage(findHost(circuit));
1270} 925}
1271 926
1272#endif 927#endif