Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/xmpp.c @ 1646:472cd6ac20fa
Small optimization
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 04 Nov 2009 22:18:31 +0100 |
parents | 73fc85ea0b4b |
children | cfa1fff86f78 |
comparison
equal
deleted
inserted
replaced
1645:d3cd4db23f55 | 1646:472cd6ac20fa |
---|---|
1156 LmMessageNode *x; | 1156 LmMessageNode *x; |
1157 const char *body = NULL; | 1157 const char *body = NULL; |
1158 const char *enc = NULL; | 1158 const char *enc = NULL; |
1159 const char *subject = NULL; | 1159 const char *subject = NULL; |
1160 time_t timestamp = 0L; | 1160 time_t timestamp = 0L; |
1161 LmMessageSubType mstype; | |
1162 | |
1163 mstype = lm_message_get_sub_type(m); | |
1161 | 1164 |
1162 body = lm_message_node_get_child_value(m->node, "body"); | 1165 body = lm_message_node_get_child_value(m->node, "body"); |
1163 | 1166 |
1164 x = lm_message_node_find_xmlns(m->node, NS_ENCRYPTED); | 1167 x = lm_message_node_find_xmlns(m->node, NS_ENCRYPTED); |
1165 if (x && (p = lm_message_node_get_value(x)) != NULL) | 1168 if (x && (p = lm_message_node_get_value(x)) != NULL) |
1166 enc = p; | 1169 enc = p; |
1167 | 1170 |
1168 p = lm_message_node_get_child_value(m->node, "subject"); | 1171 p = lm_message_node_get_child_value(m->node, "subject"); |
1169 if (p != NULL) { | 1172 if (p != NULL) { |
1170 if (lm_message_get_sub_type(m) != LM_MESSAGE_SUB_TYPE_GROUPCHAT) { | 1173 if (mstype != LM_MESSAGE_SUB_TYPE_GROUPCHAT) { |
1171 // Chat message | 1174 // Chat message |
1172 subject = p; | 1175 subject = p; |
1173 } else { // Room topic | 1176 } else { // Room topic |
1174 GSList *roombuddy; | 1177 GSList *roombuddy; |
1175 gchar *mbuf; | 1178 gchar *mbuf; |
1202 } | 1205 } |
1203 | 1206 |
1204 // Timestamp? | 1207 // Timestamp? |
1205 timestamp = lm_message_node_get_timestamp(m->node); | 1208 timestamp = lm_message_node_get_timestamp(m->node); |
1206 | 1209 |
1207 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { | 1210 if (mstype == LM_MESSAGE_SUB_TYPE_ERROR) { |
1208 x = lm_message_node_get_child(m->node, "error"); | 1211 x = lm_message_node_get_child(m->node, "error"); |
1209 display_server_error(x); | 1212 display_server_error(x); |
1210 #if defined JEP0022 || defined JEP0085 | 1213 #if defined JEP0022 || defined JEP0085 |
1211 // If the JEP85/22 support is probed, set it back to unknown so that | 1214 // If the JEP85/22 support is probed, set it back to unknown so that |
1212 // we probe it again. | 1215 // we probe it again. |
1214 #endif | 1217 #endif |
1215 } else { | 1218 } else { |
1216 handle_state_events(from, m->node); | 1219 handle_state_events(from, m->node); |
1217 } | 1220 } |
1218 if (from && (body || subject)) | 1221 if (from && (body || subject)) |
1219 gotmessage(lm_message_get_sub_type(m), from, body, enc, subject, timestamp, | 1222 gotmessage(mstype, from, body, enc, subject, timestamp, |
1220 lm_message_node_find_xmlns(m->node, NS_SIGNED)); | 1223 lm_message_node_find_xmlns(m->node, NS_SIGNED)); |
1221 //report received message if message receipt was requested | 1224 //report received message if message receipt was requested |
1222 if (lm_message_node_get_child(m->node, "request")) { | 1225 if (lm_message_node_get_child(m->node, "request")) { |
1223 LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE); | 1226 LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE); |
1224 lm_message_node_set_attribute(rcvd->node, "id", lm_message_get_id(m)); | 1227 lm_message_node_set_attribute(rcvd->node, "id", lm_message_get_id(m)); |
1241 | 1244 |
1242 static LmHandlerResult cb_caps(LmMessageHandler *h, LmConnection *c, | 1245 static LmHandlerResult cb_caps(LmMessageHandler *h, LmConnection *c, |
1243 LmMessage *m, gpointer user_data) | 1246 LmMessage *m, gpointer user_data) |
1244 { | 1247 { |
1245 char *ver = user_data; | 1248 char *ver = user_data; |
1249 LmMessageSubType mstype = lm_message_get_sub_type(m); | |
1246 | 1250 |
1247 caps_add(ver); | 1251 caps_add(ver); |
1248 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { | 1252 if (mstype == LM_MESSAGE_SUB_TYPE_ERROR) { |
1249 display_server_error(lm_message_node_get_child(m->node, "error")); | 1253 display_server_error(lm_message_node_get_child(m->node, "error")); |
1250 } else if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { | 1254 } else if (mstype == LM_MESSAGE_SUB_TYPE_RESULT) { |
1251 LmMessageNode *info; | 1255 LmMessageNode *info; |
1252 LmMessageNode *query = lm_message_node_get_child(m->node, "query"); | 1256 LmMessageNode *query = lm_message_node_get_child(m->node, "query"); |
1253 | 1257 |
1254 info = lm_message_node_get_child(query, "identity"); | 1258 info = lm_message_node_get_child(query, "identity"); |
1255 if (info) | 1259 if (info) |
1275 const char *from, *rname, *p=NULL, *ustmsg=NULL; | 1279 const char *from, *rname, *p=NULL, *ustmsg=NULL; |
1276 enum imstatus ust; | 1280 enum imstatus ust; |
1277 char bpprio; | 1281 char bpprio; |
1278 time_t timestamp = 0L; | 1282 time_t timestamp = 0L; |
1279 LmMessageNode *muc_packet, *caps; | 1283 LmMessageNode *muc_packet, *caps; |
1284 LmMessageSubType mstype; | |
1280 | 1285 |
1281 // Check for MUC presence packet | 1286 // Check for MUC presence packet |
1282 muc_packet = lm_message_node_find_xmlns | 1287 muc_packet = lm_message_node_find_xmlns |
1283 (m->node, "http://jabber.org/protocol/muc#user"); | 1288 (m->node, "http://jabber.org/protocol/muc#user"); |
1284 | 1289 |
1293 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; // Ignoring self presence | 1298 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; // Ignoring self presence |
1294 } | 1299 } |
1295 } | 1300 } |
1296 | 1301 |
1297 r = jidtodisp(from); | 1302 r = jidtodisp(from); |
1298 | 1303 mstype = lm_message_get_sub_type(m); |
1299 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { | 1304 |
1305 if (mstype == LM_MESSAGE_SUB_TYPE_ERROR) { | |
1300 LmMessageNode *x; | 1306 LmMessageNode *x; |
1301 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); | 1307 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); |
1302 x = lm_message_node_find_child(m->node, "error"); | 1308 x = lm_message_node_find_child(m->node, "error"); |
1303 display_server_error(x); | 1309 display_server_error(x); |
1304 // Let's check it isn't a nickname conflict. | 1310 // Let's check it isn't a nickname conflict. |
1329 else if (!strcmp(p, "dnd")) ust = dontdisturb; | 1335 else if (!strcmp(p, "dnd")) ust = dontdisturb; |
1330 else if (!strcmp(p, "xa")) ust = notavail; | 1336 else if (!strcmp(p, "xa")) ust = notavail; |
1331 else if (!strcmp(p, "chat")) ust = freeforchat; | 1337 else if (!strcmp(p, "chat")) ust = freeforchat; |
1332 } | 1338 } |
1333 | 1339 |
1334 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_UNAVAILABLE) | 1340 if (mstype == LM_MESSAGE_SUB_TYPE_UNAVAILABLE) |
1335 ust = offline; | 1341 ust = offline; |
1336 | 1342 |
1337 ustmsg = lm_message_node_get_child_value(m->node, "status"); | 1343 ustmsg = lm_message_node_get_child_value(m->node, "status"); |
1338 | 1344 |
1339 // Timestamp? | 1345 // Timestamp? |
1403 { | 1409 { |
1404 int i; | 1410 int i; |
1405 guint dbgflg; | 1411 guint dbgflg; |
1406 const char *xmlns = NULL; | 1412 const char *xmlns = NULL; |
1407 LmMessageNode *x; | 1413 LmMessageNode *x; |
1414 LmMessageSubType mstype = lm_message_get_sub_type(m); | |
1408 | 1415 |
1409 for (x = m->node->children; x; x=x->next) { | 1416 for (x = m->node->children; x; x=x->next) { |
1410 xmlns = lm_message_node_get_attribute(x, "xmlns"); | 1417 xmlns = lm_message_node_get_attribute(x, "xmlns"); |
1411 if (xmlns) | 1418 if (xmlns) |
1412 for (i=0; iq_handlers[i].xmlns; ++i) | 1419 for (i=0; iq_handlers[i].xmlns; ++i) |
1413 if (!strcmp(iq_handlers[i].xmlns, xmlns)) | 1420 if (!strcmp(iq_handlers[i].xmlns, xmlns)) |
1414 return iq_handlers[i].handler(NULL, connection, m, user_data); | 1421 return iq_handlers[i].handler(NULL, connection, m, user_data); |
1415 xmlns = NULL; | 1422 xmlns = NULL; |
1416 } | 1423 } |
1417 | 1424 |
1418 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_ERROR) { | 1425 if (mstype == LM_MESSAGE_SUB_TYPE_ERROR) { |
1419 display_server_error(lm_message_node_get_child(m->node, "error")); | 1426 display_server_error(lm_message_node_get_child(m->node, "error")); |
1420 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 1427 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1421 } | 1428 } |
1422 | 1429 |
1423 if ((lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_SET) || | 1430 if ((mstype == LM_MESSAGE_SUB_TYPE_SET) || |
1424 (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_GET)) | 1431 (mstype == LM_MESSAGE_SUB_TYPE_GET)) |
1425 send_iq_error(connection, m, XMPP_ERROR_NOT_IMPLEMENTED); | 1432 send_iq_error(connection, m, XMPP_ERROR_NOT_IMPLEMENTED); |
1426 | 1433 |
1427 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) | 1434 if (mstype == LM_MESSAGE_SUB_TYPE_RESULT) |
1428 dbgflg = LPRINT_DEBUG; | 1435 dbgflg = LPRINT_DEBUG; |
1429 else | 1436 else |
1430 dbgflg = LPRINT_NORMAL|LPRINT_DEBUG; | 1437 dbgflg = LPRINT_NORMAL|LPRINT_DEBUG; |
1431 | 1438 |
1432 scr_LogPrint(dbgflg, "Unhandled IQ: %s", lm_message_node_to_string(m->node)); | 1439 scr_LogPrint(dbgflg, "Unhandled IQ: %s", lm_message_node_to_string(m->node)); |
1439 { | 1446 { |
1440 char *r; | 1447 char *r; |
1441 char *buf; | 1448 char *buf; |
1442 int newbuddy; | 1449 int newbuddy; |
1443 const char *from = lm_message_get_from(m); | 1450 const char *from = lm_message_get_from(m); |
1451 LmMessageSubType mstype; | |
1444 | 1452 |
1445 r = jidtodisp(from); | 1453 r = jidtodisp(from); |
1446 | 1454 |
1447 newbuddy = !roster_find(r, jidsearch, 0); | 1455 newbuddy = !roster_find(r, jidsearch, 0); |
1448 | 1456 mstype = lm_message_get_sub_type(m); |
1449 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) { | 1457 |
1458 if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) { | |
1450 /* The sender wishes to subscribe to our presence */ | 1459 /* The sender wishes to subscribe to our presence */ |
1451 const char *msg; | 1460 const char *msg; |
1452 int isagent; | 1461 int isagent; |
1453 eviqs *evn; | 1462 eviqs *evn; |
1454 | 1463 |
1481 buf = g_strdup_printf("Unable to create a new event!"); | 1490 buf = g_strdup_printf("Unable to create a new event!"); |
1482 } | 1491 } |
1483 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); | 1492 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
1484 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 1493 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
1485 g_free(buf); | 1494 g_free(buf); |
1486 } else if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE) { | 1495 } else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE) { |
1487 /* The sender is unsubscribing from our presence */ | 1496 /* The sender is unsubscribing from our presence */ |
1488 xmpp_send_s10n(from, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED); | 1497 xmpp_send_s10n(from, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED); |
1489 buf = g_strdup_printf("<%s> is unsubscribing from your " | 1498 buf = g_strdup_printf("<%s> is unsubscribing from your " |
1490 "presence updates", from); | 1499 "presence updates", from); |
1491 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); | 1500 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
1492 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 1501 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
1493 g_free(buf); | 1502 g_free(buf); |
1494 } else if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_SUBSCRIBED) { | 1503 } else if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBED) { |
1495 /* The sender has allowed us to receive their presence */ | 1504 /* The sender has allowed us to receive their presence */ |
1496 buf = g_strdup_printf("<%s> has allowed you to receive their " | 1505 buf = g_strdup_printf("<%s> has allowed you to receive their " |
1497 "presence updates", from); | 1506 "presence updates", from); |
1498 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); | 1507 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
1499 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | 1508 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
1500 g_free(buf); | 1509 g_free(buf); |
1501 } else if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED) { | 1510 } else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED) { |
1502 /* The subscription request has been denied or a previously-granted | 1511 /* The subscription request has been denied or a previously-granted |
1503 subscription has been cancelled */ | 1512 subscription has been cancelled */ |
1504 roster_unsubscribed(from); | 1513 roster_unsubscribed(from); |
1505 update_roster = TRUE; | 1514 update_roster = TRUE; |
1506 buf = g_strdup_printf("<%s> has cancelled your subscription to " | 1515 buf = g_strdup_printf("<%s> has cancelled your subscription to " |