From a918638dd89a73a51023e5bafe7d5a0ee09bf9d2 Mon Sep 17 00:00:00 2001 From: Vlad Mironov Date: Mon, 31 Mar 2014 04:00:46 +0000 Subject: Variables: added ability to get a contact info by handle. git-svn-id: http://svn.miranda-ng.org/main/trunk@8804 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/contact.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index ff139c7e93..64d4dfb308 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -227,29 +227,33 @@ int getContactFromString(CONTACTSINFO *ci) } /* contact was not in cache, do a search */ - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + { + TCHAR *szFind = NULL; + BOOL bMatch = FALSE; + + // <_HANDLE_:hContact> + size_t size = _tcslen(_T(PROTOID_HANDLE)) + 36; + 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, _tcslen(tszContact))) + bMatch = TRUE; + + mir_free(szFind); + } + char *szProto = GetContactProto(hContact); if (szProto == NULL) continue; // (exact) - TCHAR *szFind = NULL; - BOOL bMatch = FALSE; - if (ci->flags & CI_PROTOID) { + if ((ci->flags & CI_PROTOID) && !bMatch) + { TCHAR *cInfo = getContactInfoT(CNF_UNIQUEID, hContact); - if (cInfo == NULL) { - // - size_t size = _tcslen(_T(PROTOID_HANDLE)) + 36; - 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, _tcslen(tszContact))) - bMatch = TRUE; - - mir_free(szFind); - } - } - else { + if (cInfo) + { size_t size = _tcslen(cInfo) + strlen(szProto) + 4; szFind = (TCHAR *)mir_alloc(size * sizeof(TCHAR)); if (szFind != NULL) { -- cgit v1.2.3