diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/delphi/m_clistint.inc | 18 | ||||
-rw-r--r-- | include/delphi/m_protocols.inc | 1 | ||||
-rw-r--r-- | include/delphi/m_protomod.inc | 15 | ||||
-rw-r--r-- | include/m_plugin.h | 258 | ||||
-rw-r--r-- | include/m_protocols.h | 31 | ||||
-rw-r--r-- | include/newpluginapi.h | 260 |
6 files changed, 274 insertions, 309 deletions
diff --git a/include/delphi/m_clistint.inc b/include/delphi/m_clistint.inc index 724ad30bf7..3ec038b04d 100644 --- a/include/delphi/m_clistint.inc +++ b/include/delphi/m_clistint.inc @@ -23,24 +23,6 @@ {$IFNDEF M_CLISTINT}
{$DEFINE M_CLISTINT}
-{Type
- P_menuProto = ^_menuProto;
- PClcCacheEntryBase = ^ClcCacheEntryBase;
- PClcContact = ^ClcContact;
- PClcData = ^ClcData;
- PClcFontInfo = ^ClcFontInfo;
- PClcGroup = ^ClcGroup;
- PClcProtoStatus = ^ClcProtoStatus;
- PCLIST_INTERFACE = ^CLIST_INTERFACE;
- PCListEvent = ^CListEvent;
- PCLCCacheEntry = ^CLCCacheEntry;
- PContactList = ^ContactList;
- PEventList = ^EventList;
- PMenuProto = ^MenuProto;
- PMIRANDASYSTRAYNOTIFY = ^MIRANDASYSTRAYNOTIFY;
- PPROTOCOLDESCRIPTOR = ^PROTOCOLDESCRIPTOR;
- PtrayIconInfo_t = ^trayIconInfo_t;
-}
const
HCONTACT_ISGROUP = $80000000;
HCONTACT_ISINFO = $FFFF0000;
diff --git a/include/delphi/m_protocols.inc b/include/delphi/m_protocols.inc index 713bbb031a..d7bf082421 100644 --- a/include/delphi/m_protocols.inc +++ b/include/delphi/m_protocols.inc @@ -157,7 +157,6 @@ type PPROTOCOLDESCRIPTOR = ^TPROTOCOLDESCRIPTOR;
PPPROTOCOLDESCRIPTOR = ^PPROTOCOLDESCRIPTOR;
TPROTOCOLDESCRIPTOR = record
- cbSize : size_t;
szName : PAnsiChar; // unique name of the module
_type : int; // module type, see PROTOTYPE_ constants
end;
diff --git a/include/delphi/m_protomod.inc b/include/delphi/m_protomod.inc index 416d5758e5..df9d30f2aa 100644 --- a/include/delphi/m_protomod.inc +++ b/include/delphi/m_protomod.inc @@ -39,8 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. be done for PROTOTYPE_PROTOCOL.
}
-function Proto_RegisterModule(descr:pPROTOCOLDESCRIPTOR) : int; stdcall;
- external AppDLL name 'Proto_RegisterModule';
+function Proto_RegisterModule(iType:int; name:PAnsiChar) : int; stdcall; external AppDLL;
{
Affect : Add the given protocol module to the chain for a contact, see notes
@@ -49,16 +48,14 @@ function Proto_RegisterModule(descr:pPROTOCOLDESCRIPTOR) : int; stdcall; registered type.
}
-function Proto_AddToContact(hContact:TMCONTACT; proto:PAnsiChar) : int; stdcall;
- external AppDLL name 'Proto_AddToContact';
+function Proto_AddToContact(hContact:TMCONTACT; proto:PAnsiChar) : int; stdcall; external AppDLL;
{
Affect : Remove the given protocol name from the chain for the given contact
Returns: 0 on success, [non zero] on failure
}
-function Proto_RemoveFromContact(hContact:TMCONTACT; proto:PAnsiChar) : int; stdcall;
- external AppDLL name 'Proto_RemoveFromContact';
+function Proto_RemoveFromContact(hContact:TMCONTACT; proto:PAnsiChar) : int; stdcall; external AppDLL;
{
Affect : Call the next service in the chain for the send operation, see notes
@@ -69,8 +66,7 @@ function Proto_RemoveFromContact(hContact:TMCONTACT; proto:PAnsiChar) : int; std typically your service should return ASAP.
}
-function Proto_ChainSend(order:int; ccs:pCCSDATA) : INT_PTR; stdcall;
- external AppDLL name 'Proto_ChainSend';
+function Proto_ChainSend(order:int; ccs:pCCSDATA) : INT_PTR; stdcall; external AppDLL;
{
Affect : Call the next service in the chain in this receive operation, see notes
@@ -84,7 +80,6 @@ function Proto_ChainSend(order:int; ccs:pCCSDATA) : INT_PTR; stdcall; are translated to the main thread and passed from there.
}
-function Proto_ChainRecv(order:int; ccs:pCCSDATA) : INT_PTR; stdcall;
- external AppDLL name 'Proto_ChainRecv';
+function Proto_ChainRecv(order:int; ccs:pCCSDATA) : INT_PTR; stdcall; external AppDLL;
{$ENDIF}
diff --git a/include/m_plugin.h b/include/m_plugin.h deleted file mode 100644 index 340b3100fe..0000000000 --- a/include/m_plugin.h +++ /dev/null @@ -1,258 +0,0 @@ -#pragma once - -#include <m_core.h> -#include <m_database.h> -#include <m_protocols.h> - -class MIR_APP_EXPORT CMPluginBase -{ - void tryOpenLog(); - -protected: - const char *m_szModuleName; - HANDLE m_hLogger = nullptr; - HINSTANCE m_hInst; - - CMPluginBase(const char *moduleName); - ~CMPluginBase(); - - // pass one of PROTOTYPE_* constants as type - void RegisterProtocol(int type, pfnInitProto = nullptr, pfnUninitProto = nullptr); - __forceinline void SetUniqueId(const char *pszUniqueId) - { - ::Proto_SetUniqueId(m_szModuleName, pszUniqueId); - } - -public: - void debugLogA(LPCSTR szFormat, ...); - void debugLogW(LPCWSTR wszFormat, ...); - - __forceinline HINSTANCE getInst() const { return m_hInst; } - __forceinline void setInst(HINSTANCE hInst) { m_hInst = hInst; } - - __forceinline INT_PTR delSetting(const char *name) - { - return db_unset(0, m_szModuleName, name); - } - __forceinline INT_PTR delSetting(MCONTACT hContact, const char *name) - { - return db_unset(hContact, m_szModuleName, name); - } - - __forceinline bool getBool(const char *name, bool defaultValue = false) - { - return db_get_b(0, m_szModuleName, name, defaultValue) != 0; - } - __forceinline bool getBool(MCONTACT hContact, const char *name, bool defaultValue = false) - { - return db_get_b(hContact, m_szModuleName, name, defaultValue) != 0; - } - - __forceinline int getByte(const char *name, BYTE defaultValue = 0) - { - return db_get_b(0, m_szModuleName, name, defaultValue); - } - __forceinline int getByte(MCONTACT hContact, const char *name, BYTE defaultValue = 0) - { - return db_get_b(hContact, m_szModuleName, name, defaultValue); - } - - __forceinline int getWord(const char *name, WORD defaultValue = 0) - { - return db_get_w(0, m_szModuleName, name, defaultValue); - } - __forceinline int getWord(MCONTACT hContact, const char *name, WORD defaultValue = 0) - { - return db_get_w(hContact, m_szModuleName, name, defaultValue); - } - - __forceinline DWORD getDword(const char *name, DWORD defaultValue = 0) - { - return db_get_dw(0, m_szModuleName, name, defaultValue); - } - __forceinline DWORD getDword(MCONTACT hContact, const char *name, DWORD defaultValue = 0) - { - return db_get_dw(hContact, m_szModuleName, name, defaultValue); - } - - __forceinline INT_PTR getString(const char *name, DBVARIANT *result) - { - return db_get_s(0, m_szModuleName, name, result); - } - __forceinline INT_PTR getString(MCONTACT hContact, const char *name, DBVARIANT *result) - { - return db_get_s(hContact, m_szModuleName, name, result); - } - - __forceinline INT_PTR getWString(const char *name, DBVARIANT *result) - { - return db_get_ws(0, m_szModuleName, name, result); - } - __forceinline INT_PTR getWString(MCONTACT hContact, const char *name, DBVARIANT *result) - { - return db_get_ws(hContact, m_szModuleName, name, result); - } - - __forceinline char* getStringA(const char *name) - { - return db_get_sa(0, m_szModuleName, name); - } - __forceinline char* getStringA(MCONTACT hContact, const char *name) - { - return db_get_sa(hContact, m_szModuleName, name); - } - - __forceinline wchar_t* getWStringA(const char *name) - { - return db_get_wsa(0, m_szModuleName, name); - } - __forceinline wchar_t* getWStringA(MCONTACT hContact, const char *name) - { - return db_get_wsa(hContact, m_szModuleName, name); - } - - __forceinline void setByte(const char *name, BYTE value) - { - db_set_b(0, m_szModuleName, name, value); - } - __forceinline void setByte(MCONTACT hContact, const char *name, BYTE value) - { - db_set_b(hContact, m_szModuleName, name, value); - } - - __forceinline void setWord(const char *name, WORD value) - { - db_set_w(0, m_szModuleName, name, value); - } - __forceinline void setWord(MCONTACT hContact, const char *name, WORD value) - { - db_set_w(hContact, m_szModuleName, name, value); - } - - __forceinline void setDword(const char *name, DWORD value) - { - db_set_dw(0, m_szModuleName, name, value); - } - __forceinline void setDword(MCONTACT hContact, const char *name, DWORD value) - { - db_set_dw(hContact, m_szModuleName, name, value); - } - - __forceinline void setString(const char *name, const char* value) - { - db_set_s(0, m_szModuleName, name, value); - } - __forceinline void setString(MCONTACT hContact, const char *name, const char* value) - { - db_set_s(hContact, m_szModuleName, name, value); - } - - __forceinline void setWString(const char *name, const wchar_t* value) - { - db_set_ws(0, m_szModuleName, name, value); - } - __forceinline void setWString(MCONTACT hContact, const char *name, const wchar_t* value) - { - db_set_ws(hContact, m_szModuleName, name, value); - } -}; - -extern struct CMPlugin g_plugin; - -///////////////////////////////////////////////////////////////////////////////////////// -// Basic class for plugins (not protocols) written in C++ - -typedef BOOL(WINAPI * const _pfnCrtInit)(HINSTANCE, DWORD, LPVOID); - -template<class T> class PLUGIN : public CMPluginBase -{ - typedef CMPluginBase CSuper; - -public: - static BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD, LPVOID) - { - g_plugin.setInst(hInstance); - return TRUE; - } - -protected: - PLUGIN(const char *moduleName) - : CSuper(moduleName) - {} - - __forceinline HANDLE CreatePluginEvent(const char *name) - { - CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name); - return CreateHookableEvent(str); - } - - typedef int(__cdecl T::*MyEventFunc)(WPARAM, LPARAM); - __forceinline void HookPluginEvent(const char *name, MyEventFunc pFunc) - { - HookEventObj(name, (MIRANDAHOOKOBJ)*(void**)&pFunc, this); - } - - typedef INT_PTR(__cdecl T::*MyServiceFunc)(WPARAM, LPARAM); - __forceinline void CreatePluginService(const char *name, MyServiceFunc pFunc) - { - CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name); - CreateServiceFunctionObj(str, (MIRANDASERVICEOBJ)*(void**)&pFunc, this); - } - - typedef INT_PTR(__cdecl T::*MyServiceFuncParam)(WPARAM, LPARAM, LPARAM); - __forceinline void CreatePluginServiceParam(const char *name, MyServiceFuncParam pFunc, LPARAM param) - { - CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name); - CreateServiceFunctionObjParam(str, (MIRANDASERVICEOBJPARAM)*(void**)&pFunc, this, param); - } -}; - -///////////////////////////////////////////////////////////////////////////////////////// -// Basic class for protocols with accounts - -struct CMPlugin; - -template<class P> class ACCPROTOPLUGIN : public PLUGIN<CMPlugin> -{ - typedef PLUGIN<CMPlugin> CSuper; - -protected: - ACCPROTOPLUGIN(const char *moduleName) : - CSuper(moduleName) - { - CMPluginBase::RegisterProtocol(PROTOTYPE_PROTOCOL, &fnInit, &fnUninit); - } - - static PROTO_INTERFACE* fnInit(const char *szModuleName, const wchar_t *wszAccountName) - { - P *ppro = new P(szModuleName, wszAccountName); - g_arInstances.insert(ppro); - return ppro; - } - - static int fnUninit(PROTO_INTERFACE *ppro) - { - g_arInstances.remove((P*)ppro); - return 0; - } - -public: - static OBJLIST<P> g_arInstances; - - static P* getInstance(const char *szProto) - { - for (auto &it : g_arInstances) - if (mir_strcmp(szProto, it->m_szModuleName) == 0) - return it; - - return nullptr; - } - - static P* getInstance(MCONTACT hContact) - { - return getInstance(::GetContactProto(hContact)); - } -}; - -template<class P> -OBJLIST<P> ACCPROTOPLUGIN<P>::g_arInstances(1, PtrKeySortT); diff --git a/include/m_protocols.h b/include/m_protocols.h index db32e1f94a..ff364d3e7e 100644 --- a/include/m_protocols.h +++ b/include/m_protocols.h @@ -126,8 +126,6 @@ struct PROTOFILETRANSFERSTATUS uint64_t currentFileTime; // as seconds since 1970
};
-#define PROTOCOLDESCRIPTOR_V3_SIZE (sizeof(size_t)+sizeof(INT_PTR)+sizeof(char*))
-
/////////////////////////////////////////////////////////////////////////////////////////
// For recv, it will go from lower to higher, so in this case:
// check ignore, decrypt (encryption), translate
@@ -137,30 +135,19 @@ struct PROTOFILETRANSFERSTATUS // The DB will store higher numbers here, LOWER in the protocol chain, and lower numbers
// here HIGHER in the protocol chain
-#define PROTOTYPE_IGNORE 50 // added during v0.3.3
-#define PROTOTYPE_PROTOCOL 1000
-#define PROTOTYPE_VIRTUAL 1001 // virtual protocol (has no accounts)
-#define PROTOTYPE_ENCRYPTION 2000
-#define PROTOTYPE_FILTER 3000
-#define PROTOTYPE_TRANSLATION 4000
-#define PROTOTYPE_OTHER 10000 // avoid using this if at all possible
-
- // initializes an empty account
-typedef struct PROTO_INTERFACE* (*pfnInitProto)(const char* szModuleName, const wchar_t* szUserName);
-
-// deallocates an account instance
-typedef int (*pfnUninitProto)(PROTO_INTERFACE*);
+#define PROTOTYPE_IGNORE 50 // added during v0.3.3
+#define PROTOTYPE_PROTOCOL 1000 // old style protocol
+#define PROTOTYPE_VIRTUAL 1001 // virtual protocol (has no accounts)
+#define PROTOTYPE_PROTOWITHACCS 1002 // new style protocol
+#define PROTOTYPE_ENCRYPTION 2000
+#define PROTOTYPE_FILTER 3000
+#define PROTOTYPE_TRANSLATION 4000
+#define PROTOTYPE_OTHER 10000 // avoid using this if at all possible
struct PROTOCOLDESCRIPTOR
{
- size_t cbSize;
char *szName; // unique name of the module
int type; // module type, see PROTOTYPE_ constants
-
- // these fields should be filled only for protos with accounts
- pfnInitProto fnInit; // initializes an empty account
- pfnUninitProto fnUninit; // deallocates an account instance
- HINSTANCE hInst; // module to which that proto belongs to
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -428,7 +415,7 @@ typedef struct { // PROTOTYPE_PROTOCOL modules must not do this. The value must be exact.
// See MS_PROTO_ENUMPROTOCOLS for more notes.
-EXTERN_C MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR*);
+EXTERN_C MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_RegisterModule(int type, const char *szName);
/////////////////////////////////////////////////////////////////////////////////////////
// adds the specified protocol module to the chain for a contact
diff --git a/include/newpluginapi.h b/include/newpluginapi.h index 6ced312160..85d0b94007 100644 --- a/include/newpluginapi.h +++ b/include/newpluginapi.h @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define M_NEWPLUGINAPI_H__
#include <m_core.h>
+#include <m_database.h>
#define PLUGIN_MAKE_VERSION(a, b, c, d) (((((DWORD)(a))&0xFF)<<24)|((((DWORD)(b))&0xFF)<<16)|((((DWORD)(c))&0xFF)<<8)|(((DWORD)(d))&0xFF))
#define MAXMODULELABELLENGTH 64
@@ -142,4 +143,263 @@ struct PLUGININFOEX EXTERN_C MIR_CORE_DLL(void) mir_getLP(const PLUGININFOEX *pInfo, int *_hLang = &hLangpack);
+/////////////////////////////////////////////////////////////////////////////////////////
+// plugin's class
+
+// initializes an empty account
+typedef struct PROTO_INTERFACE* (*pfnInitProto)(const char* szModuleName, const wchar_t* szUserName);
+
+// deallocates an account instance
+typedef int(*pfnUninitProto)(PROTO_INTERFACE*);
+
+class MIR_APP_EXPORT CMPluginBase
+{
+ void tryOpenLog();
+
+protected:
+ const char *m_szModuleName;
+ HANDLE m_hLogger = nullptr;
+ HINSTANCE m_hInst;
+
+ CMPluginBase(const char *moduleName);
+ ~CMPluginBase();
+
+ // pass one of PROTOTYPE_* constants as type
+ void RegisterProtocol(int type, pfnInitProto = nullptr, pfnUninitProto = nullptr);
+ void SetUniqueId(const char *pszUniqueId);
+
+public:
+ void debugLogA(LPCSTR szFormat, ...);
+ void debugLogW(LPCWSTR wszFormat, ...);
+
+ __forceinline HINSTANCE getInst() const { return m_hInst; }
+ __forceinline void setInst(HINSTANCE hInst) { m_hInst = hInst; }
+
+ __forceinline INT_PTR delSetting(const char *name)
+ {
+ return db_unset(0, m_szModuleName, name);
+ }
+ __forceinline INT_PTR delSetting(MCONTACT hContact, const char *name)
+ {
+ return db_unset(hContact, m_szModuleName, name);
+ }
+
+ __forceinline bool getBool(const char *name, bool defaultValue = false)
+ {
+ return db_get_b(0, m_szModuleName, name, defaultValue) != 0;
+ }
+ __forceinline bool getBool(MCONTACT hContact, const char *name, bool defaultValue = false)
+ {
+ return db_get_b(hContact, m_szModuleName, name, defaultValue) != 0;
+ }
+
+ __forceinline int getByte(const char *name, BYTE defaultValue = 0)
+ {
+ return db_get_b(0, m_szModuleName, name, defaultValue);
+ }
+ __forceinline int getByte(MCONTACT hContact, const char *name, BYTE defaultValue = 0)
+ {
+ return db_get_b(hContact, m_szModuleName, name, defaultValue);
+ }
+
+ __forceinline int getWord(const char *name, WORD defaultValue = 0)
+ {
+ return db_get_w(0, m_szModuleName, name, defaultValue);
+ }
+ __forceinline int getWord(MCONTACT hContact, const char *name, WORD defaultValue = 0)
+ {
+ return db_get_w(hContact, m_szModuleName, name, defaultValue);
+ }
+
+ __forceinline DWORD getDword(const char *name, DWORD defaultValue = 0)
+ {
+ return db_get_dw(0, m_szModuleName, name, defaultValue);
+ }
+ __forceinline DWORD getDword(MCONTACT hContact, const char *name, DWORD defaultValue = 0)
+ {
+ return db_get_dw(hContact, m_szModuleName, name, defaultValue);
+ }
+
+ __forceinline INT_PTR getString(const char *name, DBVARIANT *result)
+ {
+ return db_get_s(0, m_szModuleName, name, result);
+ }
+ __forceinline INT_PTR getString(MCONTACT hContact, const char *name, DBVARIANT *result)
+ {
+ return db_get_s(hContact, m_szModuleName, name, result);
+ }
+
+ __forceinline INT_PTR getWString(const char *name, DBVARIANT *result)
+ {
+ return db_get_ws(0, m_szModuleName, name, result);
+ }
+ __forceinline INT_PTR getWString(MCONTACT hContact, const char *name, DBVARIANT *result)
+ {
+ return db_get_ws(hContact, m_szModuleName, name, result);
+ }
+
+ __forceinline char* getStringA(const char *name)
+ {
+ return db_get_sa(0, m_szModuleName, name);
+ }
+ __forceinline char* getStringA(MCONTACT hContact, const char *name)
+ {
+ return db_get_sa(hContact, m_szModuleName, name);
+ }
+
+ __forceinline wchar_t* getWStringA(const char *name)
+ {
+ return db_get_wsa(0, m_szModuleName, name);
+ }
+ __forceinline wchar_t* getWStringA(MCONTACT hContact, const char *name)
+ {
+ return db_get_wsa(hContact, m_szModuleName, name);
+ }
+
+ __forceinline void setByte(const char *name, BYTE value)
+ {
+ db_set_b(0, m_szModuleName, name, value);
+ }
+ __forceinline void setByte(MCONTACT hContact, const char *name, BYTE value)
+ {
+ db_set_b(hContact, m_szModuleName, name, value);
+ }
+
+ __forceinline void setWord(const char *name, WORD value)
+ {
+ db_set_w(0, m_szModuleName, name, value);
+ }
+ __forceinline void setWord(MCONTACT hContact, const char *name, WORD value)
+ {
+ db_set_w(hContact, m_szModuleName, name, value);
+ }
+
+ __forceinline void setDword(const char *name, DWORD value)
+ {
+ db_set_dw(0, m_szModuleName, name, value);
+ }
+ __forceinline void setDword(MCONTACT hContact, const char *name, DWORD value)
+ {
+ db_set_dw(hContact, m_szModuleName, name, value);
+ }
+
+ __forceinline void setString(const char *name, const char* value)
+ {
+ db_set_s(0, m_szModuleName, name, value);
+ }
+ __forceinline void setString(MCONTACT hContact, const char *name, const char* value)
+ {
+ db_set_s(hContact, m_szModuleName, name, value);
+ }
+
+ __forceinline void setWString(const char *name, const wchar_t* value)
+ {
+ db_set_ws(0, m_szModuleName, name, value);
+ }
+ __forceinline void setWString(MCONTACT hContact, const char *name, const wchar_t* value)
+ {
+ db_set_ws(hContact, m_szModuleName, name, value);
+ }
+};
+
+extern struct CMPlugin g_plugin;
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Basic class for plugins (not protocols) written in C++
+
+typedef BOOL(WINAPI * const _pfnCrtInit)(HINSTANCE, DWORD, LPVOID);
+
+template<class T> class PLUGIN : public CMPluginBase
+{
+ typedef CMPluginBase CSuper;
+
+public:
+ static BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD, LPVOID)
+ {
+ g_plugin.setInst(hInstance);
+ return TRUE;
+ }
+
+protected:
+ PLUGIN(const char *moduleName)
+ : CSuper(moduleName)
+ {}
+
+ __forceinline HANDLE CreatePluginEvent(const char *name)
+ {
+ CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name);
+ return CreateHookableEvent(str);
+ }
+
+ typedef int(__cdecl T::*MyEventFunc)(WPARAM, LPARAM);
+ __forceinline void HookPluginEvent(const char *name, MyEventFunc pFunc)
+ {
+ HookEventObj(name, (MIRANDAHOOKOBJ)*(void**)&pFunc, this);
+ }
+
+ typedef INT_PTR(__cdecl T::*MyServiceFunc)(WPARAM, LPARAM);
+ __forceinline void CreatePluginService(const char *name, MyServiceFunc pFunc)
+ {
+ CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name);
+ CreateServiceFunctionObj(str, (MIRANDASERVICEOBJ)*(void**)&pFunc, this);
+ }
+
+ typedef INT_PTR(__cdecl T::*MyServiceFuncParam)(WPARAM, LPARAM, LPARAM);
+ __forceinline void CreatePluginServiceParam(const char *name, MyServiceFuncParam pFunc, LPARAM param)
+ {
+ CMStringA str(FORMAT, "%s\\%s", m_szModuleName, name);
+ CreateServiceFunctionObjParam(str, (MIRANDASERVICEOBJPARAM)*(void**)&pFunc, this, param);
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Basic class for protocols with accounts
+
+struct CMPlugin;
+
+template<class P> class ACCPROTOPLUGIN : public PLUGIN<CMPlugin>
+{
+ typedef PLUGIN<CMPlugin> CSuper;
+
+protected:
+ ACCPROTOPLUGIN(const char *moduleName) :
+ CSuper(moduleName)
+ {
+ CMPluginBase::RegisterProtocol(1002, &fnInit, &fnUninit);
+ }
+
+ static PROTO_INTERFACE* fnInit(const char *szModuleName, const wchar_t *wszAccountName)
+ {
+ P *ppro = new P(szModuleName, wszAccountName);
+ g_arInstances.insert(ppro);
+ return ppro;
+ }
+
+ static int fnUninit(PROTO_INTERFACE *ppro)
+ {
+ g_arInstances.remove((P*)ppro);
+ return 0;
+ }
+
+public:
+ static OBJLIST<P> g_arInstances;
+
+ static P* getInstance(const char *szProto)
+ {
+ for (auto &it : g_arInstances)
+ if (mir_strcmp(szProto, it->m_szModuleName) == 0)
+ return it;
+
+ return nullptr;
+ }
+
+ static P* getInstance(MCONTACT hContact)
+ {
+ return getInstance(::GetContactProto(hContact));
+ }
+};
+
+template<class P>
+OBJLIST<P> ACCPROTOPLUGIN<P>::g_arInstances(1, PtrKeySortT);
+
#endif // M_NEWPLUGINAPI_H__
|