PageRenderTime 32ms CodeModel.GetById 23ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/lltrustedmessageservice.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 84 lines | 49 code | 7 blank | 28 comment | 5 complexity | 2e4c302d9f94ecd023a8378463e91215 MD5 | raw file
 1/**
 2 * @file lltrustedmessageservice.cpp
 3 * @brief LLTrustedMessageService implementation
 4 *
 5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "linden_common.h"
28
29#include "lltrustedmessageservice.h"
30#include "llhost.h"
31#include "llmessageconfig.h"
32#include "message.h"
33
34
35bool LLTrustedMessageService::validate(const std::string& name, LLSD& context)
36const
37{
38	return true;
39}
40
41void LLTrustedMessageService::post(LLHTTPNode::ResponsePtr response,
42								   const LLSD& context,
43								   const LLSD& input) const
44{
45	std::string name = context["request"]["wildcard"]["message-name"];
46	std::string senderIP = context["request"]["remote-host"];
47	std::string senderPort = context["request"]["headers"]
48		["x-secondlife-udp-listen-port"];
49
50	LLSD message_data;
51	std::string sender = senderIP + ":" + senderPort;
52	message_data["sender"] = sender;
53	message_data["body"] = input;
54	
55	// untrusted senders should not have access to the trusted message
56	// service, but this can happen in development, so check and warn
57	LLMessageConfig::SenderTrust trust =
58		LLMessageConfig::getSenderTrustedness(name);
59	if ((trust == LLMessageConfig::TRUSTED ||
60		 (trust == LLMessageConfig::NOT_SET &&
61		  gMessageSystem->isTrustedMessage(name)))
62		 && !gMessageSystem->isTrustedSender(LLHost(sender)))
63	{
64		LL_WARNS("Messaging") << "trusted message POST to /trusted-message/" 
65				<< name << " from unknown or untrusted sender "
66				<< sender << llendl;
67		response->status(403, "Unknown or untrusted sender");
68	}
69	else
70	{
71		gMessageSystem->receivedMessageFromTrustedSender();
72		if (input.has("binary-template-data"))
73		{
74			llinfos << "Dispatching template: " << input << llendl;
75			// try and send this message using udp dispatch
76			LLMessageSystem::dispatchTemplate(name, message_data, response);
77		}
78		else
79		{
80			llinfos << "Dispatching without template: " << input << llendl;
81			LLMessageSystem::dispatch(name, message_data, response);
82		}
83	}
84}