WIP: viewer side of ER-864: Include message ids and args in login.cgi responses

* Look for message_id and message_args in XMLRPC response, look up localized string in strings.xml
* Support sub-maps in XMLRPC response conversion to LLSD
* Explicitly request extended error info during login (since including sub-maps breaks older viewers)
* Support LLSD-based substitutions in LLTrans::getString/findString
meow-7.2.2
Joshua Bell 2011-05-11 17:36:11 -07:00
parent a5118ccd67
commit e54e9b4eed
5 changed files with 76 additions and 23 deletions

View File

@ -30,6 +30,7 @@
#include "llfasttimer.h" // for call count statistics
#include "llxuiparser.h"
#include "llsd.h"
#include <map>
@ -154,13 +155,28 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::
}
else
{
LLSD args;
args["STRING_NAME"] = xml_desc;
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return "MissingString("+xml_desc+")";
}
}
//LLNotificationsUtil::add("MissingString", args); // *TODO: resurrect
//return xml_desc;
//static
std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
LLFastTimer timer(FTM_GET_TRANS);
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
std::string text = iter->second.mText;
LLStringUtil::format(text, msg_args);
return text;
}
else
{
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return "MissingString("+xml_desc+")";
}
}
@ -182,11 +198,27 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const
}
else
{
LLSD args;
args["STRING_NAME"] = xml_desc;
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
//LLNotificationsUtil::add("MissingString", args);
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return false;
}
}
//static
bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD& msg_args)
{
LLFastTimer timer(FTM_GET_TRANS);
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
std::string text = iter->second.mText;
LLStringUtil::format(text, msg_args);
result = text;
return true;
}
else
{
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return false;
}
}

View File

@ -32,6 +32,8 @@
#include "llstring.h"
#include "llxmlnode.h"
class LLSD;
/**
* @brief String template loaded from strings.xml
*/
@ -72,7 +74,9 @@ public:
* @returns Translated string
*/
static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
static std::string getString(const std::string &xml_desc, const LLSD& args);
static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args);
static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args);
// Returns translated string with [COUNT] replaced with a number, following
// special per-language logic for plural nouns. For example, some languages

View File

@ -608,6 +608,7 @@ void LLLoginInstance::constructAuthParams(LLPointer<LLCredential> user_credentia
request_params["channel"] = LLVersionInfo::getChannel();
request_params["id0"] = mSerialNumber;
request_params["host_id"] = gSavedSettings.getString("HostID");
request_params["extended_errors"] = true; // request message_id and message_args
mRequestData.clear();
mRequestData["method"] = "login_to_simulator";

View File

@ -995,6 +995,7 @@ bool idle_startup()
if(STATE_LOGIN_PROCESS_RESPONSE == LLStartUp::getStartupState())
{
// Generic failure message
std::ostringstream emsg;
emsg << LLTrans::getString("LoginFailed") << "\n";
if(LLLoginInstance::getInstance()->authFailure())
@ -1003,24 +1004,32 @@ bool idle_startup()
<< LLLoginInstance::getInstance()->getResponse() << LL_ENDL;
LLSD response = LLLoginInstance::getInstance()->getResponse();
// Still have error conditions that may need some
// sort of handling.
// sort of handling - dig up specific message
std::string reason_response = response["reason"];
std::string message_response = response["message"];
if(!message_response.empty())
std::string message_id = response["message_id"];
std::string message; // actual string to show the user
if(!message_id.empty() && LLTrans::findString(message, message_id, response["message_args"]))
{
// XUI: fix translation for strings returned during login
// We need a generic table for translations
std::string big_reason = LLAgent::sTeleportErrorMessages[ message_response ];
if ( big_reason.size() == 0 )
{
emsg << message_response;
}
else
{
emsg << big_reason;
}
// message will be populated with the templated string
}
else if(!message_response.empty())
{
// *HACK: "no_inventory_host" sent as the message itself.
// Remove this clause when server is sending message_id as well.
message = LLAgent::sTeleportErrorMessages[ message_response ];
}
if (message.empty())
{
// Fallback to server-supplied string; necessary since server
// may add strings that this viewer is not yet aware of
message = message_response;
}
emsg << message;
if(reason_response == "key")
{

View File

@ -499,6 +499,13 @@ private:
// 'array' as the value of this 'key'.
responses.insert(key, array);
}
else if (xmlrpc_type_struct == type)
{
LLSD submap = parseValues(status_string,
STRINGIZE(key_pfx << key << ':'),
current);
responses.insert(key, submap);
}
else
{
// whoops - unrecognized type