|
10969
|
1
|
|
|
2 /*
|
|
|
3 Meanwhile - Unofficial Lotus Sametime Community Client Library
|
|
|
4 Copyright (C) 2004 Christopher (siege) O'Brien
|
|
|
5
|
|
|
6 This library is free software; you can redistribute it and/or
|
|
|
7 modify it under the terms of the GNU Library General Public
|
|
|
8 License as published by the Free Software Foundation; either
|
|
|
9 version 2 of the License, or (at your option) any later version.
|
|
|
10
|
|
|
11 This library is distributed in the hope that it will be useful,
|
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
14 Library General Public License for more details.
|
|
|
15
|
|
|
16 You should have received a copy of the GNU Library General Public
|
|
|
17 License along with this library; if not, write to the Free
|
|
|
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
19 */
|
|
|
20
|
|
|
21 #ifndef _MW_SESSION_H
|
|
|
22 #define _MW_SESSION_H
|
|
|
23
|
|
|
24
|
|
|
25 #include "mw_common.h"
|
|
|
26
|
|
|
27
|
|
|
28 /** @file session.h
|
|
|
29
|
|
|
30 A client session with a Sametime server is encapsulated in the
|
|
|
31 mwSession structure. The session controls channels, provides
|
|
|
32 encryption ciphers, and manages services using messages over the
|
|
|
33 Master channel.
|
|
|
34
|
|
|
35 A session does not directly communicate with a socket or stream,
|
|
|
36 instead the session is initialized from client code with an
|
|
|
37 instance of a mwSessionHandler structure. This session handler
|
|
|
38 provides functions as call-backs for common session events, and
|
|
|
39 provides functions for writing-to and closing the connection to
|
|
|
40 the server.
|
|
|
41
|
|
|
42 A session does not perform reads on a socket directly. Instead, it
|
|
|
43 must be fed from an outside source via the mwSession_recv
|
|
|
44 function. The session will buffer and merge data passed to this
|
|
|
45 function to build complete protocol messages, and will act upon
|
|
|
46 each complete message accordingly.
|
|
|
47 */
|
|
|
48
|
|
|
49
|
|
|
50 struct mwCipher;
|
|
|
51 struct mwMessage;
|
|
|
52
|
|
|
53
|
|
|
54 /** default protocol major version */
|
|
|
55 #define MW_PROTOCOL_VERSION_MAJOR 0x001e
|
|
|
56
|
|
|
57
|
|
|
58 /** default protocol minor version */
|
|
|
59 #define MW_PROTOCOL_VERSION_MINOR 0x001d
|
|
|
60
|
|
|
61
|
|
|
62 /** @section Session Properties
|
|
|
63 ...
|
|
|
64 */
|
|
|
65 /*@{*/
|
|
|
66
|
|
|
67 /** char *, session user ID */
|
|
|
68 #define mwSession_AUTH_USER_ID "session.auth.user"
|
|
|
69
|
|
|
70 /** char *, plaintext password */
|
|
|
71 #define mwSession_AUTH_PASSWORD "session.auth.password"
|
|
|
72
|
|
|
73 /** struct mwOpaque *, authentication token */
|
|
|
74 #define mwSession_AUTH_TOKEN "session.auth.token"
|
|
|
75
|
|
|
76 /** guint16, major version of client protocol */
|
|
|
77 #define mwSession_CLIENT_VER_MAJOR "client.version.major"
|
|
|
78
|
|
|
79 /** guint16, minor version of client protocol */
|
|
|
80 #define mwSession_CLIENT_VER_MINOR "client.version.minor"
|
|
|
81
|
|
|
82 /** guint16, client type identifier */
|
|
|
83 #define mwSession_CLIENT_TYPE_ID "client.id"
|
|
|
84
|
|
|
85 /** guint16, major version of server protocol */
|
|
|
86 #define mwSession_SERVER_VER_MAJOR "server.version.major"
|
|
|
87
|
|
|
88 /** guint16, minor version of server protocol */
|
|
|
89 #define mwSession_SERVER_VER_MINOR "server.version.minor"
|
|
|
90
|
|
|
91 /*@}*/
|
|
|
92
|
|
|
93
|
|
|
94 enum mwSessionState {
|
|
|
95 mwSession_STARTING, /**< session is starting */
|
|
|
96 mwSession_HANDSHAKE, /**< session has sent handshake */
|
|
|
97 mwSession_HANDSHAKE_ACK, /**< session has received handshake ack */
|
|
|
98 mwSession_LOGIN, /**< session has sent login */
|
|
|
99 mwSession_LOGIN_REDIR, /**< session has been redirected */
|
|
|
100 mwSession_LOGIN_ACK, /**< session has received login ack */
|
|
|
101 mwSession_STARTED, /**< session is active */
|
|
|
102 mwSession_STOPPING, /**< session is shutting down */
|
|
|
103 mwSession_STOPPED, /**< session is stopped */
|
|
|
104 mwSession_UNKNOWN, /**< indicates an error determining state */
|
|
|
105 mwSession_LOGIN_CONT, /**< session has sent a login continue */
|
|
|
106 };
|
|
|
107
|
|
|
108
|
|
|
109 #define mwSession_isState(session, state) \
|
|
|
110 (mwSession_getState((session)) == (state))
|
|
|
111
|
|
|
112 #define mwSession_isStarting(s) \
|
|
|
113 (mwSession_isState((s), mwSession_STARTING) || \
|
|
|
114 mwSession_isState((s), mwSession_HANDSHAKE) || \
|
|
|
115 mwSession_isState((s), mwSession_HANDSHAKE_ACK) || \
|
|
|
116 mwSession_isState((s), mwSession_LOGIN) || \
|
|
|
117 mwSession_isState((s), mwSession_LOGIN_ACK) || \
|
|
|
118 mwSession_isState((s), mwSession_LOGIN_REDIR) || \
|
|
|
119 mwSession_isState((s), mwSession_LOGIN_CONT))
|
|
|
120
|
|
|
121 #define mwSession_isStarted(s) \
|
|
|
122 (mwSession_isState((s), mwSession_STARTED))
|
|
|
123
|
|
|
124 #define mwSession_isStopping(s) \
|
|
|
125 (mwSession_isState((s), mwSession_STOPPING))
|
|
|
126
|
|
|
127 #define mwSession_isStopped(s) \
|
|
|
128 (mwSession_isState((s), mwSession_STOPPED))
|
|
|
129
|
|
|
130
|
|
|
131 /** @struct mwSession
|
|
|
132
|
|
|
133 Represents a Sametime client session */
|
|
|
134 struct mwSession;
|
|
|
135
|
|
|
136
|
|
|
137 /** @struct mwSessionHandler
|
|
|
138
|
|
|
139 session handler. Structure which interfaces a session with client
|
|
|
140 code to provide I/O and event handling */
|
|
|
141 struct mwSessionHandler {
|
|
|
142
|
|
|
143 /** write data to the server connection. Required. Should return
|
|
|
144 zero for success, non-zero for error */
|
|
|
145 int (*io_write)(struct mwSession *, const char *buf, gsize len);
|
|
|
146
|
|
|
147 /** close the server connection. Required */
|
|
|
148 void (*io_close)(struct mwSession *);
|
|
|
149
|
|
|
150 /** triggered by mwSession_free. Optional. Put cleanup code here */
|
|
|
151 void (*clear)(struct mwSession *);
|
|
|
152
|
|
|
153 /** Called when the session has changed status.
|
|
|
154
|
|
|
155 Uses of the info param:
|
|
|
156 - <code>STOPPING</code> error code causing the session to shut down
|
|
|
157
|
|
|
158 @todo change info to a gpointer
|
|
|
159
|
|
|
160 @param s the session
|
|
|
161 @param state the session's state
|
|
|
162 @param info additional state info. */
|
|
|
163 void (*on_stateChange)(struct mwSession *s,
|
|
|
164 enum mwSessionState state, guint32 info);
|
|
|
165
|
|
|
166 /** called when privacy information has been sent or received
|
|
|
167
|
|
|
168 @see mwSession_getPrivacyInfo
|
|
|
169 */
|
|
|
170 void (*on_setPrivacyInfo)(struct mwSession *);
|
|
|
171
|
|
|
172 /** called when user status has changed
|
|
|
173
|
|
|
174 @see mwSession_getUserStatus */
|
|
|
175 void (*on_setUserStatus)(struct mwSession *);
|
|
|
176
|
|
|
177 /** called when an admin messages has been received */
|
|
|
178 void (*on_admin)(struct mwSession *, const char *text);
|
|
|
179
|
|
|
180 /** called when a login redirect message is received
|
|
|
181
|
|
|
182 @todo remove in favour of on_stateChange, passing host as a
|
|
|
183 gpointer in info */
|
|
|
184 void (*on_loginRedirect)(struct mwSession *, const char *host);
|
|
|
185 };
|
|
|
186
|
|
|
187
|
|
|
188 /** allocate a new session */
|
|
|
189 struct mwSession *mwSession_new(struct mwSessionHandler *);
|
|
|
190
|
|
|
191
|
|
|
192 /** stop, clear, free a session. Does not free contained ciphers or
|
|
|
193 services, these must be taken care of explicitly. */
|
|
|
194 void mwSession_free(struct mwSession *);
|
|
|
195
|
|
|
196
|
|
|
197 /** obtain a reference to the session's handler */
|
|
|
198 struct mwSessionHandler *mwSession_getHandler(struct mwSession *);
|
|
|
199
|
|
|
200
|
|
|
201 /** instruct the session to begin. This will result in the initial
|
|
|
202 handshake message being sent. */
|
|
|
203 void mwSession_start(struct mwSession *);
|
|
|
204
|
|
|
205
|
|
|
206 /** instruct the session to shut down with the following reason
|
|
|
207 code. */
|
|
|
208 void mwSession_stop(struct mwSession *, guint32 reason);
|
|
|
209
|
|
|
210
|
|
|
211 /** Data is buffered, unpacked, and parsed into a message, then
|
|
|
212 processed accordingly. */
|
|
|
213 void mwSession_recv(struct mwSession *, const char *, gsize);
|
|
|
214
|
|
|
215
|
|
|
216 /** primarily used by services to have messages serialized and sent
|
|
|
217 @param s session to send message over
|
|
|
218 @param msg message to serialize and send
|
|
|
219 @returns 0 for success */
|
|
|
220 int mwSession_send(struct mwSession *s, struct mwMessage *msg);
|
|
|
221
|
|
|
222
|
|
|
223 /** sends the keepalive byte */
|
|
|
224 int mwSession_sendKeepalive(struct mwSession *s);
|
|
|
225
|
|
|
226
|
|
|
227 /** respond to a login redirect message by forcing the login sequence
|
|
|
228 to continue through the immediate server. */
|
|
|
229 int mwSession_forceLogin(struct mwSession *s);
|
|
|
230
|
|
|
231
|
|
|
232 /** set the internal privacy information, and inform the server as
|
|
|
233 necessary. Triggers the on_setPrivacyInfo call-back. */
|
|
|
234 int mwSession_setPrivacyInfo(struct mwSession *, struct mwPrivacyInfo *);
|
|
|
235
|
|
|
236
|
|
|
237 struct mwPrivacyInfo *mwSession_getPrivacyInfo(struct mwSession *);
|
|
|
238
|
|
|
239
|
|
|
240 /** reference the login information for the session */
|
|
|
241 struct mwLoginInfo *mwSession_getLoginInfo(struct mwSession *);
|
|
|
242
|
|
|
243
|
|
|
244 /** set the internal user status state, and inform the server as
|
|
|
245 necessary. Triggers the on_setUserStatus call-back */
|
|
|
246 int mwSession_setUserStatus(struct mwSession *, struct mwUserStatus *);
|
|
|
247
|
|
|
248
|
|
|
249 struct mwUserStatus *mwSession_getUserStatus(struct mwSession *);
|
|
|
250
|
|
|
251
|
|
|
252 /** current status of the session */
|
|
|
253 enum mwSessionState mwSession_getState(struct mwSession *);
|
|
|
254
|
|
|
255
|
|
|
256 /** additional status-specific information */
|
|
|
257 guint32 mwSession_getStateInfo(struct mwSession *);
|
|
|
258
|
|
|
259
|
|
|
260 struct mwChannelSet *mwSession_getChannels(struct mwSession *);
|
|
|
261
|
|
|
262
|
|
|
263 /** adds a service to the session. If the session is started (or when
|
|
|
264 the session is successfully started) and the service has a start
|
|
|
265 function, the session will request service availability from the
|
|
|
266 server. On receipt of the service availability notification, the
|
|
|
267 session will call the service's start function.
|
|
|
268
|
|
|
269 @return TRUE if the session was added correctly */
|
|
|
270 gboolean mwSession_addService(struct mwSession *, struct mwService *);
|
|
|
271
|
|
|
272
|
|
|
273 /** find a service by its type identifier */
|
|
|
274 struct mwService *mwSession_getService(struct mwSession *, guint32 type);
|
|
|
275
|
|
|
276
|
|
|
277 /** removes a service from the session. If the session is started and
|
|
|
278 the service has a stop function, it will be called. Returns the
|
|
|
279 removed service */
|
|
|
280 struct mwService *mwSession_removeService(struct mwSession *, guint32 type);
|
|
|
281
|
|
|
282
|
|
|
283 /** a GList of services in this session. The GList needs to be freed
|
|
|
284 after use */
|
|
|
285 GList *mwSession_getServices(struct mwSession *);
|
|
|
286
|
|
|
287
|
|
|
288 /** instruct a STARTED session to check the server for the presense of
|
|
|
289 a given service. The service will be automatically started upon
|
|
|
290 receipt of an affirmative reply from the server. This function is
|
|
|
291 automatically called upon all services in a session when the
|
|
|
292 session is fully STARTED.
|
|
|
293
|
|
|
294 Services which terminate due to an error may call this on
|
|
|
295 themselves to re-initialize when their server-side counterpart is
|
|
|
296 made available again.
|
|
|
297
|
|
|
298 @param s owning session
|
|
|
299 @param type service type ID */
|
|
|
300 void mwSession_senseService(struct mwSession *s, guint32 type);
|
|
|
301
|
|
|
302
|
|
|
303 /** adds a cipher to the session. */
|
|
|
304 gboolean mwSession_addCipher(struct mwSession *, struct mwCipher *);
|
|
|
305
|
|
|
306
|
|
|
307 /** find a cipher by its type identifier */
|
|
|
308 struct mwCipher *mwSession_getCipher(struct mwSession *, guint16 type);
|
|
|
309
|
|
|
310
|
|
|
311 /** remove a cipher from the session */
|
|
|
312 struct mwCipher *mwSession_removeCipher(struct mwSession *, guint16 type);
|
|
|
313
|
|
|
314
|
|
|
315 /** a GList of ciphers in this session. The GList needs to be freed
|
|
|
316 after use */
|
|
|
317 GList *mwSession_getCiphers(struct mwSession *);
|
|
|
318
|
|
|
319
|
|
|
320 /** associate a key:value pair with the session. If an existing value is
|
|
|
321 associated with the same key, it will have its clear function called
|
|
|
322 and will be replaced with the new value */
|
|
|
323 void mwSession_setProperty(struct mwSession *, const char *key,
|
|
|
324 gpointer val, GDestroyNotify clear);
|
|
|
325
|
|
|
326
|
|
|
327 /** obtain the value of a previously set property, or NULL */
|
|
|
328 gpointer mwSession_getProperty(struct mwSession *, const char *key);
|
|
|
329
|
|
|
330
|
|
|
331 /** remove a property, calling the optional GDestroyNotify function
|
|
|
332 indicated in mwSession_setProperty if applicable */
|
|
|
333 void mwSession_removeProperty(struct mwSession *, const char *key);
|
|
|
334
|
|
|
335
|
|
|
336 /** associate arbitrary data with the session for use by the client
|
|
|
337 code. Only client applications should use this, never services.
|
|
|
338
|
|
|
339 @param session the session to associate the data with
|
|
|
340 @param data arbitrary client data
|
|
|
341 @param clear optional cleanup function called on data from
|
|
|
342 mwSession_removeClientData and mwSession_free
|
|
|
343 */
|
|
|
344 void mwSession_setClientData(struct mwSession *session,
|
|
|
345 gpointer data, GDestroyNotify clear);
|
|
|
346
|
|
|
347
|
|
|
348 gpointer mwSession_getClientData(struct mwSession *session);
|
|
|
349
|
|
|
350
|
|
|
351 /** remove client data, calling the optional GDestroyNotify function
|
|
|
352 indicated in mwSession_setClientData if applicable */
|
|
|
353 void mwSession_removeClientData(struct mwSession *session);
|
|
|
354
|
|
|
355
|
|
|
356 #endif
|
|
|
357
|