Tue, 01 Jun 2004 06:42:20 +0000
[gaim-migrate @ 9942]
Patch from Felipe Contreras to sync our MSN prpl with what's in his tree.
He says this may fix a couple bugs, but the important thing is the
restructuring of how MsnMessages work. Lots of style changes and other
stuff as well.
committer: Christian Hammond <chipx86@chipx86.com>
| 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 | ||
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
37 | if (format != NULL) |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
38 | { |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
39 | va_start(arg, format); |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
40 | trans->params = g_strdup_vprintf(format, arg); |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
41 | va_end(arg); |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8810
diff
changeset
|
42 | } |
| 8810 | 43 | |
| 44 | /* trans->queue = g_queue_new(); */ | |
| 45 | ||
| 46 | return trans; | |
| 47 | } | |
| 48 | ||
| 49 | void | |
| 50 | msn_transaction_destroy(MsnTransaction *trans) | |
| 51 | { | |
| 52 | g_return_if_fail(trans != NULL); | |
| 53 | ||
| 54 | g_free(trans->command); | |
| 55 | g_free(trans->params); | |
| 56 | g_free(trans->payload); | |
| 57 | ||
| 58 | #if 0 | |
| 59 | if (trans->pendent_cmd != NULL) | |
| 60 | msn_message_unref(trans->pendent_msg); | |
| 61 | #endif | |
| 62 | ||
| 63 | #if 0 | |
| 64 | MsnTransaction *elem; | |
| 65 | if (trans->queue != NULL) | |
| 66 | { | |
| 67 | while ((elem = g_queue_pop_head(trans->queue)) != NULL) | |
| 68 | msn_transaction_destroy(elem); | |
| 69 | ||
| 70 | g_queue_free(trans->queue); | |
| 71 | } | |
| 72 | #endif | |
| 73 | ||
| 74 | g_free(trans); | |
| 75 | } | |
| 76 | ||
| 77 | char * | |
| 78 | msn_transaction_to_string(MsnTransaction *trans) | |
| 79 | { | |
| 80 | char *str; | |
| 81 | ||
| 82 | g_return_val_if_fail(trans != NULL, FALSE); | |
| 83 | ||
| 84 | if (trans->params != NULL) | |
| 85 | str = g_strdup_printf("%s %u %s\r\n", trans->command, trans->trId, trans->params); | |
| 86 | else | |
| 87 | str = g_strdup_printf("%s %u\r\n", trans->command, trans->trId); | |
| 88 | ||
| 89 | return str; | |
| 90 | } | |
| 91 | ||
| 92 | void | |
| 93 | msn_transaction_set_payload(MsnTransaction *trans, | |
| 94 | const char *payload, int payload_len) | |
| 95 | { | |
| 96 | g_return_if_fail(trans != NULL); | |
| 97 | g_return_if_fail(payload != NULL); | |
| 98 | ||
| 99 | trans->payload = g_strdup(payload); | |
| 100 | trans->payload_len = payload_len ? payload_len : strlen(trans->payload); | |
| 101 | } |