Mercurial > pidgin
comparison libpurple/protocols/msn/cmdproc.c @ 30695:d827357c6ce9
Since when do we use camel case?
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 08 Feb 2010 08:00:22 +0000 |
parents | 33b4ae796648 |
children | d22b9e73c929 |
comparison
equal
deleted
inserted
replaced
30694:33b4ae796648 | 30695:d827357c6ce9 |
---|---|
241 | 241 |
242 void | 242 void |
243 msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | 243 msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
244 { | 244 { |
245 MsnMsgTypeCb cb; | 245 MsnMsgTypeCb cb; |
246 const char *messageId = NULL; | 246 const char *message_id = NULL; |
247 | 247 |
248 /* Multi-part messages */ | 248 /* Multi-part messages */ |
249 if ((messageId = msn_message_get_header_value(msg, "Message-ID")) != NULL) { | 249 message_id = msn_message_get_header_value(msg, "Message-ID"); |
250 if (message_id != NULL) { | |
250 const char *chunk_text = msn_message_get_header_value(msg, "Chunks"); | 251 const char *chunk_text = msn_message_get_header_value(msg, "Chunks"); |
251 guint chunk; | 252 guint chunk; |
252 if (chunk_text != NULL) { | 253 if (chunk_text != NULL) { |
253 chunk = strtol(chunk_text, NULL, 10); | 254 chunk = strtol(chunk_text, NULL, 10); |
254 /* 1024 chunks of ~1300 bytes is ~1MB, which seems OK to prevent | 255 /* 1024 chunks of ~1300 bytes is ~1MB, which seems OK to prevent |
255 some random client causing pidgin to hog a ton of memory. | 256 some random client causing pidgin to hog a ton of memory. |
256 Probably should figure out the maximum that the official client | 257 Probably should figure out the maximum that the official client |
257 actually supports, though. */ | 258 actually supports, though. */ |
258 if (chunk > 0 && chunk < 1024) { | 259 if (chunk > 0 && chunk < 1024) { |
259 msg->total_chunks = chunk; | 260 msg->total_chunks = chunk; |
260 msg->received_chunks = 1; | 261 msg->received_chunks = 1; |
261 g_hash_table_insert(cmdproc->multiparts, (gpointer)messageId, msn_message_ref(msg)); | 262 g_hash_table_insert(cmdproc->multiparts, (gpointer)message_id, msn_message_ref(msg)); |
262 purple_debug_info("msn", "Received chunked message, messageId: '%s', total chunks: %d\n", | 263 purple_debug_info("msn", "Received chunked message, message_id: '%s', total chunks: %d\n", |
263 messageId, chunk); | 264 message_id, chunk); |
264 } else { | 265 } else { |
265 purple_debug_error("msn", "MessageId '%s' has too many chunks: %d\n", messageId, chunk); | 266 purple_debug_error("msn", "MessageId '%s' has too many chunks: %d\n", message_id, chunk); |
266 } | 267 } |
267 return; | 268 return; |
268 } else { | 269 } else { |
269 chunk_text = msn_message_get_header_value(msg, "Chunk"); | 270 chunk_text = msn_message_get_header_value(msg, "Chunk"); |
270 if (chunk_text != NULL) { | 271 if (chunk_text != NULL) { |
271 MsnMessage *first = g_hash_table_lookup(cmdproc->multiparts, messageId); | 272 MsnMessage *first = g_hash_table_lookup(cmdproc->multiparts, message_id); |
272 chunk = strtol(chunk_text, NULL, 10); | 273 chunk = strtol(chunk_text, NULL, 10); |
273 if (first == NULL) { | 274 if (first == NULL) { |
274 purple_debug_error("msn", | 275 purple_debug_error("msn", |
275 "Unable to find first chunk of messageId '%s' to correspond with chunk %d.\n", | 276 "Unable to find first chunk of message_id '%s' to correspond with chunk %d.\n", |
276 messageId, chunk+1); | 277 message_id, chunk+1); |
277 } else if (first->received_chunks == chunk) { | 278 } else if (first->received_chunks == chunk) { |
278 /* Chunk is from 1 to total-1 (doesn't count first one) */ | 279 /* 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 purple_debug_info("msn", "Received chunk %d of %d, message_id: '%s'\n", |
280 chunk+1, first->total_chunks, messageId); | 281 chunk+1, first->total_chunks, message_id); |
281 first->body = g_realloc(first->body, first->body_len + msg->body_len); | 282 first->body = g_realloc(first->body, first->body_len + msg->body_len); |
282 memcpy(first->body + first->body_len, msg->body, msg->body_len); | 283 memcpy(first->body + first->body_len, msg->body, msg->body_len); |
283 first->body_len += msg->body_len; | 284 first->body_len += msg->body_len; |
284 first->received_chunks++; | 285 first->received_chunks++; |
285 if (first->received_chunks != first->total_chunks) | 286 if (first->received_chunks != first->total_chunks) |
288 /* We're done! Send it along... The caller takes care of | 289 /* We're done! Send it along... The caller takes care of |
289 freeing the old one. */ | 290 freeing the old one. */ |
290 msg = first; | 291 msg = first; |
291 } else { | 292 } else { |
292 /* TODO: Can you legitimately receive chunks out of order? */ | 293 /* TODO: Can you legitimately receive chunks out of order? */ |
293 g_hash_table_remove(cmdproc->multiparts, messageId); | 294 g_hash_table_remove(cmdproc->multiparts, message_id); |
294 return; | 295 return; |
295 } | 296 } |
296 } else { | 297 } else { |
297 purple_debug_error("msn", "Received MessageId '%s' with no chunk number!\n", messageId); | 298 purple_debug_error("msn", "Received MessageId '%s' with no chunk number!\n", message_id); |
298 } | 299 } |
299 } | 300 } |
300 } | 301 } |
301 | 302 |
302 if (msn_message_get_content_type(msg) == NULL) | 303 if (msn_message_get_content_type(msg) == NULL) |
312 cb(cmdproc, msg); | 313 cb(cmdproc, msg); |
313 else | 314 else |
314 purple_debug_warning("msn", "Unhandled content-type '%s'\n", | 315 purple_debug_warning("msn", "Unhandled content-type '%s'\n", |
315 msn_message_get_content_type(msg)); | 316 msn_message_get_content_type(msg)); |
316 | 317 |
317 if (messageId != NULL) | 318 if (message_id != NULL) |
318 g_hash_table_remove(cmdproc->multiparts, messageId); | 319 g_hash_table_remove(cmdproc->multiparts, message_id); |
319 } | 320 } |
320 | 321 |
321 void | 322 void |
322 msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | 323 msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
323 { | 324 { |