diff options
Diffstat (limited to 'linden/indra/llmessage/llcachename.cpp')
-rw-r--r-- | linden/indra/llmessage/llcachename.cpp | 221 |
1 files changed, 217 insertions, 4 deletions
diff --git a/linden/indra/llmessage/llcachename.cpp b/linden/indra/llmessage/llcachename.cpp index 70e1ccf..8f02358 100644 --- a/linden/indra/llmessage/llcachename.cpp +++ b/linden/indra/llmessage/llcachename.cpp | |||
@@ -41,7 +41,8 @@ | |||
41 | #include "llsdserialize.h" | 41 | #include "llsdserialize.h" |
42 | #include "lluuid.h" | 42 | #include "lluuid.h" |
43 | #include "message.h" | 43 | #include "message.h" |
44 | 44 | #include "llservicebuilder.h" | |
45 | #include "llframetimer.h" | ||
45 | // Constants | 46 | // Constants |
46 | static const std::string CN_WAITING("(Loading...)"); // *TODO: translate | 47 | static const std::string CN_WAITING("(Loading...)"); // *TODO: translate |
47 | static const std::string CN_NOBODY("(nobody)"); // *TODO: translate | 48 | static const std::string CN_NOBODY("(nobody)"); // *TODO: translate |
@@ -196,6 +197,8 @@ class LLCacheName::Impl | |||
196 | public: | 197 | public: |
197 | LLMessageSystem* mMsg; | 198 | LLMessageSystem* mMsg; |
198 | LLHost mUpstreamHost; | 199 | LLHost mUpstreamHost; |
200 | std::string mGroupNameURL; | ||
201 | std::string mAgentNameURL; | ||
199 | 202 | ||
200 | Cache mCache; | 203 | Cache mCache; |
201 | // the map of UUIDs to names | 204 | // the map of UUIDs to names |
@@ -221,6 +224,8 @@ public: | |||
221 | void processPendingReplies(); | 224 | void processPendingReplies(); |
222 | void sendRequest(const char* msg_name, const AskQueue& queue); | 225 | void sendRequest(const char* msg_name, const AskQueue& queue); |
223 | bool isRequestPending(const LLUUID& id); | 226 | bool isRequestPending(const LLUUID& id); |
227 | void getAgentName(const AskQueue&); | ||
228 | void getGroupName(const AskQueue&); | ||
224 | 229 | ||
225 | // Message system callbacks. | 230 | // Message system callbacks. |
226 | void processUUIDRequest(LLMessageSystem* msg, bool isGroup); | 231 | void processUUIDRequest(LLMessageSystem* msg, bool isGroup); |
@@ -234,6 +239,35 @@ public: | |||
234 | void notifyObservers(const LLUUID& id, const std::string& first, const std::string& last, BOOL group); | 239 | void notifyObservers(const LLUUID& id, const std::string& first, const std::string& last, BOOL group); |
235 | }; | 240 | }; |
236 | 241 | ||
242 | class LLHTTPAgentNamesResponse : public LLHTTPClient::Responder | ||
243 | { | ||
244 | public: | ||
245 | LLHTTPAgentNamesResponse(const LLSD& agent_ids) | ||
246 | : mAgentIDs(agent_ids) | ||
247 | { } | ||
248 | void result(const LLSD& content); | ||
249 | private: | ||
250 | LLHost mSender; | ||
251 | LLSD mAgentIDs; | ||
252 | |||
253 | }; | ||
254 | |||
255 | class LLHTTPGroupNamesResponse : public LLHTTPClient::Responder | ||
256 | { | ||
257 | public: | ||
258 | LLHTTPGroupNamesResponse(const LLSD& group_ids) | ||
259 | : mGroupIDs(group_ids) | ||
260 | { }; | ||
261 | |||
262 | void result(const LLSD& content); | ||
263 | private: | ||
264 | LLHost mSender; | ||
265 | LLSD mGroupIDs; | ||
266 | |||
267 | }; | ||
268 | |||
269 | |||
270 | |||
237 | 271 | ||
238 | /// -------------------------------------------------------------------------- | 272 | /// -------------------------------------------------------------------------- |
239 | /// class LLCacheName | 273 | /// class LLCacheName |
@@ -319,6 +353,57 @@ void LLCacheName::cancelCallback(const LLUUID& id, LLCacheNameCallback callback, | |||
319 | } | 353 | } |
320 | } | 354 | } |
321 | 355 | ||
356 | void LLCacheName::sendAgentNames(const LLUUID& id, std::string& first, std::string& last) | ||
357 | { | ||
358 | |||
359 | LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache, id); | ||
360 | if (!entry) | ||
361 | { | ||
362 | entry = new LLCacheNameEntry; | ||
363 | impl.mCache[id] = entry; | ||
364 | |||
365 | } | ||
366 | entry->mIsGroup = false; | ||
367 | entry->mCreateTime = (U32)LLFrameTimer::getTotalSeconds(); | ||
368 | //entry->mFirstName = first; | ||
369 | //entry->mLastName = last; | ||
370 | //LLStringUtil::truncate(entry->mFirstName, DB_FIRST_NAME_BUF_SIZE); | ||
371 | //LLStringUtil::truncate(entry->mLastName, DB_LAST_NAME_BUF_SIZE); | ||
372 | entry->mFirstName = std::string(first, DB_FIRST_NAME_BUF_SIZE); | ||
373 | entry->mLastName = std::string(last, DB_LAST_NAME_BUF_SIZE); | ||
374 | |||
375 | impl.mPendingQueue.erase(id); | ||
376 | impl.notifyObservers(id, | ||
377 | entry->mFirstName, entry->mLastName, | ||
378 | FALSE); | ||
379 | |||
380 | } | ||
381 | |||
382 | void LLCacheName::sendGroupNames(const LLUUID& id, std::string& name) | ||
383 | { | ||
384 | |||
385 | LLCacheNameEntry* entry = get_ptr_in_map(impl.mCache, id); | ||
386 | if (!entry) | ||
387 | { | ||
388 | entry = new LLCacheNameEntry; | ||
389 | impl.mCache[id] = entry; | ||
390 | |||
391 | } | ||
392 | |||
393 | entry->mIsGroup = true; | ||
394 | entry->mCreateTime = (U32)time(NULL); | ||
395 | |||
396 | entry->mGroupName = std::string(name, DB_GROUP_NAME_BUF_SIZE); | ||
397 | |||
398 | impl.mPendingQueue.erase(id); | ||
399 | |||
400 | impl.notifyObservers(id, | ||
401 | entry->mFirstName, entry->mLastName, | ||
402 | FALSE); | ||
403 | |||
404 | |||
405 | } | ||
406 | |||
322 | void LLCacheName::importFile(LLFILE* fp) | 407 | void LLCacheName::importFile(LLFILE* fp) |
323 | { | 408 | { |
324 | S32 count = 0; | 409 | S32 count = 0; |
@@ -524,6 +609,16 @@ BOOL LLCacheName::getFullName(const LLUUID& id, std::string& fullname) | |||
524 | return res; | 609 | return res; |
525 | } | 610 | } |
526 | 611 | ||
612 | void LLCacheName::setGroupURL(const std::string& group_url) | ||
613 | { | ||
614 | impl.mGroupNameURL = group_url; | ||
615 | } | ||
616 | |||
617 | void LLCacheName::setAgentURL(const std::string& agent_url) | ||
618 | { | ||
619 | impl.mAgentNameURL = agent_url; | ||
620 | } | ||
621 | |||
527 | BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group) | 622 | BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group) |
528 | { | 623 | { |
529 | if(id.isNull()) | 624 | if(id.isNull()) |
@@ -558,6 +653,111 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, std::string& group) | |||
558 | } | 653 | } |
559 | } | 654 | } |
560 | 655 | ||
656 | void LLCacheName::Impl::getAgentName(const AskQueue &queue) | ||
657 | { | ||
658 | |||
659 | // get the names from backbone module | ||
660 | if(queue.empty()) | ||
661 | { | ||
662 | return; | ||
663 | } | ||
664 | |||
665 | LLSD request; | ||
666 | request["action"] = "GET"; | ||
667 | LLSD id_block = LLSD::emptyArray(); | ||
668 | AskQueue::const_iterator it = queue.begin(); | ||
669 | AskQueue::const_iterator end = queue.end(); | ||
670 | for(;it!=end;++it) | ||
671 | { | ||
672 | id_block.append(*it); | ||
673 | } | ||
674 | lldebugs<<LLSDOStreamer<LLSDNotationFormatter>(id_block) <<llendl; | ||
675 | |||
676 | request["agents"] = id_block; | ||
677 | |||
678 | LLHTTPClient::post( | ||
679 | mAgentNameURL, | ||
680 | request, | ||
681 | new LLHTTPAgentNamesResponse(id_block)); | ||
682 | |||
683 | |||
684 | lldebugs<<"Service builder call to agent-name "<<mAgentNameURL<<llendl; | ||
685 | |||
686 | } | ||
687 | |||
688 | void LLHTTPAgentNamesResponse::result(const LLSD& content) | ||
689 | { | ||
690 | LLUUID id; | ||
691 | lldebugs<<LLSDOStreamer<LLSDNotationFormatter>(content) <<llendl; | ||
692 | |||
693 | LLSD::map_const_iterator iter = content.beginMap(); | ||
694 | for ( ; iter != content.endMap(); ++iter) | ||
695 | { | ||
696 | id.set((*iter).first); | ||
697 | LLSD name = (*iter).second; | ||
698 | LLCacheNameEntry* entry = new LLCacheNameEntry; | ||
699 | entry->mIsGroup = FALSE; | ||
700 | entry->mCreateTime = (U32)LLFrameTimer::getTotalSeconds(); | ||
701 | std::string first = name["first"]; | ||
702 | std::string last = name["last"]; | ||
703 | entry->mFirstName = std::string(first, DB_FIRST_NAME_BUF_SIZE); | ||
704 | entry->mLastName = std::string(last, DB_LAST_NAME_BUF_SIZE); | ||
705 | |||
706 | gCacheName->sendAgentNames(id,first,last); | ||
707 | } | ||
708 | } | ||
709 | |||
710 | |||
711 | void LLCacheName::Impl::getGroupName(const AskQueue &queue) | ||
712 | { | ||
713 | // get the group names from backbone module | ||
714 | if(queue.empty()) | ||
715 | { | ||
716 | return; | ||
717 | } | ||
718 | |||
719 | LLSD request; | ||
720 | request["action"] = "GET"; | ||
721 | LLSD id_block = LLSD::emptyArray(); | ||
722 | AskQueue::const_iterator it = queue.begin(); | ||
723 | AskQueue::const_iterator end = queue.end(); | ||
724 | for(;it!=end;++it) | ||
725 | { | ||
726 | id_block.append(*it); | ||
727 | } | ||
728 | |||
729 | request["groups"] = id_block; | ||
730 | |||
731 | if(!mGroupNameURL.empty()) | ||
732 | { | ||
733 | LLHTTPClient::post( | ||
734 | mGroupNameURL, | ||
735 | request, | ||
736 | new LLHTTPGroupNamesResponse(id_block)); | ||
737 | } | ||
738 | lldebugs<<"Service builder call to group-name "<< mGroupNameURL<<llendl; | ||
739 | } | ||
740 | |||
741 | void LLHTTPGroupNamesResponse::result(const LLSD& content) | ||
742 | { | ||
743 | lldebugs<<"Result"<<LLSDOStreamer<LLSDNotationFormatter>(content) << llendl; | ||
744 | LLUUID id; | ||
745 | |||
746 | LLSD::map_const_iterator iter = content.beginMap(); | ||
747 | for ( ; iter != content.endMap(); ++iter) | ||
748 | { | ||
749 | |||
750 | id.set((*iter).first); | ||
751 | std::string name = (*iter).second.asString(); | ||
752 | LLCacheNameEntry* entry = new LLCacheNameEntry; | ||
753 | entry->mIsGroup = TRUE; | ||
754 | entry->mCreateTime = (U32)time(NULL); | ||
755 | entry->mGroupName = std::string(name, DB_GROUP_NAME_BUF_SIZE); | ||
756 | lldebugs<<"Group Name"<<name<<llendl; | ||
757 | gCacheName->sendGroupNames(id,name); | ||
758 | } | ||
759 | } | ||
760 | |||
561 | // TODO: Make the cache name callback take a SINGLE std::string, | 761 | // TODO: Make the cache name callback take a SINGLE std::string, |
562 | // not a separate first and last name. | 762 | // not a separate first and last name. |
563 | void LLCacheName::get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callback, void* user_data) | 763 | void LLCacheName::get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callback, void* user_data) |
@@ -606,12 +806,14 @@ void LLCacheName::processPending() | |||
606 | return; | 806 | return; |
607 | } | 807 | } |
608 | 808 | ||
809 | /* | ||
609 | if(!impl.mUpstreamHost.isOk()) | 810 | if(!impl.mUpstreamHost.isOk()) |
610 | { | 811 | { |
611 | lldebugs << "LLCacheName::processPending() - bad upstream host." | 812 | lldebugs << "LLCacheName::processPending() - bad upstream host." |
612 | << llendl; | 813 | << llendl; |
613 | return; | 814 | return; |
614 | } | 815 | } |
816 | */ | ||
615 | 817 | ||
616 | impl.processPendingAsks(); | 818 | impl.processPendingAsks(); |
617 | impl.processPendingReplies(); | 819 | impl.processPendingReplies(); |
@@ -693,8 +895,16 @@ std::string LLCacheName::getDefaultName() | |||
693 | 895 | ||
694 | void LLCacheName::Impl::processPendingAsks() | 896 | void LLCacheName::Impl::processPendingAsks() |
695 | { | 897 | { |
696 | sendRequest(_PREHASH_UUIDNameRequest, mAskNameQueue); | 898 | if (mUpstreamHost.isOk()) //its the vuewer asking for names send request to simulator |
697 | sendRequest(_PREHASH_UUIDGroupNameRequest, mAskGroupQueue); | 899 | { |
900 | sendRequest(_PREHASH_UUIDNameRequest, mAskNameQueue); | ||
901 | sendRequest(_PREHASH_UUIDGroupNameRequest, mAskGroupQueue); | ||
902 | } | ||
903 | else //its simulator asking for names ask the backbone | ||
904 | { | ||
905 | getAgentName(mAskNameQueue); | ||
906 | getGroupName(mAskGroupQueue); | ||
907 | } | ||
698 | mAskNameQueue.clear(); | 908 | mAskNameQueue.clear(); |
699 | mAskGroupQueue.clear(); | 909 | mAskGroupQueue.clear(); |
700 | } | 910 | } |
@@ -815,12 +1025,15 @@ void LLCacheName::Impl::processUUIDRequest(LLMessageSystem* msg, bool isGroup) | |||
815 | { | 1025 | { |
816 | // You should only get this message if the cache is at the simulator | 1026 | // You should only get this message if the cache is at the simulator |
817 | // level, hence having an upstream provider. | 1027 | // level, hence having an upstream provider. |
1028 | // 03/31/2008 Simulator is talking to backbone and not dataserver | ||
1029 | // This check was for dataserver | ||
1030 | /* | ||
818 | if (!mUpstreamHost.isOk()) | 1031 | if (!mUpstreamHost.isOk()) |
819 | { | 1032 | { |
820 | llwarns << "LLCacheName - got UUID name/group request, but no upstream provider!" << llendl; | 1033 | llwarns << "LLCacheName - got UUID name/group request, but no upstream provider!" << llendl; |
821 | return; | 1034 | return; |
822 | } | 1035 | } |
823 | 1036 | */ | |
824 | LLHost fromHost = msg->getSender(); | 1037 | LLHost fromHost = msg->getSender(); |
825 | ReplySender sender(msg); | 1038 | ReplySender sender(msg); |
826 | 1039 | ||