Mercurial > pidgin
annotate src/protocols/msn/transaction.c @ 13561:104fbbfc91fb
[gaim-migrate @ 15940]
beta3 for the RPM spec file too
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Sat, 25 Mar 2006 15:17:15 +0000 |
| parents | bcfea6c3d5c9 |
| children | b488205ad0bc |
| 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 | |
| 10481 | 115 if (!cmdproc->servconn->connected) |
| 116 return; | |
| 117 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
118 gaim_debug_info("msn", "unqueueing command.\n"); |
| 9218 | 119 cmd = trans->pendent_cmd; |
| 120 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
121 g_return_if_fail(cmd != NULL); |
|
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 msn_cmdproc_process_cmd(cmdproc, cmd); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
124 msn_command_unref(cmd); |
|
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 trans->pendent_cmd = NULL; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
127 } |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
128 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
129 #if 0 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
130 void |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
131 msn_transaction_queue(MsnTransaction *trans, MsnTransaction *elem) |
|
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 if (trans->queue == NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
134 trans->queue = g_queue_new(); |
|
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 g_queue_push_tail(trans->queue, 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 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
139 void |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
140 msn_transaction_unqueue(MsnTransaction *trans, MsnCmdProc *cmdproc) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
141 { |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
142 MsnTransaction *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 while ((elem = g_queue_pop_head(trans->queue)) != NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
145 msn_cmdproc_send_trans(cmdproc, elem); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
146 } |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
147 #endif |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
148 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
149 void |
| 8810 | 150 msn_transaction_set_payload(MsnTransaction *trans, |
| 151 const char *payload, int payload_len) | |
| 152 { | |
| 153 g_return_if_fail(trans != NULL); | |
| 154 g_return_if_fail(payload != NULL); | |
| 155 | |
| 156 trans->payload = g_strdup(payload); | |
| 157 trans->payload_len = payload_len ? payload_len : strlen(trans->payload); | |
| 158 } | |
|
9193
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 void |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
161 msn_transaction_set_data(MsnTransaction *trans, void *data) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
162 { |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
163 g_return_if_fail(trans != NULL); |
|
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 trans->data = data; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
166 } |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
167 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
168 void |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
169 msn_transaction_add_cb(MsnTransaction *trans, char *answer, |
| 10225 | 170 MsnTransCb cb) |
|
9193
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_return_if_fail(trans != NULL); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
173 g_return_if_fail(answer != NULL); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
174 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
175 if (trans->callbacks == NULL) |
| 10284 | 176 { |
| 177 trans->has_custom_callbacks = TRUE; | |
| 178 trans->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, | |
| 179 NULL); | |
| 180 } | |
| 181 else if (trans->has_custom_callbacks != TRUE) | |
| 182 g_return_if_reached (); | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
183 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
184 g_hash_table_insert(trans->callbacks, answer, cb); |
| 10225 | 185 } |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
186 |
| 10225 | 187 static gboolean |
| 188 transaction_timeout(gpointer data) | |
| 189 { | |
| 190 MsnTransaction *trans; | |
| 191 | |
| 192 trans = data; | |
| 193 g_return_val_if_fail(trans != NULL, FALSE); | |
| 194 | |
| 10403 | 195 #if 0 |
| 196 gaim_debug_info("msn", "timed out: %s %d %s\n", trans->command, trans->trId, trans->params); | |
| 197 #endif | |
| 10225 | 198 |
| 199 if (trans->timeout_cb != NULL) | |
| 200 trans->timeout_cb(trans->cmdproc, trans); | |
| 201 | |
| 202 return FALSE; | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
203 } |
| 10225 | 204 |
| 205 void | |
| 206 msn_transaction_set_timeout_cb(MsnTransaction *trans, MsnTimeoutCb cb) | |
| 207 { | |
| 208 if (trans->timer) | |
| 209 { | |
| 210 gaim_debug_error("msn", "This shouldn't be happening\n"); | |
| 211 gaim_timeout_remove(trans->timer); | |
| 212 } | |
| 213 trans->timeout_cb = cb; | |
| 214 trans->timer = gaim_timeout_add(60000, transaction_timeout, trans); | |
| 215 } | |
| 216 | |
| 217 void | |
| 218 msn_transaction_set_error_cb(MsnTransaction *trans, MsnErrorCb cb) | |
| 219 { | |
| 220 trans->error_cb = cb; | |
| 221 } |
