00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _MW_SESSION_H
00022 #define _MW_SESSION_H
00023
00024
00047 #include "mw_common.h"
00048
00049
00050 #ifdef __cplusplus
00051 extern "C" {
00052 #endif
00053
00054
00055 struct mwChannelSet;
00056 struct mwCipher;
00057 struct mwMessage;
00058 struct mwService;
00059
00060
00062 #define MW_PROTOCOL_VERSION_MAJOR 0x001e
00063
00064
00066 #define MW_PROTOCOL_VERSION_MINOR 0x001d
00067
00068
00073
00075 #define mwSession_AUTH_USER_ID "session.auth.user"
00076
00078 #define mwSession_AUTH_PASSWORD "session.auth.password"
00079
00081 #define mwSession_AUTH_TOKEN "session.auth.token"
00082
00084 #define mwSession_CLIENT_HOST "client.host"
00085
00087 #define mwSession_CLIENT_IP "client.ip"
00088
00090 #define mwSession_CLIENT_VER_MAJOR "client.version.major"
00091
00093 #define mwSession_CLIENT_VER_MINOR "client.version.minor"
00094
00096 #define mwSession_CLIENT_TYPE_ID "client.id"
00097
00099 #define mwSession_SERVER_VER_MAJOR "server.version.major"
00100
00102 #define mwSession_SERVER_VER_MINOR "server.version.minor"
00103
00107 enum mwSessionState {
00108 mwSession_STARTING,
00109 mwSession_HANDSHAKE,
00110 mwSession_HANDSHAKE_ACK,
00111 mwSession_LOGIN,
00112 mwSession_LOGIN_REDIR,
00113 mwSession_LOGIN_ACK,
00114 mwSession_STARTED,
00115 mwSession_STOPPING,
00116 mwSession_STOPPED,
00117 mwSession_UNKNOWN,
00118 mwSession_LOGIN_CONT,
00119 };
00120
00121
00122 #define mwSession_isState(session, state) \
00123 (mwSession_getState((session)) == (state))
00124
00125 #define mwSession_isStarting(s) \
00126 (mwSession_isState((s), mwSession_STARTING) || \
00127 mwSession_isState((s), mwSession_HANDSHAKE) || \
00128 mwSession_isState((s), mwSession_HANDSHAKE_ACK) || \
00129 mwSession_isState((s), mwSession_LOGIN) || \
00130 mwSession_isState((s), mwSession_LOGIN_ACK) || \
00131 mwSession_isState((s), mwSession_LOGIN_REDIR) || \
00132 mwSession_isState((s), mwSession_LOGIN_CONT))
00133
00134 #define mwSession_isStarted(s) \
00135 (mwSession_isState((s), mwSession_STARTED))
00136
00137 #define mwSession_isStopping(s) \
00138 (mwSession_isState((s), mwSession_STOPPING))
00139
00140 #define mwSession_isStopped(s) \
00141 (mwSession_isState((s), mwSession_STOPPED))
00142
00143
00147 struct mwSession;
00148
00149
00154 struct mwSessionHandler {
00155
00158 int (*io_write)(struct mwSession *, const guchar *buf, gsize len);
00159
00161 void (*io_close)(struct mwSession *);
00162
00164 void (*clear)(struct mwSession *);
00165
00173 void (*on_stateChange)(struct mwSession *s,
00174 enum mwSessionState state, gpointer info);
00175
00180 void (*on_setPrivacyInfo)(struct mwSession *);
00181
00185 void (*on_setUserStatus)(struct mwSession *);
00186
00188 void (*on_admin)(struct mwSession *, const char *text);
00189
00191 void (*on_announce)(struct mwSession *, struct mwLoginInfo *from,
00192 gboolean may_reply, const char *text);
00193
00194 };
00195
00196
00198 struct mwSession *mwSession_new(struct mwSessionHandler *);
00199
00200
00203 void mwSession_free(struct mwSession *);
00204
00205
00207 struct mwSessionHandler *mwSession_getHandler(struct mwSession *);
00208
00209
00212 void mwSession_start(struct mwSession *);
00213
00214
00217 void mwSession_stop(struct mwSession *, guint32 reason);
00218
00219
00222 void mwSession_recv(struct mwSession *, const guchar *, gsize);
00223
00224
00229 int mwSession_send(struct mwSession *s, struct mwMessage *msg);
00230
00231
00233 int mwSession_sendKeepalive(struct mwSession *s);
00234
00235
00238 int mwSession_forceLogin(struct mwSession *s);
00239
00240
00251 int mwSession_sendAnnounce(struct mwSession *s, gboolean may_reply,
00252 const char *text, const GList *recipients);
00253
00254
00257 int mwSession_setPrivacyInfo(struct mwSession *, struct mwPrivacyInfo *);
00258
00259
00261 struct mwPrivacyInfo *mwSession_getPrivacyInfo(struct mwSession *);
00262
00263
00265 struct mwLoginInfo *mwSession_getLoginInfo(struct mwSession *);
00266
00267
00270 int mwSession_setUserStatus(struct mwSession *, struct mwUserStatus *);
00271
00272
00273 struct mwUserStatus *mwSession_getUserStatus(struct mwSession *);
00274
00275
00277 enum mwSessionState mwSession_getState(struct mwSession *);
00278
00279
00292 gpointer mwSession_getStateInfo(struct mwSession *);
00293
00294
00295 struct mwChannelSet *mwSession_getChannels(struct mwSession *);
00296
00297
00305 gboolean mwSession_addService(struct mwSession *, struct mwService *);
00306
00307
00309 struct mwService *mwSession_getService(struct mwSession *, guint32 type);
00310
00311
00315 struct mwService *mwSession_removeService(struct mwSession *, guint32 type);
00316
00317
00320 GList *mwSession_getServices(struct mwSession *);
00321
00322
00335 void mwSession_senseService(struct mwSession *s, guint32 type);
00336
00337
00339 gboolean mwSession_addCipher(struct mwSession *, struct mwCipher *);
00340
00341
00343 struct mwCipher *mwSession_getCipher(struct mwSession *, guint16 type);
00344
00345
00347 struct mwCipher *mwSession_removeCipher(struct mwSession *, guint16 type);
00348
00349
00352 GList *mwSession_getCiphers(struct mwSession *);
00353
00354
00358 void mwSession_setProperty(struct mwSession *, const char *key,
00359 gpointer val, GDestroyNotify clear);
00360
00361
00363 gpointer mwSession_getProperty(struct mwSession *, const char *key);
00364
00365
00368 void mwSession_removeProperty(struct mwSession *, const char *key);
00369
00370
00379 void mwSession_setClientData(struct mwSession *session,
00380 gpointer data, GDestroyNotify clear);
00381
00382
00383 gpointer mwSession_getClientData(struct mwSession *session);
00384
00385
00388 void mwSession_removeClientData(struct mwSession *session);
00389
00390
00391 #ifdef __cplusplus
00392 }
00393 #endif
00394
00395
00396 #endif
00397