void completedRaw(
		const LLChannelDescriptors& channels,
		const LLIOPipe::buffer_ptr_t& buffer)
	{
		completedHeader();

		if (!isGoodStatus())
		{
			if (getStatus() == HTTP_NOT_MODIFIED)
			{
				LL_INFOS("fsdata") << "Got [304] not modified for " << mURL << LL_ENDL;
			}
			else
			{
				LL_WARNS("fsdata") << "Error fetching " << mURL << " Status: [" << getStatus() << "]" << LL_ENDL;
			}
			return;
		}

		S32 data_size = buffer->countAfter(channels.in(), NULL);
		if (data_size <= 0)
		{
			LL_WARNS("fsdata") << "Received zero data for " << mURL << LL_ENDL;
			return;
		}

		U8* data = new U8[data_size];
		buffer->readAfter(channels.in(), NULL, data, data_size);

		// basic check for valid data received
		LLXMLNodePtr xml_root;
		if ( (!LLXMLNode::parseBuffer(data, data_size, xml_root, NULL)) || (xml_root.isNull()) || (!xml_root->hasName("script_library")) )
		{
			LL_WARNS("fsdata") << "Could not read the script library data from "<< mURL << LL_ENDL;
			delete[] data;
			data = NULL;
			return;
		}
		
		LLAPRFile outfile ;
		outfile.open(mFilename, LL_APR_WB);
		if (!outfile.getFileHandle())
		{
			LL_WARNS("fsdata") << "Unable to open file for writing: " << mFilename << LL_ENDL;
		}
		else
		{
			LL_INFOS("fsdata") << "Saving " << mFilename << LL_ENDL;
			outfile.write(data, data_size);
			outfile.close() ;
		}
		delete[] data;
		data = NULL;
	}
