summaryrefslogtreecommitdiff
path: root/indra/llmessage/llcachename.cpp
diff options
context:
space:
mode:
authorJosh Bell <josh@lindenlab.com>2008-02-13 01:02:09 +0000
committerJosh Bell <josh@lindenlab.com>2008-02-13 01:02:09 +0000
commit54e428d2094267d993fd51dc1d879106083d3db5 (patch)
treee9586f1c2fffbdaba897fa43f6d5ead18ae6f0df /indra/llmessage/llcachename.cpp
parenteb55ba3c7f51fa47336bead33077c298cec33b65 (diff)
svn merge -r 79828:79862 svn+ssh://svn.lindenlab.com/svn/linden/qa/combo-merge-2008-02-12 --> release
QAR-280 - combo merge of: * QAR-249 Allow specifying max http protocol version in eventlet.httpd, and change backbone.py to specify HTTP/1.0 explicitly * QAR-272 Switch logout/disconnect messages to syslog/streambase * QAR-253 Test for the group names fix * QAR-260 metrics-3 for release merge
Diffstat (limited to 'indra/llmessage/llcachename.cpp')
-rw-r--r--indra/llmessage/llcachename.cpp129
1 files changed, 97 insertions, 32 deletions
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index f731c95a14..3472c3eb5d 100644
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -34,12 +34,13 @@
#include "llcachename.h"
// linden library includes
-#include "message.h"
-#include "llrand.h"
#include "lldbstrings.h"
#include "llframetimer.h"
#include "llhost.h"
+#include "llrand.h"
+#include "llsdserialize.h"
#include "lluuid.h"
+#include "message.h"
// Constants
const char* CN_WAITING = "(waiting)";
@@ -48,6 +49,14 @@ const char* CN_NONE = "(none)";
const char* CN_HIPPOS = "(hippos)";
const F32 HIPPO_PROBABILITY = 0.01f;
+// llsd serialization constants
+static const std::string AGENTS("agents");
+static const std::string GROUPS("groups");
+static const std::string CTIME("ctime");
+static const std::string FIRST("first");
+static const std::string LAST("last");
+static const std::string NAME("name");
+
// We track name requests in flight for up to this long.
// We won't re-request a name during this time
const U32 PENDING_TIMEOUT_SECS = 5 * 60;
@@ -392,41 +401,100 @@ void LLCacheName::importFile(FILE* fp)
llinfos << "LLCacheName loaded " << count << " names" << llendl;
}
-
-void LLCacheName::exportFile(FILE* fp)
+bool LLCacheName::importFile(std::istream& istr)
{
- fprintf(fp, "version\t%d\n", CN_FILE_VERSION);
+ LLSD data;
+ if(LLSDSerialize::fromXML(data, istr) < 1)
+ return false;
- for (Cache::iterator iter = impl.mCache.begin(),
- end = impl.mCache.end();
- iter != end; iter++)
+ // We'll expire entries more than a week old
+ U32 now = (U32)time(NULL);
+ const U32 SECS_PER_DAY = 60 * 60 * 24;
+ U32 delete_before_time = now - (7 * SECS_PER_DAY);
+
+ // iterate over the agents
+ S32 count = 0;
+ LLSD agents = data[AGENTS];
+ LLSD::map_iterator iter = agents.beginMap();
+ LLSD::map_iterator end = agents.endMap();
+ for( ; iter != end; ++iter)
{
- LLCacheNameEntry* entry = iter->second;
- // Only write entries for which we have valid data.
- // HACK: Only write agent names. This makes the reader easier.
- if ( entry->mFirstName[0]
- && entry->mLastName[0])
- {
- LLUUID id = iter->first;
+ LLUUID id((*iter).first);
+ LLSD agent = (*iter).second;
+ U32 ctime = (U32)agent[CTIME].asInteger();
+ if(ctime < delete_before_time) continue;
- // Trivial XOR encoding
- S32 i;
- for (i = 0; i < UUID_BYTES; i++)
- {
- id.mData[i] ^= 0x33;
- }
+ LLCacheNameEntry* entry = new LLCacheNameEntry();
+ entry->mIsGroup = false;
+ entry->mCreateTime = ctime;
+ std::string first = agent[FIRST].asString();
+ first.copy(entry->mFirstName, DB_FIRST_NAME_BUF_SIZE, 0);
+ entry->mFirstName[llmin(first.size(),(std::string::size_type)DB_FIRST_NAME_BUF_SIZE-1)] = '\0';
+ std::string last = agent[LAST].asString();
+ last.copy(entry->mLastName, DB_LAST_NAME_BUF_SIZE, 0);
+ entry->mLastName[llmin(last.size(),(std::string::size_type)DB_LAST_NAME_BUF_SIZE-1)] = '\0';
+ impl.mCache[id] = entry;
+ ++count;
+ }
+ llinfos << "LLCacheName loaded " << count << " agent names" << llendl;
+
+ count = 0;
+ LLSD groups = data[GROUPS];
+ iter = groups.beginMap();
+ end = groups.endMap();
+ for( ; iter != end; ++iter)
+ {
+ LLUUID id((*iter).first);
+ LLSD group = (*iter).second;
+ U32 ctime = (U32)group[CTIME].asInteger();
+ if(ctime < delete_before_time) continue;
- char id_string[UUID_STR_SIZE]; /*Flawfinder:ignore*/
- id.toString(id_string);
+ LLCacheNameEntry* entry = new LLCacheNameEntry();
+ entry->mIsGroup = true;
+ entry->mCreateTime = ctime;
+ std::string name = group[NAME].asString();
+ name.copy(entry->mGroupName, DB_GROUP_NAME_BUF_SIZE, 0);
+ entry->mGroupName[llmin(name.size(), (std::string::size_type)DB_GROUP_NAME_BUF_SIZE-1)] = '\0';
+ impl.mCache[id] = entry;
+ ++count;
+ }
+ llinfos << "LLCacheName loaded " << count << " group names" << llendl;
+ return true;
+}
- // ...not a group name
- fprintf(fp, "%s\t%u\t%s\t%s\n",
- id_string,
- entry->mCreateTime,
- entry->mFirstName,
- entry->mLastName);
+void LLCacheName::exportFile(std::ostream& ostr)
+{
+ LLSD data;
+ Cache::iterator iter = impl.mCache.begin();
+ Cache::iterator end = impl.mCache.end();
+ for( ; iter != end; ++iter)
+ {
+ // Only write entries for which we have valid data.
+ LLCacheNameEntry* entry = iter->second;
+ if(!entry
+ || (NULL != strchr(entry->mFirstName, '?'))
+ || (NULL != strchr(entry->mGroupName, '?')))
+ {
+ continue;
+ }
+
+ // store it
+ LLUUID id = iter->first;
+ std::string id_str = id.asString();
+ if(entry->mFirstName[0] && entry->mLastName[0])
+ {
+ data[AGENTS][id_str][FIRST] = entry->mFirstName;
+ data[AGENTS][id_str][LAST] = entry->mLastName;
+ data[AGENTS][id_str][CTIME] = (S32)entry->mCreateTime;
+ }
+ else if(entry->mIsGroup && entry->mGroupName[0])
+ {
+ data[GROUPS][id_str][NAME] = entry->mGroupName;
+ data[GROUPS][id_str][CTIME] = (S32)entry->mCreateTime;
}
}
+
+ LLSDSerialize::toPrettyXML(data, ostr);
}
@@ -884,6 +952,3 @@ void LLCacheName::Impl::handleUUIDGroupNameReply(LLMessageSystem* msg, void** us
((LLCacheName::Impl*)userData)->processUUIDReply(msg, true);
}
-
-
-