PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llhttpsender.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 95 lines | 52 code | 11 blank | 32 comment | 4 complexity | c4e7cb8107e33adbba6f107307ecd8b2 MD5 | raw file
 1/** 
 2 * @file llhttpsender.cpp
 3 * @brief Abstracts details of sending messages via HTTP.
 4 *
 5 * $LicenseInfo:firstyear=2007&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 "llhttpsender.h"
30
31#include <map>
32#include <sstream>
33
34#include "llhost.h"
35#include "llsd.h"
36
37namespace
38{
39	typedef std::map<LLHost, LLHTTPSender*> SenderMap;
40	static SenderMap senderMap;
41	static LLHTTPSender* defaultSender = new LLHTTPSender();
42}
43
44//virtual 
45LLHTTPSender::~LLHTTPSender()
46{
47}
48
49//virtual 
50void LLHTTPSender::send(const LLHost& host, const std::string& name, 
51						const LLSD& body, 
52						LLHTTPClient::ResponderPtr response) const
53{
54	// Default implementation inserts sender, message and sends HTTP POST
55	std::ostringstream stream;
56	stream << "http://" << host << "/trusted-message/" << name;
57	llinfos << "LLHTTPSender::send: POST to " << stream.str() << llendl;
58	LLHTTPClient::post(stream.str(), body, response);
59}
60
61//static 
62void LLHTTPSender::setSender(const LLHost& host, LLHTTPSender* sender)
63{
64	llinfos << "LLHTTPSender::setSender " << host << llendl;
65	senderMap[host] = sender;
66}
67
68//static
69const LLHTTPSender& LLHTTPSender::getSender(const LLHost& host)
70{
71	SenderMap::const_iterator iter = senderMap.find(host);
72	if(iter == senderMap.end())
73	{
74		return *defaultSender;
75	}
76	return *(iter->second);
77}
78
79//static 
80void LLHTTPSender::clearSender(const LLHost& host)
81{
82	SenderMap::iterator iter = senderMap.find(host);
83	if(iter != senderMap.end())
84	{
85		delete iter->second;
86		senderMap.erase(iter);
87	}
88}
89
90//static 
91void LLHTTPSender::setDefaultSender(LLHTTPSender* sender)
92{
93	delete defaultSender;
94	defaultSender = sender;
95}