1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*
Jabber Protocol Plugin for Miranda IM
Copyright ( C ) 2002-04 Santithorn Bunchua
Copyright ( C ) 2005-08 George Hazan
Copyright ( C ) 2007 Maxim Mluhov
Copyright ( C ) 2008-09 Dmitriy Chervov
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or ( at your option ) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
File name : $URL: https://miranda.svn.sourceforge.net/svnroot/miranda/trunk/miranda/include/m_jabber.h $
Revision : $Revision: 9996 $
Last change on : $Date: 2009-11-15 13:27:32 +0200 $
Last change by : $Author: dchervov $
*/
#ifndef M_JABBER_H__
#define M_JABBER_H__
#ifdef __cplusplus
#include <m_xml.h>
struct IJabberInterface;
struct IJabberSysInterface
{
// Returns version of IJabberSysInterface.
virtual int STDMETHODCALLTYPE GetVersion() const = 0;
// Compares JIDs by their node@domain part (without resource name).
virtual int STDMETHODCALLTYPE CompareJIDs(LPCTSTR jid1, LPCTSTR jid2) = 0;
// Returns contact handle for given JID, or NULL on error.
virtual HANDLE STDMETHODCALLTYPE ContactFromJID(LPCTSTR jid) = 0;
// Returns JID of hContact, or NULL on error. You must free the result using mir_free().
virtual LPTSTR STDMETHODCALLTYPE ContactToJID(HANDLE hContact) = 0;
// Returns best resource name for given JID, or NULL on error. You must free the result using mir_free().
virtual LPTSTR STDMETHODCALLTYPE GetBestResourceName(LPCTSTR jid) = 0;
// Returns all resource names for a given JID in format "resource1\0resource2\0resource3\0\0" (all resources are separated by \0 character and the whole string is terminated with two \0 characters), or NULL on error. You must free returned string using mir_free().
virtual LPTSTR STDMETHODCALLTYPE GetResourceList(LPCTSTR jid) = 0;
// Returns Jabber module name. DO NOT free the returned string.
virtual char* STDMETHODCALLTYPE GetModuleName() const = 0;
};
// Iq type flags
enum
{
JABBER_IQ_TYPE_FAIL = 0,
JABBER_IQ_TYPE_RESULT = 1,
JABBER_IQ_TYPE_ERROR = 2,
JABBER_IQ_TYPE_GET = 4,
JABBER_IQ_TYPE_SET = 8,
JABBER_IQ_TYPE_RESULT_ERROR = JABBER_IQ_TYPE_RESULT | JABBER_IQ_TYPE_ERROR,
JABBER_IQ_TYPE_GOOD = JABBER_IQ_TYPE_RESULT | JABBER_IQ_TYPE_GET | JABBER_IQ_TYPE_SET,
JABBER_IQ_TYPE_ANY = JABBER_IQ_TYPE_RESULT | JABBER_IQ_TYPE_ERROR | JABBER_IQ_TYPE_GET | JABBER_IQ_TYPE_SET
};
// Message type flags
enum
{
JABBER_MESSAGE_TYPE_FAIL = 0,
JABBER_MESSAGE_TYPE_NORMAL = 1,
JABBER_MESSAGE_TYPE_ERROR = 2,
JABBER_MESSAGE_TYPE_CHAT = 4,
JABBER_MESSAGE_TYPE_GROUPCHAT = 8,
JABBER_MESSAGE_TYPE_HEADLINE = 0x10,
JABBER_MESSAGE_TYPE_ANY = JABBER_MESSAGE_TYPE_NORMAL | JABBER_MESSAGE_TYPE_ERROR | JABBER_MESSAGE_TYPE_CHAT | JABBER_MESSAGE_TYPE_GROUPCHAT | JABBER_MESSAGE_TYPE_HEADLINE
};
// Handler priority values.
// All handler calls are ordered by priority specified when adding a handler.
// For recv, it will go from lower to higher, so in this case: check ignore, default.
// For send handlers, it will go in the opposite order: default, check ignore, send.
// You may also use other values than specified here for your handler priority, if it's necessary.
// IMPORTANT: In all incoming stanza handlers, return FALSE to continue processing the stanza (Jabber plugin will then call other handlers), or TRUE to stop processing the stanza (if you're sure noone else needs to process this stanza).
// In an outgoing stanza handler it works in the same way: return TRUE to stop processing the stanza and abort sending.
// All handlers may modify the stanza if it's necessary; these modifications will be passed to remaining handlers.
enum
{
JH_PRIORITY_IGNORE = 50,
JH_PRIORITY_DEFAULT = 1000,
JH_PRIORITY_UNHANDLED = 5000 // useful for example to catch unhandled Iq stanzas to send a correct reply.
};
typedef void* HJHANDLER;
typedef BOOL (*JABBER_HANDLER_FUNC)(IJabberInterface *ji, HXML node, void *pUserData);
struct IJabberNetInterface
{
// Returns version of IJabberNetInterface.
virtual int STDMETHODCALLTYPE GetVersion() const = 0;
// Returns id that can be used for next message sent through SendXmlNode().
virtual unsigned int STDMETHODCALLTYPE SerialNext() = 0;
// Sends XML node.
virtual int STDMETHODCALLTYPE SendXmlNode(HXML node) = 0;
// Registers incoming <presence/> handler. Returns handler handle on success or NULL on error.
virtual HJHANDLER STDMETHODCALLTYPE AddPresenceHandler(JABBER_HANDLER_FUNC Func, void *pUserData = NULL, int iPriority = JH_PRIORITY_DEFAULT) = 0;
// Registers incoming <message/> handler for messages of types specified by iMsgTypes. iMsgTypes is a combination of JABBER_MESSAGE_TYPE_* flags. Returns handler handle on success or NULL on error.
virtual HJHANDLER STDMETHODCALLTYPE AddMessageHandler(JABBER_HANDLER_FUNC Func, int iMsgTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData = NULL, int iPriority = JH_PRIORITY_DEFAULT) = 0;
// Registers incoming <iq/> handler. iIqTypes is a combination of JABBER_IQ_TYPE_* flags. Returns handler handle on success or NULL on error.
virtual HJHANDLER STDMETHODCALLTYPE AddIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData = NULL, int iPriority = JH_PRIORITY_DEFAULT) = 0;
// Registers temporary handler for incoming <iq/> stanza of type iIqType with id iIqId. iIqTypes is a combination of JABBER_IQ_TYPE_* flags. Returns handler handle on success or NULL on error.
// If dwTimeout milliseconds pass and no Iq stanza with the specified iIqId is received, Jabber plugin will call Func() with NULL node.
virtual HJHANDLER STDMETHODCALLTYPE AddTemporaryIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, int iIqId, void *pUserData = NULL, DWORD dwTimeout = 30000, int iPriority = JH_PRIORITY_DEFAULT) = 0;
// Registers handler for outgoing nodes. Returns handler handle on success or NULL on error.
// Return FALSE in the handler to continue, or TRUE to abort sending.
virtual HJHANDLER STDMETHODCALLTYPE AddSendHandler(JABBER_HANDLER_FUNC Func, void *pUserData = NULL, int iPriority = JH_PRIORITY_DEFAULT) = 0;
// Unregisters handler by its handle.
virtual int STDMETHODCALLTYPE RemoveHandler(HJHANDLER hHandler) = 0;
// Entity capabilities support (see xep-0115)
// Registers feature so that it's displayed with proper description in other users' details. Call this function in your ME_SYSTEM_MODULESLOADED handler. Returns TRUE on success or FALSE on error.
virtual int STDMETHODCALLTYPE RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription) = 0;
// Adds features to the list of features supported by the client. szFeatures is a list of features separated by \0 character and terminated with two \0 characters. You can call this function at any time. Returns TRUE on success or FALSE on error.
virtual int STDMETHODCALLTYPE AddFeatures(LPCTSTR szFeatures) = 0;
// Removes features from the list of features supported by the client. szFeatures is a list of features separated by \0 character and terminated with two \0 characters. You can call this function at any time.
virtual int STDMETHODCALLTYPE RemoveFeatures(LPCTSTR szFeatures) = 0;
// Returns features supported by JID in format "feature1\0feature2\0...\0featureN\0\0" (a list of features separated by \0 character and terminated with two \0 characters), or NULL on error. JID may contain resource name to get features of a specific resource. If there's no resource name, GetResourceFeatures() returns features for the same resource as IJabberSysInterface::GetBestResourceName() returns. If a feature you're checking for is not supported by Jabber plugin natively, you must register it with RegisterFeature(), otherwise GetContactFeatures() won't be able to return it. You must free returned string using mir_free().
virtual LPTSTR STDMETHODCALLTYPE GetResourceFeatures(LPCTSTR jid) = 0;
};
// IJabberInterface::dwFlags values
enum
{
JIF_UNICODE = 1
};
// Overall Jabber interface
struct IJabberInterface
{
// Set of JIF_* flags.
virtual DWORD STDMETHODCALLTYPE GetFlags() const = 0;
// Returns version of IJabberInterface.
virtual int STDMETHODCALLTYPE GetVersion() const = 0;
// Returns Jabber plugin version.
virtual DWORD STDMETHODCALLTYPE GetJabberVersion() const = 0;
// Jabber system utilities.
virtual IJabberSysInterface* STDMETHODCALLTYPE Sys() const = 0;
// Jabber network interface.
virtual IJabberNetInterface* STDMETHODCALLTYPE Net() const = 0;
};
/*
A service to obtain Jabber API for a given account.
If you store the pointer to the interface for later use, you must also hook ME_PROTO_ACCLISTCHANGED and update the pointer to prevent calling API for a removed account.
wParam = 0;
lParam = (LPARAM)(IJabberInterface**).
Returns FALSE if all is Ok, and TRUE otherwise.
*/
#define JS_GETJABBERAPI "/GetJabberApi"
__forceinline IJabberInterface *getJabberApi(const char *szAccount)
{
IJabberInterface *ji;
if (!CallProtoService(szAccount, JS_GETJABBERAPI, 0, (LPARAM)&ji))
{
return ji;
}
return NULL;
}
/* Custom Status helper API *
DB settings and write values to them (UTF-8 strings best). (obsolete)
- use JS_GETXSTATUSEX and JS_SETXSTATUSEX for controling Custom Status
*/
#define CSSF_MASK_STATUS 0x0001 // status member valid for set/get
#define CSSF_MASK_NAME 0x0002 // pszName member valid for set/get
#define CSSF_MASK_MESSAGE 0x0004 // pszMessage member valid for set/get
#define CSSF_DISABLE_MENU 0x0020 // disable default custom status menu, wParam = bEnable
#define CSSF_DISABLE_UI 0x0040 // disable default custom status UI, wParam = bEnable
#define CSSF_DEFAULT_NAME 0x0080 // only with CSSF_MASK_NAME and get API to get default custom status name (wParam = status)
#define CSSF_STATUSES_COUNT 0x0100 // returns number of custom statuses in wParam, only get API
#define CSSF_STR_SIZES 0x0200 // returns sizes of custom status name & message (wParam & lParam members) in chars
#define CSSF_UNICODE 0x1000 // strings are in UCS-2
#if defined(_UNICODE)
#define CSSF_TCHAR CSSF_UNICODE
#else
#define CSSF_TCHAR 0
#endif
typedef struct {
int cbSize; // size of the structure
int flags; // combination of CSSF_*
int *status; // custom status id
union {
char *pszMessage; // buffer for custom status message
TCHAR *ptszMessage;
WCHAR *pwszMessage;
};
WPARAM *wParam; // extra params, see flags
LPARAM *lParam;
} JABBER_CUSTOM_STATUS;
// Sets owner current custom status
//wParam = 0 // reserved
//lParam = (JABBER_CUSTOM_STATUS*)pData // contains what to set and new values
//return = 0 (for success)
#define JS_SETXSTATUSEX "/SetXStatusEx"
// Retrieves custom status details for specified hContact
//wParam = (HANDLE)hContact
//lParam = (JABBER_CUSTOM_STATUS*)pData // receives details (members must be prepared)
//return = 0 (for success)
// not needed anymore and therefore commented out
//#define JS_GETXSTATUSEX "/GetXStatusEx"
#endif // __cplusplus
#endif // M_JABBER_H__
|