| |
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 #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 |
| |
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. */ |
| |
132 }; |
| |
133 |
| |
134 /** |
| |
135 * Creates a new, empty message. |
| |
136 * |
| |
137 * @return A new message. |
| |
138 */ |
| |
139 MsnMessage *msn_message_new(MsnMsgType type); |
| |
140 |
| |
141 /** |
| |
142 * Creates a new, empty MSNSLP message. |
| |
143 * |
| |
144 * @return A new MSNSLP message. |
| |
145 */ |
| |
146 MsnMessage *msn_message_new_msnslp(void); |
| |
147 |
| |
148 /** |
| |
149 * Creates a new nudge message. |
| |
150 * |
| |
151 * @return A new nudge message. |
| |
152 */ |
| |
153 MsnMessage *msn_message_new_nudge(void); |
| |
154 |
| |
155 /** |
| |
156 * Creates a new plain message. |
| |
157 * |
| |
158 * @return A new plain message. |
| |
159 */ |
| |
160 MsnMessage *msn_message_new_plain(const char *message); |
| |
161 |
| |
162 /** |
| |
163 * Creates a MSNSLP ack message. |
| |
164 * |
| |
165 * @param acked_msg The message to acknowledge. |
| |
166 * |
| |
167 * @return A new MSNSLP ack message. |
| |
168 */ |
| |
169 MsnMessage *msn_message_new_msnslp_ack(MsnMessage *acked_msg); |
| |
170 |
| |
171 /** |
| |
172 * Creates a new message based off a command. |
| |
173 * |
| |
174 * @param session The MSN session. |
| |
175 * @param cmd The command. |
| |
176 * |
| |
177 * @return The new message. |
| |
178 */ |
| |
179 MsnMessage *msn_message_new_from_cmd(MsnSession *session, MsnCommand *cmd); |
| |
180 |
| |
181 /** |
| |
182 * Parses the payload of a message. |
| |
183 * |
| |
184 * @param msg The message. |
| |
185 * @param payload The payload. |
| |
186 * @param payload_len The length of the payload. |
| |
187 */ |
| |
188 void msn_message_parse_payload(MsnMessage *msg, const char *payload, |
| |
189 size_t payload_len, |
| |
190 const char *line_dem,const char *body_dem); |
| |
191 |
| |
192 /** |
| |
193 * Destroys a message. |
| |
194 * |
| |
195 * @param msg The message to destroy. |
| |
196 */ |
| |
197 void msn_message_destroy(MsnMessage *msg); |
| |
198 |
| |
199 /** |
| |
200 * Increments the reference count on a message. |
| |
201 * |
| |
202 * @param msg The message. |
| |
203 * |
| |
204 * @return @a msg |
| |
205 */ |
| |
206 MsnMessage *msn_message_ref(MsnMessage *msg); |
| |
207 |
| |
208 /** |
| |
209 * Decrements the reference count on a message. |
| |
210 * |
| |
211 * This will destroy the structure if the count hits 0. |
| |
212 * |
| |
213 * @param msg The message. |
| |
214 * |
| |
215 * @return @a msg, or @c NULL if the new count is 0. |
| |
216 */ |
| |
217 MsnMessage *msn_message_unref(MsnMessage *msg); |
| |
218 |
| |
219 /** |
| |
220 * Generates the payload data of a message. |
| |
221 * |
| |
222 * @param msg The message. |
| |
223 * @param ret_size The returned size of the payload. |
| |
224 * |
| |
225 * @return The payload data of the message. |
| |
226 */ |
| |
227 char *msn_message_gen_payload(MsnMessage *msg, size_t *ret_size); |
| |
228 |
| |
229 /** |
| |
230 * Sets the flag for an outgoing message. |
| |
231 * |
| |
232 * @param msg The message. |
| |
233 * @param flag The flag. |
| |
234 */ |
| |
235 void msn_message_set_flag(MsnMessage *msg, char flag); |
| |
236 |
| |
237 /** |
| |
238 * Returns the flag for an outgoing message. |
| |
239 * |
| |
240 * @param msg The message. |
| |
241 * |
| |
242 * @return The flag. |
| |
243 */ |
| |
244 char msn_message_get_flag(const MsnMessage *msg); |
| |
245 |
| |
246 #if 0 |
| |
247 /** |
| |
248 * Sets the body of a message. |
| |
249 * |
| |
250 * @param msg The message. |
| |
251 * @param body The body of the message. |
| |
252 */ |
| |
253 void msn_message_set_body(MsnMessage *msg, const char *body); |
| |
254 |
| |
255 /** |
| |
256 * Returns the body of the message. |
| |
257 * |
| |
258 * @param msg The message. |
| |
259 * |
| |
260 * @return The body of the message. |
| |
261 */ |
| |
262 const char *msn_message_get_body(const MsnMessage *msg); |
| |
263 #endif |
| |
264 /** |
| |
265 * Sets the binary content of the message. |
| |
266 * |
| |
267 * @param msg The message. |
| |
268 * @param data The binary data. |
| |
269 * @param len The length of the data. |
| |
270 */ |
| |
271 void msn_message_set_bin_data(MsnMessage *msg, const void *data, size_t len); |
| |
272 |
| |
273 /** |
| |
274 * Returns the binary content of the message. |
| |
275 * |
| |
276 * @param msg The message. |
| |
277 * @param len The returned length of the data. |
| |
278 * |
| |
279 * @return The binary data. |
| |
280 */ |
| |
281 const void *msn_message_get_bin_data(const MsnMessage *msg, size_t *len); |
| |
282 |
| |
283 /** |
| |
284 * Sets the content type in a message. |
| |
285 * |
| |
286 * @param msg The message. |
| |
287 * @param type The content-type. |
| |
288 */ |
| |
289 void msn_message_set_content_type(MsnMessage *msg, const char *type); |
| |
290 |
| |
291 /** |
| |
292 * Returns the content type in a message. |
| |
293 * |
| |
294 * @param msg The message. |
| |
295 * |
| |
296 * @return The content-type. |
| |
297 */ |
| |
298 const char *msn_message_get_content_type(const MsnMessage *msg); |
| |
299 |
| |
300 /** |
| |
301 * Sets the charset in a message. |
| |
302 * |
| |
303 * @param msg The message. |
| |
304 * @param charset The charset. |
| |
305 */ |
| |
306 void msn_message_set_charset(MsnMessage *msg, const char *charset); |
| |
307 |
| |
308 /** |
| |
309 * Returns the charset in a message. |
| |
310 * |
| |
311 * @param msg The message. |
| |
312 * |
| |
313 * @return The charset. |
| |
314 */ |
| |
315 const char *msn_message_get_charset(const MsnMessage *msg); |
| |
316 |
| |
317 /** |
| |
318 * Sets an attribute in a message. |
| |
319 * |
| |
320 * @param msg The message. |
| |
321 * @param attr The attribute name. |
| |
322 * @param value The attribute value. |
| |
323 */ |
| |
324 void msn_message_set_attr(MsnMessage *msg, const char *attr, |
| |
325 const char *value); |
| |
326 |
| |
327 /** |
| |
328 * Returns an attribute from a message. |
| |
329 * |
| |
330 * @param msg The message. |
| |
331 * @param attr The attribute. |
| |
332 * |
| |
333 * @return The value, or @c NULL if not found. |
| |
334 */ |
| |
335 const char *msn_message_get_attr(const MsnMessage *msg, const char *attr); |
| |
336 |
| |
337 /** |
| |
338 * Parses the body and returns it in the form of a hashtable. |
| |
339 * |
| |
340 * @param msg The message. |
| |
341 * |
| |
342 * @return The resulting hashtable. |
| |
343 */ |
| |
344 GHashTable *msn_message_get_hashtable_from_body(const MsnMessage *msg); |
| |
345 |
| |
346 void msn_message_show_readable(MsnMessage *msg, const char *info, |
| |
347 gboolean text_body); |
| |
348 |
| |
349 void msn_message_parse_slp_body(MsnMessage *msg, const char *body, |
| |
350 size_t len); |
| |
351 |
| |
352 char *msn_message_gen_slp_body(MsnMessage *msg, size_t *ret_size); |
| |
353 |
| |
354 char *msn_message_to_string(MsnMessage *msg); |
| |
355 |
| |
356 #endif /* _MSN_MSG_H_ */ |