Mercurial > pidgin
annotate src/protocols/sametime/meanwhile/mw_session.h @ 12264:2be62353f708
[gaim-migrate @ 14566]
this was TRUE in oldstatus
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Tue, 29 Nov 2005 23:50:39 +0000 |
| parents | 0110fc7c6a8a |
| children | a2ebf585d8c6 |
| rev | line source |
|---|---|
| 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 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
25 /** @file mw_session.h |
| 10969 | 26 |
| 27 A client session with a Sametime server is encapsulated in the | |
| 28 mwSession structure. The session controls channels, provides | |
| 29 encryption ciphers, and manages services using messages over the | |
| 30 Master channel. | |
| 31 | |
| 32 A session does not directly communicate with a socket or stream, | |
| 33 instead the session is initialized from client code with an | |
| 34 instance of a mwSessionHandler structure. This session handler | |
| 35 provides functions as call-backs for common session events, and | |
| 36 provides functions for writing-to and closing the connection to | |
| 37 the server. | |
| 38 | |
| 39 A session does not perform reads on a socket directly. Instead, it | |
| 40 must be fed from an outside source via the mwSession_recv | |
| 41 function. The session will buffer and merge data passed to this | |
| 42 function to build complete protocol messages, and will act upon | |
| 43 each complete message accordingly. | |
| 44 */ | |
| 45 | |
| 46 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
47 #include "mw_common.h" |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
48 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
49 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
50 struct mwChannelSet; |
| 10969 | 51 struct mwCipher; |
| 52 struct mwMessage; | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
53 struct mwService; |
| 10969 | 54 |
| 55 | |
| 56 /** default protocol major version */ | |
| 57 #define MW_PROTOCOL_VERSION_MAJOR 0x001e | |
| 58 | |
| 59 | |
| 60 /** default protocol minor version */ | |
| 61 #define MW_PROTOCOL_VERSION_MINOR 0x001d | |
| 62 | |
| 63 | |
| 64 /** @section Session Properties | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
65 for use with mwSession_setProperty, et al. |
| 10969 | 66 */ |
| 67 /*@{*/ | |
| 68 | |
| 69 /** char *, session user ID */ | |
| 70 #define mwSession_AUTH_USER_ID "session.auth.user" | |
| 71 | |
| 72 /** char *, plaintext password */ | |
| 73 #define mwSession_AUTH_PASSWORD "session.auth.password" | |
| 74 | |
| 75 /** struct mwOpaque *, authentication token */ | |
| 76 #define mwSession_AUTH_TOKEN "session.auth.token" | |
| 77 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
78 /** char *, hostname of client */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
79 #define mwSession_CLIENT_HOST "client.host" |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
80 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
81 /** guint32, local IP of client */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
82 #define mwSession_CLIENT_IP "client.ip" |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
83 |
| 10969 | 84 /** guint16, major version of client protocol */ |
| 85 #define mwSession_CLIENT_VER_MAJOR "client.version.major" | |
| 86 | |
| 87 /** guint16, minor version of client protocol */ | |
| 88 #define mwSession_CLIENT_VER_MINOR "client.version.minor" | |
| 89 | |
| 90 /** guint16, client type identifier */ | |
| 91 #define mwSession_CLIENT_TYPE_ID "client.id" | |
| 92 | |
| 93 /** guint16, major version of server protocol */ | |
| 94 #define mwSession_SERVER_VER_MAJOR "server.version.major" | |
| 95 | |
| 96 /** guint16, minor version of server protocol */ | |
| 97 #define mwSession_SERVER_VER_MINOR "server.version.minor" | |
| 98 | |
| 99 /*@}*/ | |
| 100 | |
| 101 | |
| 102 enum mwSessionState { | |
| 103 mwSession_STARTING, /**< session is starting */ | |
| 104 mwSession_HANDSHAKE, /**< session has sent handshake */ | |
| 105 mwSession_HANDSHAKE_ACK, /**< session has received handshake ack */ | |
| 106 mwSession_LOGIN, /**< session has sent login */ | |
| 107 mwSession_LOGIN_REDIR, /**< session has been redirected */ | |
| 108 mwSession_LOGIN_ACK, /**< session has received login ack */ | |
| 109 mwSession_STARTED, /**< session is active */ | |
| 110 mwSession_STOPPING, /**< session is shutting down */ | |
| 111 mwSession_STOPPED, /**< session is stopped */ | |
| 112 mwSession_UNKNOWN, /**< indicates an error determining state */ | |
| 113 mwSession_LOGIN_CONT, /**< session has sent a login continue */ | |
| 114 }; | |
| 115 | |
| 116 | |
| 117 #define mwSession_isState(session, state) \ | |
| 118 (mwSession_getState((session)) == (state)) | |
| 119 | |
| 120 #define mwSession_isStarting(s) \ | |
| 121 (mwSession_isState((s), mwSession_STARTING) || \ | |
| 122 mwSession_isState((s), mwSession_HANDSHAKE) || \ | |
| 123 mwSession_isState((s), mwSession_HANDSHAKE_ACK) || \ | |
| 124 mwSession_isState((s), mwSession_LOGIN) || \ | |
| 125 mwSession_isState((s), mwSession_LOGIN_ACK) || \ | |
| 126 mwSession_isState((s), mwSession_LOGIN_REDIR) || \ | |
| 127 mwSession_isState((s), mwSession_LOGIN_CONT)) | |
| 128 | |
| 129 #define mwSession_isStarted(s) \ | |
| 130 (mwSession_isState((s), mwSession_STARTED)) | |
| 131 | |
| 132 #define mwSession_isStopping(s) \ | |
| 133 (mwSession_isState((s), mwSession_STOPPING)) | |
| 134 | |
| 135 #define mwSession_isStopped(s) \ | |
| 136 (mwSession_isState((s), mwSession_STOPPED)) | |
| 137 | |
| 138 | |
| 139 /** @struct mwSession | |
| 140 | |
| 141 Represents a Sametime client session */ | |
| 142 struct mwSession; | |
| 143 | |
| 144 | |
| 145 /** @struct mwSessionHandler | |
| 146 | |
| 147 session handler. Structure which interfaces a session with client | |
| 148 code to provide I/O and event handling */ | |
| 149 struct mwSessionHandler { | |
| 150 | |
| 151 /** write data to the server connection. Required. Should return | |
| 152 zero for success, non-zero for error */ | |
| 153 int (*io_write)(struct mwSession *, const char *buf, gsize len); | |
| 154 | |
| 155 /** close the server connection. Required */ | |
| 156 void (*io_close)(struct mwSession *); | |
| 157 | |
| 158 /** triggered by mwSession_free. Optional. Put cleanup code here */ | |
| 159 void (*clear)(struct mwSession *); | |
| 160 | |
| 161 /** Called when the session has changed status. | |
| 162 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
163 @see mwSession_getStateInfo for uses of info field |
| 10969 | 164 |
| 165 @param s the session | |
| 166 @param state the session's state | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
167 @param info additional state information */ |
| 10969 | 168 void (*on_stateChange)(struct mwSession *s, |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
169 enum mwSessionState state, gpointer info); |
| 10969 | 170 |
| 171 /** called when privacy information has been sent or received | |
| 172 | |
| 173 @see mwSession_getPrivacyInfo | |
| 174 */ | |
| 175 void (*on_setPrivacyInfo)(struct mwSession *); | |
| 176 | |
| 177 /** called when user status has changed | |
| 178 | |
| 179 @see mwSession_getUserStatus */ | |
| 180 void (*on_setUserStatus)(struct mwSession *); | |
| 181 | |
| 182 /** called when an admin messages has been received */ | |
| 183 void (*on_admin)(struct mwSession *, const char *text); | |
| 184 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
185 /** called when an announcement arrives */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
186 void (*on_announce)(struct mwSession *, struct mwLoginInfo *from, |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
187 gboolean may_reply, const char *text); |
| 10969 | 188 |
| 189 }; | |
| 190 | |
| 191 | |
| 192 /** allocate a new session */ | |
| 193 struct mwSession *mwSession_new(struct mwSessionHandler *); | |
| 194 | |
| 195 | |
| 196 /** stop, clear, free a session. Does not free contained ciphers or | |
| 197 services, these must be taken care of explicitly. */ | |
| 198 void mwSession_free(struct mwSession *); | |
| 199 | |
| 200 | |
| 201 /** obtain a reference to the session's handler */ | |
| 202 struct mwSessionHandler *mwSession_getHandler(struct mwSession *); | |
| 203 | |
| 204 | |
| 205 /** instruct the session to begin. This will result in the initial | |
| 206 handshake message being sent. */ | |
| 207 void mwSession_start(struct mwSession *); | |
| 208 | |
| 209 | |
| 210 /** instruct the session to shut down with the following reason | |
| 211 code. */ | |
| 212 void mwSession_stop(struct mwSession *, guint32 reason); | |
| 213 | |
| 214 | |
| 215 /** Data is buffered, unpacked, and parsed into a message, then | |
| 216 processed accordingly. */ | |
| 217 void mwSession_recv(struct mwSession *, const char *, gsize); | |
| 218 | |
| 219 | |
| 220 /** primarily used by services to have messages serialized and sent | |
| 221 @param s session to send message over | |
| 222 @param msg message to serialize and send | |
| 223 @returns 0 for success */ | |
| 224 int mwSession_send(struct mwSession *s, struct mwMessage *msg); | |
| 225 | |
| 226 | |
| 227 /** sends the keepalive byte */ | |
| 228 int mwSession_sendKeepalive(struct mwSession *s); | |
| 229 | |
| 230 | |
| 231 /** respond to a login redirect message by forcing the login sequence | |
| 232 to continue through the immediate server. */ | |
| 233 int mwSession_forceLogin(struct mwSession *s); | |
| 234 | |
| 235 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
236 /** send an announcement to a list of users/groups. Targets of |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
237 announcement must be in the same community as the session. |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
238 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
239 @param s session to send announcement from |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
240 @param may_reply permit clients to reply. Not all clients honor this. |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
241 @param text text of announcement |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
242 @param recipients list of recipients. Each recipient is specified |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
243 by a single string, prefix with "@U " for users |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
244 and "@G " for Notes Address Book groups. |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
245 */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
246 int mwSession_sendAnnounce(struct mwSession *s, gboolean may_reply, |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
247 const char *text, const GList *recipients); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
248 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
249 |
| 10969 | 250 /** set the internal privacy information, and inform the server as |
| 251 necessary. Triggers the on_setPrivacyInfo call-back. */ | |
| 252 int mwSession_setPrivacyInfo(struct mwSession *, struct mwPrivacyInfo *); | |
| 253 | |
| 254 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
255 /** direct reference to the session's internal privacy structure */ |
| 10969 | 256 struct mwPrivacyInfo *mwSession_getPrivacyInfo(struct mwSession *); |
| 257 | |
| 258 | |
| 259 /** reference the login information for the session */ | |
| 260 struct mwLoginInfo *mwSession_getLoginInfo(struct mwSession *); | |
| 261 | |
| 262 | |
| 263 /** set the internal user status state, and inform the server as | |
| 264 necessary. Triggers the on_setUserStatus call-back */ | |
| 265 int mwSession_setUserStatus(struct mwSession *, struct mwUserStatus *); | |
| 266 | |
| 267 | |
| 268 struct mwUserStatus *mwSession_getUserStatus(struct mwSession *); | |
| 269 | |
| 270 | |
| 271 /** current status of the session */ | |
| 272 enum mwSessionState mwSession_getState(struct mwSession *); | |
| 273 | |
| 274 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
275 /** additional status-specific information. Depending on the state of |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
276 the session, this value has different meaning. |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
277 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
278 @li @c mwSession_STOPPING guint32 error code causing |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
279 the session to shut down |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
280 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
281 @li @c mwSession_STOPPED guint32 error code causing |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
282 the session to shut down |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
283 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
284 @li @c mwSession_LOGIN_REDIR (char *) host to redirect |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
285 to |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
286 */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
287 gpointer mwSession_getStateInfo(struct mwSession *); |
| 10969 | 288 |
| 289 | |
| 290 struct mwChannelSet *mwSession_getChannels(struct mwSession *); | |
| 291 | |
| 292 | |
| 293 /** adds a service to the session. If the session is started (or when | |
| 294 the session is successfully started) and the service has a start | |
| 295 function, the session will request service availability from the | |
| 296 server. On receipt of the service availability notification, the | |
| 297 session will call the service's start function. | |
| 298 | |
| 299 @return TRUE if the session was added correctly */ | |
| 300 gboolean mwSession_addService(struct mwSession *, struct mwService *); | |
| 301 | |
| 302 | |
| 303 /** find a service by its type identifier */ | |
| 304 struct mwService *mwSession_getService(struct mwSession *, guint32 type); | |
| 305 | |
| 306 | |
| 307 /** removes a service from the session. If the session is started and | |
| 308 the service has a stop function, it will be called. Returns the | |
| 309 removed service */ | |
| 310 struct mwService *mwSession_removeService(struct mwSession *, guint32 type); | |
| 311 | |
| 312 | |
| 313 /** a GList of services in this session. The GList needs to be freed | |
| 314 after use */ | |
| 315 GList *mwSession_getServices(struct mwSession *); | |
| 316 | |
| 317 | |
| 318 /** instruct a STARTED session to check the server for the presense of | |
| 319 a given service. The service will be automatically started upon | |
| 320 receipt of an affirmative reply from the server. This function is | |
| 321 automatically called upon all services in a session when the | |
| 322 session is fully STARTED. | |
| 323 | |
| 324 Services which terminate due to an error may call this on | |
| 325 themselves to re-initialize when their server-side counterpart is | |
| 326 made available again. | |
| 327 | |
| 328 @param s owning session | |
| 329 @param type service type ID */ | |
| 330 void mwSession_senseService(struct mwSession *s, guint32 type); | |
| 331 | |
| 332 | |
| 333 /** adds a cipher to the session. */ | |
| 334 gboolean mwSession_addCipher(struct mwSession *, struct mwCipher *); | |
| 335 | |
| 336 | |
| 337 /** find a cipher by its type identifier */ | |
| 338 struct mwCipher *mwSession_getCipher(struct mwSession *, guint16 type); | |
| 339 | |
| 340 | |
| 341 /** remove a cipher from the session */ | |
| 342 struct mwCipher *mwSession_removeCipher(struct mwSession *, guint16 type); | |
| 343 | |
| 344 | |
| 345 /** a GList of ciphers in this session. The GList needs to be freed | |
| 346 after use */ | |
| 347 GList *mwSession_getCiphers(struct mwSession *); | |
| 348 | |
| 349 | |
| 350 /** associate a key:value pair with the session. If an existing value is | |
| 351 associated with the same key, it will have its clear function called | |
| 352 and will be replaced with the new value */ | |
| 353 void mwSession_setProperty(struct mwSession *, const char *key, | |
| 354 gpointer val, GDestroyNotify clear); | |
| 355 | |
| 356 | |
| 357 /** obtain the value of a previously set property, or NULL */ | |
| 358 gpointer mwSession_getProperty(struct mwSession *, const char *key); | |
| 359 | |
| 360 | |
| 361 /** remove a property, calling the optional GDestroyNotify function | |
| 362 indicated in mwSession_setProperty if applicable */ | |
| 363 void mwSession_removeProperty(struct mwSession *, const char *key); | |
| 364 | |
| 365 | |
| 366 /** associate arbitrary data with the session for use by the client | |
| 367 code. Only client applications should use this, never services. | |
| 368 | |
| 369 @param session the session to associate the data with | |
| 370 @param data arbitrary client data | |
| 371 @param clear optional cleanup function called on data from | |
| 372 mwSession_removeClientData and mwSession_free | |
| 373 */ | |
| 374 void mwSession_setClientData(struct mwSession *session, | |
| 375 gpointer data, GDestroyNotify clear); | |
| 376 | |
| 377 | |
| 378 gpointer mwSession_getClientData(struct mwSession *session); | |
| 379 | |
| 380 | |
| 381 /** remove client data, calling the optional GDestroyNotify function | |
| 382 indicated in mwSession_setClientData if applicable */ | |
| 383 void mwSession_removeClientData(struct mwSession *session); | |
| 384 | |
| 385 | |
| 386 #endif | |
| 387 |
