File: mw_srvc_im.h

package info (click to toggle)
meanwhile 1.0.2-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,732 kB
  • ctags: 3,503
  • sloc: ansic: 13,856; sh: 8,360; makefile: 145
file content (276 lines) | stat: -rw-r--r-- 8,622 bytes parent folder | download | duplicates (5)
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

/*
  Meanwhile - Unofficial Lotus Sametime Community Client Library
  Copyright (C) 2004  Christopher (siege) O'Brien
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.
  
  This library 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
  Library General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _MW_SRVC_IM_H
#define _MW_SRVC_IM_H


/** @file mw_srvc_im.h

    The IM service provides one-on-one communication between
    users. Messages sent over conversations may relay different types
    of information, in a variety of formats. The basic feature-set
    provides plain-text chat with typing notification. More complex
    features may be negotiated transparently by setting the IM Client
    Type for a conversation, or for the service as a whole.
*/


#include <glib.h>
#include "mw_common.h"


#ifdef __cplusplus
extern "C" {
#endif
  
  
/* identifier for the IM service */
#define mwService_IM  0x00001000
  
  
/** @struct mwServiceIm

    An instance of the IM service. This service provides simple
    instant messaging functionality */
struct mwServiceIm;


/** @struct mwConversation

    A conversation between the local service and a single other user */
struct mwConversation;


enum mwImClientType {
  mwImClient_PLAIN       = 0x00000001,  /**< text, typing */
  mwImClient_NOTESBUDDY  = 0x00033453,  /**< adds html, subject, mime */
  mwImClient_PRECONF     = 0x00000019,  /**< pre-conference, legacy */
  mwImClient_UNKNOWN     = 0xffffffff,  /**< trouble determining type */
};


/**
   Types of supported messages. When a conversation is created, the
   least common denominator of features between either side of the
   conversation (based on what features are available in the IM
   service itself) becomes the set of supported features for that
   conversation. At any point, the feature set for the service may
   change, without affecting any existing conversations.

   @see mwServiceIm_supports
   @see mwServiceIm_setSupported
   @see mwConversation_supports
   @see mwConversation_send
   @see mwServiceImHandler::conversation_recv
 */
enum mwImSendType {
  mwImSend_PLAIN,   /**< char *, plain-text message */
  mwImSend_TYPING,  /**< gboolean, typing status */
  mwImSend_HTML,    /**< char *, HTML formatted message (NOTESBUDDY) */
  mwImSend_SUBJECT, /**< char *, conversation subject (NOTESBUDDY) */
  mwImSend_MIME,    /**< char *, MIME-encoded message (NOTESBUDDY) */
  mwImSend_TIMESTAMP, /**< char *, YYYY:MM:DD:HH:mm:SS format (NOTESBUDDY) */
};



/** @see mwConversation_getState */
enum mwConversationState {
  mwConversation_CLOSED,   /**< conversation is not open */
  mwConversation_PENDING,  /**< conversation is opening */
  mwConversation_OPEN,     /**< conversation is open */
  mwConversation_UNKNOWN,  /**< unknown state */
};


#define mwConversation_isState(conv, state) \
  (mwConversation_getState(conv) == (state))

#define mwConversation_isClosed(conv) \
  mwConversation_isState((conv), mwConversation_CLOSED)

#define mwConversation_isPending(conv) \
  mwConversation_isState((conv), mwConversation_PENDING)

#define mwConversation_isOpen(conv) \
  mwConversation_isState((conv), mwConversation_OPEN)



/** IM Service Handler. Provides functions for events triggered from an
    IM service instance. */
struct mwImHandler {

  /** A conversation has been successfully opened */
  void (*conversation_opened)(struct mwConversation *conv);

  /** A conversation has been closed */
  void (*conversation_closed)(struct mwConversation *conv, guint32 err);
  
  /** A message has been received on a conversation */
  void (*conversation_recv)(struct mwConversation *conv,
			    enum mwImSendType type, gconstpointer msg);

  /** Handle a Place invitation. Set this to NULL and we should end up
      receiving a conference invitation instead. */
  void (*place_invite)(struct mwConversation *conv,
		       const char *message,
		       const char *title, const char *name);

  /** optional. called from mwService_free */
  void (*clear)(struct mwServiceIm *srvc);
};


struct mwServiceIm *mwServiceIm_new(struct mwSession *session,
				    struct mwImHandler *handler);


struct mwImHandler *mwServiceIm_getHandler(struct mwServiceIm *srvc);


/** reference an existing conversation to target, or create a new
    conversation to target if one does not already exist */
struct mwConversation *mwServiceIm_getConversation(struct mwServiceIm *srvc,
						   struct mwIdBlock *target);


/** reference an existing conversation to target */
struct mwConversation *mwServiceIm_findConversation(struct mwServiceIm *srvc,
						    struct mwIdBlock *target);


/** determine if the conversations created from this service will
    support a given send type */
gboolean mwServiceIm_supports(struct mwServiceIm *srvc,
			      enum mwImSendType type);


/** Set the default client type for the service. Newly created
    conversations will attempt to meet this level of functionality
    first.

    @param srvc       the IM service
    @param type       the send type to enable/disable
*/
void mwServiceIm_setClientType(struct mwServiceIm *srvc,
			       enum mwImClientType type);


enum mwImClientType mwServiceIm_getClientType(struct mwServiceIm *srvc);


/** attempt to open a conversation. If the conversation was not
    already open and it is accepted,
    mwServiceImHandler::conversation_opened will be triggered. Upon
    failure, mwServiceImHandler::conversation_closed will be
    triggered */
void mwConversation_open(struct mwConversation *conv);


/** close a conversation. If the conversation was not already closed,
    mwServiceImHandler::conversation_closed will be triggered */
void mwConversation_close(struct mwConversation *conv, guint32 err);


/** determine whether a conversation supports the given message type */
gboolean mwConversation_supports(struct mwConversation *conv,
				 enum mwImSendType type);


enum mwImClientType mwConversation_getClientType(struct mwConversation *conv);


/** get the state of a conversation

    @see mwConversation_isOpen
    @see mwConversation_isClosed
    @see mwConversation_isPending
*/
enum mwConversationState mwConversation_getState(struct mwConversation *conv);


/** send a message over an open conversation */
int mwConversation_send(struct mwConversation *conv,
			enum mwImSendType type, gconstpointer send);


/** @returns owning service for a conversation */
struct mwServiceIm *mwConversation_getService(struct mwConversation *conv);


/** login information for conversation partner. returns NULL if conversation 
    is not OPEN */
struct mwLoginInfo *mwConversation_getTargetInfo(struct mwConversation *conv);


/** ID for conversation partner */
struct mwIdBlock *mwConversation_getTarget(struct mwConversation *conv);


/** set whether outgoing messages should be encrypted using the
    negotiated cipher, if any */
void mwConversation_setEncrypted(struct mwConversation *conv,
				 gboolean useCipher);


/** determine whether outgoing messages are being encrypted */
gboolean mwConversation_isEncrypted(struct mwConversation *conv);


/** Associates client data with a conversation. If there is existing data,
    it will not have its cleanup function called.

    @see mwConversation_getClientData
    @see mwConversation_removeClientData
*/
void mwConversation_setClientData(struct mwConversation *conv,
				  gpointer data, GDestroyNotify clean);


/** Reference associated client data

    @see mwConversation_setClientData
    @see mwConversation_removeClientData
 */
gpointer mwConversation_getClientData(struct mwConversation *conv);


/** Remove any associated client data, calling the optional cleanup
    function if one was provided

    @see mwConversation_setClientData
    @see mwConversation_getClientData
*/
void mwConversation_removeClientData(struct mwConversation *conv);


/** close and destroy the conversation and its backing channel, and
    call the optional client data cleanup function */
void mwConversation_free(struct mwConversation *conv);


#ifdef __cplusplus
}
#endif


#endif /* _MW_SRVC_IM_H */