aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llcachename.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmessage/llcachename.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llmessage/llcachename.cpp')
-rw-r--r--linden/indra/llmessage/llcachename.cpp194
1 files changed, 134 insertions, 60 deletions
diff --git a/linden/indra/llmessage/llcachename.cpp b/linden/indra/llmessage/llcachename.cpp
index fb6ca5b..6075958 100644
--- a/linden/indra/llmessage/llcachename.cpp
+++ b/linden/indra/llmessage/llcachename.cpp
@@ -34,19 +34,26 @@
34#include "llcachename.h" 34#include "llcachename.h"
35 35
36// linden library includes 36// linden library includes
37#include "message.h"
38#include "llrand.h"
39#include "lldbstrings.h" 37#include "lldbstrings.h"
40#include "llframetimer.h" 38#include "llframetimer.h"
41#include "llhost.h" 39#include "llhost.h"
40#include "llrand.h"
41#include "llsdserialize.h"
42#include "lluuid.h" 42#include "lluuid.h"
43#include "message.h"
43 44
44// Constants 45// Constants
45const char* CN_WAITING = "(waiting)"; 46const char* CN_WAITING = "(waiting)";
46const char* CN_NOBODY = "(nobody)"; 47const char* CN_NOBODY = "(nobody)";
47const char* CN_NONE = "(none)"; 48const char* CN_NONE = "(none)";
48const char* CN_HIPPOS = "(hippos)"; 49
49const F32 HIPPO_PROBABILITY = 0.01f; 50// llsd serialization constants
51static const std::string AGENTS("agents");
52static const std::string GROUPS("groups");
53static const std::string CTIME("ctime");
54static const std::string FIRST("first");
55static const std::string LAST("last");
56static const std::string NAME("name");
50 57
51// We track name requests in flight for up to this long. 58// We track name requests in flight for up to this long.
52// We won't re-request a name during this time 59// We won't re-request a name during this time
@@ -392,73 +399,123 @@ void LLCacheName::importFile(FILE* fp)
392 llinfos << "LLCacheName loaded " << count << " names" << llendl; 399 llinfos << "LLCacheName loaded " << count << " names" << llendl;
393} 400}
394 401
395 402bool LLCacheName::importFile(std::istream& istr)
396void LLCacheName::exportFile(FILE* fp)
397{ 403{
398 fprintf(fp, "version\t%d\n", CN_FILE_VERSION); 404 LLSD data;
405 if(LLSDSerialize::fromXML(data, istr) < 1)
406 return false;
399 407
400 for (Cache::iterator iter = impl.mCache.begin(), 408 // We'll expire entries more than a week old
401 end = impl.mCache.end(); 409 U32 now = (U32)time(NULL);
402 iter != end; iter++) 410 const U32 SECS_PER_DAY = 60 * 60 * 24;
411 U32 delete_before_time = now - (7 * SECS_PER_DAY);
412
413 // iterate over the agents
414 S32 count = 0;
415 LLSD agents = data[AGENTS];
416 LLSD::map_iterator iter = agents.beginMap();
417 LLSD::map_iterator end = agents.endMap();
418 for( ; iter != end; ++iter)
403 { 419 {
404 LLCacheNameEntry* entry = iter->second; 420 LLUUID id((*iter).first);
405 // Only write entries for which we have valid data. 421 LLSD agent = (*iter).second;
406 // HACK: Only write agent names. This makes the reader easier. 422 U32 ctime = (U32)agent[CTIME].asInteger();
407 if ( entry->mFirstName[0] 423 if(ctime < delete_before_time) continue;
408 && entry->mLastName[0])
409 {
410 LLUUID id = iter->first;
411 424
412 // Trivial XOR encoding 425 LLCacheNameEntry* entry = new LLCacheNameEntry();
413 S32 i; 426 entry->mIsGroup = false;
414 for (i = 0; i < UUID_BYTES; i++) 427 entry->mCreateTime = ctime;
415 { 428 std::string first = agent[FIRST].asString();
416 id.mData[i] ^= 0x33; 429 first.copy(entry->mFirstName, DB_FIRST_NAME_BUF_SIZE, 0);
417 } 430 entry->mFirstName[llmin(first.size(),(std::string::size_type)DB_FIRST_NAME_BUF_SIZE-1)] = '\0';
431 std::string last = agent[LAST].asString();
432 last.copy(entry->mLastName, DB_LAST_NAME_BUF_SIZE, 0);
433 entry->mLastName[llmin(last.size(),(std::string::size_type)DB_LAST_NAME_BUF_SIZE-1)] = '\0';
434 impl.mCache[id] = entry;
435 ++count;
436 }
437 llinfos << "LLCacheName loaded " << count << " agent names" << llendl;
418 438
419 char id_string[UUID_STR_SIZE]; /*Flawfinder:ignore*/ 439 count = 0;
420 id.toString(id_string); 440 LLSD groups = data[GROUPS];
441 iter = groups.beginMap();
442 end = groups.endMap();
443 for( ; iter != end; ++iter)
444 {
445 LLUUID id((*iter).first);
446 LLSD group = (*iter).second;
447 U32 ctime = (U32)group[CTIME].asInteger();
448 if(ctime < delete_before_time) continue;
421 449
422 // ...not a group name 450 LLCacheNameEntry* entry = new LLCacheNameEntry();
423 fprintf(fp, "%s\t%u\t%s\t%s\n", 451 entry->mIsGroup = true;
424 id_string, 452 entry->mCreateTime = ctime;
425 entry->mCreateTime, 453 std::string name = group[NAME].asString();
426 entry->mFirstName, 454 name.copy(entry->mGroupName, DB_GROUP_NAME_BUF_SIZE, 0);
427 entry->mLastName); 455 entry->mGroupName[llmin(name.size(), (std::string::size_type)DB_GROUP_NAME_BUF_SIZE-1)] = '\0';
456 impl.mCache[id] = entry;
457 ++count;
458 }
459 llinfos << "LLCacheName loaded " << count << " group names" << llendl;
460 return true;
461}
462
463void LLCacheName::exportFile(std::ostream& ostr)
464{
465 LLSD data;
466 Cache::iterator iter = impl.mCache.begin();
467 Cache::iterator end = impl.mCache.end();
468 for( ; iter != end; ++iter)
469 {
470 // Only write entries for which we have valid data.
471 LLCacheNameEntry* entry = iter->second;
472 if(!entry
473 || (NULL != strchr(entry->mFirstName, '?'))
474 || (NULL != strchr(entry->mGroupName, '?')))
475 {
476 continue;
477 }
478
479 // store it
480 LLUUID id = iter->first;
481 std::string id_str = id.asString();
482 if(entry->mFirstName[0] && entry->mLastName[0])
483 {
484 data[AGENTS][id_str][FIRST] = entry->mFirstName;
485 data[AGENTS][id_str][LAST] = entry->mLastName;
486 data[AGENTS][id_str][CTIME] = (S32)entry->mCreateTime;
487 }
488 else if(entry->mIsGroup && entry->mGroupName[0])
489 {
490 data[GROUPS][id_str][NAME] = entry->mGroupName;
491 data[GROUPS][id_str][CTIME] = (S32)entry->mCreateTime;
428 } 492 }
429 } 493 }
494
495 LLSDSerialize::toPrettyXML(data, ostr);
430} 496}
431 497
432 498
433BOOL LLCacheName::getName(const LLUUID& id, char* first, char* last) 499BOOL LLCacheName::getName(const LLUUID& id, std::string& first, std::string& last)
434{ 500{
435 if(id.isNull()) 501 if(id.isNull())
436 { 502 {
437 // The function signature needs to change to pass in the 503 first = CN_NOBODY;
438 // length of first and last. 504 last.clear();
439 strcpy(first, CN_NOBODY); /*Flawfinder: ignore*/
440 last[0] = '\0';
441 return FALSE; 505 return FALSE;
442 } 506 }
443 507
444 LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache, id ); 508 LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache, id );
445 if (entry) 509 if (entry)
446 { 510 {
447 // The function signature needs to change to pass in the 511 first = entry->mFirstName;
448 // length of first and last. 512 last = entry->mLastName;
449 strcpy(first, entry->mFirstName); /*Flawfinder: ignore*/
450 strcpy(last, entry->mLastName); /*Flawfinder: ignore*/
451 return TRUE; 513 return TRUE;
452 } 514 }
453 else 515 else
454 { 516 {
455 //The function signature needs to change to pass in the 517 first = CN_WAITING;
456 //length of first and last. 518 last.clear();
457 strcpy(first,(ll_frand() < HIPPO_PROBABILITY)
458 ? CN_HIPPOS
459 : CN_WAITING);
460 strcpy(last, ""); /*Flawfinder: ignore*/
461
462 if (!impl.isRequestPending(id)) 519 if (!impl.isRequestPending(id))
463 { 520 {
464 impl.mAskNameQueue.insert(id); 521 impl.mAskNameQueue.insert(id);
@@ -468,15 +525,29 @@ BOOL LLCacheName::getName(const LLUUID& id, char* first, char* last)
468 525
469} 526}
470 527
528BOOL LLCacheName::getFullName(const LLUUID& id, std::string& fullname)
529{
530 std::string first_name, last_name;
531 BOOL res = getName(id, first_name, last_name);
532 fullname = first_name + " " + last_name;
533 return res;
534}
471 535
536// *TODO: Deprecate
537BOOL LLCacheName::getName(const LLUUID& id, char* first, char* last)
538{
539 std::string first_name, last_name;
540 BOOL res = getName(id, first_name, last_name);
541 strcpy(first, first_name.c_str());
542 strcpy(last, last_name.c_str());
543 return res;
544}
472 545
473BOOL LLCacheName::getGroupName(const LLUUID& id, char* group) 546BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group)
474{ 547{
475 if(id.isNull()) 548 if(id.isNull())
476 { 549 {
477 // The function signature needs to change to pass in the 550 group = CN_NONE;
478 // length of first and last.
479 strcpy(group, CN_NONE); /*Flawfinder: ignore*/
480 return FALSE; 551 return FALSE;
481 } 552 }
482 553
@@ -492,16 +563,12 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, char* group)
492 563
493 if (entry) 564 if (entry)
494 { 565 {
495 // The function signature needs to change to pass in the length 566 group = entry->mGroupName;
496 // of group.
497 strcpy(group, entry->mGroupName); /*Flawfinder: ignore*/
498 return TRUE; 567 return TRUE;
499 } 568 }
500 else 569 else
501 { 570 {
502 // The function signature needs to change to pass in the length 571 group = CN_WAITING;
503 // of first and last.
504 strcpy(group, CN_WAITING); /*Flawfinder: ignore*/
505 if (!impl.isRequestPending(id)) 572 if (!impl.isRequestPending(id))
506 { 573 {
507 impl.mAskGroupQueue.insert(id); 574 impl.mAskGroupQueue.insert(id);
@@ -510,6 +577,16 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, char* group)
510 } 577 }
511} 578}
512 579
580// *TODO: Deprecate
581BOOL LLCacheName::getGroupName(const LLUUID& id, char* group)
582{
583 std::string group_name;
584 BOOL res = getGroupName(id, group_name);
585 strcpy(group, group_name.c_str());
586 return res;
587}
588
589
513// TODO: Make the cache name callback take a SINGLE std::string, 590// TODO: Make the cache name callback take a SINGLE std::string,
514// not a separate first and last name. 591// not a separate first and last name.
515void LLCacheName::get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callback, void* user_data) 592void LLCacheName::get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callback, void* user_data)
@@ -884,6 +961,3 @@ void LLCacheName::Impl::handleUUIDGroupNameReply(LLMessageSystem* msg, void** us
884 ((LLCacheName::Impl*)userData)->processUUIDReply(msg, true); 961 ((LLCacheName::Impl*)userData)->processUUIDReply(msg, true);
885} 962}
886 963
887
888
889