From e84b97a0622a26fe474ccd840dcadb320520601c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 3 Feb 2014 20:11:26 +0000 Subject: - new helpers for reading db strings into static buffers; - MS_DB_CONTACT_GETSETTINGSTATIC died; - DBCONTACTGETSETTING is detouched from all services; - these service calls are rewritten using parameters git-svn-id: http://svn.miranda-ng.org/main/trunk@8035 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/delphi/m_core.inc | 7 +++++ include/delphi/m_database.inc | 53 +++++++++++--------------------- include/m_core.h | 70 +++++++++++++++++++++++-------------------- include/m_database.h | 27 ----------------- include/m_db_int.h | 8 ++--- 5 files changed, 66 insertions(+), 99 deletions(-) (limited to 'include') diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index b02b09e61d..79bbe29b3f 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -280,6 +280,13 @@ function db_get_sa(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:p function db_get_wsa(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar):pWideChar; stdcall; external CoreDLL name 'db_get_wsa'; +function db_get_static(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar; szDest:pAnsiChar; destLen:int):int; stdcall; + external CoreDLL name 'db_get_static'; +function db_get_static_utf(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar; szDest:pAnsiChar; destLen:int):int; stdcall; + external CoreDLL name 'db_get_static_utf'; +function db_get_wstatic(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar; szDest:pWideChar; destLen:int):int; stdcall; + external CoreDLL name 'db_get_wstatic'; + function db_set(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar; dbv:PDBVARIANT):int_ptr; stdcall; external CoreDLL name 'db_set'; function db_set_b(hContact:THANDLE; const szModule:pAnsiChar; const szSetting:pAnsiChar; val:byte):int_ptr; stdcall; diff --git a/include/delphi/m_database.inc b/include/delphi/m_database.inc index ce6b56ac6e..f02c506806 100644 --- a/include/delphi/m_database.inc +++ b/include/delphi/m_database.inc @@ -58,44 +58,25 @@ type value : TDBVARIANT; // variant containing value to set end; -const - { - wParam : Handle for a contact to query a setting for - lParam : Pointer to a TDBCONTACTGETSETTING structure - affects: This service is almost the same as the one above, but it does - not return a dynamic copy (with malloc()) -- the caller - must do this for datatypes which require it, e.g. a string. - - This means the TDBCONTACTGETSETTING.pValue *has* to exist and be - allocated by the caller (doesn't have to be allocated from the heap) - the DBVARIANT structure has to be initalised with the type wanted - and enough buffer space around to return the info, do not - expect this service to be as fast as the one above. - - returns: 0 on success, non zero on failure. + wParam : Handle of a contact to enum settings for + lParam : Pointer to a TDBCONTACTENUMSETTINGS structure, must be initalised + affect : Enumerates all settings for a given contact under a module, + TDBCONTACTENUMSETTINGS must be filled with the function pointer to call + the TDBCONTACTENUMSETTINGS.lParam value to pass to it each time, + as well as the .szModule under which the contact is valid + returns: returns the value of the last call to the enum function, or -1 + if no settings could be enumerated + notes : the szSetting argument passed to the enumeration function is only + valid for the duration of that enumeration call, + it must be allocated dynamically if it is required after that call frame + has returned. + Also, deleting settings as they are enumerated has unpredictable results! + but writing a new value for a setting is okay. + it is unclear how you stop the enumeration once it is started, maybe + possible to return -1 to stop it. + vesion : only valid for 0.1.0.1+ } - MS_DB_CONTACT_GETSETTINGSTATIC:PAnsiChar = 'DB/Contact/GetSettingStatic'; - - { - wParam : Handle of a contact to enum settings for - lParam : Pointer to a TDBCONTACTENUMSETTINGS structure, must be initalised - affect : Enumerates all settings for a given contact under a module, - TDBCONTACTENUMSETTINGS must be filled with the function pointer to call - the TDBCONTACTENUMSETTINGS.lParam value to pass to it each time, - as well as the .szModule under which the contact is valid - returns: returns the value of the last call to the enum function, or -1 - if no settings could be enumerated - notes : the szSetting argument passed to the enumeration function is only - valid for the duration of that enumeration call, - it must be allocated dynamically if it is required after that call frame - has returned. - Also, deleting settings as they are enumerated has unpredictable results! - but writing a new value for a setting is okay. - it is unclear how you stop the enumeration once it is started, maybe - possible to return -1 to stop it. - vesion : only valid for 0.1.0.1+ - } type TDBSETTINGENUMPROC = function(const szSetting: PAnsiChar; lParam: LPARAM): int; cdecl; diff --git a/include/m_core.h b/include/m_core.h index c6c4368cb6..b6ef9ffb1d 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -284,47 +284,53 @@ MIR_CORE_DLL(HANDLE) db_event_prev(HANDLE hDbEvent); * DATABASE SETTINGS */ -MIR_CORE_DLL(INT_PTR) db_get(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv); -MIR_CORE_DLL(int) db_get_b(HANDLE hContact, const char *szModule, const char *szSetting, int errorValue); -MIR_CORE_DLL(int) db_get_w(HANDLE hContact, const char *szModule, const char *szSetting, int errorValue); -MIR_CORE_DLL(DWORD) db_get_dw(HANDLE hContact, const char *szModule, const char *szSetting, DWORD errorValue); -MIR_CORE_DLL(char*) db_get_sa(HANDLE hContact, const char *szModule, const char *szSetting); -MIR_CORE_DLL(WCHAR*) db_get_wsa(HANDLE hContact, const char *szModule, const char *szSetting); +MIR_CORE_DLL(INT_PTR) db_get(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv); +MIR_CORE_DLL(int) db_get_b(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, int errorValue); +MIR_CORE_DLL(int) db_get_w(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, int errorValue); +MIR_CORE_DLL(DWORD) db_get_dw(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DWORD errorValue); +MIR_CORE_DLL(char*) db_get_sa(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting); +MIR_CORE_DLL(WCHAR*) db_get_wsa(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting); + +MIR_CORE_DLL(int) db_get_static(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, char *pDest, int cbDest); +MIR_CORE_DLL(int) db_get_static_utf(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, char *pDest, int cbDest); +MIR_CORE_DLL(int) db_get_wstatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, WCHAR *pDest, int cbDest); #if defined(__cplusplus) - MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv, const int nType=DBVT_ASCIIZ); + MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, const int nType=DBVT_ASCIIZ); #else - MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv, const int nType); + MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, const int nType); #endif -MIR_CORE_DLL(INT_PTR) db_set(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv); -MIR_CORE_DLL(INT_PTR) db_set_b(HANDLE hContact, const char *szModule, const char *szSetting, BYTE val); -MIR_CORE_DLL(INT_PTR) db_set_w(HANDLE hContact, const char *szModule, const char *szSetting, WORD val); -MIR_CORE_DLL(INT_PTR) db_set_dw(HANDLE hContact, const char *szModule, const char *szSetting, DWORD val); -MIR_CORE_DLL(INT_PTR) db_set_s(HANDLE hContact, const char *szModule, const char *szSetting, const char *val); -MIR_CORE_DLL(INT_PTR) db_set_ws(HANDLE hContact, const char *szModule, const char *szSetting, const WCHAR *val); -MIR_CORE_DLL(INT_PTR) db_set_utf(HANDLE hContact, const char *szModule, const char *szSetting, const char *val); -MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, const char *szModule, const char *szSetting, void *val, unsigned len); +MIR_CORE_DLL(INT_PTR) db_set(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv); +MIR_CORE_DLL(INT_PTR) db_set_b(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, BYTE val); +MIR_CORE_DLL(INT_PTR) db_set_w(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, WORD val); +MIR_CORE_DLL(INT_PTR) db_set_dw(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DWORD val); +MIR_CORE_DLL(INT_PTR) db_set_s(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, LPCSTR val); +MIR_CORE_DLL(INT_PTR) db_set_ws(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, LPCWSTR val); +MIR_CORE_DLL(INT_PTR) db_set_utf(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, LPCSTR val); +MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, void *val, unsigned len); -MIR_CORE_DLL(INT_PTR) db_unset(HANDLE hContact, const char *szModule, const char *szSetting); +MIR_CORE_DLL(INT_PTR) db_unset(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting); #if defined(__cplusplus) - MIR_CORE_DLL(BOOL) db_set_resident(const char *szModule, const char *szService, BOOL bEnable=TRUE); + MIR_CORE_DLL(BOOL) db_set_resident(LPCSTR szModule, const char *szService, BOOL bEnable=TRUE); #else - MIR_CORE_DLL(BOOL) db_set_resident(const char *szModule, const char *szService, BOOL bEnable); + MIR_CORE_DLL(BOOL) db_set_resident(LPCSTR szModule, const char *szService, BOOL bEnable); #endif -#define db_get_ws(a,b,c,d) db_get_s(a,b,c,d,DBVT_WCHAR) -#define db_get_utf(a,b,c,d) db_get_s(a,b,c,d,DBVT_UTF8) +#define db_get_ws(a,b,c,d) db_get_s(a,b,c,d,DBVT_WCHAR) +#define db_get_utf(a,b,c,d) db_get_s(a,b,c,d,DBVT_UTF8) #ifdef _UNICODE - #define db_get_ts(a,b,c,d) db_get_s(a,b,c,d,DBVT_WCHAR) - #define db_get_tsa db_get_wsa - #define db_set_ts db_set_ws + #define db_get_ts(a,b,c,d) db_get_s(a,b,c,d,DBVT_WCHAR) + #define db_get_tsa db_get_wsa + #define db_set_ts db_set_ws + #define db_get_tstatic db_get_wstatic #else - #define db_get_ts(a,b,c,d) db_get_s(a,b,c,d,DBVT_ASCIIZ) - #define db_get_tsa db_get_sa - #define db_set_ts db_set_s + #define db_get_ts(a,b,c,d) db_get_s(a,b,c,d,DBVT_ASCIIZ) + #define db_get_tsa db_get_sa + #define db_set_ts db_set_s + #define db_get_tstatic db_get_static #endif /////////////////////////////////////////////////////////////////////////////// @@ -380,10 +386,10 @@ MIR_CORE_DLL(void) KillObjectServices(void* pObject); #if defined(_STATIC) __declspec(dllexport) INT_PTR CallContactService(HANDLE, const char *, WPARAM, LPARAM); -__declspec(dllexport) INT_PTR CallProtoService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam); +__declspec(dllexport) INT_PTR CallProtoService(LPCSTR szModule, const char *szService, WPARAM wParam, LPARAM lParam); #else MIR_C_CORE_DLL(INT_PTR) CallContactService(HANDLE, const char *, WPARAM, LPARAM); -MIR_C_CORE_DLL(INT_PTR) CallProtoService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam); +MIR_C_CORE_DLL(INT_PTR) CallProtoService(LPCSTR szModule, const char *szService, WPARAM wParam, LPARAM lParam); #endif /////////////////////////////////////////////////////////////////////////////// @@ -603,9 +609,9 @@ MIR_CORE_DLL(int) mir_vsnwprintf(WCHAR *buffer, size_t count, const WCHAR* fm /////////////////////////////////////////////////////////////////////////////// // protocol functions -MIR_CORE_DLL(INT_PTR) ProtoCallService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam); -MIR_CORE_DLL(int) ProtoServiceExists(const char *szModule, const char *szService); -MIR_CORE_DLL(INT_PTR) ProtoBroadcastAck(const char *szModule, HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam); +MIR_CORE_DLL(INT_PTR) ProtoCallService(LPCSTR szModule, const char *szService, WPARAM wParam, LPARAM lParam); +MIR_CORE_DLL(int) ProtoServiceExists(LPCSTR szModule, const char *szService); +MIR_CORE_DLL(INT_PTR) ProtoBroadcastAck(LPCSTR szModule, HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam); // Call it in the very beginning of your proto's constructor MIR_CORE_DLL(void) ProtoConstructor(struct PROTO_INTERFACE *pThis, const char *pszModuleName, const TCHAR *ptszUserName); diff --git a/include/m_database.h b/include/m_database.h index d017bd1cd4..b69663387e 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -155,33 +155,6 @@ typedef struct { DBVARIANT value; // variant containing the value to set } DBCONTACTWRITESETTING; -/* DB/Contact/GetSettingStatic service -Look up the value of a named setting for a specific contact in the database - wParam = (WPARAM)(HANDLE)hContact - lParam = (LPARAM)(DBCONTACTGETSETTING*)&dbcgs -hContact should have been returned by find*contact or addcontact -This service differs from db/contact/getsetting in that it won't malloc() -memory for the return value if it needs to do so. This introduces some extra -constraints: -Upon calling dbcgs.pValue->type should be initialised to the expected type of -the setting. If the setting is of an integral type it won't matter if it's -wrong and the service will correct it before returning, however if the setting -is a string or a blob the service needs to know where to put the data and will -fail if type is set wrongly. -If dbcgs.pValue->type is DBVT_ASCIIZ or DBVT_BLOB upon calling, the -corresponding data field (pszVal or pbVal) must point to a buffer allocated by -the caller and the length field (cchVal or cpbVal) must contain the size of -that buffer in bytes. -If the setting type is variable length (DBVT_ASCIIZ or DBVT_BLOB), on exit the -length field (cchVal or cpbVal) will be filled with the full length of the -setting's value (excluding the terminating nul if it's DBVT_ASCIIZ). -This service exists as well as db/contact/getsetting because malloc()/free() -can be too slow for frequently queried settings. -Returns 0 on success or nonzero if the setting name was not found or hContact -was invalid. -*/ -#define MS_DB_CONTACT_GETSETTINGSTATIC "DB/Contact/GetSettingStatic" - /* db/contact/enumsettings v0.1.0.1+ Lists all the settings a specific modules has stored in the database for a specific contact. diff --git a/include/m_db_int.h b/include/m_db_int.h index dbaaa77076..8d7adfa9b6 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -94,12 +94,12 @@ interface MIDatabase STDMETHOD_(BOOL,EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE; - STDMETHOD_(BOOL,GetContactSetting)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE; - STDMETHOD_(BOOL,GetContactSettingStr)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE; - STDMETHOD_(BOOL,GetContactSettingStatic)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE; + STDMETHOD_(BOOL,GetContactSetting)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL,GetContactSettingStr)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; + STDMETHOD_(BOOL,GetContactSettingStatic)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE; STDMETHOD_(BOOL,FreeVariant)(DBVARIANT *dbv) PURE; STDMETHOD_(BOOL,WriteContactSetting)(HANDLE hContact, DBCONTACTWRITESETTING *dbcws) PURE; - STDMETHOD_(BOOL,DeleteContactSetting)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE; + STDMETHOD_(BOOL,DeleteContactSetting)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting) PURE; STDMETHOD_(BOOL,EnumContactSettings)(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces) PURE; STDMETHOD_(BOOL,SetSettingResident)(BOOL bIsResident, const char *pszSettingName) PURE; STDMETHOD_(BOOL,EnumResidentSettings)(DBMODULEENUMPROC pFunc, void *pParam) PURE; -- cgit v1.2.3