Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/xmpp.c @ 1984:b0470ef8669b
XEP 184: don't send receipts to buddies that have no presence subscription
In order to not leak our presence, do not send message delivery receipts to
senders who are not authorized to view our presence. (XEP-0184, section 8)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 27 Mar 2011 12:45:41 +0200 |
parents | 6febc7d1f760 |
children | 024bdd1c6418 |
comparison
equal
deleted
inserted
replaced
1983:45e0b13a39e2 | 1984:b0470ef8669b |
---|---|
1201 static LmHandlerResult handle_messages(LmMessageHandler *handler, | 1201 static LmHandlerResult handle_messages(LmMessageHandler *handler, |
1202 LmConnection *connection, | 1202 LmConnection *connection, |
1203 LmMessage *m, gpointer user_data) | 1203 LmMessage *m, gpointer user_data) |
1204 { | 1204 { |
1205 const char *p, *from=lm_message_get_from(m); | 1205 const char *p, *from=lm_message_get_from(m); |
1206 char *r, *s; | 1206 char *bjid, *res; |
1207 LmMessageNode *x; | 1207 LmMessageNode *x; |
1208 const char *body = NULL; | 1208 const char *body = NULL; |
1209 const char *enc = NULL; | 1209 const char *enc = NULL; |
1210 const char *subject = NULL; | 1210 const char *subject = NULL; |
1211 time_t timestamp = 0L; | 1211 time_t timestamp = 0L; |
1217 | 1217 |
1218 x = lm_message_node_find_xmlns(m->node, NS_ENCRYPTED); | 1218 x = lm_message_node_find_xmlns(m->node, NS_ENCRYPTED); |
1219 if (x && (p = lm_message_node_get_value(x)) != NULL) | 1219 if (x && (p = lm_message_node_get_value(x)) != NULL) |
1220 enc = p; | 1220 enc = p; |
1221 | 1221 |
1222 // Get the bare-JID/room (bjid) and the resource/nickname (res) | |
1223 bjid = g_strdup(lm_message_get_from(m)); | |
1224 res = strchr(bjid, JID_RESOURCE_SEPARATOR); | |
1225 if (res) *res++ = 0; | |
1226 | |
1222 p = lm_message_node_get_child_value(m->node, "subject"); | 1227 p = lm_message_node_get_child_value(m->node, "subject"); |
1223 if (p != NULL) { | 1228 if (p != NULL) { |
1224 if (mstype != LM_MESSAGE_SUB_TYPE_GROUPCHAT) { | 1229 if (mstype != LM_MESSAGE_SUB_TYPE_GROUPCHAT) { |
1225 // Chat message | 1230 // Chat message |
1226 subject = p; | 1231 subject = p; |
1227 } else { // Room topic | 1232 } else { |
1233 // Room topic | |
1228 GSList *roombuddy; | 1234 GSList *roombuddy; |
1229 gchar *mbuf; | 1235 gchar *mbuf; |
1230 const gchar *subj = p; | 1236 const gchar *subj = p; |
1231 // Get the room (s) and the nickname (r) | |
1232 s = g_strdup(lm_message_get_from(m)); | |
1233 r = strchr(s, JID_RESOURCE_SEPARATOR); | |
1234 if (r) *r++ = 0; | |
1235 else r = s; | |
1236 // Set the new topic | 1237 // Set the new topic |
1237 roombuddy = roster_find(s, jidsearch, 0); | 1238 roombuddy = roster_find(bjid, jidsearch, 0); |
1238 if (roombuddy) | 1239 if (roombuddy) |
1239 buddy_settopic(roombuddy->data, subj); | 1240 buddy_settopic(roombuddy->data, subj); |
1240 // Display inside the room window | 1241 // Display inside the room window |
1241 if (r == s) { | 1242 if (!res) { |
1242 // No specific resource (this is certainly history) | 1243 // No specific resource (this is certainly history) |
1243 if (*subj) | 1244 if (*subj) |
1244 mbuf = g_strdup_printf("The topic has been set to: %s", subj); | 1245 mbuf = g_strdup_printf("The topic has been set to: %s", subj); |
1245 else | 1246 else |
1246 mbuf = g_strdup_printf("The topic has been cleared"); | 1247 mbuf = g_strdup_printf("The topic has been cleared"); |
1247 } else { | 1248 } else { |
1248 if (*subj) | 1249 if (*subj) |
1249 mbuf = g_strdup_printf("%s has set the topic to: %s", r, subj); | 1250 mbuf = g_strdup_printf("%s has set the topic to: %s", res, subj); |
1250 else | 1251 else |
1251 mbuf = g_strdup_printf("%s has cleared the topic", r); | 1252 mbuf = g_strdup_printf("%s has cleared the topic", res); |
1252 } | 1253 } |
1253 scr_WriteIncomingMessage(s, mbuf, 0, | 1254 scr_WriteIncomingMessage(bjid, mbuf, 0, |
1254 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); | 1255 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
1255 if (settings_opt_get_int("log_muc_conf")) | 1256 if (settings_opt_get_int("log_muc_conf")) |
1256 hlog_write_message(s, 0, -1, mbuf); | 1257 hlog_write_message(bjid, 0, -1, mbuf); |
1257 g_free(s); | |
1258 g_free(mbuf); | 1258 g_free(mbuf); |
1259 // The topic is displayed in the chat status line, so refresh now. | 1259 // The topic is displayed in the chat status line, so refresh now. |
1260 scr_update_chat_status(TRUE); | 1260 scr_update_chat_status(TRUE); |
1261 } | 1261 } |
1262 } | 1262 } |
1273 chatstates_reset_probed(from); | 1273 chatstates_reset_probed(from); |
1274 #endif | 1274 #endif |
1275 } else { | 1275 } else { |
1276 handle_state_events(from, m->node); | 1276 handle_state_events(from, m->node); |
1277 } | 1277 } |
1278 | |
1278 if (from && (body || subject)) | 1279 if (from && (body || subject)) |
1279 gotmessage(mstype, from, body, enc, subject, timestamp, | 1280 gotmessage(mstype, from, body, enc, subject, timestamp, |
1280 lm_message_node_find_xmlns(m->node, NS_SIGNED)); | 1281 lm_message_node_find_xmlns(m->node, NS_SIGNED)); |
1281 // Report received message if message receipt was requested | 1282 |
1282 if (lm_message_node_get_child(m->node, "request")) { | 1283 // Report received message if message delivery receipt was requested |
1284 if (lm_message_node_get_child(m->node, "request") && | |
1285 (roster_getsubscription(bjid) & sub_from)) { | |
1283 const gchar *mid; | 1286 const gchar *mid; |
1284 LmMessageNode *y; | 1287 LmMessageNode *y; |
1285 LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE); | 1288 LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE); |
1286 mid = lm_message_get_id(m); | 1289 mid = lm_message_get_id(m); |
1287 // For backward compatibility (XEP184 < v.1.1): | 1290 // For backward compatibility (XEP184 < v.1.1): |
1309 got_invite(from, jid, reason, password, FALSE); | 1312 got_invite(from, jid, reason, password, FALSE); |
1310 } | 1313 } |
1311 } | 1314 } |
1312 } | 1315 } |
1313 | 1316 |
1317 g_free(bjid); | |
1314 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 1318 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1315 } | 1319 } |
1316 | 1320 |
1317 static LmHandlerResult cb_caps(LmMessageHandler *h, LmConnection *c, | 1321 static LmHandlerResult cb_caps(LmMessageHandler *h, LmConnection *c, |
1318 LmMessage *m, gpointer user_data) | 1322 LmMessage *m, gpointer user_data) |