Mon, 22 Aug 2016 05:04:05 -0400
Add zephyr to meson build.
| 8810 | 1 | /** |
| 2 | * @file cmdproc.c MSN command processor functions | |
| 3 | * | |
| 15884 | 4 | * purple |
| 8810 | 5 | * |
| 15884 | 6 | * Purple is the legal property of its developers, whose names are too numerous |
|
9198
e8eb6d5eb9eb
[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 |
|
e8eb6d5eb9eb
[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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8810 | 23 | */ |
|
30945
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30915
diff
changeset
|
24 | |
|
30961
885064b16c54
Include internal.h on each c file to avoid windows breakage as recommended by Daniel.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30956
diff
changeset
|
25 | #include "internal.h" |
|
30945
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30915
diff
changeset
|
26 | #include "debug.h" |
|
b875cf477e19
Remove unnecesary includes from msn.h.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30915
diff
changeset
|
27 | |
| 8810 | 28 | #include "cmdproc.h" |
|
30956
74ba2cc3e760
A little header cleanup.
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
30945
diff
changeset
|
29 | #include "error.h" |
| 8810 | 30 | |
| 31 | MsnCmdProc * | |
| 32 | msn_cmdproc_new(MsnSession *session) | |
| 33 | { | |
| 34 | MsnCmdProc *cmdproc; | |
| 35 | ||
| 36 | cmdproc = g_new0(MsnCmdProc, 1); | |
| 37 | ||
| 38 | cmdproc->session = session; | |
| 39 | cmdproc->txqueue = g_queue_new(); | |
| 40 | cmdproc->history = msn_history_new(); | |
| 41 | ||
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
42 | cmdproc->multiparts = g_hash_table_new_full(g_str_hash, g_str_equal, |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
43 | NULL, (GDestroyNotify)msn_message_unref); |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
44 | |
| 8810 | 45 | return cmdproc; |
| 46 | } | |
| 47 | ||
| 48 | void | |
| 49 | msn_cmdproc_destroy(MsnCmdProc *cmdproc) | |
| 50 | { | |
| 51 | MsnTransaction *trans; | |
| 52 | ||
| 53 | while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) | |
| 54 | msn_transaction_destroy(trans); | |
| 55 | ||
| 56 | g_queue_free(cmdproc->txqueue); | |
| 57 | ||
| 58 | msn_history_destroy(cmdproc->history); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10481
diff
changeset
|
59 | |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10481
diff
changeset
|
60 | if (cmdproc->last_cmd != NULL) |
|
31240
db0cb3d72bc9
Use the unref functions everywhere, instead of destroy. I also removed
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31178
diff
changeset
|
61 | msn_command_unref(cmdproc->last_cmd); |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10481
diff
changeset
|
62 | |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
63 | g_hash_table_destroy(cmdproc->multiparts); |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
64 | |
|
10481
a5d6b8e1717d
[gaim-migrate @ 11769]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10403
diff
changeset
|
65 | g_free(cmdproc); |
| 8810 | 66 | } |
| 67 | ||
| 68 | void | |
| 69 | msn_cmdproc_process_queue(MsnCmdProc *cmdproc) | |
| 70 | { | |
| 71 | MsnTransaction *trans; | |
| 72 | ||
|
10481
a5d6b8e1717d
[gaim-migrate @ 11769]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10403
diff
changeset
|
73 | while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) |
| 8810 | 74 | msn_cmdproc_send_trans(cmdproc, trans); |
| 75 | } | |
| 76 | ||
| 77 | void | |
| 78 | msn_cmdproc_queue_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
| 79 | { | |
| 80 | g_return_if_fail(cmdproc != NULL); | |
| 81 | g_return_if_fail(trans != NULL); | |
| 82 | ||
| 83 | g_queue_push_tail(cmdproc->txqueue, trans); | |
| 84 | } | |
| 85 | ||
| 86 | static void | |
| 87 | show_debug_cmd(MsnCmdProc *cmdproc, gboolean incoming, const char *command) | |
| 88 | { | |
| 89 | MsnServConn *servconn; | |
| 90 | const char *names[] = { "NS", "SB" }; | |
| 91 | char *show; | |
| 92 | char tmp; | |
| 93 | size_t len; | |
| 94 | ||
| 95 | servconn = cmdproc->servconn; | |
| 96 | len = strlen(command); | |
| 97 | show = g_strdup(command); | |
| 98 | ||
| 99 | tmp = (incoming) ? 'S' : 'C'; | |
| 100 | ||
| 101 | if ((show[len - 1] == '\n') && (show[len - 2] == '\r')) | |
| 102 | { | |
| 103 | show[len - 2] = '\0'; | |
| 104 | } | |
| 105 | ||
| 15884 | 106 | purple_debug_misc("msn", "%c: %s %03d: %s\n", tmp, |
| 8810 | 107 | names[servconn->type], servconn->num, show); |
| 108 | ||
| 109 | g_free(show); | |
| 110 | } | |
| 111 | ||
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
112 | gboolean |
| 8810 | 113 | msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) |
| 114 | { | |
| 115 | MsnServConn *servconn; | |
| 116 | char *data; | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
117 | size_t len; |
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
118 | gboolean ret; |
| 8810 | 119 | |
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
120 | g_return_val_if_fail(cmdproc != NULL, TRUE); |
|
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
121 | g_return_val_if_fail(trans != NULL, TRUE); |
| 8810 | 122 | |
| 123 | servconn = cmdproc->servconn; | |
|
10481
a5d6b8e1717d
[gaim-migrate @ 11769]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10403
diff
changeset
|
124 | |
|
26569
75f5eac5703c
Make sure we free itmsurl when showing the info window for a buddy
Mark Doliner <markdoliner@pidgin.im>
parents:
25469
diff
changeset
|
125 | if (!servconn->connected) { |
|
31178
303c44f64d2c
Call msn_transaction_destroy from msn_cmdproc_send_trans. This way, it
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31109
diff
changeset
|
126 | msn_transaction_destroy(trans); |
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
127 | return FALSE; |
|
26569
75f5eac5703c
Make sure we free itmsurl when showing the info window for a buddy
Mark Doliner <markdoliner@pidgin.im>
parents:
25469
diff
changeset
|
128 | } |
|
10481
a5d6b8e1717d
[gaim-migrate @ 11769]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10403
diff
changeset
|
129 | |
|
30915
56295f0a8ade
I don't really like this name.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30913
diff
changeset
|
130 | if (trans->saveable) |
|
30913
9549143987bc
Messages without TrID's should not be saved in the history.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30909
diff
changeset
|
131 | msn_history_add(cmdproc->history, trans); |
| 8810 | 132 | |
| 133 | data = msn_transaction_to_string(trans); | |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
134 | |
| 8810 | 135 | len = strlen(data); |
| 136 | ||
| 137 | show_debug_cmd(cmdproc, FALSE, data); | |
| 138 | ||
| 139 | if (trans->callbacks == NULL) | |
| 140 | trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds, | |
| 141 | trans->command); | |
| 142 | ||
| 143 | if (trans->payload != NULL) | |
| 144 | { | |
| 145 | data = g_realloc(data, len + trans->payload_len); | |
| 146 | memcpy(data + len, trans->payload, trans->payload_len); | |
| 147 | len += trans->payload_len; | |
|
23235
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
148 | |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
149 | /* |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
150 | * We're done with trans->payload. Free it so that the memory |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
151 | * doesn't sit around in cmdproc->history. |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
152 | */ |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
153 | g_free(trans->payload); |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
154 | trans->payload = NULL; |
|
cb7d22017162
When adding outgoing MSN commands to the MsnHistory, free
Mark Doliner <markdoliner@pidgin.im>
parents:
20597
diff
changeset
|
155 | trans->payload_len = 0; |
| 8810 | 156 | } |
| 157 | ||
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
158 | ret = msn_servconn_write(servconn, data, len) != -1; |
| 8810 | 159 | |
|
31178
303c44f64d2c
Call msn_transaction_destroy from msn_cmdproc_send_trans. This way, it
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31109
diff
changeset
|
160 | if (!trans->saveable) |
|
303c44f64d2c
Call msn_transaction_destroy from msn_cmdproc_send_trans. This way, it
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31109
diff
changeset
|
161 | msn_transaction_destroy(trans); |
| 8810 | 162 | g_free(data); |
|
32008
56d1c64759d6
Fix a crash when the account is disconnected and we have requested a SB. (Hanzz, ported by shlomif)(Fixes #12431)
Jorge Villaseñor <masca@cpw.pidgin.im>
parents:
31240
diff
changeset
|
163 | return ret; |
| 8810 | 164 | } |
| 165 | ||
| 166 | void | |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
167 | msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload, |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
168 | int payload_len) |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
169 | { |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
170 | MsnCommand *last; |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
171 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
172 | g_return_if_fail(cmdproc != NULL); |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
173 | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
174 | last = cmdproc->last_cmd; |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
175 | last->payload = g_memdup(payload, payload_len); |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
176 | last->payload_len = payload_len; |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
177 | |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
178 | if (last->payload_cb != NULL) |
|
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
179 | last->payload_cb(cmdproc, last, payload, payload_len); |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
180 | } |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
181 | |
|
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
182 | void |
| 8810 | 183 | msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
| 184 | { | |
|
10345
7d7f8cfa2b4f
[gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10310
diff
changeset
|
185 | MsnMsgTypeCb cb; |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
186 | const char *message_id = NULL; |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
187 | |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
188 | /* Multi-part messages */ |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
189 | message_id = msn_message_get_header_value(msg, "Message-ID"); |
|
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
190 | if (message_id != NULL) { |
|
29459
f8d47f8c997e
Shuffle some things around and add some comments. Hopefully cleaner.
Mark Doliner <markdoliner@pidgin.im>
parents:
29458
diff
changeset
|
191 | /* This is the first in a series of chunks */ |
|
f8d47f8c997e
Shuffle some things around and add some comments. Hopefully cleaner.
Mark Doliner <markdoliner@pidgin.im>
parents:
29458
diff
changeset
|
192 | |
|
29457
15f977c9ac76
Rename "attribute" to "header" in a bunch of places. The SLP protocol
Mark Doliner <markdoliner@pidgin.im>
parents:
28175
diff
changeset
|
193 | const char *chunk_text = msn_message_get_header_value(msg, "Chunks"); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
194 | guint chunk; |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
195 | if (chunk_text != NULL) { |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
196 | chunk = strtol(chunk_text, NULL, 10); |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
197 | /* 1024 chunks of ~1300 bytes is ~1MB, which seems OK to prevent |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
198 | some random client causing pidgin to hog a ton of memory. |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
199 | Probably should figure out the maximum that the official client |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
200 | actually supports, though. */ |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
201 | if (chunk > 0 && chunk < 1024) { |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
202 | msg->total_chunks = chunk; |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
203 | msg->received_chunks = 1; |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
204 | g_hash_table_insert(cmdproc->multiparts, (gpointer)message_id, msn_message_ref(msg)); |
|
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
205 | purple_debug_info("msn", "Received chunked message, message_id: '%s', total chunks: %d\n", |
|
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
206 | message_id, chunk); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
207 | } else { |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
208 | purple_debug_error("msn", "MessageId '%s' has too many chunks: %d\n", message_id, chunk); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
209 | } |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
210 | return; |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
211 | } else { |
|
29457
15f977c9ac76
Rename "attribute" to "header" in a bunch of places. The SLP protocol
Mark Doliner <markdoliner@pidgin.im>
parents:
28175
diff
changeset
|
212 | chunk_text = msn_message_get_header_value(msg, "Chunk"); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
213 | if (chunk_text != NULL) { |
|
29459
f8d47f8c997e
Shuffle some things around and add some comments. Hopefully cleaner.
Mark Doliner <markdoliner@pidgin.im>
parents:
29458
diff
changeset
|
214 | /* This is one chunk in a series of chunks */ |
|
f8d47f8c997e
Shuffle some things around and add some comments. Hopefully cleaner.
Mark Doliner <markdoliner@pidgin.im>
parents:
29458
diff
changeset
|
215 | |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
216 | MsnMessage *first = g_hash_table_lookup(cmdproc->multiparts, message_id); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
217 | chunk = strtol(chunk_text, NULL, 10); |
|
31109
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
218 | if (first != NULL) { |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
219 | if (first->received_chunks != chunk) { |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
220 | /* |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
221 | * We received an out of order chunk number (i.e. not the |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
222 | * next one in the sequence). Not sure if this can happen |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
223 | * legitimately, but we definitely don't handle it right |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
224 | * now. |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
225 | */ |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
226 | g_hash_table_remove(cmdproc->multiparts, message_id); |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
227 | return; |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
228 | } |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
229 | |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
230 | /* Chunk is from 1 to total-1 (doesn't count first one) */ |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
231 | purple_debug_info("msn", "Received chunk %d of %d, message_id: '%s'\n", |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
232 | chunk + 1, first->total_chunks, message_id); |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
233 | first->body = g_realloc(first->body, first->body_len + msg->body_len); |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
234 | memcpy(first->body + first->body_len, msg->body, msg->body_len); |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
235 | first->body_len += msg->body_len; |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
236 | first->received_chunks++; |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
237 | if (first->received_chunks != first->total_chunks) |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
238 | /* We're waiting for more chunks */ |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
239 | return; |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
240 | |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
241 | /* |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
242 | * We have all the chunks for this message, great! Send |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
243 | * it along... The caller takes care of freeing the old one. |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
244 | */ |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
245 | msg = first; |
|
b04f3af0fd58
first can be NULL here, obviously, We don't want any NULL-pointer
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30961
diff
changeset
|
246 | } else { |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
247 | purple_debug_error("msn", |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
248 | "Unable to find first chunk of message_id '%s' to correspond with chunk %d.\n", |
|
29459
f8d47f8c997e
Shuffle some things around and add some comments. Hopefully cleaner.
Mark Doliner <markdoliner@pidgin.im>
parents:
29458
diff
changeset
|
249 | message_id, chunk + 1); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
250 | } |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
251 | } else { |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
252 | purple_debug_error("msn", "Received MessageId '%s' with no chunk number!\n", message_id); |
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
253 | } |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
254 | } |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
255 | } |
| 8810 | 256 | |
|
9881
c63823101be4
[gaim-migrate @ 10760]
Mark Doliner <markdoliner@pidgin.im>
parents:
9641
diff
changeset
|
257 | if (msn_message_get_content_type(msg) == NULL) |
|
c63823101be4
[gaim-migrate @ 10760]
Mark Doliner <markdoliner@pidgin.im>
parents:
9641
diff
changeset
|
258 | { |
| 15884 | 259 | purple_debug_misc("msn", "failed to find message content\n"); |
|
9881
c63823101be4
[gaim-migrate @ 10760]
Mark Doliner <markdoliner@pidgin.im>
parents:
9641
diff
changeset
|
260 | return; |
|
c63823101be4
[gaim-migrate @ 10760]
Mark Doliner <markdoliner@pidgin.im>
parents:
9641
diff
changeset
|
261 | } |
|
c63823101be4
[gaim-migrate @ 10760]
Mark Doliner <markdoliner@pidgin.im>
parents:
9641
diff
changeset
|
262 | |
| 8810 | 263 | cb = g_hash_table_lookup(cmdproc->cbs_table->msgs, |
| 264 | msn_message_get_content_type(msg)); | |
| 265 | ||
|
25469
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
266 | if (cb != NULL) |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
267 | cb(cmdproc, msg); |
|
d3a7fa855992
Re-combine large (multi-part) messages on MSN since we seem to say that we
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23864
diff
changeset
|
268 | else |
| 15884 | 269 | purple_debug_warning("msn", "Unhandled content-type '%s'\n", |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
270 | msn_message_get_content_type(msg)); |
| 8810 | 271 | |
|
29458
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
272 | if (message_id != NULL) |
|
84e15cd5c969
Since when do we use camel case?
Mark Doliner <markdoliner@pidgin.im>
parents:
29457
diff
changeset
|
273 | g_hash_table_remove(cmdproc->multiparts, message_id); |
| 8810 | 274 | } |
| 275 | ||
| 276 | void | |
| 277 | msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
| 278 | { | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
279 | MsnTransCb cb = NULL; |
| 8810 | 280 | MsnTransaction *trans = NULL; |
| 281 | ||
| 282 | if (cmd->trId) | |
|
23864
5fda175ef2e4
Always save the MSN transaction in each command, not just for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23235
diff
changeset
|
283 | cmd->trans = trans = msn_history_find(cmdproc->history, cmd->trId); |
| 8810 | 284 | |
|
10225
0dfea1bc8695
[gaim-migrate @ 11357]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10043
diff
changeset
|
285 | if (trans != NULL) |
|
20576
285daffed81f
Reset the timer to 0 after removing it. It looks like this may be required here.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
286 | if (trans->timer) { |
| 15884 | 287 | purple_timeout_remove(trans->timer); |
|
20576
285daffed81f
Reset the timer to 0 after removing it. It looks like this may be required here.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
288 | trans->timer = 0; |
|
285daffed81f
Reset the timer to 0 after removing it. It looks like this may be required here.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
289 | } |
|
10225
0dfea1bc8695
[gaim-migrate @ 11357]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10043
diff
changeset
|
290 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
291 | if (g_ascii_isdigit(cmd->command[0]) && trans != NULL) |
| 8810 | 292 | { |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
293 | MsnErrorCb error_cb; |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
294 | int error; |
| 8810 | 295 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
296 | error = atoi(cmd->command); |
|
10225
0dfea1bc8695
[gaim-migrate @ 11357]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10043
diff
changeset
|
297 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
298 | error_cb = trans->error_cb; |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
299 | if (error_cb == NULL) |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
300 | error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command); |
| 8810 | 301 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
302 | if (error_cb != NULL) |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
303 | error_cb(cmdproc, trans, error); |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
304 | else |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
305 | msn_error_handle(cmdproc->session, error); |
| 8810 | 306 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
307 | return; |
| 8810 | 308 | } |
| 309 | ||
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
310 | cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command); |
| 8810 | 311 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
312 | if (cb == NULL && trans != NULL && trans->callbacks != NULL) |
|
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
313 | cb = g_hash_table_lookup(trans->callbacks, cmd->command); |
| 8810 | 314 | |
|
28175
fa8b01d12ef1
Simplify. A lot of these checks aren't necessary because msn_table_new()
Mark Doliner <markdoliner@pidgin.im>
parents:
28171
diff
changeset
|
315 | if (cb == NULL) |
|
10043
4d4cc1ee9b69
[gaim-migrate @ 11002]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9881
diff
changeset
|
316 | cb = g_hash_table_lookup(cmdproc->cbs_table->fallback, cmd->command); |
|
4d4cc1ee9b69
[gaim-migrate @ 11002]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9881
diff
changeset
|
317 | |
| 8810 | 318 | if (cb != NULL) |
| 319 | cb(cmdproc, cmd); | |
| 320 | else | |
| 15884 | 321 | purple_debug_warning("msn", "Unhandled command '%s'\n", |
|
9158
f8dab42adeaf
[gaim-migrate @ 9942]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
8830
diff
changeset
|
322 | cmd->command); |
| 8810 | 323 | |
|
9193
6e76f1367896
[gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
9158
diff
changeset
|
324 | if (trans != NULL && trans->pendent_cmd != NULL) |
|
10481
a5d6b8e1717d
[gaim-migrate @ 11769]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10403
diff
changeset
|
325 | msn_transaction_unqueue_cmd(trans, cmdproc); |
| 8810 | 326 | } |
| 327 | ||
| 328 | void | |
| 329 | msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command) | |
| 330 | { | |
| 331 | show_debug_cmd(cmdproc, TRUE, command); | |
| 332 | ||
| 333 | if (cmdproc->last_cmd != NULL) | |
|
31240
db0cb3d72bc9
Use the unref functions everywhere, instead of destroy. I also removed
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31178
diff
changeset
|
334 | msn_command_unref(cmdproc->last_cmd); |
| 8810 | 335 | |
| 336 | cmdproc->last_cmd = msn_command_from_string(command); | |
| 337 | ||
| 338 | msn_cmdproc_process_cmd(cmdproc, cmdproc->last_cmd); | |
| 339 | } |