| 341 |
341 |
| 342 /* |
342 /* |
| 343 Converts strings to utf-8 if necessary using user specified encoding |
343 Converts strings to utf-8 if necessary using user specified encoding |
| 344 */ |
344 */ |
| 345 |
345 |
| 346 static gchar *zephyr_recv_convert(PurpleConnection *gc,gchar *string, int len) |
346 static gchar *zephyr_recv_convert(PurpleConnection *gc, gchar *string) |
| 347 { |
347 { |
| 348 gchar *utf8; |
348 gchar *utf8; |
| 349 GError *err = NULL; |
349 GError *err = NULL; |
| 350 zephyr_account *zephyr = gc->proto_data; |
350 zephyr_account *zephyr = gc->proto_data; |
| 351 if (g_utf8_validate(string, len, NULL)) { |
351 if (g_utf8_validate(string, -1, NULL)) { |
| 352 return g_strdup(string); |
352 return g_strdup(string); |
| 353 } else { |
353 } else { |
| 354 utf8 = g_convert(string, len, "UTF-8", zephyr->encoding, NULL, NULL, &err); |
354 utf8 = g_convert(string, -1, "UTF-8", zephyr->encoding, NULL, NULL, &err); |
| 355 if (err) { |
355 if (err) { |
| 356 purple_debug_error("zephyr", "recv conversion error: %s\n", err->message); |
356 purple_debug_error("zephyr", "recv conversion error: %s\n", err->message); |
| 357 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
357 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
| 358 g_error_free(err); |
358 g_error_free(err); |
| 359 } |
359 } |
| 841 g_snprintf(buf, len + 1, "%s", ptr); |
841 g_snprintf(buf, len + 1, "%s", ptr); |
| 842 g_strchomp(buf); |
842 g_strchomp(buf); |
| 843 tmpescape = g_markup_escape_text(buf, -1); |
843 tmpescape = g_markup_escape_text(buf, -1); |
| 844 g_free(buf); |
844 g_free(buf); |
| 845 buf2 = zephyr_to_html(tmpescape); |
845 buf2 = zephyr_to_html(tmpescape); |
| 846 buf3 = zephyr_recv_convert(gc,buf2, strlen(buf2)); |
846 buf3 = zephyr_recv_convert(gc, buf2); |
| 847 g_free(buf2); |
847 g_free(buf2); |
| 848 g_free(tmpescape); |
848 g_free(tmpescape); |
| 849 } |
849 } |
| 850 |
850 |
| |
851 stripped_sender = zephyr_strip_local_realm(zephyr,notice.z_sender); |
| |
852 |
| 851 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL") |
853 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL") |
| 852 && !g_ascii_strcasecmp(notice.z_recipient,zephyr->username)) { |
854 && !g_ascii_strcasecmp(notice.z_recipient,zephyr->username)) { |
| 853 gchar* stripped_sender; |
|
| 854 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) |
855 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) |
| 855 flags |= PURPLE_MESSAGE_AUTO_RESP; |
856 flags |= PURPLE_MESSAGE_AUTO_RESP; |
| 856 stripped_sender = zephyr_strip_local_realm(zephyr,notice.z_sender); |
|
| 857 |
857 |
| 858 if (!g_ascii_strcasecmp(notice.z_opcode,"PING")) |
858 if (!g_ascii_strcasecmp(notice.z_opcode,"PING")) |
| 859 serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, PURPLE_TYPING); |
859 serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, PURPLE_TYPING); |
| 860 else |
860 else |
| 861 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL)); |
861 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL)); |
| 862 |
862 |
| 863 g_free(stripped_sender); |
|
| 864 } else { |
863 } else { |
| 865 zephyr_triple *zt1, *zt2; |
864 zephyr_triple *zt1, *zt2; |
| 866 gchar *send_inst_utf8; |
865 gchar *send_inst_utf8; |
| 867 zephyr_account *zephyr = gc->proto_data; |
866 zephyr_account *zephyr = gc->proto_data; |
| 868 zt1 = new_triple(gc->proto_data,notice.z_class, notice.z_class_inst, notice.z_recipient); |
867 zt1 = new_triple(gc->proto_data,notice.z_class, notice.z_class_inst, notice.z_recipient); |
| 876 if (!zt2->open) { |
875 if (!zt2->open) { |
| 877 zt2->open = TRUE; |
876 zt2->open = TRUE; |
| 878 serv_got_joined_chat(gc, zt2->id, zt2->name); |
877 serv_got_joined_chat(gc, zt2->id, zt2->name); |
| 879 zephyr_chat_set_topic(gc,zt2->id,notice.z_class_inst); |
878 zephyr_chat_set_topic(gc,zt2->id,notice.z_class_inst); |
| 880 } |
879 } |
| 881 g_free(sendertmp); /* fix memory leak? */ |
880 |
| 882 /* If the person is in the default Realm, then strip the |
881 if (!g_ascii_strcasecmp(notice.z_class_inst,"PERSONAL")) |
| 883 Realm from the sender field */ |
882 send_inst_utf8 = g_strdup(stripped_sender); |
| 884 sendertmp = zephyr_strip_local_realm(zephyr,notice.z_sender); |
883 else { |
| 885 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
884 send_inst = g_strdup_printf("[%s] %s",notice.z_class_inst,stripped_sender); |
| 886 send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst)); |
885 send_inst_utf8 = zephyr_recv_convert(gc,send_inst); |
| 887 if (!send_inst_utf8) { |
886 g_free(send_inst); |
| 888 purple_debug_error("zephyr","send_inst %s became null\n", send_inst); |
887 if (!send_inst_utf8) { |
| 889 send_inst_utf8 = "malformed instance"; |
888 purple_debug_error("zephyr","Failed to convert instance for sender %s.\n", stripped_sender); |
| |
889 send_inst_utf8 = g_strdup(stripped_sender); |
| |
890 } |
| 890 } |
891 } |
| 891 |
892 |
| 892 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, |
893 gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, |
| 893 zt2->name, gc->account); |
894 zt2->name, gc->account); |
| 894 gcc = purple_conversation_get_chat_data(gconv1); |
895 gcc = purple_conversation_get_chat_data(gconv1); |
| 895 #ifndef INET_ADDRSTRLEN |
896 #ifndef INET_ADDRSTRLEN |
| 896 #define INET_ADDRSTRLEN 16 |
897 #define INET_ADDRSTRLEN 16 |
| 897 #endif |
898 #endif |
| 898 if (!purple_conv_chat_find_user(gcc, sendertmp)) { |
899 if (!purple_conv_chat_find_user(gcc, stripped_sender)) { |
| 899 gchar ipaddr[INET_ADDRSTRLEN]; |
900 gchar ipaddr[INET_ADDRSTRLEN]; |
| 900 #ifdef HAVE_INET_NTOP |
901 #ifdef HAVE_INET_NTOP |
| 901 inet_ntop(AF_INET, ¬ice.z_sender_addr.s_addr, ipaddr, sizeof(ipaddr)); |
902 inet_ntop(AF_INET, ¬ice.z_sender_addr.s_addr, ipaddr, sizeof(ipaddr)); |
| 902 #else |
903 #else |
| 903 memcpy(ipaddr,inet_ntoa(notice.z_sender_addr),sizeof(ipaddr)); |
904 memcpy(ipaddr,inet_ntoa(notice.z_sender_addr),sizeof(ipaddr)); |
| 904 #endif |
905 #endif |
| 905 purple_conv_chat_add_user(gcc, sendertmp, ipaddr, PURPLE_CBFLAGS_NONE, TRUE); |
906 purple_conv_chat_add_user(gcc, stripped_sender, ipaddr, PURPLE_CBFLAGS_NONE, TRUE); |
| 906 } |
907 } |
| 907 g_free(sendertmp); |
|
| 908 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); |
908 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); |
| 909 g_free(send_inst); |
|
| 910 g_free(send_inst_utf8); |
909 g_free(send_inst_utf8); |
| 911 |
910 |
| 912 free_triple(zt1); |
911 free_triple(zt1); |
| 913 } |
912 } |
| |
913 g_free(stripped_sender); |
| 914 g_free(buf3); |
914 g_free(buf3); |
| 915 |
|
| 916 } |
915 } |
| 917 } |
916 } |
| 918 |
917 |
| 919 static int free_parse_tree(parse_tree* tree) { |
918 static int free_parse_tree(parse_tree* tree) { |
| 920 if (!tree) { |
919 if (!tree) { |