comparison libpurple/protocols/zephyr/zephyr.c @ 26048:25e2ab1fff1d

propagate from branch 'im.pidgin.pidgin' (head dd7a36be12180dba9663c2b740553e89711d7644) to branch 'im.pidgin.pidgin.vv' (head 2149cf9a6d4604f6e78ed9a2bdb0bbc3d6041a36)
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sat, 06 Dec 2008 02:23:20 +0000
parents adf153852bcf ad6d8e627444
children 68f4edb42f39
comparison
equal deleted inserted replaced
26046:99055b8db16b 26048:25e2ab1fff1d
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 }
818 char *send_inst; 818 char *send_inst;
819 PurpleConversation *gconv1; 819 PurpleConversation *gconv1;
820 PurpleConvChat *gcc; 820 PurpleConvChat *gcc;
821 char *ptr = (char *) notice.z_message + (strlen(notice.z_message) + 1); 821 char *ptr = (char *) notice.z_message + (strlen(notice.z_message) + 1);
822 int len; 822 int len;
823 char *sendertmp = g_strdup_printf("%s", zephyr->username); 823 char *stripped_sender;
824 int signature_length = strlen(notice.z_message); 824 int signature_length = strlen(notice.z_message);
825 int message_has_no_body = 0; 825 int message_has_no_body = 0;
826 PurpleMessageFlags flags = 0; 826 PurpleMessageFlags flags = 0;
827 gchar *tmpescape; 827 gchar *tmpescape;
828 828
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, &notice.z_sender_addr.s_addr, ipaddr, sizeof(ipaddr)); 902 inet_ntop(AF_INET, &notice.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) {
2578 return; 2577 return;
2579 gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name, 2578 gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, zt->name,
2580 gc->account); 2579 gc->account);
2581 gcc = purple_conversation_get_chat_data(gconv); 2580 gcc = purple_conversation_get_chat_data(gconv);
2582 2581
2583 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic,strlen(topic)); 2582 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic);
2584 purple_conv_chat_set_topic(gcc,sender,topic_utf8); 2583 purple_conv_chat_set_topic(gcc,sender,topic_utf8);
2585 g_free(topic_utf8); 2584 g_free(topic_utf8);
2586 return; 2585 return;
2587 } 2586 }
2588 2587