From 017b7066ab8c82880a62f9208e25c36c43c76a03 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 8 Apr 2016 10:49:29 +0000 Subject: Variables: - massive code simplification; - old shit removed and replaced with lists; - version bump. git-svn-id: http://svn.miranda-ng.org/main/trunk@16613 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/Version.h | 4 +- plugins/Variables/src/contact.cpp | 287 +++++++++++---------------- plugins/Variables/src/contact.h | 26 +-- plugins/Variables/src/help.cpp | 2 +- plugins/Variables/src/parse_metacontacts.cpp | 47 +---- plugins/Variables/src/parse_miranda.cpp | 129 +++--------- plugins/Variables/src/stdafx.h | 2 +- 7 files changed, 157 insertions(+), 340 deletions(-) (limited to 'plugins/Variables') diff --git a/plugins/Variables/src/Version.h b/plugins/Variables/src/Version.h index 5effadf6b7..40ca251672 100644 --- a/plugins/Variables/src/Version.h +++ b/plugins/Variables/src/Version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 -#define __RELEASE_NUM 3 -#define __BUILD_NUM 10 +#define __RELEASE_NUM 3 +#define __BUILD_NUM 11 #include diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index 995a4ce610..ecd0da1e65 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -73,20 +73,31 @@ static builtinCnfs[] = { CCNF_PROTOID, STR_PROTOID } }; -typedef struct +/* contact cache entry */ +struct CONTACTCE { + ~CONTACTCE() + { + mir_free(tszContact); + } + TCHAR* tszContact; + int flags; MCONTACT hContact; - DWORD flags; -} CONTACTCE; /* contact cache entry */ +}; + +static int SortContactCache(const CONTACTCE *p1, const CONTACTCE *p2) +{ + if (p1->flags != p2->flags) + return (p1->flags > p2->flags) ? 1 : -1; + + return _tcscmp(p1->tszContact, p2->tszContact); +} /* cache for 'getcontactfromstring' service */ -static CONTACTCE *cce = NULL; -static int cacheSize = 0; +static OBJLIST arContactCache(20, SortContactCache); static mir_cs csContactCache; -static HANDLE hContactSettingChangedHook; - /* converts a string into a CNF_ type */ @@ -195,163 +206,134 @@ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact) /* MS_VARS_GETCONTACTFROMSTRING */ -int getContactFromString(CONTACTSINFO *ci) +MCONTACT getContactFromString(const TCHAR *tszContact, DWORD dwFlags, int nMatch) { /* service to retrieve a contact's HANDLE from a given string */ - if (ci == NULL) - return -1; - - TCHAR *tszContact; - if (ci->flags & CI_UNICODE) - tszContact = NEWTSTR_ALLOCA(ci->tszContact); - else { - WCHAR* tmp = mir_a2t(ci->szContact); - tszContact = NEWTSTR_ALLOCA(tmp); - mir_free(tmp); + if (tszContact == NULL || *tszContact == 0) + return INVALID_CONTACT_ID; + + bool bReturnCount; + if (dwFlags & CI_NEEDCOUNT) { + dwFlags &= ~CI_NEEDCOUNT; + bReturnCount = true; } - if ((tszContact == NULL) || (mir_tstrlen(tszContact) == 0)) - return -1; + else bReturnCount = false; - ci->hContacts = NULL; - int count = 0; /* search the cache */ { + CONTACTCE tmp = { (TCHAR*)tszContact, dwFlags, 0 }; + mir_cslock lck(csContactCache); - for (int i = 0; i < cacheSize; i++) { - if ((!mir_tstrcmp(cce[i].tszContact, tszContact)) && (ci->flags == cce[i].flags)) { - /* found in cache */ - ci->hContacts = (MCONTACT*)mir_alloc(sizeof(MCONTACT)); - if (ci->hContacts == NULL) - return -1; - - ci->hContacts[0] = cce[i].hContact; - return 1; - } - } + CONTACTCE *p = arContactCache.find(&tmp); + if (p != NULL) + return (bReturnCount) ? 1 : p->hContact; // found in cache } /* contact was not in cache, do a search */ - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - bool bMatch = false; + CMString tmp; + int count = 0; + MCONTACT hContact; + LIST arResults(0); + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { // <_HANDLE_:hContact> - { - size_t size = mir_tstrlen(_T(PROTOID_HANDLE)) + 36; - TCHAR *szFind = (TCHAR *)mir_alloc(size * sizeof(TCHAR)); - if (szFind != NULL) { - mir_sntprintf(szFind, size, _T("<%s:%p>"), _T(PROTOID_HANDLE), hContact); - if (!_tcsncmp(tszContact, szFind, mir_tstrlen(tszContact))) - bMatch = true; - - mir_free(szFind); - } - } + tmp.Format(_T("<%s:%d>"), _T(PROTOID_HANDLE), hContact); + bool bMatch = (tmp == tszContact); char *szProto = GetContactProto(hContact); if (szProto == NULL) continue; // (exact) - if ((ci->flags & CI_PROTOID) && !bMatch) { - TCHAR *cInfo = getContactInfoT(CNF_UNIQUEID, hContact); + if ((dwFlags & CI_PROTOID) && !bMatch) { + ptrT cInfo(getContactInfoT(CNF_UNIQUEID, hContact)); if (cInfo) { - size_t size = mir_tstrlen(cInfo) + mir_strlen(szProto) + 4; - TCHAR *szFind = (TCHAR *)mir_alloc(size * sizeof(TCHAR)); - if (szFind != NULL) { - mir_sntprintf(szFind, size, _T("<%S:%s>"), szProto, cInfo); - mir_free(cInfo); - if (!_tcsncmp(tszContact, szFind, mir_tstrlen(tszContact))) - bMatch = true; - mir_free(szFind); - } + tmp.Format(_T("<%S:%s>"), szProto, cInfo); + if (tmp == tszContact) + bMatch = true; } } + // id (exact) - if ((ci->flags & CI_UNIQUEID) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_UNIQUEID, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_UNIQUEID) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_UNIQUEID, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // nick (not exact) - if ((ci->flags & CI_NICK) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_NICK, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_NICK) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_NICK, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // list name (not exact) - if ((ci->flags & CI_LISTNAME) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_DISPLAY, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_LISTNAME) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_DISPLAY, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // firstname (exact) - if ((ci->flags & CI_FIRSTNAME) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_FIRSTNAME, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_FIRSTNAME) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_FIRSTNAME, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // lastname (exact) - if ((ci->flags & CI_LASTNAME) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_LASTNAME, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_LASTNAME) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_LASTNAME, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // email (exact) - if ((ci->flags & CI_EMAIL) && (!bMatch)) { - TCHAR *szFind = getContactInfoT(CNF_EMAIL, hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_EMAIL) && !bMatch) { + ptrT szFind(getContactInfoT(CNF_EMAIL, hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } + // CNF_ (exact) - if ((ci->flags & CI_CNFINFO) && (!bMatch)) { - TCHAR *szFind = getContactInfoT((BYTE)(ci->flags&~(CI_CNFINFO | CI_TCHAR)), hContact); - if (szFind != NULL) { - if (!mir_tstrcmp(tszContact, szFind)) - bMatch = true; - mir_free(szFind); - } + if ((dwFlags & CI_CNFINFO) && !bMatch) { + ptrT szFind(getContactInfoT((BYTE)(dwFlags & ~CI_CNFINFO), hContact)); + if (!mir_tstrcmp(tszContact, szFind)) + bMatch = true; } - if (bMatch) { - ci->hContacts = (MCONTACT*)mir_realloc(ci->hContacts, (count + 1)*sizeof(MCONTACT)); - if (ci->hContacts == NULL) - return -1; - ci->hContacts[count] = hContact; + if (bMatch) { + if (nMatch == -1) + arResults.insert((HANDLE)hContact); + else if (nMatch == count) + break; count++; } } - if (count == 1) { /* cache the found result */ + if (bReturnCount) + return count; + + if (hContact == 0) + return INVALID_CONTACT_ID; + + // return random contact + if (nMatch == -1) + return (MCONTACT)arResults[rand() % arResults.getCount()]; + + // cache the found result + if (count == 1) { mir_cslock lck(csContactCache); - cce = (CONTACTCE*)mir_realloc(cce, (cacheSize + 1)*sizeof(CONTACTCE)); - if (cce != NULL) { - cce[cacheSize].hContact = ci->hContacts[0]; - cce[cacheSize].flags = ci->flags; - cce[cacheSize].tszContact = mir_tstrdup(tszContact); - if (cce[cacheSize].tszContact != NULL) - cacheSize++; - } + + CONTACTCE *cce = new CONTACTCE(); + cce->hContact = hContact; + cce->flags = dwFlags; + cce->tszContact = mir_tstrdup(tszContact); + arContactCache.insert(cce); } - return count; + return hContact; } /* keep cache consistent */ @@ -373,29 +355,21 @@ static int contactSettingChanged(WPARAM hContact, LPARAM lParam) bool isUid = (((INT_PTR)uid != CALLSERVICE_NOTFOUND) && (uid != NULL)) && (!strcmp(dbw->szSetting, uid)); mir_cslock lck(csContactCache); - for (int i = 0; i < cacheSize; i++) { - if (hContact != cce[i].hContact && (cce[i].flags & CI_CNFINFO) == 0) + for (int i = 0; i < arContactCache.getCount(); i++) { + CONTACTCE &cce = arContactCache[i]; + if (hContact != cce.hContact && (cce.flags & CI_CNFINFO) == 0) continue; - if ((isNick && (cce[i].flags & CI_NICK)) || - (isFirstName && (cce[i].flags & CI_FIRSTNAME)) || - (isLastName && (cce[i].flags & CI_LASTNAME)) || - (isEmail && (cce[i].flags & CI_EMAIL)) || - (isMyHandle && (cce[i].flags & CI_LISTNAME)) || - (cce[i].flags & CI_CNFINFO) != 0 || // lazy; always invalidate CNF info cache entries - (isUid && (cce[i].flags & CI_UNIQUEID))) { + if ((isNick && (cce.flags & CI_NICK)) || + (isFirstName && (cce.flags & CI_FIRSTNAME)) || + (isLastName && (cce.flags & CI_LASTNAME)) || + (isEmail && (cce.flags & CI_EMAIL)) || + (isMyHandle && (cce.flags & CI_LISTNAME)) || + (cce.flags & CI_CNFINFO) != 0 || // lazy; always invalidate CNF info cache entries + (isUid && (cce.flags & CI_UNIQUEID))) + { /* remove from cache */ - mir_free(cce[i].tszContact); - if (cacheSize > 1) { - memmove(&cce[i], &cce[cacheSize - 1], sizeof(CONTACTCE)); - cce = (CONTACTCE*)mir_realloc(cce, (cacheSize - 1)*sizeof(CONTACTCE)); - cacheSize -= 1; - } - else { - mir_free(cce); - cce = NULL; - cacheSize = 0; - } + arContactCache.remove(i); break; } } @@ -404,13 +378,13 @@ static int contactSettingChanged(WPARAM hContact, LPARAM lParam) int initContactModule() { - hContactSettingChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, contactSettingChanged); + HookEvent(ME_DB_CONTACT_SETTINGCHANGED, contactSettingChanged); return 0; } int deinitContactModule() { - UnhookEvent(hContactSettingChangedHook); + arContactCache.destroy(); return 0; } @@ -419,8 +393,11 @@ int deinitContactModule() TCHAR* encodeContactToString(MCONTACT hContact) { char *szProto = GetContactProto(hContact); + if (szProto == NULL) + return NULL; + TCHAR *tszUniqueId = getContactInfoT(CNF_UNIQUEID, hContact); - if (szProto == NULL || tszUniqueId == NULL) + if (tszUniqueId == NULL) return NULL; size_t size = mir_tstrlen(tszUniqueId) + mir_strlen(szProto) + 4; @@ -429,25 +406,3 @@ TCHAR* encodeContactToString(MCONTACT hContact) mir_sntprintf(tszResult, size, _T("<%S:%s>"), szProto, tszUniqueId); return tszResult; } - -// returns a contact from a string in the form -// returns INVALID_HANDLE_VALUE in case of an error. -MCONTACT decodeContactFromString(TCHAR *tszContact) -{ - MCONTACT hContact = INVALID_CONTACT_ID; - CONTACTSINFO ci = { sizeof(ci) }; - ci.tszContact = tszContact; - ci.flags = CI_PROTOID | CI_TCHAR; - int count = getContactFromString(&ci); - if (count != 1) { - mir_free(ci.hContacts); - return hContact; - } - - if (ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - - return hContact; -} diff --git a/plugins/Variables/src/contact.h b/plugins/Variables/src/contact.h index 052e969d2c..f5968d2e03 100644 --- a/plugins/Variables/src/contact.h +++ b/plugins/Variables/src/contact.h @@ -74,20 +74,6 @@ #define PROTOID_HANDLE "_HANDLE_" -// Note: The hContacts array needs to be freed after use using mir_free - -typedef struct { - int cbSize; // Set this to sizeof(CONTACTSINFO). - union { - char *szContact; // String to search for, e.g. last name (can't be NULL). - WCHAR *wszContact; - TCHAR *tszContact; - }; - MCONTACT *hContacts; // (output) Array of contacts found. - DWORD flags; // Contact details that will be matched with the search - // string (flags can be combined). -} CONTACTSINFO; - // Possible flags: #define CI_PROTOID 0x00000001 // The contact in the string is encoded // in the format , e.g. @@ -103,17 +89,9 @@ typedef struct { // (contact details). #define CI_UNIQUEID 0x00000040 // Search unique ids of the contac, e.g. // UIN. -#define CI_CNFINFO 0x40000000 // Searches one of the CNF_* flags (set +#define CI_CNFINFO 0x40000000 // Searches one of the CNF_* flags (set // flags to CI_CNFINFO|CNF_X), only one // CNF_ type possible -#define CI_UNICODE 0x80000000 // tszContact is a unicode string - // (WCHAR*). - -#if defined(UNICODE) || defined(_UNICODE) -#define CI_TCHAR CI_UNICODE // Strings in structure are TCHAR*. -#else -#define CI_TCHAR 0 -#endif +#define CI_NEEDCOUNT 0x80000000 // returns contacts count TCHAR *encodeContactToString(MCONTACT hContact); -MCONTACT decodeContactFromString(TCHAR *tszContact); diff --git a/plugins/Variables/src/help.cpp b/plugins/Variables/src/help.cpp index cb6a2d28ac..d83e8cf2fa 100644 --- a/plugins/Variables/src/help.cpp +++ b/plugins/Variables/src/help.cpp @@ -136,7 +136,7 @@ static INT_PTR CALLBACK clistDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM TCHAR *tszContact = db_get_tsa(NULL, MODULENAME, SETTING_SUBJECT); log_debugA("VARM_SETSUBJECT: %s", tszContact); if (tszContact != NULL) { - hContact = decodeContactFromString(tszContact); + hContact = getContactFromString(tszContact, CI_PROTOID); log_debugA("VARM_SETSUBJECT decoded: %u", hContact); mir_free(tszContact); } } diff --git a/plugins/Variables/src/parse_metacontacts.cpp b/plugins/Variables/src/parse_metacontacts.cpp index bbe87a9506..abbfff5df8 100644 --- a/plugins/Variables/src/parse_metacontacts.cpp +++ b/plugins/Variables/src/parse_metacontacts.cpp @@ -24,20 +24,9 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai) if (ai->argc != 2) return NULL; - MCONTACT hContact = NULL; - - CONTACTSINFO ci = { sizeof(ci) }; - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } hContact = db_mc_getMeta(hContact); if (hContact == NULL) @@ -63,21 +52,9 @@ static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) if (ai->argc != 2) return NULL; - MCONTACT hContact = NULL; - - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } hContact = db_mc_getDefault(hContact); if (hContact == NULL) @@ -103,21 +80,9 @@ static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) if (ai->argc != 2) return NULL; - MCONTACT hContact = NULL; - - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } hContact = db_mc_getMostOnline(hContact); if (hContact == NULL) diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index 598fc4dd6d..4e3251e123 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -70,7 +70,6 @@ static int getContactInfoFlags(TCHAR *tszDesc) if (flags != 0) flags |= CI_CNFINFO; } - flags |= CI_TCHAR; return flags; } @@ -81,28 +80,18 @@ static TCHAR* parseContact(ARGUMENTSINFO *ai) return NULL; int n = 0; - if (ai->argc == 4 && *ai->targv[3] != 'r') - n = ttoi(ai->targv[3]) - 1; + if (ai->argc == 4) { + if (*ai->targv[3] != 'r') // random contact + n = -1; + else + n = ttoi(ai->targv[3]) - 1; + } - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = getContactInfoFlags(ai->targv[2]); - int count = getContactFromString(&ci); - if (count == 0 || ci.hContacts == NULL) + MCONTACT hContact = getContactFromString(ai->targv[1], getContactInfoFlags(ai->targv[2]), n); + if (hContact == INVALID_CONTACT_ID) return NULL; - if (ai->argc == 4 && *ai->targv[3] == 'r') - n = rand() % count; - - if (count != 1 && ai->argc != 4) { - mir_free(ci.hContacts); - return NULL; - } - MCONTACT hContact = ci.hContacts[n]; log_debugA("contact: %x", hContact); - mir_free(ci.hContacts); - return encodeContactToString(hContact); } @@ -111,14 +100,7 @@ static TCHAR* parseContactCount(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = getContactInfoFlags(ai->targv[2]); - int count = getContactFromString(&ci); - if (count != 0 && ci.hContacts != NULL) - mir_free(ci.hContacts); - + int count = getContactFromString(ai->targv[1], CI_NEEDCOUNT | getContactInfoFlags(ai->targv[2])); return itot(count); } @@ -127,20 +109,10 @@ static TCHAR* parseContactInfo(ARGUMENTSINFO *ai) if (ai->argc != 3) return NULL; - MCONTACT hContact = NULL; - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } + BYTE type = getContactInfoType(ai->targv[2]); if (type == 0) return NULL; @@ -211,19 +183,9 @@ static TCHAR* parseDBSetting(ARGUMENTSINFO *ai) MCONTACT hContact = NULL; if (mir_tstrlen(ai->targv[1]) > 0) { - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } } char *szModule = mir_t2a(ai->targv[2]); @@ -249,20 +211,9 @@ static TCHAR* parseLastSeenDate(ARGUMENTSINFO *ai) if (ai->argc <= 1) return NULL; - MCONTACT hContact = NULL; - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } TCHAR *szFormat; if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0)) @@ -302,21 +253,9 @@ static TCHAR* parseLastSeenTime(ARGUMENTSINFO *ai) if (ai->argc <= 1) return NULL; - MCONTACT hContact = NULL; - - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if (count == 1 && ci.hContacts != NULL) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } TCHAR *szFormat; if (ai->argc == 2 || (ai->argc > 2 && mir_tstrlen(ai->targv[2]) == 0)) @@ -357,20 +296,10 @@ static TCHAR* parseLastSeenStatus(ARGUMENTSINFO *ai) if (ai->argc != 2) return NULL; - MCONTACT hContact = NULL; - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if ((count == 1) && (ci.hContacts != NULL)) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else { - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) return NULL; - } + char *szModule = SEEN_MODULE; int status = db_get_w(hContact, szModule, "Status", 0); if (status == 0) @@ -641,19 +570,9 @@ static TCHAR* parseDbEvent(ARGUMENTSINFO *ai) break; } - MCONTACT hContact = NULL; - - CONTACTSINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.tszContact = ai->targv[1]; - ci.flags = 0xFFFFFFFF ^ (CI_TCHAR == 0 ? CI_UNICODE : 0); - int count = getContactFromString(&ci); - if ((count == 1) && (ci.hContacts != NULL)) { - hContact = ci.hContacts[0]; - mir_free(ci.hContacts); - } - else if (ci.hContacts != NULL) - mir_free(ci.hContacts); + MCONTACT hContact = getContactFromString(ai->targv[1], 0xFFFFFFFF); + if (hContact == INVALID_CONTACT_ID) + return NULL; MEVENT hDbEvent = findDbEvent(hContact, NULL, flags); if (hDbEvent == NULL) diff --git a/plugins/Variables/src/stdafx.h b/plugins/Variables/src/stdafx.h index 7948708b2d..5968340da7 100644 --- a/plugins/Variables/src/stdafx.h +++ b/plugins/Variables/src/stdafx.h @@ -173,7 +173,7 @@ int deinitTokenRegister(); // contact.c BYTE getContactInfoType(TCHAR* type); TCHAR* getContactInfoT(BYTE type, MCONTACT hContact); -int getContactFromString( CONTACTSINFO* ); +MCONTACT getContactFromString(const TCHAR *tszContact, DWORD dwFlags, int nMatch = 0); int initContactModule(); int deinitContactModule(); // alias -- cgit v1.2.3