diff options
Diffstat (limited to 'plugins/NewsAggregator/Src/CheckFeed.cpp')
-rw-r--r-- | plugins/NewsAggregator/Src/CheckFeed.cpp | 138 |
1 files changed, 116 insertions, 22 deletions
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp index 8c2eac19fd..aa24ef077f 100644 --- a/plugins/NewsAggregator/Src/CheckFeed.cpp +++ b/plugins/NewsAggregator/Src/CheckFeed.cpp @@ -33,10 +33,19 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg) mir_free(tszData);
mir_free(szData);
if (hXml != NULL) {
+ LPCTSTR codepage = NULL;
int childcount = 0;
HXML node;
- if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml")))
+ if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml"))) {
+ for (int i = 0; xmlGetAttrCount(hXml); i++) {
+ LPCTSTR szAttrName = xmlGetAttrName(hXml, i);
+ if (!mir_tstrcmpi(szAttrName, _T("encoding"))) {
+ codepage = xmlGetAttrValue(hXml, szAttrName);
+ break;
+ }
+ }
node = xmlGetChild(hXml, childcount);
+ }
else
node = hXml;
while (node) {
@@ -49,7 +58,13 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg) TCHAR mes[MAX_PATH];
mir_sntprintf(mes, _countof(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
- return xmlGetText(child);
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ return mir_tstrdup(buf);
+ }
+ else
+ return mir_tstrdup(xmlGetText(child));
}
}
}
@@ -60,7 +75,13 @@ LPCTSTR CheckFeed(TCHAR *tszURL, HWND hwndDlg) TCHAR mes[MAX_PATH];
mir_sntprintf(mes, _countof(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
- return xmlGetText(child);
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ return mir_tstrdup(buf);
+ }
+ else
+ return mir_tstrdup(xmlGetText(child));
}
}
}
@@ -182,10 +203,19 @@ void CheckCurrentFeed(MCONTACT hContact) CMString szValue;
if (hXml != NULL) {
+ LPCTSTR codepage = NULL;
int childcount = 0;
HXML node;
- if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml")))
+ if (!mir_tstrcmpi(xmlGetName(hXml), _T("xml"))) {
+ for (int i = 0; xmlGetAttrCount(hXml); i++) {
+ LPCTSTR szAttrName = xmlGetAttrName(hXml, i);
+ if (!mir_tstrcmpi(szAttrName, _T("encoding"))) {
+ codepage = xmlGetAttrValue(hXml, szAttrName);
+ break;
+ }
+ }
node = xmlGetChild(hXml, childcount);
+ }
else
node = hXml;
while (node) {
@@ -211,17 +241,38 @@ void CheckCurrentFeed(MCONTACT hContact) HXML child = xmlGetChild(chan, j);
LPCTSTR childName = xmlGetName(child);
if (!mir_tstrcmpi(childName, _T("title"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "FirstName", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("link"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Homepage", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("description"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText) {
ClearText(szValue, szChildText);
db_set_ts(hContact, MODULE, "About", szValue);
@@ -229,22 +280,50 @@ void CheckCurrentFeed(MCONTACT hContact) }
}
else if (!mir_tstrcmpi(childName, _T("language"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Language1", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("managingEditor"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "e-mail", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("category"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_ts(hContact, MODULE, "Interest0Text", ClearText(szValue, szChildText));
}
else if (!mir_tstrcmpi(childName, _T("copyright"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText)
db_set_s(hContact, "UserInfo", "MyNotes", _T2A(ClearText(szValue, szChildText)));
}
@@ -279,10 +358,16 @@ void CheckCurrentFeed(MCONTACT hContact) }
}
else if (!mir_tstrcmpi(childName, _T("lastBuildDate"))) {
- LPCTSTR szChildText = xmlGetText(child);
+ LPCTSTR szChildText = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(child)), -1, buf, _countof(buf));
+ szChildText = buf;
+ }
+ else
+ szChildText = xmlGetText(child);
if (szChildText) {
- TCHAR *lastupdtime = (TCHAR *)xmlGetText(child);
- time_t stamp = DateToUnixTime(lastupdtime, 0);
+ time_t stamp = DateToUnixTime(szChildText, 0);
double deltaupd = difftime(time(NULL), stamp);
double deltacheck = difftime(time(NULL), (time_t)db_get_dw(hContact, MODULE, "LastCheck", 0));
if (deltaupd - deltacheck >= 0) {
@@ -298,31 +383,40 @@ void CheckCurrentFeed(MCONTACT hContact) for (int z = 0; z < xmlGetChildCount(child); z++) {
HXML itemval = xmlGetChild(child, z);
LPCTSTR itemName = xmlGetName(itemval);
+ LPCTSTR value = NULL;
+ if (!mir_tstrcmpi(codepage, _T("koi8-r"))) {
+ TCHAR buf[MAX_PATH];
+ MultiByteToWideChar(20866, 0, _T2A(xmlGetText(itemval)), -1, buf, _countof(buf));
+ value = buf;
+ }
+ else
+ value = xmlGetText(itemval);
+
// We only use the first tag for now and ignore the rest.
if (!mir_tstrcmpi(itemName, _T("title")))
- ClearText(title, xmlGetText(itemval));
+ ClearText(title, value);
else if (!mir_tstrcmpi(itemName, _T("link")))
- ClearText(link, xmlGetText(itemval));
+ ClearText(link, value);
else if (!mir_tstrcmpi(itemName, _T("pubDate")) || !mir_tstrcmpi(itemName, _T("date"))) {
if (stamp == 0)
- stamp = DateToUnixTime(xmlGetText(itemval), 0);
+ stamp = DateToUnixTime(value, 0);
}
else if (!mir_tstrcmpi(itemName, _T("description")) || !mir_tstrcmpi(itemName, _T("encoded")))
- ClearText(descr, xmlGetText(itemval));
+ ClearText(descr, value);
else if (!mir_tstrcmpi(itemName, _T("author")) || !mir_tstrcmpi(itemName, _T("creator")))
- ClearText(author, xmlGetText(itemval));
+ ClearText(author, value);
else if (!mir_tstrcmpi(itemName, _T("comments")))
- ClearText(comments, xmlGetText(itemval));
+ ClearText(comments, value);
else if (!mir_tstrcmpi(itemName, _T("guid")))
- ClearText(guid, xmlGetText(itemval));
+ ClearText(guid, value);
else if (!mir_tstrcmpi(itemName, _T("category")))
- ClearText(category, xmlGetText(itemval));
+ ClearText(category, value);
}
XmlToMsg(hContact, title, link, descr, author, comments, guid, category, stamp);
|