diff options
Diffstat (limited to 'indra/llmessage/llservicebuilder.cpp')
-rw-r--r-- | indra/llmessage/llservicebuilder.cpp | 141 |
1 files changed, 58 insertions, 83 deletions
diff --git a/indra/llmessage/llservicebuilder.cpp b/indra/llmessage/llservicebuilder.cpp index d5c6014140..b9aef3d0ba 100644 --- a/indra/llmessage/llservicebuilder.cpp +++ b/indra/llmessage/llservicebuilder.cpp @@ -2,30 +2,25 @@ * @file llservicebuilder.cpp * @brief Implementation of the LLServiceBuilder class. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -39,11 +34,11 @@ void LLServiceBuilder::loadServiceDefinitionsFromFile( const std::string& service_filename) { - llifstream service_file(service_filename.c_str(), std::ios::binary); + llifstream service_file(service_filename, std::ios::binary); if(service_file.is_open()) { LLSD service_data; - LLSDSerialize::fromXML(service_data, service_file); + LLSDSerialize::fromXMLDocument(service_data, service_file); service_file.close(); // Load service LLSD service_map = service_data["services"]; @@ -85,20 +80,42 @@ void LLServiceBuilder::createServiceDefinition( } } -std::string LLServiceBuilder::buildServiceURI(const std::string& service_name) +static +bool starts_with(const std::string& text, const char* prefix) +{ + return text.substr(0, strlen(prefix)) == prefix; +} + +// TODO: Build a real services.xml for windows development. +// and remove the base_url logic below. +std::string LLServiceBuilder::buildServiceURI(const std::string& service_name) const { std::ostringstream service_url; // Find the service builder - if(mServiceMap.find(service_name) != mServiceMap.end()) + std::map<std::string, std::string>::const_iterator it = + mServiceMap.find(service_name); + if(it != mServiceMap.end()) { // construct the service builder url LLApp* app = LLApp::instance(); if(app) { - LLSD base_url = app->getOption("services-base-url"); + // We define a base-url for some development configurations + // In production neither of these are defined and all services have full urls + LLSD base_url; + + if (starts_with(service_name,"cap")) + { + base_url = app->getOption("cap-base-url"); + } + + if (base_url.asString().empty()) + { + base_url = app->getOption("services-base-url"); + } service_url << base_url.asString(); } - service_url << mServiceMap[service_name]; + service_url << it->second; } else { @@ -109,12 +126,15 @@ std::string LLServiceBuilder::buildServiceURI(const std::string& service_name) std::string LLServiceBuilder::buildServiceURI( const std::string& service_name, - const LLSD& option_map) + const LLSD& option_map) const +{ + return russ_format(buildServiceURI(service_name), option_map); +} + +std::string russ_format(const std::string& format_str, const LLSD& context) { - std::string service_url = buildServiceURI(service_name); - - // Find the Service Name - if(!service_url.empty() && option_map.isMap()) + std::string service_url(format_str); + if(!service_url.empty() && context.isMap()) { // throw in a ridiculously large limiter to make sure we don't // loop forever with bad input. @@ -134,9 +154,9 @@ std::string LLServiceBuilder::buildServiceURI( std::string::iterator end(service_url.end()); std::string::iterator deepest_node(service_url.end()); std::string::iterator deepest_node_end(service_url.end()); - //parse out the variables to replace by going through {}s one at a time, - // starting with the "deepest" in series {{}}, - // and otherwise replacing right-to-left + // parse out the variables to replace by going through {}s + // one at a time, starting with the "deepest" in series + // {{}}, and otherwise replacing right-to-left for(; iter != end; ++iter) { switch(*iter) @@ -171,7 +191,7 @@ std::string LLServiceBuilder::buildServiceURI( // params and straight string substitution, so it's a // known distance of 2 to skip the directive. std::string key(deepest_node + 2, deepest_node_end); - LLSD value = option_map[key]; + LLSD value = context[key]; switch(*(deepest_node + 1)) { case '$': @@ -184,7 +204,9 @@ std::string LLServiceBuilder::buildServiceURI( } else { - llwarns << "Unknown key: " << key << " in option map: " << LLSDOStreamer<LLSDNotationFormatter>(option_map) << llendl; + llwarns << "Unknown key: " << key << " in option map: " + << LLSDOStreamer<LLSDNotationFormatter>(context) + << llendl; keep_looping = false; } break; @@ -212,50 +234,3 @@ std::string LLServiceBuilder::buildServiceURI( } return service_url; } - - - -// Old, not as good implementation. Phoenix 2007-10-15 -#if 0 - // Do brace replacements - NOT CURRENTLY RECURSIVE - for(LLSD::map_const_iterator option_itr = option_map.beginMap(); - option_itr != option_map.endMap(); - ++option_itr) - { - std::string variable_name = "{$"; - variable_name.append((*option_itr).first); - variable_name.append("}"); - std::string::size_type find_pos = service_url.find(variable_name); - if(find_pos != std::string::npos) - { - service_url.replace( - find_pos, - variable_name.length(), - (*option_itr).second.asString()); - continue; - } - variable_name.assign("{%"); - variable_name.append((*option_itr).first); - variable_name.append("}"); - find_pos = service_url.find(variable_name); - if(find_pos != std::string::npos) - { - std::string query_str = LLURI::mapToQueryString( - (*option_itr).second); - service_url.replace( - find_pos, - variable_name.length(), - query_str); - } - } - } - - if (service_url.find('{') != std::string::npos) - { - llwarns << "Constructed a likely bogus service URL: " << service_url - << llendl; - } - - return service_url; -} -#endif |