diff options
Diffstat (limited to 'indra/llmessage/lltemplatemessagereader.cpp')
-rw-r--r-- | indra/llmessage/lltemplatemessagereader.cpp | 137 |
1 files changed, 82 insertions, 55 deletions
diff --git a/indra/llmessage/lltemplatemessagereader.cpp b/indra/llmessage/lltemplatemessagereader.cpp index f9b703b52a..3bfcd58c69 100644 --- a/indra/llmessage/lltemplatemessagereader.cpp +++ b/indra/llmessage/lltemplatemessagereader.cpp @@ -2,30 +2,25 @@ * @file lltemplatemessagereader.cpp * @brief LLTemplateMessageReader class implementation. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -171,9 +166,6 @@ S32 LLTemplateMessageReader::getNumberOfBlocks(const char *blockname) if (iter == mCurrentRMessageData->mMemberBlocks.end()) { -// sprintf(errmsg, "Block %s not in message %s", bnamep, mCurrentRMessageData->mName); -// llerrs << errmsg << llendl; -// return -1; return 0; } @@ -184,15 +176,15 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, const char *varname) { // is there a message ready to go? if (mReceiveSize == -1) - { + { // This is a serious error - crash llerrs << "No message waiting for decode 4!" << llendl; - return -1; + return LL_MESSAGE_ERROR; } if (!mCurrentRMessageData) - { + { // This is a serious error - crash llerrs << "Invalid mCurrentRMessageData in getData!" << llendl; - return -1; + return LL_MESSAGE_ERROR; } char *bnamep = (char *)blockname; @@ -200,10 +192,10 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, const char *varname) LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); if (iter == mCurrentRMessageData->mMemberBlocks.end()) - { - llerrs << "Block " << bnamep << " not in message " + { // don't crash + llinfos << "Block " << bnamep << " not in message " << mCurrentRMessageData->mName << llendl; - return -1; + return LL_BLOCK_NOT_IN_MESSAGE; } char *vnamep = (char *)varname; @@ -212,17 +204,17 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, const char *varname) LLMsgVarData& vardata = msg_data->mMemberVarData[vnamep]; if (!vardata.getName()) - { - llerrs << "Variable " << varname << " not in message " + { // don't crash + llinfos << "Variable " << varname << " not in message " << mCurrentRMessageData->mName << " block " << bnamep << llendl; - return -1; + return LL_VARIABLE_NOT_IN_BLOCK; } if (mCurrentRMessageTemplate->mMemberBlocks[bnamep]->mType != MBT_SINGLE) - { + { // This is a serious error - crash llerrs << "Block " << bnamep << " isn't type MBT_SINGLE," " use getSize with blocknum argument!" << llendl; - return -1; + return LL_MESSAGE_ERROR; } return vardata.getSize(); @@ -232,15 +224,15 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, S32 blocknum, const { // is there a message ready to go? if (mReceiveSize == -1) - { + { // This is a serious error - crash llerrs << "No message waiting for decode 5!" << llendl; - return -1; + return LL_MESSAGE_ERROR; } if (!mCurrentRMessageData) - { + { // This is a serious error - crash llerrs << "Invalid mCurrentRMessageData in getData!" << llendl; - return -1; + return LL_MESSAGE_ERROR; } char *bnamep = (char *)blockname + blocknum; @@ -249,20 +241,20 @@ S32 LLTemplateMessageReader::getSize(const char *blockname, S32 blocknum, const LLMsgData::msg_blk_data_map_t::const_iterator iter = mCurrentRMessageData->mMemberBlocks.find(bnamep); if (iter == mCurrentRMessageData->mMemberBlocks.end()) - { - llerrs << "Block " << bnamep << " not in message " + { // don't crash + llinfos << "Block " << bnamep << " not in message " << mCurrentRMessageData->mName << llendl; - return -1; + return LL_BLOCK_NOT_IN_MESSAGE; } LLMsgBlkData* msg_data = iter->second; LLMsgVarData& vardata = msg_data->mMemberVarData[vnamep]; if (!vardata.getName()) - { - llerrs << "Variable " << vnamep << " not in message " + { // don't crash + llinfos << "Variable " << vnamep << " not in message " << mCurrentRMessageData->mName << " block " << bnamep << llendl; - return -1; + return LL_VARIABLE_NOT_IN_BLOCK; } return vardata.getSize(); @@ -433,6 +425,14 @@ inline void LLTemplateMessageReader::getString(const char *block, const char *va s[buffer_size - 1] = '\0'; } +inline void LLTemplateMessageReader::getString(const char *block, const char *var, std::string& outstr, S32 blocknum ) +{ + char s[MTUBYTES + 1]= {0}; // every element is initialized with 0 + getData(block, var, s, 0, blocknum, MTUBYTES); + s[MTUBYTES] = '\0'; + outstr = s; +} + //virtual S32 LLTemplateMessageReader::getMessageSize() const { @@ -524,6 +524,8 @@ void LLTemplateMessageReader::logRanOffEndOfPacket( const LLHost& host, const S3 gMessageSystem->callExceptionFunc(MX_RAN_OFF_END_OF_PACKET); } +static LLFastTimer::DeclareTimer FTM_PROCESS_MESSAGES("Process Messages"); + // decode a given message BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender ) { @@ -568,7 +570,9 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender // repeat number is a single byte if (decode_pos >= mReceiveSize) { - logRanOffEndOfPacket(sender, decode_pos, 1); + // commented out - hetgrid says that missing variable blocks + // at end of message are legal + // logRanOffEndOfPacket(sender, decode_pos, 1); // default to 0 repeats repeat_number = 0; @@ -667,8 +671,7 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender // default to 0s. U32 size = mvci.getSize(); - std::vector<U8> data(size); - memset(&(data[0]), 0, size); + std::vector<U8> data(size, 0); cur_data_block->addData(mvci.getName(), &(data[0]), size, mvci.getType()); } @@ -701,7 +704,7 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender } { - LLFastTimer t(LLFastTimer::FTM_PROCESS_MESSAGES); + LLFastTimer t(FTM_PROCESS_MESSAGES); if( !mCurrentRMessageTemplate->callHandlerFunc(gMessageSystem) ) { llwarns << "Message from " << sender << " with no handler function received: " << mCurrentRMessageTemplate->mName << llendl; @@ -746,18 +749,38 @@ BOOL LLTemplateMessageReader::decodeData(const U8* buffer, const LLHost& sender BOOL LLTemplateMessageReader::validateMessage(const U8* buffer, S32 buffer_size, - const LLHost& sender) + const LLHost& sender, + bool trusted) { mReceiveSize = buffer_size; - BOOL result = decodeTemplate(buffer, buffer_size, &mCurrentRMessageTemplate ); - if(result) + BOOL valid = decodeTemplate(buffer, buffer_size, &mCurrentRMessageTemplate ); + if(valid) { mCurrentRMessageTemplate->mReceiveCount++; - //lldebugs << "MessageRecvd:" + //lldebugs << "MessageRecvd:" // << mCurrentRMessageTemplate->mName // << " from " << sender << llendl; } - return result; + + if (valid && isBanned(trusted)) + { + LL_WARNS("Messaging") << "LLMessageSystem::checkMessages " + << "received banned message " + << getMessageName() + << " from " + << ((trusted) ? "trusted " : "untrusted ") + << sender << llendl; + valid = FALSE; + } + + if(valid && isUdpBanned()) + { + llwarns << "Received UDP black listed message " + << getMessageName() + << " from " << sender << llendl; + valid = FALSE; + } + return valid; } BOOL LLTemplateMessageReader::readMessage(const U8* buffer, @@ -783,12 +806,16 @@ bool LLTemplateMessageReader::isTrusted() const return mCurrentRMessageTemplate->getTrust() == MT_TRUST; } -//virtual bool LLTemplateMessageReader::isBanned(bool trustedSource) const { return mCurrentRMessageTemplate->isBanned(trustedSource); } +bool LLTemplateMessageReader::isUdpBanned() const +{ + return mCurrentRMessageTemplate->isUdpBanned(); +} + //virtual void LLTemplateMessageReader::copyToBuilder(LLMessageBuilder& builder) const { |