| 1454 purple_debug_warning("gg", "Unknown search_type!\n"); |
1454 purple_debug_warning("gg", "Unknown search_type!\n"); |
| 1455 break; |
1455 break; |
| 1456 } |
1456 } |
| 1457 } |
1457 } |
| 1458 |
1458 |
| 1459 static void ggp_recv_image_handler(PurpleConnection *gc, const struct gg_event *ev) |
|
| 1460 { |
|
| 1461 gint imgid = 0; |
|
| 1462 GGPInfo *info = purple_connection_get_protocol_data(gc); |
|
| 1463 GList *entry = g_list_first(info->pending_richtext_messages); |
|
| 1464 gchar *handlerid = g_strdup_printf("IMGID_HANDLER-%i", ev->event.image_reply.crc32); |
|
| 1465 |
|
| 1466 imgid = purple_imgstore_add_with_id( |
|
| 1467 g_memdup(ev->event.image_reply.image, ev->event.image_reply.size), |
|
| 1468 ev->event.image_reply.size, |
|
| 1469 ev->event.image_reply.filename); |
|
| 1470 |
|
| 1471 purple_debug_info("gg", "ggp_recv_image_handler: got image with crc32: %u\n", ev->event.image_reply.crc32); |
|
| 1472 |
|
| 1473 while(entry) { |
|
| 1474 if (strstr((gchar *)entry->data, handlerid) != NULL) { |
|
| 1475 gchar **split = g_strsplit((gchar *)entry->data, handlerid, 3); |
|
| 1476 gchar *text = g_strdup_printf("%s%i%s", split[0], imgid, split[1]); |
|
| 1477 purple_debug_info("gg", "ggp_recv_image_handler: found message matching crc32: %s\n", (gchar *)entry->data); |
|
| 1478 g_strfreev(split); |
|
| 1479 info->pending_richtext_messages = g_list_remove(info->pending_richtext_messages, entry->data); |
|
| 1480 /* We don't have any more images to download */ |
|
| 1481 if (strstr(text, "<IMG ID=\"IMGID_HANDLER") == NULL) { |
|
| 1482 gchar *buf = g_strdup_printf("%lu", (unsigned long int)ev->event.image_reply.sender); |
|
| 1483 serv_got_im(gc, buf, text, PURPLE_MESSAGE_IMAGES, time(NULL)); |
|
| 1484 g_free(buf); |
|
| 1485 purple_debug_info("gg", "ggp_recv_image_handler: richtext message: %s\n", text); |
|
| 1486 g_free(text); |
|
| 1487 break; |
|
| 1488 } |
|
| 1489 info->pending_richtext_messages = g_list_append(info->pending_richtext_messages, text); |
|
| 1490 break; |
|
| 1491 } |
|
| 1492 entry = g_list_next(entry); |
|
| 1493 } |
|
| 1494 g_free(handlerid); |
|
| 1495 |
|
| 1496 return; |
|
| 1497 } |
|
| 1498 |
|
| 1499 |
|
| 1500 /** |
1459 /** |
| 1501 * Dispatch a message received from a buddy. |
1460 * Dispatch a message received from a buddy. |
| 1502 * |
1461 * |
| 1503 * @param gc PurpleConnection. |
1462 * @param gc PurpleConnection. |
| 1504 * @param ev Gadu-Gadu event structure. |
1463 * @param ev Gadu-Gadu event structure. |
| 1528 */ |
1488 */ |
| 1529 tmp = g_strdup_printf("%s", ev->event.msg.message); |
1489 tmp = g_strdup_printf("%s", ev->event.msg.message); |
| 1530 purple_str_strip_char(tmp, '\r'); |
1490 purple_str_strip_char(tmp, '\r'); |
| 1531 msg = g_markup_escape_text(tmp, -1); |
1491 msg = g_markup_escape_text(tmp, -1); |
| 1532 g_free(tmp); |
1492 g_free(tmp); |
| |
1493 |
| |
1494 if (ev->event.msg.msgclass & GG_CLASS_QUEUED) |
| |
1495 mtime = ev->event.msg.time; |
| |
1496 else |
| |
1497 mtime = time(NULL); |
| 1533 |
1498 |
| 1534 /* We got richtext message */ |
1499 /* We got richtext message */ |
| 1535 if (ev->event.msg.formats_length) |
1500 if (ev->event.msg.formats_length) |
| 1536 { |
1501 { |
| 1537 gboolean got_image = FALSE, bold = FALSE, italic = FALSE, under = FALSE; |
1502 gboolean got_image = FALSE, bold = FALSE, italic = FALSE, under = FALSE; |
| 1539 char *cformats_end = cformats + ev->event.msg.formats_length; |
1504 char *cformats_end = cformats + ev->event.msg.formats_length; |
| 1540 gint increased_len = 0; |
1505 gint increased_len = 0; |
| 1541 struct gg_msg_richtext_format *actformat; |
1506 struct gg_msg_richtext_format *actformat; |
| 1542 struct gg_msg_richtext_image *actimage; |
1507 struct gg_msg_richtext_image *actimage; |
| 1543 GString *message = g_string_new(msg); |
1508 GString *message = g_string_new(msg); |
| 1544 gchar *handlerid; |
|
| 1545 |
1509 |
| 1546 purple_debug_info("gg", "ggp_recv_message_handler: richtext msg from (%s): %s %i formats\n", from, msg, ev->event.msg.formats_length); |
1510 purple_debug_info("gg", "ggp_recv_message_handler: richtext msg from (%s): %s %i formats\n", from, msg, ev->event.msg.formats_length); |
| 1547 |
1511 |
| 1548 while (cformats < cformats_end) |
1512 while (cformats < cformats_end) |
| 1549 { |
1513 { |
| 1562 (actformat->font & GG_FONT_BOLD) != 0, |
1526 (actformat->font & GG_FONT_BOLD) != 0, |
| 1563 (actformat->font & GG_FONT_ITALIC) != 0, |
1527 (actformat->font & GG_FONT_ITALIC) != 0, |
| 1564 (actformat->font & GG_FONT_UNDERLINE) != 0, |
1528 (actformat->font & GG_FONT_UNDERLINE) != 0, |
| 1565 increased_len); |
1529 increased_len); |
| 1566 |
1530 |
| 1567 if (actformat->font & GG_FONT_IMAGE) { |
1531 if (actformat->font & GG_FONT_IMAGE) |
| |
1532 { |
| |
1533 const char *placeholder; |
| |
1534 |
| 1568 got_image = TRUE; |
1535 got_image = TRUE; |
| 1569 actimage = (struct gg_msg_richtext_image*)(cformats); |
1536 actimage = (struct gg_msg_richtext_image*)(cformats); |
| 1570 cformats += sizeof(struct gg_msg_richtext_image); |
1537 cformats += sizeof(struct gg_msg_richtext_image); |
| 1571 purple_debug_info("gg", "ggp_recv_message_handler: image received, size: %d, crc32: %i\n", actimage->size, actimage->crc32); |
1538 purple_debug_info("gg", "ggp_recv_message_handler: image received, size: %d, crc32: %i\n", actimage->size, actimage->crc32); |
| 1572 |
1539 |
| 1578 } |
1545 } |
| 1579 |
1546 |
| 1580 gg_image_request(info->session, ev->event.msg.sender, |
1547 gg_image_request(info->session, ev->event.msg.sender, |
| 1581 actimage->size, actimage->crc32); |
1548 actimage->size, actimage->crc32); |
| 1582 |
1549 |
| 1583 handlerid = g_strdup_printf("<IMG ID=\"IMGID_HANDLER-%i\">", actimage->crc32); |
1550 placeholder = ggp_image_pending_placeholder(actimage->crc32); |
| 1584 g_string_insert(message, byteoffset, handlerid); |
1551 g_string_insert(message, byteoffset, placeholder); |
| 1585 increased_len += strlen(handlerid); |
1552 increased_len += strlen(placeholder); |
| 1586 g_free(handlerid); |
|
| 1587 continue; |
1553 continue; |
| 1588 } |
1554 } |
| 1589 |
1555 |
| 1590 if (actformat->font & GG_FONT_BOLD) { |
1556 if (actformat->font & GG_FONT_BOLD) { |
| 1591 if (bold == FALSE) { |
1557 if (bold == FALSE) { |
| 1629 } |
1595 } |
| 1630 |
1596 |
| 1631 msg = message->str; |
1597 msg = message->str; |
| 1632 g_string_free(message, FALSE); |
1598 g_string_free(message, FALSE); |
| 1633 |
1599 |
| 1634 if (got_image) { |
1600 if (got_image) |
| 1635 info->pending_richtext_messages = g_list_append(info->pending_richtext_messages, msg); |
1601 { |
| |
1602 ggp_image_got_im(gc, sender, msg, mtime); |
| 1636 return; |
1603 return; |
| 1637 } |
1604 } |
| 1638 } |
1605 } |
| 1639 |
1606 |
| 1640 purple_debug_info("gg", "ggp_recv_message_handler: msg from (%s): %s (class = %d; rcpt_count = %d)\n", |
1607 purple_debug_info("gg", "ggp_recv_message_handler: msg from (%s): %s (class = %d; rcpt_count = %d)\n", |
| 1641 from, msg, ev->event.msg.msgclass, |
1608 from, msg, ev->event.msg.msgclass, |
| 1642 ev->event.msg.recipients_count); |
1609 ev->event.msg.recipients_count); |
| 1643 |
|
| 1644 if (ev->event.msg.msgclass & GG_CLASS_QUEUED) |
|
| 1645 mtime = ev->event.msg.time; |
|
| 1646 else |
|
| 1647 mtime = time(NULL); |
|
| 1648 |
1610 |
| 1649 if (ev->event.msg.recipients_count == 0) { |
1611 if (ev->event.msg.recipients_count == 0) { |
| 1650 serv_got_im(gc, from, msg, 0, mtime); |
1612 serv_got_im(gc, from, msg, 0, mtime); |
| 1651 } else { |
1613 } else { |
| 1652 const char *chat_name; |
1614 const char *chat_name; |
| 1678 } |
1640 } |
| 1679 g_free(msg); |
1641 g_free(msg); |
| 1680 g_free(from); |
1642 g_free(from); |
| 1681 } |
1643 } |
| 1682 |
1644 |
| |
1645 /* TODO: image */ |
| 1683 static void ggp_send_image_handler(PurpleConnection *gc, const struct gg_event *ev) |
1646 static void ggp_send_image_handler(PurpleConnection *gc, const struct gg_event *ev) |
| 1684 { |
1647 { |
| 1685 GGPInfo *info = purple_connection_get_protocol_data(gc); |
1648 GGPInfo *info = purple_connection_get_protocol_data(gc); |
| 1686 PurpleStoredImage *image; |
1649 PurpleStoredImage *image; |
| 1687 gint imgid = GPOINTER_TO_INT(g_hash_table_lookup(info->pending_images, GINT_TO_POINTER(ev->event.image_request.crc32))); |
1650 gint imgid = GPOINTER_TO_INT(g_hash_table_lookup(info->image_data.pending_images, GINT_TO_POINTER(ev->event.image_request.crc32))); |
| 1688 |
1651 |
| 1689 purple_debug_info("gg", "ggp_send_image_handler: image request received, crc32: %u, imgid: %d\n", ev->event.image_request.crc32, imgid); |
1652 purple_debug_info("gg", "ggp_send_image_handler: image request received, crc32: %u, imgid: %d\n", ev->event.image_request.crc32, imgid); |
| 1690 |
1653 |
| 1691 if(imgid) |
1654 if(imgid) |
| 1692 { |
1655 { |
| 1699 gg_image_reply(info->session, (unsigned long int)ev->event.image_request.sender, image_filename, image_bin, image_size); |
1662 gg_image_reply(info->session, (unsigned long int)ev->event.image_request.sender, image_filename, image_bin, image_size); |
| 1700 purple_imgstore_unref(image); |
1663 purple_imgstore_unref(image); |
| 1701 } else { |
1664 } else { |
| 1702 purple_debug_error("gg", "ggp_send_image_handler: image imgid: %i, crc: %u in hash but not found in imgstore!\n", imgid, ev->event.image_request.crc32); |
1665 purple_debug_error("gg", "ggp_send_image_handler: image imgid: %i, crc: %u in hash but not found in imgstore!\n", imgid, ev->event.image_request.crc32); |
| 1703 } |
1666 } |
| 1704 g_hash_table_remove(info->pending_images, GINT_TO_POINTER(ev->event.image_request.crc32)); |
1667 g_hash_table_remove(info->image_data.pending_images, GINT_TO_POINTER(ev->event.image_request.crc32)); |
| 1705 } |
1668 } |
| 1706 } |
1669 } |
| 1707 |
1670 |
| 1708 static void ggp_typing_notification_handler(PurpleConnection *gc, uin_t uin, int length) { |
1671 static void ggp_typing_notification_handler(PurpleConnection *gc, uin_t uin, int length) { |
| 1709 gchar *from; |
1672 gchar *from; |
| 1814 "ggp_callback_recv: message sent to: %i, delivery status=%d, seq=%d\n", |
1777 "ggp_callback_recv: message sent to: %i, delivery status=%d, seq=%d\n", |
| 1815 ev->event.ack.recipient, ev->event.ack.status, |
1778 ev->event.ack.recipient, ev->event.ack.status, |
| 1816 ev->event.ack.seq); |
1779 ev->event.ack.seq); |
| 1817 break; |
1780 break; |
| 1818 case GG_EVENT_IMAGE_REPLY: |
1781 case GG_EVENT_IMAGE_REPLY: |
| 1819 ggp_recv_image_handler(gc, ev); |
1782 ggp_image_recv(gc, &ev->event.image_reply); |
| 1820 break; |
1783 break; |
| 1821 case GG_EVENT_IMAGE_REQUEST: |
1784 case GG_EVENT_IMAGE_REQUEST: |
| 1822 ggp_send_image_handler(gc, ev); |
1785 ggp_send_image_handler(gc, ev); |
| 1823 break; |
1786 break; |
| 1824 case GG_EVENT_NOTIFY: |
1787 case GG_EVENT_NOTIFY: |
| 2274 info->session = NULL; |
2237 info->session = NULL; |
| 2275 info->chats = NULL; |
2238 info->chats = NULL; |
| 2276 info->chats_count = 0; |
2239 info->chats_count = 0; |
| 2277 info->token = NULL; |
2240 info->token = NULL; |
| 2278 info->searches = ggp_search_new(); |
2241 info->searches = ggp_search_new(); |
| 2279 info->pending_richtext_messages = NULL; |
|
| 2280 info->pending_images = g_hash_table_new(g_direct_hash, g_direct_equal); |
|
| 2281 info->status_broadcasting = purple_account_get_bool(account, "status_broadcasting", TRUE); |
2242 info->status_broadcasting = purple_account_get_bool(account, "status_broadcasting", TRUE); |
| 2282 |
2243 |
| 2283 purple_connection_set_protocol_data(gc, info); |
2244 purple_connection_set_protocol_data(gc, info); |
| 2284 |
2245 |
| |
2246 ggp_image_setup(gc); |
| |
2247 |
| 2285 glp->uin = ggp_get_uin(account); |
2248 glp->uin = ggp_get_uin(account); |
| 2286 glp->password = charset_convert(purple_account_get_password(account), |
2249 glp->password = charset_convert(purple_account_get_password(account), |
| 2287 "UTF-8", "CP1250"); |
2250 "UTF-8", "CP1250"); |
| 2288 |
2251 |
| 2289 if (glp->uin == 0) { |
2252 if (glp->uin == 0) { |
| 2393 * upon the contents of info->searches, which we are about to destroy. |
2356 * upon the contents of info->searches, which we are about to destroy. |
| 2394 */ |
2357 */ |
| 2395 purple_notify_close_with_handle(gc); |
2358 purple_notify_close_with_handle(gc); |
| 2396 |
2359 |
| 2397 ggp_search_destroy(info->searches); |
2360 ggp_search_destroy(info->searches); |
| 2398 g_list_free(info->pending_richtext_messages); |
2361 ggp_image_free(gc); |
| 2399 g_hash_table_destroy(info->pending_images); |
|
| 2400 |
2362 |
| 2401 if (info->inpa > 0) |
2363 if (info->inpa > 0) |
| 2402 purple_input_remove(info->inpa); |
2364 purple_input_remove(info->inpa); |
| 2403 |
2365 |
| 2404 purple_connection_set_protocol_data(gc, NULL); |
2366 purple_connection_set_protocol_data(gc, NULL); |
| 2441 if(start - last) { |
2403 if(start - last) { |
| 2442 pos = pos + g_utf8_strlen(last, start - last); |
2404 pos = pos + g_utf8_strlen(last, start - last); |
| 2443 g_string_append_len(string_buffer, last, start - last); |
2405 g_string_append_len(string_buffer, last, start - last); |
| 2444 } |
2406 } |
| 2445 |
2407 |
| |
2408 /* TODO: image */ |
| 2446 if((id = g_datalist_get_data(&attribs, "id")) && (image = purple_imgstore_find_by_id(atoi(id)))) { |
2409 if((id = g_datalist_get_data(&attribs, "id")) && (image = purple_imgstore_find_by_id(atoi(id)))) { |
| 2447 struct gg_msg_richtext_format actformat; |
2410 struct gg_msg_richtext_format actformat; |
| 2448 struct gg_msg_richtext_image actimage; |
2411 struct gg_msg_richtext_image actimage; |
| 2449 gint image_size = purple_imgstore_get_size(image); |
2412 gint image_size = purple_imgstore_get_size(image); |
| 2450 gconstpointer image_bin = purple_imgstore_get_data(image); |
2413 gconstpointer image_bin = purple_imgstore_get_data(image); |
| 2451 const char *image_filename = purple_imgstore_get_filename(image); |
2414 const char *image_filename = purple_imgstore_get_filename(image); |
| 2452 uint32_t crc32 = gg_crc32(0, image_bin, image_size); |
2415 uint32_t crc32 = gg_crc32(0, image_bin, image_size); |
| 2453 |
2416 |
| 2454 g_hash_table_insert(info->pending_images, GINT_TO_POINTER(crc32), GINT_TO_POINTER(atoi(id))); |
2417 g_hash_table_insert(info->image_data.pending_images, GINT_TO_POINTER(crc32), GINT_TO_POINTER(atoi(id))); |
| 2455 purple_imgstore_ref(image); |
2418 purple_imgstore_ref(image); |
| 2456 purple_debug_info("gg", "ggp_send_im_richtext: got crc: %u for imgid: %i\n", crc32, atoi(id)); |
2419 purple_debug_info("gg", "ggp_send_im_richtext: got crc: %u for imgid: %i\n", crc32, atoi(id)); |
| 2457 |
2420 |
| 2458 actformat.font = GG_FONT_IMAGE; |
2421 actformat.font = GG_FONT_IMAGE; |
| 2459 actformat.position = pos; |
2422 actformat.position = pos; |