summaryrefslogtreecommitdiff
path: root/indra/llmessage/message.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/message.h')
-rw-r--r--indra/llmessage/message.h187
1 files changed, 132 insertions, 55 deletions
diff --git a/indra/llmessage/message.h b/indra/llmessage/message.h
index 61d34b7fc1..1589ea29c1 100644
--- a/indra/llmessage/message.h
+++ b/indra/llmessage/message.h
@@ -2,30 +2,25 @@
* @file message.h
* @brief LLMessageSystem class header file
*
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2001&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$
*/
@@ -58,17 +53,20 @@
#include "llhttpclient.h"
#include "llhttpnode.h"
#include "llpacketack.h"
+#include "llsingleton.h"
#include "message_prehash.h"
#include "llstl.h"
#include "llmsgvariabletype.h"
-#include "llmsgvariabletype.h"
+#include "llmessagesenderinterface.h"
+
+#include "llstoredmessage.h"
const U32 MESSAGE_MAX_STRINGS_LENGTH = 64;
const U32 MESSAGE_NUMBER_OF_HASH_BUCKETS = 8192;
const S32 MESSAGE_MAX_PER_FRAME = 400;
-class LLMessageStringTable
+class LLMessageStringTable : public LLSingleton<LLMessageStringTable>
{
public:
LLMessageStringTable();
@@ -81,7 +79,6 @@ public:
char mString[MESSAGE_NUMBER_OF_HASH_BUCKETS][MESSAGE_MAX_STRINGS_LENGTH]; /* Flawfinder: ignore */
};
-extern LLMessageStringTable gMessageStringTable;
// Individual Messages are described with the following format
// Note that to ease parsing, keywords are used
@@ -206,12 +203,15 @@ public:
virtual void complete(const LLHost& host, const LLUUID& agent) const = 0;
};
-class LLMessageSystem
+class LLMessageSystem : public LLMessageSenderInterface
{
private:
U8 mSendBuffer[MAX_BUFFER_SIZE];
S32 mSendSize;
+ bool mBlockUntrustedInterface;
+ LLHost mUntrustedInterface;
+
public:
LLPacketRing mPacketRing;
LLReliablePacketParams mReliablePacketParams;
@@ -284,8 +284,10 @@ public:
public:
// Read file and build message templates
- LLMessageSystem(const char *filename, U32 port, S32 version_major,
- S32 version_minor, S32 version_patch);
+ LLMessageSystem(const std::string& filename, U32 port, S32 version_major,
+ S32 version_minor, S32 version_patch,
+ bool failure_is_fatal,
+ const F32 circuit_heartbeat_interval, const F32 circuit_timeout);
~LLMessageSystem();
@@ -295,14 +297,14 @@ public:
// Read file and build message templates filename must point to a
// valid string which specifies the path of a valid linden
// template.
- void loadTemplateFile(const char* filename);
+ void loadTemplateFile(const std::string& filename, bool failure_is_fatal);
// methods for building, sending, receiving, and handling messages
void setHandlerFuncFast(const char *name, void (*handler_func)(LLMessageSystem *msgsystem, void **user_data), void **user_data = NULL);
void setHandlerFunc(const char *name, void (*handler_func)(LLMessageSystem *msgsystem, void **user_data), void **user_data = NULL)
{
- setHandlerFuncFast(gMessageStringTable.getString(name), handler_func, user_data);
+ setHandlerFuncFast(LLMessageStringTable::getInstance()->getString(name), handler_func, user_data);
}
// Set a callback function for a message system exception.
@@ -339,7 +341,7 @@ public:
BOOL isMessageFast(const char *msg);
BOOL isMessage(const char *msg)
{
- return isMessageFast(gMessageStringTable.getString(msg));
+ return isMessageFast(LLMessageStringTable::getInstance()->getString(msg));
}
void dumpPacketToLog();
@@ -350,6 +352,8 @@ public:
U32 getSenderIP() const; // getSender() is preferred
U32 getSenderPort() const; // getSender() is preferred
+ const LLHost& getReceivingInterface() const;
+
// This method returns the uuid associated with the sender. The
// UUID will be null if it is not yet known or is a server
// circuit.
@@ -366,14 +370,34 @@ public:
void newMessageFast(const char *name);
void newMessage(const char *name);
- void copyMessageRtoS();
- void clearMessage();
+
+public:
+ LLStoredMessagePtr getReceivedMessage() const;
+ LLStoredMessagePtr getBuiltMessage() const;
+ S32 sendMessage(const LLHost &host, LLStoredMessagePtr message);
+
+private:
+ LLSD getReceivedMessageLLSD() const;
+ LLSD getBuiltMessageLLSD() const;
+
+ // NOTE: babbage: Only use to support legacy misuse of the
+ // LLMessageSystem API where values are dangerously written
+ // as one type and read as another. LLSD does not support
+ // dangerous conversions and so converting the message to an
+ // LLSD would result in the reads failing. All code which
+ // misuses the message system in this way should be made safe
+ // but while the unsafe code is run in old processes, this
+ // method should be used to forward unsafe messages.
+ LLSD wrapReceivedTemplateData() const;
+ LLSD wrapBuiltTemplateData() const;
+
+public:
+
+ void copyMessageReceivedToSend();
+ void clearMessage();
void nextBlockFast(const char *blockname);
- void nextBlock(const char *blockname)
- {
- nextBlockFast(gMessageStringTable.getString(blockname));
- }
+ void nextBlock(const char *blockname);
public:
void addBinaryDataFast(const char *varname, const void *data, S32 size);
@@ -454,14 +478,14 @@ public:
void (*callback)(void **,S32), void ** callback_data);
// flush sends a message only if data's been pushed on it.
- S32 flushSemiReliable( const LLHost &host,
+ S32 flushSemiReliable( const LLHost &host,
void (*callback)(void **,S32), void ** callback_data);
- S32 flushReliable( const LLHost &host );
+ S32 flushReliable( const LLHost &host );
- void forwardMessage(const LLHost &host);
- void forwardReliable(const LLHost &host);
- void forwardReliable(const U32 circuit_code);
+ void forwardMessage(const LLHost &host);
+ void forwardReliable(const LLHost &host);
+ void forwardReliable(const U32 circuit_code);
S32 forwardReliable(
const LLHost &host,
S32 retries,
@@ -473,11 +497,28 @@ public:
LLHTTPClient::ResponderPtr createResponder(const std::string& name);
S32 sendMessage(const LLHost &host);
S32 sendMessage(const U32 circuit);
+private:
S32 sendMessage(const LLHost &host, const char* name,
const LLSD& message);
-
+public:
// BOOL decodeData(const U8 *buffer, const LLHost &host);
+ /**
+ gets binary data from the current message.
+
+ @param blockname the name of the block in the message (from the message template)
+
+ @param varname
+
+ @param datap
+
+ @param size expected size - set to zero to get any amount of data up to max_size.
+ Make sure max_size is set in that case!
+
+ @param blocknum
+
+ @param max_size the max number of bytes to read
+ */
void getBinaryDataFast(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
void getBinaryData(const char *blockname, const char *varname, void *datap, S32 size, S32 blocknum = 0, S32 max_size = S32_MAX);
void getBOOLFast( const char *block, const char *var, BOOL &data, S32 blocknum = 0);
@@ -516,6 +557,8 @@ public:
void getIPPort( const char *block, const char *var, U16 &port, S32 blocknum = 0);
void getStringFast( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
void getString( const char *block, const char *var, S32 buffer_size, char *buffer, S32 blocknum = 0);
+ void getStringFast( const char *block, const char *var, std::string& outstr, S32 blocknum = 0);
+ void getString( const char *block, const char *var, std::string& outstr, S32 blocknum = 0);
// Utility functions to generate a replay-resistant digest check
@@ -552,14 +595,28 @@ public:
void sendDenyTrustedCircuit(const LLHost &host);
/** Return false if host is unknown or untrusted */
+ // Note:DaveH/Babbage some trusted messages can be received without a circuit
bool isTrustedSender(const LLHost& host) const;
+ /** Return true if current message is from trusted source */
+ bool isTrustedSender() const;
+
/** Return false true if name is unknown or untrusted */
bool isTrustedMessage(const std::string& name) const;
/** Return false true if name is unknown or trusted */
bool isUntrustedMessage(const std::string& name) const;
+ // Mark an interface ineligible for trust
+ void setUntrustedInterface( const LLHost host ) { mUntrustedInterface = host; }
+ LLHost getUntrustedInterface() const { return mUntrustedInterface; }
+ void setBlockUntrustedInterface( bool block ) { mBlockUntrustedInterface = block; } // Throw a switch to allow, sending warnings only
+ bool getBlockUntrustedInterface() const { return mBlockUntrustedInterface; }
+
+ // Change this message to be UDP black listed.
+ void banUdpMessage(const std::string& name);
+
+
private:
// A list of the circuits that need to be sent DenyTrustedCircuit messages.
typedef std::set<LLHost> host_set_t;
@@ -576,6 +633,7 @@ public:
void establishBidirectionalTrust(const LLHost &host, S64 frame_count = 0);
// returns whether the given host is on a trusted circuit
+ // Note:DaveH/Babbage some trusted messages can be received without a circuit
BOOL getCircuitTrust(const LLHost &host);
void setCircuitAllowTimeout(const LLHost &host, BOOL allow);
@@ -589,13 +647,14 @@ public:
LLHost findHost(const U32 circuit_code);
void sanityCheck();
- S32 getNumberOfBlocksFast(const char *blockname);
- S32 getNumberOfBlocks(const char *blockname);
- S32 getSizeFast(const char *blockname, const char *varname);
- S32 getSize(const char *blockname, const char *varname);
+ BOOL has(const char *blockname) const;
+ S32 getNumberOfBlocksFast(const char *blockname) const;
+ S32 getNumberOfBlocks(const char *blockname) const;
+ S32 getSizeFast(const char *blockname, const char *varname) const;
+ S32 getSize(const char *blockname, const char *varname) const;
S32 getSizeFast(const char *blockname, S32 blocknum,
- const char *varname); // size in bytes of data
- S32 getSize(const char *blockname, S32 blocknum, const char *varname);
+ const char *varname) const; // size in bytes of data
+ S32 getSize(const char *blockname, S32 blocknum, const char *varname) const;
void resetReceiveCounts(); // resets receive counts for all message types to 0
void dumpReceiveCounts(); // dumps receive count for each message type to llinfos
@@ -644,6 +703,12 @@ public:
const LLSD& message,
LLHTTPNode::ResponsePtr responsep);
+ // this is added to support specific legacy messages and is
+ // ***not intended for general use*** Si, Gabriel, 2009
+ static void dispatchTemplate(const std::string& msg_name,
+ const LLSD& message,
+ LLHTTPNode::ResponsePtr responsep);
+
void setMessageBans(const LLSD& trusted, const LLSD& untrusted);
/**
@@ -671,9 +736,18 @@ public:
// Check UDP messages and pump http_pump to receive HTTP messages.
bool checkAllMessages(S64 frame_count, LLPumpIO* http_pump);
+
+ // Moved to allow access from LLTemplateMessageDispatcher
+ void clearReceiveState();
+
+ // This will cause all trust queries to return true until the next message
+ // is read: use with caution!
+ void receivedMessageFromTrustedSender();
private:
+ bool mLastMessageFromTrustedMessageService;
+
// The mCircuitCodes is a map from circuit codes to session
// ids. This allows us to verify sessions on connect.
typedef std::map<U32, LLUUID> code_session_map_t;
@@ -684,7 +758,6 @@ private:
LLUUID mSessionID;
void addTemplate(LLMessageTemplate *templatep);
- void clearReceiveState();
BOOL decodeTemplate( const U8* buffer, S32 buffer_size, LLMessageTemplate** msg_template );
void logMsgFromInvalidCircuit( const LLHost& sender, BOOL recv_reliable );
@@ -739,6 +812,7 @@ private:
void init(); // ctor shared initialisation.
LLHost mLastSender;
+ LLHost mLastReceivingIF;
S32 mIncomingCompressedSize; // original size of compressed msg (0 if uncomp.)
TPACKETID mCurrentRecvPacketID; // packet ID of current receive packet (for reporting)
@@ -765,18 +839,21 @@ extern LLMessageSystem *gMessageSystem;
// Must specific overall system version, which is used to determine
// if a patch is available in the message template checksum verification.
-// Return TRUE if able to initialize system.
-BOOL start_messaging_system(
+// Return true if able to initialize system.
+bool start_messaging_system(
const std::string& template_name,
U32 port,
S32 version_major,
S32 version_minor,
S32 version_patch,
- BOOL b_dump_prehash_file,
+ bool b_dump_prehash_file,
const std::string& secret,
- const LLUseCircuitCodeResponder* responder = NULL);
+ const LLUseCircuitCodeResponder* responder,
+ bool failure_is_fatal,
+ const F32 circuit_heartbeat_interval,
+ const F32 circuit_timeout);
-void end_messaging_system();
+void end_messaging_system(bool print_summary = true);
void null_message_callback(LLMessageSystem *msg, void **data);
@@ -953,8 +1030,7 @@ inline void *ntohmemcpy(void *s, const void *ct, EMsgVariableType type, size_t n
return(htonmemcpy(s,ct,type, n));
}
-
-inline const LLHost& LLMessageSystem::getSender() const {return mLastSender;}
+inline const LLHost& LLMessageSystem::getReceivingInterface() const {return mLastReceivingIF;}
inline U32 LLMessageSystem::getSenderIP() const
{
@@ -966,6 +1042,7 @@ inline U32 LLMessageSystem::getSenderPort() const
return mLastSender.getPort();
}
+
//-----------------------------------------------------------------------------
// Transmission aliases
//-----------------------------------------------------------------------------