summaryrefslogtreecommitdiff
path: root/indra/llmessage/llcachename.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/llcachename.cpp')
-rw-r--r--indra/llmessage/llcachename.cpp98
1 files changed, 63 insertions, 35 deletions
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index b42c5237f7..379f390625 100644
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -2,31 +2,25 @@
* @file llcachename.cpp
* @brief A hierarchical cache of first and last names queried based on UUID.
*
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2002&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://secondlifegrid.net/programs/open_source/licensing/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://secondlifegrid.net/programs/open_source/licensing/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$
*/
@@ -81,6 +75,8 @@ public:
};
LLCacheNameEntry::LLCacheNameEntry()
+ : mIsGroup(false),
+ mCreateTime(0)
{
}
@@ -97,7 +93,7 @@ public:
{
}
- boost::signals::connection setCallback(const LLCacheNameCallback& cb)
+ boost::signals2::connection setCallback(const LLCacheNameCallback& cb)
{
return mSignal.connect(cb);
}
@@ -125,7 +121,7 @@ private:
};
ReplySender::ReplySender(LLMessageSystem* msg)
- : mMsg(msg), mPending(false)
+ : mMsg(msg), mPending(false), mCurrIsGroup(false)
{ }
ReplySender::~ReplySender()
@@ -189,6 +185,7 @@ typedef std::set<LLUUID> AskQueue;
typedef std::list<PendingReply*> ReplyQueue;
typedef std::map<LLUUID,U32> PendingQueue;
typedef std::map<LLUUID, LLCacheNameEntry*> Cache;
+typedef std::map<std::string, LLUUID> ReverseCache;
class LLCacheName::Impl
{
@@ -198,7 +195,9 @@ public:
Cache mCache;
// the map of UUIDs to names
-
+ ReverseCache mReverseCache;
+ // map of names to UUIDs
+
AskQueue mAskNameQueue;
AskQueue mAskGroupQueue;
// UUIDs to ask our upstream host about
@@ -216,7 +215,7 @@ public:
Impl(LLMessageSystem* msg);
~Impl();
- boost::signals::connection addPending(const LLUUID& id, const LLCacheNameCallback& callback);
+ boost::signals2::connection addPending(const LLUUID& id, const LLCacheNameCallback& callback);
void addPending(const LLUUID& id, const LLHost& host);
void processPendingAsks();
@@ -277,10 +276,10 @@ LLCacheName::Impl::~Impl()
for_each(mReplyQueue.begin(), mReplyQueue.end(), DeletePointer());
}
-boost::signals::connection LLCacheName::Impl::addPending(const LLUUID& id, const LLCacheNameCallback& callback)
+boost::signals2::connection LLCacheName::Impl::addPending(const LLUUID& id, const LLCacheNameCallback& callback)
{
PendingReply* reply = new PendingReply(id, LLHost());
- boost::signals::connection res = reply->setCallback(callback);
+ boost::signals2::connection res = reply->setCallback(callback);
mReplyQueue.push_back(reply);
return res;
}
@@ -296,7 +295,7 @@ void LLCacheName::setUpstream(const LLHost& upstream_host)
impl.mUpstreamHost = upstream_host;
}
-boost::signals::connection LLCacheName::addObserver(const LLCacheNameCallback& callback)
+boost::signals2::connection LLCacheName::addObserver(const LLCacheNameCallback& callback)
{
return impl.mSignal.connect(callback);
}
@@ -371,7 +370,9 @@ void LLCacheName::importFile(LLFILE* fp)
entry->mFirstName = firstname;
entry->mLastName = lastname;
impl.mCache[id] = entry;
-
+ std::string fullname = entry->mFirstName + " " + entry->mLastName;
+ impl.mReverseCache[fullname] = id;
+
count++;
}
@@ -407,6 +408,8 @@ bool LLCacheName::importFile(std::istream& istr)
entry->mFirstName = agent[FIRST].asString();
entry->mLastName = agent[LAST].asString();
impl.mCache[id] = entry;
+ std::string fullname = entry->mFirstName + " " + entry->mLastName;
+ impl.mReverseCache[fullname] = id;
++count;
}
@@ -428,6 +431,7 @@ bool LLCacheName::importFile(std::istream& istr)
entry->mCreateTime = ctime;
entry->mGroupName = group[NAME].asString();
impl.mCache[id] = entry;
+ impl.mReverseCache[entry->mGroupName] = id;
++count;
}
llinfos << "LLCacheName loaded " << count << " group names" << llendl;
@@ -476,7 +480,7 @@ BOOL LLCacheName::getName(const LLUUID& id, std::string& first, std::string& las
{
first = sCacheName["nobody"];
last.clear();
- return FALSE;
+ return TRUE;
}
LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache, id );
@@ -520,7 +524,7 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group)
if(id.isNull())
{
group = sCacheName["none"];
- return FALSE;
+ return TRUE;
}
LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache,id);
@@ -548,16 +552,37 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group)
return FALSE;
}
}
+
+BOOL LLCacheName::getUUID(const std::string& first, const std::string& last, LLUUID& id)
+{
+ std::string fullname = first + " " + last;
+ return getUUID(fullname, id);
+}
+
+BOOL LLCacheName::getUUID(const std::string& fullname, LLUUID& id)
+{
+ ReverseCache::iterator iter = impl.mReverseCache.find(fullname);
+ if (iter != impl.mReverseCache.end())
+ {
+ id = iter->second;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
// This is a little bit kludgy. LLCacheNameCallback is a slot instead of a function pointer.
// The reason it is a slot is so that the legacy get() function below can bind an old callback
// and pass it as a slot. The reason it isn't a boost::function is so that trackable behavior
-// deson't get lost. As a result, we have to bind the slot to a signal to call it, even when
+// doesn't get lost. As a result, we have to bind the slot to a signal to call it, even when
// we call it immediately. -Steve
// NOTE: Even though passing first and last name is a bit of extra overhead, it eliminates the
// potential need for any parsing should any code need to handle first and last name independently.
-boost::signals::connection LLCacheName::get(const LLUUID& id, BOOL is_group, const LLCacheNameCallback& callback)
+boost::signals2::connection LLCacheName::get(const LLUUID& id, BOOL is_group, const LLCacheNameCallback& callback)
{
- boost::signals::connection res;
+ boost::signals2::connection res;
if(id.isNull())
{
@@ -601,7 +626,7 @@ boost::signals::connection LLCacheName::get(const LLUUID& id, BOOL is_group, con
return res;
}
-boost::signals::connection LLCacheName::get(const LLUUID& id, BOOL is_group, old_callback_t callback, void* user_data)
+boost::signals2::connection LLCacheName::get(const LLUUID& id, BOOL is_group, old_callback_t callback, void* user_data)
{
return get(id, is_group, boost::bind(callback, _1, _2, _3, _4, user_data));
}
@@ -897,10 +922,13 @@ void LLCacheName::Impl::processUUIDReply(LLMessageSystem* msg, bool isGroup)
if (!isGroup)
{
mSignal(id, entry->mFirstName, entry->mLastName, FALSE);
+ std::string fullname = entry->mFirstName + " " + entry->mLastName;
+ mReverseCache[fullname] = id;
}
else
{
mSignal(id, entry->mGroupName, "", TRUE);
+ mReverseCache[entry->mGroupName] = id;
}
}
}