1276 handle_state_events(from, m->node); |
1280 handle_state_events(from, m->node); |
1277 } |
1281 } |
1278 |
1282 |
1279 // Check for carbons! |
1283 // Check for carbons! |
1280 x = lm_message_node_find_xmlns(m->node, NS_CARBONS_2); |
1284 x = lm_message_node_find_xmlns(m->node, NS_CARBONS_2); |
1281 char carbons = 0; |
1285 gboolean carbons = FALSE; |
1282 if (x) { |
1286 if (x) { |
1283 carbons = 1; |
1287 carbons = TRUE; |
1284 // Parse a message that is send to one of our other resources |
1288 // Parse a message that is send to one of our other resources |
1285 if (!g_strcmp0(x->name, "received")) { |
1289 if (!g_strcmp0(x->name, "received")) { |
1286 // Go 1 level deeper to the forwarded message |
1290 // Go 1 level deeper to the forwarded message |
1287 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0"); |
1291 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0"); |
1288 x = lm_message_node_get_child(x, "message"); |
1292 x = lm_message_node_get_child(x, "message"); |
1289 |
1293 |
1290 from = lm_message_node_get_attribute(x, "from"); |
1294 from = lm_message_node_get_attribute(x, "from"); |
|
1295 if (!from) { |
|
1296 scr_LogPrint(LPRINT_LOGNORM, "Malformed carbon copy!"); |
|
1297 goto handle_messages_return; |
|
1298 } |
1291 g_free(bjid); |
1299 g_free(bjid); |
1292 bjid = g_strdup(from); |
1300 bjid = g_strdup(from); |
1293 res = strchr(bjid, JID_RESOURCE_SEPARATOR); |
1301 res = strchr(bjid, JID_RESOURCE_SEPARATOR); |
1294 if (res) *res++ = 0; |
1302 if (res) *res++ = 0; |
1295 scr_WriteIncomingMessage(bjid, body, timestamp, HBB_PREFIX_IN, 0); |
1303 |
1296 |
1304 if (body && *body && !subject && !enc) |
1297 scr_LogPrint(LPRINT_DEBUG, "carbon from:%s", |
1305 ns_signed = lm_message_node_find_xmlns(x, NS_SIGNED); |
1298 lm_message_node_get_attribute(x, "from")); |
1306 else |
|
1307 skip_process = TRUE; |
|
1308 |
|
1309 // We (probably) cannot handle encrypted forwarded messages |
|
1310 if (lm_message_node_find_xmlns(x, NS_ENCRYPTED)) |
|
1311 skip_process = TRUE; |
|
1312 |
|
1313 // Try to handle forwarded chat state messages |
|
1314 if (!skip_process) |
|
1315 handle_state_events(from, x); |
|
1316 |
|
1317 scr_LogPrint(LPRINT_DEBUG, "Received incoming carbon from <%s>", from); |
1299 |
1318 |
1300 } else if (!g_strcmp0(x->name, "sent")) { |
1319 } else if (!g_strcmp0(x->name, "sent")) { |
1301 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0"); |
1320 x = lm_message_node_find_xmlns(x, "urn:xmpp:forward:0"); |
1302 x = lm_message_node_get_child(x, "message"); |
1321 x = lm_message_node_get_child(x, "message"); |
1303 |
1322 |
1304 const char *to= lm_message_node_get_attribute(x, "to"); |
1323 const char *to= lm_message_node_get_attribute(x, "to"); |
|
1324 if (!to) { |
|
1325 scr_LogPrint(LPRINT_LOGNORM, "Malformed carbon copy!"); |
|
1326 goto handle_messages_return; |
|
1327 } |
1305 g_free(bjid); |
1328 g_free(bjid); |
1306 bjid = g_strdup(to); |
1329 bjid = jidtodisp(to); |
1307 res = strchr(bjid, JID_RESOURCE_SEPARATOR); |
1330 |
1308 if (res) *res++ = 0; |
1331 if (body && *body) |
1309 |
1332 hk_message_out(bjid, NULL, timestamp, body, 0, NULL); |
1310 scr_write_outgoing_message(bjid, body, 0, NULL); |
1333 |
1311 } |
1334 scr_LogPrint(LPRINT_DEBUG, "Received outgoing carbon for <%s>", to); |
1312 } |
1335 goto handle_messages_return; |
1313 |
1336 } |
1314 |
1337 } else { // Not a Carbon |
1315 if (from && (body || subject) && !carbons) |
1338 ns_signed = lm_message_node_find_xmlns(m->node, NS_SIGNED); |
|
1339 } |
|
1340 |
|
1341 // Do not process the message if some fields are missing |
|
1342 if (!from || (!body && !subject)) |
|
1343 skip_process = TRUE; |
|
1344 |
|
1345 if (!skip_process) { |
1316 gotmessage(mstype, from, body, enc, subject, timestamp, |
1346 gotmessage(mstype, from, body, enc, subject, timestamp, |
1317 lm_message_node_find_xmlns(m->node, NS_SIGNED)); |
1347 ns_signed, carbons); |
|
1348 } |
|
1349 |
|
1350 // We're done if it was a Carbon forwarded message |
|
1351 if (carbons) |
|
1352 goto handle_messages_return; |
1318 |
1353 |
1319 // Report received message if message delivery receipt was requested |
1354 // Report received message if message delivery receipt was requested |
1320 if (lm_message_node_get_child(m->node, "request") && |
1355 if (lm_message_node_get_child(m->node, "request") && |
1321 (roster_getsubscription(bjid) & sub_from)) { |
1356 (roster_getsubscription(bjid) & sub_from)) { |
1322 const gchar *mid; |
1357 const gchar *mid; |