diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2013-07-19 07:20:05 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2013-07-19 07:20:05 +0000 |
commit | e3246e53e131dee9729b5577e6b15e3090b314f9 (patch) | |
tree | df8a085d98c950bad4ca63677598c49fa3e901f5 | |
parent | 524ba7c684e5eda13c2e3ddb8cb0ca8fae2d7c29 (diff) |
files reorganization
git-svn-id: http://svn.miranda-ng.org/main/trunk@5413 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/NewsAggregator/NewsAggregator_11.vcxproj | 3 | ||||
-rw-r--r-- | plugins/NewsAggregator/NewsAggregator_11.vcxproj.filters | 9 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Authentication.cpp | 135 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/CheckFeed.cpp | 706 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Common.h | 6 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/ExportImport.cpp | 273 | ||||
-rw-r--r-- | plugins/NewsAggregator/Src/Utils.cpp | 1054 |
7 files changed, 1132 insertions, 1054 deletions
diff --git a/plugins/NewsAggregator/NewsAggregator_11.vcxproj b/plugins/NewsAggregator/NewsAggregator_11.vcxproj index 976ce24f74..27b77888cd 100644 --- a/plugins/NewsAggregator/NewsAggregator_11.vcxproj +++ b/plugins/NewsAggregator/NewsAggregator_11.vcxproj @@ -189,6 +189,9 @@ <ClInclude Include="src\Version.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="Src\Authentication.cpp" />
+ <ClCompile Include="Src\CheckFeed.cpp" />
+ <ClCompile Include="Src\ExportImport.cpp" />
<ClCompile Include="Src\Icons.cpp" />
<ClCompile Include="Src\Menus.cpp" />
<ClCompile Include="Src\Options.cpp" />
diff --git a/plugins/NewsAggregator/NewsAggregator_11.vcxproj.filters b/plugins/NewsAggregator/NewsAggregator_11.vcxproj.filters index 0918725b26..d207133ec7 100644 --- a/plugins/NewsAggregator/NewsAggregator_11.vcxproj.filters +++ b/plugins/NewsAggregator/NewsAggregator_11.vcxproj.filters @@ -61,6 +61,15 @@ <ClCompile Include="Src\Stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Src\Authentication.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Src\CheckFeed.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Src\ExportImport.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\AddFeed.ico">
diff --git a/plugins/NewsAggregator/Src/Authentication.cpp b/plugins/NewsAggregator/Src/Authentication.cpp new file mode 100644 index 0000000000..7d3c2d703d --- /dev/null +++ b/plugins/NewsAggregator/Src/Authentication.cpp @@ -0,0 +1,135 @@ +/*
+Copyright (C) 2012 Mataes
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+#include "common.h"
+
+void CreateAuthString(char *auth, HANDLE hContact, HWND hwndDlg)
+{
+ DBVARIANT dbv;
+ char *user = NULL, *pass = NULL;
+ TCHAR *tlogin = NULL, *tpass = NULL, buf[MAX_PATH] = {0};
+ 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);
+ }
+ ptrA pwd(db_get_sa(hContact, MODULE, "Password"));
+ if (pwd)
+ CallService(MS_DB_CRYPT_DECODESTRING, strlen(pwd), pwd);
+ tpass = mir_a2t(pwd);
+ }
+ else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
+ 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 str[MAX_PATH];
+ int len = mir_snprintf(str, SIZEOF(str), "%s:%s", user, pass);
+ mir_free(user);
+ mir_free(pass);
+ mir_free(tlogin);
+ mir_free(tpass);
+
+ mir_snprintf(auth, 250, "Basic %s", ptrA(mir_base64_encode((PBYTE)str, len)));
+}
+
+INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ {
+ ItemInfo &SelItem = *(ItemInfo*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG)&SelItem);
+
+ if (SelItem.hwndList)
+ {
+ TCHAR str[MAX_PATH];
+ if (GetDlgItemText(SelItem.hwndList, IDC_FEEDTITLE, str, SIZEOF(str)))
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
+ else
+ {
+ GetDlgItemText(SelItem.hwndList, IDC_FEEDURL, str, SIZEOF(str));
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
+ }
+ }
+ else if (SelItem.hContact)
+ {
+ DBVARIANT dbv;
+ if (!db_get_ts(SelItem.hContact, MODULE, "Nick", &dbv)) {
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
+ db_free(&dbv);
+ }
+ else if (!db_get_ts(SelItem.hContact, MODULE, "URL", &dbv)) {
+ SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
+ db_free(&dbv);
+ }
+ }
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ {
+ ItemInfo &SelItem = *(ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ TCHAR username[MAX_PATH];
+ char passw[MAX_PATH];
+ if (!GetDlgItemText(hwndDlg, IDC_FEEDUSERNAME, username, SIZEOF(username))) {
+ MessageBox(hwndDlg, TranslateT("Enter your username"), TranslateT("Error"), MB_OK);
+ break;
+ }
+ if (!GetDlgItemTextA(hwndDlg, IDC_FEEDPASSWORD, passw, SIZEOF(passw))) {
+ MessageBox(hwndDlg, TranslateT("Enter your password"), TranslateT("Error"), MB_OK);
+ break;
+ }
+ if (SelItem.hwndList)
+ {
+ CheckDlgButton(SelItem.hwndList, IDC_USEAUTH, BST_CHECKED);
+ EnableWindow(GetDlgItem(SelItem.hwndList, IDC_LOGIN), TRUE);
+ EnableWindow(GetDlgItem(SelItem.hwndList, IDC_PASSWORD), TRUE);
+ SetDlgItemText(SelItem.hwndList, IDC_LOGIN, username);
+ SetDlgItemTextA(SelItem.hwndList, IDC_PASSWORD, passw);
+ }
+ else if (SelItem.hContact)
+ {
+ db_set_b(SelItem.hContact, MODULE, "UseAuth", 1);
+ db_set_ts(SelItem.hContact, MODULE, "Login", username);
+ CallService(MS_DB_CRYPT_ENCODESTRING, strlen(passw), (LPARAM)&passw);
+ db_set_s(SelItem.hContact, MODULE, "Password", passw);
+ }
+ EndDialog(hwndDlg, IDOK);
+ return TRUE;
+ }
+
+ case IDCANCEL:
+ {
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+ }
+ }
+ break;
+ }
+
+ return FALSE;
+}
\ No newline at end of file diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp new file mode 100644 index 0000000000..9db5cd84da --- /dev/null +++ b/plugins/NewsAggregator/Src/CheckFeed.cpp @@ -0,0 +1,706 @@ +/*
+Copyright (C) 2012 Mataes
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+#include "common.h"
+
+TCHAR * CheckFeed(TCHAR *tszURL, HWND hwndDlg)
+{
+ char *szData = NULL;
+ DBVARIANT dbVar = {0};
+ GetNewsData(tszURL, &szData, NULL, hwndDlg);
+ 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) {
+ if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _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("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);
+ TCHAR *tszTitle = (TCHAR *)xi.getText(child);
+ return tszTitle;
+ }
+ }
+ }
+ else if (!lstrcmpi(xi.getName(node), _T("feed"))) {
+ for (int j = 0; j < xi.getChildCount(node); j++) {
+ HXML child = xi.getChild(node, j);
+ 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);
+ TCHAR *tszTitle = (TCHAR *)xi.getText(child);
+ return tszTitle;
+ }
+ }
+ }
+ childcount +=1;
+ node = xi.getChild(hXml, childcount);
+ }
+ }
+ xi.destroyNode(hXml);
+ }
+ TCHAR mes[MAX_PATH];
+ mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis not a valid feed's address."), tszURL);
+ MessageBox(hwndDlg, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONERROR);
+ return NULL;
+}
+
+VOID CheckCurrentFeed(HANDLE 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);
+ 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) {
+ if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf"))) {
+ if (!lstrcmpi(xi.getName(node), _T("rss"))) {
+ for (int i = 0; i < xi.getAttrCount(node); i++) {
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("version"))) {
+ TCHAR ver[MAX_PATH];
+ mir_sntprintf(ver, SIZEOF(ver), _T("RSS %s"), xi.getAttrValue(node, xi.getAttrName(node, i)));
+ db_set_ts(hContact, MODULE, "MirVer", ver);
+ break;
+ }
+ }
+ }
+ else if (!lstrcmpi(xi.getName(node), _T("rdf")))
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ 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;
+ DBVARIANT dbVar = {0};
+
+ if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = GetImageFormat(ext);
+
+ TCHAR *filename = dbVar.ptszVal;
+ 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);
+ 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;
+ }
+ if (!lstrcmpi(xi.getName(child), _T("item"))) {
+ TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
+ for (int z = 0; z < xi.getChildCount(child); z++) {
+ HXML itemval = xi.getChild(child, z);
+ if (!lstrcmpi(xi.getName(itemval), _T("title"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ title = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("link"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ link = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("pubDate"))) {
+ datetime = (TCHAR *)xi.getText(itemval);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("dc:date"))) {
+ datetime = (TCHAR *)xi.getText(itemval);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("description"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ descr = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("author"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ author = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("comments"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ comments = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("guid"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ guid = mir_tstrdup(string);
+ mir_free(string);
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("category"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ category = mir_tstrdup(string);
+ mir_free(string);
+ 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);
+ 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);
+ }
+
+ time_t stamp;
+ if (!datetime)
+ stamp = time(NULL);
+ else
+ stamp = DateToUnixTime(datetime, 0);
+
+ HANDLE hDbEvent = db_event_first(hContact);
+ BOOL MesExist = FALSE;
+ while (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;
+ }
+ hDbEvent = db_event_next(hDbEvent);
+ mir_free(olddbei.pBlob);
+ mir_free(pszTemp);
+ }
+
+ if (!MesExist) {
+ PROTORECVEVENT recv;
+ recv.flags = PREF_TCHAR;
+ recv.timestamp = stamp;
+ recv.tszMessage = message;
+ ProtoChainRecvMsg(hContact, &recv);
+ }
+ mir_free(message);
+ }
+ }
+ }
+ else if (!lstrcmpi(xi.getName(node), _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;
+ }
+ if (!lstrcmpi(xi.getName(child), _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)));
+ }
+ 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;
+ }
+ 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;
+ }
+ if (!lstrcmpi(xi.getName(child), _T("author"))) {
+ for (int x = 0; x < xi.getChildCount(child); x++) {
+ HXML authorval = xi.getChild(child, x);
+ if (!lstrcmpi(xi.getName(authorval), _T("name"))) {
+ db_set_ts(hContact, MODULE, "e-mail", xi.getText(authorval));
+ 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;
+ }
+ 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);
+
+ PROTO_AVATAR_INFORMATIONT pai = {NULL};
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+ DBVARIANT dbVar = {0};
+
+ if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = GetImageFormat(ext);
+
+ TCHAR *filename = dbVar.ptszVal;
+ 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);
+ 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;
+ }
+ if (!lstrcmpi(xi.getName(child), _T("entry"))) {
+ TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
+ 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;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _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;
+ }
+ }
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("updated"))) {
+ datetime = (TCHAR *)xi.getText(itemval);
+ continue;
+ }
+ 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;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _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;
+ }
+ }
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("comments")) && xi.getText(itemval)) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ comments = string;
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _T("id"))) {
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ guid = string;
+ continue;
+ }
+ if (!lstrcmpi(xi.getName(itemval), _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)));
+ 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);
+
+ 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);
+ }
+
+ time_t stamp;
+ if (!datetime)
+ stamp = time(NULL);
+ else
+ stamp = DateToUnixTime(datetime, 1);
+
+ HANDLE hDbEvent = db_event_first(hContact);
+ BOOL MesExist = FALSE;
+ while (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(hDbEvent);
+ mir_free(olddbei.pBlob);
+ mir_free(pszTemp);
+ }
+
+ if (!MesExist) {
+ PROTORECVEVENT recv;
+ recv.flags = PREF_TCHAR;
+ recv.timestamp = stamp;
+ recv.tszMessage = message;
+ ProtoChainRecvMsg(hContact, &recv);
+ }
+ mir_free(message);
+ }
+ }
+ }
+ childcount +=1;
+ node = xi.getChild(hXml, childcount);
+ }
+ xi.destroyNode(hXml);
+ }
+ }
+ db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
+ }
+}
+
+VOID CheckCurrentFeedAvatar(HANDLE 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);
+ 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) {
+ if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _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;
+ DBVARIANT dbVar = {0};
+
+ if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = GetImageFormat(ext);
+
+ TCHAR *filename = dbVar.ptszVal;
+ 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);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ else if (!lstrcmpi(xi.getName(node), _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);
+
+ PROTO_AVATAR_INFORMATIONT pai = {NULL};
+ pai.cbSize = sizeof(pai);
+ pai.hContact = hContact;
+ DBVARIANT dbVar = {0};
+
+ if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
+ TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
+ pai.format = GetImageFormat(ext);
+
+ TCHAR *filename = dbVar.ptszVal;
+ 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);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ childcount +=1;
+ node = xi.getChild(hXml, childcount);
+ }
+ xi.destroyNode(hXml);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h index 720db642b2..c332557b8c 100644 --- a/plugins/NewsAggregator/Src/Common.h +++ b/plugins/NewsAggregator/Src/Common.h @@ -131,6 +131,12 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg); void UpdateMenu(BOOL State);
int ImportFeedsDialog();
VOID ExportFeedsDialog();
+VOID ClearText(TCHAR *&message);
+int GetImageFormat(const TCHAR *ext);
+BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
+int StrReplace(TCHAR *lpszOld, TCHAR *lpszNew, TCHAR *&lpszStr);
+void CreateAuthString(char *auth, HANDLE hContact, HWND hwndDlg);
+INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
// =============== NewsAggregator SERVICES ================
// Check all Feeds info
diff --git a/plugins/NewsAggregator/Src/ExportImport.cpp b/plugins/NewsAggregator/Src/ExportImport.cpp new file mode 100644 index 0000000000..364f08ce65 --- /dev/null +++ b/plugins/NewsAggregator/Src/ExportImport.cpp @@ -0,0 +1,273 @@ +/*
+Copyright (C) 2012 Mataes
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+#include "common.h"
+
+int ImportFeedsDialog()
+{
+ TCHAR FileName[MAX_PATH];
+ TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+
+ OPENFILENAME ofn = {0};
+ ofn.lStructSize = sizeof(ofn);
+ TCHAR tmp[MAX_PATH];
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.opml, *.xml)%c*.opml;*.xml%c%c"), TranslateT("OPML files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = 0;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY;
+ ofn.lpstrInitialDir = tszMirDir;
+ *FileName = '\0';
+ ofn.lpstrDefExt = _T("");
+
+ if (GetOpenFileName(&ofn)) {
+ int bytesParsed = 0;
+ HXML hXml = xi.parseFile(FileName, &bytesParsed, NULL);
+ if(hXml != NULL) {
+ BYTE isTitleUTF = 0, isURLUTF = 0, isSiteURLUTF = 0, isGroupUTF = 0;
+ HXML node = xi.getChildByPath(hXml, _T("opml/body/outline"), 0);
+ if ( !node)
+ node = xi.getChildByPath(hXml, _T("body/outline"), 0);
+ if (node) {
+ while (node) {
+ int outlineAttr = xi.getAttrCount(node);
+ int outlineChildsCount = xi.getChildCount(node);
+ TCHAR *type = (TCHAR *)xi.getAttrValue(node, _T("type"));
+ if ( !type && !outlineChildsCount) {
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ } while (lstrcmpi(xi.getName(node), _T("body")));
+ }
+ }
+ else if (!type && outlineChildsCount)
+ node = xi.getFirstChild(node);
+ else if (type) {
+ TCHAR *title = NULL, *url = NULL, *siteurl = NULL, *group = NULL, *utfgroup = NULL;
+ for (int i = 0; i < outlineAttr; i++) {
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("title"))) {
+ title = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !title) {
+ isTitleUTF = 0;
+ title = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isTitleUTF = 1;
+ continue;
+ }
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("xmlUrl"))) {
+ url = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !url) {
+ isURLUTF = 0;
+ url = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isURLUTF = 1;
+ continue;
+ }
+ if (!lstrcmpi(xi.getAttrName(node, i), _T("htmlUrl"))) {
+ siteurl = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
+ if ( !siteurl) {
+ isSiteURLUTF = 0;
+ siteurl = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
+ } else
+ isSiteURLUTF = 1;
+ continue;
+ }
+ if (title && url && siteurl)
+ break;
+ }
+
+ HXML parent = xi.getParent(node);
+ while (lstrcmpi(xi.getName(parent), _T("body"))) {
+ for (int i = 0; i < xi.getAttrCount(parent); i++) {
+ if (!lstrcmpi(xi.getAttrName(parent, i), _T("title"))) {
+ if ( !group)
+ group = (TCHAR *)xi.getAttrValue(parent, xi.getAttrName(parent, i));
+ else {
+ TCHAR tmpgroup[1024];
+ mir_sntprintf(tmpgroup, SIZEOF(tmpgroup), _T("%s\\%s"), xi.getAttrValue(parent, xi.getAttrName(parent, i)), group);
+ group = tmpgroup;
+ }
+ break;
+ }
+ }
+ parent = xi.getParent(parent);
+ }
+
+ if (group) {
+ utfgroup = mir_utf8decodeT(_T2A(group));
+ if ( !utfgroup) {
+ isGroupUTF = 0;
+ utfgroup = group;
+ } else
+ isGroupUTF = 1;
+ }
+
+ HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
+ db_set_ts(hContact, MODULE, "Nick", title);
+ db_set_ts(hContact, MODULE, "URL", url);
+ 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_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0));
+ if (utfgroup) {
+ db_set_ts(hContact, "CList", "Group", utfgroup);
+ int hGroup = 1;
+ char *group_name;
+ BYTE GroupExist = 0;
+ do {
+ group_name = (char *)CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, 0);
+ if (group_name != NULL && !strcmp(group_name, _T2A(utfgroup))) {
+ GroupExist = 1;
+ break;
+ }
+ hGroup++;
+ }
+ while (group_name);
+
+ if(!GroupExist)
+ CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)utfgroup);
+ }
+ if (isTitleUTF)
+ mir_free(title);
+ if (isURLUTF)
+ mir_free(url);
+ if (isGroupUTF)
+ mir_free(utfgroup);
+ if (isSiteURLUTF)
+ mir_free(siteurl);
+
+ HXML tmpnode = node;
+ node = xi.getNextNode(node);
+ if ( !node) {
+ do {
+ node = tmpnode;
+ node = xi.getParent(node);
+ tmpnode = node;
+ node = xi.getNextNode(node);
+ if (node)
+ break;
+ }
+ while (lstrcmpi(xi.getName(tmpnode), _T("body")));
+ }
+ }
+ }
+ }
+ else MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
+ xi.destroyNode(hXml);
+ }
+ else MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
+
+ mir_free(tszMirDir);
+ return 0;
+ }
+ mir_free(tszMirDir);
+ return 1;
+}
+
+VOID ExportFeedsDialog()
+{
+ TCHAR FileName[MAX_PATH];
+ TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+
+ OPENFILENAME ofn = {0};
+ ofn.lStructSize = sizeof(ofn);
+ TCHAR tmp[MAX_PATH];
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.opml)%c*.opml%c%c"), TranslateT("OPML files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = 0;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
+ ofn.lpstrInitialDir = tszMirDir;
+ *FileName = '\0';
+ ofn.lpstrDefExt = _T("");
+
+ if (GetSaveFileName(&ofn)) {
+ HXML hXml = xi.createNode(_T("opml"), NULL, FALSE);
+ xi.addAttr(hXml, _T("version"), _T("1.0"));
+ HXML header = xi.addChild(hXml, _T("head"), NULL);
+ HXML title = xi.addChild(header, _T("title"), _T("Miranda NG NewsAggregator plugin export"));
+ header = xi.addChild(hXml, _T("body"), NULL);
+
+ for (HANDLE hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) {
+ 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);
+ }
+ HXML elem = header;
+ if (group)
+ {
+ TCHAR *section = _tcstok(group, _T("\\"));
+ while (section != NULL)
+ {
+ HXML existgroup = xi.getChildByAttrValue(header, _T("outline"), _T("title"), section);
+ if ( !existgroup)
+ {
+ elem = xi.addChild(elem, _T("outline"), NULL);
+ xi.addAttr(elem, _T("title"), section);
+ xi.addAttr(elem, _T("text"), section);
+ } else {
+ elem = existgroup;
+ }
+ section = _tcstok(NULL, _T("\\"));
+ }
+ elem = xi.addChild(elem, _T("outline"), NULL);
+ } else
+ elem = xi.addChild(elem, _T("outline"), NULL);
+ xi.addAttr(elem, _T("text"), title);
+ xi.addAttr(elem, _T("title"), title);
+ xi.addAttr(elem, _T("type"), _T("rss"));
+ xi.addAttr(elem, _T("xmlUrl"), url);
+ xi.addAttr(elem, _T("htmlUrl"), siteurl);
+
+ mir_free(title);
+ mir_free(url);
+ mir_free(siteurl);
+ mir_free(group);
+ }
+ xi.toFile(hXml, FileName, 1);
+ xi.destroyNode(hXml);
+ }
+}
\ No newline at end of file diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp index 21c8e5c037..d5baafedb5 100644 --- a/plugins/NewsAggregator/Src/Utils.cpp +++ b/plugins/NewsAggregator/Src/Utils.cpp @@ -84,121 +84,6 @@ int GetImageFormat(const TCHAR *ext) return PA_FORMAT_UNKNOWN;
}
-void CreateAuthString(char *auth, HANDLE hContact, HWND hwndDlg)
-{
- DBVARIANT dbv;
- char *user = NULL, *pass = NULL;
- TCHAR *tlogin = NULL, *tpass = NULL, buf[MAX_PATH] = {0};
- 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);
- }
- ptrA pwd(db_get_sa(hContact, MODULE, "Password"));
- if (pwd)
- CallService(MS_DB_CRYPT_DECODESTRING, strlen(pwd), pwd);
- tpass = mir_a2t(pwd);
- }
- else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
- 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 str[MAX_PATH];
- int len = mir_snprintf(str, SIZEOF(str), "%s:%s", user, pass);
- mir_free(user);
- mir_free(pass);
- mir_free(tlogin);
- mir_free(tpass);
-
- mir_snprintf(auth, 250, "Basic %s", ptrA(mir_base64_encode((PBYTE)str, len)));
-}
-
-INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- ItemInfo &SelItem = *(ItemInfo*)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG)&SelItem);
-
- if (SelItem.hwndList)
- {
- TCHAR str[MAX_PATH];
- if (GetDlgItemText(SelItem.hwndList, IDC_FEEDTITLE, str, SIZEOF(str)))
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
- else
- {
- GetDlgItemText(SelItem.hwndList, IDC_FEEDURL, str, SIZEOF(str));
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, str);
- }
- }
- else if (SelItem.hContact)
- {
- DBVARIANT dbv;
- if (!db_get_ts(SelItem.hContact, MODULE, "Nick", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
- db_free(&dbv);
- }
- else if (!db_get_ts(SelItem.hContact, MODULE, "URL", &dbv)) {
- SetDlgItemText(hwndDlg, IDC_FEEDNAME, dbv.ptszVal);
- db_free(&dbv);
- }
- }
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- {
- ItemInfo &SelItem = *(ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- TCHAR username[MAX_PATH];
- char passw[MAX_PATH];
- if (!GetDlgItemText(hwndDlg, IDC_FEEDUSERNAME, username, SIZEOF(username))) {
- MessageBox(hwndDlg, TranslateT("Enter your username"), TranslateT("Error"), MB_OK);
- break;
- }
- if (!GetDlgItemTextA(hwndDlg, IDC_FEEDPASSWORD, passw, SIZEOF(passw))) {
- MessageBox(hwndDlg, TranslateT("Enter your password"), TranslateT("Error"), MB_OK);
- break;
- }
- if (SelItem.hwndList)
- {
- CheckDlgButton(SelItem.hwndList, IDC_USEAUTH, BST_CHECKED);
- EnableWindow(GetDlgItem(SelItem.hwndList, IDC_LOGIN), TRUE);
- EnableWindow(GetDlgItem(SelItem.hwndList, IDC_PASSWORD), TRUE);
- SetDlgItemText(SelItem.hwndList, IDC_LOGIN, username);
- SetDlgItemTextA(SelItem.hwndList, IDC_PASSWORD, passw);
- }
- else if (SelItem.hContact)
- {
- db_set_b(SelItem.hContact, MODULE, "UseAuth", 1);
- db_set_ts(SelItem.hContact, MODULE, "Login", username);
- CallService(MS_DB_CRYPT_ENCODESTRING, strlen(passw), (LPARAM)&passw);
- db_set_s(SelItem.hContact, MODULE, "Password", passw);
- }
- EndDialog(hwndDlg, IDOK);
- return TRUE;
- }
-
- case IDCANCEL:
- {
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- }
- }
- break;
- }
-
- return FALSE;
-}
-
VOID GetNewsData(TCHAR *tszUrl, char **szData, HANDLE hContact, HWND hwndDlg)
{
NETLIBHTTPREQUEST nlhr = {0};
@@ -705,943 +590,4 @@ VOID ClearText(TCHAR *&message) }
SysFreeString(bstrHtml);
CoUninitialize();
-}
-
-TCHAR * CheckFeed(TCHAR *tszURL, HWND hwndDlg)
-{
- char *szData = NULL;
- DBVARIANT dbVar = {0};
- GetNewsData(tszURL, &szData, NULL, hwndDlg);
- 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) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _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("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);
- TCHAR *tszTitle = (TCHAR *)xi.getText(child);
- return tszTitle;
- }
- }
- }
- else if (!lstrcmpi(xi.getName(node), _T("feed"))) {
- for (int j = 0; j < xi.getChildCount(node); j++) {
- HXML child = xi.getChild(node, j);
- 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);
- TCHAR *tszTitle = (TCHAR *)xi.getText(child);
- return tszTitle;
- }
- }
- }
- childcount +=1;
- node = xi.getChild(hXml, childcount);
- }
- }
- xi.destroyNode(hXml);
- }
- TCHAR mes[MAX_PATH];
- mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis not a valid feed's address."), tszURL);
- MessageBox(hwndDlg, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONERROR);
- return NULL;
-}
-
-VOID CheckCurrentFeed(HANDLE 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);
- 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) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf"))) {
- if (!lstrcmpi(xi.getName(node), _T("rss"))) {
- for (int i = 0; i < xi.getAttrCount(node); i++) {
- if (!lstrcmpi(xi.getAttrName(node, i), _T("version"))) {
- TCHAR ver[MAX_PATH];
- mir_sntprintf(ver, SIZEOF(ver), _T("RSS %s"), xi.getAttrValue(node, xi.getAttrName(node, i)));
- db_set_ts(hContact, MODULE, "MirVer", ver);
- break;
- }
- }
- }
- else if (!lstrcmpi(xi.getName(node), _T("rdf")))
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- DBVARIANT dbVar = {0};
-
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
-
- TCHAR *filename = dbVar.ptszVal;
- 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);
- 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;
- }
- if (!lstrcmpi(xi.getName(child), _T("item"))) {
- TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
- for (int z = 0; z < xi.getChildCount(child); z++) {
- HXML itemval = xi.getChild(child, z);
- if (!lstrcmpi(xi.getName(itemval), _T("title"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- title = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("link"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- link = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("pubDate"))) {
- datetime = (TCHAR *)xi.getText(itemval);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("dc:date"))) {
- datetime = (TCHAR *)xi.getText(itemval);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("description"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- descr = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("author"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- author = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("comments"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- comments = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("guid"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = mir_tstrdup(string);
- mir_free(string);
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("category"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- category = mir_tstrdup(string);
- mir_free(string);
- 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);
- 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);
- }
-
- time_t stamp;
- if (!datetime)
- stamp = time(NULL);
- else
- stamp = DateToUnixTime(datetime, 0);
-
- HANDLE hDbEvent = db_event_first(hContact);
- BOOL MesExist = FALSE;
- while (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;
- }
- hDbEvent = db_event_next(hDbEvent);
- mir_free(olddbei.pBlob);
- mir_free(pszTemp);
- }
-
- if (!MesExist) {
- PROTORECVEVENT recv;
- recv.flags = PREF_TCHAR;
- recv.timestamp = stamp;
- recv.tszMessage = message;
- ProtoChainRecvMsg(hContact, &recv);
- }
- mir_free(message);
- }
- }
- }
- else if (!lstrcmpi(xi.getName(node), _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;
- }
- if (!lstrcmpi(xi.getName(child), _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)));
- }
- 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;
- }
- 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;
- }
- if (!lstrcmpi(xi.getName(child), _T("author"))) {
- for (int x = 0; x < xi.getChildCount(child); x++) {
- HXML authorval = xi.getChild(child, x);
- if (!lstrcmpi(xi.getName(authorval), _T("name"))) {
- db_set_ts(hContact, MODULE, "e-mail", xi.getText(authorval));
- 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;
- }
- 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);
-
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- DBVARIANT dbVar = {0};
-
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
-
- TCHAR *filename = dbVar.ptszVal;
- 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);
- 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;
- }
- if (!lstrcmpi(xi.getName(child), _T("entry"))) {
- TCHAR *title = NULL, *link = NULL, *datetime = NULL, *descr = NULL, *author = NULL, *comments = NULL, *guid = NULL, *category = NULL;
- 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;
- }
- if (!lstrcmpi(xi.getName(itemval), _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;
- }
- }
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("updated"))) {
- datetime = (TCHAR *)xi.getText(itemval);
- continue;
- }
- 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;
- }
- if (!lstrcmpi(xi.getName(itemval), _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;
- }
- }
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("comments")) && xi.getText(itemval)) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- comments = string;
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _T("id"))) {
- TCHAR *string = mir_tstrdup(xi.getText(itemval));
- ClearText(string);
- guid = string;
- continue;
- }
- if (!lstrcmpi(xi.getName(itemval), _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)));
- 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);
-
- 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);
- }
-
- time_t stamp;
- if (!datetime)
- stamp = time(NULL);
- else
- stamp = DateToUnixTime(datetime, 1);
-
- HANDLE hDbEvent = db_event_first(hContact);
- BOOL MesExist = FALSE;
- while (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(hDbEvent);
- mir_free(olddbei.pBlob);
- mir_free(pszTemp);
- }
-
- if (!MesExist) {
- PROTORECVEVENT recv;
- recv.flags = PREF_TCHAR;
- recv.timestamp = stamp;
- recv.tszMessage = message;
- ProtoChainRecvMsg(hContact, &recv);
- }
- mir_free(message);
- }
- }
- }
- childcount +=1;
- node = xi.getChild(hXml, childcount);
- }
- xi.destroyNode(hXml);
- }
- }
- db_set_dw(hContact, MODULE, "LastCheck", time(NULL));
- }
-}
-
-VOID CheckCurrentFeedAvatar(HANDLE 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);
- 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) {
- if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _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;
- DBVARIANT dbVar = {0};
-
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
-
- TCHAR *filename = dbVar.ptszVal;
- 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);
- break;
- }
- }
- }
- }
- }
- }
- else if (!lstrcmpi(xi.getName(node), _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);
-
- PROTO_AVATAR_INFORMATIONT pai = {NULL};
- pai.cbSize = sizeof(pai);
- pai.hContact = hContact;
- DBVARIANT dbVar = {0};
-
- if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
- TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
-
- TCHAR *filename = dbVar.ptszVal;
- 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);
- break;
- }
- }
- }
- }
- }
- }
- childcount +=1;
- node = xi.getChild(hXml, childcount);
- }
- xi.destroyNode(hXml);
- }
- }
- }
-}
-
-int ImportFeedsDialog()
-{
- TCHAR FileName[MAX_PATH];
- TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
-
- OPENFILENAME ofn = {0};
- ofn.lStructSize = sizeof(ofn);
- TCHAR tmp[MAX_PATH];
- mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.opml, *.xml)%c*.opml;*.xml%c%c"), TranslateT("OPML files"), 0, 0, 0);
- ofn.lpstrFilter = tmp;
- ofn.hwndOwner = 0;
- ofn.lpstrFile = FileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY;
- ofn.lpstrInitialDir = tszMirDir;
- *FileName = '\0';
- ofn.lpstrDefExt = _T("");
-
- if (GetOpenFileName(&ofn)) {
- int bytesParsed = 0;
- HXML hXml = xi.parseFile(FileName, &bytesParsed, NULL);
- if(hXml != NULL) {
- BYTE isTitleUTF = 0, isURLUTF = 0, isSiteURLUTF = 0, isGroupUTF = 0;
- HXML node = xi.getChildByPath(hXml, _T("opml/body/outline"), 0);
- if ( !node)
- node = xi.getChildByPath(hXml, _T("body/outline"), 0);
- if (node) {
- while (node) {
- int outlineAttr = xi.getAttrCount(node);
- int outlineChildsCount = xi.getChildCount(node);
- TCHAR *type = (TCHAR *)xi.getAttrValue(node, _T("type"));
- if ( !type && !outlineChildsCount) {
- HXML tmpnode = node;
- node = xi.getNextNode(node);
- if ( !node) {
- do {
- node = tmpnode;
- node = xi.getParent(node);
- tmpnode = node;
- node = xi.getNextNode(node);
- if (node)
- break;
- } while (lstrcmpi(xi.getName(node), _T("body")));
- }
- }
- else if (!type && outlineChildsCount)
- node = xi.getFirstChild(node);
- else if (type) {
- TCHAR *title = NULL, *url = NULL, *siteurl = NULL, *group = NULL, *utfgroup = NULL;
- for (int i = 0; i < outlineAttr; i++) {
- if (!lstrcmpi(xi.getAttrName(node, i), _T("title"))) {
- title = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
- if ( !title) {
- isTitleUTF = 0;
- title = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
- } else
- isTitleUTF = 1;
- continue;
- }
- if (!lstrcmpi(xi.getAttrName(node, i), _T("xmlUrl"))) {
- url = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
- if ( !url) {
- isURLUTF = 0;
- url = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
- } else
- isURLUTF = 1;
- continue;
- }
- if (!lstrcmpi(xi.getAttrName(node, i), _T("htmlUrl"))) {
- siteurl = mir_utf8decodeT(_T2A(xi.getAttrValue(node, xi.getAttrName(node, i))));
- if ( !siteurl) {
- isSiteURLUTF = 0;
- siteurl = (TCHAR *)xi.getAttrValue(node, xi.getAttrName(node, i));
- } else
- isSiteURLUTF = 1;
- continue;
- }
- if (title && url && siteurl)
- break;
- }
-
- HXML parent = xi.getParent(node);
- while (lstrcmpi(xi.getName(parent), _T("body"))) {
- for (int i = 0; i < xi.getAttrCount(parent); i++) {
- if (!lstrcmpi(xi.getAttrName(parent, i), _T("title"))) {
- if ( !group)
- group = (TCHAR *)xi.getAttrValue(parent, xi.getAttrName(parent, i));
- else {
- TCHAR tmpgroup[1024];
- mir_sntprintf(tmpgroup, SIZEOF(tmpgroup), _T("%s\\%s"), xi.getAttrValue(parent, xi.getAttrName(parent, i)), group);
- group = tmpgroup;
- }
- break;
- }
- }
- parent = xi.getParent(parent);
- }
-
- if (group) {
- utfgroup = mir_utf8decodeT(_T2A(group));
- if ( !utfgroup) {
- isGroupUTF = 0;
- utfgroup = group;
- } else
- isGroupUTF = 1;
- }
-
- HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
- db_set_ts(hContact, MODULE, "Nick", title);
- db_set_ts(hContact, MODULE, "URL", url);
- 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_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0));
- if (utfgroup) {
- db_set_ts(hContact, "CList", "Group", utfgroup);
- int hGroup = 1;
- char *group_name;
- BYTE GroupExist = 0;
- do {
- group_name = (char *)CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, 0);
- if (group_name != NULL && !strcmp(group_name, _T2A(utfgroup))) {
- GroupExist = 1;
- break;
- }
- hGroup++;
- }
- while (group_name);
-
- if(!GroupExist)
- CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)utfgroup);
- }
- if (isTitleUTF)
- mir_free(title);
- if (isURLUTF)
- mir_free(url);
- if (isGroupUTF)
- mir_free(utfgroup);
- if (isSiteURLUTF)
- mir_free(siteurl);
-
- HXML tmpnode = node;
- node = xi.getNextNode(node);
- if ( !node) {
- do {
- node = tmpnode;
- node = xi.getParent(node);
- tmpnode = node;
- node = xi.getNextNode(node);
- if (node)
- break;
- }
- while (lstrcmpi(xi.getName(tmpnode), _T("body")));
- }
- }
- }
- }
- else MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
- xi.destroyNode(hXml);
- }
- else MessageBox(NULL, TranslateT("Not valid import file."), TranslateT("Error"), MB_OK | MB_ICONERROR);
-
- mir_free(tszMirDir);
- return 0;
- }
- mir_free(tszMirDir);
- return 1;
-}
-
-VOID ExportFeedsDialog()
-{
- TCHAR FileName[MAX_PATH];
- TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
-
- OPENFILENAME ofn = {0};
- ofn.lStructSize = sizeof(ofn);
- TCHAR tmp[MAX_PATH];
- mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.opml)%c*.opml%c%c"), TranslateT("OPML files"), 0, 0, 0);
- ofn.lpstrFilter = tmp;
- ofn.hwndOwner = 0;
- ofn.lpstrFile = FileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
- ofn.lpstrInitialDir = tszMirDir;
- *FileName = '\0';
- ofn.lpstrDefExt = _T("");
-
- if (GetSaveFileName(&ofn)) {
- HXML hXml = xi.createNode(_T("opml"), NULL, FALSE);
- xi.addAttr(hXml, _T("version"), _T("1.0"));
- HXML header = xi.addChild(hXml, _T("head"), NULL);
- HXML title = xi.addChild(header, _T("title"), _T("Miranda NG NewsAggregator plugin export"));
- header = xi.addChild(hXml, _T("body"), NULL);
-
- for (HANDLE hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) {
- 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);
- }
- HXML elem = header;
- if (group)
- {
- TCHAR *section = _tcstok(group, _T("\\"));
- while (section != NULL)
- {
- HXML existgroup = xi.getChildByAttrValue(header, _T("outline"), _T("title"), section);
- if ( !existgroup)
- {
- elem = xi.addChild(elem, _T("outline"), NULL);
- xi.addAttr(elem, _T("title"), section);
- xi.addAttr(elem, _T("text"), section);
- } else {
- elem = existgroup;
- }
- section = _tcstok(NULL, _T("\\"));
- }
- elem = xi.addChild(elem, _T("outline"), NULL);
- } else
- elem = xi.addChild(elem, _T("outline"), NULL);
- xi.addAttr(elem, _T("text"), title);
- xi.addAttr(elem, _T("title"), title);
- xi.addAttr(elem, _T("type"), _T("rss"));
- xi.addAttr(elem, _T("xmlUrl"), url);
- xi.addAttr(elem, _T("htmlUrl"), siteurl);
-
- mir_free(title);
- mir_free(url);
- mir_free(siteurl);
- mir_free(group);
- }
- xi.toFile(hXml, FileName, 1);
- xi.destroyNode(hXml);
- }
}
\ No newline at end of file |