// --------------------------------------------------------------------------- // Save() // 2channel.brd形式でファイルに保存 // --------------------------------------------------------------------------- bool O2Boards:: Save(void) { if (boards.empty()) return false; wstring s; BoardsLock.Lock(); { wstring category; s += _T("0,0\r\n"); for (uint i = 0; i < boards.size(); i++) { if (category != boards[i].category) { category = boards[i].category; s += category; s += L"\t0\r\n"; } s += L"\t"; s += boards[i].host; s += L"\t"; s += boards[i].bbsname; s += L"\t"; s += boards[i].title; s += L"\r\n"; } } BoardsLock.Unlock(); string sjis; FromUnicode(L"shift_jis", s, sjis); File f; if (!f.open(filepath.c_str(), MODE_W)) return false; f.write((void*)&sjis[0], sjis.size()); f.close(); struct _utimbuf times; times.actime = LastModified; times.modtime = LastModified; #ifdef _WIN32 _wutime(filepath.c_str(), ×); #else string tmp; FromUnicode(_T(DEFAULT_XML_CHARSET), filepath, tmp); utime(tmp.c_str(), ×); #endif return true; }
uint64 O2KeyDB:: ExportToXML(const O2KeyList &keys, string &out) { O2KeySelectCondition cond; wstring xml; xml += L"<?xml version=\"1.0\" encoding=\""; xml += cond.charset; xml += L"\"?>" EOL; xml += L"<keys>" EOL; uint64 out_count = 0; O2KeyList::const_iterator it; for (it = keys.begin(); it != keys.end(); it++) { MakeKeyElement(*it, cond, xml); out_count++; } xml += L"</keys>" EOL; if (!FromUnicode(cond.charset.c_str(), xml, out)) return (0); return (out_count); }
void RTFParser::ReadText(const WString& text) { if(!IsNull(state.dest)) return; LLOG("Output text: <" << FromUnicode(text, state.charset) << ">, " << state.charformat); para.Cat(text, state.charformat); }
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()); }
/* * SetConfDir() * GetConfDirA() * GetConfDirW() * MakeConfDir() * */ void O2Profile:: SetConfDir(const wchar_t *path) { ConfDirW = path; if (ConfDirW[ConfDirW.size()-1] == L'\\') ConfDirW.erase(ConfDirW.size()-1); FromUnicode(L"shift_jis", ConfDirW, ConfDirA); }
/* * SetDBDir() * GetDBDirA() * GetDBDirW() * MakeDBDir() * */ void O2Profile:: SetDBDir(const wchar_t *path) { DBDirW = path; if (DBDirW[DBDirW.size()-1] == L'\\') DBDirW.erase(DBDirW.size()-1); FromUnicode(L"shift_jis", DBDirW, DBDirA); }
/* * SetAdminRoot() * GetAdminRootA() * GetAdminRootW() * CheckAdminRoot() * */ void O2Profile:: SetAdminRoot(const wchar_t *path) { AdminRootW = path; if (AdminRootW[AdminRootW.size()-1] == L'\\') AdminRootW.erase(AdminRootW.size()-1); FromUnicode(L"shift_jis", AdminRootW, AdminRootA); }
bool O2IMDB:: MakeSendXML(O2Profile *profile, const wchar_t *charset, const wchar_t *msg, string &out) { wstring xml; wstring tmpstr; wchar_t tmp[16]; if (profile->GetIP() == 0) return false; xml += L"<?xml version=\"1.0\" encoding=\""; xml += charset; xml += L"\"?>" EOL; xml += L"<messages>" EOL; xml += L"<message>" EOL; ip2e(profile->GetIP(), tmpstr); xml += L" <ip>"; xml += tmpstr; xml += L"</ip>" EOL; swprintf_s(tmp, 16, L"%d", profile->GetP2PPort()); xml += L" <port>"; xml += tmp; xml += L"</port>" EOL; hashT id; profile->GetID(id); id.to_string(tmpstr); xml += L" <id>"; xml += tmpstr; xml += L"</id>" EOL; wstring pubkey; profile->GetPubkeyW(pubkey); xml += L" <pubkey>"; xml += pubkey; xml += L"</pubkey>" EOL; xml += L" <name>"; xml += profile->GetNodeNameW(); xml += L"</name>" EOL; makeCDATA(msg, tmpstr); xml += L" <msg>"; xml += tmpstr; xml += L"</msg>" EOL; xml += L"</message>" EOL; xml += L"</messages>" EOL; FromUnicode(charset, xml, out); return true; }
/* * SetCacheRoot() * GetCacheRootA() * GetCacheRootW() * MakeCacheRoot() * */ void O2Profile:: SetCacheRoot(const wchar_t *path) { CacheRootW = path; if (CacheRootW[CacheRootW.size()-1] == L'\\') CacheRootW.erase(CacheRootW.size()-1); FromUnicode(L"shift_jis", CacheRootW, CacheRootA); }
String LanguageInfo::ToString() const { String out; out << "LANGUAGE={" << LNGAsText(language) << "}\n" << "ENGLISH_NAME={" << english_name << "}\n" "NATIVE_NAME={" << native_name << "}\n" "THOUSAND_SEPARATOR={" << thousand_separator << "}\n" "DECIMAL_POINT={" << decimal_point << "}\n" "MONTH_NAMES={\n"; int i; for(i = 0; i < __countof(month_names); i++) out << " {" << FromUnicode(month_names[i]) << "} / {" << FromUnicode(short_month_names[i]) << "}\n"; out << "}\n" "DAY_NAMES={\n"; for(i = 0; i < __countof(day_names); i++) out << " {" << FromUnicode(day_names[i]) << "} / {" << FromUnicode(short_day_names[i]) << "}\n"; out << "}\n"; return out; }
bool O2Profile:: SetNodeName(const wchar_t *name) { if (wcslen(name) > O2_MAX_NAME_LEN) return false; if (wcsstr(name, L"]]>")) return false; Lock(); NodeNameW = name; FromUnicode(_T(DEFAULT_XML_CHARSET), NodeNameW, NodeNameA); Unlock(); return true; }
bool Speller::CheckOld(const WString& wstr) const { int len = wstr.GetLength(); if(len == 1) return true; if(len < 64) { String w = FromUnicode(wstr, charset); String wl = FromUnicode(ToLower(wstr), charset); int i; if(len == 2) { w.Cat(127); wl.Cat(127); } i = line.Find(ToLower(wl[0], charset) + (ToLower(wl[1], charset) << 8) + (ToLower(wl[2], charset) << 16)); if(i >= 0) { const byte *s = line[i].begin; const byte *e = line[i].end; String q; while(s < e) if(*s < dict) { if(q == w || q == wl) return true; q.Trim(*s++); } else { ASSERT(*s >= dict); const char *x = voc[(int)*s++ - dict]; q.Cat(x); } if(q == w || q == wl) return true; } } return user.Find(wstr) >= 0;; }
void WindowsMenu(Bar& bar) { Vector<Ctrl *> w = Ctrl::GetTopWindows(); int p = 1; for(int i = 0; i < w.GetCount() && p < 10; i++) { TopWindow *q = dynamic_cast<TopWindow *>(w[i]); if(q && !q->GetOwner() && p < 10) { bar.Add(Format("&%d ", p++) + FromUnicode(q->GetTitle(), CHARSET_DEFAULT), callback1(PutForeground, Ptr<Ctrl>(q))) .Check(q->IsForeground()) .Help(t_("Activate this window")); } } if(p >= 10) bar.Add(t_("More windows.."), callback(WindowsList)); }
void TopWindow::DefSyncTitle() { GuiLock __; if(title2 == title) return; title2 = title; if(IsOpen() && GetWindow()) { Window w = GetWindow(); XStoreName(Xdisplay, w, title.ToString()); XSetIconName(Xdisplay, w, title.ToString()); String utf8title = FromUnicode(title, CHARSET_UTF8); XChangeProperty(Xdisplay, w, XAtom("_NET_WM_NAME"), XAtom("UTF8_STRING"), 8, PropModeReplace, (const unsigned char *)~utf8title, utf8title.GetLength()); XChangeProperty(Xdisplay, w, XAtom("_NET_WM_ICON_NAME"), XAtom("UTF8_STRING"), 8, PropModeReplace, (const unsigned char *)~utf8title, utf8title.GetLength()); } }
NAMESPACE_UPP static void sLoadBom(Stream& in, String *t, WString *wt, byte def_charset) { if(in.IsOpen()) { String s; if(in.GetLeft() > 3) { word header = in.Get16le(); if(header == 0xfffe || header == 0xfeff) { int n = (int)in.GetLeft() / 2; WStringBuffer ws(n); ws.SetLength(in.Get(~ws, 2 * n) / 2); if(header == 0xfffe) EndianSwap((word *)~ws, ws.GetCount()); if(wt) *wt = ws; else *t = FromUnicode(ws); return; } int c = in.Get(); if(c < 0) return; byte *h = (byte *)&header; if(h[0] == 0xef && h[1] == 0xbb && c == 0xbf) { if(wt) *wt = FromUtf8(LoadStream(in)); else *t = ToCharset(CHARSET_DEFAULT, LoadStream(in), CHARSET_UTF8); return; } s.Cat(h, 2); s.Cat(c); } s.Cat(LoadStream(in)); if(wt) *wt = ToUnicode(s, def_charset); else *t = ToCharset(CHARSET_DEFAULT, s, def_charset); return; } return; }
uint64 O2KeyDB:: ExportToXML(const O2Key &key, string &out) { O2KeySelectCondition cond; wstring xml; xml += L"<?xml version=\"1.0\" encoding=\""; xml += cond.charset; xml += L"\"?>" EOL; xml += L"<keys>" EOL; MakeKeyElement(key, cond, xml); xml += L"</keys>" EOL; if (!FromUnicode(cond.charset.c_str(), xml, out)) return (0); return (1); }
bool O2IMDB:: Load(const wchar_t *filename) { struct _stat st; if (_wstat(filename, &st) == -1) return false; // マルチバイト化 string mFilename; FromUnicode(_T(DEFAULT_XML_CHARSET), wstring(filename), mFilename); if (stat(mFilename.c_str(), &st) == -1) return false; if (st.st_size == 0) return false; ImportFromXML(filename, NULL, 0); NewMessageFlag = false; return true; }
// --------------------------------------------------------------------------- // SaveEx() // 独自の情報を別ファイルに保存 // --------------------------------------------------------------------------- bool O2Boards:: SaveEx(void) { wstring xml; xml += L"<?xml version=\"1.0\" encoding=\""; xml += _T(DEFAULT_XML_CHARSET); xml += L"\"?>" EOL; xml += L"<boards>" EOL; ExLock.Lock(); { for (O2BoardExMapIt it = exmap.begin(); it != exmap.end(); it++) { xml += L"<board>" EOL; xml_AddElement(xml, L"name", NULL, it->first.c_str()); xml_AddElement(xml, L"enable", NULL, it->second->enable ? L"1" : L"0"); xml += L"</board>" EOL; } } ExLock.Unlock(); xml += L"</boards>" EOL; string out; FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out); /* FILE *fp; if (_wfopen_s(&fp, exfilepath.c_str(), L"wb") != 0) return false; fwrite(&out[0], 1, out.size(), fp); fclose(fp); */ File f; if (!f.open(exfilepath.c_str(), MODE_W)) return false; f.write((void*)&out[0], out.size()); f.close(); return true; }
bool LineEdit::InsertChar(dword key, int count, bool canow) { if(key == K_TAB && !processtab) return false; if(filter && key >= 32 && key < 65535) key = (*filter)(key); if(!IsReadOnly() && (key >= 32 && key < 65536 || key == '\t' || key == '\n' || key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { if(key >= 128 && key < 65536 && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { int q = cursor; int i = GetLinePos(q); if(q + count - 1 < GetLineLength(i)) Remove(cursor, count); } WString text(key == K_ENTER ? '\n' : key == K_SHIFT_SPACE ? ' ' : key, count); Insert(cursor, text, true); PlaceCaret(cursor + count); Action(); return true; } return false; }
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); }
std::string XMLReader::ReadElementString(TextEncoding encoding) { return FromUnicode(ReadElementString(), encoding); }
std::string XMLReader::ReadElementString(const char * name, TextEncoding encoding) { return FromUnicode(ReadElementString(name), encoding); }
std::string XMLReader::ReadElementString(const char * localName, const char * namespaceURI, TextEncoding encoding) { return FromUnicode(ReadElementString(localName, namespaceURI), encoding); }
std::string XMLReader::GetAttribute(size_t i, TextEncoding encoding) const { return FromUnicode(GetAttribute(i), encoding); }
bool O2Profile:: ExportToXML(const O2ProfileSelectCondition cond, string &out) { wstring tmpstr; wchar_t tmp[32]; 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"<"; xml += cond.rootelement; xml += L">" EOL; Lock(); //ID if (cond.mask & PROF_XMLELM_ID) { ID.to_string(tmpstr); xml += L" <ID>"; xml += tmpstr; xml += L"</ID>" EOL; } //IP if (cond.mask & PROF_XMLELM_IP) { ip2e(IP, tmpstr); xml += L" <IP>"; xml += tmpstr; xml += L"</IP>" EOL; } //NodeName if (cond.mask & PROF_XMLELM_NAME) { makeCDATA(NodeNameW, tmpstr); xml += L" <nodename>"; xml += tmpstr; xml += L"</nodename>" EOL; } //Comment if (cond.mask & PROF_XMLELM_COMMENT) { makeCDATA(Comment, tmpstr); xml += L" <comment>"; xml += tmpstr; xml += L"</comment>" EOL; } //P2PPort if (cond.mask & PROF_XMLELM_P2PPORT) { xml += L" <port>"; swprintf_s(tmp, 16, L"%d", P2PPort); xml += tmp; xml += L"</port>" EOL; } //ProxyPort if (cond.mask & PROF_XMLELM_PROXYPORT) { xml += L" <ProxyPort>"; swprintf_s(tmp, 16, L"%d", ProxyPort); xml += tmp; xml += L"</ProxyPort>" EOL; } //AdminPort if (cond.mask & PROF_XMLELM_ADMINPORT) { xml += L" <AdminPort>"; swprintf_s(tmp, 16, L"%d", AdminPort); xml += tmp; xml += L"</AdminPort>" EOL; } //PrivKey if (cond.mask & PROF_XMLELM_PRIVKEY) { PrivKey.to_string(tmpstr); xml += L" <PrivKey>"; xml += tmpstr; xml += L"</PrivKey>" EOL; } //PubKey if (cond.mask & PROF_XMLELM_PUBKEY) { PubKey.to_string(tmpstr); xml += L" <PubKey>"; xml += tmpstr; xml += L"</PubKey>" EOL; } //DBDir if (cond.mask & PROF_XMLELM_DBDIR) { makeCDATA(DBDirW, tmpstr); xml += L" <DBDir>"; xml += tmpstr; xml += L"</DBDir>" EOL; } //CacheRoot if (cond.mask & PROF_XMLELM_CACHEROOT) { makeCDATA(CacheRootW, tmpstr); xml += L" <CacheRoot>"; xml += tmpstr; xml += L"</CacheRoot>" EOL; } //AdminRoot if (cond.mask & PROF_XMLELM_ADMINROOT) { makeCDATA(AdminRootW, tmpstr); xml += L" <AdminRoot>"; xml += tmpstr; xml += L"</AdminRoot>" EOL; } //AdminBrowserType if (cond.mask & PROF_XMLELM_ADMIN_BROWSER_TYPE) { xml += L" <AdminBrowserType>"; xml += AdminBrowserType; xml += L"</AdminBrowserType>" EOL; } //AdminBrowserPath if (cond.mask & PROF_XMLELM_ADMIN_BROWSER_PATH) { makeCDATA(AdminBrowserPath, tmpstr); xml += L" <AdminBrowserPath>"; xml += tmpstr; xml += L"</AdminBrowserPath>" EOL; } //UPnPAdapterName if (cond.mask & PROF_XMLELM_UPNP_ADAPTERNAME) { ascii2unicode(UPnPAdapterName, tmpstr); makeCDATA(tmpstr, tmpstr); xml += L" <UPnPAdapterName>"; xml += tmpstr; xml += L"</UPnPAdapterName>" EOL; } //UPnPLocation if (cond.mask & PROF_XMLELM_UPNP_LOCATION) { ascii2unicode(UPnPLocation, tmpstr); makeCDATA(tmpstr, tmpstr); xml += L" <UPnPLocation>"; xml += tmpstr; xml += L"</UPnPLocation>" EOL; } //UPnPServiceId if (cond.mask & PROF_XMLELM_UPNP_SERVICEID) { ascii2unicode(UPnPServiceId, tmpstr); makeCDATA(tmpstr, tmpstr); xml += L" <UPnPServiceId>"; xml += tmpstr; xml += L"</UPnPServiceId>" EOL; } //limits if (cond.mask & PROF_XMLELM_LIMIT) { swprintf_s(tmp, 16, L"%u", P2PSessionLimit); xml += L" <p2psessionlimit>"; xml += tmp; xml += L"</p2psessionlimit>" EOL; /* swprintf_s(tmp, 16, L"%u", NodeLimit); xml += L" <nodelimit>"; xml += tmp; xml += L"</nodelimit>" EOL; */ swprintf_s(tmp, 16, L"%u", KeyLimit); xml += L" <keylimit>"; xml += tmp; xml += L"</keylimit>" EOL; swprintf_s(tmp, 16, L"%u", QueryLimit); xml += L" <querylimit>"; xml += tmp; xml += L"</querylimit>" EOL; swprintf_s(tmp, 16, L"%u", LogLimit); xml += L" <loglimit>"; xml += tmp; xml += L"</loglimit>" EOL; swprintf_s(tmp, 16, L"%u", NetLogLimit); xml += L" <netloglimit>"; xml += tmp; xml += L"</netloglimit>" EOL; swprintf_s(tmp, 16, L"%u", HokanLogLimit); xml += L" <hokanloglimit>"; xml += tmp; xml += L"</hokanloglimit>" EOL; swprintf_s(tmp, 16, L"%u", IPFLogLimit); xml += L" <ipfloglimit>"; xml += tmp; xml += L"</ipfloglimit>" EOL; swprintf_s(tmp, 32, L"%I64u", QuarterSize); xml += L" <quartersize>"; xml += tmp; xml += L"</quartersize>" EOL; swprintf_s(tmp, 16, L"%u", QuarterFullOperation); xml += L" <quarterfulloperation>"; xml += tmp; xml += L"</quarterfulloperation>" EOL; swprintf_s(tmp, 16, L"%u", ResumeDelayMs); xml += L" <ResumeDelayMs>"; xml += tmp; xml += L"</ResumeDelayMs>" EOL; } if (cond.mask & PROF_XMLELM_BOOL) { xml += L" <port0>"; xml += (Port0 ? L"1" : L"0"); xml += L"</port0>" EOL; xml += L" <p2pautostart>"; xml += (P2PAutoStart ? L"1" : L"0"); xml += L"</p2pautostart>" EOL; xml += L" <loadsubdirindex>"; xml += (LoadSubdirIndex ? L"1" : L"0"); xml += L"</loadsubdirindex>" EOL; xml += L" <maruuser>"; xml += (MaruUser ? L"1" : L"0"); xml += L"</maruuser>" EOL; xml += L" <publicprofile>"; xml += (PublicReport ? L"1" : L"0"); xml += L"</publicprofile>" EOL; xml += L" <publicrecentdat>"; xml += (PublicRecentDat ? L"1" : L"0"); xml += L"</publicrecentdat>" EOL; xml += L" <baloon_p2p>"; xml += (Baloon_P2P ? L"1" : L"0"); xml += L"</baloon_p2p>" EOL; xml += L" <baloon_query>"; xml += (Baloon_Query ? L"1" : L"0"); xml += L"</baloon_query>" EOL; xml += L" <baloon_hokan>"; xml += (Baloon_Hokan ? L"1" : L"0"); xml += L"</baloon_hokan>" EOL; xml += L" <baloon_im>"; xml += (Baloon_IM ? L"1" : L"0"); xml += L"</baloon_im>" EOL; xml += L" <AutoResume>"; xml += (AutoResume ? L"1" : L"0"); xml += L"</AutoResume>" EOL; xml += L" <UseUPnP>"; xml += (UseUPnP ? L"1" : L"0"); xml += L"</UseUPnP>" EOL; } Unlock(); xml += L"</"; xml += cond.rootelement; xml += L">" EOL; return (FromUnicode(cond.charset.c_str(), xml, out)); }
void O2ReportMaker:: GetReport(string &out, bool pub) { double ptime; double ptimeavg; int handle_c; int thread_c; PerformanceCounter->GetValue(ptime, ptimeavg, handle_c, thread_c); long tzoffset; _get_timezone(&tzoffset); // start time time_t starttime = PerformanceCounter->GetStartTime(); wchar_t starttime_str[32]; if (starttime != 0) { time_t t = starttime - tzoffset; struct tm tm; gmtime_s(&tm, &t); wcsftime(starttime_str, 32, L"%Y/%m/%d %H:%M:%S", &tm); } else wcscpy_s(starttime_str, 32, L"-"); // uptime uint64 uptime = PerformanceCounter->GetUptime(); wchar_t uptime_str[32]; if (uptime != 0) { swprintf_s(uptime_str, 32, L"%I64dd %02I64d:%02I64d:%02I64d", uptime/86400, (uptime%86400)/3600, (uptime%3600)/60, uptime%60); } else wcscpy_s(uptime_str, 32, L"-"); // uptime (累計) uint64 total_uptime = PerformanceCounter->GetTotalUptime() + uptime; wchar_t total_uptime_str[32]; swprintf_s(total_uptime_str, 32, L"%I64dd %02I64d:%02I64d:%02I64d", total_uptime/86400, (total_uptime%86400)/3600, (total_uptime%3600)/60, total_uptime%60); wchar_t ptime_str[32]; swprintf_s(ptime_str, 32, L"%.1f%% (%.1f%%)", ptime, ptimeavg); // 送受信バイト数 (現在のセッション) uint64 total_u = Server_P2P->GetSendByte() + Client->GetSendByte(); uint64 total_d = Server_P2P->GetRecvByte() + Client->GetRecvByte(); wchar_t traffic_u[32]; swprintf_s(traffic_u, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)total_u/1024/uptime), (uptime == 0 ? 0 : (double)total_u/uptime*8)); wchar_t traffic_d[32]; swprintf_s(traffic_d, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)total_d/1024/uptime), (uptime == 0 ? 0 : (double)total_d/uptime*8)); wchar_t traffic_ud[32]; swprintf_s(traffic_ud, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)(total_u+total_d)/1024/uptime), (uptime == 0 ? 0 : (double)(total_u+total_d)/uptime*8)); // 送受信バイト数 (累計) uint64 accum_total_u = PerformanceCounter->GetTotalSend() + total_u; uint64 accum_total_d = PerformanceCounter->GetTotalRecv() + total_d; wchar_t a_traffic_u[32]; swprintf_s(a_traffic_u, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)accum_total_u/1024/total_uptime), (total_uptime == 0 ? 0 : (double)accum_total_u/total_uptime*8)); wchar_t a_traffic_d[32]; swprintf_s(a_traffic_d, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)accum_total_d/1024/total_uptime), (total_uptime == 0 ? 0 : (double)accum_total_d/total_uptime*8)); wchar_t a_traffic_ud[32]; swprintf_s(a_traffic_ud, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)(accum_total_u+accum_total_d)/1024/total_uptime), (total_uptime == 0 ? 0 : (double)(accum_total_u+accum_total_d)/total_uptime*8)); //dat数、サイズ uint64 datnum = 0; uint64 datsize = 0; uint64 pubnum = 0; DatDB->select_report(PUBLISH_ORIGINAL_TT, datnum, datsize, pubnum); //publish率 wchar_t publishper[32]; if (datnum == 0) wcscpy_s(publishper, 32, L"0.0%"); else { swprintf(publishper, 32, L"%.1f%% (%I64u)", (double)pubnum/datnum*100.0, pubnum); } wstring tmpstr; wstring xml; xml += L"<?xml version=\"1.0\" encoding=\""; xml += _T(DEFAULT_XML_CHARSET); xml += L"\"?>"EOL; if (pub) xml += L"<?xml-stylesheet type=\"text/xsl\" href=\"/profile.xsl\"?>"; xml += L"<report>"EOL; // // 名前、コメント、閲覧履歴 // if (pub) { makeCDATA(Profile->GetNodeNameW(), tmpstr); xml += L"<name>"; xml += tmpstr; xml += L"</name>"EOL; xml += L"<category>"EOL; xml += L"<table>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"ID"); hashT hash; Profile->GetID(hash); wstring hashstr; hash.to_string(hashstr); xml_AddElement(xml, L"td", L"class=\"L\"", hashstr.c_str()); xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"コメント"); makeCDATA(Profile->GetComment(), tmpstr); xml += L" <pre>"; xml += tmpstr; xml += L"</pre>"EOL; xml += L"</tr>"EOL; // if (Profile->IsPublicRecentDat()) { xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"閲覧履歴"); xml += L"<pre>"; O2KeyList recent; Server_Proxy->GetRecentDatList(recent); tmpstr.erase(); for (O2KeyListIt it = recent.begin(); it != recent.end(); it++) { wchar_t timestr[TIMESTR_BUFF_SIZE]; struct tm tm; localtime_s(&tm, &it->date); wcsftime(timestr, TIMESTR_BUFF_SIZE, L"%Y/%m/%d %H:%M:%S", &tm); tmpstr += timestr; tmpstr += L" [ "; tmpstr += it->url; tmpstr += L" ] "; tmpstr += it->title; tmpstr += L"\r\n"; } makeCDATA(tmpstr, tmpstr); xml += tmpstr; xml += L"</pre>"EOL; xml += L"</tr>"EOL; } xml += L"</table>"EOL; xml += L"</category>"EOL; } // // 概要 // if (!pub || Profile->IsPublicReport()) { xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"概要"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"状態"); xml_AddElement(xml, L"td", L"type=\"h\"", L"CPU(平均)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ハンドル"); xml_AddElement(xml, L"td", L"type=\"h\"", L"スレッド"); xml_AddElement(xml, L"td", L"type=\"h\"", L"総dat数"); xml_AddElement(xml, L"td", L"type=\"h\"", L"総datサイズ"); xml_AddElement(xml, L"td", L"type=\"h\"", L"publish率"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; if (PerformanceCounter->IsActive()) xml_AddElement(xml, L"td", L"class=\"active\"", L"稼動中"); else xml_AddElement(xml, L"td", L"class=\"deactive\"", L"停止中"); xml_AddElement(xml, L"td", L"class=\"C\"", ptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", handle_c); xml_AddElement(xml, L"td", L"class=\"N\"", thread_c); xml_AddElement(xml, L"td", L"class=\"N\"", datnum); xml_AddElement(xml, L"td", L"class=\"N\"", datsize); xml_AddElement(xml, L"td", L"class=\"R\"", publishper); xml += L"</tr>"EOL; xml += L"</table>"EOL; // xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"起動日時"); xml_AddElement(xml, L"td", L"type=\"h\"", L"グローバルIP"); xml_AddElement(xml, L"td", (Server_P2P->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"P2P"); xml_AddElement(xml, L"td", (Server_Proxy->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"Proxy"); xml_AddElement(xml, L"td", (Server_Admin->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"Admin"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Ver"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; wstring ipstr; ulong2ipstr(Profile->GetIP(), ipstr); xml_AddElement(xml, L"td", L"class=\"C\"", starttime_str); xml_AddElement(xml, L"td", L"class=\"C\"", ipstr.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetP2PPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetProxyPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetAdminPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetUserAgentW()); xml += L"</tr>"EOL; xml += L"</table>"EOL; // xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"稼働時間"); xml_AddElement(xml, L"td", L"type=\"h\"", L"上り"); xml_AddElement(xml, L"td", L"type=\"h\"", L"下り"); xml_AddElement(xml, L"td", L"type=\"h\"", L"合計"); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"上りKB/s(bps)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"下りKB/s(bps)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"合計KB/s(bps)"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"今回"); xml_AddElement(xml, L"td", L"class=\"C\"", uptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", total_u); xml_AddElement(xml, L"td", L"class=\"N\"", total_d); xml_AddElement(xml, L"td", L"class=\"N\"", total_u+total_d); xml_AddElement(xml, L"td", L"", L""); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_u); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_d); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_ud); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"累計"); xml_AddElement(xml, L"td", L"class=\"C\"", total_uptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_u); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_d); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_u+accum_total_d); xml_AddElement(xml, L"td", L"", L""); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_u); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_d); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_ud); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // DB // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"DB"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"Node"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Friend"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Key"); xml_AddElement(xml, L"td", L"type=\"h\"", L"SakuKey"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Query"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Saku"); xml_AddElement(xml, L"td", L"type=\"h\"", L"IM"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Broadcast"); xml_AddElement(xml, L"td", L"type=\"h\"", L"BCQueue"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Logger"); xml_AddElement(xml, L"td", L"type=\"h\"", L"IPFilter"); xml_AddElement(xml, L"td", L"type=\"h\"", L"DatRequest"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"保持数"); xml_AddElement(xml, L"td", L"class=\"N\"", NodeDB->count()); xml_AddElement(xml, L"td", L"class=\"N\"", FriendDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", KeyDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", SakuKeyDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", QueryDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", SakuDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", IMDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", BroadcastDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", Job_Broadcast->GetQueueCount()); xml_AddElement(xml, L"td", L"class=\"N\"", Logger->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", IPFilter_P2P->Count()+IPFilter_Proxy->Count()+IPFilter_Admin->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", Job_QueryDat->GetRequestQueueCount()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // Server // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Server"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"dat"); xml_AddElement(xml, L"td", L"type=\"h\"", L"collection"); xml_AddElement(xml, L"td", L"type=\"h\"", L"im"); xml_AddElement(xml, L"td", L"type=\"h\"", L"broadcast"); xml_AddElement(xml, L"td", L"type=\"h\"", L"profile"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ping"); xml_AddElement(xml, L"td", L"type=\"h\"", L"store"); xml_AddElement(xml, L"td", L"type=\"h\"", L"findnode"); xml_AddElement(xml, L"td", L"type=\"h\"", L"findvalue"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ERROR"); xml_AddElement(xml, L"td", L"type=\"h\"", L"?"); xml_AddElement(xml, L"td", L"type=\"h\"", L"計"); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"Proxy"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Admin"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"接続回数"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetTotalSessionCount()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetTotalSessionCount()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetSendByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetSendByte()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"down"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetRecvByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetRecvByte()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up + down"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("dat") + Server_P2P->GetRecvByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("collection") + Server_P2P->GetRecvByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("im") + Server_P2P->GetRecvByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("broadcast") + Server_P2P->GetRecvByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("profile") + Server_P2P->GetRecvByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ping") + Server_P2P->GetRecvByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("store") + Server_P2P->GetRecvByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findnode") + Server_P2P->GetRecvByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findvalue") + Server_P2P->GetRecvByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ERROR") + Server_P2P->GetRecvByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("UNKNOWN") + Server_P2P->GetRecvByteByPath("UNKNOWN")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath(NULL) + Server_P2P->GetRecvByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetSendByte() + Server_Proxy->GetRecvByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetRecvByte() + Server_Admin->GetRecvByte()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"同時接続数ピーク"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionPeak()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // Agent // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Agent"); xml += L"<table>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); size_t i; for (i = 0; i < Jobs.size(); i++) { if (Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"type=\"h\" class=\"active\"", Jobs[i]->GetName()); else xml_AddElement(xml, L"td", L"type=\"h\" class=\"deactive\"", Jobs[i]->GetName()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"実行"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else if (Jobs[i]->IsWorking()) xml_AddElement(xml, L"td", L"class=\"active\"", L"実行中"); else xml_AddElement(xml, L"td", L"class=\"wait\"", L"待機"); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"間隔(s)"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"C\"", Jobs[i]->GetInterval()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"起動まで"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive() || Jobs[i]->IsWorking()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"C\"", Jobs[i]->GetRemain()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"接続回数"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetTotalSessionCount()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetSendByte()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"down"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetRecvByte()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up+down"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetSendByte()+Jobs[i]->GetRecvByte()); } xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"同時接続数ピーク"); xml_AddElement(xml, L"td", L"class=\"N\"", Client->GetSessionPeak()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; if (O2DEBUG && TRACE_CONNECTIONS && !pub) { // // Connections // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Connections"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"IP"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Port"); xml_AddElement(xml, L"td", L"type=\"h\"", L"接続時間(s)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"recv"); xml_AddElement(xml, L"td", L"type=\"h\"", L"send"); xml_AddElement(xml, L"td", L"type=\"h\"", L"rbuff"); xml += L"</tr>"EOL; O2SocketSessionPList lst; time_t now = time(NULL); Server_P2P->GetSessionList(lst); for (O2SocketSessionPListIt it = lst.begin(); it != lst.end(); it++) { O2SocketSession *ss = *it; wstring e_ip; ip2e(ss->ip, e_ip); xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"class=\"C\"", L"Server"); xml_AddElement(xml, L"td", L"class=\"C\"", e_ip.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", ss->port); xml_AddElement(xml, L"td", L"class=\"R\"", now - ss->connect_t); xml_AddElement(xml, L"td", L"class=\"N\"", ss->rbuffoffset); xml_AddElement(xml, L"td", L"class=\"N\"", ss->sbuffoffset); wstring rbuff; ascii2unicode(ss->rbuff, rbuff); xml_AddElement(xml, L"td", L"class=\"L\"", rbuff.c_str(), true); xml += L"</tr>"EOL; delete *it; } lst.clear(); Client->GetSessionList(lst); for (O2SocketSessionPListIt it = lst.begin(); it != lst.end(); it++) { O2SocketSession *ss = *it; wstring e_ip; ip2e(ss->ip, e_ip); xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"class=\"C\"", L"Agent"); xml_AddElement(xml, L"td", L"class=\"C\"", e_ip.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", ss->port); xml_AddElement(xml, L"td", L"class=\"R\"", now - ss->connect_t); xml_AddElement(xml, L"td", L"class=\"N\"", ss->rbuffoffset); xml_AddElement(xml, L"td", L"class=\"N\"", ss->sbuffoffset); wstring rbuff; ascii2unicode(ss->rbuff, rbuff); xml_AddElement(xml, L"td", L"class=\"L\"", rbuff.c_str(), true); xml += L"</tr>"EOL; delete *it; } xml += L"</table>"EOL; xml += L"</category>"EOL; } } xml += L"</report>"EOL; FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out); }
std::string XMLReader::GetAttribute(const char * name, TextEncoding encoding) const { return FromUnicode(GetAttribute(name), encoding); }
// --------------------------------------------------------------------------- // Load() // 2channel.brd形式のファイルから読み込む // --------------------------------------------------------------------------- bool O2Boards:: Load(const wchar_t *fn) { const wchar_t *filename = fn ? fn : filepath.c_str(); #ifdef _WIN32 struct _stat st; if (_tstat(filename, &st) == -1) return false; #else /** VC++ function equivalent */ struct stat st; string unixFilename; FromUnicode(_T(DEFAULT_XML_CHARSET), filename, unixFilename); if (_tstat(unixFilename.c_str(), &st) == -1) return false; #endif if (st.st_size == 0) return false; FILE *fp; #ifdef _WIN32 if (_tfopen_s(&fp, filename, _T("rb")) != 0) return false; #else /** VC++ _s function equivalent */ if (fopen_s(&fp, unixFilename.c_str(), "rb") != 0) return false; #endif string buff; buff.resize(st.st_size); fread(&buff[0], 1, st.st_size, fp); fclose(fp); wstring unicode; if (!ToUnicode(L"shift_jis", buff, unicode)) return false; BoardsLock.Lock(); boards.clear(); BoardsLock.Unlock(); std::wstringstream ss(unicode); std::wstring line; std::wstring category; std::getline(ss, line); //skip first line while (!ss.fail()) { std::getline(ss, line); if (line.empty()) continue; if (*(line.end()-1) == L'\r') line.erase(line.end()-1); boost::wregex regex(L"^\t?([^[\t]+)\t([^[\t]+)(?:\t([^[\t]+))?$"); boost::wsmatch m; boost::regex_match(line, m, regex); if (line[0] != L'\t') { category = m.str(1); } else { const wchar_t *domain = host2domain(m.str(1).c_str()); if (!domain) continue; O2Board brd; brd.bbsname = m.str(2); brd.title = m.str(3); brd.category = category; brd.host = m.str(1); brd.domain = domain; BoardsLock.Lock(); O2BoardArrayIt it = std::find(boards.begin(), boards.end(), brd); if (it == boards.end()) boards.push_back(brd); BoardsLock.Unlock(); } } LastModified = st.st_mtime; /* TRACEA("st.st_mtime:"); TRACEA(ctime(&st.st_mtime)); TRACEA("bbsmenu_lastmodified:"); TRACEA(ctime(&bbsmenu_lastmodified)); */ return true; }
bool O2IMDB:: MakeSendXML(const O2IMessage &im, string &out) { wstring xml; wstring tmpstr; wchar_t tmp[16]; xml += L"<?xml version=\"1.0\" encoding=\""; xml += _T(DEFAULT_XML_CHARSET); xml += L"\"?>" EOL; xml += L"<messages>" EOL; xml += L"<message>" EOL; ip2e(im.ip, tmpstr); xml += L" <ip>"; xml += tmpstr; xml += L"</ip>" EOL; swprintf_s(tmp, 16, L"%d", im.port); xml += L" <port>"; xml += tmp; xml += L"</port>" EOL; im.id.to_string(tmpstr); xml += L" <id>"; xml += tmpstr; xml += L"</id>" EOL; im.pubkey.to_string(tmpstr); xml += L" <pubkey>"; xml += tmpstr; xml += L"</pubkey>" EOL; xml += L" <name>"; xml += im.name; xml += L"</name>" EOL; makeCDATA(im.msg, tmpstr); xml += L" <msg>"; xml += tmpstr; xml += L"</msg>" EOL; im.key.to_string(tmpstr); xml += L" <key>"; xml += tmpstr; xml += L"</key>" EOL; for (hashListT::const_iterator it = im.paths.begin(); it != im.paths.end(); it++) { it->to_string(tmpstr); xml += L" <path>"; xml += tmpstr; xml += L"</path>" EOL; } xml += L"</message>" EOL; xml += L"</messages>" EOL; FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out); return true; }
// --------------------------------------------------------------------------- // MakeBBSMenuXML() // // --------------------------------------------------------------------------- bool O2Boards:: MakeBBSMenuXML(string &out, O2DatDB *db) { wstring xml; wstring category; wstring domain_bbsname; wstrarray token; wstrnummap::iterator nmit; O2BoardExMapIt exit; uint64 total; uint64 num; if (boards.empty()) return false; wstrnummap nummap; if (db) total = db->select_datcount(nummap); ExLock.Lock(); for (exit = exmap.begin(); exit != exmap.end(); exit++) { nummap.insert(wstrnummap::value_type(exit->first, 0)); } ExLock.Unlock(); for (size_t i = 0; i < boards.size(); i++) { if (category != boards[i].category) { category = boards[i].category; if (i != 0) xml += L"</category>" EOL; xml += L"<category>" EOL; xml_AddElement(xml, L"categoryname", NULL, category.c_str()); } xml += L"<board>" EOL; xml_AddElement(xml, L"bbsname", NULL, boards[i].bbsname.c_str()); xml_AddElement(xml, L"title", NULL, boards[i].title.c_str(), true); xml_AddElement(xml, L"host", NULL, boards[i].host.c_str()); xml_AddElement(xml, L"domain", NULL, boards[i].domain.c_str()); domain_bbsname = boards[i].domain + L":" + boards[i].bbsname; nmit = nummap.find(domain_bbsname); num = nmit == nummap.end() ? 0 : nmit->second; xml_AddElement(xml, L"datnum", NULL, num); //xml_AddElement(xml, L"ratio", NULL, total == 0 ? 0 : (uint)((double)num/total*100.0)); xml_AddElement(xml, L"ratio", NULL, num > 1000 ? 100 : (uint)((double)num/1000*100.0)); if (nmit != nummap.end()) nummap.erase(nmit); ExLock.Lock(); exit = exmap.find(domain_bbsname); xml_AddElement(xml, L"enable", NULL, exit != exmap.end() && exit->second->enable ? L"1" : L"0"); ExLock.Unlock(); xml += L"</board>" EOL; } xml += L"</category>" EOL; // xml += L"<category>" EOL; xml_AddElement(xml, L"categoryname", NULL, L"不明"); for (nmit = nummap.begin(); nmit != nummap.end(); nmit++) { wsplit(nmit->first.c_str(), L":", token); xml += L"<board>" EOL; xml_AddElement(xml, L"bbsname", NULL, token[1].c_str()); xml_AddElement(xml, L"title", NULL, token[1].c_str(), true); xml_AddElement(xml, L"host", NULL, L""); xml_AddElement(xml, L"domain", NULL, token[0].c_str()); xml_AddElement(xml, L"datnum", NULL, nmit->second); xml_AddElement(xml, L"ratio", NULL, total == 0 ? 0 : (uint)((double)nmit->second/total*100.0)); ExLock.Lock(); exit = exmap.find(nmit->first); xml_AddElement(xml, L"enable", NULL, exit != exmap.end() ? L"1" : L"0"); ExLock.Unlock(); xml += L"</board>" EOL; } xml += L"</category>" EOL; FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out); return true; }