diff options
author | George Hazan <george.hazan@gmail.com> | 2015-03-02 17:24:43 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-03-02 17:24:43 +0000 |
commit | 20cc2883a8790563b18e7ba2985b6e92b27073af (patch) | |
tree | 9a7fb043b04465a9df88434ffc0f60e438bfe7c1 /plugins/SeenPlugin/src/utils.cpp | |
parent | 2c65784dd4a3c4bfdca6487244291926b9ff9132 (diff) |
- much more effective protocol filter;
- support for server-side LastSeen requests;
- interception of LastSeen writes from another modules;
- code cleaning;
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@12300 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SeenPlugin/src/utils.cpp')
-rw-r--r-- | plugins/SeenPlugin/src/utils.cpp | 414 |
1 files changed, 218 insertions, 196 deletions
diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index a0e28b90e1..ea830618b1 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -24,36 +24,37 @@ void FileWrite(MCONTACT); void HistoryWrite(MCONTACT hcontact);
extern HANDLE g_hShutdownEvent;
-char * courProtoName = 0;
+char *courProtoName = 0;
+
+void LoadWatchedProtos()
+{
+ ptrA szProtos(db_get_sa(NULL, S_MOD, "WatchedProtocols"));
+ if (szProtos == NULL)
+ return;
+
+ for (char *p = strtok(szProtos, " "); p != NULL; p = strtok(NULL, " "))
+ arWatchedProtos.insert(mir_strdup(p));
+}
+
+void UnloadWatchedProtos()
+{
+ for (int i = 0; i < arWatchedProtos.getCount(); i++)
+ mir_free(arWatchedProtos[i]);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Returns true if the protocols is to be monitored
-/*
-Returns true if the protocols is to be monitored
-*/
int IsWatchedProtocol(const char* szProto)
{
if (szProto == NULL)
return 0;
-
+
PROTOACCOUNT *pd = ProtoGetAccount(szProto);
if (pd == NULL || CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0) == 0)
return 0;
- int iProtoLen = (int)strlen(szProto);
- char *szWatched;
- DBVARIANT dbv;
- if ( db_get_s(NULL, S_MOD, "WatchedProtocols", &dbv))
- szWatched = DEFAULT_WATCHEDPROTOCOLS;
- else {
- szWatched = NEWSTR_ALLOCA(dbv.pszVal);
- db_free(&dbv);
- }
-
- if (*szWatched == '\0')
- return 1; //empty string: all protocols are watched
-
- char sTemp[MAXMODULELABELLENGTH+1];
- mir_snprintf(sTemp, SIZEOF(sTemp), "%s ", szProto);
- return strstr(szWatched, sTemp) != NULL;
+ return arWatchedProtos.find((char*)szProto) != NULL;
}
BOOL isYahoo(char *protoname)
@@ -100,10 +101,10 @@ DWORD isSeen(MCONTACT hcontact, SYSTEMTIME *st) {
FILETIME ft;
ULONGLONG ll;
- DWORD res = db_get_dw(hcontact,S_MOD,"seenTS",0);
+ DWORD res = db_get_dw(hcontact, S_MOD, "seenTS", 0);
if (res) {
if (st) {
- ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,res,0), 10000000) + NUM100NANOSEC;
+ ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, res, 0), 10000000) + NUM100NANOSEC;
ft.dwLowDateTime = (DWORD)ll;
ft.dwHighDateTime = (DWORD)(ll >> 32);
FileTimeToSystemTime(&ft, st);
@@ -113,26 +114,28 @@ DWORD isSeen(MCONTACT hcontact, SYSTEMTIME *st) SYSTEMTIME lst;
memset(&lst, 0, sizeof(lst));
- if (lst.wYear = db_get_w(hcontact,S_MOD,"Year",0)) {
- if (lst.wMonth = db_get_w(hcontact,S_MOD,"Month",0)) {
- if (lst.wDay = db_get_w(hcontact,S_MOD,"Day",0)) {
- lst.wDayOfWeek = db_get_w(hcontact,S_MOD,"WeekDay",0);
- lst.wHour = db_get_w(hcontact,S_MOD,"Hours",0);
- lst.wMinute = db_get_w(hcontact,S_MOD,"Minutes",0);
- lst.wSecond = db_get_w(hcontact,S_MOD,"Seconds",0);
- if (SystemTimeToFileTime(&lst,&ft)) {
- ll = ((LONGLONG)ft.dwHighDateTime<<32)|((LONGLONG)ft.dwLowDateTime);
+ if (lst.wYear = db_get_w(hcontact, S_MOD, "Year", 0)) {
+ if (lst.wMonth = db_get_w(hcontact, S_MOD, "Month", 0)) {
+ if (lst.wDay = db_get_w(hcontact, S_MOD, "Day", 0)) {
+ lst.wDayOfWeek = db_get_w(hcontact, S_MOD, "WeekDay", 0);
+ lst.wHour = db_get_w(hcontact, S_MOD, "Hours", 0);
+ lst.wMinute = db_get_w(hcontact, S_MOD, "Minutes", 0);
+ lst.wSecond = db_get_w(hcontact, S_MOD, "Seconds", 0);
+ if (SystemTimeToFileTime(&lst, &ft)) {
+ ll = ((LONGLONG)ft.dwHighDateTime << 32) | ((LONGLONG)ft.dwLowDateTime);
ll -= NUM100NANOSEC;
ll /= 10000000;
//perform LOCALTOTIMESTAMP
- res = (DWORD)ll - CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,0,0);
+ res = (DWORD)ll - CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, 0, 0);
//nevel look for Year/Month/Day/Hour/Minute/Second again
- db_set_dw(hcontact,S_MOD,"seenTS",res);
+ db_set_dw(hcontact, S_MOD, "seenTS", res);
}
- } } }
+ }
+ }
+ }
if (st)
- memcpy (st, &lst, sizeof (SYSTEMTIME));
+ memcpy(st, &lst, sizeof(SYSTEMTIME));
return res;
}
@@ -145,18 +148,18 @@ TCHAR *mnames_short[] = { LPGENT("Jan."), LPGENT("Feb."), LPGENT("Mar."), LPGENT TCHAR *ParseString(TCHAR *szstring, MCONTACT hcontact, BYTE isfile)
{
#define MAXSIZE 1024
- static TCHAR sztemp[MAXSIZE+1];
+ static TCHAR sztemp[MAXSIZE + 1];
TCHAR szdbsetting[128];
TCHAR *charPtr;
- int isetting=0;
- DWORD dwsetting=0;
+ int isetting = 0;
+ DWORD dwsetting = 0;
struct in_addr ia;
DBVARIANT dbv;
sztemp[0] = '\0';
SYSTEMTIME st;
- if ( !isSeen(hcontact, &st)) {
+ if (!isSeen(hcontact, &st)) {
_tcscat(sztemp, TranslateT("<never seen>"));
return sztemp;
}
@@ -170,13 +173,13 @@ TCHAR *ParseString(TCHAR *szstring, MCONTACT hcontact, BYTE isfile) if (d >= sztemp + MAXSIZE)
break;
- if (*p != '%' && *p !='#') {
+ if (*p != '%' && *p != '#') {
*d++ = *p;
continue;
}
- bool wantempty = *p =='#';
- switch(*++p) {
+ bool wantempty = *p == '#';
+ switch (*++p) {
case 'Y':
if (!st.wYear) goto LBL_noData;
d += _stprintf(d, _T("%04i"), st.wYear); //!!!!!!!!!!!!
@@ -188,8 +191,8 @@ TCHAR *ParseString(TCHAR *szstring, MCONTACT hcontact, BYTE isfile) break;
case 'm':
- if (!(isetting=st.wMonth)) goto LBL_noData;
-LBL_2DigNum:
+ if (!(isetting = st.wMonth)) goto LBL_noData;
+ LBL_2DigNum:
d += _stprintf(d, _T("%02i"), isetting); //!!!!!!!!!!!!
break;
@@ -199,30 +202,30 @@ LBL_2DigNum: case 'W':
isetting = st.wDayOfWeek;
- if (isetting == -1){
-LBL_noData:
+ if (isetting == -1) {
+ LBL_noData:
charPtr = wantempty ? _T("") : TranslateT("<unknown>");
goto LBL_charPtr;
}
charPtr = TranslateTS(weekdays[isetting]);
-LBL_charPtr:
- d += mir_sntprintf(d, MAXSIZE-(d-sztemp), _T("%s"), charPtr);
+ LBL_charPtr:
+ d += mir_sntprintf(d, MAXSIZE - (d - sztemp), _T("%s"), charPtr);
break;
case 'w':
isetting = st.wDayOfWeek;
if (isetting == -1) goto LBL_noData;
- charPtr = TranslateTS( wdays_short[isetting] );
+ charPtr = TranslateTS(wdays_short[isetting]);
goto LBL_charPtr;
case 'E':
- if ( !(isetting = st.wMonth)) goto LBL_noData;
- charPtr = TranslateTS( monthnames[isetting-1] );
+ if (!(isetting = st.wMonth)) goto LBL_noData;
+ charPtr = TranslateTS(monthnames[isetting - 1]);
goto LBL_charPtr;
case 'e':
- if ( !(isetting = st.wMonth)) goto LBL_noData;
- charPtr = TranslateTS( mnames_short[isetting-1] );
+ if (!(isetting = st.wMonth)) goto LBL_noData;
+ charPtr = TranslateTS(mnames_short[isetting - 1]);
goto LBL_charPtr;
case 'H':
@@ -232,7 +235,7 @@ LBL_charPtr: case 'h':
if ((isetting = st.wHour) == -1) goto LBL_noData;
if (!isetting) isetting = 12;
- isetting = isetting-((isetting>12)?12:0);
+ isetting = isetting - ((isetting > 12) ? 12 : 0);
goto LBL_2DigNum;
case 'p':
@@ -254,14 +257,14 @@ LBL_charPtr: case 'N':
ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
+ if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
charPtr = ci.pszVal;
goto LBL_charPtr;
}
goto LBL_noData;
case 'G':
- if ( !db_get_ts(hcontact, "CList", "Group", &dbv)) {
+ if (!db_get_ts(hcontact, "CList", "Group", &dbv)) {
_tcsncpy(szdbsetting, dbv.ptszVal, SIZEOF(szdbsetting));
db_free(&dbv);
charPtr = szdbsetting;
@@ -271,8 +274,8 @@ LBL_charPtr: case 'u':
ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
- if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- switch(ci.type) {
+ if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
+ switch (ci.type) {
case CNFT_BYTE:
_ltot(ci.bVal, szdbsetting, 10);
break;
@@ -292,9 +295,9 @@ LBL_charPtr: goto LBL_charPtr;
case 's':
- if (isetting = db_get_w(hcontact,S_MOD,hcontact ? "StatusTriger" : courProtoName, 0)) {
- _tcsncpy(szdbsetting, (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)(isetting|0x8000), GSMDF_TCHAR), SIZEOF(szdbsetting));
- if ( !(isetting & 0x8000)) {
+ if (isetting = db_get_w(hcontact, S_MOD, hcontact ? "StatusTriger" : courProtoName, 0)) {
+ _tcsncpy(szdbsetting, (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)(isetting | 0x8000), GSMDF_TCHAR), SIZEOF(szdbsetting));
+ if (!(isetting & 0x8000)) {
_tcsncat(szdbsetting, _T("/"), SIZEOF(szdbsetting));
_tcsncat(szdbsetting, TranslateT("Idle"), SIZEOF(szdbsetting));
}
@@ -304,16 +307,16 @@ LBL_charPtr: goto LBL_noData;
case 'T':
- if ( db_get_ts(hcontact, "CList", "StatusMsg", &dbv))
+ if (db_get_ts(hcontact, "CList", "StatusMsg", &dbv))
goto LBL_noData;
- d += mir_sntprintf(d, MAXSIZE-(d-sztemp), _T("%s"), dbv.ptszVal);
+ d += mir_sntprintf(d, MAXSIZE - (d - sztemp), _T("%s"), dbv.ptszVal);
db_free(&dbv);
break;
case 'o':
if (isetting = db_get_w(hcontact, S_MOD, hcontact ? "OldStatus" : courProtoName, 0)) {
- _tcsncpy(szdbsetting, (TCHAR*) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)isetting, GSMDF_TCHAR), SIZEOF(szdbsetting));
+ _tcsncpy(szdbsetting, (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)isetting, GSMDF_TCHAR), SIZEOF(szdbsetting));
if (includeIdle && hcontact && db_get_b(hcontact, S_MOD, "OldIdle", 0)) {
_tcsncat(szdbsetting, _T("/"), SIZEOF(szdbsetting));
_tcsncat(szdbsetting, TranslateT("Idle"), SIZEOF(szdbsetting));
@@ -325,8 +328,8 @@ LBL_charPtr: case 'i':
case 'r':
- if ( isJabber(ci.szProto)) {
- if ( db_get_ts(hcontact, ci.szProto, *p == 'i' ? "Resource" : "System", &dbv))
+ if (isJabber(ci.szProto)) {
+ if (db_get_ts(hcontact, ci.szProto, *p == 'i' ? "Resource" : "System", &dbv))
goto LBL_noData;
_tcsncpy(szdbsetting, dbv.ptszVal, SIZEOF(szdbsetting));
@@ -339,7 +342,7 @@ LBL_charPtr: goto LBL_noData;
ia.S_un.S_addr = htonl(dwsetting);
- _tcsncpy(szdbsetting, _A2T( inet_ntoa(ia)), SIZEOF(szdbsetting));
+ _tcsncpy(szdbsetting, _A2T(inet_ntoa(ia)), SIZEOF(szdbsetting));
charPtr = szdbsetting;
}
goto LBL_charPtr;
@@ -354,7 +357,7 @@ LBL_charPtr: goto LBL_charPtr;
case 'C': // Get Client Info
- if ( !db_get_ts(hcontact, ci.szProto, "MirVer", &dbv)) {
+ if (!db_get_ts(hcontact, ci.szProto, "MirVer", &dbv)) {
_tcsncpy(szdbsetting, dbv.ptszVal, SIZEOF(szdbsetting));
db_free(&dbv);
}
@@ -367,14 +370,14 @@ LBL_charPtr: goto LBL_charPtr;
case 'A':
- {
+ {
PROTOACCOUNT *pa = ProtoGetAccount(ci.szProto);
- if(!pa) goto LBL_noData;
+ if (!pa) goto LBL_noData;
_tcsncpy(szdbsetting, pa->tszAccountName, SIZEOF(szdbsetting));
charPtr = szdbsetting;
goto LBL_charPtr;
- }
-
+ }
+
default:
*d++ = p[-1];
@@ -388,39 +391,41 @@ LBL_charPtr: void _DBWriteTime(SYSTEMTIME *st, MCONTACT hcontact)
{
- db_set_w(hcontact,S_MOD,"Day",st->wDay);
- db_set_w(hcontact,S_MOD,"Month",st->wMonth);
- db_set_w(hcontact,S_MOD,"Year",st->wYear);
- db_set_w(hcontact,S_MOD,"Hours",st->wHour);
- db_set_w(hcontact,S_MOD,"Minutes",st->wMinute);
- db_set_w(hcontact,S_MOD,"Seconds",st->wSecond);
- db_set_w(hcontact,S_MOD,"WeekDay",st->wDayOfWeek);
+ db_set_w(hcontact, S_MOD, "Day", st->wDay);
+ db_set_w(hcontact, S_MOD, "Month", st->wMonth);
+ db_set_w(hcontact, S_MOD, "Year", st->wYear);
+ db_set_w(hcontact, S_MOD, "Hours", st->wHour);
+ db_set_w(hcontact, S_MOD, "Minutes", st->wMinute);
+ db_set_w(hcontact, S_MOD, "Seconds", st->wSecond);
+ db_set_w(hcontact, S_MOD, "WeekDay", st->wDayOfWeek);
}
-void DBWriteTimeTS(DWORD t, MCONTACT hcontact){
+void DBWriteTimeTS(DWORD t, MCONTACT hcontact)
+{
SYSTEMTIME st;
FILETIME ft;
- ULONGLONG ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,t,0), 10000000) + NUM100NANOSEC;
+ ULONGLONG ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, t, 0), 10000000) + NUM100NANOSEC;
ft.dwLowDateTime = (DWORD)ll;
ft.dwHighDateTime = (DWORD)(ll >> 32);
FileTimeToSystemTime(&ft, &st);
- db_set_dw(hcontact,S_MOD,"seenTS",t);
+ db_set_dw(hcontact, S_MOD, "seenTS", t);
_DBWriteTime(&st, hcontact);
}
-void GetColorsFromDWord(LPCOLORREF First, LPCOLORREF Second, DWORD colDword){
+void GetColorsFromDWord(LPCOLORREF First, LPCOLORREF Second, DWORD colDword)
+{
WORD temp;
- COLORREF res=0;
- temp = (WORD)(colDword>>16);
- res |= ((temp & 0x1F) <<3);
- res |= ((temp & 0x3E0) <<6);
- res |= ((temp & 0x7C00) <<9);
+ COLORREF res = 0;
+ temp = (WORD)(colDword >> 16);
+ res |= ((temp & 0x1F) << 3);
+ res |= ((temp & 0x3E0) << 6);
+ res |= ((temp & 0x7C00) << 9);
if (First) *First = res;
res = 0;
temp = (WORD)colDword;
- res |= ((temp & 0x1F) <<3);
- res |= ((temp & 0x3E0) <<6);
- res |= ((temp & 0x7C00) <<9);
+ res |= ((temp & 0x1F) << 3);
+ res |= ((temp & 0x3E0) << 6);
+ res |= ((temp & 0x7C00) << 9);
if (Second) *Second = res;
}
@@ -437,63 +442,65 @@ DWORD StatusColors15bits[] = { 0x5EFD0000, // 0x00B8B8E8, 0x00000000, Out to lunch
};
-DWORD GetDWordFromColors(COLORREF First, COLORREF Second){
+DWORD GetDWordFromColors(COLORREF First, COLORREF Second)
+{
DWORD res = 0;
- res |= (First&0xF8)>>3;
- res |= (First&0xF800)>>6;
- res |= (First&0xF80000)>>9;
+ res |= (First & 0xF8) >> 3;
+ res |= (First & 0xF800) >> 6;
+ res |= (First & 0xF80000) >> 9;
res <<= 16;
- res |= (Second&0xF8)>>3;
- res |= (Second&0xF800)>>6;
- res |= (Second&0xF80000)>>9;
+ res |= (Second & 0xF8) >> 3;
+ res |= (Second & 0xF800) >> 6;
+ res |= (Second & 0xF80000) >> 9;
return res;
}
-LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
- switch(message) {
- case WM_COMMAND:
- if (HIWORD(wParam) == STN_CLICKED){
- MCONTACT hContact = PUGetContact(hwnd);
- if (hContact > 0) CallService(MS_MSG_SENDMESSAGE,hContact,0);
- }
- case WM_CONTEXTMENU:
- PUDeletePopup(hwnd);
- break;
- case UM_INITPOPUP: return 0;
+ switch (message) {
+ case WM_COMMAND:
+ if (HIWORD(wParam) == STN_CLICKED) {
+ MCONTACT hContact = PUGetContact(hwnd);
+ if (hContact > 0) CallService(MS_MSG_SENDMESSAGE, hContact, 0);
+ }
+ case WM_CONTEXTMENU:
+ PUDeletePopup(hwnd);
+ break;
+ case UM_INITPOPUP: return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
};
void ShowPopup(MCONTACT hcontact, const char * lpzProto, int newStatus)
{
- if ( CallService(MS_IGNORE_ISIGNORED, (WPARAM)hcontact, IGNOREEVENT_USERONLINE))
+ if (CallService(MS_IGNORE_ISIGNORED, (WPARAM)hcontact, IGNOREEVENT_USERONLINE))
return;
- if ( !ServiceExists(MS_POPUP_QUERY))
+ if (!ServiceExists(MS_POPUP_QUERY))
return;
- if ( !db_get_b(NULL, S_MOD, "UsePopups", 0) || !db_get_b(hcontact, "CList", "Hidden", 0))
+ if (!db_get_b(NULL, S_MOD, "UsePopups", 0) || !db_get_b(hcontact, "CList", "Hidden", 0))
return;
DBVARIANT dbv;
char szSetting[10];
mir_snprintf(szSetting, SIZEOF(szSetting), "Col_%d", newStatus - ID_STATUS_OFFLINE);
- DWORD sett = db_get_dw(NULL, S_MOD, szSetting, StatusColors15bits[newStatus-ID_STATUS_OFFLINE]);
+ DWORD sett = db_get_dw(NULL, S_MOD, szSetting, StatusColors15bits[newStatus - ID_STATUS_OFFLINE]);
- POPUPDATAT ppd = {0};
- GetColorsFromDWord(&ppd.colorBack,&ppd.colorText,sett);
+ POPUPDATAT ppd = { 0 };
+ GetColorsFromDWord(&ppd.colorBack, &ppd.colorText, sett);
ppd.lchContact = hcontact;
ppd.lchIcon = LoadSkinnedProtoIcon(lpzProto, newStatus);
- if ( !db_get_ts(NULL, S_MOD, "PopupStamp", &dbv)) {
+ if (!db_get_ts(NULL, S_MOD, "PopupStamp", &dbv)) {
_tcsncpy(ppd.lptzContactName, ParseString(dbv.ptszVal, hcontact, 0), MAX_CONTACTNAME);
db_free(&dbv);
}
else _tcsncpy(ppd.lptzContactName, ParseString(DEFAULT_POPUPSTAMP, hcontact, 0), MAX_CONTACTNAME);
- if ( !db_get_ts(NULL, S_MOD, "PopupStampText", &dbv)) {
+ if (!db_get_ts(NULL, S_MOD, "PopupStampText", &dbv)) {
_tcsncpy(ppd.lptzText, ParseString(dbv.ptszVal, hcontact, 0), MAX_SECONDLINE);
db_free(&dbv);
}
@@ -504,7 +511,7 @@ void ShowPopup(MCONTACT hcontact, const char * lpzProto, int newStatus) void myPlaySound(MCONTACT hcontact, WORD newStatus, WORD oldStatus)
{
- if (CallService(MS_IGNORE_ISIGNORED,(WPARAM)hcontact,IGNOREEVENT_USERONLINE)) return;
+ if (CallService(MS_IGNORE_ISIGNORED, (WPARAM)hcontact, IGNOREEVENT_USERONLINE)) return;
//oldStatus and hcontact are not used yet
char *soundname = NULL;
if ((newStatus == ID_STATUS_ONLINE) || (newStatus == ID_STATUS_FREECHAT)) soundname = "LastSeenTrackedStatusOnline";
@@ -515,25 +522,25 @@ void myPlaySound(MCONTACT hcontact, WORD newStatus, WORD oldStatus) SkinPlaySound(soundname);
}
-//will add hContact to queue and will return position;
+// will add hContact to queue and will return position;
static void waitThread(void *param)
{
logthread_info* infoParam = (logthread_info*)param;
- WORD prevStatus = db_get_w(infoParam->hContact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE);
-
+ WORD prevStatus = db_get_w(infoParam->hContact, S_MOD, "StatusTriger", ID_STATUS_OFFLINE);
+
// I hope in 1.5 second all the needed info will be set
- if ( WaitForSingleObject(g_hShutdownEvent, 1500) == WAIT_TIMEOUT) {
+ if (WaitForSingleObject(g_hShutdownEvent, 1500) == WAIT_TIMEOUT) {
if (includeIdle)
- if (db_get_dw(infoParam->hContact,infoParam->sProtoName,"IdleTS",0))
- infoParam->currStatus &=0x7FFF;
+ if (db_get_dw(infoParam->hContact, infoParam->sProtoName, "IdleTS", 0))
+ infoParam->currStatus &= 0x7FFF;
- if (infoParam->currStatus != prevStatus){
- db_set_w(infoParam->hContact,S_MOD,"OldStatus",(WORD)(prevStatus|0x8000));
+ if (infoParam->currStatus != prevStatus) {
+ db_set_w(infoParam->hContact, S_MOD, "OldStatus", (WORD)(prevStatus | 0x8000));
if (includeIdle)
- db_set_b(infoParam->hContact,S_MOD,"OldIdle",(BYTE)((prevStatus&0x8000)==0));
+ db_set_b(infoParam->hContact, S_MOD, "OldIdle", (BYTE)((prevStatus & 0x8000) == 0));
- db_set_w(infoParam->hContact,S_MOD,"StatusTriger",infoParam->currStatus);
+ db_set_w(infoParam->hContact, S_MOD, "StatusTriger", infoParam->currStatus);
}
}
{
@@ -543,64 +550,74 @@ static void waitThread(void *param) mir_free(infoParam);
}
-int UpdateValues(WPARAM hContact,LPARAM lparam)
+int UpdateValues(WPARAM hContact, LPARAM lparam)
{
// to make this code faster
if (!hContact)
return 0;
- DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING *)lparam;
- //if (CallService(MS_IGNORE_ISIGNORED,hContact,IGNOREEVENT_USERONLINE)) return 0;
- BOOL isIdleEvent = includeIdle?(strcmp(cws->szSetting,"IdleTS")==0):0;
- if (strcmp(cws->szSetting,"Status") && strcmp(cws->szSetting,"StatusTriger") && (isIdleEvent==0)) return 0;
- if (!strcmp(cws->szModule,S_MOD)) {
- //here we will come when Settings/SeenModule/StatusTriger is changed
- WORD prevStatus=db_get_w(hContact, S_MOD, "OldStatus", ID_STATUS_OFFLINE);
- if (includeIdle){
- if ( db_get_b(hContact, S_MOD, "OldIdle", 0)) prevStatus &= 0x7FFF;
- else prevStatus |= 0x8000;
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lparam;
+ char *szProto = GetContactProto(hContact);
+
+ if (cws->value.type == DBVT_DWORD && !strcmp(cws->szSetting, "LastSeen") && !mir_strcmp(cws->szModule, szProto)) {
+ DBWriteTimeTS(cws->value.dVal, hContact);
+
+ HWND hwnd = WindowList_Find(g_pUserInfo, hContact);
+ if (hwnd != NULL)
+ SendMessage(hwnd, WM_REFRESH_UI, hContact, 0);
+ return 0;
+ }
+
+ BOOL isIdleEvent = includeIdle ? (strcmp(cws->szSetting, "IdleTS") == 0) : 0;
+ if (strcmp(cws->szSetting, "Status") && strcmp(cws->szSetting, "StatusTriger") && (isIdleEvent == 0))
+ return 0;
+
+ if (!strcmp(cws->szModule, S_MOD)) {
+ // here we will come when Settings/SeenModule/StatusTriger is changed
+ WORD prevStatus = db_get_w(hContact, S_MOD, "OldStatus", ID_STATUS_OFFLINE);
+ if (includeIdle) {
+ if (db_get_b(hContact, S_MOD, "OldIdle", 0))
+ prevStatus &= 0x7FFF;
+ else
+ prevStatus |= 0x8000;
}
- if ((cws->value.wVal|0x8000)<=ID_STATUS_OFFLINE)
- {
+ if ((cws->value.wVal | 0x8000) <= ID_STATUS_OFFLINE) {
// avoid repeating the offline status
- if ((prevStatus|0x8000)<=ID_STATUS_OFFLINE)
+ if ((prevStatus | 0x8000) <= ID_STATUS_OFFLINE)
return 0;
- char *proto = GetContactProto(hContact);
db_set_b(hContact, S_MOD, "Offline", 1);
{
- DWORD t;
char str[MAXMODULELABELLENGTH + 9];
- mir_snprintf(str, SIZEOF(str), "OffTime-%s", proto);
- t = db_get_dw(NULL, S_MOD, str, 0);
+ mir_snprintf(str, SIZEOF(str), "OffTime-%s", szProto);
+ DWORD t = db_get_dw(NULL, S_MOD, str, 0);
if (!t)
t = time(NULL);
DBWriteTimeTS(t, hContact);
}
- if (!db_get_b(NULL,S_MOD,"IgnoreOffline",1))
- {
- if ( db_get_b(NULL,S_MOD,"FileOutput",0))
+ if (!db_get_b(NULL, S_MOD, "IgnoreOffline", 1)) {
+ if (db_get_b(NULL, S_MOD, "FileOutput", 0))
FileWrite(hContact);
char *sProto = GetContactProto(hContact);
- if (CallProtoService(sProto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE) {
+ if (CallProtoService(sProto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE) {
myPlaySound(hContact, ID_STATUS_OFFLINE, prevStatus);
- if ( db_get_b(NULL, S_MOD, "UsePopups", 0))
+ if (db_get_b(NULL, S_MOD, "UsePopups", 0))
ShowPopup(hContact, sProto, ID_STATUS_OFFLINE);
}
- if ( db_get_b(NULL, S_MOD, "KeepHistory", 0))
+ if (db_get_b(NULL, S_MOD, "KeepHistory", 0))
HistoryWrite(hContact);
- if ( db_get_b(hContact, S_MOD, "OnlineAlert", 0))
+ if (db_get_b(hContact, S_MOD, "OnlineAlert", 0))
ShowHistory(hContact, 1);
}
- } else {
-
- if (cws->value.wVal==prevStatus && !db_get_b(hContact, S_MOD, "Offline", 0))
+ }
+ else {
+ if (cws->value.wVal == prevStatus && !db_get_b(hContact, S_MOD, "Offline", 0))
return 0;
DBWriteTimeTS(time(NULL), hContact);
@@ -611,7 +628,7 @@ int UpdateValues(WPARAM hContact,LPARAM lparam) if (prevStatus != cws->value.wVal) myPlaySound(hContact, cws->value.wVal, prevStatus);
if (db_get_b(NULL, S_MOD, "UsePopups", 0))
if (prevStatus != cws->value.wVal)
- ShowPopup(hContact, GetContactProto(hContact), cws->value.wVal|0x8000);
+ ShowPopup(hContact, GetContactProto(hContact), cws->value.wVal | 0x8000);
if (db_get_b(NULL, S_MOD, "KeepHistory", 0)) HistoryWrite(hContact);
if (db_get_b(hContact, S_MOD, "OnlineAlert", 0)) ShowHistory(hContact, 1);
@@ -619,8 +636,8 @@ int UpdateValues(WPARAM hContact,LPARAM lparam) }
}
else if (hContact && IsWatchedProtocol(cws->szModule) && !db_get_b(hContact, cws->szModule, "ChatRoom", false)) {
- //here we will come when <User>/<module>/Status is changed or it is idle event and if <module> is watched
- if ( CallProtoService(cws->szModule,PS_GETSTATUS,0,0) > ID_STATUS_OFFLINE){
+ // here we will come when <User>/<module>/Status is changed or it is idle event and if <module> is watched
+ if (CallProtoService(cws->szModule, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE) {
mir_cslock lck(csContacts);
logthread_info *p = arContacts.find((logthread_info*)&hContact);
if (p == NULL) {
@@ -631,7 +648,8 @@ int UpdateValues(WPARAM hContact,LPARAM lparam) mir_forkthread(waitThread, p);
}
p->currStatus = isIdleEvent ? db_get_w(hContact, cws->szModule, "Status", ID_STATUS_OFFLINE) : cws->value.wVal;
- } }
+ }
+ }
return 0;
}
@@ -642,14 +660,14 @@ static void cleanThread(void *param) char *szProto = infoParam->sProtoName;
// I hope in 10 secons all logged-in contacts will be listed
- if ( WaitForSingleObject(g_hShutdownEvent, 10000) == WAIT_TIMEOUT) {
+ if (WaitForSingleObject(g_hShutdownEvent, 10000) == WAIT_TIMEOUT) {
for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) {
- WORD oldStatus = db_get_w(hContact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE) | 0x8000;
+ WORD oldStatus = db_get_w(hContact, S_MOD, "StatusTriger", ID_STATUS_OFFLINE) | 0x8000;
if (oldStatus > ID_STATUS_OFFLINE) {
- if (db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE)==ID_STATUS_OFFLINE){
- db_set_w(hContact,S_MOD,"OldStatus",(WORD)(oldStatus|0x8000));
- if (includeIdle)db_set_b(hContact,S_MOD,"OldIdle",(BYTE)((oldStatus&0x8000)?0:1));
- db_set_w(hContact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE);
+ if (db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) {
+ db_set_w(hContact, S_MOD, "OldStatus", (WORD)(oldStatus | 0x8000));
+ if (includeIdle)db_set_b(hContact, S_MOD, "OldIdle", (BYTE)((oldStatus & 0x8000) ? 0 : 1));
+ db_set_w(hContact, S_MOD, "StatusTriger", ID_STATUS_OFFLINE);
}
}
}
@@ -661,33 +679,33 @@ static void cleanThread(void *param) free(infoParam);
}
-int ModeChange(WPARAM wparam,LPARAM lparam)
+int ModeChange(WPARAM wparam, LPARAM lparam)
{
- ACKDATA *ack=(ACKDATA *)lparam;
+ ACKDATA *ack = (ACKDATA *)lparam;
- if (ack->type!=ACKTYPE_STATUS || ack->result!=ACKRESULT_SUCCESS || ack->hContact!=NULL) return 0;
+ if (ack->type != ACKTYPE_STATUS || ack->result != ACKRESULT_SUCCESS || ack->hContact != NULL) return 0;
courProtoName = (char *)ack->szModule;
- if (!IsWatchedProtocol(courProtoName) && strncmp(courProtoName,"MetaContacts",12))
+ if (!IsWatchedProtocol(courProtoName) && strncmp(courProtoName, "MetaContacts", 12))
return 0;
- DBWriteTimeTS(time(NULL),NULL);
+ DBWriteTimeTS(time(NULL), NULL);
-// isetting=CallProtoService(ack->szModule,PS_GETSTATUS,0,0);
- WORD isetting=(WORD)ack->lParam;
- if (isetting<ID_STATUS_OFFLINE) isetting = ID_STATUS_OFFLINE;
- if ((isetting>ID_STATUS_OFFLINE)&&((WORD)ack->hProcess<=ID_STATUS_OFFLINE)) {
+ // isetting=CallProtoService(ack->szModule,PS_GETSTATUS,0,0);
+ WORD isetting = (WORD)ack->lParam;
+ if (isetting < ID_STATUS_OFFLINE) isetting = ID_STATUS_OFFLINE;
+ if ((isetting > ID_STATUS_OFFLINE) && ((WORD)ack->hProcess <= ID_STATUS_OFFLINE)) {
//we have just loged-in
db_set_dw(NULL, "UserOnline", ack->szModule, GetTickCount());
if (!Miranda_Terminated() && IsWatchedProtocol(ack->szModule)) {
logthread_info *info = (logthread_info *)malloc(sizeof(logthread_info));
- strncpy(info->sProtoName,courProtoName,MAXMODULELABELLENGTH);
+ strncpy(info->sProtoName, courProtoName, MAXMODULELABELLENGTH);
info->hContact = 0;
info->currStatus = 0;
mir_forkthread(cleanThread, info);
}
}
- else if ((isetting==ID_STATUS_OFFLINE)&&((WORD)ack->hProcess>ID_STATUS_OFFLINE)) {
+ else if ((isetting == ID_STATUS_OFFLINE) && ((WORD)ack->hProcess > ID_STATUS_OFFLINE)) {
//we have just loged-off
if (IsWatchedProtocol(ack->szModule)) {
char str[MAXMODULELABELLENGTH + 9];
@@ -698,13 +716,13 @@ int ModeChange(WPARAM wparam,LPARAM lparam) db_set_dw(NULL, S_MOD, str, t);
}
}
-
- if (isetting==db_get_w(NULL,S_MOD,courProtoName,ID_STATUS_OFFLINE))
+
+ if (isetting == db_get_w(NULL, S_MOD, courProtoName, ID_STATUS_OFFLINE))
return 0;
- db_set_w(NULL,S_MOD,courProtoName,isetting);
+ db_set_w(NULL, S_MOD, courProtoName, isetting);
- if ( db_get_b(NULL,S_MOD,"FileOutput",0))
+ if (db_get_b(NULL, S_MOD, "FileOutput", 0))
FileWrite(NULL);
courProtoName = NULL;
@@ -714,37 +732,41 @@ int ModeChange(WPARAM wparam,LPARAM lparam) short int isDbZero(MCONTACT hContact, const char *module_name, const char *setting_name)
{
DBVARIANT dbv;
- if ( !db_get(hContact, module_name, setting_name, &dbv)) {
+ if (!db_get(hContact, module_name, setting_name, &dbv)) {
short int res = 0;
switch (dbv.type) {
- case DBVT_BYTE: res=dbv.bVal==0; break;
- case DBVT_WORD: res=dbv.wVal==0; break;
- case DBVT_DWORD: res=dbv.dVal==0; break;
- case DBVT_BLOB: res=dbv.cpbVal==0; break;
- default: res=dbv.pszVal[0]==0; break;
+ case DBVT_BYTE: res = dbv.bVal == 0; break;
+ case DBVT_WORD: res = dbv.wVal == 0; break;
+ case DBVT_DWORD: res = dbv.dVal == 0; break;
+ case DBVT_BLOB: res = dbv.cpbVal == 0; break;
+ default: res = dbv.pszVal[0] == 0; break;
}
- db_free(&dbv);
+ db_free(&dbv);
return res;
}
return -1;
}
-TCHAR *any_to_IdleNotidleUnknown(MCONTACT hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen) {
+TCHAR* any_to_IdleNotidleUnknown(MCONTACT hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen)
+{
short int r = isDbZero(hContact, module_name, setting_name);
- if (r==-1){
+ if (r == -1) {
_tcsncpy(buff, TranslateT("Unknown"), bufflen);
- } else {
+ }
+ else {
_tcsncpy(buff, r ? TranslateT("Not Idle") : TranslateT("Idle"), bufflen);
};
buff[bufflen - 1] = 0;
return buff;
}
-TCHAR *any_to_Idle(MCONTACT hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen) {
- if (isDbZero(hContact, module_name, setting_name)==0) { //DB setting is NOT zero and exists
+TCHAR* any_to_Idle(MCONTACT hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen)
+{
+ if (isDbZero(hContact, module_name, setting_name) == 0) { //DB setting is NOT zero and exists
buff[0] = L'/';
- _tcsncpy(&buff[1], TranslateT("Idle"), bufflen-1);
- } else buff[0] = 0;
+ _tcsncpy(&buff[1], TranslateT("Idle"), bufflen - 1);
+ }
+ else buff[0] = 0;
buff[bufflen - 1] = 0;
return buff;
}
|