llhttpsender.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llhttpsender.h"
00035 
00036 #include <map>
00037 #include <sstream>
00038 
00039 #include "llhost.h"
00040 #include "llsd.h"
00041 
00042 namespace
00043 {
00044         typedef std::map<LLHost, LLHTTPSender*> SenderMap;
00045         static SenderMap senderMap;
00046         static LLHTTPSender* defaultSender = new LLHTTPSender();
00047 }
00048 
00049 //virtual 
00050 LLHTTPSender::~LLHTTPSender()
00051 {
00052 }
00053 
00054 //virtual 
00055 void LLHTTPSender::send(const LLHost& host, const char* name, 
00056                                                 const LLSD& body, 
00057                                                 LLHTTPClient::ResponderPtr response) const
00058 {
00059         // Default implementation inserts sender, message and sends HTTP POST
00060         std::ostringstream stream;
00061         stream << "http://" << host << "/trusted-message/" << name;
00062         llinfos << "LLHTTPSender::send: POST to " << stream.str() << llendl;
00063         LLHTTPClient::post(stream.str(), body, response);
00064 }
00065 
00066 //static 
00067 void LLHTTPSender::setSender(const LLHost& host, LLHTTPSender* sender)
00068 {
00069         llinfos << "LLHTTPSender::setSender " << host << llendl;
00070         senderMap[host] = sender;
00071 }
00072 
00073 //static
00074 const LLHTTPSender& LLHTTPSender::getSender(const LLHost& host)
00075 {
00076         SenderMap::const_iterator iter = senderMap.find(host);
00077         if(iter == senderMap.end())
00078         {
00079                 return *defaultSender;
00080         }
00081         return *(iter->second);
00082 }
00083 
00084 //static 
00085 void LLHTTPSender::clearSender(const LLHost& host)
00086 {
00087         SenderMap::iterator iter = senderMap.find(host);
00088         if(iter != senderMap.end())
00089         {
00090                 delete iter->second;
00091                 senderMap.erase(iter);
00092         }
00093 }
00094 
00095 //static 
00096 void LLHTTPSender::setDefaultSender(LLHTTPSender* sender)
00097 {
00098         delete defaultSender;
00099         defaultSender = sender;
00100 }

Generated on Thu Jul 1 06:08:42 2010 for Second Life Viewer by  doxygen 1.4.7