comparison libpurple/protocols/zephyr/zephyr.c @ 24543:a6a6a6c19058

A Warmenhoved patch from rwbarton to avoid showing the default instance name (PERSONAL) in Zephyr chats and to show the instance before the sender name for other instances. Fixes #3007 The functional change is two lines, but I cleaned up some string allocation mess at the same time. I don't use Zephyr, so this may not work. I should be getting access to a test account soon, though.
author Richard Laager <rlaager@wiktel.com>
date Wed, 26 Nov 2008 21:40:37 +0000
parents 4777c4681776
children 737bf6236bd3
comparison
equal deleted inserted replaced
24542:4777c4681776 24543:a6a6a6c19058
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
846 buf3 = zephyr_recv_convert(gc, 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); 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);
904 #endif 905 #endif
905 purple_conv_chat_add_user(gcc, sendertmp, ipaddr, PURPLE_CBFLAGS_NONE, TRUE); 906 purple_conv_chat_add_user(gcc, sendertmp, ipaddr, PURPLE_CBFLAGS_NONE, TRUE);
906 } 907 }
907 g_free(sendertmp); 908 g_free(sendertmp);
908 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); 909 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); 910 g_free(send_inst_utf8);
911 911
912 free_triple(zt1); 912 free_triple(zt1);
913 } 913 }
914 g_free(stripped_sender);
914 g_free(buf3); 915 g_free(buf3);
915
916 } 916 }
917 } 917 }
918 918
919 static int free_parse_tree(parse_tree* tree) { 919 static int free_parse_tree(parse_tree* tree) {
920 if (!tree) { 920 if (!tree) {