summaryrefslogtreecommitdiff
path: root/protocols/NewsAggregator/Src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2012-06-14 21:12:01 +0000
committerKirill Volinsky <mataes2007@gmail.com>2012-06-14 21:12:01 +0000
commit017bb0233c3495eb6b441f5adbfb864f8ac93dce (patch)
tree62fbd2e6fbb5a4a63772248581001c08f76491a1 /protocols/NewsAggregator/Src
parent37f6d368b6214799b74dbc6050db106cb9df68af (diff)
NewsAggregator:
working without boost libs (maybe have bugs) Check News Feed when message dialog is opened git-svn-id: http://svn.miranda-ng.org/main/trunk@418 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/NewsAggregator/Src')
-rw-r--r--protocols/NewsAggregator/Src/Common.h5
-rw-r--r--protocols/NewsAggregator/Src/Entities.cpp381
-rw-r--r--protocols/NewsAggregator/Src/Services.cpp14
-rw-r--r--protocols/NewsAggregator/Src/Utils.cpp562
4 files changed, 318 insertions, 644 deletions
diff --git a/protocols/NewsAggregator/Src/Common.h b/protocols/NewsAggregator/Src/Common.h
index fedb81250c..63f436e667 100644
--- a/protocols/NewsAggregator/Src/Common.h
+++ b/protocols/NewsAggregator/Src/Common.h
@@ -29,8 +29,7 @@ Boston, MA 02111-1307, USA.
#include <string.h>
#include <stdlib.h>
#include <sys\stat.h>
-
-#include <boost/regex.hpp>
+#include <mshtml.h>
// Miranda header files
#include <newpluginapi.h>
@@ -45,6 +44,7 @@ Boston, MA 02111-1307, USA.
#include <m_hotkeys.h>
#include <m_netlib.h>
#include <m_icolib.h>
+#include <m_message.h>
#include <win2k.h>
#include <m_protocols.h>
#include <m_protomod.h>
@@ -134,7 +134,6 @@ VOID DeleteAllItems(HWND hwndList);
time_t __stdcall DateToUnixTime(TCHAR *stamp, BOOL FeedType);
VOID CheckCurrentFeed (HANDLE hContact);
TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg);
-size_t decode_html_entities_utf8(char *dest, const char *src);
// =============== NewsAggr SERVICES ================
// Check all Feeds info
diff --git a/protocols/NewsAggregator/Src/Entities.cpp b/protocols/NewsAggregator/Src/Entities.cpp
deleted file mode 100644
index 46a00d2d8d..0000000000
--- a/protocols/NewsAggregator/Src/Entities.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-#include "common.h"
-
-#define UNICODE_MAX 0x10FFFFul
-
-static const char *named_entities[][2] =
-{
- { "AElig;", "Æ" },
- { "Aacute;", "Á" },
- { "Acirc;", "Â" },
- { "Agrave;", "À" },
- { "Alpha;", "Α" },
- { "Aring;", "Å" },
- { "Atilde;", "Ã" },
- { "Auml;", "Ä" },
- { "Beta;", "Β" },
- { "Ccedil;", "Ç" },
- { "Chi;", "Χ" },
- { "Dagger;", "‡" },
- { "Delta;", "Δ" },
- { "ETH;", "Ð" },
- { "Eacute;", "É" },
- { "Ecirc;", "Ê" },
- { "Egrave;", "È" },
- { "Epsilon;", "Ε" },
- { "Eta;", "Η" },
- { "Euml;", "Ë" },
- { "Gamma;", "Γ" },
- { "Iacute;", "Í" },
- { "Icirc;", "Î" },
- { "Igrave;", "Ì" },
- { "Iota;", "Ι" },
- { "Iuml;", "Ï" },
- { "Kappa;", "Κ" },
- { "Lambda;", "Λ" },
- { "Mu;", "Μ" },
- { "Ntilde;", "Ñ" },
- { "Nu;", "Ν" },
- { "OElig;", "Œ" },
- { "Oacute;", "Ó" },
- { "Ocirc;", "Ô" },
- { "Ograve;", "Ò" },
- { "Omega;", "Ω" },
- { "Omicron;", "Ο" },
- { "Oslash;", "Ø" },
- { "Otilde;", "Õ" },
- { "Ouml;", "Ö" },
- { "Phi;", "Φ" },
- { "Pi;", "Π" },
- { "Prime;", "″" },
- { "Psi;", "Ψ" },
- { "Rho;", "Ρ" },
- { "Scaron;", "Š" },
- { "Sigma;", "Σ" },
- { "THORN;", "Þ" },
- { "Tau;", "Τ" },
- { "Theta;", "Θ" },
- { "Uacute;", "Ú" },
- { "Ucirc;", "Û" },
- { "Ugrave;", "Ù" },
- { "Upsilon;", "Υ" },
- { "Uuml;", "Ü" },
- { "Xi;", "Ξ" },
- { "Yacute;", "Ý" },
- { "Yuml;", "Ÿ" },
- { "Zeta;", "Ζ" },
- { "aacute;", "á" },
- { "acirc;", "â" },
- { "acute;", "´" },
- { "aelig;", "æ" },
- { "agrave;", "à" },
- { "alefsym;", "ℵ" },
- { "alpha;", "α" },
- { "amp;", "&" },
- { "and;", "∧" },
- { "ang;", "∠" },
- { "apos;", "'" },
- { "aring;", "å" },
- { "asymp;", "≈" },
- { "atilde;", "ã" },
- { "auml;", "ä" },
- { "bdquo;", "„" },
- { "beta;", "β" },
- { "brvbar;", "¦" },
- { "bull;", "•" },
- { "cap;", "∩" },
- { "ccedil;", "ç" },
- { "cedil;", "¸" },
- { "cent;", "¢" },
- { "chi;", "χ" },
- { "circ;", "ˆ" },
- { "clubs;", "♣" },
- { "cong;", "≅" },
- { "copy;", "©" },
- { "crarr;", "↵" },
- { "cup;", "∪" },
- { "curren;", "¤" },
- { "dArr;", "⇓" },
- { "dagger;", "†" },
- { "darr;", "↓" },
- { "deg;", "°" },
- { "delta;", "δ" },
- { "diams;", "♦" },
- { "divide;", "÷" },
- { "eacute;", "é" },
- { "ecirc;", "ê" },
- { "egrave;", "è" },
- { "empty;", "∅" },
- { "emsp;", " " },
- { "ensp;", " " },
- { "epsilon;", "ε" },
- { "equiv;", "≡" },
- { "eta;", "η" },
- { "eth;", "ð" },
- { "euml;", "ë" },
- { "euro;", "€" },
- { "exist;", "∃" },
- { "fnof;", "ƒ" },
- { "forall;", "∀" },
- { "frac12;", "½" },
- { "frac14;", "¼" },
- { "frac34;", "¾" },
- { "frasl;", "⁄" },
- { "gamma;", "γ" },
- { "ge;", "≥" },
- { "gt;", ">" },
- { "hArr;", "⇔" },
- { "harr;", "↔" },
- { "hearts;", "♥" },
- { "hellip;", "…" },
- { "iacute;", "í" },
- { "icirc;", "î" },
- { "iexcl;", "¡" },
- { "igrave;", "ì" },
- { "image;", "ℑ" },
- { "infin;", "∞" },
- { "int;", "∫" },
- { "iota;", "ι" },
- { "iquest;", "¿" },
- { "isin;", "∈" },
- { "iuml;", "ï" },
- { "kappa;", "κ" },
- { "lArr;", "⇐" },
- { "lambda;", "λ" },
- { "lang;", "〈" },
- { "laquo;", "«" },
- { "larr;", "←" },
- { "lceil;", "⌈" },
- { "ldquo;", "“" },
- { "le;", "≤" },
- { "lfloor;", "⌊" },
- { "lowast;", "∗" },
- { "loz;", "◊" },
- { "lrm;", "\xE2\x80\x8E" },
- { "lsaquo;", "‹" },
- { "lsquo;", "‘" },
- { "lt;", "<" },
- { "macr;", "¯" },
- { "mdash;", "—" },
- { "micro;", "µ" },
- { "middot;", "·" },
- { "minus;", "−" },
- { "mu;", "μ" },
- { "nabla;", "∇" },
- { "nbsp;", " " },
- { "ndash;", "–" },
- { "ne;", "≠" },
- { "ni;", "∋" },
- { "not;", "¬" },
- { "notin;", "∉" },
- { "nsub;", "⊄" },
- { "ntilde;", "ñ" },
- { "nu;", "ν" },
- { "oacute;", "ó" },
- { "ocirc;", "ô" },
- { "oelig;", "œ" },
- { "ograve;", "ò" },
- { "oline;", "‾" },
- { "omega;", "ω" },
- { "omicron;", "ο" },
- { "oplus;", "⊕" },
- { "or;", "∨" },
- { "ordf;", "ª" },
- { "ordm;", "º" },
- { "oslash;", "ø" },
- { "otilde;", "õ" },
- { "otimes;", "⊗" },
- { "ouml;", "ö" },
- { "para;", "¶" },
- { "part;", "∂" },
- { "permil;", "‰" },
- { "perp;", "⊥" },
- { "phi;", "φ" },
- { "pi;", "π" },
- { "piv;", "ϖ" },
- { "plusmn;", "±" },
- { "pound;", "£" },
- { "prime;", "′" },
- { "prod;", "∏" },
- { "prop;", "∝" },
- { "psi;", "ψ" },
- { "quot;", "\"" },
- { "rArr;", "⇒" },
- { "radic;", "√" },
- { "rang;", "〉" },
- { "raquo;", "»" },
- { "rarr;", "→" },
- { "rceil;", "⌉" },
- { "rdquo;", "”" },
- { "real;", "ℜ" },
- { "reg;", "®" },
- { "rfloor;", "⌋" },
- { "rho;", "ρ" },
- { "rlm;", "\xE2\x80\x8F" },
- { "rsaquo;", "›" },
- { "rsquo;", "’" },
- { "sbquo;", "‚" },
- { "scaron;", "š" },
- { "sdot;", "⋅" },
- { "sect;", "§" },
- { "shy;", "\xC2\xAD" },
- { "sigma;", "σ" },
- { "sigmaf;", "ς" },
- { "sim;", "∼" },
- { "spades;", "♠" },
- { "sub;", "⊂" },
- { "sube;", "⊆" },
- { "sum;", "∑" },
- { "sup;", "⊃" },
- { "sup1;", "¹" },
- { "sup2;", "²" },
- { "sup3;", "³" },
- { "supe;", "⊇" },
- { "szlig;", "ß" },
- { "tau;", "τ" },
- { "there4;", "∴" },
- { "theta;", "θ" },
- { "thetasym;", "ϑ" },
- { "thinsp;", " " },
- { "thorn;", "þ" },
- { "tilde;", "˜" },
- { "times;", "×" },
- { "trade;", "™" },
- { "uArr;", "⇑" },
- { "uacute;", "ú" },
- { "uarr;", "↑" },
- { "ucirc;", "û" },
- { "ugrave;", "ù" },
- { "uml;", "¨" },
- { "upsih;", "ϒ" },
- { "upsilon;", "υ" },
- { "uuml;", "ü" },
- { "weierp;", "℘" },
- { "xi;", "ξ" },
- { "yacute;", "ý" },
- { "yen;", "¥" },
- { "yuml;", "ÿ" },
- { "zeta;", "ζ" },
- { "zwj;", "\xE2\x80\x8D" },
- { "zwnj;", "\xE2\x80\x8C" }
-};
-
-static int cmp(const void *key, const void *element)
-{
- return strncmp((const char *)key, *(const char **)element,
- strlen(*(const char **)element));
-}
-
-static const char *get_named_entity(const char *name)
-{
- const char **entity = (const char **)bsearch(name, named_entities, sizeof(named_entities) / sizeof(*named_entities),
- sizeof(*named_entities), cmp);
-
- return entity ? entity[1] : NULL;
-}
-
-static size_t putc_utf8(unsigned long cp, char *buffer)
-{
- unsigned char *bytes = (unsigned char *)buffer;
-
- if(cp <= 0x007Ful)
- {
- bytes[0] = (unsigned char)cp;
- return 1;
- }
-
- if(cp <= 0x07FFul)
- {
- bytes[1] = (unsigned char)((2u << 6) | (cp & 0x3Fu));
- bytes[0] = (unsigned char)((6u << 5) | (cp >> 6));
- return 2;
- }
-
- if(cp <= 0xFFFFul)
- {
- bytes[2] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu));
- bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu));
- bytes[0] = (unsigned char)((14u << 4) | (cp >> 12));
- return 3;
- }
-
- if(cp <= 0x10FFFFul)
- {
- bytes[3] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu));
- bytes[2] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu));
- bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 12) & 0x3Fu));
- bytes[0] = (unsigned char)((30u << 3) | (cp >> 18));
- return 4;
- }
-
- return 0;
-}
-
-static BOOL parse_entity(const char *current, char **to, const char **from)
-{
- const char *end = strchr(current, ';');
- if (!end) return 0;
-
- if(current[1] == '#')
- {
- char *tail = NULL;
- errno = 0;
-
- BOOL hex = current[2] == 'x' || current[2] == 'X';
-
- unsigned long cp = strtoul(
- current + (hex ? 3 : 2), &tail, hex ? 16 : 10);
-
- if(tail == end && !errno && cp <= UNICODE_MAX)
- {
- *to += putc_utf8(cp, *to);
- *from = end + 1;
-
- return 1;
- }
- }
- else
- {
- const char *entity = get_named_entity(&current[1]);
- if(entity)
- {
- size_t len = strlen(entity);
- memcpy(*to, entity, len);
-
- *to += len;
- *from = end + 1;
-
- return 1;
- }
- }
-
- return 0;
-}
-
-size_t decode_html_entities_utf8(char *dest, const char *src)
-{
- if (!src) src = dest;
-
- char *to = dest;
- const char *from = src;
-
- const char *current;
- while(current = strchr(from, '&'))
- {
- memcpy(to, from, (size_t)(current - from));
- to += current - from;
-
- if(parse_entity(current, &to, &from))
- continue;
-
- from = current;
- *to++ = *from++;
- }
-
- size_t remaining = strlen(from);
-
- memcpy(to, from, remaining);
- to += remaining;
-
- *to = 0;
- return (size_t)(to - dest);
-} \ No newline at end of file
diff --git a/protocols/NewsAggregator/Src/Services.cpp b/protocols/NewsAggregator/Src/Services.cpp
index 0c23983c79..38213c0ce6 100644
--- a/protocols/NewsAggregator/Src/Services.cpp
+++ b/protocols/NewsAggregator/Src/Services.cpp
@@ -22,6 +22,16 @@ Boston, MA 02111-1307, USA.
int g_nStatus = ID_STATUS_OFFLINE;
UINT_PTR timerId = 0;
+HANDLE hOpenMessageWindow = NULL;
+
+int OnMessageWindowOpen(WPARAM,LPARAM lParam)
+{
+ MessageWindowEventData *hWindowEvent = (MessageWindowEventData*) lParam;
+ if (hWindowEvent->uType == MSG_WINDOW_EVT_OPENING && IsMyContact(hWindowEvent->hContact))
+ CheckCurrentFeed(hWindowEvent->hContact);
+ return 0;
+}
+
void SetContactStatus(HANDLE hContact,int nNewStatus)
{
if(DBGetContactSettingWord(hContact,MODULE,"Status",ID_STATUS_OFFLINE) != nNewStatus)
@@ -58,6 +68,8 @@ int NewsAggrInit(WPARAM wParam,LPARAM lParam)
InitIcons();
InitMenu();
+ hOpenMessageWindow = HookEvent(ME_MSG_WINDOWEVENT,OnMessageWindowOpen);
+
// timer for the first update
timerId = SetTimer(NULL, 0, 5000, timerProc2); // first update is 5 sec after load
@@ -76,6 +88,8 @@ int NewsAggrPreShutdown(WPARAM wParam,LPARAM lParam)
KillTimer(NULL, timerId);
NetlibUnInit();
+ if(hOpenMessageWindow) UnhookEvent(hOpenMessageWindow);
+
return 0;
}
diff --git a/protocols/NewsAggregator/Src/Utils.cpp b/protocols/NewsAggregator/Src/Utils.cpp
index c42a3f7dd1..f76e680774 100644
--- a/protocols/NewsAggregator/Src/Utils.cpp
+++ b/protocols/NewsAggregator/Src/Utils.cpp
@@ -62,38 +62,34 @@ static void arrayToHex(BYTE* data, size_t datasz, char* res)
int GetImageFormat(const TCHAR* ext)
{
- if(lstrcmp(ext,_T(".jpg")) || lstrcmp(ext,_T(".jpeg")))
+ if(!lstrcmp(ext,_T(".jpg")) || !lstrcmp(ext,_T(".jpeg")))
{
return PA_FORMAT_JPEG;
}
- else if(lstrcmp(ext,_T(".png")))
+ else if(!lstrcmp(ext,_T(".png")))
{
return PA_FORMAT_PNG;
}
- else if(lstrcmp(ext,_T(".gif")))
+ else if(!lstrcmp(ext,_T(".gif")))
{
return PA_FORMAT_GIF;
}
- else if(lstrcmp(ext,_T(".ico")))
+ else if(!lstrcmp(ext,_T(".ico")))
{
return PA_FORMAT_ICON;
}
- else if(lstrcmp(ext,_T(".bmp")))
+ else if(!lstrcmp(ext,_T(".bmp")))
{
return PA_FORMAT_BMP;
}
- else if(lstrcmp(ext,_T(".swf")))
+ else if(!lstrcmp(ext,_T(".swf")))
{
return PA_FORMAT_SWF;
}
- else if(lstrcmp(ext,_T(".xml")))
+ else if(!lstrcmp(ext,_T(".xml")))
{
return PA_FORMAT_XML;
}
- else if(lstrcmp(ext,_T(".jpg")) || lstrcmp(ext,_T(".jpeg")))
- {
- return PA_FORMAT_JPEG;
- }
else
{
return PA_FORMAT_UNKNOWN;
@@ -108,17 +104,13 @@ void CreateAuthString(char* auth, HANDLE hContact, HWND hwndDlg)
DBVARIANT dbLogin = {0};
if (!DBGetContactSettingTString(hContact, MODULE, "Login", &dbLogin))
{
- tlogin = (TCHAR*)mir_alloc(_tcslen(dbLogin.ptszVal)*sizeof(TCHAR));
- memcpy(tlogin, dbLogin.ptszVal, _tcslen(dbLogin.ptszVal)*sizeof(TCHAR));
- tlogin[_tcslen(dbLogin.ptszVal)] = 0;
+ tlogin = mir_tstrdup(dbLogin.ptszVal);
DBFreeVariant(&dbLogin);
}
DBVARIANT dbPass = {0};
if (!DBGetContactSettingTString(hContact, MODULE, "Password", &dbPass))
{
- tpass = (TCHAR*)mir_alloc(_tcslen(dbPass.ptszVal)*sizeof(TCHAR));
- memcpy(tpass, dbPass.ptszVal, _tcslen(dbPass.ptszVal)*sizeof(TCHAR));
- tpass[_tcslen(dbPass.ptszVal)] = 0;
+ tpass = mir_tstrdup(dbPass.ptszVal);
DBFreeVariant(&dbPass);
}
}
@@ -136,6 +128,8 @@ void CreateAuthString(char* auth, HANDLE hContact, HWND hwndDlg)
int len = mir_snprintf(str, SIZEOF(str), "%s:%s", user, pass);
mir_free(user);
mir_free(pass);
+ mir_free(tlogin);
+ mir_free(tpass);
strcpy(auth, "Basic ");
NETLIBBASE64 nlb = { auth+6, 250, (PBYTE)str, len };
@@ -342,33 +336,33 @@ time_t __stdcall DateToUnixTime(TCHAR* stamp, BOOL FeedType)
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")) ==0)
+ if (!lstrcmpi(monthstr, _T("Jan")))
month = 1;
- if (lstrcmpi(monthstr, _T("Feb")) ==0)
+ if (!lstrcmpi(monthstr, _T("Feb")))
month = 2;
- if (lstrcmpi(monthstr, _T("Mar")) ==0)
+ if (!lstrcmpi(monthstr, _T("Mar")))
month = 3;
- if (lstrcmpi(monthstr, _T("Apr")) ==0)
+ if (!lstrcmpi(monthstr, _T("Apr")))
month = 4;
- if (lstrcmpi(monthstr, _T("May")) ==0)
+ if (!lstrcmpi(monthstr, _T("May")))
month = 5;
- if (lstrcmpi(monthstr, _T("Jun")) ==0)
+ if (!lstrcmpi(monthstr, _T("Jun")))
month = 6;
- if (lstrcmpi(monthstr, _T("Jul")) ==0)
+ if (!lstrcmpi(monthstr, _T("Jul")))
month = 7;
- if (lstrcmpi(monthstr, _T("Aug")) ==0)
+ if (!lstrcmpi(monthstr, _T("Aug")))
month = 8;
- if (lstrcmpi(monthstr, _T("Sep")) ==0)
+ if (!lstrcmpi(monthstr, _T("Sep")))
month = 9;
- if (lstrcmpi(monthstr, _T("Oct")) ==0)
+ if (!lstrcmpi(monthstr, _T("Oct")))
month = 10;
- if (lstrcmpi(monthstr, _T("Nov")) ==0)
+ if (!lstrcmpi(monthstr, _T("Nov")))
month = 11;
- if (lstrcmpi(monthstr, _T("Dec")) ==0)
+ if (!lstrcmpi(monthstr, _T("Dec")))
month = 12;
- if (lstrcmp(timezonesign, _T("+")) ==0)
+ if (!lstrcmp(timezonesign, _T("+")))
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour-timezoneh, min-timezonem, sec);
- else if (lstrcmp(timezonesign, _T("-")) ==0)
+ else if (!lstrcmp(timezonesign, _T("-")))
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour+timezoneh, min+timezonem, sec);
else
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour, min, sec);
@@ -376,9 +370,9 @@ time_t __stdcall DateToUnixTime(TCHAR* stamp, BOOL FeedType)
else
{
_stscanf( p, _T("%d-%d-%d %d:%d:%d %1s%02d%02d"), &year, &month, &day, &hour, &min, &sec, &timezonesign, &timezoneh, &timezonem);
- if (lstrcmp(timezonesign, _T("+")) ==0)
+ if (!lstrcmp(timezonesign, _T("+")))
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour-timezoneh, min-timezonem, sec);
- else if (lstrcmp(timezonesign, _T("-")) ==0)
+ else if (!lstrcmp(timezonesign, _T("-")))
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour+timezoneh, min+timezonem, sec);
else
mir_sntprintf(p, 4+2+2+1+2+1+2+1+2+1, _T("%04d%02d%02dT%02d:%02d:%02d"), year, month, day, hour, min, sec);
@@ -492,12 +486,12 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
char *date = NULL, *size = NULL;
for (int i = 0; i < pReply->headersCount; i++)
{
- if (lstrcmpiA(pReply->headers[i].szName, "Last-Modified") == 0)
+ if (!lstrcmpiA(pReply->headers[i].szName, "Last-Modified"))
{
date = pReply->headers[i].szValue;
continue;
}
- if (lstrcmpiA(pReply->headers[i].szName, "Content-Length") == 0)
+ if (!lstrcmpiA(pReply->headers[i].szName, "Content-Length"))
{
size = pReply->headers[i].szValue;
continue;
@@ -553,7 +547,109 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
}
size_t PathToRelative(const TCHAR *pSrc, TCHAR *pOut)
-{ return CallService( MS_UTILS_PATHTORELATIVET, (WPARAM)pSrc, (LPARAM)pOut );
+{
+ return CallService( MS_UTILS_PATHTORELATIVET, (WPARAM)pSrc, (LPARAM)pOut );
+}
+
+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;
+}
+
+HRESULT TestDocumentText(IHTMLDocument3* pHtmlDoc, BSTR& message)
+{
+ IHTMLDocument2 *pDoc = NULL;
+ IHTMLElement *pElem = NULL;
+ BSTR bstrId = SysAllocString(L"test");
+
+ HRESULT hr = pHtmlDoc->QueryInterface(IID_PPV_ARGS(&pDoc));
+ if (SUCCEEDED(hr) && pDoc)
+ {
+ hr = pDoc->get_body(&pElem);
+ if (SUCCEEDED(hr) && pElem)
+ {
+ BSTR bstrText = NULL;
+ pElem->get_innerText(&bstrText);
+ message = SysAllocString(bstrText);
+ SysFreeString(bstrText);
+ pElem->Release();
+ }
+
+ pDoc->Release();
+ }
+
+ SysFreeString(bstrId);
+ return hr;
+}
+
+VOID ClearText(TCHAR*& message)
+{
+ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+ BSTR bstrHtml = SysAllocString(message);
+ HRESULT hr = TestMarkupServices(bstrHtml, &TestDocumentText, message);
+ SysFreeString(bstrHtml);
+ CoUninitialize();
}
TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
@@ -583,13 +679,13 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
HXML node = xi.getChild(hXml, childcount);
while(node)
{
- if (lstrcmpi(xi.getName(node), _T("rss")) == 0 || lstrcmpi(xi.getName(node), _T("rdf")) == 0)
+ 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")) == 0)
+ 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);
@@ -608,12 +704,12 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg)
}
}
}
- else if (lstrcmpi(xi.getName(node), _T("feed")) == 0)
+ 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")) == 0)
+ 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);
@@ -678,13 +774,13 @@ VOID CheckCurrentFeed(HANDLE hContact)
HXML node = xi.getChild(hXml, childcount);
while(node)
{
- if (lstrcmpi(xi.getName(node), _T("rss")) == 0 || lstrcmpi(xi.getName(node), _T("rdf")) == 0)
+ if (!lstrcmpi(xi.getName(node), _T("rss")) || !lstrcmpi(xi.getName(node), _T("rdf")))
{
- if (lstrcmpi(xi.getName(node), _T("rss")) == 0)
+ if (!lstrcmpi(xi.getName(node), _T("rss")))
{
for (int i = 0; i < xi.getAttrCount(node); i++)
{
- if (lstrcmpi(xi.getAttrName(node, i), _T("version")) == 0)
+ 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)));
@@ -693,7 +789,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
}
}
- else if (lstrcmpi(xi.getName(node), _T("rdf")) == 0)
+ else if (!lstrcmpi(xi.getName(node), _T("rdf")))
{
DBWriteContactSettingTString(hContact, MODULE, "MirVer", _T("RSS 1.0"));
}
@@ -702,129 +798,114 @@ VOID CheckCurrentFeed(HANDLE hContact)
for (int j = 0; j < xi.getChildCount(chan); j++)
{
HXML child = xi.getChild(chan, j);
- if (lstrcmpi(xi.getName(child), _T("title")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "FirstName", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "FirstName", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "FirstName", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("link")) == 0)
+ if (!lstrcmpi(xi.getName(child), _T("link")))
{
DBWriteContactSettingTString(hContact, MODULE, "Homepage", xi.getText(child));
continue;
}
- if (lstrcmpi(xi.getName(child), _T("description")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("description")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "About", tszstring);
DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "About", tszstring);
- DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "About", string);
+ DBWriteContactSettingTString(hContact, "CList", "StatusMsg", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("language")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "Language1", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "Language1", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "Language1", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("managingEditor")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("managingEditor")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "e-mail", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "e-mail", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "e-mail", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("category")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("image")) == 0)
+ 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")) == 0)
+ if (!lstrcmpi(xi.getName(imageval), _T("url")))
{
LPCTSTR url = xi.getText(imageval);
DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
@@ -859,7 +940,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
}
}
- if (lstrcmpi(xi.getName(child), _T("lastBuildDate")) == 0 && 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);
@@ -873,53 +954,53 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (lstrcmpi(xi.getName(child), _T("item")) == 0)
+ 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")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("title")))
{
title = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("link")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("link")))
{
link = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("pubDate")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("pubDate")))
{
datetime = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("dc:date")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("dc:date")))
{
datetime = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("description")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("description")))
{
descr = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("author")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("author")))
{
author = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("comments")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("comments")))
{
comments = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("guid")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("guid")))
{
guid = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("category")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("category")))
{
category = (TCHAR*)xi.getText(itemval);
continue;
@@ -930,60 +1011,46 @@ VOID CheckCurrentFeed(HANDLE hContact)
if (DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
message = _T(TAGSDEFAULT);
else
- {
- message = (TCHAR*)mir_alloc(_tcslen(dbMsg.ptszVal)*sizeof(TCHAR));
- memcpy(message, dbMsg.ptszVal, _tcslen(dbMsg.ptszVal)*sizeof(TCHAR));
- message[_tcslen(dbMsg.ptszVal)] = 0;
- DBFreeVariant(&dbMsg);
- }
- if (lstrcmp(title, NULL) == 0)
+ message = mir_tstrdup(dbMsg.ptszVal);
+ DBFreeVariant(&dbMsg);
+ if (!title)
message = StrReplace(_T("#<title>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<title>#"), title, message);
- if (lstrcmp(link, NULL) == 0)
+ if (!link)
message = StrReplace(_T("#<link>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<link>#"), link, message);
- if (lstrcmp(descr, NULL) == 0)
+ if (!descr)
message = StrReplace(_T("#<description>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<description>#"), descr, message);
- if (lstrcmp(author, NULL) == 0)
+ if (!author)
message = StrReplace(_T("#<author>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<author>#"), author, message);
- if (lstrcmp(comments, NULL) == 0)
+ if (!comments)
message = StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<comments>#"), comments, message);
- if (lstrcmp(guid, NULL) == 0)
+ if (!guid)
message = StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<guid>#"), guid, message);
- if (lstrcmp(category, NULL) == 0)
+ if (!category)
message = StrReplace(_T("#<category>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<category>#"), category, message);
- message = StrReplace(_T("<br>"), _T("\n"), message);
- message = StrReplace(_T("<br/>"), _T("\n"), message);
- message = StrReplace(_T("<br />"), _T("\n"), message);
-
+ ClearText(message);
char* pszUtf;
if (!UtfEncode)
pszUtf = mir_utf8encodeT(message);
else
pszUtf = mir_t2a(message);
- decode_html_entities_utf8(pszUtf, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(pszUtf);
- strcpy(pszUtf, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- xRegEx = "^\\s+";
- xStr = pszUtf;
- strcpy(pszUtf, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
time_t stamp;
- if (lstrcmpi(datetime, NULL) ==0)
+ if (!datetime)
stamp = time(NULL);
else
stamp = DateToUnixTime(datetime, 0);
@@ -998,7 +1065,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
olddbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0);
olddbei.pBlob = (PBYTE)mir_alloc(olddbei.cbBlob);
CallService(MS_DB_EVENT_GET, (WPARAM)hDbEvent, (LPARAM)&olddbei);
- if (olddbei.cbBlob == lstrlenA(pszUtf) + 1 && lstrcmpA((char*)olddbei.pBlob, pszUtf) == 0)
+ if (olddbei.cbBlob == lstrlenA(pszUtf) + 1 && !lstrcmpA((char*)olddbei.pBlob, pszUtf))
MesExist = TRUE;
hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hDbEvent, 0);
mir_free(olddbei.pBlob);
@@ -1017,106 +1084,97 @@ VOID CheckCurrentFeed(HANDLE hContact)
CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei);
}
mir_free(pszUtf);
- mir_free(message);
+ SysFreeString(message);
}
}
}
- else if (lstrcmpi(xi.getName(node), _T("feed")) == 0)
+ else if (!lstrcmpi(xi.getName(node), _T("feed")))
{
DBWriteContactSettingTString(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")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("title")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "FirstName", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "FirstName", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "FirstName", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("link")) == 0)
+ if (!lstrcmpi(xi.getName(child), _T("link")))
{
for (int x = 0; x < xi.getAttrCount(child); x++)
{
- if (lstrcmpi(xi.getAttrName(child, x), _T("rel")) == 0)
+ if (!lstrcmpi(xi.getAttrName(child, x), _T("rel")))
{
- if (lstrcmpi(xi.getAttrValue(child, xi.getAttrName(child, x)), _T("self")) == 0)
+ if (!lstrcmpi(xi.getAttrValue(child, xi.getAttrName(child, x)), _T("self")))
break;
}
- if (lstrcmpi(xi.getAttrName(child, x), _T("href")) == 0)
+ if (!lstrcmpi(xi.getAttrName(child, x), _T("href")))
{
DBWriteContactSettingTString(hContact, MODULE, "Homepage", xi.getAttrValue(child, xi.getAttrName(child, x)));
}
}
continue;
}
- if (lstrcmpi(xi.getName(child), _T("subtitle")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("subtitle")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "About", tszstring);
DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "About", tszstring);
- DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "About", string);
+ DBWriteContactSettingTString(hContact, "CList", "StatusMsg", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("language")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("language")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "Language1", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "Language1", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "Language1", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("author")) == 0)
+ 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")) == 0)
+ if (!lstrcmpi(xi.getName(authorval), _T("name")))
{
DBWriteContactSettingTString(hContact, MODULE, "e-mail", xi.getText(authorval));
break;
@@ -1124,34 +1182,31 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (lstrcmpi(xi.getName(child), _T("category")) == 0 && xi.getText(child))
+ if (!lstrcmpi(xi.getName(child), _T("category")) && xi.getText(child))
{
- char* szstring = mir_t2a(xi.getText(child));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
+ TCHAR *string = mir_tstrdup(xi.getText(child));
+ ClearText(string);
if (UtfEncode)
{
+ char *szstring = mir_t2a(string);
TCHAR* tszstring = mir_utf8decodeT(szstring);
DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", tszstring);
mir_free(tszstring);
+ mir_free(szstring);
}
else
{
- TCHAR* tszstring = mir_a2t(szstring);
- DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", tszstring);
- mir_free(tszstring);
+ DBWriteContactSettingTString(hContact, MODULE, "Interest0Text", string);
}
- mir_free(szstring);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(child), _T("icon")) == 0)
+ 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")) == 0)
+ if (!lstrcmpi(xi.getName(imageval), _T("url")))
{
LPCTSTR url = xi.getText(imageval);
DBWriteContactSettingTString(hContact, MODULE, "ImageURL", url);
@@ -1186,7 +1241,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
}
}
- if (lstrcmpi(xi.getName(child), _T("updated")) == 0 && 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);
@@ -1200,28 +1255,25 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (lstrcmpi(xi.getName(child), _T("entry")) == 0)
+ 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")) == 0 && xi.getText(itemval))
+ if (!lstrcmpi(xi.getName(itemval), _T("title")) && xi.getText(itemval))
{
- char* szstring = mir_t2a(xi.getText(itemval));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- title = mir_a2t(szstring);
- mir_free(szstring);
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ title = mir_tstrdup(string);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("link")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("link")))
{
for (int x = 0; x < xi.getAttrCount(itemval); x++)
{
- if (lstrcmpi(xi.getAttrName(itemval, x), _T("href")) == 0)
+ if (!lstrcmpi(xi.getAttrName(itemval, x), _T("href")))
{
link = (TCHAR*)xi.getAttrValue(itemval, xi.getAttrName(itemval, x));
break;
@@ -1229,70 +1281,58 @@ VOID CheckCurrentFeed(HANDLE hContact)
}
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("updated")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("updated")))
{
datetime = (TCHAR*)xi.getText(itemval);
continue;
}
- if ((lstrcmpi(xi.getName(itemval), _T("summary")) == 0 || lstrcmpi(xi.getName(itemval), _T("content")) == 0) && xi.getText(itemval))
+ if ((!lstrcmpi(xi.getName(itemval), _T("summary")) || !lstrcmpi(xi.getName(itemval), _T("content"))) && xi.getText(itemval))
{
- char* szstring = mir_t2a(xi.getText(itemval));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- descr = mir_a2t(szstring);
- mir_free(szstring);
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ descr = mir_tstrdup(string);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("author")) == 0)
+ 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")) == 0 && xi.getText(authorval))
+ if (!lstrcmpi(xi.getName(authorval), _T("name")) && xi.getText(authorval))
{
- char* szstring = mir_t2a(xi.getText(authorval));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- author = mir_a2t(szstring);
- mir_free(szstring);
+ TCHAR *string = mir_tstrdup(xi.getText(authorval));
+ ClearText(string);
+ author = mir_tstrdup(string);
+ SysFreeString(string);
break;
}
}
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("comments")) == 0 && xi.getText(itemval))
+ if (!lstrcmpi(xi.getName(itemval), _T("comments")) && xi.getText(itemval))
{
- char* szstring = mir_t2a(xi.getText(itemval));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- comments = mir_a2t(szstring);
- mir_free(szstring);
+ TCHAR *string = mir_tstrdup(xi.getText(itemval));
+ ClearText(string);
+ comments = mir_tstrdup(string);
+ SysFreeString(string);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("id")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("id")))
{
guid = (TCHAR*)xi.getText(itemval);
continue;
}
- if (lstrcmpi(xi.getName(itemval), _T("category")) == 0)
+ if (!lstrcmpi(xi.getName(itemval), _T("category")))
{
for (int x = 0; x < xi.getAttrCount(itemval); x++)
{
- if (lstrcmpi(xi.getAttrName(itemval, x), _T("term")) == 0 && xi.getText(itemval))
+ if (!lstrcmpi(xi.getAttrName(itemval, x), _T("term")) && xi.getText(itemval))
{
- char* szstring = mir_t2a(xi.getAttrValue(itemval, xi.getAttrName(itemval, x)));
- decode_html_entities_utf8(szstring, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(szstring);
- strcpy(szstring, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- category = mir_a2t(szstring);
- mir_free(szstring);
+ TCHAR *string = mir_tstrdup(xi.getAttrValue(itemval, xi.getAttrName(itemval, x)));
+ ClearText(string);
+ category = mir_tstrdup(string);
+ SysFreeString(string);
break;
}
}
@@ -1304,60 +1344,62 @@ VOID CheckCurrentFeed(HANDLE hContact)
if (DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
message = _T(TAGSDEFAULT);
else
- {
- message = (TCHAR*)mir_alloc(_tcslen(dbMsg.ptszVal)*sizeof(TCHAR));
- memcpy(message, dbMsg.ptszVal, _tcslen(dbMsg.ptszVal)*sizeof(TCHAR));
- message[_tcslen(dbMsg.ptszVal)] = 0;
- DBFreeVariant(&dbMsg);
- }
- if (lstrcmp(title, NULL) == 0)
+ message = mir_tstrdup(dbMsg.ptszVal);
+ DBFreeVariant(&dbMsg);
+
+ if (!title)
message = StrReplace(_T("#<title>#"), TranslateT("empty"), message);
else
+ {
message = StrReplace(_T("#<title>#"), title, message);
- if (lstrcmp(link, NULL) == 0)
+ mir_free(title);
+ }
+ if (!link)
message = StrReplace(_T("#<link>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<link>#"), link, message);
- if (lstrcmp(descr, NULL) == 0)
+ if (!descr)
message = StrReplace(_T("#<description>#"), TranslateT("empty"), message);
else
+ {
message = StrReplace(_T("#<description>#"), descr, message);
- if (lstrcmp(author, NULL) == 0)
+ mir_free(descr);
+ }
+ if (!author)
message = StrReplace(_T("#<author>#"), TranslateT("empty"), message);
else
+ {
message = StrReplace(_T("#<author>#"), author, message);
- if (lstrcmp(comments, NULL) == 0)
+ mir_free(author);
+ }
+ if (!comments)
message = StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
else
+ {
message = StrReplace(_T("#<comments>#"), comments, message);
- if (lstrcmp(guid, NULL) == 0)
+ mir_free(comments);
+ }
+ if (!guid)
message = StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
else
message = StrReplace(_T("#<guid>#"), guid, message);
- if (lstrcmp(category, NULL) == 0)
+ if (!category)
message = StrReplace(_T("#<category>#"), TranslateT("empty"), message);
else
+ {
message = StrReplace(_T("#<category>#"), category, message);
+ mir_free(category);
+ }
- message = StrReplace(_T("<br>"), _T("\n"), message);
- message = StrReplace(_T("<br/>"), _T("\n"), message);
- message = StrReplace(_T("<br />"), _T("\n"), message);
-
+ ClearText(message);
char* pszUtf;
if (!UtfEncode)
pszUtf = mir_utf8encodeT(message);
else
pszUtf = mir_t2a(message);
- decode_html_entities_utf8(pszUtf, 0);
- boost::regex xRegEx("<(.|\n)*?>");
- std::string xStr(pszUtf);
- strcpy(pszUtf, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
- xRegEx = "^\\s+";
- xStr = pszUtf;
- strcpy(pszUtf, boost::regex_replace(xStr, xRegEx, "", boost::match_default | boost::format_perl).c_str());
time_t stamp;
- if (lstrcmpi(datetime, NULL) ==0)
+ if (!datetime)
stamp = time(NULL);
else
stamp = DateToUnixTime(datetime, 1);
@@ -1372,7 +1414,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
olddbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0);
olddbei.pBlob = (PBYTE)malloc(olddbei.cbBlob);
CallService(MS_DB_EVENT_GET, (WPARAM)hDbEvent, (LPARAM)&olddbei);
- if (olddbei.cbBlob == lstrlenA(pszUtf) + 1 && lstrcmpA((char*)olddbei.pBlob, pszUtf) == 0)
+ if (olddbei.cbBlob == lstrlenA(pszUtf) + 1 && !lstrcmpA((char*)olddbei.pBlob, pszUtf))
MesExist = TRUE;
hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hDbEvent, 0);
}