void EmeraldDicDownloader::completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer)
{
	if (status < 200 || status >= 300)
	{
		return;
	}
	LLBufferStream istr(channels, buffer.get());
	std::string dicpath(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", name.c_str()));

	llofstream ostr(dicpath, std::ios::binary);

	while (istr.good() && ostr.good())
	{
		ostr << istr.rdbuf();
	}
	ostr.close();
	if (panel)
	{
        if (panel->empanel)
        {
    		panel->empanel->refresh();
        }
        else
        {
            llinfos << "completedRaw(): No empanel to refresh()!" << llendl;
        }

		panel->close();
	}
}
void exoFlickrResponse::completedRaw(
									U32 status,
									const std::string& reason,
									const LLChannelDescriptors& channels,
									const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	std::stringstream strstrm;
	strstrm << istr.rdbuf();
	std::string result = strstrm.str();
	Json::Value root;
	Json::Reader reader;

	bool success = reader.parse(result, root);
	if(!success)
	{
		mCallback(false, LLSD());
		return;
	}
	else
	{
		LL_INFOS("FlickrAPI") << "Got response string: " << result << LL_ENDL;
		LLSD response;
		JsonToLLSD(root, response);
		mCallback(isGoodStatus(status), response);
	}
}
示例#4
0
	virtual void completedRaw(U32 status,
				const std::string& reason,
				const LLChannelDescriptors& channels,
				const LLIOPipe::buffer_ptr_t& buffer)
	{
		if (!isGoodStatus(status))
		{
			llinfos << mURL << " [" << status << "]: " << reason << llendl;
			if (mURL == legacy_client_list)
			{
				LL_WARNS("ClientTags") << "client_list_v2.xml download failed with status of " << status << LL_ENDL;
				// Wolfspirit: If something failes, try to use the local file
				FSData::getInstance()->updateClientTagsLocal();
			}
			return;
		}
	  
		LLSD content;
		LLBufferStream istr(channels, buffer.get());
		if (!LLSDSerialize::fromXML(content, istr))
		{
			llinfos << "Failed to deserialize LLSD. " << mURL << " [" << status << "]: " << reason << llendl;
			if (mURL == legacy_client_list)
			{
				LL_WARNS("ClientTags") << "Downloaded client_list_v2.xml decode failed." << LL_ENDL;
				// Wolfspirit: If something failes, try to use the local file
				FSData::getInstance()->updateClientTagsLocal();
			}
			return;
		}
		
		FSData::getInstance()->processResponder(content, mURL);
	}
示例#5
0
	/// Overrides the default LLSD parsing behaviour, to allow parsing a JSON response.
	virtual void completedRaw(U32 status, const std::string& reason,
							  const LLChannelDescriptors& channels,
							  const LLIOPipe::buffer_ptr_t& buffer)
	{
/*
		 // Dump the body, for debugging.

		 LLBufferStream istr1(channels, buffer.get());
		 std::ostringstream ostr;
		 std::string body;

		 while (istr1.good())
		 {
			char buf[1024];
			istr1.read(buf, sizeof(buf));
			body.append(buf, istr1.gcount());
		 }
		 LL_DEBUGS("WebSharing") << body << LL_ENDL;
*/
		LLSD content;
		LLBufferStream istr(channels, buffer.get());
		LLPointer<LLSDParser> parser = new LLSDNotationParser();

		if (parser->parse(istr, content, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
		{
			LL_WARNS("WebSharing") << "Failed to deserialize LLSD from JSON response. " << " [" << status << "]: " << reason << LL_ENDL;
		}
		else
		{
			completed(status, reason, content);
		}
	}
示例#6
0
void exoFlickrAuthResponse::completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	std::ostringstream oss;
	oss << istr.rdbuf();
	std::string str = oss.str();
	LLSD result = LLURI::queryMap(str);
	mCallback((status == 200), result);
}
void exoFlickrUploadResponse::completedRaw(
										  U32 status,
										  const std::string& reason,
										  const LLChannelDescriptors& channels,
										  const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	std::stringstream strstrm;
	strstrm << istr.rdbuf();
	std::string result = std::string(strstrm.str());

	LLSD output;
	bool success;

	LLXmlTree tree;
	if(!tree.parseString(result))
	{
		LL_WARNS("FlickrAPI") << "Couldn't parse flickr response(" << status << "): " << result << LL_ENDL;
		mCallback(false, LLSD());
		return;
	}
	LLXmlTreeNode* root = tree.getRoot();
	if(!root->hasName("rsp"))
	{
		LL_WARNS("FlickrAPI") << "Bad root node: " << root->getName() << LL_ENDL;
		mCallback(false, LLSD());
		return;
	}
	std::string stat;
	root->getAttributeString("stat", stat);
	output["stat"] = stat;
	if(stat == "ok")
	{
		success = true;
		LLXmlTreeNode* photoid_node = root->getChildByName("photoid");
		if(photoid_node)
		{
			output["photoid"] = photoid_node->getContents();
		}
	}
	else
	{
		success = false;
		LLXmlTreeNode* err_node = root->getChildByName("err");
		if(err_node)
		{
			S32 code;
			std::string msg;
			err_node->getAttributeS32("code", code);
			err_node->getAttributeString("msg", msg);
			output["code"] = code;
			output["msg"] = msg;
		}
	}
	mCallback(success, output);
}
示例#8
0
文件: llcurl.cpp 项目: Boy/rainbow
// virtual
void LLCurl::Responder::completedRaw(
	U32 status,
	const std::string& reason,
	const LLChannelDescriptors& channels,
	const LLIOPipe::buffer_ptr_t& buffer)
{
	LLSD content;
	LLBufferStream istr(channels, buffer.get());
	LLSDSerialize::fromXML(content, istr);
	completed(status, reason, content);
}
示例#9
0
void ModularSystemsDownloader::completedRaw(
			U32 status,
			const std::string& reason,
			const LLChannelDescriptors& channels,
			const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	std::stringstream strstrm;
	strstrm << istr.rdbuf();
	std::string result = std::string(strstrm.str());
	mCallback(status, result);
}
示例#10
0
文件: llcurl.cpp 项目: Kiera/Crow
// virtual
void LLCurl::Responder::completedRaw(
	U32 status,
	const std::string& reason,
	const LLChannelDescriptors& channels,
	const LLIOPipe::buffer_ptr_t& buffer)
{
	LLSD content;
	LLBufferStream istr(channels, buffer.get());
	if (!LLSDSerialize::fromXML(content, istr))
	{
		llinfos << "Failed to deserialize LLSD. " << mURL << " [" << status << "]: " << reason << llendl;
	}
	completed(status, reason, content);
}
示例#11
0
	/*virtual*/ void completedRaw(
		U32 status,
		const std::string& reason,
		const LLChannelDescriptors& channels,
		const LLIOPipe::buffer_ptr_t& buffer)
	{
		LLBufferStream istr(channels, buffer.get());
		std::stringstream strstrm;
		strstrm << istr.rdbuf();
		const std::string body = strstrm.str();

		if (status != 200)
		{
			llwarns << "Failed to get upload config (" << status << ")" << llendl;
			LLWebProfile::reportImageUploadStatus(false);
			return;
		}

		Json::Value root;
		Json::Reader reader;
		if (!reader.parse(body, root))
		{
			llwarns << "Failed to parse upload config: " << reader.getFormatedErrorMessages() << llendl;
			LLWebProfile::reportImageUploadStatus(false);
			return;
		}

		// *TODO: 404 = not supported by the grid
		// *TODO: increase timeout or handle 499 Expired

		// Convert config to LLSD.
		const Json::Value data = root["data"];
		const std::string upload_url = root["url"].asString();
		LLSD config;
		config["acl"]						= data["acl"].asString();
		config["AWSAccessKeyId"]			= data["AWSAccessKeyId"].asString();
		config["Content-Type"]				= data["Content-Type"].asString();
		config["key"]						= data["key"].asString();
		config["policy"]					= data["policy"].asString();
		config["success_action_redirect"]	= data["success_action_redirect"].asString();
		config["signature"]					= data["signature"].asString();
		config["add_loc"]					= data.get("add_loc", "0").asString();
		config["caption"]					= data.get("caption", "").asString();

		// Do the actual image upload using the configuration.
		LL_DEBUGS("Snapshots") << "Got upload config, POSTing image to " << upload_url << ", config=[" << config << "]" << llendl;
		LLWebProfile::post(mImagep, config, upload_url);
	}
示例#12
0
	// the grid info is no LLSD *sigh* ... override the default LLSD parsing behaviour 
	virtual  void completedRaw(U32 status, const std::string& reason,
									const LLChannelDescriptors& channels,
									const LLIOPipe::buffer_ptr_t& buffer)
	{
		mOwner->decResponderCount();
		LL_DEBUGS("GridManager") << mData->grid[GRID_VALUE] << " status: " << status << " reason: " << reason << llendl;
		if(LLGridManager::TRYLEGACY == mState && 200 == status)
		{
			mOwner->addGrid(mData, LLGridManager::SYSTEM);
		}
		else if (200 == status)// OK
		{
			LL_DEBUGS("GridManager") << "Parsing gridinfo xml file from "
				<< mData->grid[GRID_VALUE] << LL_ENDL;

			LLBufferStream istr(channels, buffer.get());
			if(LLXMLNode::parseStream( istr, mData->info_root, NULL))
			{
				mOwner->gridInfoResponderCB(mData);
			}
			else
			{
				LLSD args;
				args["GRID"] = mData->grid[GRID_VALUE];
				//Could not add [GRID] to the grid list.
				args["REASON"] = "Server provided broken grid info xml. Please";
				//[REASON] contact support of [GRID].
				LLNotificationsUtil::add("CantAddGrid", args);

				llwarns << " Could not parse grid info xml from server."
					<< mData->grid[GRID_VALUE] << " skipping." << llendl;
				mOwner->addGrid(mData, LLGridManager::FAIL);
			}
		}
		else if (304 == status && !LLGridManager::TRYLEGACY == mState)// not modified
		{
			mOwner->addGrid(mData, LLGridManager::FINISH);
		}
		else if (499 == status && LLGridManager::LOCAL == mState) //add localhost even if its not up
		{
			mOwner->addGrid(mData,	LLGridManager::FINISH);
			//since we know now that its not up we cold also start it
		}
		else
		{
			error(status, reason);
		}
	}
示例#13
0
	/// Overrides the default LLSD parsing behaviour, to allow parsing a JSON response.
	virtual void completedRaw(U32 status, const std::string& reason,
							  const LLChannelDescriptors& channels,
							  const LLIOPipe::buffer_ptr_t& buffer)
	{
		LLSD content;
		LLBufferStream istr(channels, buffer.get());
		LLPointer<LLSDParser> parser = new LLSDNotationParser();

		if (parser->parse(istr, content, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
		{
			LL_WARNS("WebSharing") << "Failed to deserialize LLSD from JSON response. " << " [" << status << "]: " << reason << LL_ENDL;
		}
		else
		{
			completed(status, reason, content);
		}
	}
// virtual
void LLCurl::Responder::completedRaw(
	const LLChannelDescriptors& channels,
	const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	const bool emit_parse_errors = false;

	// <Techwolf Lupindo> pass parse error down code path
	mDeserializeError = false;

	std::string debug_body("(empty)");
	bool parsed=true;
	if (EOF == istr.peek())
	{
		parsed=false;
	}
	// Try to parse body as llsd, no matter what 'content-type' says.
	else if (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXML(mContent, istr, emit_parse_errors))
	{
		parsed=false;
		char body[1025]; 
		body[1024] = '\0';
		istr.seekg(0, std::ios::beg);
		istr.get(body,1024);
		if (strlen(body) > 0)
		{
			mContent = body;
			debug_body = body;
		}
		// <Techwolf Lupindo> pass parse error down code path
		mDeserializeError = true;
	}

	// Only emit a warning if we failed to parse when 'content-type' == 'application/llsd+xml'
	if (!parsed && (HTTP_CONTENT_LLSD_XML == getResponseHeader(HTTP_IN_HEADER_CONTENT_TYPE)))
	{
		LL_WARNS() << "Failed to deserialize . " << mURL << " [status:" << mStatus << "] " 
			<< "(" << mReason << ") body: " << debug_body << LL_ENDL;
	}

	httpCompleted();
}
示例#15
0
	/*virtual*/ void completedRaw(
		U32 status,
		const std::string& reason,
		const LLChannelDescriptors& channels,
		const LLIOPipe::buffer_ptr_t& buffer)
	{
		if (status != 200)
		{
			llwarns << "Failed to upload image: " << status << " " << reason << llendl;
			LLWebProfile::reportImageUploadStatus(false);
			return;
		}

		LLBufferStream istr(channels, buffer.get());
		std::stringstream strstrm;
		strstrm << istr.rdbuf();
		const std::string body = strstrm.str();
		llinfos << "Image uploaded." << llendl;
		LL_DEBUGS("Snapshots") << "Uploading image succeeded. Response: [" << body << "]" << llendl;
		LLWebProfile::reportImageUploadStatus(true);
	}
示例#16
0
// virtual
void LLTranslate::TranslationReceiver::completedRaw(
	U32 http_status,
	const std::string& reason,
	const LLChannelDescriptors& channels,
	const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	std::stringstream strstrm;
	strstrm << istr.rdbuf();

	const std::string body = strstrm.str();
	std::string translation, detected_lang, err_msg;
	int status = http_status;
	LL_DEBUGS("Translate") << "HTTP status: " << status << " " << reason << LL_ENDL;
	LL_DEBUGS("Translate") << "Response body: " << body << LL_ENDL;
	if (mHandler.parseResponse(status, body, translation, detected_lang, err_msg))
	{
		// Fix up the response
		LLStringUtil::replaceString(translation, "&lt;", "<");
		LLStringUtil::replaceString(translation, "&gt;",">");
		LLStringUtil::replaceString(translation, "&quot;","\"");
		LLStringUtil::replaceString(translation, "&#39;","'");
		LLStringUtil::replaceString(translation, "&amp;","&");
		LLStringUtil::replaceString(translation, "&apos;","'");

		handleResponse(translation, detected_lang);
	}
	else
	{
		if (err_msg.empty())
		{
			err_msg = LLTrans::getString("TranslationResponseParseError");
		}

		llwarns << "Translation request failed: " << err_msg << llendl;
		handleFailure(status, err_msg);
	}
}