diff options
Diffstat (limited to 'plugins')
30 files changed, 186 insertions, 824 deletions
diff --git a/plugins/AvatarHistory/src/utils.cpp b/plugins/AvatarHistory/src/utils.cpp index 637458b60d..39b4db8534 100644 --- a/plugins/AvatarHistory/src/utils.cpp +++ b/plugins/AvatarHistory/src/utils.cpp @@ -77,35 +77,6 @@ void ConvertToFilename(TCHAR *str, size_t size) }
}
-int GetUIDFromHContact(MCONTACT contact, TCHAR* uinout, int uinout_len)
-{
- bool found = true;
-
- CONTACTINFO cinfo = { sizeof(cinfo) };
- cinfo.hContact = contact;
- cinfo.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
- if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&cinfo) == 0) {
- if (cinfo.type == CNFT_ASCIIZ) {
- mir_tstrncpy(uinout, cinfo.pszVal, uinout_len);
- // It is up to us to free the string
- // The catch? We need to use Miranda's free(), not our CRT's :)
- mir_free(cinfo.pszVal);
- }
- else if (cinfo.type == CNFT_DWORD)
- _itot(cinfo.dVal,uinout,10);
- else if (cinfo.type == CNFT_WORD)
- _itot(cinfo.wVal,uinout,10);
- else
- found = false;
- }
- else found = false;
-
- if (!found)
- mir_tstrncpy(uinout, TranslateT("Unknown UIN"), uinout_len);
-
- return 0;
-}
-
TCHAR* GetExtension(TCHAR *file)
{
if (file == NULL) return _T("");
@@ -144,7 +115,8 @@ TCHAR* GetContactFolder(TCHAR *fn, MCONTACT hContact) GetProtocolFolder(fn, proto);
TCHAR uin[MAX_PATH];
- GetUIDFromHContact(hContact, uin, _countof(uin));
+ ptrT id(Contact_GetInfo(CNF_UNIQUEID, hContact, proto));
+ _tcsncpy_s(uin, (id == NULL) ? TranslateT("Unknown UIN") : id, _TRUNCATE);
ConvertToFilename(uin, MAX_PATH); //added so that weather id's like "yw/CI0000" work
mir_sntprintf(fn, MAX_PATH, _T("%s\\%s"), fn, uin);
CreateDirectoryTreeT(fn);
diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp index 96caf57292..22c9122f11 100644 --- a/plugins/BasicHistory/src/EventList.cpp +++ b/plugins/BasicHistory/src/EventList.cpp @@ -396,40 +396,10 @@ std::wstring HistoryEventList::GetContactName() return TranslateT("System");
}
-void GetInfo(CONTACTINFO& ci, std::wstring& str)
-{
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- if (ci.type == CNFT_ASCIIZ) {
- str = ci.pszVal;
- mir_free(ci.pszVal);
- }
- else if (ci.type == CNFT_DWORD) {
- TCHAR buf[20];
- _ltot_s(ci.dVal, buf, 10);
- str = buf;
- }
- else if (ci.type == CNFT_WORD) {
- TCHAR buf[20];
- _ltot_s(ci.wVal, buf, 10);
- str = buf;
- }
- }
-}
-
std::wstring HistoryEventList::GetMyName()
{
- std::wstring myName;
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.szProto = GetContactProto(m_hContact);
- ci.hContact = 0;
- ci.dwFlag = CNF_DISPLAY | CNF_TCHAR;
- GetInfo(ci, myName);
- if (myName.empty())
- return TranslateT("Me");
-
- return myName;
+ ptrT name(Contact_GetInfo(CNF_DISPLAY, NULL, GetContactProto(m_hContact)));
+ return (name == NULL) ? TranslateT("Me") : name;
}
inline std::wstring GetProtocolName(MCONTACT hContact)
@@ -461,28 +431,14 @@ std::string HistoryEventList::GetBaseProtocol() std::wstring HistoryEventList::GetMyId()
{
- std::wstring myId;
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.szProto = GetContactProto(m_hContact);
- ci.hContact = 0;
- ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR;
- GetInfo(ci, myId);
- return myId;
+ ptrT id(Contact_GetInfo(CNF_DISPLAYUID, NULL, GetContactProto(m_hContact)));
+ return (id == NULL) ? L"" : id;
}
inline std::wstring GetContactId(MCONTACT hContact)
{
- std::wstring id;
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.szProto = GetContactProto(hContact);
- ci.hContact = hContact;
- ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR;
- GetInfo(ci, id);
- return id;
+ ptrT id(Contact_GetInfo(CNF_DISPLAYUID, hContact));
+ return (id == NULL) ? L"" : id;
}
std::wstring HistoryEventList::GetContactId()
diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index 993b300648..69d3d93578 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -152,29 +152,8 @@ int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, #pragma warning (disable: 4312)
char* GetContactName(MCONTACT hContact, char *szProto)
{
- char proto[200];
-
- CONTACTINFO ctInfo;
- memset(&ctInfo, 0, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- if (szProto)
- ctInfo.szProto = szProto;
- else {
- GetContactProto(hContact, proto, sizeof(proto));
- ctInfo.szProto = proto;
- }
- ctInfo.dwFlag = CNF_DISPLAY;
- ctInfo.hContact = hContact;
-
- //_debug_message("retrieving contact name for %d", hContact);
- INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
- if (ret)
- return NULL;
-
- //_debug_message(" contact name %s", ctInfo.pszVal);
- char *buffer = strdup((char*)ctInfo.pszVal);
- mir_free(ctInfo.pszVal);
- return buffer;
+ ptrT name(Contact_GetInfo(CNF_DISPLAY, hContact, szProto));
+ return (name == NULL) ? NULL : strdup(_T2A(name));
}
#pragma warning (default: 4312)
@@ -196,42 +175,8 @@ char* GetContactID(MCONTACT hContact) char* GetContactID(MCONTACT hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- memset(&ctInfo, 0, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- ctInfo.szProto = szProto;
- ctInfo.dwFlag = CNF_UNIQUEID;
- ctInfo.hContact = hContact;
- INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
- if (ret)
- return NULL;
-
- char *buffer;
- char tmp[16];
- switch (ctInfo.type) {
- case CNFT_BYTE:
- mir_snprintf(tmp, "%d", ctInfo.bVal);
- buffer = strdup(tmp);
- break;
-
- case CNFT_WORD:
- mir_snprintf(tmp, "%d", ctInfo.wVal);
- buffer = strdup(tmp);
- break;
-
- case CNFT_DWORD:
- mir_snprintf(tmp, "%ld", ctInfo.dVal);
- buffer = strdup(tmp);
- break;
-
- case CNFT_ASCIIZ:
- default:
- buffer = _strdup((char*)ctInfo.pszVal);
- break;
- }
-
- mir_free(ctInfo.pszVal);
- return buffer;
+ ptrT name(Contact_GetInfo(CNF_UNIQUEID, hContact, szProto));
+ return (name == NULL) ? NULL : strdup(_T2A(name));
}
#pragma warning (default: 4312)
diff --git a/plugins/FavContacts/src/contact_cache.cpp b/plugins/FavContacts/src/contact_cache.cpp index d35e8c890e..38cd4abb62 100644 --- a/plugins/FavContacts/src/contact_cache.cpp +++ b/plugins/FavContacts/src/contact_cache.cpp @@ -116,23 +116,13 @@ float CContactCache::getWeight(int rate) static bool AppendInfo(TCHAR *buf, int size, MCONTACT hContact, int info)
{
- CONTACTINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.hContact = hContact;
- ci.dwFlag = info;
- ci.dwFlag |= CNF_UNICODE;
-
- bool ret = false;
-
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) && (ci.type == CNFT_ASCIIZ) && ci.pszVal) {
- if (*ci.pszVal && (mir_tstrlen(ci.pszVal) < size - 2)) {
- mir_tstrcpy(buf, ci.pszVal);
- ret = true;
- }
- mir_free(ci.pszVal);
+ ptrT str(Contact_GetInfo(info, hContact));
+ if (str != NULL) {
+ mir_tstrncpy(buf, str, size);
+ return true;
}
- return ret;
+ return false;
}
void CContactCache::TContactInfo::LoadInfo()
diff --git a/plugins/HistoryPlusPlus/hpp_contacts.pas b/plugins/HistoryPlusPlus/hpp_contacts.pas index fa8b9f6a4e..e898d003f3 100644 --- a/plugins/HistoryPlusPlus/hpp_contacts.pas +++ b/plugins/HistoryPlusPlus/hpp_contacts.pas @@ -88,7 +88,6 @@ end; function GetContactDisplayName(hContact: TMCONTACT; Proto: AnsiString = ''; Contact: boolean = false): String;
var
- ci: TContactInfo;
RetPWideChar, UW: PChar;
begin
if (hContact = 0) and Contact then
@@ -101,13 +100,9 @@ begin Result := TranslateW('''(Unknown Contact)''' { TRANSLATE-IGNORE } )
else
begin
- ci.cbSize := SizeOf(ci);
- ci.hContact := hContact;
- ci.szProto := PAnsiChar(Proto);
- ci.dwFlag := CNF_DISPLAY + CNF_UNICODE;
- if CallService(MS_CONTACT_GETCONTACTINFO, 0, LPARAM(@ci)) = 0 then
+ RetPWideChar := Contact_GetInfo(CNF_DISPLAY, hContact, PAnsiChar(Proto));
+ if RetPWideChar <> nil then
begin
- RetPWideChar := ci.retval.szVal.w;
UW := TranslateW('''(Unknown Contact)''' { TRANSLATE-IGNORE } );
if WideCompareText(RetPWideChar, UW) = 0 then
Result := AnsiToWideString(GetContactID(hContact, Proto), CP_ACP)
diff --git a/plugins/IEHistory/src/utils.cpp b/plugins/IEHistory/src/utils.cpp index d1f7f704bf..d34557b094 100644 --- a/plugins/IEHistory/src/utils.cpp +++ b/plugins/IEHistory/src/utils.cpp @@ -78,23 +78,10 @@ int Info(char *title, char *format, ...) returns the name of a contact */ -TCHAR *GetContactName(MCONTACT contact) +TCHAR* GetContactName(MCONTACT contact) { - CONTACTINFO ctInfo = { sizeof(ctInfo) }; - // if(db_mc_isMeta(contact)) - // contact=db_mc_getMostOnline(contact); - ctInfo.szProto = GetContactProto(contact); - ctInfo.dwFlag = CNF_DISPLAY; -#ifdef _UNICODE - ctInfo.dwFlag += CNF_UNICODE; -#endif - ctInfo.hContact = contact; - if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ctInfo)){ - return NULL; - } - TCHAR* buffer = _tcsdup(ctInfo.pszVal); - mir_free(ctInfo.pszVal); - return buffer; + ptrT name(Contact_GetInfo(CNF_DISPLAY, contact)); + return (name) ? _tcsdup(name) : NULL; } /* diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index 272b08e891..c80d259648 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -182,65 +182,28 @@ bool HTMLBuilder::isSameDate(time_t time1, time_t time2) void HTMLBuilder::getUINs(MCONTACT hContact, char *&uinIn, char *&uinOut)
{
- CONTACTINFO ci = { 0 };
- char buf[128] = { 0 };
- const char *szProto = GetContactProto(hContact);
-
hContact = getRealContact(hContact);
- ci.cbSize = sizeof(ci);
- ci.hContact = hContact;
- ci.szProto = const_cast<char*>(szProto);
- ci.dwFlag = CNF_UNIQUEID;
+ ptrT id(Contact_GetInfo(CNF_UNIQUEID, hContact));
+ uinIn = mir_utf8encodeT((id != NULL) ? id : _T(""));
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE);
- mir_free(ci.pszVal);
- break;
- case CNFT_DWORD:
- mir_snprintf(buf, "%u", ci.dVal);
- break;
- }
- }
- uinIn = mir_utf8encode(buf);
- ci.hContact = NULL;
-
- buf[0] = 0;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE);
- mir_free(ci.pszVal);
- break;
- case CNFT_DWORD:
- mir_snprintf(buf, "%u", ci.dVal);
- break;
- }
- }
- uinOut = mir_utf8encode(buf);
+ id = Contact_GetInfo(CNF_UNIQUEID, NULL);
+ uinOut = mir_utf8encodeT((id != NULL) ? id : _T(""));
}
-wchar_t *HTMLBuilder::getContactName(MCONTACT hContact, const char *szProto)
+wchar_t* HTMLBuilder::getContactName(MCONTACT hContact, const char *szProto)
{
- CONTACTINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.hContact = hContact;
- ci.szProto = (char *)szProto;
- ci.dwFlag = CNF_DISPLAY | CNF_UNICODE;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci))
- if (ci.type == CNFT_ASCIIZ && ci.pszVal) // already mir_tstrdup'ed
- return ci.pszVal;
-
- ci.dwFlag = CNF_UNIQUEID;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci))
- if (ci.type == CNFT_ASCIIZ && ci.pszVal) // already mir_tstrdup'ed
- return ci.pszVal;
-
- TCHAR *szNameStr = pcli->pfnGetContactDisplayName(hContact, 0);
- if (szNameStr != NULL)
- return mir_tstrdup(szNameStr);
+ TCHAR *str = Contact_GetInfo(CNF_DISPLAY, hContact, szProto);
+ if (str != NULL)
+ return str;
+
+ str = Contact_GetInfo(CNF_UNIQUEID, hContact, szProto);
+ if (str != NULL)
+ return str;
+
+ str = pcli->pfnGetContactDisplayName(hContact, 0);
+ if (str != NULL)
+ return mir_tstrdup(str);
return mir_tstrdup(TranslateT("(Unknown Contact)"));
}
diff --git a/plugins/IEView/src/TemplateHTMLBuilder.cpp b/plugins/IEView/src/TemplateHTMLBuilder.cpp index ad7271e9a8..4ace2ae70b 100644 --- a/plugins/IEView/src/TemplateHTMLBuilder.cpp +++ b/plugins/IEView/src/TemplateHTMLBuilder.cpp @@ -178,22 +178,13 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr db_free(&dbv);
}
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = event->hContact;
- ci.szProto = szProto;
- ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci))
- szNickIn = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
-
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = NULL;
- ci.szProto = szProto;
- ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci))
- szNickOut = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
+ ptrT tszNick(Contact_GetInfo(CNF_NICK, event->hContact, szProto));
+ if (tszNick != NULL)
+ szNickIn = encodeUTF8(event->hContact, szRealProto, tszNick, ENF_NAMESMILEYS, true);
+
+ tszNick = Contact_GetInfo(CNF_NICK, NULL, szProto);
+ if (tszNick != NULL)
+ szNickOut = encodeUTF8(event->hContact, szRealProto, tszNick, ENF_NAMESMILEYS, true);
Template *tmplt = NULL;
if (tmpm) {
@@ -361,22 +352,13 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, }
}
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = event->hContact;
- ci.szProto = szProto;
- ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci))
- szNickIn = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
-
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = NULL;
- ci.szProto = szProto;
- ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci))
- szNickOut = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
+ ptrT tszNick(Contact_GetInfo(CNF_NICK, event->hContact, szProto));
+ if (tszNick != NULL)
+ szNickIn = encodeUTF8(event->hContact, szRealProto, tszNick, ENF_NAMESMILEYS, true);
+
+ tszNick = Contact_GetInfo(CNF_NICK, NULL, szProto);
+ if (tszNick != NULL)
+ szNickOut = encodeUTF8(event->hContact, szRealProto, tszNick, ENF_NAMESMILEYS, true);
IEVIEWEVENTDATA* eventData = event->eventData;
for (int eventIdx = 0; eventData != NULL && (eventIdx < event->count || event->count == -1); eventData = eventData->next, eventIdx++) {
diff --git a/plugins/ImportTXT/General.pas b/plugins/ImportTXT/General.pas index 3fedce5df0..f68486afac 100644 --- a/plugins/ImportTXT/General.pas +++ b/plugins/ImportTXT/General.pas @@ -256,7 +256,6 @@ function GetContactByUID(const proto: AnsiString; const id: AnsiString): THandle var
Contact: THandle;
otherproto: AnsiString;
- ci: TCONTACTINFO;
idnum: integer;
tempwstr: PWideChar;
ws: WideString;
@@ -272,19 +271,13 @@ begin otherproto := Proto_GetProtoName(Contact);
if otherproto = proto then
begin
- ci.cbSize := SizeOf(ci);
- ci.dwFlag := CNF_UNIQUEID or CNF_UNICODE;
- ci.hContact := Contact;
- ci.szProto := PAnsiChar(otherproto);
- if CallService(MS_CONTACT_GETCONTACTINFO, 0, lparam(@ci)) = 0 then
+ tempwstr := Contact_GetInfo(CNF_UNIQUEID, Contact, PAnsiChar(otherproto));
+ if (tempwstr <> nil) and (tempwstr = ws) then
begin
- case (ci._type) of
- CNFT_BYTE: if ci.retval.bVal = idnum then break;
- CNFT_WORD: if ci.retval.wVal = idnum then break;
- CNFT_DWORD: if ci.retval.dVal = DWORD(idnum) then break;
- CNFT_ASCIIZ: if ws = ci.retval.szVal.w then break;
- end; // case
- end; // if
+ mir_free(tempwstr);
+ break;
+ end;
+ mir_free(tempwstr);
end; // if
Contact := db_find_next(Contact);
end; // while
@@ -298,7 +291,7 @@ function GetContactByNick(const proto: AnsiString; const Nick: WideString): THan var
Contact: THandle;
otherproto: AnsiString;
- ci: TCONTACTINFO;
+ tmpwstr: PWideChar;
begin
result := INVALID_HANDLE_VALUE;
Contact := db_find_first();
@@ -307,19 +300,14 @@ begin otherproto := Proto_GetProtoName(Contact);
if otherproto = proto then
begin
- ci.cbSize := SizeOf(ci);
- ci.dwFlag := CNF_NICK;
- ci.dwFlag := ci.dwFlag or CNF_UNICODE;
- ci.hContact := Contact;
- ci.szProto := PAnsiChar(otherproto);
- if CallService(MS_CONTACT_GETCONTACTINFO, 0, lparam(@ci)) = 0 then
+ tmpwstr := Contact_GetInfo(CNF_NICK, Contact, PAnsiChar(otherproto));
+ if (tmpwstr <> nil) and (Nick = tmpwstr) then
begin
- if Nick = ci.retval.szVal.w then
- begin
- result := Contact;
- break;
- end;
+ mir_free(tmpwstr);
+ result := Contact;
+ break;
end; // if
+ mir_free(tmpwstr);
end; // if
Contact := db_find_next(Contact);
end; // while
diff --git a/plugins/ListeningTo/src/listeningto.cpp b/plugins/ListeningTo/src/listeningto.cpp index ea276f77ff..5538f37b8b 100644 --- a/plugins/ListeningTo/src/listeningto.cpp +++ b/plugins/ListeningTo/src/listeningto.cpp @@ -461,7 +461,8 @@ INT_PTR MainMenuClicked(WPARAM wParam, LPARAM) return -1;
if (wParam < proto_items.size()) {
- ProtocolInfo &pi = proto_items[wParam];
EnableListeningTo(pi.proto, !ListeningToEnabled(pi.proto, TRUE));
+ ProtocolInfo &pi = proto_items[wParam];
+ EnableListeningTo(pi.proto, !ListeningToEnabled(pi.proto, TRUE));
}
return 0;
}
diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index 234f21cd1c..9d2d30a9ac 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -91,37 +91,13 @@ void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]) *p = '\0'; } -char* contact_get_id(MCONTACT hContact, bool bNameOnError) { - char* pszUniqueID = NULL; - CONTACTINFO ci; - memset(&ci, 0, sizeof(ci)); - ci.cbSize = sizeof(ci); - ci.hContact = hContact; - ci.dwFlag = CNF_UNIQUEID; - - if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0) - { - if (ci.type == CNFT_ASCIIZ) { - pszUniqueID = (char*)ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc - } else if (ci.type == CNFT_DWORD) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.dVal); - } else if (ci.type == CNFT_WORD) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.wVal); - } else if (ci.type == CNFT_BYTE) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.bVal); - } - } - if (!pszUniqueID && bNameOnError) { - const TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0); - if (name) pszUniqueID = mir_t2a(name); - } - return pszUniqueID; +char* contact_get_id(MCONTACT hContact, bool bNameOnError) +{ + ptrT pszUniqueID(Contact_GetInfo(CNF_UNIQUEID, hContact)); + if (!pszUniqueID && bNameOnError) + pszUniqueID = mir_tstrdup(pcli->pfnGetContactDisplayName(hContact, 0)); + + return mir_t2a(pszUniqueID); } __inline const TCHAR* contact_get_nameT(MCONTACT hContact) { @@ -130,24 +106,8 @@ __inline const TCHAR* contact_get_nameT(MCONTACT hContact) { TCHAR* ProtoGetNickname(const char* proto) { - CONTACTINFO ci = {sizeof(ci)}; - ci.dwFlag = CNF_TCHAR | CNF_NICK; - ci.szProto = (char*)proto; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - return ci.pszVal; - case CNFT_DWORD: - mir_free(ci.pszVal); - ci.pszVal=(TCHAR*)mir_alloc(12*sizeof(TCHAR)); // long can only have up to 11 characters (unsigned = 10) - if(ci.pszVal) - _ltot(ci.dVal, ci.pszVal, 10); - return ci.pszVal; - default: - mir_free(ci.pszVal); - } - } - return mir_tstrdup(_T("")); + TCHAR *p = Contact_GetInfo(CNF_NICK, NULL, proto); + return (p != NULL) ? p : mir_tstrdup(_T("")); } void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const MCONTACT hContact) { diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 42df6bda09..b5d13d04af 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -973,23 +973,9 @@ void ExportDBEventInfo(MCONTACT hContact, DBEVENTINFO &dbei) for (int nCur = 0; nCur < 9; nCur++)
ReplaceAll(output, pszReplaceList[nCur], _DBGetString(hContact, sProto.c_str(), pszReplaceListA[nCur], _T("")));
- CONTACTINFO ci = {};
- ci.cbSize = sizeof(ci);
- ci.hContact = hContact;
- ci.szProto = (char*)sProto.c_str();
- ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - ReplaceAll(output, _T("%UIN%"), ci.pszVal);
- mir_free(ci.pszVal); - break; - case CNFT_DWORD: - mir_sntprintf(szTemp, _T("%u"), ci.dVal); - ReplaceAll(output, _T("%UIN%"), szTemp);
- break; - } - }
+ ptrT id(Contact_GetInfo(CNF_UNIQUEID, hContact, sProto.c_str()));
+ if (id != NULL)
+ ReplaceAll(output, _T("%UIN%"), id);
mir_sntprintf(szTemp, _T("%d"), db_get_w(hContact, sProto.c_str(), "Age", 0));
ReplaceAll(output, _T("%Age%"), szTemp);
@@ -1447,9 +1433,6 @@ void SaveSettings() TCHAR* GetMyOwnNick(MCONTACT hContact)
{
- CONTACTINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.szProto = GetContactProto(hContact);
- ci.dwFlag = CNF_DISPLAY | CNF_TCHAR;
- return CallService(MS_CONTACT_GETCONTACTINFO, 0, LPARAM(&ci)) ? mir_tstrdup(TranslateT("No_Nick")) : ci.pszVal;
+ TCHAR *p = Contact_GetInfo(CNF_DISPLAY, NULL, GetContactProto(hContact));
+ return (p != NULL) ? p : mir_tstrdup(TranslateT("No_Nick"));
}
diff --git a/plugins/MyDetails/src/data.cpp b/plugins/MyDetails/src/data.cpp index 88f9b1eab1..39132d8121 100644 --- a/plugins/MyDetails/src/data.cpp +++ b/plugins/MyDetails/src/data.cpp @@ -284,27 +284,10 @@ int Protocol::GetNickMaxLength() return ret;
}
-TCHAR *Protocol::GetNick()
+TCHAR* Protocol::GetNick()
{
- // Get it
- CONTACTINFO ci = { 0 };
- ci.cbSize = sizeof(ci);
- ci.hContact = NULL;
- ci.szProto = name;
- ci.dwFlag = CNF_DISPLAY;
-
-#ifdef UNICODE
- ci.dwFlag |= CNF_UNICODE;
-#endif
-
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) {
- // CNF_DISPLAY always returns a string type
- lcopystr(nickname, ci.pszVal, _countof(nickname));
- mir_free(ci.pszVal);
- }
- else
- lcopystr(nickname, _T(""), _countof(nickname));
-
+ ptrT nick(Contact_GetInfo(CNF_DISPLAY, NULL, name));
+ lcopystr(nickname, (nick != NULL) ? nick : _T(""), _countof(nickname));
return nickname;
}
diff --git a/plugins/QuickMessages/src/Utils.cpp b/plugins/QuickMessages/src/Utils.cpp index 7878317d5c..9067c7ac12 100644 --- a/plugins/QuickMessages/src/Utils.cpp +++ b/plugins/QuickMessages/src/Utils.cpp @@ -397,7 +397,6 @@ TCHAR* ParseString(MCONTACT hContact, TCHAR* ptszQValIn, TCHAR* ptszText, TCHAR* TCHAR* p = NULL; int NameLenght = 0; TCHAR* ptszName = NULL; - CONTACTINFO ci; if (!_tcschr(ptszQValue, varstr)) return ptszQValue; @@ -499,16 +498,10 @@ TCHAR* ParseString(MCONTACT hContact, TCHAR* ptszQValIn, TCHAR* ptszText, TCHAR* i = -1; break; case 'F': - memset(&ci, 0, sizeof(CONTACTINFO)); - ci.cbSize = sizeof(CONTACTINFO); - ci.hContact = hContact; - ci.dwFlag = CNF_FIRSTNAME | CNF_UNICODE; - ci.szProto = GetContactProto(hContact); - - if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) + ptszName = Contact_GetInfo(CNF_FIRSTNAME, hContact); + if (ptszName == NULL) break; - NameLenght = (int)mir_tstrlen(ci.pszVal); - ptszName = ci.pszVal; + NameLenght = (int)mir_tstrlen(ptszName); p = (TCHAR *)realloc(tempQValue, (QVSize + NameLenght + 1) * sizeof(TCHAR)); if (!p) { mir_free(ptszName); @@ -531,16 +524,11 @@ TCHAR* ParseString(MCONTACT hContact, TCHAR* ptszQValIn, TCHAR* ptszText, TCHAR* i = -1; break; case 'L': - memset(&ci, 0, sizeof(CONTACTINFO)); - ci.cbSize = sizeof(CONTACTINFO); - ci.hContact = hContact; - ci.dwFlag = CNF_LASTNAME | CNF_UNICODE; - ci.szProto = GetContactProto(hContact); - - if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) + ptszName = Contact_GetInfo(CNF_LASTNAME, hContact); + if (ptszName == NULL) break; - NameLenght = (int)mir_tstrlen(ci.pszVal); - ptszName = ci.pszVal; + + NameLenght = (int)mir_tstrlen(ptszName); p = (TCHAR *)realloc(tempQValue, (QVSize + NameLenght + 1) * sizeof(TCHAR)); if (!p) { mir_free(ptszName); diff --git a/plugins/QuickSearch/i_ok.inc b/plugins/QuickSearch/i_ok.inc index 009dcd6ba5..c710f76880 100644 --- a/plugins/QuickSearch/i_ok.inc +++ b/plugins/QuickSearch/i_ok.inc @@ -257,8 +257,8 @@ end; procedure LoadOneItem(hContact:THANDLE;column:pcolumnitem;proto:integer; var res:tQSRec);
var
lmodule:PAnsiChar;
+ pInfo:PWideChar;
DbEvent:TMEVENT;
- cni:TCONTACTINFO;
dbei:TDBEVENTINFO;
data:tSubstData;
begin
@@ -299,36 +299,14 @@ begin end;
QST_CONTACTINFO: begin
- FillChar(cni,SizeOf(cni),0);
- cni.cbSize :=sizeof(cni);
- cni.dwFlag :=cnftype or CNF_UNICODE;
- cni.hContact:=hContact;
- cni.szProto :=GetProtoName(proto);
- if CallService(MS_CONTACT_GETCONTACTINFO,0,tlparam(@cni))=0 then
+ pInfo := Contact_GetInfo(cnftype,hContact,nil);
+ if pInfo <> nil then
begin
- case cni._type of
- CNFT_ASCIIZ: begin
- if cni.retval.szVal.w<>nil then
- begin
- StrDupW(res.text,cni.retval.szVal.w);
- mir_free(cni.retval.szVal.w);
- end;
- exit;
- end;
- CNFT_BYTE :begin
- res.data:=cni.retval.bVal;
- if cnftype=CNF_GENDER then
- begin
- if not (res.data in [70,77]) then
- res.data:=DBReadByte(hContact,'UserInfo','Gender',0);
- exit;
- end
- end;
- CNFT_WORD :res.data:=cni.retval.wVal;
- CNFT_DWORD:res.data:=cni.retval.dVal;
- end;
- res.text:=int2strw(res.data);
+ StrDupW(res.text,pInfo);
+ mir_free(pInfo);
+ exit;
end;
+ res.text:=int2strw(res.data);
end;
QST_SETTING: begin
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index fd908788d0..0f8ec8a47e 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -144,19 +144,9 @@ EventData* getEventFromDB(SrmmWindowData *dat, MCONTACT hContact, MEVENT hDbEven evt->time = dbei.timestamp;
evt->pszNick = NULL;
- if (evt->dwFlags & IEEDF_SENT) {
- CONTACTINFO ci = {};
- ci.cbSize = sizeof(ci);
- ci.szProto = dat->szProto;
- ci.dwFlag = CNF_DISPLAY | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, LPARAM(&ci))) {
- if (ci.type == CNFT_ASCIIZ)
- evt->pszNickT = ci.pszVal;
- else
- evt->pszNickT = CMString(FORMAT, _T("%d"), ci.dVal).Detach();
- }
- }
- if (evt->pszNickT == NULL)
+ if (evt->dwFlags & IEEDF_SENT)
+ evt->pszNickT = Contact_GetInfo(CNF_DISPLAY, NULL);
+ else
evt->pszNickT = mir_tstrdup(pcli->pfnGetContactDisplayName(hContact, 0));
if (evt->eventType == EVENTTYPE_FILE) {
diff --git a/plugins/Scriver/src/utils.cpp b/plugins/Scriver/src/utils.cpp index 588871c788..8cc13d209b 100644 --- a/plugins/Scriver/src/utils.cpp +++ b/plugins/Scriver/src/utils.cpp @@ -387,24 +387,9 @@ void SetSearchEngineIcons(HMENU hMenu, HIMAGELIST hImageList) void GetContactUniqueId(SrmmWindowData *dat, char *buf, int maxlen)
{
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = dat->hContact;
- ci.szProto = dat->szProto;
- ci.dwFlag = CNF_UNIQUEID;
- buf[0] = 0;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- strncpy_s(buf, maxlen, (char*)ci.pszVal, _TRUNCATE);
- mir_free(ci.pszVal);
- break;
- case CNFT_DWORD:
- mir_snprintf(buf, maxlen, "%u", ci.dVal);
- break;
- }
- }
+ ptrT id(Contact_GetInfo(CNF_UNIQUEID, dat->hContact, dat->szProto));
+ if (id != NULL)
+ strncpy_s(buf, maxlen, _T2A(id), _TRUNCATE);
}
HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle, RECT *rect)
diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index cdbec7f7f4..08826a6b51 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -165,9 +165,8 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) return sztemp;
}
- CONTACTINFO ci = { sizeof(CONTACTINFO) };
- ci.hContact = hcontact;
- ci.szProto = hcontact ? GetContactProto(hcontact) : courProtoName;
+ char *szProto = hcontact ? GetContactProto(hcontact) : courProtoName;
+ ptrT info;
TCHAR *d = sztemp;
for (TCHAR *p = szstring; *p; p++) {
@@ -257,9 +256,8 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) goto LBL_charPtr;
case 'N':
- ci.dwFlag = CNF_NICK | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- charPtr = ci.pszVal;
+ if (info = Contact_GetInfo(CNF_NICK, hcontact, szProto)) {
+ charPtr = info;
goto LBL_charPtr;
}
goto LBL_noData;
@@ -274,26 +272,11 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) break;
case 'u':
- ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- switch (ci.type) {
- case CNFT_BYTE:
- _ltot(ci.bVal, szdbsetting, 10);
- break;
- case CNFT_WORD:
- _ltot(ci.wVal, szdbsetting, 10);
- break;
- case CNFT_DWORD:
- _ltot(ci.dVal, szdbsetting, 10);
- break;
- case CNFT_ASCIIZ:
- _tcsncpy(szdbsetting, ci.pszVal, _countof(szdbsetting));
- break;
- }
+ if (info = Contact_GetInfo(CNF_UNIQUEID, hcontact, szProto)) {
+ charPtr = info;
+ goto LBL_charPtr;
}
- else goto LBL_noData;
- charPtr = szdbsetting;
- goto LBL_charPtr;
+ goto LBL_noData;
case 's':
if (isetting = db_get_w(hcontact, S_MOD, hcontact ? "StatusTriger" : courProtoName, 0)) {
@@ -329,16 +312,15 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) case 'i':
case 'r':
- if (isJabber(ci.szProto)) {
- if (db_get_ts(hcontact, ci.szProto, *p == 'i' ? "Resource" : "System", &dbv))
- goto LBL_noData;
-
- _tcsncpy(szdbsetting, dbv.ptszVal, _countof(szdbsetting));
- db_free(&dbv);
- charPtr = szdbsetting;
+ if (isJabber(szProto)) {
+ if (info = db_get_tsa(hcontact, szProto, *p == 'i' ? "Resource" : "System")) {
+ charPtr = info;
+ goto LBL_charPtr;
+ }
+ goto LBL_noData;
}
else {
- dwsetting = db_get_dw(hcontact, ci.szProto, *p == 'i' ? "IP" : "RealIP", 0);
+ dwsetting = db_get_dw(hcontact, szProto, *p == 'i' ? "IP" : "RealIP", 0);
if (!dwsetting)
goto LBL_noData;
@@ -349,7 +331,7 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) goto LBL_charPtr;
case 'P':
- _tcsncpy(szdbsetting, ci.szProto ? _A2T(ci.szProto) : (wantempty ? _T("") : _T("ProtoUnknown")), _countof(szdbsetting));
+ _tcsncpy(szdbsetting, szProto ? _A2T(szProto) : (wantempty ? _T("") : _T("ProtoUnknown")), _countof(szdbsetting));
charPtr = szdbsetting;
goto LBL_charPtr;
@@ -358,27 +340,26 @@ TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) goto LBL_charPtr;
case 'C': // Get Client Info
- if (!db_get_ts(hcontact, ci.szProto, "MirVer", &dbv)) {
- _tcsncpy(szdbsetting, dbv.ptszVal, _countof(szdbsetting));
- db_free(&dbv);
+ if (info = db_get_tsa(hcontact, szProto, "MirVer")) {
+ charPtr = info;
+ goto LBL_charPtr;
}
- else goto LBL_noData;
- charPtr = szdbsetting;
- goto LBL_charPtr;
+ goto LBL_noData;
case 't':
charPtr = _T("\t");
goto LBL_charPtr;
case 'A':
- {
- PROTOACCOUNT *pa = Proto_GetAccount(ci.szProto);
- if (!pa) goto LBL_noData;
- _tcsncpy(szdbsetting, pa->tszAccountName, _countof(szdbsetting));
- charPtr = szdbsetting;
+ {
+ PROTOACCOUNT *pa = Proto_GetAccount(szProto);
+ if (!pa)
+ goto LBL_noData;
+
+ _tcsncpy(szdbsetting, pa->tszAccountName, _countof(szdbsetting));
+ charPtr = szdbsetting;
+ }
goto LBL_charPtr;
- }
-
default:
*d++ = p[-1];
diff --git a/plugins/SendScreenshotPlus/src/CSendEmail.cpp b/plugins/SendScreenshotPlus/src/CSendEmail.cpp index 9b00c3b4f3..c674e13186 100644 --- a/plugins/SendScreenshotPlus/src/CSendEmail.cpp +++ b/plugins/SendScreenshotPlus/src/CSendEmail.cpp @@ -63,24 +63,8 @@ int CSendEmail::Send() mir_free(m_pszFileA); m_pszFileA = mir_t2a(m_pszFile); - - // AnsiString Email, Subject, FriendlyName; - CONTACTINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.hContact = m_hContact; - ci.szProto = m_pszProto; - //ci.dwFlag = CNF_TCHAR; - - ci.dwFlag = CNF_EMAIL | CNF_TCHAR; - CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); - m_Email = mir_t2a(ci.pszVal); - - ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); - m_FriendlyName = mir_t2a(ci.pszVal); - - mir_free(ci.pszVal); - + m_Email = mir_t2a(ptrT(Contact_GetInfo(CNF_EMAIL, m_hContact, m_pszProto))); + m_FriendlyName = mir_t2a(ptrT(Contact_GetInfo(CNF_DISPLAY, m_hContact, m_pszProto))); m_Subject = mir_t2a(m_pszFileDesc); //SendByEmail(m_pszFileA, "", m_FriendlyName, m_Email, m_Subject); diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index cc13f07cbd..16265231d2 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -190,36 +190,9 @@ BOOL IsUrlContains(TCHAR * Str) tstring GetContactUid(MCONTACT hContact, tstring Protocol)
{
- tstring Uid;
- TCHAR dUid[32] = { 0 };
- char aUid[32] = { 0 };
char *szProto = mir_utf8encodeW(Protocol.c_str());
- CONTACTINFO ci;
- memset(&ci, 0, sizeof(ci));
-
- ci.hContact = hContact;
- ci.szProto = szProto;
- ci.cbSize = sizeof(ci);
-
- ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR;
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- Uid = ci.pszVal;
- mir_free((void *)ci.pszVal);
- break;
- case CNFT_DWORD:
- _itoa_s(ci.dVal, aUid, 32, 10);
- OemToChar(aUid, dUid);
- Uid = dUid;
- break;
- default:
- Uid = _T("");
- break;
- };
- }
- mir_free(szProto);
- return Uid;
+ ptrT uid(Contact_GetInfo(CNF_DISPLAYUID, hContact, szProto));
+ return (uid) ? uid : _T("");
}
void LogSpamToFile(MCONTACT hContact, tstring message)
diff --git a/plugins/TabSRMM/src/contactcache.cpp b/plugins/TabSRMM/src/contactcache.cpp index e51fee1f34..62781bbc5b 100644 --- a/plugins/TabSRMM/src/contactcache.cpp +++ b/plugins/TabSRMM/src/contactcache.cpp @@ -178,21 +178,9 @@ bool CContactCache::updateUIN() m_szUIN[0] = 0; if (m_Valid) { - CONTACTINFO ci = { sizeof(ci) }; - ci.hContact = getActiveContact(); - ci.szProto = const_cast<char *>(getActiveProto()); - ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - _tcsncpy_s(m_szUIN, ci.pszVal, _TRUNCATE); - mir_free(ci.pszVal); - break; - case CNFT_DWORD: - mir_sntprintf(m_szUIN, _T("%u"), ci.dVal); - break; - } - } + ptrT uid(Contact_GetInfo(CNF_DISPLAYUID, getActiveContact(), getActiveProto())); + if (uid != NULL) + _tcsncpy_s(m_szUIN, uid, _TRUNCATE); } return false; diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index c669c187cb..0e5bc78714 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -1037,25 +1037,11 @@ BOOL TSAPI DoRtfToTags(const TWindowData *dat, CMString &pszText, int iNumColors void TSAPI GetMYUIN(TWindowData *dat)
{
- CONTACTINFO ci = { sizeof(ci) };
- ci.szProto = const_cast<char *>(dat->cache->getActiveProto());
- ci.dwFlag = CNF_TCHAR | CNF_DISPLAYUID;
-
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- _tcsncpy_s(dat->myUin, ci.pszVal, _TRUNCATE);
- mir_free((void*)ci.pszVal);
- break;
- case CNFT_DWORD:
- mir_sntprintf(dat->myUin, _T("%u"), ci.dVal);
- break;
- default:
- dat->myUin[0] = 0;
- break;
- }
- }
- else dat->myUin[0] = 0;
+ ptrT uid(Contact_GetInfo(CNF_DISPLAYUID, NULL, dat->cache->getActiveProto()));
+ if (uid != NULL)
+ _tcsncpy_s(dat->myUin, uid, _TRUNCATE);
+ else
+ dat->myUin[0] = 0;
}
static int g_IEViewAvail = -1;
@@ -1748,37 +1734,14 @@ void TSAPI GetClientIcon(TWindowData *dat) void TSAPI GetMyNick(TWindowData *dat)
{
- CONTACTINFO ci;
-
- memset(&ci, 0, sizeof(ci));
- ci.cbSize = sizeof(ci);
- ci.hContact = NULL;
- ci.szProto = const_cast<char *>(dat->cache->getActiveProto());
- ci.dwFlag = CNF_TCHAR | CNF_NICK;
-
- if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- switch (ci.type) {
- case CNFT_ASCIIZ:
- if (mir_tstrlen((TCHAR*)ci.pszVal) == 0 ||
- !mir_tstrcmp((TCHAR*)ci.pszVal, TranslateT("'(Unknown contact)'"))) {
- _tcsncpy_s(dat->szMyNickname, (dat->myUin[0] ? dat->myUin : TranslateT("'(Unknown contact)'")), _TRUNCATE);
- }
- else {
- _tcsncpy_s(dat->szMyNickname, (TCHAR*)ci.pszVal, _TRUNCATE);
- }
- break;
- case CNFT_DWORD:
- _ltot(ci.dVal, dat->szMyNickname, 10);
- break;
- default:
- _tcsncpy_s(dat->szMyNickname, _T("<undef>"), _TRUNCATE); // that really should *never* happen
- break;
- }
- mir_free(ci.pszVal);
- }
- else {
- _tcsncpy_s(dat->szMyNickname, _T("<undef>"), _TRUNCATE); // same here
+ ptrT tszNick(Contact_GetInfo(CNF_NICK, NULL, dat->cache->getActiveProto()));
+ if (tszNick != NULL) {
+ if (mir_tstrlen(tszNick) == 0 || !mir_tstrcmp(tszNick, TranslateT("'(Unknown contact)'")))
+ _tcsncpy_s(dat->szMyNickname, (dat->myUin[0] ? dat->myUin : TranslateT("'(Unknown contact)'")), _TRUNCATE);
+ else
+ _tcsncpy_s(dat->szMyNickname, tszNick, _TRUNCATE);
}
+ else _tcsncpy_s(dat->szMyNickname, _T("<undef>"), _TRUNCATE); // same here
}
HICON TSAPI MY_GetContactIcon(const TWindowData *dat, LPCSTR szSetting)
diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp index 102fe49b42..a669db5ecd 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp @@ -291,25 +291,13 @@ void CExImContactBase::toIni(FILE* file, int modCount) } else { // Proto loaded - GetContactName(hContact,pszProto,0) - LPSTR pszCI = NULL; - CONTACTINFO ci = {}; - ci.cbSize = sizeof(ci); - ci.hContact = _hContact; - ci.szProto = _pszProto; - ci.dwFlag = CNF_DISPLAY; - if (!CallService(MS_CONTACT_GETCONTACTINFO, NULL, (LPARAM)&ci)) { - // CNF_DISPLAY always returns a string type - pszCI = (LPSTR)ci.pszVal; - } - LPSTR pszUID = uid2String(FALSE); + ptrT pszCI(Contact_GetInfo(CNF_DISPLAY, _hContact, _pszProto)); + ptrA pszUID(uid2String(FALSE)); if (_pszUIDKey && pszUID) - mir_snprintf(name, "%s *(%s)*<%s>*{%s}*", pszCI, _pszProto, _pszUIDKey, pszUID); + mir_snprintf(name, "%S *(%s)*<%s>*{%s}*", pszCI, _pszProto, _pszUIDKey, pszUID); else - mir_snprintf(name, "%s (%s)", pszCI, _pszProto); - - mir_free(pszCI); - mir_free(pszUID); - } // end else (Proto loaded) + mir_snprintf(name, "%S (%s)", pszCI, _pszProto); + } // it is not the best solution (but still works if only basic modules export) - need rework if (modCount > 3) diff --git a/plugins/Utils.pas/mircontacts.pas b/plugins/Utils.pas/mircontacts.pas index dc43b8d84e..43abcda5ba 100644 --- a/plugins/Utils.pas/mircontacts.pas +++ b/plugins/Utils.pas/mircontacts.pas @@ -85,8 +85,7 @@ end; function GetContactDisplayName(hContact: TMCONTACT; Proto: PAnsiChar = nil; Contact: boolean = false): PWideChar;
var
- ci: TContactInfo;
- pUnk:PWideChar;
+ pName, pUnk:PWideChar;
begin
if (hContact = 0) and Contact then
StrDupW(Result, TranslateW('Server'))
@@ -99,17 +98,14 @@ begin StrDupW(Result, pUnk)
else
begin
- ci.cbSize := SizeOf(ci);
- ci.hContact := hContact;
- ci.szProto := Proto;
- ci.dwFlag := CNF_DISPLAY + CNF_UNICODE;
- if CallService(MS_CONTACT_GETCONTACTINFO, 0, LPARAM(@ci)) = 0 then
+ pName := Contact_GetInfo(CNF_DISPLAY, hContact, Proto);
+ if pName <> nil then
begin
- if StrCmpW(ci.retval.szVal.w, pUnk)=0 then
+ if StrCmpW(pName, pUnk)=0 then
AnsiToWide(GetContactID(hContact, Proto), Result, CP_ACP)
else
- StrDupW(Result, ci.retval.szVal.w);
- mir_free(ci.retval.szVal.w);
+ StrDupW(Result, pName);
+ mir_free(pName);
end
else
AnsiToWide(GetContactID(hContact, Proto), Result);
diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index 7ab46f484e..88b93ea931 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -164,32 +164,7 @@ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact) break;
}
- CONTACTINFO ci = { sizeof(ci) };
- ci.hContact = hContact;
- ci.dwFlag = type | CNF_UNICODE;
- CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci);
-
- char szVal[16];
- memset(szVal, '\0', sizeof(szVal));
- switch (ci.type) {
- case CNFT_BYTE:
- if (type == CNF_GENDER) {
- szVal[0] = (char)ci.bVal; szVal[1] = 0;
- return mir_a2t(szVal);
- }
- return itot(ci.bVal);
-
- case CNFT_WORD:
- return itot(ci.wVal);
-
- case CNFT_DWORD:
- return itot(ci.dVal);
-
- case CNFT_ASCIIZ:
- return ci.pszVal;
- }
-
- return NULL;
+ return Contact_GetInfo(type, hContact);
}
// MS_VARS_GETCONTACTFROMSTRING
diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index e6431a19cb..42a9762bd4 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -361,15 +361,8 @@ static TCHAR* parseProtoInfo(ARGUMENTSINFO *ai) if (INT_PTR(szRes) == CALLSERVICE_NOTFOUND)
return NULL;
}
- else if (!mir_tstrcmp(ai->targv[2], _T(STR_PINICK))) {
- CONTACTINFO ci;
- ci.cbSize = sizeof(CONTACTINFO);
- ci.dwFlag = CNF_DISPLAY | CNF_UNICODE;
- ci.hContact = NULL;
- ci.szProto = szProto;
- CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci);
- tszRes = ci.pszVal;
- }
+ else if (!mir_tstrcmp(ai->targv[2], _T(STR_PINICK)))
+ tszRes = Contact_GetInfo(CNF_DISPLAY, NULL, szProto);
if (szRes == NULL && tszRes == NULL)
return NULL;
diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp index 8018101d68..9667b1bc37 100644 --- a/plugins/WhenWasIt/src/utils.cpp +++ b/plugins/WhenWasIt/src/utils.cpp @@ -140,43 +140,13 @@ int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, si TCHAR* GetContactID(MCONTACT hContact)
{
- return GetContactID(hContact, GetContactProto(hContact));
+ return GetContactID(hContact, NULL);
}
TCHAR* GetContactID(MCONTACT hContact, char *szProto)
{
- CONTACTINFO ctInfo = { sizeof(ctInfo) };
- ctInfo.szProto = szProto;
- ctInfo.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
- ctInfo.hContact = hContact;
- INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ctInfo);
- TCHAR *buffer;
- if (!ret) {
- TCHAR tmp[16];
- switch (ctInfo.type) {
- case CNFT_BYTE:
- mir_sntprintf(tmp, _T("%d"), ctInfo.bVal);
- buffer = _tcsdup(tmp);
- break;
-
- case CNFT_WORD:
- mir_sntprintf(tmp, _T("%d"), ctInfo.wVal);
- buffer = _tcsdup(tmp);
- break;
-
- case CNFT_DWORD:
- mir_sntprintf(tmp, _T("%ld"), ctInfo.dVal);
- buffer = _tcsdup(tmp);
- break;
-
- default:
- buffer = _tcsdup(ctInfo.pszVal);
- break;
- }
- }
-
- mir_free(ctInfo.pszVal);
- return (!ret) ? buffer : NULL;
+ ptrT res(Contact_GetInfo(CNF_UNIQUEID, hContact, szProto));
+ return (res) ? _tcsdup(res) : NULL;
}
MCONTACT GetContactFromID(TCHAR *szID, char *szProto)
diff --git a/plugins/YARelay/src/main.cpp b/plugins/YARelay/src/main.cpp index fb3e97319e..a39708cbce 100644 --- a/plugins/YARelay/src/main.cpp +++ b/plugins/YARelay/src/main.cpp @@ -151,20 +151,11 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDBEvent) case 'i':
case 'I':
{
- // get sender's uin
- CONTACTINFO ci = { sizeof(ci) };
- ci.dwFlag = CNF_UNIQUEID;
- if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0){
- if (ci.type == CNFT_ASCIIZ)
- _tcsncpy_s(buf, ci.pszVal, _TRUNCATE);
- else if (ci.type == CNFT_BYTE)
- mir_sntprintf(buf, _T("%u"), ci.bVal);
- else if (ci.type == CNFT_WORD)
- mir_sntprintf(buf, _T("%u"), ci.wVal);
- else if (ci.type == CNFT_DWORD)
- mir_sntprintf(buf, _T("%u"), ci.dVal);
- }
- else mir_sntprintf(buf, _T("%p"), hContact);
+ ptrT id(Contact_GetInfo(CNF_UNIQUEID, NULL));
+ if (id != NULL)
+ _tcsncpy_s(buf, id, _TRUNCATE);
+ else
+ mir_sntprintf(buf, _T("%p"), hContact);
}
szUtfMsg.append(T2Utf(buf));
break;
diff --git a/plugins/YahooGroups/src/utils.cpp b/plugins/YahooGroups/src/utils.cpp index 0557790b2d..b33d7d888f 100644 --- a/plugins/YahooGroups/src/utils.cpp +++ b/plugins/YahooGroups/src/utils.cpp @@ -158,35 +158,10 @@ int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, return GetStringFromDatabase(NULL, ModuleName, szSettingName, szError, szResult, count);
}
-TCHAR *GetContactName(MCONTACT hContact, char *szProto)
+TCHAR* GetContactName(MCONTACT hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- char proto[200];
-
- memset(&ctInfo, 0, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- if (szProto)
- {
- ctInfo.szProto = szProto;
- }
- else{
- GetContactProtocol(hContact, proto, sizeof(proto));
- ctInfo.szProto = proto;
- }
- ctInfo.dwFlag = CNF_DISPLAY | CNF_TCHAR;
- ctInfo.hContact = hContact;
- //_debug_message("retrieving contact name for %d", hContact);
- INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
- //_debug_message(" contact name %s", ctInfo.pszVal);
- TCHAR *buffer;
- if (!ret)
- buffer = _tcsdup(ctInfo.pszVal);
-
- mir_free(ctInfo.pszVal);
- if (!ret)
- return buffer;
-
- return NULL;
+ ptrT id(Contact_GetInfo(CNF_DISPLAYUID, hContact, szProto));
+ return (id != NULL) ? _tcsdup(id) : NULL;
}
void GetContactProtocol(MCONTACT hContact, char *szProto, int size)
@@ -202,62 +177,10 @@ TCHAR *GetContactID(MCONTACT hContact) return GetContactID(hContact, protocol);
}
-TCHAR *GetContactID(MCONTACT hContact, char *szProto)
+TCHAR* GetContactID(MCONTACT hContact, char *szProto)
{
- CONTACTINFO ctInfo;
-
- memset(&ctInfo, 0, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- ctInfo.szProto = szProto;
- ctInfo.dwFlag = CNF_DISPLAY | CNF_TCHAR;
- ctInfo.hContact = hContact;
- INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
- TCHAR *buffer;
- if (!ret)
- {
- TCHAR tmp[16];
- switch (ctInfo.type)
- {
- case CNFT_BYTE:
- {
- mir_sntprintf(tmp, _T("%d"), ctInfo.bVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_WORD:
- {
- mir_sntprintf(tmp, _T("%d"), ctInfo.wVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_DWORD:
- {
- mir_sntprintf(tmp, _T("%ld"), ctInfo.dVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_ASCIIZ:
- default:
- {
- buffer = _tcsdup(ctInfo.pszVal);
-
- break;
- }
- }
-
-
- }
- mir_free(ctInfo.pszVal);
- if (!ret)
- return buffer;
-
- return NULL;
+ ptrT id(Contact_GetInfo(CNF_DISPLAY, hContact, szProto));
+ return (id != NULL) ? _tcsdup(id) : NULL;
}
MCONTACT GetContactFromID(TCHAR *szID, char *szProto)
diff --git a/plugins/mRadio/i_myservice.inc b/plugins/mRadio/i_myservice.inc index 88ae278633..d55ab469e9 100644 --- a/plugins/mRadio/i_myservice.inc +++ b/plugins/mRadio/i_myservice.inc @@ -3,9 +3,9 @@ function Service_RadioPlayStop(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
p:PAnsiChar;
+ tmpw, res:PWideChar;
lnew:bool;
hContact:TMCONTACT;
- cni:TCONTACTINFO;
i:integer;
begin
result:=0;
@@ -21,30 +21,21 @@ begin // wParam = station name
else
begin
- FillChar(cni,SizeOf(cni),0);
- cni.cbSize :=sizeof(cni);
- if lParam=1 then
- cni.dwFlag:=CNF_DISPLAY
- else
- cni.dwFlag:=CNF_DISPLAY or CNF_UNICODE;
- cni.szProto :=PluginName;
-
+ AnsiToWide(pAnsiChar(wParam), tmpw);
hContact:=db_find_first(PluginName);
while hContact<>0 do
begin
- cni.hContact:=hContact;
- if CallService(MS_CONTACT_GETCONTACTINFO,0,tlparam(@cni))=0 then
+ res:=Contact_GetInfo(CNF_DISPLAY,hContact,PluginName);
+ if res <> nil then
begin
- if lParam=1 then
- i:=StrCmp(pAnsiChar(wParam),cni.retval.szVal.a)
- else
- i:=StrCmpW(pWideChar(wParam),cni.retval.szVal.w);
- mir_free(cni.retval.szVal.w);
+ i:=StrCmpW(tmpw, res);
+ mir_free(res);
if i=0 then
break;
end;
hContact:=db_find_next(hContact,PluginName);
end;
+ mFreeMem(tmpw);
end;
if hContact<>0 then
|