summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-06-30 12:16:44 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-06-30 12:16:44 +0000
commit25ec54ea27a7099f33573b260a620ed7273176fe (patch)
tree1810a0cb35d23deeed9ccdaf0ab276a4022f9a41 /plugins/UserInfoEx/src
parenta546606709e6bb72e01eb38b2c8c8756608fd5d6 (diff)
- 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
Diffstat (limited to 'plugins/UserInfoEx/src')
-rw-r--r--plugins/UserInfoEx/src/ctrl_edit.cpp2
-rw-r--r--plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp7
-rw-r--r--plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp97
-rw-r--r--plugins/UserInfoEx/src/ex_import/svc_ExImINI.cpp40
-rw-r--r--plugins/UserInfoEx/src/mir_db.cpp20
-rw-r--r--plugins/UserInfoEx/src/mir_db.h6
6 files changed, 66 insertions, 106 deletions
diff --git a/plugins/UserInfoEx/src/ctrl_edit.cpp b/plugins/UserInfoEx/src/ctrl_edit.cpp
index 947bb68c19..2d25aa7213 100644
--- a/plugins/UserInfoEx/src/ctrl_edit.cpp
+++ b/plugins/UserInfoEx/src/ctrl_edit.cpp
@@ -208,7 +208,7 @@ void CEditCtrl::OnApply(HANDLE hContact, LPCSTR pszProto)
}
if (dbv.type != DBVT_DELETED)
{
- if (!DB::Setting::WriteVariant(hContact, pszModule, _pszSetting, &dbv))
+ if (!db_set(hContact, pszModule, _pszSetting, &dbv))
{
if (!hContact)
{
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);
}
/**
diff --git a/plugins/UserInfoEx/src/mir_db.cpp b/plugins/UserInfoEx/src/mir_db.cpp
index e40855b24b..fcd347e373 100644
--- a/plugins/UserInfoEx/src/mir_db.cpp
+++ b/plugins/UserInfoEx/src/mir_db.cpp
@@ -466,26 +466,6 @@ BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszVa
}
/**
- * This function calls MS_DB_CONTACT_WRITESETTING to write a DBVARIANT structure to the database.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to write
- * @param dbv - the DBVARIANT to store
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
-BYTE WriteVariant(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, const DBVARIANT *dbv)
-{
- DBCONTACTWRITESETTING cws;
-
- cws.szModule = pszModule;
- cws.szSetting = pszSetting;
- memcpy(&cws.value, dbv, sizeof(DBVARIANT));
- return CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM) hContact, (LPARAM) &cws) != 0;
-}
-
-/**
* This function checks for the existence of the given setting in the database
* @param hContact - handle to the contact
* @param pszModule - the module to read the setting from (e.g. USERINFO)
diff --git a/plugins/UserInfoEx/src/mir_db.h b/plugins/UserInfoEx/src/mir_db.h
index be4248bebf..ed60f07b90 100644
--- a/plugins/UserInfoEx/src/mir_db.h
+++ b/plugins/UserInfoEx/src/mir_db.h
@@ -97,17 +97,11 @@ namespace Setting {
BYTE GetStatic (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR szValue, int cchValue);
- /**
- * write values to the database.
- **/
- BYTE WriteVariant (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, const DBVARIANT *dbv);
-
#define GetTString GetWString
#define GetTStringEx GetWStringEx
#define GetTStringCtrl GetWStringCtrl
#define WriteTString WriteWString
-
/**
* misc operations
**/