summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator/Src/CheckFeed.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewsAggregator/Src/CheckFeed.cpp')
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp577
1 files changed, 307 insertions, 270 deletions
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index ebdb806acd..d357599a1b 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -19,10 +19,10 @@ 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);
char *szData = NULL;
- DBVARIANT dbVar = {0};
GetNewsData(tszURL, &szData, NULL, hwndDlg);
if (szData) {
TCHAR *tszData = mir_utf8decodeT(szData);
@@ -40,7 +40,8 @@ TCHAR * CheckFeed(TCHAR *tszURL, HWND hwndDlg)
else
node = hXml;
while (node) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf"))) {
+ 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);
@@ -53,7 +54,7 @@ TCHAR * CheckFeed(TCHAR *tszURL, HWND hwndDlg)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed"))) {
+ 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("title"))) {
@@ -65,28 +66,31 @@ TCHAR * CheckFeed(TCHAR *tszURL, HWND hwndDlg)
}
}
}
- childcount +=1;
- node = xi.getChild(hXml, childcount);
+ node = xi.getChild(hXml, ++childcount);
}
}
xi.destroyNode(hXml);
}
+ 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);
return NULL;
}
-VOID CheckCurrentFeed(MCONTACT hContact)
+void CheckCurrentFeed(MCONTACT hContact)
{
- char *szData = NULL;
- DBVARIANT dbURL = {0};
- if (db_get_ts(hContact, MODULE, "URL", &dbURL))
- return;
-
+ // Check is disabled by the user?
if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
- GetNewsData(dbURL.ptszVal, &szData, hContact, NULL);
- db_free(&dbURL);
+
+ 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)
@@ -98,79 +102,97 @@ VOID CheckCurrentFeed(MCONTACT hContact)
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;
while (node) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf"))) {
- if (!lstrcmpi(xi.getName(node), _T("rss"))) {
+ 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++) {
- if (!lstrcmpi(xi.getAttrName(node, i), _T("version"))) {
+ 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, xi.getAttrName(node, i)));
+ mir_sntprintf(ver, SIZEOF(ver), _T("RSS %s"), xi.getAttrValue(node, szAttrName));
db_set_ts(hContact, MODULE, "MirVer", ver);
break;
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("rdf")))
+ 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);
- if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "FirstName", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("link")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "Homepage", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("description")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "About", string);
- db_set_ts(hContact, "CList", "StatusMsg", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "Language1", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("managingEditor")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "e-mail", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "Interest0Text", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("copyright")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_s(hContact, "UserInfo", "MyNotes", _T2A(string));
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("image"))) {
+ 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"))) {
@@ -180,13 +202,13 @@ VOID CheckCurrentFeed(MCONTACT hContact)
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
- DBVARIANT dbVar = {0};
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
pai.format = ProtoGetAvatarFormat(url);
- TCHAR *filename = dbVar.ptszVal;
+ TCHAR *filename = szNick;
StrReplace(_T("/"), _T("_"), filename);
mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
CreateDirectoryTreeT(tszRoot);
@@ -195,37 +217,42 @@ VOID CheckCurrentFeed(MCONTACT hContact)
ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE) &pai, NULL);
}
else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
- db_free(&dbVar);
+ mir_free(szNick);
break;
}
}
}
}
- if (!lstrcmpi(xi.getName(child), _T("lastBuildDate")) && xi.getText(child)) {
- 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;
- }
- continue;
+ 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;
+ }
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("item"))) {
- TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
+ 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);
- TCHAR *tmp = (TCHAR*)xi.getName(itemval);
- if (!lstrcmpi(xi.getName(itemval), _T("title"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- title = mir_tstrdup(string);
- mir_free(string);
+ 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(xi.getName(itemval), _T("link"))) {
- // We only use the first <link> tag for now and ignore the rest.
+ else if (!lstrcmpi(itemName, _T("link"))) {
if (link == NULL) {
TCHAR *string = mir_tstrdup(xi.getText(itemval));
ClearText(string);
@@ -233,52 +260,58 @@ VOID CheckCurrentFeed(MCONTACT hContact)
mir_free(string);
}
}
- else if (!lstrcmpi(xi.getName(itemval), _T("pubDate"))) {
- datetime = (TCHAR *)xi.getText(itemval);
- }
- else if (!lstrcmpi(xi.getName(itemval), _T("dc:date"))) {
- datetime = (TCHAR *)xi.getText(itemval);
+ else if (!lstrcmpi(itemName, _T("pubDate")) || !lstrcmpi(itemName, _T("dc:date"))) {
+ if (stamp == 0)
+ stamp = DateToUnixTime((TCHAR *)xi.getText(itemval), 0);
}
- else if (!lstrcmpi(xi.getName(itemval), _T("description")) || !lstrcmpi(xi.getName(itemval), _T("encoded"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- descr = mir_tstrdup(string);
- mir_free(string);
+ 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(xi.getName(itemval), _T("author"))) {
- 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("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(xi.getName(itemval), _T("comments"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- comments = mir_tstrdup(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(xi.getName(itemval), _T("guid"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = 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(xi.getName(itemval), _T("category"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- category = 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);
+ }
}
}
- TCHAR *message;
- DBVARIANT dbMsg = {0};
- if (db_get_ts(hContact, MODULE, "MsgFormat", &dbMsg))
- message = _T(TAGSDEFAULT);
- else
- message = mir_tstrdup(dbMsg.ptszVal);
- db_free(&dbMsg);
+
+ TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
+ if (!message)
+ message = mir_tstrdup(TAGSDEFAULT);
+
if (!title)
StrReplace(_T("#<title>#"), TranslateT("empty"), message);
else {
@@ -322,30 +355,26 @@ VOID CheckCurrentFeed(MCONTACT hContact)
mir_free(category);
}
- time_t stamp;
- if (!datetime)
- stamp = time(NULL);
- else
- stamp = DateToUnixTime(datetime, 0);
-
- HANDLE hDbEvent = db_event_first(hContact);
- BOOL MesExist = FALSE;
- while (hDbEvent) {
+ 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);
char *pszTemp = mir_utf8encodeT(message);
if (olddbei.cbBlob == lstrlenA(pszTemp) + 1 && !lstrcmpA((char *)olddbei.pBlob, pszTemp)) {
- MesExist = TRUE;
- break;
+ MesExist = true;
}
- hDbEvent = db_event_next(hContact, hDbEvent);
+
mir_free(olddbei.pBlob);
- mir_free(pszTemp);
+ if (MesExist)
+ break;
}
if (!MesExist) {
+ if (stamp == 0)
+ stamp = time(NULL);
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_TCHAR;
recv.timestamp = stamp;
@@ -356,18 +385,21 @@ VOID CheckCurrentFeed(MCONTACT hContact)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed"))) {
+ 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);
- if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "FirstName", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("link"))) {
+ 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")))
@@ -376,24 +408,27 @@ VOID CheckCurrentFeed(MCONTACT hContact)
if (!lstrcmpi(xi.getAttrName(child, x), _T("href")))
db_set_ts(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
}
- continue;
}
- if (!lstrcmpi(xi.getName(child), _T("subtitle")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "About", string);
- db_set_ts(hContact, "CList", "StatusMsg", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "Language1", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("author"))) {
+ 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"))) {
@@ -401,67 +436,73 @@ VOID CheckCurrentFeed(MCONTACT hContact)
break;
}
}
- continue;
}
- if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child)) {
- TCHAR *string = mir_tstrdup(xi.getText(child));
- ClearText(string);
- db_set_ts(hContact, MODULE, "Interest0Text", string);
- mir_free(string);
- continue;
+ 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);
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("icon"))) {
+ 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);
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- DBVARIANT dbVar = {0};
-
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ 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 = dbVar.ptszVal;
+ 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);
- db_free(&dbVar);
+ mir_free(szNick);
break;
}
}
}
}
- if (!lstrcmpi(xi.getName(child), _T("updated")) && xi.getText(child)) {
- TCHAR *lastupdtime = (TCHAR *)xi.getText(child);
- 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;
- }
- continue;
+ 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;
+ }
+ }
}
- if (!lstrcmpi(xi.getName(child), _T("entry"))) {
- TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
+ 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);
- if (!lstrcmpi(xi.getName(itemval), _T("title")) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- title = string;
- continue;
+ 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;
+ }
}
- if (!lstrcmpi(xi.getName(itemval), _T("link"))) {
+ 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)));
@@ -470,19 +511,20 @@ VOID CheckCurrentFeed(MCONTACT hContact)
break;
}
}
- continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("updated"))) {
- datetime = (TCHAR *)xi.getText(itemval);
- continue;
+ else if (!lstrcmpi(szItemName, _T("updated"))) {
+ if (stamp == 0)
+ stamp = DateToUnixTime((TCHAR *)xi.getText(itemval), 0);
}
- if ((!lstrcmpi(xi.getName(itemval), _T("summary")) || !lstrcmpi(xi.getName(itemval), _T("content"))) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- descr = string;
- continue;
+ 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;
+ }
}
- if (!lstrcmpi(xi.getName(itemval), _T("author"))) {
+ 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)) {
@@ -492,39 +534,39 @@ VOID CheckCurrentFeed(MCONTACT hContact)
break;
}
}
- continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("comments")) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- comments = string;
- continue;
+ else if (!lstrcmpi(szItemName, _T("comments"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText) {
+ TCHAR *string = mir_tstrdup(szItemText);
+ ClearText(string);
+ comments = string;
+ }
}
- if (!lstrcmpi(xi.getName(itemval), _T("id"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = string;
- continue;
+ else if (!lstrcmpi(szItemName, _T("id"))) {
+ LPCTSTR szItemText = xi.getText(itemval);
+ if (szItemText) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ guid = string;
+ }
}
- if (!lstrcmpi(xi.getName(itemval), _T("category"))) {
+ else if (!lstrcmpi(szItemName, _T("category"))) {
for (int x = 0; x < xi.getAttrCount(itemval); x++) {
- if (!lstrcmpi(xi.getAttrName(itemval, x), _T("term")) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getAttrValue(itemval, xi.getAttrName(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;
}
}
- continue;
}
}
- TCHAR *message;
- DBVARIANT dbMsg = {0};
- if (db_get_ts(hContact, MODULE, "MsgFormat", &dbMsg))
- message = _T(TAGSDEFAULT);
- else
- message = mir_tstrdup(dbMsg.ptszVal);
- db_free(&dbMsg);
+
+ TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
+ if (!message)
+ message = mir_tstrdup(TAGSDEFAULT);
if (!title)
StrReplace(_T("#<title>#"), TranslateT("empty"), message);
@@ -569,31 +611,26 @@ VOID CheckCurrentFeed(MCONTACT hContact)
mir_free(category);
}
- time_t stamp;
- if (!datetime)
- stamp = time(NULL);
- else
- stamp = DateToUnixTime(datetime, 1);
-
- HANDLE hDbEvent = db_event_first(hContact);
- BOOL MesExist = FALSE;
- while (hDbEvent) {
+
+ 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);
- char *pszTemp = mir_utf8encodeT(message);
if (olddbei.cbBlob == lstrlenA(pszTemp) + 1 && !lstrcmpA((char *)olddbei.pBlob, pszTemp))
- MesExist = TRUE;
- hDbEvent = db_event_next(hContact, hDbEvent);
+ MesExist = true;
+
mir_free(olddbei.pBlob);
- mir_free(pszTemp);
+ if (MesExist)
+ break;
}
if (!MesExist) {
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_TCHAR;
- recv.timestamp = stamp;
+ recv.timestamp = (stamp == 0) ? time(NULL) : stamp;
recv.tszMessage = message;
ProtoChainRecvMsg(hContact, &recv);
}
@@ -601,8 +638,7 @@ VOID CheckCurrentFeed(MCONTACT hContact)
}
}
}
- childcount +=1;
- node = xi.getChild(hXml, childcount);
+ node = xi.getChild(hXml, ++childcount);
}
xi.destroyNode(hXml);
}
@@ -611,16 +647,17 @@ VOID CheckCurrentFeed(MCONTACT hContact)
}
}
-VOID CheckCurrentFeedAvatar(MCONTACT hContact)
+void CheckCurrentFeedAvatar(MCONTACT hContact)
{
- char *szData = NULL;
- DBVARIANT dbURL = {0};
- if (db_get_ts(hContact, MODULE, "URL", &dbURL))
- return;
-
if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
- GetNewsData(dbURL.ptszVal, &szData, hContact, NULL);
- db_free(&dbURL);
+ 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)
@@ -633,7 +670,8 @@ VOID CheckCurrentFeedAvatar(MCONTACT hContact)
int childcount = 0;
HXML node = xi.getChild(hXml, childcount);
while (node) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf"))) {
+ 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);
@@ -647,20 +685,20 @@ VOID CheckCurrentFeedAvatar(MCONTACT hContact)
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
- DBVARIANT dbVar = {0};
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
pai.format = ProtoGetAvatarFormat(ext);
- TCHAR *filename = dbVar.ptszVal;
+ 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);
- db_free(&dbVar);
+ mir_free(szNick);
break;
}
}
@@ -668,7 +706,7 @@ VOID CheckCurrentFeedAvatar(MCONTACT hContact)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed"))) {
+ 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"))) {
@@ -678,23 +716,23 @@ VOID CheckCurrentFeedAvatar(MCONTACT hContact)
LPCTSTR url = xi.getText(imageval);
db_set_ts(hContact, MODULE, "ImageURL", url);
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- DBVARIANT dbVar = {0};
+ TCHAR *szNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (szNick) {
+ PROTO_AVATAR_INFORMATIONT pai = {NULL};
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
pai.format = ProtoGetAvatarFormat(ext);
- TCHAR *filename = dbVar.ptszVal;
+ 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);
- db_free(&dbVar);
+ mir_free(szNick);
break;
}
}
@@ -702,8 +740,7 @@ VOID CheckCurrentFeedAvatar(MCONTACT hContact)
}
}
}
- childcount +=1;
- node = xi.getChild(hXml, childcount);
+ node = xi.getChild(hXml, ++childcount);
}
xi.destroyNode(hXml);
}