aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lltemplatemessagereader.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:02 -0500
committerJacek Antonelli2008-08-15 23:45:02 -0500
commitd644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch)
tree7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/llmessage/lltemplatemessagereader.cpp
parentSecond Life viewer sources 1.17.3.0 (diff)
downloadmeta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz
Second Life viewer sources 1.18.0.6
Diffstat (limited to 'linden/indra/llmessage/lltemplatemessagereader.cpp')
-rw-r--r--linden/indra/llmessage/lltemplatemessagereader.cpp151
1 files changed, 97 insertions, 54 deletions
diff --git a/linden/indra/llmessage/lltemplatemessagereader.cpp b/linden/indra/llmessage/lltemplatemessagereader.cpp
index bb3f4f4..a1f5213 100644
--- a/linden/indra/llmessage/lltemplatemessagereader.cpp
+++ b/linden/indra/llmessage/lltemplatemessagereader.cpp
@@ -1,3 +1,31 @@
1/**
2 * @file lltemplatemessagereader.cpp
3 * @brief LLTemplateMessageReader class implementation.
4 *
5 * Copyright (c) 2007-2007, Linden Research, Inc.
6 *
7 * Second Life Viewer Source Code
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
1#include "lltemplatemessagereader.h" 29#include "lltemplatemessagereader.h"
2 30
3#include "llfasttimer.h" 31#include "llfasttimer.h"
@@ -53,7 +81,7 @@ void LLTemplateMessageReader::getData(const char *blockname, const char *varname
53 char *bnamep = (char *)blockname + blocknum; // this works because it's just a hash. The bnamep is never derefference 81 char *bnamep = (char *)blockname + blocknum; // this works because it's just a hash. The bnamep is never derefference
54 char *vnamep = (char *)varname; 82 char *vnamep = (char *)varname;
55 83
56 LLMsgData::msg_blk_data_map_t::iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); 84 LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep);
57 85
58 if (iter == mCurrentRMessageData->mMemberBlocks.end()) 86 if (iter == mCurrentRMessageData->mMemberBlocks.end())
59 { 87 {
@@ -135,7 +163,7 @@ S32 LLTemplateMessageReader::getNumberOfBlocks(const char *blockname)
135 163
136 char *bnamep = (char *)blockname; 164 char *bnamep = (char *)blockname;
137 165
138 LLMsgData::msg_blk_data_map_t::iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); 166 LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep);
139 167
140 if (iter == mCurrentRMessageData->mMemberBlocks.end()) 168 if (iter == mCurrentRMessageData->mMemberBlocks.end())
141 { 169 {
@@ -165,7 +193,7 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, const char *varname)
165 193
166 char *bnamep = (char *)blockname; 194 char *bnamep = (char *)blockname;
167 195
168 LLMsgData::msg_blk_data_map_t::iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); 196 LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep);
169 197
170 if (iter == mCurrentRMessageData->mMemberBlocks.end()) 198 if (iter == mCurrentRMessageData->mMemberBlocks.end())
171 { 199 {
@@ -214,7 +242,7 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, S32 blocknum, const
214 char *bnamep = (char *)blockname + blocknum; 242 char *bnamep = (char *)blockname + blocknum;
215 char *vnamep = (char *)varname; 243 char *vnamep = (char *)varname;
216 244
217 LLMsgData::msg_blk_data_map_t::iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); 245 LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep);
218 246
219 if (iter == mCurrentRMessageData->mMemberBlocks.end()) 247 if (iter == mCurrentRMessageData->mMemberBlocks.end())
220 { 248 {
@@ -497,16 +525,21 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
497 llassert( !mCurrentRMessageData ); 525 llassert( !mCurrentRMessageData );
498 delete mCurrentRMessageData; // just to make sure 526 delete mCurrentRMessageData; // just to make sure
499 527
500 S32 decode_pos = LL_PACKET_ID_SIZE + (S32)(mCurrentRMessageTemplate->mFrequency); 528 // The offset tells us how may bytes to skip after the end of the
529 // message name.
530 U8 offset = buffer[PHL_OFFSET];
531 S32 decode_pos = LL_PACKET_ID_SIZE + (S32)(mCurrentRMessageTemplate->mFrequency) + offset;
501 532
502 // create base working data set 533 // create base working data set
503 mCurrentRMessageData = new LLMsgData(mCurrentRMessageTemplate->mName); 534 mCurrentRMessageData = new LLMsgData(mCurrentRMessageTemplate->mName);
504 535
505 // loop through the template building the data structure as we go 536 // loop through the template building the data structure as we go
506 for (LLMessageTemplate::message_block_map_t::iterator iter = mCurrentRMessageTemplate->mMemberBlocks.begin(); 537 LLMessageTemplate::message_block_map_t::const_iterator iter;
507 iter != mCurrentRMessageTemplate->mMemberBlocks.end(); iter++) 538 for(iter = mCurrentRMessageTemplate->mMemberBlocks.begin();
539 iter != mCurrentRMessageTemplate->mMemberBlocks.end();
540 ++iter)
508 { 541 {
509 LLMessageBlock* mbci = iter->second; 542 LLMessageBlock* mbci = *iter;
510 U8 repeat_number; 543 U8 repeat_number;
511 S32 i; 544 S32 i;
512 545
@@ -528,11 +561,16 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
528 // repeat number is a single byte 561 // repeat number is a single byte
529 if (decode_pos >= mReceiveSize) 562 if (decode_pos >= mReceiveSize)
530 { 563 {
531 logRanOffEndOfPacket( sender ); 564 logRanOffEndOfPacket(sender);
532 return FALSE; 565
566 // default to 0 repeats
567 repeat_number = 0;
568 }
569 else
570 {
571 repeat_number = buffer[decode_pos];
572 decode_pos++;
533 } 573 }
534 repeat_number = buffer[decode_pos];
535 decode_pos++;
536 } 574 }
537 else 575 else
538 { 576 {
@@ -561,10 +599,12 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
561 mCurrentRMessageData->addBlock(cur_data_block); 599 mCurrentRMessageData->addBlock(cur_data_block);
562 600
563 // now read the variables 601 // now read the variables
564 for (LLMessageBlock::message_variable_map_t::iterator iter = mbci->mMemberVariables.begin(); 602 for (LLMessageBlock::message_variable_map_t::const_iterator iter =
603 mbci->mMemberVariables.begin();
565 iter != mbci->mMemberVariables.end(); iter++) 604 iter != mbci->mMemberVariables.end(); iter++)
566 { 605 {
567 LLMessageVariable& mvci = *(iter->second); 606 const LLMessageVariable& mvci = **iter;
607
568 // ok, build out the variables 608 // ok, build out the variables
569 // add variable block 609 // add variable block
570 cur_data_block->addVariable(mvci.getName(), mvci.getType()); 610 cur_data_block->addVariable(mvci.getName(), mvci.getType());
@@ -580,34 +620,33 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
580 620
581 if ((decode_pos + data_size) > mReceiveSize) 621 if ((decode_pos + data_size) > mReceiveSize)
582 { 622 {
583 logRanOffEndOfPacket( sender ); 623 logRanOffEndOfPacket(sender);
584 return FALSE; 624
625 // default to 0 length variable blocks
626 tsize = 0;
585 } 627 }
586 switch(data_size) 628 else
587 { 629 {
588 case 1: 630 switch(data_size)
589 htonmemcpy(&tsizeb, &buffer[decode_pos], MVT_U8, 1); 631 {
590 tsize = tsizeb; 632 case 1:
591 break; 633 htonmemcpy(&tsizeb, &buffer[decode_pos], MVT_U8, 1);
592 case 2: 634 tsize = tsizeb;
593 htonmemcpy(&tsizeh, &buffer[decode_pos], MVT_U16, 2); 635 break;
594 tsize = tsizeh; 636 case 2:
595 break; 637 htonmemcpy(&tsizeh, &buffer[decode_pos], MVT_U16, 2);
596 case 4: 638 tsize = tsizeh;
597 htonmemcpy(&tsize, &buffer[decode_pos], MVT_U32, 4); 639 break;
598 break; 640 case 4:
599 default: 641 htonmemcpy(&tsize, &buffer[decode_pos], MVT_U32, 4);
600 llerrs << "Attempting to read variable field with unknown size of " << data_size << llendl; 642 break;
601 break; 643 default:
602 644 llerrs << "Attempting to read variable field with unknown size of " << data_size << llendl;
645 break;
646 }
603 } 647 }
604 decode_pos += data_size; 648 decode_pos += data_size;
605 649
606 if ((decode_pos + (S32)tsize) > mReceiveSize)
607 {
608 logRanOffEndOfPacket( sender );
609 return FALSE;
610 }
611 cur_data_block->addData(mvci.getName(), &buffer[decode_pos], tsize, mvci.getType()); 650 cur_data_block->addData(mvci.getName(), &buffer[decode_pos], tsize, mvci.getType());
612 decode_pos += tsize; 651 decode_pos += tsize;
613 } 652 }
@@ -615,14 +654,24 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
615 { 654 {
616 // fixed! 655 // fixed!
617 // so, copy data pointer and set data size to fixed size 656 // so, copy data pointer and set data size to fixed size
618
619 if ((decode_pos + mvci.getSize()) > mReceiveSize) 657 if ((decode_pos + mvci.getSize()) > mReceiveSize)
620 { 658 {
621 logRanOffEndOfPacket( sender ); 659 logRanOffEndOfPacket(sender);
622 return FALSE; 660
661 // default to 0s.
662 U32 size = mvci.getSize();
663 std::vector<U8> data(size);
664 memset(&(data[0]), 0, size);
665 cur_data_block->addData(mvci.getName(), &(data[0]),
666 size, mvci.getType());
667 }
668 else
669 {
670 cur_data_block->addData(mvci.getName(),
671 &buffer[decode_pos],
672 mvci.getSize(),
673 mvci.getType());
623 } 674 }
624
625 cur_data_block->addData(mvci.getName(), &buffer[decode_pos], mvci.getSize(), mvci.getType());
626 decode_pos += mvci.getSize(); 675 decode_pos += mvci.getSize();
627 } 676 }
628 } 677 }
@@ -644,11 +693,6 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
644 decode_timer.reset(); 693 decode_timer.reset();
645 } 694 }
646 695
647 // if( mCurrentRMessageTemplate->mName == _PREHASH_AgentToNewRegion )
648 // {
649 // VTResume(); // VTune
650 // }
651
652 { 696 {
653 LLFastTimer t(LLFastTimer::FTM_PROCESS_MESSAGES); 697 LLFastTimer t(LLFastTimer::FTM_PROCESS_MESSAGES);
654 if( !mCurrentRMessageTemplate->callHandlerFunc(gMessageSystem) ) 698 if( !mCurrentRMessageTemplate->callHandlerFunc(gMessageSystem) )
@@ -657,11 +701,6 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender
657 } 701 }
658 } 702 }
659 703
660 // if( mCurrentRMessageTemplate->mName == _PREHASH_AgentToNewRegion )
661 // {
662 // VTPause(); // VTune
663 // }
664
665 if(LLMessageReader::getTimeDecodes() || gMessageSystem->getTimingCallback()) 704 if(LLMessageReader::getTimeDecodes() || gMessageSystem->getTimingCallback())
666 { 705 {
667 F32 decode_time = decode_timer.getElapsedTimeF32(); 706 F32 decode_time = decode_timer.getElapsedTimeF32();
@@ -723,8 +762,12 @@ BOOL LLTemplateMessageReader::readMessage(const U8* buffer,
723//virtual 762//virtual
724const char* LLTemplateMessageReader::getMessageName() const 763const char* LLTemplateMessageReader::getMessageName() const
725{ 764{
726 static char empty_string[] = ""; 765 if (!mCurrentRMessageTemplate)
727 return mCurrentRMessageTemplate ? mCurrentRMessageTemplate->mName : empty_string; 766 {
767 llwarns << "no mCurrentRMessageTemplate" << llendl;
768 return "";
769 }
770 return mCurrentRMessageTemplate->mName;
728} 771}
729 772
730//virtual 773//virtual