comparison mcabber/mcabber/xmpp.c @ 2166:f51c341a9da5

Simplify handle_state_events()
author franky
date Fri, 17 Oct 2014 22:39:05 +0200
parents db6ca1e1e082
children 634cc23e8c1c
comparison
equal deleted inserted replaced
2165:db6ca1e1e082 2166:f51c341a9da5
850 scr_LogPrint(LPRINT_NORMAL, "Disconnected, reason: %d->'%s'", reason, str); 850 scr_LogPrint(LPRINT_NORMAL, "Disconnected, reason: %d->'%s'", reason, str);
851 851
852 xmpp_setstatus(offline, NULL, mystatusmsg, TRUE); 852 xmpp_setstatus(offline, NULL, mystatusmsg, TRUE);
853 } 853 }
854 854
855 static void handle_state_events(const char *from, LmMessageNode *node) 855 static void handle_state_events(const char *bjid,
856 const char *resource,
857 LmMessageNode *node)
856 { 858 {
857 #if defined XEP0085 859 #if defined XEP0085
858 LmMessageNode *state_ns = NULL; 860 LmMessageNode *state_ns = NULL;
859 char *rname, *bjid;
860 GSList *sl_buddy; 861 GSList *sl_buddy;
861 struct xep0085 *xep85 = NULL; 862 struct xep0085 *xep85 = NULL;
862 863
863 rname = strchr(from, JID_RESOURCE_SEPARATOR);
864 if (rname)
865 ++rname;
866 else
867 rname = (char *)from + strlen(from);
868 bjid = jidtodisp(from);
869 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); 864 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER);
870 g_free(bjid);
871 865
872 if (!sl_buddy) { 866 if (!sl_buddy) {
873 return; 867 return;
874 } 868 }
875 869
876 /* Let's see whether the contact supports XEP0085 */ 870 /* Let's see whether the contact supports XEP0085 */
877 xep85 = buddy_resource_xep85(sl_buddy->data, rname); 871 xep85 = buddy_resource_xep85(sl_buddy->data, resource);
878 if (xep85) 872 if (xep85)
879 state_ns = lm_message_node_find_xmlns(node, NS_CHATSTATES); 873 state_ns = lm_message_node_find_xmlns(node, NS_CHATSTATES);
880 874
881 if (!state_ns) { /* Sender does not use chat states */ 875 if (!state_ns) { /* Sender does not use chat states */
882 return; 876 return;
894 xep85->last_state_rcvd = ROSTER_EVENT_INACTIVE; 888 xep85->last_state_rcvd = ROSTER_EVENT_INACTIVE;
895 } else if (!strcmp(state_ns->name, "gone")) { 889 } else if (!strcmp(state_ns->name, "gone")) {
896 xep85->last_state_rcvd = ROSTER_EVENT_GONE; 890 xep85->last_state_rcvd = ROSTER_EVENT_GONE;
897 } 891 }
898 892
899 buddy_resource_setevents(sl_buddy->data, rname, xep85->last_state_rcvd); 893 buddy_resource_setevents(sl_buddy->data, resource, xep85->last_state_rcvd);
900 update_roster = TRUE; 894 update_roster = TRUE;
901 #endif 895 #endif
902 } 896 }
903 897
904 static void gotmessage(LmMessageSubType type, const char *from, 898 static void gotmessage(LmMessageSubType type, const char *from,
1094 // If the XEP85/22 support is probed, set it back to unknown so that 1088 // If the XEP85/22 support is probed, set it back to unknown so that
1095 // we probe it again. 1089 // we probe it again.
1096 chatstates_reset_probed(from); 1090 chatstates_reset_probed(from);
1097 #endif 1091 #endif
1098 } else { 1092 } else {
1099 handle_state_events(from, m->node); 1093 handle_state_events(bjid, res, m->node);
1100 } 1094 }
1101 1095
1102 // Check for carbons! 1096 // Check for carbons!
1103 x = lm_message_node_find_xmlns(m->node, NS_CARBONS_2); 1097 x = lm_message_node_find_xmlns(m->node, NS_CARBONS_2);
1104 gboolean carbons = FALSE; 1098 gboolean carbons = FALSE;
1124 ns_signed = lm_message_node_find_xmlns(x, NS_SIGNED); 1118 ns_signed = lm_message_node_find_xmlns(x, NS_SIGNED);
1125 else 1119 else
1126 skip_process = TRUE; 1120 skip_process = TRUE;
1127 1121
1128 // Try to handle forwarded chat state messages 1122 // Try to handle forwarded chat state messages
1129 handle_state_events(from, x); 1123 handle_state_events(from, res, x);
1130 1124
1131 scr_LogPrint(LPRINT_DEBUG, "Received incoming carbon from <%s>", from); 1125 scr_LogPrint(LPRINT_DEBUG, "Received incoming carbon from <%s>", from);
1132 1126
1133 } else if (!g_strcmp0(x->name, "sent")) { 1127 } else if (!g_strcmp0(x->name, "sent")) {
1134 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0"); 1128 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0");