~ubuntu-branches/ubuntu/raring/pidgin/raring

1 by Ari Pollak
Import upstream version 2.0.0+dfsg.1
1
/**
2
 * @file msg.h Message functions
3
 *
4
 * purple
5
 *
6
 * Purple is the legal property of its developers, whose names are too numerous
7
 * to list here.  Please refer to the COPYRIGHT file distributed with this
8
 * source distribution.
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
1.1.4 by Sebastien Bacher
Import upstream version 2.2.0
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
1 by Ari Pollak
Import upstream version 2.0.0+dfsg.1
23
 */
24
#ifndef _MSN_MSG_H_
25
#define _MSN_MSG_H_
26
27
typedef struct _MsnMessage MsnMessage;
28
29
#include "session.h"
30
#include "user.h"
31
32
#include "command.h"
33
#include "transaction.h"
34
35
typedef void (*MsnMsgCb)(MsnMessage *, void *data);
36
1.1.7 by Pedro Fragoso
Import upstream version 2.3.1
37
#define MSG_BODY_DEM	"\r\n\r\n"
38
#define MSG_LINE_DEM	"\r\n"
39
40
#define MSG_OIM_BODY_DEM	"\n\n"
41
#define MSG_OIM_LINE_DEM	"\n"
42
1 by Ari Pollak
Import upstream version 2.0.0+dfsg.1
43
/*
44
typedef enum
45
{
46
	MSN_MSG_NORMAL,
47
	MSN_MSG_SLP_SB,
48
	MSN_MSG_SLP_DC
49
50
} MsnMsgType;
51
*/
52
53
typedef enum
54
{
55
	MSN_MSG_UNKNOWN,
56
	MSN_MSG_TEXT,
57
	MSN_MSG_TYPING,
58
	MSN_MSG_CAPS,
59
	MSN_MSG_SLP,
60
	MSN_MSG_NUDGE
61
62
} MsnMsgType;
63
64
typedef enum
65
{
66
	MSN_MSG_ERROR_NONE, /**< No error. */
67
	MSN_MSG_ERROR_TIMEOUT, /**< The message timedout. */
68
	MSN_MSG_ERROR_NAK, /**< The message could not be sent. */
69
	MSN_MSG_ERROR_SB, /**< The error comes from the switchboard. */
70
	MSN_MSG_ERROR_UNKNOWN /**< An unknown error occurred. */
71
72
} MsnMsgErrorType;
73
74
typedef struct
75
{
76
	guint32 session_id;
77
	guint32 id;
78
	guint64 offset;
79
	guint64 total_size;
80
	guint32 length;
81
	guint32 flags;
82
	guint32 ack_id;
83
	guint32 ack_sub_id;
84
	guint64 ack_size;
85
86
} MsnSlpHeader;
87
88
typedef struct
89
{
90
	guint32 value;
91
92
} MsnSlpFooter;
93
94
/**
95
 * A message.
96
 */
97
struct _MsnMessage
98
{
99
	size_t ref_count;           /**< The reference count.       */
100
101
	MsnMsgType type;
102
103
	gboolean msnslp_message;
104
105
	char *remote_user;
106
	char flag;
107
108
	char *content_type;
109
	char *charset;
110
	char *body;
111
	gsize body_len;
112
113
	MsnSlpHeader msnslp_header;
114
	MsnSlpFooter msnslp_footer;
115
116
	GHashTable *attr_table;
117
	GList *attr_list;
118
119
	gboolean ack_ref;           /**< A flag that states if this message has
120
								  been ref'ed for using it in a callback. */
121
122
	MsnCommand *cmd;
123
	MsnTransaction *trans;
124
125
	MsnMsgCb ack_cb; /**< The callback to call when we receive an ACK of this
126
					   message. */
127
	MsnMsgCb nak_cb; /**< The callback to call when we receive a NAK of this
128
					   message. */
129
	void *ack_data; /**< The data used by callbacks. */
130
131
	MsnMsgErrorType error; /**< The error of the message. */
1.1.14 by Sebastien Bacher
Import upstream version 2.5.2
132
133
	guint32 retries;
1 by Ari Pollak
Import upstream version 2.0.0+dfsg.1
134
};
135
136
/**
137
 * Creates a new, empty message.
138
 *
139
 * @return A new message.
140
 */
141
MsnMessage *msn_message_new(MsnMsgType type);
142
143
/**
144
 * Creates a new, empty MSNSLP message.
145
 *
146
 * @return A new MSNSLP message.
147
 */
148
MsnMessage *msn_message_new_msnslp(void);
149
150
/**
151
 * Creates a new nudge message.
152
 *
153
 * @return A new nudge message.
154
 */
155
MsnMessage *msn_message_new_nudge(void);
156
157
/**
158
 * Creates a new plain message.
159
 *
160
 * @return A new plain message.
161
 */
162
MsnMessage *msn_message_new_plain(const char *message);
163
164
/**
165
 * Creates a MSNSLP ack message.
166
 *
167
 * @param acked_msg The message to acknowledge.
168
 *
169
 * @return A new MSNSLP ack message.
170
 */
