aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llservicebuilder.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:54 -0500
committerJacek Antonelli2008-08-15 23:44:54 -0500
commitb2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch)
tree3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llmessage/llservicebuilder.cpp
parentSecond Life viewer sources 1.14.0.1 (diff)
downloadmeta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/llmessage/llservicebuilder.cpp')
-rw-r--r--linden/indra/llmessage/llservicebuilder.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llservicebuilder.cpp b/linden/indra/llmessage/llservicebuilder.cpp
new file mode 100644
index 0000000..86b7d9d
--- /dev/null
+++ b/linden/indra/llmessage/llservicebuilder.cpp
@@ -0,0 +1,135 @@
1/**
2* @file llservicebuilder.cpp
3* @brief Implementation of the LLServiceBuilder class.
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 "llapp.h"
30#include "llfile.h"
31#include "llservicebuilder.h"
32#include "llsd.h"
33#include "llsdserialize.h"
34
35void LLServiceBuilder::loadServiceDefinitionsFromFile(
36 const std::string& service_filename)
37{
38 llifstream service_file(service_filename.c_str(), std::ios::binary);
39 if(service_file.is_open())
40 {
41 LLSD service_data;
42 LLSDSerialize::fromXML(service_data, service_file);
43 service_file.close();
44 // Load service
45 LLSD service_map = service_data["services"];
46 for(LLSD::array_iterator array_itr = service_map.beginArray();
47 array_itr != service_map.endArray();
48 ++array_itr)
49 {
50 LLSD service_llsd = (*array_itr)["service-builder"];
51 std::string service_name = (*array_itr)["name"].asString();
52 createServiceDefinition(service_name, service_llsd);
53 }
54 llinfos << "loaded config file: " << service_filename << llendl;
55 }
56 else
57 {
58 llwarns << "unable to find config file: " << service_filename << llendl;
59 }
60}
61
62void LLServiceBuilder::createServiceDefinition(
63 const std::string& service_name,
64 LLSD& service_llsd)
65{
66 if(service_llsd.isString())
67 {
68 mServiceMap[ service_name ] = service_llsd.asString();
69 }
70 else if(service_llsd.isMap())
71 {
72 for(LLSD::map_iterator map_itr = service_llsd.beginMap();
73 map_itr != service_llsd.endMap();
74 ++map_itr)
75 {
76 std::string compound_builder_name = service_name;
77 compound_builder_name.append("-");
78 compound_builder_name.append((*map_itr).first);
79 mServiceMap[ compound_builder_name ] = (*map_itr).second.asString();
80 }
81 }
82}
83
84std::string LLServiceBuilder::buildServiceURI(const std::string& service_name)
85{
86 std::ostringstream service_url;
87 // Find the service builder
88 if(mServiceMap.find(service_name) != mServiceMap.end())
89 {
90 // construct the service builder url
91 LLApp* app = LLApp::instance();
92 if(app)
93 {
94 LLSD base_url = app->getOption("services-base-url");
95 service_url << base_url.asString();
96 }
97 service_url << mServiceMap[service_name];
98 }
99 else
100 {
101 llwarns << "Cannot find service " << service_name << llendl;
102 }
103 return service_url.str();
104}
105
106std::string LLServiceBuilder::buildServiceURI(
107 const std::string& service_name,
108 const LLSD& option_map)
109{
110 std::string service_url = buildServiceURI(service_name);
111
112 // Find the Service Name
113 if(!service_url.empty() && option_map.isMap())
114 {
115 // Do brace replacements - NOT CURRENTLY RECURSIVE
116 for(LLSD::map_const_iterator option_itr = option_map.beginMap();
117 option_itr != option_map.endMap();
118 ++option_itr)
119 {
120 std::string variable_name = "{$";
121 variable_name.append((*option_itr).first);
122 variable_name.append("}");
123 std::string::size_type find_pos = service_url.find(variable_name);
124 if(find_pos != std::string::npos)
125 {
126 service_url.replace(
127 find_pos,
128 variable_name.length(),
129 (*option_itr).second.asString());
130 }
131 }
132 }
133
134 return service_url;
135}