From 89e3959cf393ce9eeb058304264d4f55f4fe9ca2 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Fri, 7 Jun 2013 12:58:04 -0400 Subject: SH-4216 WIP - moved AISv3 commands and responders to llaisapi.* files --- indra/newview/llaisapi.cpp | 481 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 481 insertions(+) create mode 100755 indra/newview/llaisapi.cpp (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp new file mode 100755 index 0000000000..6adf35efb8 --- /dev/null +++ b/indra/newview/llaisapi.cpp @@ -0,0 +1,481 @@ +/** + * @file llaisapi.cpp + * @brief classes and functions for interfacing with the v3+ ais inventory service. + * + * $LicenseInfo:firstyear=2013&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2013, 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. + * + * 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. + * + * 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 + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + * + */ + +#include "llviewerprecompiledheaders.h" +#include "llaisapi.h" + +#include "llagent.h" +#include "llcallbacklist.h" +#include "llinventorymodel.h" +#include "llsdutil.h" +#include "llviewerregion.h" + +///---------------------------------------------------------------------------- +/// Classes for AISv3 support. +///---------------------------------------------------------------------------- + +// AISCommand - base class for retry-able HTTP requests using the AISv3 cap. +AISCommand::AISCommand(LLPointer callback): + mCallback(callback) +{ + mRetryPolicy = new LLAdaptiveRetryPolicy(1.0, 32.0, 2.0, 10); +} + +void AISCommand::run_command() +{ + mCommandFunc(); +} + +void AISCommand::setCommandFunc(command_func_type command_func) +{ + mCommandFunc = command_func; +} + +// virtual +bool AISCommand::getResponseUUID(const LLSD& content, LLUUID& id) +{ + return false; +} + +/* virtual */ +void AISCommand::httpSuccess() +{ + // Command func holds a reference to self, need to release it + // after a success or final failure. + setCommandFunc(no_op); + + const LLSD& content = getContent(); + if (!content.isMap()) + { + failureResult(HTTP_INTERNAL_ERROR, "Malformed response contents", content); + return; + } + mRetryPolicy->onSuccess(); + + gInventory.onAISUpdateReceived("AISCommand", content); + + if (mCallback) + { + LLUUID item_id; // will default to null if parse fails. + getResponseUUID(content,item_id); + mCallback->fire(item_id); + } +} + +/*virtual*/ +void AISCommand::httpFailure() +{ + const LLSD& content = getContent(); + S32 status = getStatus(); + const std::string& reason = getReason(); + const LLSD& headers = getResponseHeaders(); + if (!content.isMap()) + { + LL_DEBUGS("Inventory") << "Malformed response contents " << content + << " status " << status << " reason " << reason << llendl; + } + else + { + LL_DEBUGS("Inventory") << "failed with content: " << ll_pretty_print_sd(content) + << " status " << status << " reason " << reason << llendl; + } + mRetryPolicy->onFailure(status, headers); + F32 seconds_to_wait; + if (mRetryPolicy->shouldRetry(seconds_to_wait)) + { + doAfterInterval(boost::bind(&AISCommand::run_command,this),seconds_to_wait); + } + else + { + // Command func holds a reference to self, need to release it + // after a success or final failure. + setCommandFunc(no_op); + } +} + +//static +bool AISCommand::getCap(std::string& cap) +{ + if (gAgent.getRegion()) + { + cap = gAgent.getRegion()->getCapability("InventoryAPIv3"); + } + if (!cap.empty()) + { + return true; + } + return false; +} + +RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, + LLPointer callback): + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + std::string url = cap + std::string("/item/") + item_id.asString(); + LL_DEBUGS("Inventory") << "url: " << url << llendl; + LLHTTPClient::ResponderPtr responder = this; + LLSD headers; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); + setCommandFunc(cmd); +} + +RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, + LLPointer callback): + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + std::string url = cap + std::string("/category/") + item_id.asString(); + LL_DEBUGS("Inventory") << "url: " << url << llendl; + LLHTTPClient::ResponderPtr responder = this; + LLSD headers; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); + setCommandFunc(cmd); +} + +PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, + LLPointer callback): + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; + LL_DEBUGS("Inventory") << "url: " << url << llendl; + LLCurl::ResponderPtr responder = this; + LLSD headers; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); + setCommandFunc(cmd); +} + +UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, + const LLSD& updates, + LLPointer callback): + mUpdates(updates), + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + std::string url = cap + std::string("/item/") + item_id.asString(); + LL_DEBUGS("Inventory") << "url: " << url << llendl; + LLCurl::ResponderPtr responder = this; + LLSD headers; + headers["Content-Type"] = "application/llsd+xml"; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); + setCommandFunc(cmd); +} + +UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& item_id, + const LLSD& updates, + LLPointer callback): + mUpdates(updates), + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + std::string url = cap + std::string("/category/") + item_id.asString(); + LL_DEBUGS("Inventory") << "url: " << url << llendl; + LLCurl::ResponderPtr responder = this; + LLSD headers; + headers["Content-Type"] = "application/llsd+xml"; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); + setCommandFunc(cmd); +} + +SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer callback): + mContents(contents), + AISCommand(callback) +{ + std::string cap; + if (!getCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + LLUUID tid; + tid.generate(); + std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); + llinfos << url << llendl; + LLCurl::ResponderPtr responder = this; + LLSD headers; + headers["Content-Type"] = "application/llsd+xml"; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::put, url, mContents, responder, headers, timeout); + setCommandFunc(cmd); +} + +AISUpdate::AISUpdate(const LLSD& update) +{ + parseUpdate(update); +} + +void AISUpdate::parseUpdate(const LLSD& update) +{ + // parse _categories_removed -> mObjectsDeleted + uuid_vec_t cat_ids; + parseUUIDArray(update,"_categories_removed",cat_ids); + for (uuid_vec_t::const_iterator it = cat_ids.begin(); + it != cat_ids.end(); ++it) + { + LLViewerInventoryCategory *cat = gInventory.getCategory(*it); + mCatDeltas[cat->getParentUUID()]--; + mObjectsDeleted.insert(*it); + } + + // parse _categories_items_removed -> mObjectsDeleted + uuid_vec_t item_ids; + parseUUIDArray(update,"_category_items_removed",item_ids); + for (uuid_vec_t::const_iterator it = item_ids.begin(); + it != item_ids.end(); ++it) + { + LLViewerInventoryItem *item = gInventory.getItem(*it); + mCatDeltas[item->getParentUUID()]--; + mObjectsDeleted.insert(*it); + } + + // parse _broken_links_removed -> mObjectsDeleted + uuid_vec_t broken_link_ids; + parseUUIDArray(update,"_broken_links_removed",broken_link_ids); + for (uuid_vec_t::const_iterator it = broken_link_ids.begin(); + it != broken_link_ids.end(); ++it) + { + LLViewerInventoryItem *item = gInventory.getItem(*it); + mCatDeltas[item->getParentUUID()]--; + mObjectsDeleted.insert(*it); + } + + // parse _created_items + parseUUIDArray(update,"_created_items",mItemsCreatedIds); + + if (update.has("_embedded")) + { + const LLSD& embedded = update["_embedded"]; + for(LLSD::map_const_iterator it = embedded.beginMap(), + end = embedded.endMap(); + it != end; ++it) + { + const std::string& field = (*it).first; + + // parse created links + if (field == "link") + { + const LLSD& links = embedded["link"]; + parseCreatedLinks(links); + } + else + { + llwarns << "unrecognized embedded field " << field << llendl; + } + } + + } + + // Parse item update at the top level. + if (update.has("item_id")) + { + LLUUID item_id = update["item_id"].asUUID(); + LLPointer new_item(new LLViewerInventoryItem); + BOOL rv = new_item->unpackMessage(update); + if (rv) + { + mItemsUpdated[item_id] = new_item; + // This statement is here to cause a new entry with 0 + // delta to be created if it does not already exist; + // otherwise has no effect. + mCatDeltas[new_item->getParentUUID()]; + } + else + { + llerrs << "unpack failed" << llendl; + } + } + + // Parse updated category versions. + const std::string& ucv = "_updated_category_versions"; + if (update.has(ucv)) + { + for(LLSD::map_const_iterator it = update[ucv].beginMap(), + end = update[ucv].endMap(); + it != end; ++it) + { + const LLUUID id((*it).first); + S32 version = (*it).second.asInteger(); + mCatVersions[id] = version; + } + } +} + +void AISUpdate::parseUUIDArray(const LLSD& content, const std::string& name, uuid_vec_t& ids) +{ + ids.clear(); + if (content.has(name)) + { + for(LLSD::array_const_iterator it = content[name].beginArray(), + end = content[name].endArray(); + it != end; ++it) + { + ids.push_back((*it).asUUID()); + } + } +} + +void AISUpdate::parseLink(const LLUUID& link_id, const LLSD& link_map) +{ + LLPointer new_link(new LLViewerInventoryItem); + BOOL rv = new_link->unpackMessage(link_map); + if (rv) + { + LLPermissions default_perms; + default_perms.init(gAgent.getID(),gAgent.getID(),LLUUID::null,LLUUID::null); + default_perms.initMasks(PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE); + new_link->setPermissions(default_perms); + LLSaleInfo default_sale_info; + new_link->setSaleInfo(default_sale_info); + //LL_DEBUGS("Inventory") << "creating link from llsd: " << ll_pretty_print_sd(link_map) << llendl; + mItemsCreated[link_id] = new_link; + const LLUUID& parent_id = new_link->getParentUUID(); + mCatDeltas[parent_id]++; + } + else + { + llwarns << "failed to parse" << llendl; + } +} + +void AISUpdate::parseCreatedLinks(const LLSD& links) +{ + for(LLSD::map_const_iterator linkit = links.beginMap(), + linkend = links.endMap(); + linkit != linkend; ++linkit) + { + const LLUUID link_id((*linkit).first); + const LLSD& link_map = (*linkit).second; + uuid_vec_t::const_iterator pos = + std::find(mItemsCreatedIds.begin(), + mItemsCreatedIds.end(),link_id); + if (pos != mItemsCreatedIds.end()) + { + parseLink(link_id,link_map); + } + else + { + LL_DEBUGS("Inventory") << "Ignoring link not in created items list " << link_id << llendl; + } + } +} + +void AISUpdate::doUpdate() +{ + // Do descendent/version accounting. + // Can remove this if/when we use the version info directly. + for (std::map::const_iterator catit = mCatDeltas.begin(); + catit != mCatDeltas.end(); ++catit) + { + const LLUUID cat_id(catit->first); + S32 delta = catit->second; + LLInventoryModel::LLCategoryUpdate up(cat_id, delta); + gInventory.accountForUpdate(up); + } + + // TODO - how can we use this version info? Need to be sure all + // changes are going through AIS first, or at least through + // something with a reliable responder. + for (uuid_int_map_t::iterator ucv_it = mCatVersions.begin(); + ucv_it != mCatVersions.end(); ++ucv_it) + { + const LLUUID id = ucv_it->first; + S32 version = ucv_it->second; + LLViewerInventoryCategory *cat = gInventory.getCategory(id); + if (cat->getVersion() != version) + { + llwarns << "Possible version mismatch, viewer " << cat->getVersion() + << " server " << version << llendl; + } + } + + // CREATE ITEMS + for (deferred_item_map_t::const_iterator create_it = mItemsCreated.begin(); + create_it != mItemsCreated.end(); ++create_it) + { + LLUUID item_id(create_it->first); + LLPointer new_item = create_it->second; + + // FIXME risky function since it calls updateServer() in some + // cases. Maybe break out the update/create cases, in which + // case this is create. + LL_DEBUGS("Inventory") << "created item " << item_id << llendl; + gInventory.updateItem(new_item); + } + + // UPDATE ITEMS + for (deferred_item_map_t::const_iterator update_it = mItemsUpdated.begin(); + update_it != mItemsUpdated.end(); ++update_it) + { + LLUUID item_id(update_it->first); + LLPointer new_item = update_it->second; + // FIXME risky function since it calls updateServer() in some + // cases. Maybe break out the update/create cases, in which + // case this is update. + LL_DEBUGS("Inventory") << "updated item " << item_id << llendl; + gInventory.updateItem(new_item); + } + + // DELETE OBJECTS + for (std::set::const_iterator del_it = mObjectsDeleted.begin(); + del_it != mObjectsDeleted.end(); ++del_it) + { + LL_DEBUGS("Inventory") << "deleted item " << *del_it << llendl; + gInventory.onObjectDeletedFromServer(*del_it, false, false); + } +} + -- cgit v1.2.3 From 6d46132ef5218cd17d8d201f16e5a7df4b1e39a6 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 10 Jun 2013 16:29:10 -0400 Subject: SH-4216 WIP - finished item/cat update and reorg of aisv3 code --- indra/newview/llaisapi.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 6adf35efb8..393e5c0a68 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -202,6 +202,7 @@ UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, } std::string url = cap + std::string("/item/") + item_id.asString(); LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << llendl; LLCurl::ResponderPtr responder = this; LLSD headers; headers["Content-Type"] = "application/llsd+xml"; -- cgit v1.2.3 From 2d0b329003d0350c12ce4686f1261e68ce39573b Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 17 Jun 2013 16:20:17 -0400 Subject: SH-4238 WIP - postpone calling notifyObservers until all deletes are processed. --- indra/newview/llaisapi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 393e5c0a68..21f6482a06 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -476,7 +476,9 @@ void AISUpdate::doUpdate() del_it != mObjectsDeleted.end(); ++del_it) { LL_DEBUGS("Inventory") << "deleted item " << *del_it << llendl; - gInventory.onObjectDeletedFromServer(*del_it, false, false); + gInventory.onObjectDeletedFromServer(*del_it, false, false, false); } + + gInventory.notifyObservers(); } -- cgit v1.2.3 From 1a42b98a8f55662aed448e9bcd5035082140bbcf Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 17 Jun 2013 16:56:59 -0400 Subject: SH-4237 WIP - logging cleanup in onAIS handling --- indra/newview/llaisapi.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 21f6482a06..e57bbbb0be 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -315,7 +315,7 @@ void AISUpdate::parseUpdate(const LLSD& update) } else { - llwarns << "unrecognized embedded field " << field << llendl; + //LL_DEBUGS("Inventory") << "unhandled embedded field " << field << llendl; } } @@ -439,8 +439,9 @@ void AISUpdate::doUpdate() LLViewerInventoryCategory *cat = gInventory.getCategory(id); if (cat->getVersion() != version) { - llwarns << "Possible version mismatch, viewer " << cat->getVersion() - << " server " << version << llendl; + llwarns << "Possible version mismatch for category " << cat->getName() + << ", viewer version " << cat->getVersion() + << " server version " << version << llendl; } } -- cgit v1.2.3 From 27fc270c73fdf3db5c07e9ed43b7f4d0994b2cc2 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 18 Jun 2013 16:51:37 -0400 Subject: SH-4262 WIP - fix for the reordering bug in AIS regions. --- indra/newview/llaisapi.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 393e5c0a68..aad12a9cc9 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -326,6 +326,12 @@ void AISUpdate::parseUpdate(const LLSD& update) { LLUUID item_id = update["item_id"].asUUID(); LLPointer new_item(new LLViewerInventoryItem); + LLViewerInventoryItem *curr_item = gInventory.getItem(item_id); + if (curr_item) + { + // Default to current values where not provided. + new_item->copyViewerItem(curr_item); + } BOOL rv = new_item->unpackMessage(update); if (rv) { @@ -468,6 +474,7 @@ void AISUpdate::doUpdate() // cases. Maybe break out the update/create cases, in which // case this is update. LL_DEBUGS("Inventory") << "updated item " << item_id << llendl; + //LL_DEBUGS("Inventory") << ll_pretty_print_sd(new_item->asLLSD()) << llendl; gInventory.updateItem(new_item); } -- cgit v1.2.3 From f88594599c01edff981b6d070f84566fcb7d4ecf Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 18 Jun 2013 16:54:37 -0400 Subject: SH-4237 WIP - removed somewhat misleading warning --- indra/newview/llaisapi.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 7e751ad6c7..8037654812 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -313,12 +313,7 @@ void AISUpdate::parseUpdate(const LLSD& update) const LLSD& links = embedded["link"]; parseCreatedLinks(links); } - else - { - llwarns << "unrecognized embedded field " << field << llendl; - } } - } // Parse item update at the top level. -- cgit v1.2.3 From a85fa3b10a406218cabfecc0d592e816f8dfdb53 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Thu, 11 Jul 2013 15:15:04 -0700 Subject: Adding support for COPY methods to httpclient. Implementing viewer-side use of AISv3 COPY library folder operation. (SH-4304) --- indra/newview/llaisapi.cpp | 588 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 462 insertions(+), 126 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 6d5f1951f9..cb8700865a 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -40,14 +40,25 @@ // AISCommand - base class for retry-able HTTP requests using the AISv3 cap. AISCommand::AISCommand(LLPointer callback): + mCommandFunc(NULL), mCallback(callback) { mRetryPolicy = new LLAdaptiveRetryPolicy(1.0, 32.0, 2.0, 10); } -void AISCommand::run_command() +bool AISCommand::run_command() { - mCommandFunc(); + if (NULL == mCommandFunc) + { + // This may happen if a command failed to initiate itself. + LL_WARNS("Inventory") << "AIS command attempted with null command function" << LL_ENDL; + return false; + } + else + { + mCommandFunc(); + return true; + } } void AISCommand::setCommandFunc(command_func_type command_func) @@ -80,9 +91,9 @@ void AISCommand::httpSuccess() if (mCallback) { - LLUUID item_id; // will default to null if parse fails. - getResponseUUID(content,item_id); - mCallback->fire(item_id); + LLUUID id; // will default to null if parse fails. + getResponseUUID(content,id); + mCallback->fire(id); } } @@ -96,12 +107,12 @@ void AISCommand::httpFailure() if (!content.isMap()) { LL_DEBUGS("Inventory") << "Malformed response contents " << content - << " status " << status << " reason " << reason << llendl; + << " status " << status << " reason " << reason << LL_ENDL; } else { LL_DEBUGS("Inventory") << "failed with content: " << ll_pretty_print_sd(content) - << " status " << status << " reason " << reason << llendl; + << " status " << status << " reason " << reason << LL_ENDL; } mRetryPolicy->onFailure(status, headers); F32 seconds_to_wait; @@ -113,12 +124,23 @@ void AISCommand::httpFailure() { // Command func holds a reference to self, need to release it // after a success or final failure. + // *TODO: Notify user? This seems bad. setCommandFunc(no_op); } } //static -bool AISCommand::getCap(std::string& cap) +bool AISCommand::isAPIAvailable() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->isCapabilityAvailable("InventoryAPIv3"); + } + return false; +} + +//static +bool AISCommand::getInvCap(std::string& cap) { if (gAgent.getRegion()) { @@ -131,18 +153,39 @@ bool AISCommand::getCap(std::string& cap) return false; } +//static +bool AISCommand::getLibCap(std::string& cap) +{ + if (gAgent.getRegion()) + { + cap = gAgent.getRegion()->getCapability("LibraryAPIv3"); + } + if (!cap.empty()) + { + return true; + } + return false; +} + +//static +void AISCommand::getCapabilityNames(LLSD& capabilityNames) +{ + capabilityNames.append("InventoryAPIv3"); + capabilityNames.append("LibraryAPIv3"); +} + RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, LLPointer callback): AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; } std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LLHTTPClient::ResponderPtr responder = this; LLSD headers; F32 timeout = HTTP_REQUEST_EXPIRY_SECS; @@ -155,13 +198,13 @@ RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; } std::string url = cap + std::string("/category/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LLHTTPClient::ResponderPtr responder = this; LLSD headers; F32 timeout = HTTP_REQUEST_EXPIRY_SECS; @@ -174,13 +217,13 @@ PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; } std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; - LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; F32 timeout = HTTP_REQUEST_EXPIRY_SECS; @@ -195,14 +238,14 @@ UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; } std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; - LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << llendl; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; headers["Content-Type"] = "application/llsd+xml"; @@ -218,13 +261,13 @@ UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& item_id, AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; } std::string url = cap + std::string("/category/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; headers["Content-Type"] = "application/llsd+xml"; @@ -238,7 +281,7 @@ SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& conten AISCommand(callback) { std::string cap; - if (!getCap(cap)) + if (!getInvCap(cap)) { llwarns << "No cap found" << llendl; return; @@ -255,146 +298,335 @@ SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& conten setCommandFunc(cmd); } +CopyLibraryCategoryCommand::CopyLibraryCategoryCommand(const LLUUID& source_id, + const LLUUID& dest_id, + LLPointer callback): + AISCommand(callback) +{ + std::string cap; + if (!getLibCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + LL_DEBUGS("Inventory") << "Copying library category: " << source_id << " => " << dest_id << LL_ENDL; + LLUUID tid; + tid.generate(); + std::string url = cap + std::string("/category/") + source_id.asString() + "?tid=" + tid.asString(); + llinfos << url << llendl; + LLCurl::ResponderPtr responder = this; + LLSD headers; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::copy, url, dest_id.asString(), responder, headers, timeout); + setCommandFunc(cmd); +} + +bool CopyLibraryCategoryCommand::getResponseUUID(const LLSD& content, LLUUID& id) +{ + if (content.has("category_id")) + { + id = content["category_id"]; + return true; + } + return false; +} + AISUpdate::AISUpdate(const LLSD& update) { parseUpdate(update); } +void AISUpdate::clearParseResults() +{ + mCatDescendentDeltas.clear(); + mCatDescendentsKnown.clear(); + mCatVersionsUpdated.clear(); + mItemsCreated.clear(); + mItemsUpdated.clear(); + mCategoriesCreated.clear(); + mCategoriesUpdated.clear(); + mObjectsDeletedIds.clear(); + mItemIds.clear(); + mCategoryIds.clear(); +} + void AISUpdate::parseUpdate(const LLSD& update) { - // parse _categories_removed -> mObjectsDeleted - uuid_vec_t cat_ids; + clearParseResults(); + parseMeta(update); + parseContent(update); +} + +void AISUpdate::parseMeta(const LLSD& update) +{ + // parse _categories_removed -> mObjectsDeletedIds + uuid_list_t cat_ids; parseUUIDArray(update,"_categories_removed",cat_ids); - for (uuid_vec_t::const_iterator it = cat_ids.begin(); + for (uuid_list_t::const_iterator it = cat_ids.begin(); it != cat_ids.end(); ++it) { LLViewerInventoryCategory *cat = gInventory.getCategory(*it); - mCatDeltas[cat->getParentUUID()]--; - mObjectsDeleted.insert(*it); + mCatDescendentDeltas[cat->getParentUUID()]--; + mObjectsDeletedIds.insert(*it); } - // parse _categories_items_removed -> mObjectsDeleted - uuid_vec_t item_ids; + // parse _categories_items_removed -> mObjectsDeletedIds + uuid_list_t item_ids; parseUUIDArray(update,"_category_items_removed",item_ids); - for (uuid_vec_t::const_iterator it = item_ids.begin(); + parseUUIDArray(update,"_removed_items",item_ids); + for (uuid_list_t::const_iterator it = item_ids.begin(); it != item_ids.end(); ++it) { LLViewerInventoryItem *item = gInventory.getItem(*it); - mCatDeltas[item->getParentUUID()]--; - mObjectsDeleted.insert(*it); + mCatDescendentDeltas[item->getParentUUID()]--; + mObjectsDeletedIds.insert(*it); } - // parse _broken_links_removed -> mObjectsDeleted - uuid_vec_t broken_link_ids; + // parse _broken_links_removed -> mObjectsDeletedIds + uuid_list_t broken_link_ids; parseUUIDArray(update,"_broken_links_removed",broken_link_ids); - for (uuid_vec_t::const_iterator it = broken_link_ids.begin(); + for (uuid_list_t::const_iterator it = broken_link_ids.begin(); it != broken_link_ids.end(); ++it) { LLViewerInventoryItem *item = gInventory.getItem(*it); - mCatDeltas[item->getParentUUID()]--; - mObjectsDeleted.insert(*it); + mCatDescendentDeltas[item->getParentUUID()]--; + mObjectsDeletedIds.insert(*it); } // parse _created_items - parseUUIDArray(update,"_created_items",mItemsCreatedIds); + parseUUIDArray(update,"_created_items",mItemIds); + + // parse _created_categories + parseUUIDArray(update,"_created_categories",mCategoryIds); - if (update.has("_embedded")) + // Parse updated category versions. + const std::string& ucv = "_updated_category_versions"; + if (update.has(ucv)) { - const LLSD& embedded = update["_embedded"]; - for(LLSD::map_const_iterator it = embedded.beginMap(), - end = embedded.endMap(); - it != end; ++it) + for(LLSD::map_const_iterator it = update[ucv].beginMap(), + end = update[ucv].endMap(); + it != end; ++it) { - const std::string& field = (*it).first; - - // parse created links - if (field == "link") - { - const LLSD& links = embedded["link"]; - parseCreatedLinks(links); - } + const LLUUID id((*it).first); + S32 version = (*it).second.asInteger(); + mCatVersionsUpdated[id] = version; } } +} - // Parse item update at the top level. - if (update.has("item_id")) +void AISUpdate::parseContent(const LLSD& update) +{ + if (update.has("linked_id")) { - LLUUID item_id = update["item_id"].asUUID(); - LLPointer new_item(new LLViewerInventoryItem); - LLViewerInventoryItem *curr_item = gInventory.getItem(item_id); - if (curr_item) + parseLink(update); + } + else if (update.has("item_id")) + { + parseItem(update); + } + + if (update.has("category_id")) + { + parseCategory(update); + } + else + { + if (update.has("_embedded")) { - // Default to current values where not provided. - new_item->copyViewerItem(curr_item); + parseEmbedded(update["_embedded"]); } - BOOL rv = new_item->unpackMessage(update); - if (rv) + } +} + +void AISUpdate::parseItem(const LLSD& item_map) +{ + LLUUID item_id = item_map["item_id"].asUUID(); + LLPointer new_item(new LLViewerInventoryItem); + LLViewerInventoryItem *curr_item = gInventory.getItem(item_id); + if (curr_item) + { + // Default to current values where not provided. + new_item->copyViewerItem(curr_item); + } + BOOL rv = new_item->unpackMessage(item_map); + if (rv) + { + if (curr_item) { mItemsUpdated[item_id] = new_item; // This statement is here to cause a new entry with 0 // delta to be created if it does not already exist; // otherwise has no effect. - mCatDeltas[new_item->getParentUUID()]; + mCatDescendentDeltas[new_item->getParentUUID()]; } else { - llerrs << "unpack failed" << llendl; + mItemsCreated[item_id] = new_item; + mCatDescendentDeltas[new_item->getParentUUID()]++; } } + else + { + // *TODO: Wow, harsh. Should we just complain and get out? + llerrs << "unpack failed" << llendl; + } +} - // Parse updated category versions. - const std::string& ucv = "_updated_category_versions"; - if (update.has(ucv)) +void AISUpdate::parseLink(const LLSD& link_map) +{ + LLUUID item_id = link_map["item_id"].asUUID(); + LLPointer new_link(new LLViewerInventoryItem); + LLViewerInventoryItem *curr_link = gInventory.getItem(item_id); + if (curr_link) { - for(LLSD::map_const_iterator it = update[ucv].beginMap(), - end = update[ucv].endMap(); - it != end; ++it) + // Default to current values where not provided. + new_link->copyViewerItem(curr_link); + } + BOOL rv = new_link->unpackMessage(link_map); + if (rv) + { + const LLUUID& parent_id = new_link->getParentUUID(); + if (curr_link) { - const LLUUID id((*it).first); - S32 version = (*it).second.asInteger(); - mCatVersions[id] = version; + mItemsUpdated[item_id] = new_link; + // This statement is here to cause a new entry with 0 + // delta to be created if it does not already exist; + // otherwise has no effect. + mCatDescendentDeltas[parent_id]; + } + else + { + LLPermissions default_perms; + default_perms.init(gAgent.getID(),gAgent.getID(),LLUUID::null,LLUUID::null); + default_perms.initMasks(PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE); + new_link->setPermissions(default_perms); + LLSaleInfo default_sale_info; + new_link->setSaleInfo(default_sale_info); + //LL_DEBUGS("Inventory") << "creating link from llsd: " << ll_pretty_print_sd(link_map) << LL_ENDL; + mItemsCreated[item_id] = new_link; + mCatDescendentDeltas[parent_id]++; } } + else + { + // *TODO: Wow, harsh. Should we just complain and get out? + llerrs << "unpack failed" << llendl; + } } -void AISUpdate::parseUUIDArray(const LLSD& content, const std::string& name, uuid_vec_t& ids) + +void AISUpdate::parseCategory(const LLSD& category_map) { - ids.clear(); - if (content.has(name)) + LLUUID category_id = category_map["category_id"].asUUID(); + + // Check descendent count first, as it may be needed + // to populate newly created categories + if (category_map.has("_embedded")) { - for(LLSD::array_const_iterator it = content[name].beginArray(), - end = content[name].endArray(); - it != end; ++it) + parseDescendentCount(category_id, category_map["_embedded"]); + } + + LLPointer new_cat(new LLViewerInventoryCategory(category_id)); + LLViewerInventoryCategory *curr_cat = gInventory.getCategory(category_id); + if (curr_cat) + { + // Default to current values where not provided. + new_cat->copyViewerCategory(curr_cat); + } + BOOL rv = new_cat->unpackMessage(category_map); + // *NOTE: unpackMessage does not unpack version or descendent count. + //if (category_map.has("version")) + //{ + // mCatVersionsUpdated[category_id] = category_map["version"].asInteger(); + //} + if (rv) + { + if (curr_cat) + { + mCategoriesUpdated[category_id] = new_cat; + // This statement is here to cause a new entry with 0 + // delta to be created if it does not already exist; + // otherwise has no effect. + mCatDescendentDeltas[new_cat->getParentUUID()]; + } + else { - ids.push_back((*it).asUUID()); + // Set version/descendents for newly created categories. + if (category_map.has("version")) + { + S32 version = category_map["version"].asInteger(); + LL_DEBUGS("Inventory") << "Setting version to " << version + << " for new category " << category_id << LL_ENDL; + new_cat->setVersion(version); + } + uuid_int_map_t::const_iterator lookup_it = mCatDescendentsKnown.find(category_id); + if (mCatDescendentsKnown.end() != lookup_it) + { + S32 descendent_count = lookup_it->second; + LL_DEBUGS("Inventory") << "Setting descendents count to " << descendent_count + << " for new category " << category_id << LL_ENDL; + new_cat->setDescendentCount(descendent_count); + } + mCategoriesCreated[category_id] = new_cat; + mCatDescendentDeltas[new_cat->getParentUUID()]++; } } + else + { + // *TODO: Wow, harsh. Should we just complain and get out? + llerrs << "unpack failed" << llendl; + } + + // Check for more embedded content. + if (category_map.has("_embedded")) + { + parseEmbedded(category_map["_embedded"]); + } } -void AISUpdate::parseLink(const LLUUID& link_id, const LLSD& link_map) +void AISUpdate::parseDescendentCount(const LLUUID& category_id, const LLSD& embedded) { - LLPointer new_link(new LLViewerInventoryItem); - BOOL rv = new_link->unpackMessage(link_map); - if (rv) + // We can only determine true descendent count if this contains all descendent types. + if (embedded.has("category") && + embedded.has("link") && + embedded.has("item")) { - LLPermissions default_perms; - default_perms.init(gAgent.getID(),gAgent.getID(),LLUUID::null,LLUUID::null); - default_perms.initMasks(PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE); - new_link->setPermissions(default_perms); - LLSaleInfo default_sale_info; - new_link->setSaleInfo(default_sale_info); - //LL_DEBUGS("Inventory") << "creating link from llsd: " << ll_pretty_print_sd(link_map) << llendl; - mItemsCreated[link_id] = new_link; - const LLUUID& parent_id = new_link->getParentUUID(); - mCatDeltas[parent_id]++; + mCatDescendentsKnown[category_id] = embedded["category"].size(); + mCatDescendentsKnown[category_id] += embedded["link"].size(); + mCatDescendentsKnown[category_id] += embedded["item"].size(); } - else +} + +void AISUpdate::parseEmbedded(const LLSD& embedded) +{ + if (embedded.has("link")) + { + parseEmbeddedLinks(embedded["link"]); + } + if (embedded.has("item")) + { + parseEmbeddedItems(embedded["item"]); + } + if (embedded.has("category")) { - llwarns << "failed to parse" << llendl; + parseEmbeddedCategories(embedded["category"]); + } +} + +void AISUpdate::parseUUIDArray(const LLSD& content, const std::string& name, uuid_list_t& ids) +{ + if (content.has(name)) + { + for(LLSD::array_const_iterator it = content[name].beginArray(), + end = content[name].endArray(); + it != end; ++it) + { + ids.insert((*it).asUUID()); + } } } -void AISUpdate::parseCreatedLinks(const LLSD& links) +void AISUpdate::parseEmbeddedLinks(const LLSD& links) { for(LLSD::map_const_iterator linkit = links.beginMap(), linkend = links.endMap(); @@ -402,47 +634,134 @@ void AISUpdate::parseCreatedLinks(const LLSD& links) { const LLUUID link_id((*linkit).first); const LLSD& link_map = (*linkit).second; - uuid_vec_t::const_iterator pos = - std::find(mItemsCreatedIds.begin(), - mItemsCreatedIds.end(),link_id); - if (pos != mItemsCreatedIds.end()) + if (mItemIds.end() == mItemIds.find(link_id)) + { + LL_DEBUGS("Inventory") << "Ignoring link not in items list " << link_id << LL_ENDL; + } + else + { + parseLink(link_map); + } + } +} + +void AISUpdate::parseEmbeddedItems(const LLSD& items) +{ + // Special case: this may be a single item (_embedded in a link) + if (items.has("item_id")) + { + if (mItemIds.end() != mItemIds.find(items["item_id"].asUUID())) + { + parseContent(items); + } + return; + } + + for(LLSD::map_const_iterator itemit = items.beginMap(), + itemend = items.endMap(); + itemit != itemend; ++itemit) + { + const LLUUID item_id((*itemit).first); + const LLSD& item_map = (*itemit).second; + if (mItemIds.end() == mItemIds.find(item_id)) + { + LL_DEBUGS("Inventory") << "Ignoring item not in items list " << item_id << LL_ENDL; + } + else + { + parseItem(item_map); + } + } +} + +void AISUpdate::parseEmbeddedCategories(const LLSD& categories) +{ + for(LLSD::map_const_iterator categoryit = categories.beginMap(), + categoryend = categories.endMap(); + categoryit != categoryend; ++categoryit) + { + const LLUUID category_id((*categoryit).first); + const LLSD& category_map = (*categoryit).second; + if (mCategoryIds.end() == mCategoryIds.find(category_id)) { - parseLink(link_id,link_map); + LL_DEBUGS("Inventory") << "Ignoring category not in categories list " << category_id << LL_ENDL; } else { - LL_DEBUGS("Inventory") << "Ignoring link not in created items list " << link_id << llendl; + parseCategory(category_map); } } } void AISUpdate::doUpdate() { - // Do descendent/version accounting. - // Can remove this if/when we use the version info directly. - for (std::map::const_iterator catit = mCatDeltas.begin(); - catit != mCatDeltas.end(); ++catit) + // Do version/descendent accounting. + for (std::map::const_iterator catit = mCatDescendentDeltas.begin(); + catit != mCatDescendentDeltas.end(); ++catit) { const LLUUID cat_id(catit->first); - S32 delta = catit->second; - LLInventoryModel::LLCategoryUpdate up(cat_id, delta); - gInventory.accountForUpdate(up); + // Don't account for update if we just created this category. + if (mCategoriesCreated.find(cat_id) != mCategoriesCreated.end()) + { + LL_DEBUGS("Inventory") << "Skipping version increment for new category " << cat_id << LL_ENDL; + continue; + } + + // Don't account for update unless AIS told us it updated that category. + if (mCatVersionsUpdated.find(cat_id) == mCatVersionsUpdated.end()) + { + LL_DEBUGS("Inventory") << "Skipping version increment for non-updated category " << cat_id << LL_ENDL; + continue; + } + + // If we have a known descendent count, set that now. + LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id); + if (cat) + { + S32 descendent_delta = catit->second; + S32 old_count = cat->getDescendentCount(); + LL_DEBUGS("Inventory") << "Updating descendent count for " << cat_id + << " with delta " << descendent_delta << " from " + << old_count << " to " << (old_count+descendent_delta) << LL_ENDL; + LLInventoryModel::LLCategoryUpdate up(cat_id, descendent_delta); + gInventory.accountForUpdate(up); + } + else + { + LL_DEBUGS("Inventory") << "Skipping version accounting for unknown category " << cat_id << LL_ENDL; + } } - - // TODO - how can we use this version info? Need to be sure all - // changes are going through AIS first, or at least through - // something with a reliable responder. - for (uuid_int_map_t::iterator ucv_it = mCatVersions.begin(); - ucv_it != mCatVersions.end(); ++ucv_it) + + // CREATE CATEGORIES + for (deferred_category_map_t::const_iterator create_it = mCategoriesCreated.begin(); + create_it != mCategoriesCreated.end(); ++create_it) { - const LLUUID id = ucv_it->first; - S32 version = ucv_it->second; - LLViewerInventoryCategory *cat = gInventory.getCategory(id); - if (cat->getVersion() != version) + LLUUID category_id(create_it->first); + LLPointer new_category = create_it->second; + + gInventory.updateCategory(new_category); + LL_DEBUGS("Inventory") << "created category " << category_id << LL_ENDL; + } + + // UPDATE CATEGORIES + for (deferred_category_map_t::const_iterator update_it = mCategoriesUpdated.begin(); + update_it != mCategoriesUpdated.end(); ++update_it) + { + LLUUID category_id(update_it->first); + LLPointer new_category = update_it->second; + // Since this is a copy of the category *before* the accounting update, above, + // we need to transfer back the updated version/descendent count. + LLViewerInventoryCategory* curr_cat = gInventory.getCategory(new_category->getUUID()); + if (NULL == curr_cat) { - llwarns << "Possible version mismatch for category " << cat->getName() - << ", viewer version " << cat->getVersion() - << " server version " << version << llendl; + LL_WARNS("Inventory") << "Failed to update unknown category " << new_category->getUUID() << LL_ENDL; + } + else + { + new_category->setVersion(curr_cat->getVersion()); + new_category->setDescendentCount(curr_cat->getDescendentCount()); + gInventory.updateCategory(new_category); + LL_DEBUGS("Inventory") << "updated category " << category_id << LL_ENDL; } } @@ -456,7 +775,7 @@ void AISUpdate::doUpdate() // FIXME risky function since it calls updateServer() in some // cases. Maybe break out the update/create cases, in which // case this is create. - LL_DEBUGS("Inventory") << "created item " << item_id << llendl; + LL_DEBUGS("Inventory") << "created item " << item_id << LL_ENDL; gInventory.updateItem(new_item); } @@ -469,19 +788,36 @@ void AISUpdate::doUpdate() // FIXME risky function since it calls updateServer() in some // cases. Maybe break out the update/create cases, in which // case this is update. - LL_DEBUGS("Inventory") << "updated item " << item_id << llendl; - //LL_DEBUGS("Inventory") << ll_pretty_print_sd(new_item->asLLSD()) << llendl; + LL_DEBUGS("Inventory") << "updated item " << item_id << LL_ENDL; + //LL_DEBUGS("Inventory") << ll_pretty_print_sd(new_item->asLLSD()) << LL_ENDL; gInventory.updateItem(new_item); } // DELETE OBJECTS - for (std::set::const_iterator del_it = mObjectsDeleted.begin(); - del_it != mObjectsDeleted.end(); ++del_it) + for (std::set::const_iterator del_it = mObjectsDeletedIds.begin(); + del_it != mObjectsDeletedIds.end(); ++del_it) { - LL_DEBUGS("Inventory") << "deleted item " << *del_it << llendl; + LL_DEBUGS("Inventory") << "deleted item " << *del_it << LL_ENDL; gInventory.onObjectDeletedFromServer(*del_it, false, false, false); } + // TODO - how can we use this version info? Need to be sure all + // changes are going through AIS first, or at least through + // something with a reliable responder. + for (uuid_int_map_t::iterator ucv_it = mCatVersionsUpdated.begin(); + ucv_it != mCatVersionsUpdated.end(); ++ucv_it) + { + const LLUUID id = ucv_it->first; + S32 version = ucv_it->second; + LLViewerInventoryCategory *cat = gInventory.getCategory(id); + if (cat->getVersion() != version) + { + llwarns << "Possible version mismatch for category " << cat->getName() + << ", viewer version " << cat->getVersion() + << " server version " << version << llendl; + } + } + gInventory.notifyObservers(); } -- cgit v1.2.3 From a428acf331dc63b2d6bac10101a8339e91a73adc Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 16 Jul 2013 17:08:24 -0400 Subject: SH-4333 FIX - turned on category patch now that AISv3 has it --- indra/newview/llaisapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index cb8700865a..9389aeb3b4 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -794,7 +794,7 @@ void AISUpdate::doUpdate() } // DELETE OBJECTS - for (std::set::const_iterator del_it = mObjectsDeletedIds.begin(); + for (uuid_list_t::const_iterator del_it = mObjectsDeletedIds.begin(); del_it != mObjectsDeletedIds.end(); ++del_it) { LL_DEBUGS("Inventory") << "deleted item " << *del_it << LL_ENDL; -- cgit v1.2.3 From 28a5015074e3f6e0ba961dc260edcb9662e6f14b Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 22 Jul 2013 17:07:45 -0400 Subject: SH-4333 WIP - do version accounting for category when updated --- indra/newview/llaisapi.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 9389aeb3b4..f8c9447b17 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -548,6 +548,8 @@ void AISUpdate::parseCategory(const LLSD& category_map) // delta to be created if it does not already exist; // otherwise has no effect. mCatDescendentDeltas[new_cat->getParentUUID()]; + // Capture update for the category itself as well. + mCatDescendentDeltas[category_id]; } else { @@ -699,6 +701,8 @@ void AISUpdate::doUpdate() for (std::map::const_iterator catit = mCatDescendentDeltas.begin(); catit != mCatDescendentDeltas.end(); ++catit) { + LL_DEBUGS("Inventory") << "descendent accounting for " << catit->first << llendl; + const LLUUID cat_id(catit->first); // Don't account for update if we just created this category. if (mCategoriesCreated.find(cat_id) != mCategoriesCreated.end()) @@ -720,7 +724,8 @@ void AISUpdate::doUpdate() { S32 descendent_delta = catit->second; S32 old_count = cat->getDescendentCount(); - LL_DEBUGS("Inventory") << "Updating descendent count for " << cat_id + LL_DEBUGS("Inventory") << "Updating descendent count for " + << cat->getName() << " " << cat_id << " with delta " << descendent_delta << " from " << old_count << " to " << (old_count+descendent_delta) << LL_ENDL; LLInventoryModel::LLCategoryUpdate up(cat_id, descendent_delta); @@ -761,7 +766,7 @@ void AISUpdate::doUpdate() new_category->setVersion(curr_cat->getVersion()); new_category->setDescendentCount(curr_cat->getDescendentCount()); gInventory.updateCategory(new_category); - LL_DEBUGS("Inventory") << "updated category " << category_id << LL_ENDL; + LL_DEBUGS("Inventory") << "updated category " << new_category->getName() << " " << category_id << LL_ENDL; } } -- cgit v1.2.3 From c1af1a692a6bd0f3cdfb3f49cc2451717481b685 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Fri, 9 Aug 2013 14:52:54 -0700 Subject: Routing link creating through AISv3 when available. --- indra/newview/llaisapi.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index f8c9447b17..73aaebc050 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -100,20 +100,9 @@ void AISCommand::httpSuccess() /*virtual*/ void AISCommand::httpFailure() { - const LLSD& content = getContent(); + LL_WARNS("Inventory") << dumpResponse() << LL_ENDL; S32 status = getStatus(); - const std::string& reason = getReason(); const LLSD& headers = getResponseHeaders(); - if (!content.isMap()) - { - LL_DEBUGS("Inventory") << "Malformed response contents " << content - << " status " << status << " reason " << reason << LL_ENDL; - } - else - { - LL_DEBUGS("Inventory") << "failed with content: " << ll_pretty_print_sd(content) - << " status " << status << " reason " << reason << LL_ENDL; - } mRetryPolicy->onFailure(status, headers); F32 seconds_to_wait; if (mRetryPolicy->shouldRetry(seconds_to_wait)) @@ -276,6 +265,30 @@ UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& item_id, setCommandFunc(cmd); } +CreateInventoryCommand::CreateInventoryCommand(const LLUUID& parent_id, + const LLSD& new_inventory, + LLPointer callback): + mNewInventory(new_inventory), + AISCommand(callback) +{ + std::string cap; + if (!getInvCap(cap)) + { + llwarns << "No cap found" << llendl; + return; + } + LLUUID tid; + tid.generate(); + std::string url = cap + std::string("/category/") + parent_id.asString() + "?tid=" + tid.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + LLCurl::ResponderPtr responder = this; + LLSD headers; + headers["Content-Type"] = "application/llsd+xml"; + F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + command_func_type cmd = boost::bind(&LLHTTPClient::post, url, mNewInventory, responder, headers, timeout); + setCommandFunc(cmd); +} + SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer callback): mContents(contents), AISCommand(callback) -- cgit v1.2.3 From 6128cd9f705ca5565cafbe4b969c767b138cd1f6 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 12 Aug 2013 13:45:51 -0400 Subject: cat version debug statement --- indra/newview/llaisapi.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index f8c9447b17..e710df4920 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -815,6 +815,7 @@ void AISUpdate::doUpdate() const LLUUID id = ucv_it->first; S32 version = ucv_it->second; LLViewerInventoryCategory *cat = gInventory.getCategory(id); + LL_DEBUGS("Inventory") << "cat version update " << cat->getName() << " to version " << cat->getVersion() << llendl; if (cat->getVersion() != version) { llwarns << "Possible version mismatch for category " << cat->getName() -- cgit v1.2.3 From f878b032e8c96c4e4ae752864d7641bba2ea4102 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Mon, 9 Sep 2013 13:13:22 -0700 Subject: Using transaction_id instead of raw asset_id during aisv3 patch --- indra/newview/llaisapi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 85b304d90e..6f6e6ebb35 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -243,7 +243,7 @@ UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, setCommandFunc(cmd); } -UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& item_id, +UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& cat_id, const LLSD& updates, LLPointer callback): mUpdates(updates), @@ -255,7 +255,7 @@ UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& item_id, llwarns << "No cap found" << llendl; return; } - std::string url = cap + std::string("/category/") + item_id.asString(); + std::string url = cap + std::string("/category/") + cat_id.asString(); LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; -- cgit v1.2.3 From c2ddc68afe0d9f122ee846ec1de1b4394f04998f Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Tue, 17 Sep 2013 22:30:02 -0700 Subject: Updating AISv3 api to match recent changes --- indra/newview/llaisapi.cpp | 60 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 6f6e6ebb35..14978662f6 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -602,29 +602,37 @@ void AISUpdate::parseCategory(const LLSD& category_map) void AISUpdate::parseDescendentCount(const LLUUID& category_id, const LLSD& embedded) { // We can only determine true descendent count if this contains all descendent types. - if (embedded.has("category") && - embedded.has("link") && - embedded.has("item")) + if (embedded.has("categories") && + embedded.has("links") && + embedded.has("items")) { - mCatDescendentsKnown[category_id] = embedded["category"].size(); - mCatDescendentsKnown[category_id] += embedded["link"].size(); - mCatDescendentsKnown[category_id] += embedded["item"].size(); + mCatDescendentsKnown[category_id] = embedded["categories"].size(); + mCatDescendentsKnown[category_id] += embedded["links"].size(); + mCatDescendentsKnown[category_id] += embedded["items"].size(); } } void AISUpdate::parseEmbedded(const LLSD& embedded) { - if (embedded.has("link")) + if (embedded.has("links")) // _embedded in a category { - parseEmbeddedLinks(embedded["link"]); + parseEmbeddedLinks(embedded["links"]); } - if (embedded.has("item")) + if (embedded.has("items")) // _embedded in a category { - parseEmbeddedItems(embedded["item"]); + parseEmbeddedItems(embedded["items"]); } - if (embedded.has("category")) + if (embedded.has("item")) // _embedded in a link { - parseEmbeddedCategories(embedded["category"]); + parseEmbeddedItem(embedded["item"]); + } + if (embedded.has("categories")) // _embedded in a category + { + parseEmbeddedCategories(embedded["categories"]); + } + if (embedded.has("category")) // _embedded in a link + { + parseEmbeddedCategory(embedded["category"]); } } @@ -660,18 +668,21 @@ void AISUpdate::parseEmbeddedLinks(const LLSD& links) } } -void AISUpdate::parseEmbeddedItems(const LLSD& items) +void AISUpdate::parseEmbeddedItem(const LLSD& item) { - // Special case: this may be a single item (_embedded in a link) - if (items.has("item_id")) + // a single item (_embedded in a link) + if (item.has("item_id")) { - if (mItemIds.end() != mItemIds.find(items["item_id"].asUUID())) + if (mItemIds.end() != mItemIds.find(item["item_id"].asUUID())) { - parseContent(items); + parseItem(item); } - return; } +} +void AISUpdate::parseEmbeddedItems(const LLSD& items) +{ + // a map of items (_embedded in a category) for(LLSD::map_const_iterator itemit = items.beginMap(), itemend = items.endMap(); itemit != itemend; ++itemit) @@ -689,8 +700,21 @@ void AISUpdate::parseEmbeddedItems(const LLSD& items) } } +void AISUpdate::parseEmbeddedCategory(const LLSD& category) +{ + // a single category (_embedded in a link) + if (category.has("category_id")) + { + if (mCategoryIds.end() != mCategoryIds.find(category["category_id"].asUUID())) + { + parseCategory(category); + } + } +} + void AISUpdate::parseEmbeddedCategories(const LLSD& categories) { + // a map of categories (_embedded in a category) for(LLSD::map_const_iterator categoryit = categories.beginMap(), categoryend = categories.endMap(); categoryit != categoryend; ++categoryit) -- cgit v1.2.3 From c0d780cb4473c02e885c67fbc1bc30e87536d1b8 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Mon, 25 Nov 2013 16:52:58 -0500 Subject: SH-4613 WIP - add CREATE mask bit for newly created items in AISUpdate::doUpdate() - needed for some inventory observers. --- indra/newview/llaisapi.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 14978662f6..38eb34676e 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -33,6 +33,7 @@ #include "llinventorymodel.h" #include "llsdutil.h" #include "llviewerregion.h" +#include "llinventoryobserver.h" ///---------------------------------------------------------------------------- /// Classes for AISv3 support. @@ -781,7 +782,7 @@ void AISUpdate::doUpdate() LLUUID category_id(create_it->first); LLPointer new_category = create_it->second; - gInventory.updateCategory(new_category); + gInventory.updateCategory(new_category, LLInventoryObserver::CREATE); LL_DEBUGS("Inventory") << "created category " << category_id << LL_ENDL; } @@ -818,7 +819,7 @@ void AISUpdate::doUpdate() // cases. Maybe break out the update/create cases, in which // case this is create. LL_DEBUGS("Inventory") << "created item " << item_id << LL_ENDL; - gInventory.updateItem(new_item); + gInventory.updateItem(new_item, LLInventoryObserver::CREATE); } // UPDATE ITEMS -- cgit v1.2.3 From 487ca1bad37883be0325b564ab557a8f77575388 Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Wed, 14 May 2014 17:50:59 -0400 Subject: v-r -> s-e merge WIP --- indra/newview/llaisapi.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 38eb34676e..da66ea357a 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -171,7 +171,7 @@ RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } std::string url = cap + std::string("/item/") + item_id.asString(); @@ -190,7 +190,7 @@ RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } std::string url = cap + std::string("/category/") + item_id.asString(); @@ -209,7 +209,7 @@ PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; @@ -230,7 +230,7 @@ UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } std::string url = cap + std::string("/item/") + item_id.asString(); @@ -253,7 +253,7 @@ UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& cat_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } std::string url = cap + std::string("/category/") + cat_id.asString(); @@ -275,7 +275,7 @@ CreateInventoryCommand::CreateInventoryCommand(const LLUUID& parent_id, std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } LLUUID tid; @@ -297,13 +297,13 @@ SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& conten std::string cap; if (!getInvCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } LLUUID tid; tid.generate(); std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); - llinfos << url << llendl; + LL_INFOS() << url << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; headers["Content-Type"] = "application/llsd+xml"; @@ -320,14 +320,14 @@ CopyLibraryCategoryCommand::CopyLibraryCategoryCommand(const LLUUID& source_id, std::string cap; if (!getLibCap(cap)) { - llwarns << "No cap found" << llendl; + LL_WARNS() << "No cap found" << LL_ENDL; return; } LL_DEBUGS("Inventory") << "Copying library category: " << source_id << " => " << dest_id << LL_ENDL; LLUUID tid; tid.generate(); std::string url = cap + std::string("/category/") + source_id.asString() + "?tid=" + tid.asString(); - llinfos << url << llendl; + LL_INFOS() << url << LL_ENDL; LLCurl::ResponderPtr responder = this; LLSD headers; F32 timeout = HTTP_REQUEST_EXPIRY_SECS; @@ -482,7 +482,7 @@ void AISUpdate::parseItem(const LLSD& item_map) else { // *TODO: Wow, harsh. Should we just complain and get out? - llerrs << "unpack failed" << llendl; + LL_ERRS() << "unpack failed" << LL_ENDL; } } @@ -524,7 +524,7 @@ void AISUpdate::parseLink(const LLSD& link_map) else { // *TODO: Wow, harsh. Should we just complain and get out? - llerrs << "unpack failed" << llendl; + LL_ERRS() << "unpack failed" << LL_ENDL; } } @@ -590,7 +590,7 @@ void AISUpdate::parseCategory(const LLSD& category_map) else { // *TODO: Wow, harsh. Should we just complain and get out? - llerrs << "unpack failed" << llendl; + LL_ERRS() << "unpack failed" << LL_ENDL; } // Check for more embedded content. @@ -739,7 +739,7 @@ void AISUpdate::doUpdate() for (std::map::const_iterator catit = mCatDescendentDeltas.begin(); catit != mCatDescendentDeltas.end(); ++catit) { - LL_DEBUGS("Inventory") << "descendent accounting for " << catit->first << llendl; + LL_DEBUGS("Inventory") << "descendent accounting for " << catit->first << LL_ENDL; const LLUUID cat_id(catit->first); // Don't account for update if we just created this category. @@ -853,12 +853,12 @@ void AISUpdate::doUpdate() const LLUUID id = ucv_it->first; S32 version = ucv_it->second; LLViewerInventoryCategory *cat = gInventory.getCategory(id); - LL_DEBUGS("Inventory") << "cat version update " << cat->getName() << " to version " << cat->getVersion() << llendl; + LL_DEBUGS("Inventory") << "cat version update " << cat->getName() << " to version " << cat->getVersion() << LL_ENDL; if (cat->getVersion() != version) { - llwarns << "Possible version mismatch for category " << cat->getName() + LL_WARNS() << "Possible version mismatch for category " << cat->getName() << ", viewer version " << cat->getVersion() - << " server version " << version << llendl; + << " server version " << version << LL_ENDL; } } -- cgit v1.2.3