158
msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command,
159
const char *format, ...)
161
MsnServConn *servconn;
167
g_return_if_fail(cmdproc != NULL);
168
g_return_if_fail(command != NULL);
170
servconn = cmdproc->servconn;
172
if (!servconn->connected)
177
va_start(arg, format);
178
params = g_strdup_vprintf(format, arg);
183
data = g_strdup_printf("%s %s\r\n", command, params);
185
data = g_strdup_printf("%s\r\n", command);
191
show_debug_cmd(cmdproc, FALSE, data);
193
msn_servconn_write(servconn, data, len);
199
msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command,
200
const char *format, ...)
202
MsnTransaction *trans;
205
g_return_if_fail(cmdproc != NULL);
206
g_return_if_fail(command != NULL);
208
if (!cmdproc->servconn->connected)
211
trans = g_new0(MsnTransaction, 1);
213
trans->cmdproc = cmdproc;
214
trans->command = g_strdup(command);
218
va_start(arg, format);
219
trans->params = g_strdup_vprintf(format, arg);
223
msn_cmdproc_send_trans(cmdproc, trans);
227
163
msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload,
243
179
msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
246
const char *messageId = NULL;
182
const char *message_id = NULL;
248
184
/* Multi-part messages */
249
if ((messageId = msn_message_get_attr(msg, "Message-ID")) != NULL) {
250
const char *chunk_text = msn_message_get_attr(msg, "Chunks");
185
message_id = msn_message_get_header_value(msg, "Message-ID");
186
if (message_id != NULL) {
187
/* This is the first in a series of chunks */
189
const char *chunk_text = msn_message_get_header_value(msg, "Chunks");
252
191
if (chunk_text != NULL) {
253
192
chunk = strtol(chunk_text, NULL, 10);
254
/* 1024 chunks of ~1300 bytes is ~1MB, which seems OK to prevent
193
/* 1024 chunks of ~1300 bytes is ~1MB, which seems OK to prevent
255
194
some random client causing pidgin to hog a ton of memory.
256
195
Probably should figure out the maximum that the official client
257
196
actually supports, though. */
258
197
if (chunk > 0 && chunk < 1024) {
259
198
msg->total_chunks = chunk;
260
199
msg->received_chunks = 1;
261
g_hash_table_insert(cmdproc->multiparts, (gpointer)messageId, msn_message_ref(msg));
262
purple_debug_info("msn", "Received chunked message, messageId: '%s', total chunks: %d\n",
200
g_hash_table_insert(cmdproc->multiparts, (gpointer)message_id, msn_message_ref(msg));
201
purple_debug_info("msn", "Received chunked message, message_id: '%s', total chunks: %d\n",
265
purple_debug_error("msn", "MessageId '%s' has too many chunks: %d\n", messageId, chunk);
204
purple_debug_error("msn", "MessageId '%s' has too many chunks: %d\n", message_id, chunk);
269
chunk_text = msn_message_get_attr(msg, "Chunk");
208
chunk_text = msn_message_get_header_value(msg, "Chunk");
270
209
if (chunk_text != NULL) {
271
MsnMessage *first = g_hash_table_lookup(cmdproc->multiparts, messageId);
210
/* This is one chunk in a series of chunks */
212
MsnMessage *first = g_hash_table_lookup(cmdproc->multiparts, message_id);
272
213
chunk = strtol(chunk_text, NULL, 10);
274
purple_debug_error("msn",
275
"Unable to find first chunk of messageId '%s' to correspond with chunk %d.\n",
277
} else if (first->received_chunks == chunk) {
215
if (first->received_chunks != chunk) {
217
* We received an out of order chunk number (i.e. not the
218
* next one in the sequence). Not sure if this can happen
219
* legitimately, but we definitely don't handle it right
222
g_hash_table_remove(cmdproc->multiparts, message_id);
278
226
/* Chunk is from 1 to total-1 (doesn't count first one) */
279
purple_debug_info("msn", "Received chunk %d of %d, messageId: '%s'\n",
280
chunk+1, first->total_chunks, messageId);
227
purple_debug_info("msn", "Received chunk %d of %d, message_id: '%s'\n",
228
chunk + 1, first->total_chunks, message_id);
281
229
first->body = g_realloc(first->body, first->body_len + msg->body_len);
282
230
memcpy(first->body + first->body_len, msg->body, msg->body_len);
283
231
first->body_len += msg->body_len;
284
232
first->received_chunks++;
285
233
if (first->received_chunks != first->total_chunks)
234
/* We're waiting for more chunks */
288
/* We're done! Send it along... The caller takes care of
289
freeing the old one. */
238
* We have all the chunks for this message, great! Send
239
* it along... The caller takes care of freeing the old one.
292
/* TODO: Can you legitimately receive chunks out of order? */
293
g_hash_table_remove(cmdproc->multiparts, messageId);
243
purple_debug_error("msn",
244
"Unable to find first chunk of message_id '%s' to correspond with chunk %d.\n",
245
message_id, chunk + 1);
297
purple_debug_error("msn", "Received MessageId '%s' with no chunk number!\n", messageId);
248
purple_debug_error("msn", "Received MessageId '%s' with no chunk number!\n", message_id);