comparison libpurple/protocols/msn/msg.h @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /**
2 * @file msg.h Message functions
3 *
4 * gaim
5 *
6 * Gaim 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
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
37 /*
38 typedef enum
39 {
40 MSN_MSG_NORMAL,
41 MSN_MSG_SLP_SB,
42 MSN_MSG_SLP_DC
43
44 } MsnMsgType;
45 */
46
47 typedef enum
48 {
49 MSN_MSG_UNKNOWN,
50 MSN_MSG_TEXT,
51 MSN_MSG_TYPING,
52 MSN_MSG_CAPS,
53 MSN_MSG_SLP,
54 MSN_MSG_NUDGE
55
56 } MsnMsgType;
57
58 typedef enum
59 {
60 MSN_MSG_ERROR_NONE, /**< No error. */
61 MSN_MSG_ERROR_TIMEOUT, /**< The message timedout. */
62 MSN_MSG_ERROR_NAK, /**< The message could not be sent. */
63 MSN_MSG_ERROR_SB, /**< The error comes from the switchboard. */
64 MSN_MSG_ERROR_UNKNOWN /**< An unknown error occurred. */
65
66 } MsnMsgErrorType;
67
68 typedef struct
69 {
70 guint32 session_id;
71 guint32 id;
72 guint64 offset;
73 guint64 total_size;
74 guint32 length;
75 guint32 flags;
76 guint32 ack_id;
77 guint32 ack_sub_id;
78 guint64 ack_size;
79
80 } MsnSlpHeader;
81
82 typedef struct
83 {
84 guint32 value;
85
86 } MsnSlpFooter;
87
88 /**
89 * A message.
90 */
91 struct _MsnMessage
92 {
93 size_t ref_count; /**< The reference count. */
94
95 MsnMsgType type;
96
97 gboolean msnslp_message;
98
99 char *remote_user;
100 char flag;
101
102 char *content_type;
103 char *charset;
104 char *body;
105 gsize body_len;
106
107 MsnSlpHeader msnslp_header;
108 MsnSlpFooter msnslp_footer;
109
110 GHashTable *attr_table;
111 GList *attr_list;
112
113 gboolean ack_ref; /**< A flag that states if this message has
114 been ref'ed for using it in a callback. */
115
116 MsnCommand *cmd;
117 MsnTransaction *trans;
118
119 MsnMsgCb ack_cb; /**< The callback to call when we receive an ACK of this
120 message. */
121 MsnMsgCb nak_cb; /**< The callback to call when we receive a NAK of this
122 message. */
123 void *ack_data; /**< The data used by callbacks. */
124
125 MsnMsgErrorType error; /**< The error of the message. */
126 };
127
128 /**
129 * Creates a new, empty message.
130 *
131 * @return A new message.
132 */
133 MsnMessage *msn_message_new(MsnMsgType type);
134
135 /**
136 * Creates a new, empty MSNSLP message.
137 *
138 * @return A new MSNSLP message.
139 */
140 MsnMessage *msn_message_new_msnslp(void);
141
142 /**
143 * Creates a new nudge message.
144 *
145 * @return A new nudge message.
146 */
147 MsnMessage *msn_message_new_nudge(void);
148
149 /**
150 * Creates a new plain message.
151 *
152 * @return A new plain message.
153 */
154 MsnMessage *msn_message_new_plain(const char *message);
155
156 /**
157 * Creates a MSNSLP ack message.
158 *
159 * @param acked_msg The message to acknowledge.
160 *
161 * @return A new MSNSLP ack message.
162 */
163 MsnMessage *msn_message_new_msnslp_ack(MsnMessage *acked_msg);
164
165 /**
166 * Creates a new message based off a command.
167 *
168 * @param session The MSN session.
169 * @param cmd The command.
170 *
171 * @return The new message.
172 */
173 MsnMessage *msn_message_new_from_cmd(MsnSession *session, MsnCommand *cmd);
174
175 /**
176 * Parses the payload of a message.
177 *
178 * @param msg The message.
179 * @param payload The payload.
180 * @param payload_len The length of the payload.
181 */
182 void msn_message_parse_payload(MsnMessage *msg, const char *payload,
183 size_t payload_len);
184
185 /**
186 * Destroys a message.
187 *
188 * @param msg The message to destroy.
189 */
190 void msn_message_destroy(MsnMessage *msg);
191
192 /**
193 * Increments the reference count on a message.
194 *
195 * @param msg The message.
196 *
197 * @return @a msg
198 */
199 MsnMessage *msn_message_ref(MsnMessage *msg);
200
201 /**
202 * Decrements the reference count on a message.
203 *
204 * This will destroy the structure if the count hits 0.
205 *
206 * @param msg The message.
207 *
208 * @return @a msg, or @c NULL if the new count is 0.
209 */
210 MsnMessage *msn_message_unref(MsnMessage *msg);
211
212 /**
213 * Generates the payload data of a message.
214 *
215 * @param msg The message.
216 * @param ret_size The returned size of the payload.
217 *
218 * @return The payload data of the message.
219 */
220 char *msn_message_gen_payload(MsnMessage *msg, size_t *ret_size);
221
222 /**
223 * Sets the flag for an outgoing message.
224 *
225 * @param msg The message.
226 * @param flag The flag.
227 */
228 void msn_message_set_flag(MsnMessage *msg, char flag);
229
230 /**
231 * Returns the flag for an outgoing message.
232 *
233 * @param msg The message.
234 *
235 * @return The flag.
236 */
237 char msn_message_get_flag(const MsnMessage *msg);
238
239 #if 0
240 /**
241 * Sets the body of a message.
242 *
243 * @param msg The message.
244 * @param body The body of the message.
245 */
246 void msn_message_set_body(MsnMessage *msg, const char *body);
247
248 /**
249 * Returns the body of the message.
250 *
251 * @param msg The message.
252 *
253 * @return The body of the message.
254 */
255 const char *msn_message_get_body(const MsnMessage *msg);
256 #endif
257 /**
258 * Sets the binary content of the message.
259 *
260 * @param msg The message.
261 * @param data The binary data.
262 * @param len The length of the data.
263 */
264 void msn_message_set_bin_data(MsnMessage *msg, const void *data, size_t len);
265
266 /**
267 * Returns the binary content of the message.
268 *
269 * @param msg The message.
270 * @param len The returned length of the data.
271 *
272 * @return The binary data.
273 */
274 const void *msn_message_get_bin_data(const MsnMessage *msg, size_t *len);
275
276 /**
277 * Sets the content type in a message.
278 *
279 * @param msg The message.
280 * @param type The content-type.
281 */
282 void msn_message_set_content_type(MsnMessage *msg, const char *type);
283
284 /**
285 * Returns the content type in a message.
286 *
287 * @param msg The message.
288 *
289 * @return The content-type.
290 */
291 const char *msn_message_get_content_type(const MsnMessage *msg);
292
293 /**
294 * Sets the charset in a message.
295 *
296 * @param msg The message.
297 * @param charset The charset.
298 */
299 void msn_message_set_charset(MsnMessage *msg, const char *charset);
300
301 /**
302 * Returns the charset in a message.
303 *
304 * @param msg The message.
305 *
306 * @return The charset.
307 */
308 const char *msn_message_get_charset(const MsnMessage *msg);
309
310 /**
311 * Sets an attribute in a message.
312 *
313 * @param msg The message.
314 * @param attr The attribute name.
315 * @param value The attribute value.
316 */
317 void msn_message_set_attr(MsnMessage *msg, const char *attr,
318 const char *value);
319
320 /**
321 * Returns an attribute from a message.
322 *
323 * @param msg The message.
324 * @param attr The attribute.
325 *
326 * @return The value, or @c NULL if not found.
327 */
328 const char *msn_message_get_attr(const MsnMessage *msg, const char *attr);
329
330 /**
331 * Parses the body and returns it in the form of a hashtable.
332 *
333 * @param msg The message.
334 *
335 * @return The resulting hashtable.
336 */
337 GHashTable *msn_message_get_hashtable_from_body(const MsnMessage *msg);
338
339 void msn_message_show_readable(MsnMessage *msg, const char *info,
340 gboolean text_body);
341
342 void msn_message_parse_slp_body(MsnMessage *msg, const char *body,
343 size_t len);
344
345 char *msn_message_gen_slp_body(MsnMessage *msg, size_t *ret_size);
346
347 char *msn_message_to_string(MsnMessage *msg);
348
349 #endif /* _MSN_MSG_H_ */