예제 #1
0
void feed::load_state(lazy_entry const& rd)
{
	load_struct(rd, this, feed_map, sizeof(feed_map)/sizeof(feed_map[0]));
	lazy_entry const* e = rd.dict_find_list("items");
	if (e)
	{
		m_items.reserve(e->list_size());
		for (int i = 0; i < e->list_size(); ++i)
		{
			if (e->list_at(i)->type() != lazy_entry::dict_t) continue;
			m_items.push_back(feed_item());
			load_struct(*e->list_at(i), &m_items.back(), feed_item_map
				, sizeof(feed_item_map)/sizeof(feed_item_map[0]));

			// don't load duplicates
			if (m_urls.find(m_items.back().url) != m_urls.end())
			{
				m_items.pop_back();
				continue;
			}
			m_urls.insert(m_items.back().url);
		}
	}
	load_struct(rd, &m_settings, feed_settings_map
		, sizeof(feed_settings_map)/sizeof(feed_settings_map[0]));
	e = rd.dict_find_dict("add_params");
	if (e)
	{
		load_struct(*e, &m_settings.add_args, add_torrent_map
			, sizeof(add_torrent_map)/sizeof(add_torrent_map[0]));
	}

	e = rd.dict_find_list("history");
	if (e)
	{
		for (int i = 0; i < e->list_size(); ++i)
		{
			if (e->list_at(i)->type() != lazy_entry::list_t) continue;

			lazy_entry const* item = e->list_at(i);

			if (item->list_size() != 2
				|| item->list_at(0)->type() != lazy_entry::string_t
				|| item->list_at(1)->type() != lazy_entry::int_t)
				continue;

			m_added.insert(std::pair<std::string, time_t>(
				item->list_at(0)->string_value()
				, item->list_at(1)->int_value()));
		}
	}
}
예제 #2
0
	bool default_storage::verify_resume_data(lazy_entry const& rd, error_code& error)
	{
		lazy_entry const* file_priority = rd.dict_find_list("file_priority");
		if (file_priority && file_priority->list_size()
			== files().num_files())
		{
			m_file_priority.resize(file_priority->list_size());
			for (int i = 0; i < file_priority->list_size(); ++i)
				m_file_priority[i] = boost::uint8_t(file_priority->list_int_value_at(i, 1));
		}


		bool seed = false;
		
        if (lazy_entry const* pieces = rd.dict_find_string("pieces"))
		{
			if (int(pieces->string_length()) == m_files.num_pieces())
			{
				seed = true;
				char const* p = pieces->string_ptr();
				for (int i = 0; i < pieces->string_length(); ++i)
				{
					if ((p[i] & 1) == 1) continue;
					seed = false;
					break;
				}
			}
		}
		else
		{
			error = errors::missing_pieces;
			return false;
		}

        int flags = (settings().ignore_resume_timestamps ? ignore_timestamps : 0);

        return true;

	}