Ejemplo n.º 1
0
uint64
O2IPFilter::
ExportToXML(string &out)
{
	wstring xml;
	xml += L"<?xml version=\"1.0\" encoding=\"";
	xml += _T(DEFAULT_XML_CHARSET);
	xml += L"\"?>"EOL;
	xml += L"<ipf>"EOL;

	wstring message;
	wstring message_type;
	GetXMLMessage(message, message_type);

	xml += L" <message>";
	xml += message;
	xml += L"</message>"EOL;

	xml += L" <message_type>";
	xml += message_type;
	xml += L"</message_type>"EOL;

	xml += L"<type>";
	xml += name.c_str();
	xml += L"</type>"EOL;
	xml += L"<default>";
	xml += DefaultFlag == O2_ALLOW ? L"allow" : L"deny";
	xml += L"</default>"EOL;

	Lock();
	for (uint i = 0; i < records.size(); i++) {
		xml += L"<filter>"EOL;
		xml += L" <enable>";
		xml += records[i].enable ? L"true" : L"false";
		xml += L"</enable>"EOL;
		xml += L" <flag>";
		xml += records[i].flag == O2_ALLOW ? L"allow" : L"deny";
		xml += L"</flag>"EOL;
		xml += L" <cond>";
		xml += records[i].cond;
		xml += L"</cond>"EOL;
		xml += L"</filter>"EOL;
	}
	for (uint i = 0; i < 10; i++) {
		//dummy
		xml += L"<filter>"EOL;
		xml += L" <enable/>";
		xml += L" <flag/>";
		xml += L" <cond/>";
		xml += L"</filter>"EOL;
	}
	xml += L"</ipf>"EOL;
	Unlock();
	
	if (!FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out))
		return (0);

	return (records.size());
}
Ejemplo n.º 2
0
size_t
O2IMDB::
ExportToXML(O2IMSelectCondition &cond, string &out)
{
	wchar_t tmp[16];
	wstring xml;

	xml += L"<?xml version=\"1.0\" encoding=\"";
	xml += cond.charset;
	xml += L"\"?>" EOL;
	if (!cond.xsl.empty()) {
		xml += L"<?xml-stylesheet type=\"text/xsl\" href=\"";
		xml += cond.xsl;
		xml += L"\"?>" EOL;
	}
	xml	+= L"<messages>" EOL;

	if (cond.mask & IM_XMLELM_INFO) {
		xml += L"<info>" EOL;
		{
			xml += L" <count>";
			swprintf_s(tmp, 16, L"%d", Messages.size());
			xml += tmp;
			xml += L"</count>" EOL;

			xml += L" <sort>";
			xml += cond.sort;
			xml += L"</sort>" EOL;

			wstring message;
			wstring message_type;
			GetXMLMessage(message, message_type);

			xml += L" <message>";
			xml += message;
			xml += L"</message>" EOL;

			xml += L" <message_type>";
			xml += message_type;
			xml += L"</message_type>" EOL;
		}
		xml += L"</info>" EOL;
	}

	size_t out_count = 0;

	Lock();
	if (!cond.desc) {
		O2IMessages::iterator it;
		for (it = Messages.begin(); it != Messages.end(); it++) {
			MakeIMElement(*it, cond, xml);
			out_count++;
			if (cond.limit && out_count >= cond.limit)
				break;
		}
	}
	else {
		O2IMessages::reverse_iterator it;
		for (it = Messages.rbegin(); it != Messages.rend(); it++) {
			MakeIMElement(*it, cond, xml);
			out_count++;
			if (cond.limit && out_count >= cond.limit)
				break;
		}
	}
	Unlock();

	xml	+= L"</messages>" EOL;

	if (!FromUnicode(cond.charset.c_str(), xml, out))
		return (0);
	
	return (out_count);
}
Ejemplo n.º 3
0
uint64
O2KeyDB::
ExportToXML(O2KeySelectCondition &cond, string &out)
{
	wstring xml;
	xml += L"<?xml version=\"1.0\" encoding=\"";
	xml += cond.charset;
	xml += L"\"?>" EOL;

	xml	+= L"<keys>" EOL;

	if (cond.mask & KEY_XMLELM_INFO) {
		xml += L"<info>" EOL;
		{
			wchar_t tmp[16];
			swprintf_s(tmp, 16, L"%d", Keys.size());
			xml += L" <count>";
			xml += tmp;
			xml += L"</count>" EOL;

			swprintf_s(tmp, 16, L"%d", Limit);
			xml += L" <limit>";
			xml += tmp;
			xml += L"</limit>" EOL;

			xml += L" <id>";
			wstring idstr;
			SelfNodeID.to_string(idstr);
			xml += idstr;
			xml += L"</id>" EOL;

			wstring message;
			wstring message_type;
			GetXMLMessage(message, message_type);

			xml += L" <message>";
			xml += message;
			xml += L"</message>" EOL;

			xml += L" <message_type>";
			xml += message_type;
			xml += L"</message_type>" EOL;
		}
		xml += L"</info>" EOL;
	}

	uint64 out_count = 0;
	Lock();
	{
		if (cond.orderbydate) {
			O2Keys::nth_index<3>::type& keys = Keys.get<3>();
			O2Keys::nth_index_iterator<3>::type it;

			for (it = keys.begin(); it != keys.end(); it++) {
				MakeKeyElement(*it, cond, xml);
				out_count++;
				if (cond.limit && out_count >= cond.limit)
					break;
			}
		}
		else {
			O2Keys::nth_index<2>::type& keys = Keys.get<2>();
			O2Keys::nth_index_iterator<2>::type it;

			for (it = keys.begin(); it != keys.end(); it++) {
				MakeKeyElement(*it, cond, xml);
				out_count++;
				if (cond.limit && out_count >= cond.limit)
					break;
			}
		}
	}
	Unlock();

	xml	+= L"</keys>" EOL;

	if (!FromUnicode(cond.charset.c_str(), xml, out))
		return (0);
	return (out_count);
}