summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator/Src/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewsAggregator/Src/Utils.cpp')
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp825
1 files changed, 320 insertions, 505 deletions
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 8ec665374a..6edc22936c 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -24,14 +24,13 @@ BOOL UpdateListFlag = FALSE;
BOOL IsMyContact(HANDLE hContact)
{
- const char* szProto = GetContactProto(hContact);
+ const char *szProto = GetContactProto(hContact);
return szProto != NULL && strcmp(MODULE, szProto) == 0;
}
VOID NetlibInit()
{
- NETLIBUSER nlu = {0};
- nlu.cbSize = sizeof(nlu);
+ NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR; // | NUF_HTTPGATEWAY;
nlu.ptszDescriptiveName = TranslateT("NewsAggregator HTTP connection");
nlu.szSettingsModule = MODULE;
@@ -47,8 +46,7 @@ VOID NetlibUnInit()
static void arrayToHex(BYTE* data, size_t datasz, char* res)
{
char* resptr = res;
- for (unsigned i=0; i<datasz ; i++)
- {
+ for (unsigned i=0; i < datasz ; i++) {
const BYTE ch = data[i];
const char ch0 = (char)(ch >> 4);
@@ -63,59 +61,45 @@ static void arrayToHex(BYTE* data, size_t datasz, char* res)
int GetImageFormat(const TCHAR* ext)
{
if (!lstrcmp(ext,_T(".jpg")) || !lstrcmp(ext,_T(".jpeg")))
- {
return PA_FORMAT_JPEG;
- }
- else if (!lstrcmp(ext,_T(".png")))
- {
+
+ if (!lstrcmp(ext,_T(".png")))
return PA_FORMAT_PNG;
- }
- else if (!lstrcmp(ext,_T(".gif")))
- {
+
+ if (!lstrcmp(ext,_T(".gif")))
return PA_FORMAT_GIF;
- }
- else if (!lstrcmp(ext,_T(".ico")))
- {
+
+ if (!lstrcmp(ext,_T(".ico")))
return PA_FORMAT_ICON;
- }
- else if (!lstrcmp(ext,_T(".bmp")))
- {
+
+ if (!lstrcmp(ext,_T(".bmp")))
return PA_FORMAT_BMP;
- }
- else if (!lstrcmp(ext,_T(".swf")))
- {
+
+ if (!lstrcmp(ext,_T(".swf")))
return PA_FORMAT_SWF;
- }
- else if (!lstrcmp(ext,_T(".xml")))
- {
+
+ if (!lstrcmp(ext,_T(".xml")))
return PA_FORMAT_XML;
- }
- else
- {
- return PA_FORMAT_UNKNOWN;
- }
+
+ 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 && DBGetContactSettingByte(hContact, MODULE, "UseAuth", 0))
- {
- DBVARIANT dbLogin = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Login", &dbLogin))
- {
- tlogin = mir_tstrdup(dbLogin.ptszVal);
- DBFreeVariant(&dbLogin);
+ 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);
}
- DBVARIANT dbPass = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Password", &dbPass))
- {
- tpass = mir_tstrdup(dbPass.ptszVal);
- DBFreeVariant(&dbPass);
+ if (!db_get_ts(hContact, MODULE, "Password", &dbv)) {
+ tpass = mir_tstrdup(dbv.ptszVal);
+ db_free(&dbv);
}
}
- else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
- {
+ else if (hwndDlg && IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
GetDlgItemText(hwndDlg, IDC_LOGIN, buf, SIZEOF(buf));
tlogin = buf;
GetDlgItemText(hwndDlg, IDC_PASSWORD, buf, SIZEOF(buf));
@@ -162,8 +146,7 @@ VOID GetNewsData(TCHAR *tszUrl, char** szData, HANDLE hContact, HWND hwndDlg)
nlhr.headers[3].szValue = "close";
nlhr.headers[4].szName = "Accept";
nlhr.headers[4].szValue = "*/*";
- if (DBGetContactSettingByte(hContact, MODULE, "UseAuth", 0) || IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
- {
+ if (db_get_b(hContact, MODULE, "UseAuth", 0) || IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) {
nlhr.headersCount = 6;
nlhr.headers[5].szName = "Authorization";
@@ -171,67 +154,56 @@ VOID GetNewsData(TCHAR *tszUrl, char** szData, HANDLE hContact, HWND hwndDlg)
CreateAuthString(auth, hContact, hwndDlg);
nlhr.headers[5].szValue = auth;
}
- else
- nlhr.headersCount = 5;
+ else nlhr.headersCount = 5;
// download the page
NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr);
- if (nlhrReply)
- {
+ if (nlhrReply) {
// if the recieved code is 200 OK
- switch (nlhrReply->resultCode)
- {
- case 200:
- {
- if (nlhrReply->dataLength)
- {
- // allocate memory and save the retrieved data
- *szData = (char *)mir_alloc(nlhrReply->dataLength + 2);
- memcpy(*szData, nlhrReply->pData, nlhrReply->dataLength);
- (*szData)[nlhrReply->dataLength] = 0;
- }
- break;
+ switch (nlhrReply->resultCode) {
+ case 200:
+ if (nlhrReply->dataLength) {
+ // allocate memory and save the retrieved data
+ *szData = (char *)mir_alloc(nlhrReply->dataLength + 2);
+ memcpy(*szData, nlhrReply->pData, nlhrReply->dataLength);
+ (*szData)[nlhrReply->dataLength] = 0;
}
+ break;
- case 401:
- {
- //ShowMessage(0, TranslateT("Cannot upload VersionInfo. Incorrect username or password"));
- break;
- }
+ case 401:
+ //ShowMessage(0, TranslateT("Cannot upload VersionInfo. Incorrect username or password"));
+ break;
- case 301:
- case 302:
- case 307:
- // get the url for the new location and save it to szInfo
- // look for the reply header "Location"
- for (int i=0; i<nlhrReply->headersCount; i++)
- {
- if (!strcmp(nlhrReply->headers[i].szName, "Location"))
- {
- size_t rlen = 0;
- if (nlhrReply->headers[i].szValue[0] == '/')
- {
- const char* szPath;
- const char* szPref = strstr(szUrl, "://");
- szPref = szPref ? szPref + 3 : szUrl;
- szPath = strchr(szPref, '/');
- rlen = szPath != NULL ? szPath - szUrl : strlen(szUrl);
- }
+ case 301:
+ case 302:
+ case 307:
+ // get the url for the new location and save it to szInfo
+ // look for the reply header "Location"
+ for (int i=0; i<nlhrReply->headersCount; i++) {
+ if (!strcmp(nlhrReply->headers[i].szName, "Location")) {
+ size_t rlen = 0;
+ if (nlhrReply->headers[i].szValue[0] == '/') {
+ const char* szPath;
+ const char* szPref = strstr(szUrl, "://");
+ szPref = szPref ? szPref + 3 : szUrl;
+ szPath = strchr(szPref, '/');
+ rlen = szPath != NULL ? szPath - szUrl : strlen(szUrl);
+ }
- szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + strlen(nlhrReply->headers[i].szValue)*3 + 1);
+ szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + strlen(nlhrReply->headers[i].szValue)*3 + 1);
- strncpy(szRedirUrl, szUrl, rlen);
- strcpy(szRedirUrl+rlen, nlhrReply->headers[i].szValue);
-
- nlhr.szUrl = szRedirUrl;
- break;
- }
+ strncpy(szRedirUrl, szUrl, rlen);
+ strcpy(szRedirUrl+rlen, nlhrReply->headers[i].szValue);
+
+ nlhr.szUrl = szRedirUrl;
+ break;
}
- break;
+ }
+ break;
- default:
- //ShowMessage(0, TranslateT("Cannot upload VersionInfo. Unknown error"));
- break;
+ default:
+ //ShowMessage(0, TranslateT("Cannot upload VersionInfo. Unknown error"));
+ break;
}
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply);
}
@@ -269,30 +241,26 @@ VOID UpdateList(HWND hwndList)
// items.
HANDLE hContact = db_find_first();
int i = 0;
- while (hContact != NULL)
- {
- if (IsMyContact(hContact))
- {
+ while (hContact != NULL) {
+ if (IsMyContact(hContact)) {
UpdateListFlag = TRUE;
lvI.mask = LVIF_TEXT;
lvI.iSubItem = 0;
DBVARIANT dbNick = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbNick))
- {
+ if (!db_get_ts(hContact, MODULE, "Nick", &dbNick)) {
lvI.pszText = dbNick.ptszVal;
lvI.iItem = i;
ListView_InsertItem(hwndList, &lvI);
lvI.iSubItem = 1;
DBVARIANT dbURL = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
- {
+ if (!db_get_ts(hContact, MODULE, "URL", &dbURL)) {
lvI.pszText = dbURL.ptszVal;
ListView_SetItem(hwndList, &lvI);
i += 1;
- ListView_SetCheckState(hwndList, lvI.iItem, DBGetContactSettingByte(hContact, MODULE, "CheckState", 1));
- DBFreeVariant(&dbURL);
+ ListView_SetCheckState(hwndList, lvI.iItem, db_get_b(hContact, MODULE, "CheckState", 1));
+ db_free(&dbURL);
}
- DBFreeVariant(&dbNick);
+ db_free(&dbNick);
}
}
hContact = db_find_next(hContact);
@@ -312,28 +280,25 @@ time_t __stdcall DateToUnixTime(TCHAR* stamp, BOOL FeedType)
int i, y;
time_t t;
- if ( stamp == NULL ) return ( time_t ) 0;
+ if ( stamp == NULL )
+ return 0;
TCHAR *p = stamp;
- if (FeedType)
- {
+ if (FeedType) {
// skip '-' chars
int si = 0, sj = 0;
- while (1) {
+ while (true) {
if ( p[si] == _T('-'))
si++;
- else
- if ( !( p[sj++] = p[si++] ))
- break;
- };
+ else if ( !( p[sj++] = p[si++] ))
+ break;
+ }
}
- else
- {
+ else {
TCHAR weekday[4], monthstr[4], timezonesign[2];
INT day, month, year, hour, min, sec, timezoneh, timezonem;
- if (_tcsstr(p, _T(",")))
- {
+ if (_tcsstr(p, _T(","))) {
_stscanf( p, _T("%3s, %d %3s %d %d:%d:%d %1s%02d%02d"), &weekday, &day, &monthstr, &year, &hour, &min, &sec, &timezonesign, &timezoneh, &timezonem);
if (!lstrcmpi(monthstr, _T("Jan")))
month = 1;
@@ -392,8 +357,8 @@ time_t __stdcall DateToUnixTime(TCHAR* stamp, BOOL FeedType)
y = ( date[0]-'0' )*1000 + ( date[1]-'0' )*100 + ( date[2]-'0' )*10 + date[3]-'0';
y -= 1900;
}
- else
- return ( time_t ) 0;
+ else return 0;
+
timestamp.tm_year = y;
// Parse month
timestamp.tm_mon = ( date[i-4]-'0' )*10 + date[i-3]-'0' - 1;
@@ -405,18 +370,14 @@ time_t __stdcall DateToUnixTime(TCHAR* stamp, BOOL FeedType)
// Parse time
if ( _stscanf( p, _T("%d:%d:%d"), &timestamp.tm_hour, &timestamp.tm_min, &timestamp.tm_sec ) != 3 )
- return ( time_t ) 0;
+ return 0;
timestamp.tm_isdst = 0; // DST is already present in _timezone below
t = mktime( &timestamp );
_tzset();
t -= _timezone;
-
- if ( t >= 0 )
- return t;
- else
- return ( time_t ) 0;
+ return (t >= 0) ? t : 0;
}
TCHAR * _tcsistr(const TCHAR * str, const TCHAR * substr)
@@ -460,10 +421,8 @@ int StrReplace(TCHAR* lpszOld, TCHAR* lpszNew, TCHAR*& lpszStr)
TCHAR *pszTarget = NULL;
TCHAR * pszResultStr = NULL;
- while (pszStart < pszEnd)
- {
- while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL)
- {
+ while (pszStart < pszEnd) {
+ while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL) {
nCount++;
pszStart = pszTarget + nOldLen;
}
@@ -471,8 +430,7 @@ int StrReplace(TCHAR* lpszOld, TCHAR* lpszNew, TCHAR*& lpszStr)
}
// if any changes, make them now
- if (nCount > 0)
- {
+ if (nCount > 0) {
// allocate buffer for result string
size_t nResultStrSize = nStrLen + (nNewLen - nOldLen) * nCount + 2;
pszResultStr = new TCHAR [nResultStrSize];
@@ -483,10 +441,8 @@ int StrReplace(TCHAR* lpszOld, TCHAR* lpszNew, TCHAR*& lpszStr)
TCHAR *cp = pszResultStr;
// loop again to actually do the work
- while (pszStart < pszEnd)
- {
- while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL)
- {
+ while (pszStart < pszEnd) {
+ while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL) {
int nCopyLen = (int)(pszTarget - pszStart);
_tcsncpy(cp, &lpszStr[pszStart-lpszStr], nCopyLen);
@@ -507,8 +463,7 @@ int StrReplace(TCHAR* lpszOld, TCHAR* lpszNew, TCHAR*& lpszStr)
}
int nSize = 0;
- if (pszResultStr)
- {
+ if (pszResultStr) {
nSize = (int)_tcslen(pszResultStr);
delete [] pszResultStr;
}
@@ -540,48 +495,37 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
bool ret = false;
NETLIBHTTPREQUEST *pReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr);
-
- if (pReply)
- {
- if ((200 == pReply->resultCode) && (pReply->dataLength > 0))
- {
+ if (pReply) {
+ if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) {
char *date = NULL, *size = NULL;
- for (int i = 0; i < pReply->headersCount; i++)
- {
- if (!lstrcmpiA(pReply->headers[i].szName, "Last-Modified"))
- {
+ for (int i = 0; i < pReply->headersCount; i++) {
+ if (!lstrcmpiA(pReply->headers[i].szName, "Last-Modified")) {
date = pReply->headers[i].szValue;
continue;
}
- if (!lstrcmpiA(pReply->headers[i].szName, "Content-Length"))
- {
+ if (!lstrcmpiA(pReply->headers[i].szName, "Content-Length")) {
size = pReply->headers[i].szValue;
continue;
}
}
- if (date != NULL && size != NULL)
- {
+ if (date != NULL && size != NULL) {
TCHAR *tdate = mir_a2t(date);
TCHAR *tsize = mir_a2t(size);
- int fh;
struct _stat buf;
- fh = _topen(tszLocal, _O_RDONLY);
- if (fh != -1)
- {
+ int fh = _topen(tszLocal, _O_RDONLY);
+ if (fh != -1) {
_fstat(fh, &buf);
time_t modtime = DateToUnixTime(tdate, 0);
time_t filemodtime = mktime(localtime(&buf.st_atime));
- if (modtime > filemodtime && buf.st_size != _ttoi(tsize))
- {
+ if (modtime > filemodtime && buf.st_size != _ttoi(tsize)) {
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;
}
_close(fh);
}
- else
- {
+ else {
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;
@@ -589,8 +533,7 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
mir_free(tdate);
mir_free(tsize);
}
- else
- {
+ else {
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;
@@ -612,66 +555,60 @@ typedef HRESULT (MarkupCallback)(IHTMLDocument3*, BSTR& message);
HRESULT TestMarkupServices(BSTR bstrHtml, MarkupCallback* pCallback, BSTR& message)
{
- IHTMLDocument3* pHtmlDocRoot = NULL;
-
- // Create the root document -- a "workspace" for parsing.
- HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pHtmlDocRoot));
- if (SUCCEEDED(hr) && pHtmlDocRoot)
- {
- IPersistStreamInit *pPersistStreamInit = NULL;
-
- HRESULT hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pPersistStreamInit));
- if (SUCCEEDED(hr))
- {
- // Initialize the root document to a default state -- ready for parsing.
- hr = pPersistStreamInit->InitNew();
-
- IMarkupServices *pMarkupServices = NULL;
- hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pMarkupServices));
- if (SUCCEEDED(hr))
- {
- IMarkupPointer *pMarkupBegin = NULL;
- IMarkupPointer *pMarkupEnd = NULL;
-
- // These markup pointers indicate the insertion point.
- hr = pMarkupServices->CreateMarkupPointer(&pMarkupBegin);
- if (SUCCEEDED(hr))
- hr = pMarkupServices->CreateMarkupPointer(&pMarkupEnd);
-
- if (SUCCEEDED(hr) && pMarkupBegin && pMarkupEnd)
- {
- IMarkupContainer *pMarkupContainer = NULL;
-
- // Parse the string -- the markup container contains the parsed HTML.
- // Markup pointers are updated to point to begining and end of new container.
- hr = pMarkupServices->ParseString(bstrHtml, 0, &pMarkupContainer, pMarkupBegin, pMarkupEnd);
- if (SUCCEEDED(hr) && pMarkupContainer)
- {
- IHTMLDocument3 *pHtmlDoc = NULL;
-
- // Retrieve the document interface to the markup container.
- hr = pMarkupContainer->QueryInterface(IID_PPV_ARGS(&pHtmlDoc));
- if (SUCCEEDED(hr) && pHtmlDoc)
- {
- // Invoke the user-defined action for this new fragment.
- hr = pCallback(pHtmlDoc, message);
-
- // Clean up.
- pHtmlDoc->Release();
- }
- pMarkupContainer->Release();
- }
- pMarkupEnd->Release();
- }
- if (pMarkupBegin)
- pMarkupBegin->Release();
- pMarkupServices->Release();
- }
- pPersistStreamInit->Release();
- }
- pHtmlDocRoot->Release();
- }
- return hr;
+ IHTMLDocument3* pHtmlDocRoot = NULL;
+
+ // Create the root document -- a "workspace" for parsing.
+ HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pHtmlDocRoot));
+ if (SUCCEEDED(hr) && pHtmlDocRoot) {
+ IPersistStreamInit *pPersistStreamInit = NULL;
+
+ HRESULT hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pPersistStreamInit));
+ if (SUCCEEDED(hr)) {
+ // Initialize the root document to a default state -- ready for parsing.
+ hr = pPersistStreamInit->InitNew();
+
+ IMarkupServices *pMarkupServices = NULL;
+ hr = pHtmlDocRoot->QueryInterface(IID_PPV_ARGS(&pMarkupServices));
+ if (SUCCEEDED(hr)) {
+ IMarkupPointer *pMarkupBegin = NULL;
+ IMarkupPointer *pMarkupEnd = NULL;
+
+ // These markup pointers indicate the insertion point.
+ hr = pMarkupServices->CreateMarkupPointer(&pMarkupBegin);
+ if (SUCCEEDED(hr))
+ hr = pMarkupServices->CreateMarkupPointer(&pMarkupEnd);
+
+ if (SUCCEEDED(hr) && pMarkupBegin && pMarkupEnd) {
+ IMarkupContainer *pMarkupContainer = NULL;
+
+ // Parse the string -- the markup container contains the parsed HTML.
+ // Markup pointers are updated to point to begining and end of new container.
+ hr = pMarkupServices->ParseString(bstrHtml, 0, &pMarkupContainer, pMarkupBegin, pMarkupEnd);
+ if (SUCCEEDED(hr) && pMarkupContainer) {
+ IHTMLDocument3 *pHtmlDoc = NULL;
+
+ // Retrieve the document interface to the markup container.
+ hr = pMarkupContainer->QueryInterface(IID_PPV_ARGS(&pHtmlDoc));
+ if (SUCCEEDED(hr) && pHtmlDoc) {
+ // Invoke the user-defined action for this new fragment.
+ hr = pCallback(pHtmlDoc, message);
+
+ // Clean up.
+ pHtmlDoc->Release();
+ }
+ pMarkupContainer->Release();
+ }
+ pMarkupEnd->Release();
+ }
+ if (pMarkupBegin)
+ pMarkupBegin->Release();
+ pMarkupServices->Release();
+ }
+ pPersistStreamInit->Release();
+ }
+ pHtmlDocRoot->Release();
+ }
+ return hr;
}
HRESULT TestDocumentText(IHTMLDocument3* pHtmlDoc, BSTR& message)
@@ -681,11 +618,9 @@ HRESULT TestDocumentText(IHTMLDocument3* pHtmlDoc, BSTR& message)
BSTR bstrId = SysAllocString(L"test");
HRESULT hr = pHtmlDoc->QueryInterface(IID_PPV_ARGS(&pDoc));
- if (SUCCEEDED(hr) && pDoc)
- {
+ if (SUCCEEDED(hr) && pDoc) {
hr = pDoc->get_body(&pElem);
- if (SUCCEEDED(hr) && pElem)
- {
+ if (SUCCEEDED(hr) && pElem) {
BSTR bstrText = NULL;
pElem->get_innerText(&bstrText);
message = SysAllocString(bstrText);
@@ -718,8 +653,7 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
char *szData = NULL;
DBVARIANT dbVar = {0};
GetNewsData(tszURL, &szData, NULL, hwndDlg);
- if (szData)
- {
+ if (szData) {
TCHAR *tszData = mir_utf8decodeT(szData);
if (!tszData)
tszData = mir_a2t(szData);
@@ -727,20 +661,15 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
mir_free(tszData);
mir_free(szData);
- if (hXml != NULL)
- {
+ 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")))
- {
+ 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++)
- {
+ for (int j = 0; j < xi.getChildCount(chan); j++) {
HXML child = xi.getChild(chan, j);
- if (!lstrcmpi(xi.getName(child), _T("title")))
- {
+ 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(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
@@ -749,13 +678,10 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed")))
- {
- for (int j = 0; j < xi.getChildCount(node); j++)
- {
+ 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")))
- {
+ 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(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONINFORMATION);
@@ -770,8 +696,7 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
}
xi.destroyNode(hXml);
}
- else
- {
+ else {
TCHAR mes[MAX_PATH];
mir_sntprintf(mes, SIZEOF(mes), TranslateT("%s\nis a not valid feed's address."), tszURL);
MessageBox(NULL, mes, TranslateT("New Aggregator"), MB_OK|MB_ICONERROR);
@@ -783,14 +708,13 @@ VOID CheckCurrentFeed(HANDLE hContact)
{
char *szData = NULL;
DBVARIANT dbURL = {0};
- if (DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
+ if (db_get_ts(hContact, MODULE, "URL", &dbURL))
return;
- else if (db_get_b(hContact, MODULE, "CheckState", 1) != 0)
- {
+
+ if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
GetNewsData(dbURL.ptszVal, &szData, hContact, NULL);
- DBFreeVariant(&dbURL);
- if (szData)
- {
+ db_free(&dbURL);
+ if (szData) {
TCHAR *tszData = mir_utf8decodeT(szData);
if (!tszData)
tszData = mir_a2t(szData);
@@ -798,197 +722,163 @@ VOID CheckCurrentFeed(HANDLE hContact)
HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
mir_free(tszData);
mir_free(szData);
- if(hXml != NULL)
- {
+ 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")))
- {
- if (!lstrcmpi(xi.getName(node), _T("rss")))
- {
- for (int i = 0; i < xi.getAttrCount(node); i++)
- {
- if (!lstrcmpi(xi.getAttrName(node, i), _T("version")))
- {
+ 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)));
- DBWriteContactSettingTString(hContact, MODULE, "MirVer", ver);
+ db_set_ts(hContact, MODULE, "MirVer", ver);
break;
}
}
}
else if (!lstrcmpi(xi.getName(node), _T("rdf")))
- {
- DBWriteContactSettingTString(hContact, MODULE, "MirVer", _T("RSS 1.0"));
- }
+ 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++)
- {
+ 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))
- {
+ if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "FirstName", string);
+ db_set_ts(hContact, MODULE, "FirstName", string);
mir_free(string);
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("link")))
- {
- DBWriteContactSettingTString(hContact, MODULE, "Homepage", xi.getText(child));
+ if (!lstrcmpi(xi.getName(child), _T("link"))) {
+ db_set_ts(hContact, MODULE, "Homepage", xi.getText(child));
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("description")) && xi.getText(child))
- {
+ if (!lstrcmpi(xi.getName(child), _T("description")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "About", string);
- DBWriteContactSettingTString(hContact, "CList", "StatusMsg", 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))
- {
+ if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "Language1", string);
+ db_set_ts(hContact, MODULE, "Language1", string);
mir_free(string);
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("managingEditor")) && xi.getText(child))
- {
+ if (!lstrcmpi(xi.getName(child), _T("managingEditor")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "e-mail", string);
+ db_set_ts(hContact, MODULE, "e-mail", string);
mir_free(string);
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child))
- {
+ if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", 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++)
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
LPCTSTR url = xi.getText(imageval);
- DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
DBVARIANT dbVar = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbVar))
- {
+ 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))
- {
- DBWriteContactSettingTString(hContact, MODULE, "ImagePath", pai.filename);
+ 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);
- DBFreeVariant(&dbVar);
+ 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))
- {
+ 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), DBGetContactSettingDword(hContact, MODULE, "LastCheck", 0));
- if (deltaupd - deltacheck >= 0)
- {
+ double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
+ if (deltaupd - deltacheck >= 0) {
DBWriteContactSettingDword(hContact, MODULE, "LastCheck", time(NULL));
xi.destroyNode(hXml);
return;
}
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("item")))
- {
+ 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++)
- {
+ for (int z = 0; z < xi.getChildCount(child); z++) {
HXML itemval = xi.getChild(child, z);
- if (!lstrcmpi(xi.getName(itemval), _T("title")))
- {
+ 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")))
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(itemval), _T("pubDate"))) {
datetime = (TCHAR*)xi.getText(itemval);
continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("dc:date")))
- {
+ if (!lstrcmpi(xi.getName(itemval), _T("dc:date"))) {
datetime = (TCHAR*)xi.getText(itemval);
continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("description")))
- {
+ 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")))
- {
+ 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")))
- {
+ 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")))
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(itemval), _T("category"))) {
TCHAR *string = mir_tstrdup(xi.getText(itemval));
ClearText(string);
category = mir_tstrdup(string);
@@ -998,57 +888,50 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
TCHAR* message;
DBVARIANT dbMsg = {0};
- if (DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
+ if (db_get_ts(hContact, MODULE, "MsgFormat", &dbMsg))
message = _T(TAGSDEFAULT);
else
message = mir_tstrdup(dbMsg.ptszVal);
- DBFreeVariant(&dbMsg);
+ db_free(&dbMsg);
if (!title)
StrReplace(_T("#<title>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<title>#"), title, message);
mir_free(title);
}
if (!link)
StrReplace(_T("#<link>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<link>#"), link, message);
mir_free(link);
}
if (!descr)
StrReplace(_T("#<description>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<description>#"), descr, message);
mir_free(descr);
}
if (!author)
StrReplace(_T("#<author>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<author>#"), author, message);
mir_free(author);
}
if (!comments)
StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<comments>#"), comments, message);
mir_free(comments);
}
if (!guid)
StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<guid>#"), guid, message);
mir_free(guid);
}
if (!category)
StrReplace(_T("#<category>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<category>#"), category, message);
mir_free(category);
}
@@ -1061,8 +944,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
HANDLE hDbEvent = db_event_first(hContact);
BOOL MesExist = FALSE;
- while (hDbEvent)
- {
+ while (hDbEvent) {
DBEVENTINFO olddbei = { sizeof(olddbei) };
olddbei.cbBlob = db_event_getBlobSize(hDbEvent);
olddbei.pBlob = (PBYTE)mir_alloc(olddbei.cbBlob);
@@ -1075,8 +957,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
mir_free(pszTemp);
}
- if (!MesExist)
- {
+ if (!MesExist) {
PROTORECVEVENT recv;
recv.flags = PREF_TCHAR;
recv.timestamp = stamp;
@@ -1087,142 +968,114 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed")))
- {
- DBWriteContactSettingTString(hContact, MODULE, "MirVer", _T("Atom 3"));
- for (int j = 0; j < xi.getChildCount(node); j++)
- {
+ 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))
- {
+ if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "FirstName", 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.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")))
- {
- DBWriteContactSettingTString(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
- }
+ db_set_ts(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
}
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("subtitle")) && xi.getText(child))
- {
+ if (!lstrcmpi(xi.getName(child), _T("subtitle")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "About", string);
- DBWriteContactSettingTString(hContact, "CList", "StatusMsg", 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))
- {
+ if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "Language1", 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++)
- {
+ 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")))
- {
- DBWriteContactSettingTString(hContact, MODULE, "e-mail", xi.getText(authorval));
+ 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))
- {
+ if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child)) {
TCHAR *string = mir_tstrdup(xi.getText(child));
ClearText(string);
- DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", 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++)
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
LPCTSTR url = xi.getText(imageval);
- DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
DBVARIANT dbVar = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbVar))
- {
+ 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))
- {
- DBWriteContactSettingTString(hContact, MODULE, "ImagePath", pai.filename);
+ 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);
- DBFreeVariant(&dbVar);
+ 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))
- {
+ 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), DBGetContactSettingDword(hContact, MODULE, "LastCheck", 0));
- if (deltaupd - deltacheck >= 0)
- {
+ double deltacheck = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
+ if (deltaupd - deltacheck >= 0) {
DBWriteContactSettingDword(hContact, MODULE, "LastCheck", time(NULL));
xi.destroyNode(hXml);
return;
}
continue;
}
- if (!lstrcmpi(xi.getName(child), _T("entry")))
- {
+ 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++)
- {
+ 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))
- {
+ 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")))
- {
+ 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;
@@ -1231,25 +1084,20 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("updated")))
- {
+ 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))
- {
+ 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++)
- {
+ 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))
- {
+ if (!lstrcmpi(xi.getName(authorval), _T("name")) && xi.getText(authorval)) {
TCHAR *string = mir_tstrdup(xi.getText(authorval));
ClearText(string);
author = string;
@@ -1258,26 +1106,21 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (!lstrcmpi(xi.getName(itemval), _T("comments")) && xi.getText(itemval))
- {
+ 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")))
- {
+ 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))
- {
+ 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;
@@ -1289,58 +1132,51 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
TCHAR* message;
DBVARIANT dbMsg = {0};
- if (DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
+ if (db_get_ts(hContact, MODULE, "MsgFormat", &dbMsg))
message = _T(TAGSDEFAULT);
else
message = mir_tstrdup(dbMsg.ptszVal);
- DBFreeVariant(&dbMsg);
+ db_free(&dbMsg);
if (!title)
StrReplace(_T("#<title>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<title>#"), title, message);
mir_free(title);
}
if (!link)
StrReplace(_T("#<link>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<link>#"), link, message);
mir_free(link);
}
if (!descr)
StrReplace(_T("#<description>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<description>#"), descr, message);
mir_free(descr);
}
if (!author)
StrReplace(_T("#<author>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<author>#"), author, message);
mir_free(author);
}
if (!comments)
StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<comments>#"), comments, message);
mir_free(comments);
}
if (!guid)
StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<guid>#"), guid, message);
mir_free(guid);
}
if (!category)
StrReplace(_T("#<category>#"), TranslateT("empty"), message);
- else
- {
+ else {
StrReplace(_T("#<category>#"), category, message);
mir_free(category);
}
@@ -1353,8 +1189,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
HANDLE hDbEvent = db_event_first(hContact);
BOOL MesExist = FALSE;
- while (hDbEvent)
- {
+ while (hDbEvent) {
DBEVENTINFO olddbei = { sizeof(olddbei) };
olddbei.cbBlob = db_event_getBlobSize(hDbEvent);
olddbei.pBlob = (PBYTE)mir_alloc(olddbei.cbBlob);
@@ -1367,8 +1202,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
mir_free(pszTemp);
}
- if (!MesExist)
- {
+ if (!MesExist) {
PROTORECVEVENT recv;
recv.flags = PREF_TCHAR;
recv.timestamp = stamp;
@@ -1393,14 +1227,13 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
{
char *szData = NULL;
DBVARIANT dbURL = {0};
- if (DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
+ if (db_get_ts(hContact, MODULE, "URL", &dbURL))
return;
- else if (db_get_b(hContact, MODULE, "CheckState", 1) != 0)
- {
+
+ if (db_get_b(hContact, MODULE, "CheckState", 1) != 0) {
GetNewsData(dbURL.ptszVal, &szData, hContact, NULL);
- DBFreeVariant(&dbURL);
- if (szData)
- {
+ db_free(&dbURL);
+ if (szData) {
TCHAR *tszData = mir_utf8decodeT(szData);
if (!tszData)
tszData = mir_a2t(szData);
@@ -1408,48 +1241,38 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
HXML hXml = xi.parseString(tszData, &bytesParsed, NULL);
mir_free(tszData);
mir_free(szData);
- if(hXml != NULL)
- {
+ 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")))
- {
+ 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++)
- {
+ 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++)
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
LPCTSTR url = xi.getText(imageval);
- DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
DBVARIANT dbVar = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbVar))
- {
+ 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))
- {
- DBWriteContactSettingTString(hContact, MODULE, "ImagePath", pai.filename);
+ 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);
- DBFreeVariant(&dbVar);
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
+ db_free(&dbVar);
break;
}
}
@@ -1457,41 +1280,33 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
}
}
}
- else if (!lstrcmpi(xi.getName(node), _T("feed")))
- {
- for (int j = 0; j < xi.getChildCount(node); j++)
- {
+ 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++)
- {
+ 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")))
- {
+ if (!lstrcmpi(xi.getName(imageval), _T("url"))) {
LPCTSTR url = xi.getText(imageval);
- DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
+ db_set_ts(hContact, MODULE, "ImageURL", url);
PROTO_AVATAR_INFORMATIONT pai = {NULL};
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
DBVARIANT dbVar = {0};
- if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbVar))
- {
+ 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))
- {
- DBWriteContactSettingTString(hContact, MODULE, "ImagePath", pai.filename);
+ 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);
- DBFreeVariant(&dbVar);
+ else ProtoBroadcastAck(MODULE, hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE) &pai, NULL);
+ db_free(&dbVar);
break;
}
}
@@ -1506,4 +1321,4 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
}
}
}
-} \ No newline at end of file
+}