comparison mcabber/src/jabglue.c @ 986:ed697234bd39

Chat states receival (Alexis Hildebrandt) Patch from Alexis Hildebrandt, slightly modified (mostly coding style updates).
author Mikael Berthe <mikael@lilotux.net>
date Sun, 29 Oct 2006 11:43:00 +0100
parents 5b01de4ac5e1
children f47e312560af
comparison
equal deleted inserted replaced
985:b33ca4e1c37d 986:ed697234bd39
49 static gchar *mystatusmsg; 49 static gchar *mystatusmsg;
50 static unsigned char online; 50 static unsigned char online;
51 51
52 static void statehandler(jconn, int); 52 static void statehandler(jconn, int);
53 static void packethandler(jconn, jpacket); 53 static void packethandler(jconn, jpacket);
54 void handle_state_events(char* from, xmlnode xmldata);
54 55
55 static void logger(jconn j, int io, const char *buf) 56 static void logger(jconn j, int io, const char *buf)
56 { 57 {
57 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); 58 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
58 } 59 }
427 if (subject) { 428 if (subject) {
428 xmlnode y; 429 xmlnode y;
429 y = xmlnode_insert_tag(x, "subject"); 430 y = xmlnode_insert_tag(x, "subject");
430 xmlnode_insert_cdata(y, subject, (unsigned) -1); 431 xmlnode_insert_cdata(y, subject, (unsigned) -1);
431 } 432 }
433
434 // TODO: insert event notifications request
435 #undef USE_JEP_85
436 #ifdef USE_JEP_85
437 #define NS_CHAT_STATES "http://jabber.org/features/chatstates"
438 // JEP-85
439 xmlnode event = xmlnode_insert_tag(x, "composing");
440 xmlnode_put_attrib(event, "xmlns", NS_CHAT_STATES);
441 #else
442 // JEP-22
443 xmlnode event = xmlnode_insert_tag(x, "x");
444 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
445 xmlnode_insert_tag(event, "composing");
446 #endif
447
448
432 jab_send(jc, x); 449 jab_send(jc, x);
433 xmlnode_free(x); 450 xmlnode_free(x);
434 451
435 jb_reset_keepalive(); 452 jb_reset_keepalive();
436 } 453 }
1420 if (body) strcat(tmp, body); 1437 if (body) strcat(tmp, body);
1421 body = tmp; 1438 body = tmp;
1422 } 1439 }
1423 } 1440 }
1424 1441
1442 handle_state_events(from, xmldata);
1443
1425 // Not used yet... 1444 // Not used yet...
1426 x = xml_get_xmlns(xmldata, NS_ENCRYPTED); 1445 x = xml_get_xmlns(xmldata, NS_ENCRYPTED);
1427 if (x && (p = xmlnode_get_data(x)) != NULL) { 1446 if (x && (p = xmlnode_get_data(x)) != NULL) {
1428 enc = p; 1447 enc = p;
1429 } 1448 }
1436 display_server_error(x); 1455 display_server_error(x);
1437 } 1456 }
1438 if (from && body) 1457 if (from && body)
1439 gotmessage(type, from, body, enc, timestamp); 1458 gotmessage(type, from, body, enc, timestamp);
1440 g_free(tmp); 1459 g_free(tmp);
1460 }
1461
1462 void handle_state_events(char* from, xmlnode xmldata)
1463 {
1464 xmlnode x = NULL;
1465 char *rname = strchr(from, JID_RESOURCE_SEPARATOR) + 1;
1466 char *jid = jidtodisp(from);
1467 GSList *slist = roster_find(jid, jidsearch, ROSTER_TYPE_USER);
1468 if (slist == NULL) return;
1469 int jep85 = 0;
1470
1471 guint events = buddy_resource_getevents(slist->data, rname);
1472
1473 x = xml_get_xmlns(xmldata, NS_EVENT);
1474 if (x == NULL) {
1475 x = xmldata;
1476 jep85 = 1;
1477 }
1478
1479 xmlnode tag = xmlnode_get_tag(x, "composing");
1480 if (tag != NULL) {
1481 events |= ROSTER_EVENT_COMPOSING;
1482 } else if (!jep85) {
1483 events &= ~ROSTER_EVENT_COMPOSING;
1484 }
1485
1486 if (jep85) {
1487 tag = xmlnode_get_tag(x, "paused");
1488 if (tag != NULL) {
1489 events &= ~ROSTER_EVENT_COMPOSING;
1490 }
1491 }
1492
1493 // clear composing and set new message event
1494 // if message contains message body
1495 if (xmlnode_get_tag_data(xmldata, "body") != NULL) {
1496 events |= ROSTER_EVENT_MSG;
1497 events &= ~ROSTER_EVENT_COMPOSING;
1498 }
1499
1500 buddy_resource_setevents(slist->data, rname, events);
1501
1502 scr_UpdateBuddyWindow();
1503 scr_DrawRoster();
1504
1505 g_free(jid);
1441 } 1506 }
1442 1507
1443 static void evscallback_subscription(eviqs *evp, guint evcontext) 1508 static void evscallback_subscription(eviqs *evp, guint evcontext)
1444 { 1509 {
1445 char *barejid; 1510 char *barejid;