Mercurial > pidgin.yaz
annotate src/protocols/msn/transaction.c @ 10225:ecf3ce2e2ab1
[gaim-migrate @ 11357]
This is mostly a patch from Felipe Contreras that eliminates MSN switchboard
errors and fixes MSN buddy icon syncronization, with some tweaks by me.
Thank Felipe if it works, blame me if something broke.
I also fixed a couple of text markup escaping things, fixed a glib warning that
was bugging me, fix a rare SILC crash, and make gtkstatusselector.c compile
(but do nothing) with gtk < 2.4
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 21 Nov 2004 17:48:09 +0000 |
parents | 08e7ccb4610d |
children | f776e117c17b |
rev | line source |
---|---|
8810 | 1 /** |
2 * @file transaction.c MSN transaction functions | |
3 * | |
4 * gaim | |
5 * | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
8810 | 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 #include "msn.h" | |
25 #include "transaction.h" | |
26 | |
27 MsnTransaction * | |
10225 | 28 msn_transaction_new(MsnCmdProc *cmdproc, const char *command, |
29 const char *format, ...) | |
8810 | 30 { |
31 MsnTransaction *trans; | |
32 va_list arg; | |
33 | |
34 g_return_val_if_fail(command != NULL, NULL); | |
35 | |
36 trans = g_new0(MsnTransaction, 1); | |
37 | |
10225 | 38 trans->cmdproc = cmdproc; |
8810 | 39 trans->command = g_strdup(command); |
40 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
41 if (format != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
42 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
43 va_start(arg, format); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
44 trans->params = g_strdup_vprintf(format, arg); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
45 va_end(arg); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
46 } |
8810 | 47 |
48 /* trans->queue = g_queue_new(); */ | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
49 |
8810 | 50 return trans; |
51 } | |
52 | |
53 void | |
54 msn_transaction_destroy(MsnTransaction *trans) | |
55 { | |
56 g_return_if_fail(trans != NULL); | |
57 | |
58 g_free(trans->command); | |
59 g_free(trans->params); | |
60 g_free(trans->payload); | |
61 | |
62 #if 0 | |
63 if (trans->pendent_cmd != NULL) | |
64 msn_message_unref(trans->pendent_msg); | |
65 #endif | |
66 | |
67 #if 0 | |
68 MsnTransaction *elem; | |
69 if (trans->queue != NULL) | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
70 { |
8810 | 71 while ((elem = g_queue_pop_head(trans->queue)) != NULL) |
72 msn_transaction_destroy(elem); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
73 |
8810 | 74 g_queue_free(trans->queue); |
75 } | |
76 #endif | |
77 | |
10225 | 78 if (trans->timer) |
79 gaim_timeout_remove(trans->timer); | |
80 | |
8810 | 81 g_free(trans); |
82 } | |
83 | |
84 char * | |
85 msn_transaction_to_string(MsnTransaction *trans) | |
86 { | |
87 char *str; | |
88 | |
89 g_return_val_if_fail(trans != NULL, FALSE); | |
90 | |
91 if (trans->params != NULL) | |
92 str = g_strdup_printf("%s %u %s\r\n", trans->command, trans->trId, trans->params); | |
93 else | |
94 str = g_strdup_printf("%s %u\r\n", trans->command, trans->trId); | |
95 | |
96 return str; | |
97 } | |
98 | |
99 void | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
100 msn_transaction_queue_cmd(MsnTransaction *trans, MsnCommand *cmd) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
101 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
102 gaim_debug_info("msn", "queueing command.\n"); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
103 trans->pendent_cmd = cmd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
104 msn_command_ref(cmd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
105 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
106 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
107 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
108 msn_transaction_unqueue_cmd(MsnTransaction *trans, MsnCmdProc *cmdproc) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
109 { |
9218 | 110 MsnCommand *cmd; |
111 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
112 gaim_debug_info("msn", "unqueueing command.\n"); |
9218 | 113 cmd = trans->pendent_cmd; |
114 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
115 g_return_if_fail(cmd != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
116 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
117 msn_cmdproc_process_cmd(cmdproc, cmd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
118 msn_command_unref(cmd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
119 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
120 trans->pendent_cmd = NULL; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
121 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
122 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
123 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
124 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
125 msn_transaction_queue(MsnTransaction *trans, MsnTransaction *elem) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
126 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
127 if (trans->queue == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
128 trans->queue = g_queue_new(); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
129 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
130 g_queue_push_tail(trans->queue, elem); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
131 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
132 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
133 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
134 msn_transaction_unqueue(MsnTransaction *trans, MsnCmdProc *cmdproc) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
135 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
136 MsnTransaction *elem; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
137 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
138 while ((elem = g_queue_pop_head(trans->queue)) != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
139 msn_cmdproc_send_trans(cmdproc, elem); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
140 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
141 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
142 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
143 void |
8810 | 144 msn_transaction_set_payload(MsnTransaction *trans, |
145 const char *payload, int payload_len) | |
146 { | |
147 g_return_if_fail(trans != NULL); | |
148 g_return_if_fail(payload != NULL); | |
149 | |
150 trans->payload = g_strdup(payload); | |
151 trans->payload_len = payload_len ? payload_len : strlen(trans->payload); | |
152 } | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
153 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
154 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
155 msn_transaction_set_data(MsnTransaction *trans, void *data) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
156 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
157 g_return_if_fail(trans != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
158 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
159 trans->data = data; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
160 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
161 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
162 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
163 msn_transaction_add_cb(MsnTransaction *trans, char *answer, |
10225 | 164 MsnTransCb cb) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
165 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
166 g_return_if_fail(trans != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
167 g_return_if_fail(answer != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
168 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
169 if (trans->callbacks == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
170 trans->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
171 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
172 g_hash_table_insert(trans->callbacks, answer, cb); |
10225 | 173 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
174 |
10225 | 175 static gboolean |
176 transaction_timeout(gpointer data) | |
177 { | |
178 MsnTransaction *trans; | |
179 | |
180 trans = data; | |
181 g_return_val_if_fail(trans != NULL, FALSE); | |
182 | |
183 gaim_debug_info("msn", "%s %d %s\n", trans->command, trans->trId, trans->params); | |
184 | |
185 if (trans->timeout_cb != NULL) | |
186 trans->timeout_cb(trans->cmdproc, trans); | |
187 | |
188 return FALSE; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
189 } |
10225 | 190 |
191 void | |
192 msn_transaction_set_timeout_cb(MsnTransaction *trans, MsnTimeoutCb cb) | |
193 { | |
194 if (trans->timer) | |
195 { | |
196 gaim_debug_error("msn", "This shouldn't be happening\n"); | |
197 gaim_timeout_remove(trans->timer); | |
198 } | |
199 trans->timeout_cb = cb; | |
200 trans->timer = gaim_timeout_add(60000, transaction_timeout, trans); | |
201 } | |
202 | |
203 void | |
204 msn_transaction_set_error_cb(MsnTransaction *trans, MsnErrorCb cb) | |
205 { | |
206 trans->error_cb = cb; | |
207 } |