summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2014-05-05 09:03:53 -0700
committerMerov Linden <merov@lindenlab.com>2014-05-05 09:03:53 -0700
commit5000749f6ba13448f13927dc778bef3f54260f31 (patch)
treef5dc02cc1dd06c01bc14dbf8560a8d0092689357
parenteeeacd3c5f5ae29c5d13cd8cfd983e4308882b41 (diff)
DD-22 : WIP : Clean up json code and test Json::Writer
-rwxr-xr-xindra/newview/llmarketplacefunctions.cpp87
1 files changed, 29 insertions, 58 deletions
diff --git a/indra/newview/llmarketplacefunctions.cpp b/indra/newview/llmarketplacefunctions.cpp
index 0db114b999..7dbd825d20 100755
--- a/indra/newview/llmarketplacefunctions.cpp
+++ b/indra/newview/llmarketplacefunctions.cpp
@@ -145,77 +145,38 @@ public:
LLSLMListingsResponder() {}
- virtual void completed(U32 status, const std::string& reason, const LLSD& content)
- {
- if (isGoodStatus(status))
- {
- llinfos << "Merov : completed successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
- // *TODO : Parse the Json body
- //LLMarketplaceData::instance().parseListings(content);
- }
- else
- {
- llinfos << "Merov : completed with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
- }
- }
-
virtual void completedRaw(U32 status,
const std::string& reason,
const LLChannelDescriptors& channels,
const LLIOPipe::buffer_ptr_t& buffer)
{
LLBufferStream istr(channels, buffer.get());
- LLSD content;
- // Merov : Absolutely godamn aweful parsing : this is to learn the rope
- /*
- std::ostringstream ostr;
- while (istr.good())
- {
- char buf[1024];
- istr.read(buf, sizeof(buf));
- ostr.write(buf, istr.gcount());
- }
- std::string local_string = ostr.str();
+ std::stringstream strstrm;
+ strstrm << istr.rdbuf();
+ const std::string body = strstrm.str();
+
+ if (!isGoodStatus(status))
+ {
+ std::string error_code = llformat("%d",status);
+ log_SLM_error("Get listings", status, reason, error_code, body);
+ return;
+ }
Json::Value root;
Json::Reader reader;
- if (!reader.parse(local_string,root))
- {
- // The message is not a Json string so it's a regular load url request
- llinfos << "Merov : Failed to parse the json string = " << local_string << llendl;
- }
- else
+ if (!reader.parse(body,root))
{
- // Extract the info from the Json string : just get the id for the first element in the list
- const int id = root["listings"][0u]["id"].asInt();
- //Json::Value listings = root["listings"];
- llinfos << "Merov : Parsed the json, string = " << local_string << llendl;
- llinfos << "Merov : Parsed the json, id = " << id << llendl;
+ log_SLM_error("Get listings", status, "Json parsing failed", reader.getFormatedErrorMessages(), body);
+ return;
}
- */
- // Merov : end parsing test
- // This will fail as json is not LLSD... To be deleted once we get the parsing right...
- const bool emit_errors = false;
- if (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXML(content, istr, emit_errors))
- {
- content["reason"] = reason;
- }
-
- completed(status, reason, content);
+ // Extract the info from the Json string : just get the id for the first element in the list
+ const int id = root["listings"][0u]["id"].asInt();
+ //Json::Value listings = root["listings"];
+ llinfos << "Merov : Parsed the json, string = " << body << llendl;
+ llinfos << "Merov : Parsed the json, id = " << id << llendl;
}
- void completedHeader(U32 status, const std::string& reason, const LLSD& content)
- {
- if (isGoodStatus(status))
- {
- llinfos << "Merov : completed header successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
- }
- else
- {
- llinfos << "Merov : completed header with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl;
- }
- }
};
class LLSLMCreateListingsResponder : public LLHTTPClient::Responder
@@ -821,7 +782,17 @@ void LLMarketplaceData::postSLMListing(const LLUUID& folder_id)
memcpy(data, body.str().data(), size);
std::string data_str = body.str();
- llinfos << "Merov : postSLMListing, body = " << data_str << ", header = " << headers << llendl;
+
+ Json::Value root;
+ Json::StyledWriter writer;
+
+ root["listing"]["name"] = category->getName();
+ root["listing"]["inventory_info"]["listing_folder_id"] = category->getUUID().asString();
+
+ std::string json_str = writer.write(root);
+
+ llinfos << "Merov : postSLMListing, test body = " << data_str << ", size = " << size << llendl;
+ llinfos << "Merov : postSLMListing, json body = " << json_str << ", size = " << json_str.size() << llendl;
// Send request
LLHTTPClient::postRaw(getSLMConnectURL("/listings"), data, size, new LLSLMCreateListingsResponder(), headers);