summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-10 18:36:46 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-10 18:36:46 +0300
commit288f7b5d7c5e76ba458ffa5522901b41c750f55a (patch)
tree056bae6162955b97ad4c9cfcc7df3fc4519585c6 /plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp
parent013de96b8f9abbb082fac524ca0001fa112194f5 (diff)
UInfoEx: massive ANSI cleaning
Diffstat (limited to 'plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp')
-rw-r--r--plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp259
1 files changed, 132 insertions, 127 deletions
diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp
index 19dc88f493..f7a760cdff 100644
--- a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp
+++ b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* param: none
* return: nothing
**/
+
CExImContactBase::CExImContactBase()
{
_pszNick = nullptr;
@@ -50,6 +51,7 @@ CExImContactBase::CExImContactBase()
* param: none
* return: nothing
**/
+
CExImContactBase::~CExImContactBase()
{
MIR_FREE(_pszNick);
@@ -70,6 +72,7 @@ CExImContactBase::~CExImContactBase()
* param: hContact - handle to contact whose information to read
* return: TRUE if successful or FALSE otherwise
**/
+
BYTE CExImContactBase::fromDB(MCONTACT hContact)
{
BYTE ret = FALSE;
@@ -77,7 +80,7 @@ BYTE CExImContactBase::fromDB(MCONTACT hContact)
LPSTR pszProto;
LPCSTR uidSetting;
DBVARIANT dbv;
-
+
_hContact = hContact;
_dbvUIDHash = 0;
MIR_FREE(_pszProtoOld);
@@ -92,13 +95,13 @@ BYTE CExImContactBase::fromDB(MCONTACT hContact)
// OWNER
if (!_hContact) return TRUE;
-
+
// Proto
if (!(pszProto = Proto_GetBaseAccountName(_hContact))) return FALSE;
_pszProto = mir_strdup(pszProto);
// AM_BaseProto
- if (!DB::Setting::GetUString(NULL, pszProto, "AM_BaseProto", &dbv )) {
+ if (!DB::Setting::GetUString(NULL, pszProto, "AM_BaseProto", &dbv)) {
_pszAMPro = mir_strdup(dbv.pszVal);
db_free(&dbv);
}
@@ -127,7 +130,7 @@ BYTE CExImContactBase::fromDB(MCONTACT hContact)
ret = TRUE;
}
}
-
+
// nickname
if (!DB::Setting::GetUString(_hContact, pszProto, SET_CONTACT_NICK, &dbv)) {
_pszNick = mir_strdup(dbv.pszVal);
@@ -135,12 +138,12 @@ BYTE CExImContactBase::fromDB(MCONTACT hContact)
}
if (_hContact && ret) {
- // Clist Group
+ // Clist Group
if (!DB::Setting::GetUString(_hContact, MOD_CLIST, "Group", &dbv)) {
_pszGroup = mir_strdup(dbv.pszVal);
db_free(&dbv);
}
- // Clist DisplayName
+ // Clist DisplayName
if (!DB::Setting::GetUString(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, &dbv)) {
_pszDisp = mir_strdup(dbv.pszVal);
db_free(&dbv);
@@ -156,7 +159,8 @@ BYTE CExImContactBase::fromDB(MCONTACT hContact)
* param: row - the rows data
* return: TRUE if successful or FALSE otherwise
**/
-BYTE CExImContactBase::fromIni(LPSTR& row)
+
+BYTE CExImContactBase::fromIni(LPSTR &row)
{
LPSTR p1, p2 = nullptr;
LPSTR pszUIDValue, pszUIDSetting, pszProto = nullptr;
@@ -195,7 +199,7 @@ BYTE CExImContactBase::fromIni(LPSTR& row)
_dbvUID.type = DBVT_DWORD;
}
else {
- // DBVT_UTF8
+ // DBVT_UTF8
_dbvUID.pszVal = mir_strdup(pszUIDValue);
_dbvUID.type = DBVT_UTF8;
}
@@ -207,7 +211,7 @@ BYTE CExImContactBase::fromIni(LPSTR& row)
// create valid nickname
_pszNick = mir_strdup(pszBuf);
- size_t i = mir_strlen(_pszNick)-1;
+ size_t i = mir_strlen(_pszNick) - 1;
while (i > 0 && (_pszNick[i] == ' ' || _pszNick[i] == '\t')) {
_pszNick[i] = 0;
i--;
@@ -225,6 +229,7 @@ BYTE CExImContactBase::fromIni(LPSTR& row)
* param: hMetaContact - a meta contact to add this contact to
* return: handle of the contact if successful
**/
+
MCONTACT CExImContactBase::toDB()
{
// create new contact if none exists
@@ -272,19 +277,20 @@ MCONTACT CExImContactBase::toDB()
* param: file - pointer to the opened file
* return: nothing
**/
-void CExImContactBase::toIni(FILE* file, int modCount)
+
+void CExImContactBase::toIni(FILE *file, int modCount)
{
// getting dbeditor++ NickFromHContact(hContact)
static char name[512] = "";
- if (_hContact){
+ if (_hContact) {
int loaded = _pszUIDKey ? 1 : 0;
if (_pszProto == nullptr || !loaded) {
- if (_pszProto){
+ if (_pszProto) {
if (_pszNick)
- mir_snprintf(name,"%s (%s)", _pszNick, _pszProto);
+ mir_snprintf(name, "%s (%s)", _pszNick, _pszProto);
else
- mir_snprintf(name,"(UNKNOWN) (%s)", _pszProto);
+ mir_snprintf(name, "(UNKNOWN) (%s)", _pszProto);
}
else
strncpy_s(name, "(UNKNOWN)", _TRUNCATE);
@@ -295,7 +301,7 @@ void CExImContactBase::toIni(FILE* file, int modCount)
ptrA pszUID(uid2String(FALSE));
if (_pszUIDKey && pszUID)
mir_snprintf(name, "%S *(%s)*<%s>*{%s}*", pszCI.get(), _pszProto, _pszUIDKey, pszUID.get());
- else
+ else
mir_snprintf(name, "%S (%s)", pszCI.get(), _pszProto);
}
@@ -315,46 +321,44 @@ BYTE CExImContactBase::compareUID(DBVARIANT *dbv)
{
DWORD hash = 0;
switch (dbv->type) {
- case DBVT_BYTE:
- if (dbv->bVal == _dbvUID.bVal) {
- _dbvUID.type = dbv->type;
- return TRUE;
- }
- break;
- case DBVT_WORD:
- if (dbv->wVal == _dbvUID.wVal) {
- _dbvUID.type = dbv->type;
- return TRUE;
- }
- break;
- case DBVT_DWORD:
- if (dbv->dVal == _dbvUID.dVal) {
- _dbvUID.type = dbv->type;
- return TRUE;
- }
- break;
- case DBVT_ASCIIZ:
- hash = mir_hashstr(dbv->pszVal);
- case DBVT_WCHAR:
- if (!hash) hash = mir_hashstrW(dbv->pwszVal);
- case DBVT_UTF8:
- if (!hash) {
- LPWSTR tmp = mir_utf8decodeW(dbv->pszVal);
- hash = mir_hashstrW(tmp);
- mir_free(tmp);
- }
- if (hash == _dbvUIDHash)
- return TRUE;
- break;
- case DBVT_BLOB: //'n' cpbVal and pbVal are valid
- if (_dbvUID.type == dbv->type &&
- _dbvUID.cpbVal == dbv->cpbVal &&
- memcmp(_dbvUID.pbVal, dbv->pbVal, dbv->cpbVal) == 0) {
- return TRUE;
- }
- break;
- default:
- return FALSE;
+ case DBVT_BYTE:
+ if (dbv->bVal == _dbvUID.bVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_WORD:
+ if (dbv->wVal == _dbvUID.wVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_DWORD:
+ if (dbv->dVal == _dbvUID.dVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_ASCIIZ:
+ hash = mir_hashstr(dbv->pszVal);
+ case DBVT_WCHAR:
+ if (!hash) hash = mir_hashstrW(dbv->pwszVal);
+ case DBVT_UTF8:
+ if (!hash) {
+ LPWSTR tmp = mir_utf8decodeW(dbv->pszVal);
+ hash = mir_hashstrW(tmp);
+ mir_free(tmp);
+ }
+ if (hash == _dbvUIDHash)
+ return TRUE;
+ break;
+ case DBVT_BLOB: //'n' cpbVal and pbVal are valid
+ if (_dbvUID.type == dbv->type &&
+ _dbvUID.cpbVal == dbv->cpbVal &&
+ memcmp(_dbvUID.pbVal, dbv->pbVal, dbv->cpbVal) == 0) {
+ return TRUE;
+ }
+ break;
}
return FALSE;
}
@@ -367,79 +371,79 @@ LPSTR CExImContactBase::uid2String(BYTE bPrependType)
SIZE_T baselen;
switch (_dbvUID.type) {
- case DBVT_BYTE: //'b' bVal and cVal are valid
- if (bPrependType)
- *ptr++ = 'b';
- _itoa(_dbvUID.bVal, ptr, 10);
- break;
- case DBVT_WORD: //'w' wVal and sVal are valid
- if (bPrependType)
- *ptr++ = 'w';
- _itoa(_dbvUID.wVal, ptr, 10);
- break;
- case DBVT_DWORD: //'d' dVal and lVal are valid
- if (bPrependType)
- *ptr++ = 'd';
- _itoa(_dbvUID.dVal, ptr, 10);
- break;
- case DBVT_WCHAR: //'u' pwszVal is valid
- r = mir_utf8encodeW(_dbvUID.pwszVal);
- if (r == nullptr)
- return nullptr;
- if (bPrependType == FALSE)
- return r;
+ case DBVT_BYTE: //'b' bVal and cVal are valid
+ if (bPrependType)
+ *ptr++ = 'b';
+ _itoa(_dbvUID.bVal, ptr, 10);
+ break;
+ case DBVT_WORD: //'w' wVal and sVal are valid
+ if (bPrependType)
+ *ptr++ = 'w';
+ _itoa(_dbvUID.wVal, ptr, 10);
+ break;
+ case DBVT_DWORD: //'d' dVal and lVal are valid
+ if (bPrependType)
+ *ptr++ = 'd';
+ _itoa(_dbvUID.dVal, ptr, 10);
+ break;
+ case DBVT_WCHAR: //'u' pwszVal is valid
+ r = mir_utf8encodeW(_dbvUID.pwszVal);
+ if (r == nullptr)
+ return nullptr;
+ if (bPrependType == FALSE)
+ return r;
+ *ptr++ = 'u';
+ mir_strncpy(ptr, r, sizeof(szUID) - 1);
+ mir_free(r);
+ break;
+ case DBVT_UTF8: //'u' pszVal is valid
+ if (bPrependType)
*ptr++ = 'u';
- mir_strncpy(ptr, r, sizeof(szUID) - 1);
- mir_free(r);
- break;
- case DBVT_UTF8: //'u' pszVal is valid
- if (bPrependType)
- *ptr++ = 'u';
- mir_strncpy(ptr, _dbvUID.pszVal, sizeof(szUID) - 1);
- break;
- case DBVT_ASCIIZ:
- r = mir_utf8encode(_dbvUID.pszVal);
+ mir_strncpy(ptr, _dbvUID.pszVal, sizeof(szUID) - 1);
+ break;
+ case DBVT_ASCIIZ:
+ r = mir_utf8encode(_dbvUID.pszVal);
+ if (r == nullptr)
+ return nullptr;
+ if (bPrependType == FALSE)
+ return r;
+ *ptr++ = 's';
+ mir_strncpy(ptr, r, sizeof(szUID) - 1);
+ mir_free(r);
+ break;
+ case DBVT_BLOB: //'n' cpbVal and pbVal are valid
+ if (bPrependType) { //True = XML
+ baselen = mir_base64_encode_bufsize(_dbvUID.cpbVal);
+ r = (LPSTR)mir_alloc((baselen + 8));
if (r == nullptr)
return nullptr;
- if (bPrependType == FALSE)
- return r;
- *ptr++ = 's';
- mir_strncpy(ptr, r, sizeof(szUID) - 1);
- mir_free(r);
- break;
- case DBVT_BLOB: //'n' cpbVal and pbVal are valid
- if (bPrependType) { //True = XML
- baselen = mir_base64_encode_bufsize(_dbvUID.cpbVal);
- r = (LPSTR)mir_alloc((baselen + 8));
- if (r == nullptr)
- return nullptr;
- memset((r + baselen), 0, 8);
- ptr = r;
- if (bPrependType) { // Allways true.
- ptr[0] = 'n';
- ptr ++;
- }
- if (!mir_base64_encodebuf(_dbvUID.pbVal, _dbvUID.cpbVal, ptr, baselen)) {
- mir_free(r);
- return nullptr;
- }
- return r;
+ memset((r + baselen), 0, 8);
+ ptr = r;
+ if (bPrependType) { // Allways true.
+ ptr[0] = 'n';
+ ptr++;
}
- else { //FALSE = INI
- baselen = ((_dbvUID.cpbVal * 3) + 8);
- r = (LPSTR)mir_alloc(baselen);
- if (r == nullptr)
- return nullptr;
- memset(r, 0, baselen);
- ptr = r;
- for (SIZE_T j = 0; j < _dbvUID.cpbVal; j ++, ptr += 3) {
- mir_snprintf(ptr, ((r + baselen) - ptr), "%02X ", (BYTE)_dbvUID.pbVal[j]);
- }
- return r;
+ if (!mir_base64_encodebuf(_dbvUID.pbVal, _dbvUID.cpbVal, ptr, baselen)) {
+ mir_free(r);
+ return nullptr;
}
- break;
- default:
- return nullptr;
+ return r;
+ }
+ else { //FALSE = INI
+ baselen = ((_dbvUID.cpbVal * 3) + 8);
+ r = (LPSTR)mir_alloc(baselen);
+ if (r == nullptr)
+ return nullptr;
+ memset(r, 0, baselen);
+ ptr = r;
+ for (SIZE_T j = 0; j < _dbvUID.cpbVal; j++, ptr += 3) {
+ mir_snprintf(ptr, ((r + baselen) - ptr), "%02X ", (BYTE)_dbvUID.pbVal[j]);
+ }
+ return r;
+ }
+ break;
+ default:
+ return nullptr;
}
return mir_strdup(szUID);
}
@@ -466,18 +470,18 @@ BYTE CExImContactBase::isHandle(MCONTACT hContact)
// compare uids
if (_pszUIDKey) {
// get uid
- if (DB::Setting::GetAsIs(hContact, pszProto,_pszUIDKey, &dbv))
+ if (DB::Setting::GetAsIs(hContact, pszProto, _pszUIDKey, &dbv))
return FALSE;
- isEqual = compareUID (&dbv);
+ isEqual = compareUID(&dbv);
db_free(&dbv);
}
// compare nicknames if no UID
else if (!DB::Setting::GetUString(hContact, _pszProto, SET_CONTACT_NICK, &dbv)) {
- if (dbv.type == DBVT_UTF8 && dbv.pszVal && !mir_strcmpi(dbv.pszVal,_pszNick)) {
+ if (dbv.type == DBVT_UTF8 && dbv.pszVal && !mir_strcmpi(dbv.pszVal, _pszNick)) {
LPTSTR ptszNick = mir_utf8decodeW(_pszNick);
LPTSTR ptszProto = mir_a2u(_pszProto);
- int ans = MsgBox(nullptr, MB_ICONQUESTION|MB_YESNO, LPGENW("Question"), LPGENW("contact identification"),
+ int ans = MsgBox(nullptr, MB_ICONQUESTION | MB_YESNO, LPGENW("Question"), LPGENW("contact identification"),
LPGENW("The contact %s(%s) has no unique ID in the vCard,\nbut there is a contact in your contact list with the same nick and protocol.\nDo you wish to use this contact?"),
ptszNick, ptszProto);
MIR_FREE(ptszNick);
@@ -497,6 +501,7 @@ BYTE CExImContactBase::isHandle(MCONTACT hContact)
* param: none
* return: handle if successful, INVALID_HANDLE_VALUE otherwise
**/
+
MCONTACT CExImContactBase::findHandle()
{
for (auto &hContact : Contacts()) {