summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2014-11-02 11:19:25 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2014-11-02 11:19:25 +0000
commit4fb42b711df5d8a9986d9587d7a1edc72f13eb0c (patch)
tree50d1b643508145fde1e99fe3a95cc72070d00f6f /plugins/NewsAggregator
parentb31a2b228e4585acc015760aa7e84ddf1312bc8d (diff)
NewsAggregator:
-Fixed memory leak -Fixed crash when server isn't available -performance improvements git-svn-id: http://svn.miranda-ng.org/main/trunk@10899 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewsAggregator')
-rw-r--r--plugins/NewsAggregator/Src/Authentication.cpp30
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp577
-rw-r--r--plugins/NewsAggregator/Src/Common.h4
-rw-r--r--plugins/NewsAggregator/Src/ExportImport.cpp43
-rw-r--r--plugins/NewsAggregator/Src/Menus.cpp2
-rw-r--r--plugins/NewsAggregator/Src/Options.cpp72
-rw-r--r--plugins/NewsAggregator/Src/Services.cpp42
-rw-r--r--plugins/NewsAggregator/Src/Update.cpp8
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp72
9 files changed, 445 insertions, 405 deletions
diff --git a/plugins/NewsAggregator/Src/Authentication.cpp b/plugins/NewsAggregator/Src/Authentication.cpp
index 47918c4706..5d3a56b645 100644
--- a/plugins/NewsAggregator/Src/Authentication.cpp
+++ b/plugins/NewsAggregator/Src/Authentication.cpp
@@ -21,24 +21,19 @@ Boston, MA 02111-1307, USA.
void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg)
{
- DBVARIANT dbv;
- char *user = NULL, *pass = NULL;
- TCHAR *tlogin = NULL, *tpass = NULL, buf[MAX_PATH] = {0};
+ TCHAR *tlogin = NULL, *tpass = NULL;
if (hContact && db_get_b(hContact, MODULE, "UseAuth", 0)) {
- if (!db_get_ts(hContact, MODULE, "Login", &dbv)) {
- tlogin = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
+ tlogin = db_get_tsa(hContact, MODULE, "Login");
tpass = db_get_tsa(hContact, MODULE, "Password");
}
else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
+ TCHAR buf[MAX_PATH] = {0};
GetDlgItemText(hwndDlg, IDC_LOGIN, buf, SIZEOF(buf));
tlogin = mir_tstrdup(buf);
GetDlgItemText(hwndDlg, IDC_PASSWORD, buf, SIZEOF(buf));
tpass = mir_tstrdup(buf);
}
- user = mir_t2a(tlogin);
- pass = mir_t2a(tpass);
+ char *user = mir_t2a(tlogin), *pass = mir_t2a(tpass);
char str[MAX_PATH];
int len = mir_snprintf(str, SIZEOF(str), "%s:%s", user, pass);
@@ -69,14 +64,17 @@ INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
}
}
else if (SelItem.hContact) {
- DBVARIANT dbv;
- if (!db_get_ts(SelItem.hContact, MODULE, "Nick", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
- db_free(&dbv);
+ TCHAR *ptszNick = db_get_tsa(SelItem.hContact, MODULE, "Nick");
+ if (ptszNick) {
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszNick);
+ mir_free(ptszNick);
}
- else if (!db_get_ts(SelItem.hContact, MODULE, "URL", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
- db_free(&dbv);
+ else {
+ TCHAR *ptszURL = db_get_tsa(SelItem.hContact, MODULE, "URL");
+ if (ptszURL) {
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, ptszURL);
+ mir_free(ptszURL);
+ }
}
}
}
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);
}
diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h
index 09eb380307..9e205709f8 100644
--- a/plugins/NewsAggregator/Src/Common.h
+++ b/plugins/NewsAggregator/Src/Common.h
@@ -48,13 +48,13 @@ Boston, MA 02111-1307, USA.
#include "resource.h"
#define MODULE "NewsAggregator"
-#define TAGSDEFAULT "#<title>#\r\n#<link>#\r\n#<description>#"
+#define TAGSDEFAULT _T("#<title>#\r\n#<link>#\r\n#<description>#")
#define DEFAULT_AVATARS_FOLDER "NewsAggregator"
#define DEFAULT_UPDATE_TIME 60
extern HINSTANCE hInst;
extern HWND hAddFeedDlg;
-extern HANDLE hChangeFeedDlgList;
+extern HANDLE hChangeFeedDlgList, hNetlibUser;
extern UINT_PTR timerId;
// check if Feeds is currently updating
extern BOOL ThreadRunning;
diff --git a/plugins/NewsAggregator/Src/ExportImport.cpp b/plugins/NewsAggregator/Src/ExportImport.cpp
index 15f21cd9a3..a824d6eaa7 100644
--- a/plugins/NewsAggregator/Src/ExportImport.cpp
+++ b/plugins/NewsAggregator/Src/ExportImport.cpp
@@ -155,7 +155,7 @@ INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
db_set_ts(hContact, MODULE, "Homepage", siteurl);
db_set_b(hContact, MODULE, "CheckState", 1);
db_set_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME);
- db_set_ts(hContact, MODULE, "MsgFormat", _T(TAGSDEFAULT));
+ db_set_ts(hContact, MODULE, "MsgFormat", TAGSDEFAULT);
db_set_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0));
if (utfgroup) {
db_set_ts(hContact, "CList", "Group", utfgroup);
@@ -222,7 +222,7 @@ INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
case IDC_BROWSEIMPORTFILE:
{
TCHAR FileName[MAX_PATH];
- TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+ VARST tszMirDir(_T("%miranda_path%"));
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
@@ -310,10 +310,8 @@ INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
else
MessageBox(hwndDlg, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
- mir_free(tszMirDir);
break;
}
- mir_free(tszMirDir);
break;
}
break;
@@ -469,10 +467,10 @@ INT_PTR CALLBACK DlgProcExportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
TranslateDialogDefault(hwndDlg);
Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULE, "ExportDlg");
for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) {
- DBVARIANT dbVar = {0};
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
- SendMessage(FeedsList, LB_ADDSTRING, 0, (LPARAM)dbVar.ptszVal);
- db_free(&dbVar);
+ TCHAR *message = db_get_tsa(hContact, MODULE, "Nick");
+ if (!message != NULL) {
+ SendMessage(FeedsList, LB_ADDSTRING, 0, (LPARAM)message);
+ mir_free(message);
}
}
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEFEED), FALSE);
@@ -489,7 +487,7 @@ INT_PTR CALLBACK DlgProcExportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
case IDOK:
{
TCHAR FileName[MAX_PATH];
- TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+ ptrT tszMirDir(_T("%miranda_path%"));
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
@@ -517,24 +515,12 @@ INT_PTR CALLBACK DlgProcExportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
TCHAR item[MAX_PATH];
SendMessage(FeedsExportList, LB_GETTEXT, i, (LPARAM)item);
MCONTACT hContact = GetContactByNick(item);
- TCHAR *title = NULL, *url = NULL, *siteurl = NULL, *group = NULL;
- DBVARIANT dbv = {0};
- if (!db_get_ts(hContact, MODULE, "Nick", &dbv)) {
- title = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- if (!db_get_ts(hContact, MODULE, "URL", &dbv)) {
- url = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- if (!db_get_ts(hContact, MODULE, "Homepage", &dbv)) {
- siteurl = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- if (!db_get_ts(hContact, "CList", "Group", &dbv)) {
- group = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
+ TCHAR
+ *title = db_get_tsa(hContact, MODULE, "Nick"),
+ *url = db_get_tsa(hContact, MODULE, "URL"),
+ *siteurl = db_get_tsa(hContact, MODULE, "Homepage"),
+ *group = db_get_tsa(hContact, "CList", "Group");
+
HXML elem = header;
if (group)
{
@@ -553,7 +539,8 @@ INT_PTR CALLBACK DlgProcExportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
section = _tcstok(NULL, _T("\\"));
}
elem = xi.addChild(elem, _T("outline"), NULL);
- } else
+ }
+ else
elem = xi.addChild(elem, _T("outline"), NULL);
xi.addAttr(elem, _T("text"), title);
xi.addAttr(elem, _T("title"), title);
diff --git a/plugins/NewsAggregator/Src/Menus.cpp b/plugins/NewsAggregator/Src/Menus.cpp
index 1299e03af5..b80988d337 100644
--- a/plugins/NewsAggregator/Src/Menus.cpp
+++ b/plugins/NewsAggregator/Src/Menus.cpp
@@ -21,7 +21,7 @@ Boston, MA 02111-1307, USA.
HGENMENU hService2[7];
-VOID InitMenu()
+void InitMenu()
{
CLISTMENUITEM mi = { sizeof(mi) };
mi.pszContactOwner = MODULE;
diff --git a/plugins/NewsAggregator/Src/Options.cpp b/plugins/NewsAggregator/Src/Options.cpp
index a946ba0dac..b1b299a748 100644
--- a/plugins/NewsAggregator/Src/Options.cpp
+++ b/plugins/NewsAggregator/Src/Options.cpp
@@ -27,7 +27,7 @@ INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
SetWindowText(hwndDlg, TranslateT("Add Feed"));
SetDlgItemText(hwndDlg, IDC_FEEDURL, _T("http://"));
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, TAGSDEFAULT);
SendDlgItemMessage(hwndDlg, IDC_CHECKTIME, EM_LIMITTEXT, 3, 0);
SetDlgItemInt(hwndDlg, IDC_CHECKTIME, DEFAULT_UPDATE_TIME, TRUE);
SendDlgItemMessage(hwndDlg, IDC_TIMEOUT_VALUE_SPIN, UDM_SETRANGE32, 0, 999);
@@ -113,7 +113,7 @@ INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
case IDC_RESET:
if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, TAGSDEFAULT);
break;
case IDC_DISCOVERY:
@@ -135,6 +135,7 @@ INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
break;
case WM_DESTROY:
+ hAddFeedDlg = 0;
Utils_SaveWindowPosition(hwndDlg, NULL, MODULE, "AddDlg");
break;
}
@@ -176,19 +177,20 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
SetDlgItemText(hwndDlg, IDC_FEEDTITLE, SelItem.nick);
SetDlgItemInt(hwndDlg, IDC_CHECKTIME, db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME), TRUE);
- DBVARIANT dbMsg = {0};
- if (!db_get_ts(hContact, MODULE, "MsgFormat", &dbMsg)) {
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, dbMsg.ptszVal);
- db_free(&dbMsg);
+ TCHAR *szMsgFormat = db_get_tsa(hContact, MODULE, "MsgFormat");
+ if (szMsgFormat) {
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, szMsgFormat);
+ mir_free(szMsgFormat);
}
if (db_get_b(hContact, MODULE, "UseAuth", 0)) {
CheckDlgButton(hwndDlg, IDC_USEAUTH, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
- DBVARIANT dbLogin = {0};
- if (!db_get_ts(hContact, MODULE, "Login", &dbLogin)) {
- SetDlgItemText(hwndDlg, IDC_LOGIN, dbLogin.ptszVal);
- db_free(&dbLogin);
+
+ TCHAR *szLogin = db_get_tsa(hContact, MODULE, "Login");
+ if (szLogin) {
+ SetDlgItemText(hwndDlg, IDC_LOGIN, szLogin);
+ mir_free(szLogin);
}
ptrA pwd(db_get_sa(hContact, MODULE, "Password"));
SetDlgItemTextA(hwndDlg, IDC_PASSWORD, pwd);
@@ -283,7 +285,7 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
case IDC_RESET:
if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, TAGSDEFAULT);
break;
case IDC_DISCOVERY:
@@ -305,10 +307,9 @@ INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
break;
case WM_DESTROY:
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- Utils_SaveWindowPosition(hwndDlg, hContact, MODULE, "ChangeDlg");
- WindowList_Remove(hChangeFeedDlgList, hwndDlg);
ItemInfo *SelItem = (ItemInfo *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ Utils_SaveWindowPosition(hwndDlg, SelItem->hContact, MODULE, "ChangeDlg");
+ WindowList_Remove(hChangeFeedDlgList, hwndDlg);
delete SelItem;
break;
}
@@ -328,28 +329,36 @@ INT_PTR CALLBACK DlgProcChangeFeedMenu(HWND hwndDlg, UINT msg, WPARAM wParam, LP
MCONTACT hContact = lParam;
WindowList_Add(hChangeFeedDlgList, hwndDlg, hContact);
Utils_RestoreWindowPositionNoSize(hwndDlg, hContact, MODULE, "ChangeDlg");
- DBVARIANT dbv;
- if (!db_get_ts(hContact, MODULE, "Nick", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_FEEDTITLE, dbv.ptszVal);
- db_free(&dbv);
+
+ TCHAR *ptszNick = db_get_tsa(hContact, MODULE, "Nick");
+ if(ptszNick) {
+ SetDlgItemText(hwndDlg, IDC_FEEDTITLE, ptszNick);
+ mir_free(ptszNick);
}
- if (!db_get_ts(hContact, MODULE, "URL", &dbv)) {
+
+ TCHAR *ptszURL = db_get_tsa(hContact, MODULE, "URL");
+ if(ptszNick) {
+ SetDlgItemText(hwndDlg, IDC_FEEDURL, ptszURL);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
- SetDlgItemText(hwndDlg, IDC_FEEDURL, dbv.ptszVal);
- db_free(&dbv);
+ mir_free(ptszURL);
}
+
SetDlgItemInt(hwndDlg, IDC_CHECKTIME, db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME), TRUE);
- if (!db_get_ts(hContact, MODULE, "MsgFormat", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, dbv.ptszVal);
- db_free(&dbv);
+
+ TCHAR *ptszMsgFormat = db_get_tsa(hContact, MODULE, "URL");
+ if (ptszMsgFormat) {
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, ptszMsgFormat);
+ mir_free(ptszMsgFormat);
}
+
if (db_get_b(hContact, MODULE, "UseAuth", 0)) {
CheckDlgButton(hwndDlg, IDC_USEAUTH, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
- if (!db_get_ts(hContact, MODULE, "Login", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_LOGIN, dbv.ptszVal);
- db_free(&dbv);
+ TCHAR *ptszLogin = db_get_tsa(hContact, MODULE, "Login");
+ if (ptszLogin) {
+ SetDlgItemText(hwndDlg, IDC_LOGIN, ptszLogin);
+ mir_free(ptszLogin);
}
ptrA pwd(db_get_sa(hContact, MODULE, "Password"));
SetDlgItemTextA(hwndDlg, IDC_PASSWORD, pwd);
@@ -438,7 +447,7 @@ INT_PTR CALLBACK DlgProcChangeFeedMenu(HWND hwndDlg, UINT msg, WPARAM wParam, LP
case IDC_RESET:
if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
- SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
+ SetDlgItemText(hwndDlg, IDC_TAGSEDIT, TAGSDEFAULT);
break;
case IDC_DISCOVERY:
@@ -483,7 +492,8 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_ADD:
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcAddFeedOpts, (LPARAM)hwndList);
+ if(hAddFeedDlg == 0)
+ hAddFeedDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcAddFeedOpts, (LPARAM)hwndList);
return FALSE;
case IDC_CHANGE:
@@ -553,7 +563,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
db_set_b(hContact, "CList", "Hidden", 1);
else
db_unset(hContact,"CList","Hidden");
- i += 1;
+ i++;
}
}
break;
@@ -585,7 +595,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
return FALSE;
}
-INT OptInit(WPARAM wParam, LPARAM lParam)
+INT OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.position = 100000000;
diff --git a/plugins/NewsAggregator/Src/Services.cpp b/plugins/NewsAggregator/Src/Services.cpp
index 0fe243e9f3..104730e4eb 100644
--- a/plugins/NewsAggregator/Src/Services.cpp
+++ b/plugins/NewsAggregator/Src/Services.cpp
@@ -43,10 +43,9 @@ int OnFoldersChanged(WPARAM, LPARAM)
return 0;
}
-int NewsAggrInit(WPARAM wParam, LPARAM lParam)
+int NewsAggrInit(WPARAM, LPARAM)
{
- hNewsAggregatorFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), LPGEN("News Aggregator"), MIRANDA_USERDATAT _T("\\Avatars\\")_T(DEFAULT_AVATARS_FOLDER));
- if (hNewsAggregatorFolder)
+ if (hNewsAggregatorFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), LPGEN("News Aggregator"), MIRANDA_USERDATAT _T("\\Avatars\\")_T(DEFAULT_AVATARS_FOLDER)))
FoldersGetCustomPathT(hNewsAggregatorFolder, tszRoot, MAX_PATH, _T(""));
else
lstrcpyn(tszRoot, VARST( _T("%miranda_userdata%\\Avatars\\"_T(DEFAULT_AVATARS_FOLDER))), SIZEOF(tszRoot));
@@ -69,7 +68,7 @@ int NewsAggrInit(WPARAM wParam, LPARAM lParam)
return 0;
}
-int NewsAggrPreShutdown(WPARAM wParam, LPARAM lParam)
+int NewsAggrPreShutdown(WPARAM, LPARAM)
{
if (hAddFeedDlg)
SendMessage(hAddFeedDlg, WM_CLOSE, 0, 0);
@@ -143,7 +142,7 @@ static void __cdecl AckThreadProc(void *param)
ProtoBroadcastAck(MODULE, (MCONTACT)param, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0);
}
-INT_PTR NewsAggrGetInfo(WPARAM wParam, LPARAM lParam)
+INT_PTR NewsAggrGetInfo(WPARAM, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA *)lParam;
mir_forkthread(AckThreadProc, (void*)ccs->hContact);
@@ -159,19 +158,20 @@ INT_PTR CheckAllFeeds(WPARAM wParam, LPARAM lParam)
UpdateListAdd(hContact);
}
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
+ mir_forkthread(UpdateThreadProc, 0);
return 0;
}
-INT_PTR AddFeed(WPARAM wParam, LPARAM lParam)
+INT_PTR AddFeed(WPARAM, LPARAM)
{
- hAddFeedDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_ADDFEED), NULL, DlgProcAddFeedOpts);
+ if (hAddFeedDlg == 0)
+ hAddFeedDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_ADDFEED), NULL, DlgProcAddFeedOpts);
ShowWindow(hAddFeedDlg, SW_SHOW);
return 0;
}
-INT_PTR ChangeFeed(WPARAM hContact, LPARAM lParam)
+INT_PTR ChangeFeed(WPARAM hContact, LPARAM)
{
HWND hChangeFeedDlg = WindowList_Find(hChangeFeedDlgList, hContact);
if (!hChangeFeedDlg) {
@@ -184,13 +184,13 @@ INT_PTR ChangeFeed(WPARAM hContact, LPARAM lParam)
return 0;
}
-INT_PTR ImportFeeds(WPARAM wParam, LPARAM lParam)
+INT_PTR ImportFeeds(WPARAM, LPARAM)
{
CreateDialog(hInst, MAKEINTRESOURCE(IDD_FEEDIMPORT), NULL, DlgProcImportOpts);
return 0;
}
-INT_PTR ExportFeeds(WPARAM wParam, LPARAM lParam)
+INT_PTR ExportFeeds(WPARAM, LPARAM)
{
CreateDialog(hInst, MAKEINTRESOURCE(IDD_FEEDEXPORT), NULL, DlgProcExportOpts);
return 0;
@@ -201,32 +201,32 @@ INT_PTR CheckFeed(WPARAM hContact, LPARAM lParam)
if(IsMyContact(hContact))
UpdateListAdd(hContact);
if ( !ThreadRunning)
- mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
+ mir_forkthread(UpdateThreadProc, FALSE);
return 0;
}
INT_PTR NewsAggrGetAvatarInfo(WPARAM wParam, LPARAM lParam)
{
PROTO_AVATAR_INFORMATIONT *pai = (PROTO_AVATAR_INFORMATIONT *)lParam;
- if ( !IsMyContact(pai->hContact))
+ if (!IsMyContact(pai->hContact))
return GAIR_NOAVATAR;
// if GAIF_FORCE is set, we are updating the feed
// otherwise, cached avatar is used
- if (wParam & GAIF_FORCE && db_get_dw(pai->hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME))
+ if ((wParam & GAIF_FORCE) && db_get_dw(pai->hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME))
UpdateListAdd(pai->hContact);
if (db_get_b(NULL, MODULE, "AutoUpdate", 1) != 0 && !ThreadRunning)
- mir_forkthread(UpdateThreadProc, (LPVOID)TRUE);
+ mir_forkthread(UpdateThreadProc, (void *)TRUE);
- DBVARIANT dbv;
- if(db_get_ts(pai->hContact, MODULE, "ImageURL", &dbv))
+ TCHAR *ptszImageURL = db_get_tsa(pai->hContact, MODULE, "ImageURL");
+ if(ptszImageURL == NULL)
return GAIR_NOAVATAR;
- db_free(&dbv);
+ mir_free(ptszImageURL);
return GAIR_WAITFOR;
}
-INT_PTR NewsAggrRecvMessage(WPARAM wParam, LPARAM lParam)
+INT_PTR NewsAggrRecvMessage(WPARAM, LPARAM lParam)
{
CallService(MS_PROTO_RECVMSG, 0, lParam);
return 0;
@@ -252,14 +252,14 @@ void UpdateMenu(BOOL State)
}
// update the newsaggregator auto-update menu item when click on it
-INT_PTR EnableDisable(WPARAM wParam, LPARAM lParam)
+INT_PTR EnableDisable(WPARAM, LPARAM)
{
UpdateMenu(db_get_b(NULL, MODULE, "AutoUpdate", 1));
NewsAggrSetStatus(db_get_b(NULL, MODULE, "AutoUpdate", 1) ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE, 0);
return 0;
}
-int OnToolbarLoaded(WPARAM wParam, LPARAM lParam)
+int OnToolbarLoaded(WPARAM, LPARAM)
{
TTBButton ttb = { sizeof(ttb) };
ttb.name = LPGEN("Enable/disable auto update");
diff --git a/plugins/NewsAggregator/Src/Update.cpp b/plugins/NewsAggregator/Src/Update.cpp
index cbcc2efd0f..ec394d5fc8 100644
--- a/plugins/NewsAggregator/Src/Update.cpp
+++ b/plugins/NewsAggregator/Src/Update.cpp
@@ -25,7 +25,7 @@ UPDATELIST *UpdateListHead = NULL;
UPDATELIST *UpdateListTail = NULL;
// main auto-update timer
-VOID CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+void CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
// only run if it is not current updating and the auto update option is enabled
if (!ThreadRunning && !Miranda_Terminated()) {
@@ -40,13 +40,13 @@ VOID CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
}
}
if (!ThreadRunning && HaveUpdates)
- mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
+ mir_forkthread(UpdateThreadProc, 0);
}
}
// temporary timer for first run
// when this is run, it kill the old startup timer and create the permenant one above
-VOID CALLBACK timerProc2(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+void CALLBACK timerProc2(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
KillTimer(NULL, timerId);
ThreadRunning = FALSE;
@@ -112,7 +112,7 @@ void DestroyUpdateList(void)
ReleaseMutex(hUpdateMutex);
}
-void UpdateThreadProc(LPVOID AvatarCheck)
+void UpdateThreadProc(void *AvatarCheck)
{
WaitForSingleObject(hUpdateMutex, INFINITE);
if (ThreadRunning) {
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 662841a2cb..9883812253 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -28,7 +28,7 @@ BOOL IsMyContact(MCONTACT hContact)
return szProto != NULL && strcmp(MODULE, szProto) == 0;
}
-VOID NetlibInit()
+void NetlibInit()
{
NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR; // | NUF_HTTPGATEWAY;
@@ -37,7 +37,7 @@ VOID NetlibInit()
hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
}
-VOID NetlibUnInit()
+void NetlibUnInit()
{
Netlib_CloseHandle(hNetlibUser);
hNetlibUser = NULL;
@@ -58,8 +58,9 @@ static void arrayToHex(BYTE *data, size_t datasz, char *res)
*resptr = '\0';
}
-VOID GetNewsData(TCHAR *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg)
+void GetNewsData(TCHAR *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg)
{
+ Netlib_LogfT(hNetlibUser,_T("Getting feed data %s."), tszUrl);
NETLIBHTTPREQUEST nlhr = {0};
// initialize the netlib request
@@ -98,34 +99,37 @@ VOID GetNewsData(TCHAR *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg)
if (nlhrReply) {
// if the recieved code is 200 OK
if (nlhrReply->resultCode == 200 && nlhrReply->dataLength > 0) {
+ Netlib_LogfT(hNetlibUser,_T("Code 200: Succeeded getting feed data %s."), tszUrl);
// allocate memory and save the retrieved data
*szData = (char *)mir_alloc(nlhrReply->dataLength + 2);
memcpy(*szData, nlhrReply->pData, nlhrReply->dataLength);
(*szData)[nlhrReply->dataLength] = 0;
}
else if (nlhrReply->resultCode == 401) {
+ Netlib_LogfT(hNetlibUser,_T("Code 401: feed %s needs auth data."), tszUrl);
ItemInfo SelItem = {0};
SelItem.hwndList = hwndDlg;
SelItem.hContact = hContact;
if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK)
GetNewsData(tszUrl, szData, hContact, hwndDlg);
}
+ else
+ Netlib_LogfT(hNetlibUser,_T("Code %d: Failed getting feed data %s."), nlhrReply->resultCode, tszUrl);
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply);
}
else {
- if (nlhr.resultCode == 401) {
- ItemInfo SelItem = {0};
- SelItem.hwndList = hwndDlg;
- SelItem.hContact = hContact;
- if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK)
- GetNewsData(tszUrl, szData, hContact, hwndDlg);
- }
+ Netlib_LogfT(hNetlibUser,_T("Failed getting feed data %s, no response."), tszUrl);
+ ItemInfo SelItem = {0};
+ SelItem.hwndList = hwndDlg;
+ SelItem.hContact = hContact;
+ if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK)
+ GetNewsData(tszUrl, szData, hContact, hwndDlg);
}
mir_free(szUrl);
}
-VOID CreateList(HWND hwndList)
+void CreateList(HWND hwndList)
{
SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
@@ -147,7 +151,7 @@ VOID CreateList(HWND hwndList)
ListView_InsertColumn(hwndList, 1, &lvc);
}
-VOID UpdateList(HWND hwndList)
+void UpdateList(HWND hwndList)
{
LVITEM lvI = {0};
@@ -159,27 +163,28 @@ VOID UpdateList(HWND hwndList)
UpdateListFlag = TRUE;
lvI.mask = LVIF_TEXT;
lvI.iSubItem = 0;
- DBVARIANT dbNick = {0};
- if (!db_get_ts(hContact, MODULE, "Nick", &dbNick)) {
- lvI.pszText = dbNick.ptszVal;
+ TCHAR *ptszNick = db_get_tsa(hContact, MODULE, "Nick");
+ if (ptszNick) {
+ lvI.pszText = ptszNick;
lvI.iItem = i;
ListView_InsertItem(hwndList, &lvI);
lvI.iSubItem = 1;
- DBVARIANT dbURL = {0};
- if (!db_get_ts(hContact, MODULE, "URL", &dbURL)) {
- lvI.pszText = dbURL.ptszVal;
+
+ TCHAR *ptszURL = db_get_tsa(hContact, MODULE, "URL");
+ if (ptszURL) {
+ lvI.pszText = ptszURL;
ListView_SetItem(hwndList, &lvI);
- i += 1;
+ i++;
ListView_SetCheckState(hwndList, lvI.iItem, db_get_b(hContact, MODULE, "CheckState", 1));
- db_free(&dbURL);
+ mir_free(ptszURL);
}
- db_free(&dbNick);
+ mir_free(ptszNick);
}
}
UpdateListFlag = FALSE;
}
-VOID DeleteAllItems(HWND hwndList)
+void DeleteAllItems(HWND hwndList)
{
ListView_DeleteAllItems(hwndList);
}
@@ -391,9 +396,6 @@ int StrReplace(TCHAR *lpszOld, TCHAR *lpszNew, TCHAR *&lpszStr)
BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
{
- HANDLE hFile = NULL;
- DWORD dwBytes;
-
NETLIBHTTPREQUEST nlhr = {0};
nlhr.cbSize = sizeof(nlhr);
nlhr.requestType = REQUEST_GET;
@@ -422,7 +424,7 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
date = pReply->headers[i].szValue;
continue;
}
- if (!lstrcmpiA(pReply->headers[i].szName, "Content-Length")) {
+ else if (!lstrcmpiA(pReply->headers[i].szName, "Content-Length")) {
size = pReply->headers[i].szValue;
continue;
}
@@ -438,24 +440,33 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
time_t modtime = DateToUnixTime(tdate, 0);
time_t filemodtime = mktime(localtime(&buf.st_atime));
if (modtime > filemodtime && buf.st_size != _ttoi(tsize)) {
- hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ DWORD dwBytes;
+ HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL);
ret = true;
+ if (hFile)
+ CloseHandle(hFile);
}
_close(fh);
}
else {
- hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ DWORD dwBytes;
+ HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL);
ret = true;
+ if (hFile)
+ CloseHandle(hFile);
}
mir_free(tdate);
mir_free(tsize);
}
else {
- hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ DWORD dwBytes;
+ HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL);
ret = true;
+ if (hFile)
+ CloseHandle(hFile);
}
}
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pReply);
@@ -463,9 +474,6 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
mir_free(szUrl);
- if (hFile)
- CloseHandle(hFile);
-
return ret;
}