Mercurial > pidgin
annotate src/protocols/msn/transaction.c @ 10463:9bed28273ec7
[gaim-migrate @ 11737]
Felipe Contreras fixed the MSN HTTP Method. Yay! Thanks Felipe.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 31 Dec 2004 16:34:22 +0000 |
parents | e5455f1dc9b6 |
children | bcfea6c3d5c9 |
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 | |
10284 | 78 if (trans->callbacks != NULL && trans->has_custom_callbacks) |
79 g_hash_table_destroy(trans->callbacks); | |
80 | |
10225 | 81 if (trans->timer) |
82 gaim_timeout_remove(trans->timer); | |
83 | |
8810 | 84 g_free(trans); |
85 } | |
86 | |
87 char * | |
88 msn_transaction_to_string(MsnTransaction *trans) | |
89 { | |
90 char *str; | |
91 | |
92 g_return_val_if_fail(trans != NULL, FALSE); | |
93 | |
94 if (trans->params != NULL) | |
95 str = g_strdup_printf("%s %u %s\r\n", trans->command, trans->trId, trans->params); | |
96 else | |
97 str = g_strdup_printf("%s %u\r\n", trans->command, trans->trId); | |
98 | |
99 return str; | |
100 } | |
101 | |
102 void | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
103 msn_transaction_queue_cmd(MsnTransaction *trans, MsnCommand *cmd) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
104 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
105 gaim_debug_info("msn", "queueing command.\n"); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
106 trans->pendent_cmd = cmd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
107 msn_command_ref(cmd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
108 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
109 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
110 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
111 msn_transaction_unqueue_cmd(MsnTransaction *trans, MsnCmdProc *cmdproc) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
112 { |
9218 | 113 MsnCommand *cmd; |
114 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
115 gaim_debug_info("msn", "unqueueing command.\n"); |
9218 | 116 cmd = trans->pendent_cmd; |
117 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
118 g_return_if_fail(cmd != NULL); |
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 msn_cmdproc_process_cmd(cmdproc, cmd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
121 msn_command_unref(cmd); |
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 trans->pendent_cmd = NULL; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
124 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
125 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
126 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
127 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
128 msn_transaction_queue(MsnTransaction *trans, MsnTransaction *elem) |
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 if (trans->queue == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
131 trans->queue = g_queue_new(); |
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 g_queue_push_tail(trans->queue, elem); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
134 } |
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 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
137 msn_transaction_unqueue(MsnTransaction *trans, MsnCmdProc *cmdproc) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
138 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
139 MsnTransaction *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 while ((elem = g_queue_pop_head(trans->queue)) != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
142 msn_cmdproc_send_trans(cmdproc, elem); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
143 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
144 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
145 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
146 void |
8810 | 147 msn_transaction_set_payload(MsnTransaction *trans, |
148 const char *payload, int payload_len) | |
149 { | |
150 g_return_if_fail(trans != NULL); | |
151 g_return_if_fail(payload != NULL); | |
152 | |
153 trans->payload = g_strdup(payload); | |
154 trans->payload_len = payload_len ? payload_len : strlen(trans->payload); | |
155 } | |
9193
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 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
158 msn_transaction_set_data(MsnTransaction *trans, void *data) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
159 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
160 g_return_if_fail(trans != NULL); |
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 trans->data = data; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
163 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
164 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
165 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
166 msn_transaction_add_cb(MsnTransaction *trans, char *answer, |
10225 | 167 MsnTransCb cb) |
9193
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 g_return_if_fail(trans != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
170 g_return_if_fail(answer != 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 if (trans->callbacks == NULL) |
10284 | 173 { |
174 trans->has_custom_callbacks = TRUE; | |
175 trans->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, | |
176 NULL); | |
177 } | |
178 else if (trans->has_custom_callbacks != TRUE) | |
179 g_return_if_reached (); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
180 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
181 g_hash_table_insert(trans->callbacks, answer, cb); |
10225 | 182 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
183 |
10225 | 184 static gboolean |
185 transaction_timeout(gpointer data) | |
186 { | |
187 MsnTransaction *trans; | |
188 | |
189 trans = data; | |
190 g_return_val_if_fail(trans != NULL, FALSE); | |
191 | |
10403 | 192 #if 0 |
193 gaim_debug_info("msn", "timed out: %s %d %s\n", trans->command, trans->trId, trans->params); | |
194 #endif | |
10225 | 195 |
196 if (trans->timeout_cb != NULL) | |
197 trans->timeout_cb(trans->cmdproc, trans); | |
198 | |
199 return FALSE; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
200 } |
10225 | 201 |
202 void | |
203 msn_transaction_set_timeout_cb(MsnTransaction *trans, MsnTimeoutCb cb) | |
204 { | |
205 if (trans->timer) | |
206 { | |
207 gaim_debug_error("msn", "This shouldn't be happening\n"); | |
208 gaim_timeout_remove(trans->timer); | |
209 } | |
210 trans->timeout_cb = cb; | |
211 trans->timer = gaim_timeout_add(60000, transaction_timeout, trans); | |
212 } | |
213 | |
214 void | |
215 msn_transaction_set_error_cb(MsnTransaction *trans, MsnErrorCb cb) | |
216 { | |
217 trans->error_cb = cb; | |
218 } |