summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-11-06 17:08:48 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-11-06 17:08:48 +0000
commit069389941b173066e3026713602232e4fba1d45c (patch)
tree7f301e3bc56d458ebed3e45a03b937b8099f954f /plugins
parentf0899cc7909c130426af35ba1ef0689d35a708f7 (diff)
- common message archiving code extracted to a separate function;
- manual memory allocation code removed; git-svn-id: http://svn.miranda-ng.org/main/trunk@10916 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp1075
-rw-r--r--plugins/NewsAggregator/Src/Common.h8
-rw-r--r--plugins/NewsAggregator/Src/Update.cpp4
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp19
4 files changed, 476 insertions, 630 deletions
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index 6518acb559..fff3cef96d 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -19,9 +19,9 @@ Boston, MA 02111-1307, USA.
#include "common.h"
-TCHAR *CheckFeed(TCHAR *tszURL, HWND hwndDlg)
+TCHAR* CheckFeed(TCHAR *tszURL, HWND hwndDlg)
{
- Netlib_LogfT(hNetlibUser,_T("Started validating feed %s."),tszURL);
+ Netlib_LogfT(hNetlibUser, _T("Started validating feed %s."), tszURL);
char *szData = NULL;
GetNewsData(tszURL, &szData, NULL, hwndDlg);
if (szData) {
@@ -35,7 +35,7 @@ TCHAR *CheckFeed(TCHAR *tszURL, HWND hwndDlg)
if (hXml != NULL) {
int childcount = 0;
HXML node;
- if ( !lstrcmpi(xi.getName(hXml), _T("xml")))
+ if (!lstrcmpi(xi.getName(hXml), _T("xml")))
node = xi.getChild(hXml, childcount);
else
node = hXml;
@@ -48,7 +48,7 @@ TCHAR *CheckFeed(TCHAR *tszURL, HWND hwndDlg)
if (!lstrcmpi(xi.getName(child), _T("title"))) {
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK|MB_ICONINFORMATION);
+ MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
TCHAR *tszTitle = (TCHAR *)xi.getText(child);
return tszTitle;
}
@@ -60,7 +60,7 @@ TCHAR *CheckFeed(TCHAR *tszURL, HWND hwndDlg)
if (!lstrcmpi(xi.getName(child), _T("title"))) {
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK|MB_ICONINFORMATION);
+ MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONINFORMATION);
TCHAR *tszTitle = (TCHAR *)xi.getText(child);
return tszTitle;
}
@@ -71,683 +71,522 @@ TCHAR *CheckFeed(TCHAR *tszURL, HWND hwndDlg)
}
xi.destroyNode(hXml);
}
- Netlib_LogfT(hNetlibUser,_T("%s is not a valid feed's address."),tszURL);
+ Netlib_LogfT(hNetlibUser, _T("%s is not a valid feed's address."), tszURL);
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis not a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK|MB_ICONERROR);
+ MessageBox(hwndDlg, mes, TranslateT("News Aggregator"), MB_OK | MB_ICONERROR);
return NULL;
}
+static void XmlToMsg(MCONTACT hContact, CMString &title, CMString &link, CMString &descr, CMString &author, CMString &comments, CMString &guid, CMString &category, time_t stamp)
+{
+ TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
+ if (!message)
+ message = mir_tstrdup(TAGSDEFAULT);
+
+ if (!title.IsEmpty())
+ StrReplace(_T("#<title>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<title>#"), title, message);
+
+ if (!link.IsEmpty())
+ StrReplace(_T("#<link>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<link>#"), link, message);
+
+ if (!descr.IsEmpty())
+ StrReplace(_T("#<description>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<description>#"), descr, message);
+
+ if (!author.IsEmpty())
+ StrReplace(_T("#<author>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<author>#"), author, message);
+
+ if (!comments.IsEmpty())
+ StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<comments>#"), comments, message);
+
+ if (!guid.IsEmpty())
+ StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<guid>#"), guid, message);
+
+ if (!category.IsEmpty())
+ StrReplace(_T("#<category>#"), TranslateT("empty"), message);
+ else
+ StrReplace(_T("#<category>#"), category, message);
+
+ if (stamp == 0)
+ stamp = time(NULL);
+
+ DBEVENTINFO olddbei = { 0 };
+ olddbei.cbSize = sizeof(olddbei);
+
+ bool MesExist = false;
+ ptrA pszTemp(mir_utf8encodeT(message));
+ DWORD cbMemoLen = 10000, cbOrigLen = lstrlenA(pszTemp);
+ BYTE *pbBuffer = (BYTE*)mir_alloc(cbMemoLen);
+ for (HANDLE hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) {
+ olddbei.cbBlob = db_event_getBlobSize(hDbEvent);
+ if (olddbei.cbBlob > cbMemoLen)
+ pbBuffer = (PBYTE)mir_realloc(pbBuffer, cbMemoLen = olddbei.cbBlob);
+ olddbei.pBlob = pbBuffer;
+ db_event_get(hDbEvent, &olddbei);
+
+ if (olddbei.cbBlob == cbOrigLen + 1 && !lstrcmpA((char*)olddbei.pBlob, pszTemp)) {
+ MesExist = true;
+ break;
+ }
+ }
+ mir_free(pbBuffer);
+
+ if (!MesExist) {
+ PROTORECVEVENT recv = { 0 };
+ recv.flags = PREF_TCHAR;
+ recv.timestamp = stamp;
+ recv.tszMessage = message;
+ ProtoChainRecvMsg(hContact, &recv);
+ }
+ mir_free(message);
+}
+
void CheckCurrentFeed(MCONTACT hContact)
{
// Check is disabled by the user?
- if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
-
- TCHAR *szURL = db_get_tsa(hContact, MODULE, "URL");
- if (szURL == NULL)
- return;
-
- Netlib_LogfT(hNetlibUser,_T("Started checking feed %s."),szURL);
- char *szData = NULL;
- GetNewsData(szURL, &szData, hContact, NULL);
- mir_free(szURL);
- if (szData) {
- TCHAR *tszData = mir_utf8decodeT(szData);
- if (!tszData)
- tszData = mir_a2t(szData);
- int bytesParsed = 0;
- HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
- mir_free(tszData);
- mir_free(szData);
- if(hXml != NULL) {
- int childcount = 0;
- HXML node;
- if (!lstrcmpi(xi.getName(hXml), _T("xml")))
- node = xi.getChild(hXml, childcount);
- else
- node = hXml;
- while (node) {
- LPCTSTR szNodeName = xi.getName(node);
- bool isRSS = !lstrcmpi(szNodeName, _T("rss")), isAtom = !lstrcmpi(szNodeName, _T("rdf"));
- if (isRSS || isAtom) {
- if (isRSS) {
- for (int i = 0; i < xi.getAttrCount(node); i++) {
- LPCTSTR szAttrName = xi.getAttrName(node, i);
- if (!lstrcmpi(szAttrName, _T("version"))) {
- TCHAR ver[MAX_PATH];
- mir_sntprintf(ver, SIZEOF(ver), _T("RSS %s"), xi.getAttrValue(node, szAttrName));
- db_set_ts(hContact, MODULE, "MirVer", ver);
- break;
- }
+ if (!db_get_b(hContact, MODULE, "CheckState", 1) != 0)
+ return;
+
+ TCHAR *szURL = db_get_tsa(hContact, MODULE, "URL");
+ if (szURL == NULL)
+ return;
+
+ Netlib_LogfT(hNetlibUser, _T("Started checking feed %s."), szURL);
+
+ char *szData = NULL;
+ GetNewsData(szURL, &szData, hContact, NULL);
+ mir_free(szURL);
+
+ if (szData) {
+ TCHAR *tszData = mir_utf8decodeT(szData);
+ if (!tszData)
+ tszData = mir_a2t(szData);
+ int bytesParsed = 0;
+ HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
+ mir_free(tszData);
+ mir_free(szData);
+
+ CMString szValue;
+ if (hXml != NULL) {
+ int childcount = 0;
+ HXML node;
+ if (!lstrcmpi(xi.getName(hXml), _T("xml")))
+ node = xi.getChild(hXml, childcount);
+ else
+ node = hXml;
+ while (node) {
+ LPCTSTR szNodeName = xi.getName(node);
+ bool isRSS = !lstrcmpi(szNodeName, _T("rss")), isAtom = !lstrcmpi(szNodeName, _T("rdf"));
+ if (isRSS || isAtom) {
+ if (isRSS) {
+ for (int i = 0; i < xi.getAttrCount(node); i++) {
+ LPCTSTR szAttrName = xi.getAttrName(node, i);
+ if (!lstrcmpi(szAttrName, _T("version"))) {
+ TCHAR ver[MAX_PATH];
+ mir_sntprintf(ver, SIZEOF(ver), _T("RSS %s"), xi.getAttrValue(node, szAttrName));
+ db_set_ts(hContact, MODULE, "MirVer", ver);
+ break;
}
}
- else if (isAtom)
- db_set_ts(hContact, MODULE, "MirVer", _T("RSS 1.0"));
-
- HXML chan = xi.getChild(node, 0);
- for (int j = 0; j < xi.getChildCount(chan); j++) {
- HXML child = xi.getChild(chan, j);
- LPCTSTR childName = xi.getName(child);
- if (!lstrcmpi(childName, _T("title"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "FirstName", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("link"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "Homepage", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("description"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "About", string);
- db_set_ts(hContact, "CList", "StatusMsg", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("language"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "Language1", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("managingEditor"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "e-mail", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("category"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "Interest0Text", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("copyright"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_s(hContact, "UserInfo", "MyNotes", _T2A(string));
- mir_free(string);
- }
- }
- else if (!lstrcmpi(childName, _T("image"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML imageval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
- LPCTSTR url = xi.getText(imageval);
- db_set_ts(hContact, MODULE, "ImageURL", url);
-
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
+ }
+ else if (isAtom)
+ db_set_ts(hContact, MODULE, "MirVer", _T("RSS 1.0"));
- TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
- if (szNick) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = ProtoGetAvatarFormat(url);
-
- TCHAR *filename = szNick;
- StrReplace(_T("/"), _T("_"), filename);
- mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
- CreateDirectoryTreeT(tszRoot);
- if (DownloadFile(url, pai.filename)) {
- db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
- ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE) &pai, NULL);
- }
- else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
- mir_free(szNick);
- break;
+ HXML chan = xi.getChild(node, 0);
+ for (int j = 0; j < xi.getChildCount(chan); j++) {
+ HXML child = xi.getChild(chan, j);
+ LPCTSTR childName = xi.getName(child);
+ if (!lstrcmpi(childName, _T("title"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "FirstName", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(childName, _T("link"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "Homepage", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(childName, _T("description"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText) {
+ ClearText(szValue, szChildText);
+ db_set_ts(hContact, MODULE, "About", szValue);
+ db_set_ts(hContact, "CList", "StatusMsg", szValue);
+ }
+ }
+ else if (!lstrcmpi(childName, _T("language"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "Language1", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(childName, _T("managingEditor"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "e-mail", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(childName, _T("category"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "Interest0Text", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(childName, _T("copyright"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_s(hContact, "UserInfo", "MyNotes", _T2A(ClearText(szValue, szChildText)));
+ }
+ else if (!lstrcmpi(childName, _T("image"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML imageval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
+ LPCTSTR url = xi.getText(imageval);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
+
+ PROTO_AVATAR_INFORMATIONT pai = { NULL };
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = ProtoGetAvatarFormat(url);
+
+ TCHAR *filename = szNick;
+ StrReplace(_T("/"), _T("_"), filename);
+ mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
+ CreateDirectoryTreeT(tszRoot);
+ if (DownloadFile(url, pai.filename)) {
+ db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
+ ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, NULL);
}
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&pai, NULL);
+ mir_free(szNick);
+ break;
}
}
}
- else if (!lstrcmpi(childName, _T("lastBuildDate"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *lastupdtime = (TCHAR *)xi.getText(child);
- time_t stamp = DateToUnixTime(lastupdtime, 0);
- double deltaupd = difftime(time(NULL), stamp);
- double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
- if (deltaupd - deltacheck >= 0) {
- db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
- xi.destroyNode(hXml);
- return;
- }
+ }
+ else if (!lstrcmpi(childName, _T("lastBuildDate"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText) {
+ TCHAR *lastupdtime = (TCHAR *)xi.getText(child);
+ time_t stamp = DateToUnixTime(lastupdtime, 0);
+ double deltaupd = difftime(time(NULL), stamp);
+ double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
+ if (deltaupd - deltacheck >= 0) {
+ db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
+ xi.destroyNode(hXml);
+ return;
}
}
- else if (!lstrcmpi(childName, _T("item"))) {
- TCHAR *title = NULL, *link = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
- time_t stamp = 0;
- for (int z = 0; z < xi.getChildCount(child); z++) {
- HXML itemval = xi.getChild(child, z);
- LPCTSTR itemName = xi.getName(itemval);
- // We only use the first tag for now and ignore the rest.
- if (!lstrcmpi(itemName, _T("title"))) {
- if (title == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- title = mir_tstrdup(string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("link"))) {
- if (link == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- link = mir_tstrdup(string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("pubDate")) || !lstrcmpi(itemName, _T("dc:date"))) {
- if (stamp == 0)
- stamp = DateToUnixTime((TCHAR *)xi.getText(itemval), 0);
- }
- else if (!lstrcmpi(itemName, _T("description")) || !lstrcmpi(itemName, _T("encoded"))) {
- if (descr == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- descr = mir_tstrdup(string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("author"))) {
- if (author == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- author = mir_tstrdup(string);
- if (1 == _stscanf(author, _T("%*s (%[^ \t\r\n)]s)"), string))
- replaceStrT(author, string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("comments"))) {
- if (comments == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- comments = mir_tstrdup(string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("guid"))) {
- if (guid == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = mir_tstrdup(string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(itemName, _T("category"))) {
- if (category == NULL) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- category = mir_tstrdup(string);
- mir_free(string);
- }
- }
+ }
+ else if (!lstrcmpi(childName, _T("item"))) {
+ CMString title, link, descr, author, comments, guid, category;
+ time_t stamp = 0;
+ for (int z = 0; z < xi.getChildCount(child); z++) {
+ HXML itemval = xi.getChild(child, z);
+ LPCTSTR itemName = xi.getName(itemval);
+ // We only use the first tag for now and ignore the rest.
+ if (!lstrcmpi(itemName, _T("title")))
+ ClearText(title, xi.getText(itemval));
+
+ else if (!lstrcmpi(itemName, _T("link")))
+ ClearText(link, xi.getText(itemval));
+
+ else if (!lstrcmpi(itemName, _T("pubDate")) || !lstrcmpi(itemName, _T("dc:date"))) {
+ if (stamp == 0)
+ stamp = DateToUnixTime(xi.getText(itemval), 0);
}
+ else if (!lstrcmpi(itemName, _T("description")) || !lstrcmpi(itemName, _T("encoded")))
+ ClearText(descr, xi.getText(itemval));
- TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
- if (!message)
- message = mir_tstrdup(TAGSDEFAULT);
+ else if (!lstrcmpi(itemName, _T("author")))
+ ClearText(author, xi.getText(itemval));
- if (!title)
- StrReplace(_T("#<title>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<title>#"), title, message);
- mir_free(title);
- }
- if (!link)
- StrReplace(_T("#<link>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<link>#"), link, message);
- mir_free(link);
- }
- if (!descr)
- StrReplace(_T("#<description>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<description>#"), descr, message);
- mir_free(descr);
- }
- if (!author)
- StrReplace(_T("#<author>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<author>#"), author, message);
- mir_free(author);
- }
- if (!comments)
- StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<comments>#"), comments, message);
- mir_free(comments);
- }
- if (!guid)
- StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<guid>#"), guid, message);
- mir_free(guid);
- }
- if (!category)
- StrReplace(_T("#<category>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<category>#"), category, message);
- mir_free(category);
- }
+ else if (!lstrcmpi(itemName, _T("comments")))
+ ClearText(comments, xi.getText(itemval));
- DBEVENTINFO olddbei = { 0 };
- olddbei.cbSize = sizeof(olddbei);
-
- bool MesExist = false;
- ptrA pszTemp(mir_utf8encodeT(message));
- DWORD cbMemoLen = 10000, cbOrigLen = lstrlenA(pszTemp);
- BYTE *pbBuffer = (BYTE*)mir_alloc(cbMemoLen);
- for (HANDLE hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) {
- olddbei.cbBlob = db_event_getBlobSize(hDbEvent);
- if (olddbei.cbBlob > cbMemoLen)
- pbBuffer = (PBYTE)mir_realloc(pbBuffer, cbMemoLen = olddbei.cbBlob);
- olddbei.pBlob = pbBuffer;
- db_event_get(hDbEvent, &olddbei);
-
- if (olddbei.cbBlob == cbOrigLen+1 && !lstrcmpA((char*)olddbei.pBlob, pszTemp)) {
- MesExist = true;
- break;
- }
- }
- mir_free(pbBuffer);
+ else if (!lstrcmpi(itemName, _T("guid")))
+ ClearText(guid, xi.getText(itemval));
- if (!MesExist) {
- if (stamp == 0)
- stamp = time(NULL);
- PROTORECVEVENT recv = { 0 };
- recv.flags = PREF_TCHAR;
- recv.timestamp = stamp;
- recv.tszMessage = message;
- ProtoChainRecvMsg(hContact, &recv);
- }
- mir_free(message);
+ else if (!lstrcmpi(itemName, _T("category")))
+ ClearText(category, xi.getText(itemval));
}
+
+ XmlToMsg(hContact, title, link, descr, author, comments, guid, category, stamp);
}
}
- else if (!lstrcmpi(szNodeName, _T("feed"))) {
- db_set_ts(hContact, MODULE, "MirVer", _T("Atom 3"));
- for (int j = 0; j < xi.getChildCount(node); j++) {
- HXML child = xi.getChild(node, j);
- LPCTSTR szChildName = xi.getName(child);
- if (!lstrcmpi(szChildName, _T("title"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "FirstName", string);
- mir_free(string);
- }
- }
- else if (!lstrcmpi(szChildName, _T("link"))) {
- for (int x = 0; x < xi.getAttrCount(child); x++) {
- if (!lstrcmpi(xi.getAttrName(child, x), _T("rel")))
- if (!lstrcmpi(xi.getAttrValue(child, xi.getAttrName(child, x)), _T("self")))
- break;
+ }
+ else if (!lstrcmpi(szNodeName, _T("feed"))) {
+ db_set_ts(hContact, MODULE, "MirVer", _T("Atom 3"));
+ for (int j = 0; j < xi.getChildCount(node); j++) {
+ HXML child = xi.getChild(node, j);
+ LPCTSTR szChildName = xi.getName(child);
+ if (!lstrcmpi(szChildName, _T("title"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "FirstName", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(szChildName, _T("link"))) {
+ for (int x = 0; x < xi.getAttrCount(child); x++) {
+ if (!lstrcmpi(xi.getAttrName(child, x), _T("rel")))
+ if (!lstrcmpi(xi.getAttrValue(child, xi.getAttrName(child, x)), _T("self")))
+ break;
- if (!lstrcmpi(xi.getAttrName(child, x), _T("href")))
- db_set_ts(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
- }
+ if (!lstrcmpi(xi.getAttrName(child, x), _T("href")))
+ db_set_ts(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
}
- else if (!lstrcmpi(szChildName, _T("subtitle"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "About", string);
- db_set_ts(hContact, "CList", "StatusMsg", string);
- mir_free(string);
- }
+ }
+ else if (!lstrcmpi(szChildName, _T("subtitle"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText) {
+ ClearText(szValue, szChildText);
+ db_set_ts(hContact, MODULE, "About", szValue);
+ db_set_ts(hContact, "CList", "StatusMsg", szValue);
}
- else if (!lstrcmpi(szChildName, _T("language"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "Language1", string);
- mir_free(string);
+ }
+ else if (!lstrcmpi(szChildName, _T("language"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "Language1", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(szChildName, _T("author"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML authorval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(authorval), _T("email"))) {
+ db_set_ts(hContact, MODULE, "e-mail", xi.getText(authorval));
+ break;
}
}
- else if (!lstrcmpi(szChildName, _T("author"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML authorval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(authorval), _T("email"))) {
- db_set_ts(hContact, MODULE, "e-mail", xi.getText(authorval));
+ }
+ else if (!lstrcmpi(szChildName, _T("category"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText)
+ db_set_ts(hContact, MODULE, "Interest0Text", ClearText(szValue, szChildText));
+ }
+ else if (!lstrcmpi(szChildName, _T("icon"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML imageval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
+ LPCTSTR url = xi.getText(imageval);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
+
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
+ PROTO_AVATAR_INFORMATIONT pai = { NULL };
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = ProtoGetAvatarFormat(ext);
+
+ TCHAR *filename = szNick;
+ mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
+ if (DownloadFile(url, pai.filename)) {
+ db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
+ ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, NULL);
+ }
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&pai, NULL);
+ mir_free(szNick);
break;
}
}
}
- else if (!lstrcmpi(szChildName, _T("category"))) {
- LPCTSTR szChildText = xi.getText(child);
- if (szChildText) {
- TCHAR *string = mir_tstrdup(szChildText);
- ClearText(string);
- db_set_ts(hContact, MODULE, "Interest0Text", string);
- mir_free(string);
+ }
+ else if (!lstrcmpi(szChildName, _T("updated"))) {
+ LPCTSTR szChildText = xi.getText(child);
+ if (szChildText) {
+ TCHAR *lastupdtime = (TCHAR *)szChildText;
+ time_t stamp = DateToUnixTime(lastupdtime, 1);
+ double deltaupd = difftime(time(NULL), stamp);
+ double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
+ if (deltaupd - deltacheck >= 0) {
+ db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
+ xi.destroyNode(hXml);
+ return;
}
}
- else if (!lstrcmpi(szChildName, _T("icon"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML imageval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
- LPCTSTR url = xi.getText(imageval);
- db_set_ts(hContact, MODULE, "ImageURL", url);
-
- TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
- if (szNick) {
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = ProtoGetAvatarFormat(ext);
-
- TCHAR *filename = szNick;
- mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
- if (DownloadFile(url, pai.filename)) {
- db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
- ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE) &pai, NULL);
- }
- else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
- mir_free(szNick);
+ }
+ else if (!lstrcmpi(szChildName, _T("entry"))) {
+ CMString title, link, descr, author, comments, guid, category;
+ time_t stamp = 0;
+ for (int z = 0; z < xi.getChildCount(child); z++) {
+ HXML itemval = xi.getChild(child, z);
+ LPCTSTR szItemName = xi.getName(itemval);
+ if (!lstrcmpi(szItemName, _T("title"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText)
+ ClearText(title, szItemText);
+ }
+ else if (!lstrcmpi(szItemName, _T("link"))) {
+ for (int x = 0; x < xi.getAttrCount(itemval); x++) {
+ if (!lstrcmpi(xi.getAttrName(itemval, x), _T("href"))) {
+ ClearText(link, xi.getAttrValue(itemval, xi.getAttrName(itemval, x)));
break;
}
}
}
- }
- else if (!lstrcmpi(szChildName, _T("updated"))) {
- LPCTSTR szChildText = xi.getText(child);
- if(szChildText) {
- TCHAR *lastupdtime = (TCHAR *)szChildText;
- time_t stamp = DateToUnixTime(lastupdtime, 1);
- double deltaupd = difftime(time(NULL), stamp);
- double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
- if (deltaupd - deltacheck >= 0) {
- db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
- xi.destroyNode(hXml);
- return;
- }
- }
- }
- else if (!lstrcmpi(szChildName, _T("entry"))) {
- TCHAR *title = NULL, *link = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
- time_t stamp = 0;
- for (int z = 0; z < xi.getChildCount(child); z++) {
- HXML itemval = xi.getChild(child, z);
- LPCTSTR szItemName = xi.getName(itemval);
- if (!lstrcmpi(szItemName, _T("title"))) {
- LPCTSTR szItemText = xi.getText(itemval);
- if (szItemText) {
- TCHAR *string = mir_tstrdup(szItemText);
- ClearText(string);
- title = string;
- }
- }
- else if (!lstrcmpi(szItemName, _T("link"))) {
- for (int x = 0; x < xi.getAttrCount(itemval); x++) {
- if (!lstrcmpi(xi.getAttrName(itemval, x), _T("href"))) {
- TCHAR *string = mir_tstrdup(xi.getAttrValue(itemval, xi.getAttrName(itemval, x)));
- ClearText(string);
- link = string;
- break;
- }
- }
- }
- else if (!lstrcmpi(szItemName, _T("updated"))) {
- if (stamp == 0)
- stamp = DateToUnixTime((TCHAR *)xi.getText(itemval), 0);
- }
- else if (!lstrcmpi(szItemName, _T("summary")) || !lstrcmpi(szItemName, _T("content"))) {
- LPCTSTR szItemText = xi.getText(itemval);
- if (szItemText) {
- TCHAR *string = mir_tstrdup(szItemText);
- ClearText(string);
- descr = string;
- }
- }
- else if (!lstrcmpi(szItemName, _T("author"))) {
- for (int x = 0; x < xi.getChildCount(itemval); x++) {
- HXML authorval = xi.getChild(itemval, x);
- if (!lstrcmpi(xi.getName(authorval), _T("name")) && xi.getText(authorval)) {
- TCHAR *string = mir_tstrdup(xi.getText(authorval));
- ClearText(string);
- author = string;
- break;
- }
- }
- }
- else if (!lstrcmpi(szItemName, _T("comments"))) {
- LPCTSTR szItemText = xi.getText(itemval);
- if (szItemText) {
- TCHAR *string = mir_tstrdup(szItemText);
- ClearText(string);
- comments = string;
- }
- }
- else if (!lstrcmpi(szItemName, _T("id"))) {
- LPCTSTR szItemText = xi.getText(itemval);
- if (szItemText) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = string;
+ else if (!lstrcmpi(szItemName, _T("updated"))) {
+ if (stamp == 0)
+ stamp = DateToUnixTime(xi.getText(itemval), 0);
+ }
+ else if (!lstrcmpi(szItemName, _T("summary")) || !lstrcmpi(szItemName, _T("content"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText)
+ ClearText(descr, szItemText);
+ }
+ else if (!lstrcmpi(szItemName, _T("author"))) {
+ for (int x = 0; x < xi.getChildCount(itemval); x++) {
+ HXML authorval = xi.getChild(itemval, x);
+ if (!lstrcmpi(xi.getName(authorval), _T("name")) && xi.getText(authorval)) {
+ ClearText(author, xi.getText(authorval));
+ break;
}
}
- else if (!lstrcmpi(szItemName, _T("category"))) {
- for (int x = 0; x < xi.getAttrCount(itemval); x++) {
- LPCTSTR szAttrName = xi.getAttrName(itemval, x);
- if (!lstrcmpi(szAttrName, _T("term")) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getAttrValue(itemval, szAttrName));
- ClearText(string);
- category = string;
- break;
- }
+ }
+ else if (!lstrcmpi(szItemName, _T("comments"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText)
+ ClearText(comments, szItemText);
+ }
+ else if (!lstrcmpi(szItemName, _T("id"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText)
+ ClearText(guid, xi.getText(itemval));
+ }
+ else if (!lstrcmpi(szItemName, _T("category"))) {
+ for (int x = 0; x < xi.getAttrCount(itemval); x++) {
+ LPCTSTR szAttrName = xi.getAttrName(itemval, x);
+ if (!lstrcmpi(szAttrName, _T("term")) && xi.getText(itemval)) {
+ ClearText(category, xi.getAttrValue(itemval, szAttrName));
+ break;
}
}
}
-
- TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
- if (!message)
- message = mir_tstrdup(TAGSDEFAULT);
-
- if (!title)
- StrReplace(_T("#<title>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<title>#"), title, message);
- mir_free(title);
- }
- if (!link)
- StrReplace(_T("#<link>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<link>#"), link, message);
- mir_free(link);
- }
- if (!descr)
- StrReplace(_T("#<description>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<description>#"), descr, message);
- mir_free(descr);
- }
- if (!author)
- StrReplace(_T("#<author>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<author>#"), author, message);
- mir_free(author);
- }
- if (!comments)
- StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<comments>#"), comments, message);
- mir_free(comments);
- }
- if (!guid)
- StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<guid>#"), guid, message);
- mir_free(guid);
- }
- if (!category)
- StrReplace(_T("#<category>#"), TranslateT("empty"), message);
- else {
- StrReplace(_T("#<category>#"), category, message);
- mir_free(category);
- }
-
-
- bool MesExist = false;
- ptrA pszTemp(mir_utf8encodeT(message));
- for (HANDLE hDbEvent = db_event_first(hContact);hDbEvent;hDbEvent = db_event_next(hContact, hDbEvent)) {
- DBEVENTINFO olddbei = { sizeof(olddbei) };
- olddbei.cbBlob = db_event_getBlobSize(hDbEvent);
- olddbei.pBlob = (PBYTE)mir_alloc(olddbei.cbBlob);
- db_event_get(hDbEvent, &olddbei);
- if (olddbei.cbBlob == lstrlenA(pszTemp) + 1 && !lstrcmpA((char *)olddbei.pBlob, pszTemp))
- MesExist = true;
-
- mir_free(olddbei.pBlob);
- if (MesExist)
- break;
- }
-
- if (!MesExist) {
- PROTORECVEVENT recv = { 0 };
- recv.flags = PREF_TCHAR;
- recv.timestamp = (stamp == 0) ? time(NULL) : stamp;
- recv.tszMessage = message;
- ProtoChainRecvMsg(hContact, &recv);
- }
- mir_free(message);
}
+
+ XmlToMsg(hContact, title, link, descr, author, comments, guid, category, stamp);
}
}
- node = xi.getChild(hXml, ++childcount);
}
- xi.destroyNode(hXml);
+ node = xi.getChild(hXml, ++childcount);
}
+ xi.destroyNode(hXml);
}
- db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
}
+ db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
}
void CheckCurrentFeedAvatar(MCONTACT hContact)
{
- if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
- TCHAR *szURL = db_get_tsa(hContact, MODULE, "URL");
- if (szURL == NULL)
- return;
-
- char *szData = NULL;
- GetNewsData(szURL, &szData, hContact, NULL);
- mir_free(szURL);
-
- if (szData) {
- TCHAR *tszData = mir_utf8decodeT(szData);
- if (!tszData)
- tszData = mir_a2t(szData);
- int bytesParsed = 0;
- HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
- mir_free(tszData);
- mir_free(szData);
- if(hXml != NULL) {
- int childcount = 0;
- HXML node = xi.getChild(hXml, childcount);
- while (node) {
- LPCTSTR szNodeName = xi.getName(node);
- if (!lstrcmpi(szNodeName, _T("rss")) || !lstrcmpi(szNodeName, _T("rdf"))) {
- HXML chan = xi.getChild(node, 0);
- for (int j = 0; j < xi.getChildCount(chan); j++) {
- HXML child = xi.getChild(chan, j);
- if (!lstrcmpi(xi.getName(child), _T("image"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML imageval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
- LPCTSTR url = xi.getText(imageval);
- db_set_ts(hContact, MODULE, "ImageURL", url);
-
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
+ if (!db_get_b(hContact, MODULE, "CheckState", 1))
+ return;
- TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
- if (szNick) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = ProtoGetAvatarFormat(ext);
-
- TCHAR *filename = szNick;
- mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
- if (DownloadFile(url, pai.filename)) {
- db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
- ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE) &pai, NULL);
- }
- else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
- mir_free(szNick);
- break;
- }
- }
- }
+ TCHAR *szURL = db_get_tsa(hContact, MODULE, "URL");
+ if (szURL == NULL)
+ return;
+
+ char *szData = NULL;
+ GetNewsData(szURL, &szData, hContact, NULL);
+ mir_free(szURL);
+
+ if (szData == NULL)
+ return;
+
+ TCHAR *tszData = mir_utf8decodeT(szData);
+ if (!tszData)
+ tszData = mir_a2t(szData);
+ int bytesParsed = 0;
+ HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
+ mir_free(tszData);
+ mir_free(szData);
+ if (hXml == NULL)
+ return;
+
+ int childcount = 0;
+ HXML node = xi.getChild(hXml, childcount);
+ while (node) {
+ LPCTSTR szNodeName = xi.getName(node);
+ if (!lstrcmpi(szNodeName, _T("rss")) || !lstrcmpi(szNodeName, _T("rdf"))) {
+ HXML chan = xi.getChild(node, 0);
+ for (int j = 0; j < xi.getChildCount(chan); j++) {
+ HXML child = xi.getChild(chan, j);
+ if (!lstrcmpi(xi.getName(child), _T("image"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML imageval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
+ LPCTSTR url = xi.getText(imageval);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
+
+ PROTO_AVATAR_INFORMATIONT pai = { NULL };
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = ProtoGetAvatarFormat(ext);
+
+ TCHAR *filename = szNick;
+ mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
+ if (DownloadFile(url, pai.filename)) {
+ db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
+ ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, NULL);
+ }
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&pai, NULL);
+ mir_free(szNick);
+ break;
}
}
}
- else if (!lstrcmpi(szNodeName, _T("feed"))) {
- for (int j = 0; j < xi.getChildCount(node); j++) {
- HXML child = xi.getChild(node, j);
- if (!lstrcmpi(xi.getName(child), _T("icon"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML imageval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
- LPCTSTR url = xi.getText(imageval);
- db_set_ts(hContact, MODULE, "ImageURL", url);
-
- TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
- if (szNick) {
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
-
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = ProtoGetAvatarFormat(ext);
-
- TCHAR *filename = szNick;
- mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
- if (DownloadFile(url, pai.filename)) {
- db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
- ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE) &pai, NULL);
- }
- else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
- mir_free(szNick);
- break;
- }
- }
- }
+ }
+ }
+ }
+ else if (!lstrcmpi(szNodeName, _T("feed"))) {
+ for (int j = 0; j < xi.getChildCount(node); j++) {
+ HXML child = xi.getChild(node, j);
+ if (!lstrcmpi(xi.getName(child), _T("icon"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML imageval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
+ LPCTSTR url = xi.getText(imageval);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
+
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
+ PROTO_AVATAR_INFORMATIONT pai = { NULL };
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = ProtoGetAvatarFormat(ext);
+
+ TCHAR *filename = szNick;
+ mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
+ if (DownloadFile(url, pai.filename)) {
+ db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
+ ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, NULL);
+ }
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&pai, NULL);
+ mir_free(szNick);
+ break;
}
}
}
- node = xi.getChild(hXml, ++childcount);
}
- xi.destroyNode(hXml);
}
}
+ node = xi.getChild(hXml, ++childcount);
}
-} \ No newline at end of file
+ xi.destroyNode(hXml);
+}
diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h
index 9e205709f8..b9407e7c85 100644
--- a/plugins/NewsAggregator/Src/Common.h
+++ b/plugins/NewsAggregator/Src/Common.h
@@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA.
#include <windows.h>
#include <commctrl.h>
#include <time.h>
+#include <malloc.h>
#include <fcntl.h>
#include <io.h>
#include <sys\stat.h>
@@ -43,6 +44,7 @@ Boston, MA 02111-1307, USA.
#include <m_folders.h>
#include <m_toptoolbar.h>
+#include <m_string.h>
#include "version.h"
#include "resource.h"
@@ -125,15 +127,15 @@ VOID GetNewsData(TCHAR *szUrl, char** szData, MCONTACT hContact, HWND hwndDlg);
VOID CreateList(HWND hwndList);
VOID UpdateList(HWND hwndList);
VOID DeleteAllItems(HWND hwndList);
-time_t __stdcall DateToUnixTime(TCHAR *stamp, BOOL FeedType);
+time_t __stdcall DateToUnixTime(const TCHAR *stamp, BOOL FeedType);
VOID CheckCurrentFeed(MCONTACT hContact);
VOID CheckCurrentFeedAvatar(MCONTACT hContact);
TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg);
void UpdateMenu(BOOL State);
int ImportFeedsDialog();
-VOID ClearText(TCHAR *&message);
+LPCTSTR ClearText(CMString &value, const TCHAR *message);
BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
-int StrReplace(TCHAR *lpszOld, TCHAR *lpszNew, TCHAR *&lpszStr);
+int StrReplace(TCHAR *lpszOld, const TCHAR *lpszNew, TCHAR *&lpszStr);
void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg);
INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/plugins/NewsAggregator/Src/Update.cpp b/plugins/NewsAggregator/Src/Update.cpp
index ec394d5fc8..36bf7d281f 100644
--- a/plugins/NewsAggregator/Src/Update.cpp
+++ b/plugins/NewsAggregator/Src/Update.cpp
@@ -122,6 +122,8 @@ void UpdateThreadProc(void *AvatarCheck)
ThreadRunning = TRUE; // prevent 2 instance of this thread running
ReleaseMutex(hUpdateMutex);
+ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+
// update news by getting the first station from the queue until the queue is empty
while (UpdateListHead != NULL && !Miranda_Terminated()) {
if ((BOOL)AvatarCheck)
@@ -132,4 +134,6 @@ void UpdateThreadProc(void *AvatarCheck)
// exit the update thread
ThreadRunning = FALSE;
+
+ CoUninitialize();
}
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 9883812253..1db0e19e4a 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -189,7 +189,7 @@ void DeleteAllItems(HWND hwndList)
ListView_DeleteAllItems(hwndList);
}
-time_t __stdcall DateToUnixTime(TCHAR *stamp, BOOL FeedType)
+time_t __stdcall DateToUnixTime(const TCHAR *stamp, BOOL FeedType)
{
struct tm timestamp;
TCHAR date[9];
@@ -199,7 +199,7 @@ time_t __stdcall DateToUnixTime(TCHAR *stamp, BOOL FeedType)
if (stamp == NULL)
return 0;
- TCHAR *p = stamp;
+ TCHAR *p = NEWTSTR_ALLOCA(stamp);
if (FeedType) {
// skip '-' chars
@@ -322,7 +322,7 @@ TCHAR * _tcsistr(const TCHAR *str, const TCHAR *substr)
return (TCHAR *)str;
}
-int StrReplace(TCHAR *lpszOld, TCHAR *lpszNew, TCHAR *&lpszStr)
+int StrReplace(TCHAR *lpszOld, const TCHAR *lpszNew, TCHAR *&lpszStr)
{
if (!lpszStr || !lpszOld || !lpszNew)
return 0;
@@ -561,17 +561,18 @@ HRESULT TestDocumentText(IHTMLDocument3 *pHtmlDoc, BSTR &message)
return hr;
}
-VOID ClearText(TCHAR *&message)
+LPCTSTR ClearText(CMString &result, const TCHAR *message)
{
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
BSTR bstrHtml = SysAllocString(message), bstrRes = SysAllocString(L"");
HRESULT hr = TestMarkupServices(bstrHtml, &TestDocumentText, bstrRes);
- if ( SUCCEEDED(hr)) {
- replaceStrT(message, bstrRes);
+ if (SUCCEEDED(hr)) {
+ result = bstrRes;
SysFreeString(bstrRes);
}
+ else result = message;
SysFreeString(bstrHtml);
- CoUninitialize();
+
+ return result;
}
MCONTACT GetContactByNick(const TCHAR *nick)
@@ -596,4 +597,4 @@ MCONTACT GetContactByURL(const TCHAR *url)
break;
}
return hContact;
-} \ No newline at end of file
+}