mcabber/src/jab_iq.c
changeset 1254 401639413340
parent 1224 fb0460a3cf4b
child 1255 ceada40bbe20
equal deleted inserted replaced
1253:eb38963e082f 1254:401639413340
    43 xmlnode bookmarks;
    43 xmlnode bookmarks;
    44 // Roster notes for IQ:private storage
    44 // Roster notes for IQ:private storage
    45 xmlnode rosternotes;
    45 xmlnode rosternotes;
    46 
    46 
    47 static GSList *iqs_list;
    47 static GSList *iqs_list;
       
    48 
       
    49 time_t iqlast; // last message/status change time
    48 
    50 
    49 // Enum for vCard attributes
    51 // Enum for vCard attributes
    50 enum vcard_attr {
    52 enum vcard_attr {
    51   vcard_home    = 1<<0,
    53   vcard_home    = 1<<0,
    52   vcard_work    = 1<<1,
    54   vcard_work    = 1<<1,
  1367 
  1369 
  1368   jab_send(jc, x);
  1370   jab_send(jc, x);
  1369   xmlnode_free(x);
  1371   xmlnode_free(x);
  1370 }
  1372 }
  1371 
  1373 
       
  1374 inline double seconds_since_last_use(void)
       
  1375 {
       
  1376   return difftime(time(NULL), iqlast);
       
  1377 }
       
  1378 
       
  1379 static void handle_iq_last(jconn conn, char *from, const char *id,
       
  1380                            xmlnode xmldata)
       
  1381 {
       
  1382   xmlnode x;
       
  1383   xmlnode myquery;
       
  1384   char *seconds;
       
  1385 
       
  1386   scr_LogPrint(LPRINT_LOGNORM, "Received an IQ last time request from <%s>",
       
  1387                from);
       
  1388 
       
  1389   x = jutil_iqnew(JPACKET__RESULT, NS_LAST);
       
  1390   xmlnode_put_attrib(x, "id", id);
       
  1391   xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
       
  1392   myquery = xmlnode_get_tag(x, "query");
       
  1393   seconds = g_strdup_printf("%.0f", seconds_since_last_use());
       
  1394   xmlnode_put_attrib(myquery, "seconds", seconds);
       
  1395   g_free(seconds);
       
  1396 
       
  1397   jab_send(jc, x);
       
  1398   xmlnode_free(x);
       
  1399 }
       
  1400 
  1372 static void handle_iq_ping(jconn conn, char *from, const char *id,
  1401 static void handle_iq_ping(jconn conn, char *from, const char *id,
  1373                            xmlnode xmldata)
  1402                            xmlnode xmldata)
  1374 {
  1403 {
  1375   xmlnode x;
  1404   xmlnode x;
  1376   x = jutil_iqresult(xmldata);
  1405   x = jutil_iqresult(xmldata);
  1483     handle_iq_disco_info(conn, from, id, xmldata);
  1512     handle_iq_disco_info(conn, from, id, xmldata);
  1484   } else if (ns && !strcmp(ns, NS_DISCO_ITEMS)) {
  1513   } else if (ns && !strcmp(ns, NS_DISCO_ITEMS)) {
  1485     handle_iq_disco_items(conn, from, id, xmldata);
  1514     handle_iq_disco_items(conn, from, id, xmldata);
  1486   } else if (ns && !strcmp(ns, NS_VERSION)) {
  1515   } else if (ns && !strcmp(ns, NS_VERSION)) {
  1487     handle_iq_version(conn, from, id, xmldata);
  1516     handle_iq_version(conn, from, id, xmldata);
       
  1517   } else if (ns && !strcmp(ns, NS_LAST) &&
       
  1518              !settings_opt_get_int("iq_last_disable")) {
       
  1519     handle_iq_last(conn, from, id, xmldata);
  1488   } else if (ns && !strcmp(ns, NS_TIME)) {
  1520   } else if (ns && !strcmp(ns, NS_TIME)) {
  1489     handle_iq_time(conn, from, id, xmldata);
  1521     handle_iq_time(conn, from, id, xmldata);
  1490   } else {
  1522   } else {
  1491     iq_not_implemented = TRUE;
  1523     iq_not_implemented = TRUE;
  1492   }
  1524   }