aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llhttpsender.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/llhttpsender.cpp')
-rw-r--r--linden/indra/llmessage/llhttpsender.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llhttpsender.cpp b/linden/indra/llmessage/llhttpsender.cpp
new file mode 100644
index 0000000..f96e6d2
--- /dev/null
+++ b/linden/indra/llmessage/llhttpsender.cpp
@@ -0,0 +1,90 @@
1/**
2 * @file llhttpsender.cpp
3 * @brief Abstracts details of sending messages via HTTP.
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
29#include "linden_common.h"
30
31#include "llhttpsender.h"
32
33#include <map>
34#include <sstream>
35
36#include "llhost.h"
37#include "llsd.h"
38
39namespace
40{
41 typedef std::map<LLHost, LLHTTPSender*> SenderMap;
42 static SenderMap senderMap;
43}
44
45//virtual
46LLHTTPSender::~LLHTTPSender()
47{
48}
49
50//virtual
51void LLHTTPSender::send(const LLHost& host, const char* name,
52 const LLSD& body,
53 LLHTTPClient::ResponderPtr response) const
54{
55 // Default implementation inserts sender, message and sends HTTP POST
56 std::ostringstream stream;
57 stream << "http://" << host << "/trusted-message/" << name;
58 llinfos << "LLHTTPSender::send: POST to " << stream.str() << llendl;
59 LLHTTPClient::post(stream.str(), body, response);
60}
61
62//static
63void LLHTTPSender::setSender(const LLHost& host, LLHTTPSender* sender)
64{
65 llinfos << "LLHTTPSender::setSender " << host << llendl;
66 senderMap[host] = sender;
67}
68
69//static
70const LLHTTPSender& LLHTTPSender::getSender(const LLHost& host)
71{
72 static LLHTTPSender defaultSender;
73 SenderMap::const_iterator iter = senderMap.find(host);
74 if(iter == senderMap.end())
75 {
76 return defaultSender;
77 }
78 return *(iter->second);
79}
80
81//static
82void LLHTTPSender::clearSender(const LLHost& host)
83{
84 SenderMap::iterator iter = senderMap.find(host);
85 if(iter != senderMap.end())
86 {
87 delete iter->second;
88 senderMap.erase(iter);
89 }
90}