summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorVlad Mironov <mironych@googlemail.com>2012-07-02 04:39:51 +0000
committerVlad Mironov <mironych@googlemail.com>2012-07-02 04:39:51 +0000
commit61930b2a3c3fcbd8f40284ac77902806b2b3b493 (patch)
tree51d9001807760c400a838e9aec318b0874f64268 /plugins
parent8ff9ea222993b065a49efa138919b3e062299697 (diff)
Ещё одна крошечная оптимизация (избавляемся от неюникодности).
git-svn-id: http://svn.miranda-ng.org/main/trunk@711 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Variables/contact.cpp222
-rw-r--r--plugins/Variables/parse_metacontacts.cpp2
2 files changed, 72 insertions, 152 deletions
diff --git a/plugins/Variables/contact.cpp b/plugins/Variables/contact.cpp
index c146f4e261..029f9bf818 100644
--- a/plugins/Variables/contact.cpp
+++ b/plugins/Variables/contact.cpp
@@ -109,202 +109,124 @@ BYTE getContactInfoType(TCHAR* type) {
/*
returns info about a contact as a string
*/
-static TCHAR* getContactInfo(BYTE type, HANDLE hContact)
+TCHAR* getContactInfoT(BYTE type, HANDLE hContact)
{
/* returns dynamic allocated buffer with info, or NULL if failed */
CONTACTINFO ci;
- TCHAR *res, *szStatus;
+ TCHAR *res = NULL, *szStatus;
char *szProto, protoname[128], szVal[16];
- int status;
- BYTE realType;
DBVARIANT dbv;
- res = NULL;
if (hContact == NULL)
return NULL;
- realType = (type & ~CNF_UNICODE);
- switch ( realType ) {
- case CCNF_PROTOID:
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto == NULL)
- return NULL;
-
- if (type & CNF_UNICODE )
- return (TCHAR*)mir_a2t(szProto);
- return (TCHAR*)mir_strdup(szProto);
-
- case CCNF_ACCOUNT:
- if (g_mirandaVersion < PLUGIN_MAKE_VERSION( 0,8,0,0 ))
- return NULL;
-
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto) {
- PROTOACCOUNT* pa = ProtoGetAccount( szProto );
- if (pa )
- return mir_tstrdup( pa->tszAccountName );
- }
+ szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
+ if (szProto == NULL)
return NULL;
- case CCNF_PROTOCOL:
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto == NULL)
- return NULL;
+ switch (type)
+ {
+ case CCNF_PROTOID:
+ return (TCHAR*)mir_a2t(szProto);
- if (CallProtoService(szProto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname))
- return NULL;
+ case CCNF_ACCOUNT:
+ if (g_mirandaVersion < PLUGIN_MAKE_VERSION( 0,8,0,0 ))
+ return NULL;
+ {
+ PROTOACCOUNT* pa = ProtoGetAccount(szProto);
+ return pa ? mir_tstrdup(pa->tszAccountName) : NULL;
+ }
- if (type & CNF_UNICODE )
+ case CCNF_PROTOCOL:
+ if (CallProtoService(szProto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname))
+ return NULL;
return (TCHAR*)mir_a2t(protoname);
- return (TCHAR*)mir_strdup(protoname);
-
- case CCNF_STATUS:
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto == NULL)
- return NULL;
-
- status = DBGetContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE);
- if (status == 0)
- return NULL;
-
- if (type & CNF_UNICODE) {
- szStatus = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, (LPARAM)GSMDF_UNICODE);
+ case CCNF_STATUS:
+ szStatus = (TCHAR*)CallService(
+ MS_CLIST_GETSTATUSMODEDESCRIPTION,
+ (WPARAM)DBGetContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE),
+ (LPARAM)GSMDF_UNICODE);
if (szStatus == NULL)
return NULL;
-
return mir_tstrdup(szStatus);
- }
- else {
- char *aszStatus = (char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, 0);
- if (aszStatus == NULL)
- return NULL;
-
- return (TCHAR*)mir_strdup(aszStatus);
- }
- case CCNF_INTERNALIP:
- case CCNF_EXTERNALIP:
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto == NULL)
- return NULL;
- else {
- DWORD ip = DBGetContactSettingDword(hContact, szProto, (realType==CCNF_INTERNALIP)?"RealIP":"IP", 0);
- if (ip == 0)
- return NULL;
-
- struct in_addr in;
- in.s_addr = htonl(ip);
- char* dotted = inet_ntoa(in);
- if (dotted == NULL)
- return NULL;
-
- if (type & CNF_UNICODE )
+ case CCNF_INTERNALIP:
+ case CCNF_EXTERNALIP:
+ {
+ DWORD ip = DBGetContactSettingDword(hContact, szProto, (type == CCNF_INTERNALIP) ? "RealIP" : "IP", 0);
+ if (ip == 0)
+ return NULL;
+
+ struct in_addr in;
+ in.s_addr = htonl(ip);
+ char* dotted = inet_ntoa(in);
+ if (dotted == NULL)
+ return NULL;
return (TCHAR*)mir_a2t(dotted);
- return (TCHAR*)mir_strdup(dotted);
- }
-
- case CCNF_GROUP:
- if (!DBGetContactSetting(hContact, "CList", "Group", &dbv)) {
- if (type & CNF_UNICODE )
- res = (TCHAR*)mir_a2t(dbv.pszVal);
- else
- res = (TCHAR*)mir_strdup(dbv.pszVal);
+ }
- DBFreeVariant(&dbv);
- return res;
- }
- if (!DBGetContactSettingW(hContact, "CList", "Group", &dbv)) {
- if (type & CNF_UNICODE )
+ case CCNF_GROUP:
+ if (!DBGetContactSettingTString(hContact, "CList", "Group", &dbv))
+ {
res = (TCHAR*)mir_wstrdup(dbv.pwszVal);
- else
- res = (TCHAR*)mir_u2a(dbv.pwszVal);
-
- DBFreeVariant(&dbv);
- return res;
- }
- break;
+ DBFreeVariant(&dbv);
+ return res;
+ }
+ break;
- case CNF_UNIQUEID:
- //UID for ChatRoom
- szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if (szProto != NULL) {
- if (DBGetContactSettingByte(hContact, szProto, "ChatRoom", 0) == 1) {
+ case CNF_UNIQUEID:
+ //UID for ChatRoom
+ if (DBGetContactSettingByte(hContact, szProto, "ChatRoom", 0) == 1)
+ {
DBVARIANT dbv;
- if (!DBGetContactSettingTString(hContact, szProto, "ChatRoomID", &dbv )) {
+ if (!DBGetContactSettingTString(hContact, szProto, "ChatRoomID", &dbv ))
+ {
res = mir_tstrdup( dbv.ptszVal );
DBFreeVariant( &dbv );
return res;
- } } }
- //UID for other contact
- break;
+ }
+ }
+
+ //UID for other contact
+ break;
}
ZeroMemory(&ci,sizeof(CONTACTINFO));
ci.cbSize = sizeof(CONTACTINFO);
ci.hContact = hContact;
- ci.dwFlag = type;
- if (CallService(MS_CONTACT_GETCONTACTINFO,(WPARAM)0,(LPARAM)&ci)) {
- if (!( type & CNF_UNICODE ))
- return NULL;
-
- // retrieving the data using UNICODE failed, try without
- ci.dwFlag &= ~CNF_UNICODE;
- if (CallService( MS_CONTACT_GETCONTACTINFO,(WPARAM)0,(LPARAM)&ci ))
- return NULL;
-
- if (ci.type == CNFT_ASCIIZ) {
- if (type & CNF_UNICODE) {
- TCHAR *ptszVal;
-
- ptszVal = (TCHAR*)mir_a2t((char *)ci.pszVal);
- mir_free(ci.pszVal);
- return ptszVal;
- }
- else {
- res = (TCHAR*)mir_strdup((char *)ci.pszVal);
- mir_free(ci.pszVal);
- return res;
- } } }
+ ci.dwFlag = type | CNF_UNICODE;
+ CallService(MS_CONTACT_GETCONTACTINFO, (WPARAM)0, (LPARAM)&ci);
memset(szVal, '\0', sizeof(szVal));
- switch(ci.type){
- case CNFT_BYTE:
- if (realType != CNF_GENDER)
- return itot(ci.bVal);
+ switch(ci.type)
+ {
+ case CNFT_BYTE:
+ if (type != CNF_GENDER)
+ return itot(ci.bVal);
- szVal[0] = (char)ci.bVal;
- if (type & CNF_UNICODE )
+ szVal[0] = (char)ci.bVal;
return (TCHAR*)mir_a2t(szVal);
- return (TCHAR*)mir_strdup(szVal);
- case CNFT_WORD:
- return itot(ci.wVal);
+ case CNFT_WORD:
+ return itot(ci.wVal);
- case CNFT_DWORD:
- return itot(ci.dVal);
+ case CNFT_DWORD:
+ return itot(ci.dVal);
- case CNFT_ASCIIZ:
- if (ci.pszVal != NULL) {
- if (type&CNF_UNICODE)
+ case CNFT_ASCIIZ:
+ if (ci.pszVal != NULL)
+ {
res = mir_tstrdup(ci.pszVal);
- else
- res = (TCHAR*)mir_strdup((char *)ci.pszVal);
-
- mir_free(ci.pszVal);
- }
- break;
+ mir_free(ci.pszVal);
+ }
+ break;
}
return res;
}
-TCHAR *getContactInfoT(BYTE type, HANDLE hContact)
-{
- return getContactInfo((BYTE)(type | CNF_UNICODE), hContact);
-}
-
/*
MS_VARS_GETCONTACTFROMSTRING
*/
diff --git a/plugins/Variables/parse_metacontacts.cpp b/plugins/Variables/parse_metacontacts.cpp
index 128a04a99b..8831e7a192 100644
--- a/plugins/Variables/parse_metacontacts.cpp
+++ b/plugins/Variables/parse_metacontacts.cpp
@@ -58,7 +58,6 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai)
if (szUniqueID == NULL)
{
szProto = PROTOID_HANDLE;
- //szUniqueID = itot((INT_PTR)hContact);
szUniqueID = (TCHAR*)mir_alloc(32);
_stprintf(szUniqueID, _T("%p"), hContact);
if (szProto == NULL || szUniqueID == NULL)
@@ -119,7 +118,6 @@ static TCHAR *parseGetDefault(ARGUMENTSINFO *ai)
if (szUniqueID == NULL) {
szProto = PROTOID_HANDLE;
- //szUniqueID = itot((INT_PTR)hContact);
szUniqueID = (TCHAR*)mir_alloc(32);
_stprintf(szUniqueID, _T("%p"), hContact);
if (szProto == NULL || szUniqueID == NULL)