8810
|
1 /**
|
|
2 * @file transaction.c MSN transaction functions
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #include "msn.h"
|
|
23 #include "transaction.h"
|
|
24
|
|
25 MsnTransaction *
|
|
26 msn_transaction_new(const char *command, const char *format, ...)
|
|
27 {
|
|
28 MsnTransaction *trans;
|
|
29 va_list arg;
|
|
30
|
|
31 g_return_val_if_fail(command != NULL, NULL);
|
|
32
|
|
33 trans = g_new0(MsnTransaction, 1);
|
|
34
|
|
35 trans->command = g_strdup(command);
|
|
36
|
|
37 va_start(arg, format);
|
|
38 trans->params = g_strdup_vprintf(format, arg);
|
|
39 va_end(arg);
|
|
40
|
|
41 /* trans->queue = g_queue_new(); */
|
|
42
|
|
43 return trans;
|
|
44 }
|
|
45
|
|
46 void
|
|
47 msn_transaction_destroy(MsnTransaction *trans)
|
|
48 {
|
|
49 g_return_if_fail(trans != NULL);
|
|
50
|
|
51 g_free(trans->command);
|
|
52 g_free(trans->params);
|
|
53 g_free(trans->payload);
|
|
54
|
|
55 #if 0
|
|
56 if (trans->pendent_cmd != NULL)
|
|
57 msn_message_unref(trans->pendent_msg);
|
|
58 #endif
|
|
59
|
|
60 #if 0
|
|
61 MsnTransaction *elem;
|
|
62 if (trans->queue != NULL)
|
|
63 {
|
|
64 while ((elem = g_queue_pop_head(trans->queue)) != NULL)
|
|
65 msn_transaction_destroy(elem);
|
|
66
|
|
67 g_queue_free(trans->queue);
|
|
68 }
|
|
69 #endif
|
|
70
|
|
71 g_free(trans);
|
|
72 }
|
|
73
|
|
74 char *
|
|
75 msn_transaction_to_string(MsnTransaction *trans)
|
|
76 {
|
|
77 char *str;
|
|
78
|
|
79 g_return_val_if_fail(trans != NULL, FALSE);
|
|
80
|
|
81 if (trans->params != NULL)
|
|
82 str = g_strdup_printf("%s %u %s\r\n", trans->command, trans->trId, trans->params);
|
|
83 else
|
|
84 str = g_strdup_printf("%s %u\r\n", trans->command, trans->trId);
|
|
85
|
|
86 return str;
|
|
87 }
|
|
88
|
|
89 void
|
|
90 msn_transaction_set_payload(MsnTransaction *trans,
|
|
91 const char *payload, int payload_len)
|
|
92 {
|
|
93 g_return_if_fail(trans != NULL);
|
|
94 g_return_if_fail(payload != NULL);
|
|
95
|
|
96 trans->payload = g_strdup(payload);
|
|
97 trans->payload_len = payload_len ? payload_len : strlen(trans->payload);
|
|
98 }
|