summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Goetze <cg@lindenlab.com>2008-11-18 21:20:05 +0000
committerChristian Goetze <cg@lindenlab.com>2008-11-18 21:20:05 +0000
commita86aa7d8b08f326e9422e321467dfed7ffe97a4c (patch)
tree276f78d91a21356a39becf91e319879b5d6f219b
parentba9cf4aa151950039d4e098b5637a35a204b7f6b (diff)
QAR-963 svn merge -r101685:101752 svn+ssh://svn.lindenlab.com/svn/linden/branches/rad-chilies/rc05-release-merge
-rw-r--r--indra/lib/python/indra/base/config.py29
-rw-r--r--indra/lib/python/indra/base/llsd.py1
-rw-r--r--indra/lib/python/indra/ipc/servicebuilder.py29
-rw-r--r--indra/llmessage/llhttpclient.cpp64
-rw-r--r--indra/llmessage/llhttpclient.h50
5 files changed, 137 insertions, 36 deletions
diff --git a/indra/lib/python/indra/base/config.py b/indra/lib/python/indra/base/config.py
index 1649933d37..f0119d1295 100644
--- a/indra/lib/python/indra/base/config.py
+++ b/indra/lib/python/indra/base/config.py
@@ -27,6 +27,7 @@ $/LicenseInfo$
"""
import copy
+import errno
import os
import traceback
import time
@@ -62,6 +63,8 @@ class IndraConfig(object):
self._load()
def _load(self):
+ # if you initialize the IndraConfig with None, no attempt
+ # is made to load any files
if self._indra_config_file is None:
return
@@ -164,22 +167,36 @@ class IndraConfig(object):
"""
return copy.deepcopy(self._combined_dict)
-def load(indra_xml_file = None):
+def load(config_xml_file = None):
global _g_config
- if indra_xml_file is None:
+ load_default_files = config_xml_file is None
+ if load_default_files:
## going from:
## "/opt/linden/indra/lib/python/indra/base/config.py"
## to:
## "/opt/linden/etc/indra.xml"
- indra_xml_file = realpath(
+ config_xml_file = realpath(
dirname(realpath(__file__)) + "../../../../../../etc/indra.xml")
try:
- _g_config = IndraConfig(indra_xml_file)
+ _g_config = IndraConfig(config_xml_file)
except IOError:
- # indra.xml was not openable, so let's initialize with an empty dict
- # some code relies on config behaving this way
+ # Failure to load passed in file
+ # or indra.xml default file
+ if load_default_files:
+ try:
+ config_xml_file = realpath(
+ dirname(realpath(__file__)) + "../../../../../../etc/globals.xml")
+ _g_config = IndraConfig(config_xml_file)
+ return
+ except IOError:
+ # Failure to load globals.xml
+ # fall to code below
+ pass
+
+ # Either failed to load passed in file
+ # or failed to load all default files
_g_config = IndraConfig(None)
def dump(indra_xml_file, indra_cfg = None, update_in_mem=False):
diff --git a/indra/lib/python/indra/base/llsd.py b/indra/lib/python/indra/base/llsd.py
index 5b8f5d7613..057d4e31dc 100644
--- a/indra/lib/python/indra/base/llsd.py
+++ b/indra/lib/python/indra/base/llsd.py
@@ -126,6 +126,7 @@ def date_to_python(node):
if not val:
val = "1970-01-01T00:00:00Z"
return parse_datestr(val)
+
def uri_to_python(node):
val = node.text or ''
diff --git a/indra/lib/python/indra/ipc/servicebuilder.py b/indra/lib/python/indra/ipc/servicebuilder.py
index ebd2583385..13a36a392d 100644
--- a/indra/lib/python/indra/ipc/servicebuilder.py
+++ b/indra/lib/python/indra/ipc/servicebuilder.py
@@ -51,12 +51,10 @@ def build(name, context={}, **kwargs):
> servicebuilder.build('version-manager-version', context, version='1.18.1.2')
'http://int.util.vaak.lindenlab.com/channel/Second%20Life%20Release/1.18.1.2'
"""
- context = context.copy() # shouldn't modify the caller's dictionary
- context.update(kwargs)
global _g_builder
if _g_builder is None:
_g_builder = ServiceBuilder()
- return _g_builder.buildServiceURL(name, context)
+ return _g_builder.buildServiceURL(name, context, **kwargs)
class ServiceBuilder(object):
def __init__(self, services_definition = services_config):
@@ -81,13 +79,36 @@ class ServiceBuilder(object):
else:
self.builders[service['name']] = service_builder
- def buildServiceURL(self, name, context):
+ def buildServiceURL(self, name, context={}, **kwargs):
"""\
@brief given the environment on construction, return a service URL.
@param name The name of the service.
@param context A dict of name value lookups for the service.
+ @param kwargs Any keyword arguments are treated as members of the
+ context, this allows you to be all 31337 by writing shit like:
+ servicebuilder.build('name', param=value)
@returns Returns the
"""
+ context = context.copy() # shouldn't modify the caller's dictionary
+ context.update(kwargs)
base_url = config.get('services-base-url')
svc_path = russ.format(self.builders[name], context)
return base_url + svc_path
+
+
+def on_in(query_name, host_key, schema_key):
+ """\
+ @brief Constructs an on/in snippet (for running named queries)
+ from a schema name and two keys referencing values stored in
+ indra.xml.
+
+ @param query_name Name of the query.
+ @param host_key Logical name of destination host. Will be
+ looked up in indra.xml.
+ @param schema_key Logical name of destination schema. Will
+ be looked up in indra.xml.
+ """
+ host_name = config.get(host_key)
+ schema_name = config.get(schema_key)
+ return '/'.join( ('on', host_name, 'in', schema_name, query_name.lstrip('/')) )
+
diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp
index 618d99dc48..9c716cf42b 100644
--- a/indra/llmessage/llhttpclient.cpp
+++ b/indra/llmessage/llhttpclient.cpp
@@ -1,4 +1,4 @@
- /**
+/**
* @file llhttpclient.cpp
* @brief Implementation of classes for making HTTP requests.
*
@@ -310,9 +310,13 @@ void LLHTTPClient::getByteRange(
request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers);
}
-void LLHTTPClient::head(const std::string& url, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::head(
+ const std::string& url,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout);
+ request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers);
}
void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout)
@@ -423,39 +427,66 @@ LLSD LLHTTPClient::blockingGet(const std::string& url)
return response;
}
-void LLHTTPClient::put(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::put(
+ const std::string& url,
+ const LLSD& body,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, timeout);
+ request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, timeout, headers);
}
-void LLHTTPClient::post(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::post(
+ const std::string& url,
+ const LLSD& body,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout);
+ request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout, headers);
}
-void LLHTTPClient::postRaw(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::postRaw(
+ const std::string& url,
+ const U8* data,
+ S32 size,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout);
+ request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout, headers);
}
-void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::postFile(
+ const std::string& url,
+ const std::string& filename,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout);
+ request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout, headers);
}
-void LLHTTPClient::postFile(const std::string& url, const LLUUID& uuid,
- LLAssetType::EType asset_type, ResponderPtr responder, const F32 timeout)
+void LLHTTPClient::postFile(
+ const std::string& url,
+ const LLUUID& uuid,
+ LLAssetType::EType asset_type,
+ ResponderPtr responder,
+ const LLSD& headers,
+ const F32 timeout)
{
- request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout);
+ request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout, headers);
}
// static
void LLHTTPClient::del(
const std::string& url,
ResponderPtr responder,
+ const LLSD& headers,
const F32 timeout)
{
- request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout);
+ request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout, headers);
}
// static
@@ -463,9 +494,10 @@ void LLHTTPClient::move(
const std::string& url,
const std::string& destination,
ResponderPtr responder,
+ const LLSD& hdrs,
const F32 timeout)
{
- LLSD headers;
+ LLSD headers = hdrs;
headers["Destination"] = destination;
request(url, LLURLRequest::HTTP_MOVE, NULL, responder, timeout, headers);
}
diff --git a/indra/llmessage/llhttpclient.h b/indra/llmessage/llhttpclient.h
index af79662be9..6267eb465f 100644
--- a/indra/llmessage/llhttpclient.h
+++ b/indra/llmessage/llhttpclient.h
@@ -62,28 +62,56 @@ public:
/** @name non-blocking API */
//@{
- static void head(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
+ static void head(
+ const std::string& url,
+ ResponderPtr,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void getByteRange(const std::string& url, S32 offset, S32 bytes, ResponderPtr, const LLSD& headers=LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void get(const std::string& url, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void get(const std::string& url, const LLSD& query, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
- static void put(const std::string& url, const LLSD& body, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
+ static void put(
+ const std::string& url,
+ const LLSD& body,
+ ResponderPtr,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void getHeaderOnly(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void getHeaderOnly(const std::string& url, ResponderPtr, const LLSD& headers, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
- static void post(const std::string& url, const LLSD& body, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
-
+ static void post(
+ const std::string& url,
+ const LLSD& body,
+ ResponderPtr,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
/** Takes ownership of data and deletes it when sent */
- static void postRaw(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
-
- static void postFile(const std::string& url, const std::string& filename, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
- #
- static void postFile(const std::string& url, const LLUUID& uuid,
- LLAssetType::EType asset_type, ResponderPtr responder, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
+ static void postRaw(
+ const std::string& url,
+ const U8* data,
+ S32 size,
+ ResponderPtr responder,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
+ static void postFile(
+ const std::string& url,
+ const std::string& filename,
+ ResponderPtr,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
+ static void postFile(
+ const std::string& url,
+ const LLUUID& uuid,
+ LLAssetType::EType asset_type,
+ ResponderPtr responder,
+ const LLSD& headers = LLSD(),
+ const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
static void del(
const std::string& url,
ResponderPtr responder,
+ const LLSD& headers = LLSD(),
const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
///< sends a DELETE method, but we can't call it delete in c++
@@ -93,12 +121,14 @@ public:
* @param url The complete serialized (and escaped) url to get.
* @param destination The complete serialized destination url.
* @param responder The responder that will handle the result.
+ * @param headers A map of key:value headers to pass to the request
* @param timeout The number of seconds to give the server to respond.
*/
static void move(
const std::string& url,
const std::string& destination,
ResponderPtr responder,
+ const LLSD& headers = LLSD(),
const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
//@}