From 25ec54ea27a7099f33573b260a620ed7273176fe Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 30 Jun 2013 12:16:44 +0000 Subject: - db_set_blob used everywhere for writing blobs - DBCONTACTWRITESETTING left only in the event handlers git-svn-id: http://svn.miranda-ng.org/main/trunk@5191 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../src/ex_import/classExImContactBase.cpp | 7 +- .../src/ex_import/classExImContactXML.cpp | 97 ++++++++++------------ plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp | 40 +++++---- 3 files changed, 65 insertions(+), 79 deletions(-) (limited to 'plugins/UserInfoEx/src/ex_import') diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp index 77ae97f992..ffbce296e9 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp @@ -245,8 +245,6 @@ BYTE CExImContactBase::fromIni(LPSTR& row) **/ HANDLE CExImContactBase::toDB() { - DBCONTACTWRITESETTING cws; - // create new contact if none exists if (_hContact == INVALID_HANDLE_VALUE && _pszProto && _pszUIDKey && _dbvUID.type != DBVT_DELETED) { PROTOACCOUNT* pszAccount = 0; @@ -271,10 +269,7 @@ HANDLE CExImContactBase::toDB() return INVALID_HANDLE_VALUE; } // write uid to protocol module - cws.szModule = _pszProto; - cws.szSetting = _pszUIDKey; - cws.value = _dbvUID; - if (CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)_hContact, (LPARAM)&cws)) { + if (db_set(_hContact, _pszProto, _pszUIDKey, &_dbvUID)) { DB::Contact::Delete(_hContact); _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp index e17d64f7c7..78d81fdbf6 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp @@ -964,78 +964,71 @@ int CExImContactXML::ImportModule(TiXmlNode* xmlModule) **/ int CExImContactXML::ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry) { - DBCONTACTWRITESETTING cws = {0}; - TiXmlText* xval; - LPCSTR value; - // validate parameter if (!xmlEntry || !pszModule || !*pszModule) return ERROR_INVALID_PARAMS; // validate value - xval = (TiXmlText*)xmlEntry->FirstChild(); + TiXmlText* xval = (TiXmlText*)xmlEntry->FirstChild(); if (!xval || xval->Type() != TiXmlText::TEXT) return ERROR_INVALID_VALUE; - value = xval->Value(); - // init write structure - cws.szModule = (LPSTR)pszModule; - cws.szSetting = xmlEntry->Attribute("key"); + LPCSTR value = xval->Value(); + DBVARIANT dbv = { 0 }; // convert data size_t len = 0; INT_PTR baselen = NULL; switch (value[0]) { - case 'b': //'b' bVal and cVal are valid - cws.value.type = DBVT_BYTE; - cws.value.bVal = (BYTE)atoi(value + 1); - break; - case 'w': //'w' wVal and sVal are valid - cws.value.type = DBVT_WORD; - cws.value.wVal = (WORD)atoi(value + 1); - break; - case 'd': //'d' dVal and lVal are valid - cws.value.type = DBVT_DWORD; - cws.value.dVal = (DWORD)_atoi64(value + 1); -// cws.value.dVal = (DWORD)atoi(value + 1); - break; - case 's': //'s' pszVal is valid - cws.value.type = DBVT_ASCIIZ; - cws.value.pszVal = (LPSTR)mir_utf8decodeA((LPSTR)(value + 1)); - break; - case 'u': - cws.value.type = DBVT_UTF8; - cws.value.pszVal = (LPSTR)mir_strdup((LPSTR)(value + 1)); - break; - case 'n': - len = strlen(value + 1); - baselen = Base64DecodeGetRequiredLength(len); - cws.value.type = DBVT_BLOB; - cws.value.pbVal = (PBYTE)mir_alloc(baselen +1); - if (cws.value.pbVal != NULL){ - if (Base64Decode((value + 1), len, cws.value.pbVal, &baselen)) { - cws.value.cpbVal = baselen; - } - else { - mir_free(cws.value.pbVal); - return ERROR_NOT_ADDED; - } + case 'b': //'b' bVal and cVal are valid + dbv.type = DBVT_BYTE; + dbv.bVal = (BYTE)atoi(value + 1); + break; + case 'w': //'w' wVal and sVal are valid + dbv.type = DBVT_WORD; + dbv.wVal = (WORD)atoi(value + 1); + break; + case 'd': //'d' dVal and lVal are valid + dbv.type = DBVT_DWORD; + dbv.dVal = (DWORD)_atoi64(value + 1); + break; + case 's': //'s' pszVal is valid + dbv.type = DBVT_ASCIIZ; + dbv.pszVal = (LPSTR)mir_utf8decodeA((LPSTR)(value + 1)); + break; + case 'u': + dbv.type = DBVT_UTF8; + dbv.pszVal = (LPSTR)mir_strdup((LPSTR)(value + 1)); + break; + case 'n': + len = strlen(value + 1); + baselen = Base64DecodeGetRequiredLength(len); + dbv.type = DBVT_BLOB; + dbv.pbVal = (PBYTE)mir_alloc(baselen +1); + if (dbv.pbVal != NULL){ + if (Base64Decode((value + 1), len, dbv.pbVal, &baselen)) + dbv.cpbVal = baselen; + else { + mir_free(dbv.pbVal); + return ERROR_NOT_ADDED; } - break; - default: - return ERROR_INVALID_TYPE; + } + break; + default: + return ERROR_INVALID_TYPE; } + // write value to db - if (CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)_hContact, (LPARAM)&cws)) { + if (db_set(_hContact, pszModule, xmlEntry->Attribute("key"), &dbv)) { //if (cws.value.pbVal>0) - mir_free(cws.value.pbVal); - if (cws.value.type == DBVT_ASCIIZ || cws.value.type == DBVT_UTF8) mir_free(cws.value.pszVal); + mir_free(dbv.pbVal); + if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) mir_free(dbv.pszVal); return ERROR_NOT_ADDED; } - //if (cws.value.pbVal>0) - mir_free(cws.value.pbVal); - if (cws.value.type == DBVT_ASCIIZ || cws.value.type == DBVT_UTF8) mir_free(cws.value.pszVal); + //if (dbv.pbVal>0) + mir_free(dbv.pbVal); + if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) mir_free(dbv.pszVal); return ERROR_OK; } diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp index f8b5fbc3ae..1949ae96f0 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp @@ -324,7 +324,7 @@ static HANDLE ImportFindContact(HANDLE hContact, LPSTR &strBuf, BYTE bCanCreate) **/ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) { - DBCONTACTWRITESETTING cws; + DBVARIANT dbv; LPSTR end, value; size_t numLines = 0; size_t brk; @@ -341,10 +341,8 @@ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) if (end == pszLine) return 1; *(end--) = 0; - } while (*end == '\t' || *end == ' ' || *end < 27); - - cws.szModule = pszModule; - cws.szSetting = pszLine; + } + while (*end == '\t' || *end == ' ' || *end < 27); // skip spaces from the beginning of the value do { @@ -360,22 +358,22 @@ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) case 'B': if (brk = strspn(value, "0123456789-")) *(value + brk) = 0; - cws.value.type = DBVT_BYTE; - cws.value.bVal = (BYTE)atoi(value); + dbv.type = DBVT_BYTE; + dbv.bVal = (BYTE)atoi(value); break; case 'w': case 'W': if (brk = strspn(value, "0123456789-")) *(value + brk) = 0; - cws.value.type = DBVT_WORD; - cws.value.wVal = (WORD)atoi(value); + dbv.type = DBVT_WORD; + dbv.wVal = (WORD)atoi(value); break; case 'd': case 'D': if (brk = strspn(value, "0123456789-")) *(value + brk) = 0; - cws.value.type = DBVT_DWORD; - cws.value.dVal = (DWORD)_atoi64(value); + dbv.type = DBVT_DWORD; + dbv.dVal = (DWORD)_atoi64(value); break; case 's': case 'S': @@ -396,13 +394,13 @@ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) switch (*(value - 1)) { case 's': case 'S': - cws.value.type = DBVT_ASCIIZ; - cws.value.pszVal = value; + dbv.type = DBVT_ASCIIZ; + dbv.pszVal = value; break; case 'u': case 'U': - cws.value.type = DBVT_UTF8; - cws.value.pszVal = value; + dbv.type = DBVT_UTF8; + dbv.pszVal = value; break; } break; @@ -410,10 +408,10 @@ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) case 'N': { PBYTE dest; - cws.value.type = DBVT_BLOB; - cws.value.cpbVal = (WORD)mir_strlen(value) / 3; - cws.value.pbVal = (PBYTE)value; - for ( dest = cws.value.pbVal, value = strtok(value, " "); + dbv.type = DBVT_BLOB; + dbv.cpbVal = (WORD)mir_strlen(value) / 3; + dbv.pbVal = (PBYTE)value; + for ( dest = dbv.pbVal, value = strtok(value, " "); value && *value; value = strtok(NULL, " ")) *(dest++) = (BYTE)strtol(value, NULL, 16); @@ -421,10 +419,10 @@ int ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine) break; } default: - cws.value.type = DBVT_DELETED; + dbv.type = DBVT_DELETED; //return 1; } - return CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (LPARAM)&cws); + return db_set(hContact, pszModule, pszLine, &dbv); } /** -- cgit v1.2.3