171
MsnMessage *msn_message_new_msnslp_ack(MsnMessage *acked_msg);
172
173
/**
174
 * Creates a new message based off a command.
175
 *
176
 * @param session The MSN session.
177
 * @param cmd     The command.
178
 *
179
 * @return The new message.
180
 */
181
MsnMessage *msn_message_new_from_cmd(MsnSession *session, MsnCommand *cmd);
182
183
/**
184
 * Parses the payload of a message.
185
 *
186
 * @param msg         The message.
187
 * @param payload     The payload.
188
 * @param payload_len The length of the payload.
189
 */
190
void msn_message_parse_payload(MsnMessage *msg, const char *payload,
1.1.7 by Pedro Fragoso
Import upstream version 2.3.1
191
							   size_t payload_len,
192
						  const char *line_dem,const char *body_dem);
1 by Ari Pollak
Import upstream version 2.0.0+dfsg.1
193
194
/**
195
 * Destroys a message.
196
 *
197
 * @param msg The message to destroy.
198
 */
199
void msn_message_destroy(MsnMessage *msg);
200
201
/**
202
 * Increments the reference count on a message.
203
 *
204
 * @param msg The message.
205
 *
206
 * @return @a msg
207
 */
208
MsnMessage *msn_message_ref(MsnMessage *msg);
209
210
/**
211
 * Decrements the reference count on a message.
212
 *
213
 * This will destroy the structure if the count hits 0.
214
 *
215
 * @param msg The message.
216
 *
217
 * @return @a msg, or @c NULL if the new count is 0.
218
 */
219
MsnMessage *msn_message_unref(MsnMessage *msg);
220
221
/**
222
 * Generates the payload data of a message.
223
 *
224
 * @param msg      The message.
225
 * @param ret_size The returned size of the payload.
226
 *
227
 * @return The payload data of the message.
228
 */
229
char *msn_message_gen_payload(MsnMessage *msg, size_t *ret_size);
230
231
/**
232
 * Sets the flag for an outgoing message.
233
 *
234
 * @param msg  The message.
235
 * @param flag The flag.
236
 */
237
void msn_message_set_flag(MsnMessage *msg, char flag);
238
239
/**
240
 * Returns the flag for an outgoing message.
241
 *
242
 * @param msg The message.
243
 *
244
 * @return The flag.
245
 */
246
char msn_message_get_flag(const MsnMessage *msg);
247
248
/**
249
 * Sets the binary content of the message.
250
 *
251
 * @param msg  The message.
252
 * @param data The binary data.
253
 * @param len  The length of the data.
254
 */
255
void msn_message_set_bin_data(MsnMessage *msg, const void *data, size_t len);
256
257
/**
258
 * Returns the binary content of the message.
259
 *
260
 * @param msg The message.
261
 * @param len The returned length of the data.
262
 *
263
 * @return The binary data.
264
 */
265
const void *msn_message_get_bin_data(const MsnMessage *msg, size_t *len);
266
267
/**
268
 * Sets the content type in a message.
269
 *
270
 * @param msg  The message.
271
 * @param type The content-type.
272
 */
273
void msn_message_set_content_type(MsnMessage *msg, const char *type);
274
275
/**
276
 * Returns the content type in a message.
277
 *
278
 * @param msg The message.
279
 *
280
 * @return The content-type.
281
 */
282
const char *msn_message_get_content_type(const MsnMessage *msg);
283
284
/**
285
 * Sets the charset in a message.
286
 *
287
 * @param msg     The message.
288
 * @param charset The charset.
289
 */
290
void msn_message_set_charset(MsnMessage *msg, const char *charset);
291
292
/**
293
 * Returns the charset in a message.
294
 *
295
 * @param msg The message.
296
 *
297
 * @return The charset.
298
 */
299
const char *msn_message_get_charset(const MsnMessage *msg);
300
301
/**
302
 * Sets an attribute in a message.
303
 *
304
 * @param msg   The message.
305
 * @param attr  The attribute name.
306
 * @param value The attribute value.
307
 */
308
void msn_message_set_attr(MsnMessage *msg, const char *attr,
309
						  const char *value);
310
311
/**
312
 * Returns an attribute from a message.
313
 *
314
 * @param msg  The message.
315
 * @param attr The attribute.
316
 *
317
 * @return The value, or @c NULL if not found.
318
 */
319
const char *msn_message_get_attr(const MsnMessage *msg, const char *attr);
320
321
/**
322
 * Parses the body and returns it in the form of a hashtable.
323
 *
324
 * @param msg The message.
325
 *
326
 * @return The resulting hashtable.
327
 */
328
GHashTable *msn_message_get_hashtable_from_body(const MsnMessage *msg);
329
330
void msn_message_show_readable(MsnMessage *msg, const char *info,
331
							   gboolean text_body);
332
333
void msn_message_parse_slp_body(MsnMessage *msg, const char *body,
334
								size_t len);
335
336
char *msn_message_gen_slp_body(MsnMessage *msg, size_t *ret_size);
337
338
char *msn_message_to_string(MsnMessage *msg);
339
340
#endif /* _MSN_MSG_H_ */