Mercurial > hg
changeset 1254:401639413340
More jabber:iq:last support... (misc)
This is a patch from Michael Scherer to answer iq:last requests,
slightly modified.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 22 Jun 2007 19:21:23 +0200 |
parents | eb38963e082f |
children | ceada40bbe20 |
files | mcabber/mcabberrc.example mcabber/src/jab_iq.c mcabber/src/jab_priv.h mcabber/src/jabglue.c mcabber/src/screen.c mcabber/src/screen.h |
diffstat | 6 files changed, 51 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/mcabberrc.example Fri Jun 22 19:18:44 2007 +0200 +++ b/mcabber/mcabberrc.example Fri Jun 22 19:21:23 2007 +0200 @@ -137,6 +137,10 @@ # Set iq_version_hide_os to 1 if you do not want to allow people to retrieve # your OS version. #set iq_version_hide_os = 0 +# +# Set iq_last_disable to 1 if you want to disable response to jabber:iq:last +# queries (XEP-0012). +#set iq_last_disable = 0 # Beep # Set beep_on_message to 1 if you want mcabber to beep when receiving
--- a/mcabber/src/jab_iq.c Fri Jun 22 19:18:44 2007 +0200 +++ b/mcabber/src/jab_iq.c Fri Jun 22 19:21:23 2007 +0200 @@ -46,6 +46,8 @@ static GSList *iqs_list; +time_t iqlast; // last message/status change time + // Enum for vCard attributes enum vcard_attr { vcard_home = 1<<0, @@ -1369,6 +1371,33 @@ xmlnode_free(x); } +inline double seconds_since_last_use(void) +{ + return difftime(time(NULL), iqlast); +} + +static void handle_iq_last(jconn conn, char *from, const char *id, + xmlnode xmldata) +{ + xmlnode x; + xmlnode myquery; + char *seconds; + + scr_LogPrint(LPRINT_LOGNORM, "Received an IQ last time request from <%s>", + from); + + x = jutil_iqnew(JPACKET__RESULT, NS_LAST); + xmlnode_put_attrib(x, "id", id); + xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); + myquery = xmlnode_get_tag(x, "query"); + seconds = g_strdup_printf("%.0f", seconds_since_last_use()); + xmlnode_put_attrib(myquery, "seconds", seconds); + g_free(seconds); + + jab_send(jc, x); + xmlnode_free(x); +} + static void handle_iq_ping(jconn conn, char *from, const char *id, xmlnode xmldata) { @@ -1485,6 +1514,9 @@ handle_iq_disco_items(conn, from, id, xmldata); } else if (ns && !strcmp(ns, NS_VERSION)) { handle_iq_version(conn, from, id, xmldata); + } else if (ns && !strcmp(ns, NS_LAST) && + !settings_opt_get_int("iq_last_disable")) { + handle_iq_last(conn, from, id, xmldata); } else if (ns && !strcmp(ns, NS_TIME)) { handle_iq_time(conn, from, id, xmldata); } else {
--- a/mcabber/src/jab_priv.h Fri Jun 22 19:18:44 2007 +0200 +++ b/mcabber/src/jab_priv.h Fri Jun 22 19:21:23 2007 +0200 @@ -37,6 +37,7 @@ extern char *mcabber_version(void); const char *entity_version(void); +extern time_t iqlast; /* last message/status change time */ char *jidtodisp(const char *fjid); void handle_packet_iq(jconn conn, char *type, char *from, xmlnode xmldata);
--- a/mcabber/src/jabglue.c Fri Jun 22 19:18:44 2007 +0200 +++ b/mcabber/src/jabglue.c Fri Jun 22 19:21:23 2007 +0200 @@ -60,6 +60,7 @@ static int evscallback_invitation(eviqs *evp, guint evcontext); + static void logger(jconn j, int io, const char *buf) { scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); @@ -323,6 +324,11 @@ return mystatusmsg; } +inline void update_last_use(void) +{ + iqlast = time(NULL); +} + // insert_entity_capabilities(presence_stanza) // Entity Capabilities (XEP-0115) static void insert_entity_capabilities(xmlnode x) @@ -502,6 +508,9 @@ mystatusmsg = NULL; } + if (!Autoaway) + update_last_use(); + // Update status line scr_UpdateMainStatus(TRUE); } @@ -681,6 +690,8 @@ jb_send_msg_no_chatstates: xmlnode_put_attrib(x, "id", msgid); + if (mystatus != invisible) + update_last_use(); jab_send(jc, x); xmlnode_free(x); #if defined JEP0022 @@ -1845,6 +1856,7 @@ scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " "established"); online = TRUE; + update_last_use(); // We set AutoConnection to true after the 1st successful connection AutoConnection = true; break;
--- a/mcabber/src/screen.c Fri Jun 22 19:18:44 2007 +0200 +++ b/mcabber/src/screen.c Fri Jun 22 19:21:23 2007 +0200 @@ -101,7 +101,6 @@ static char *multiline, *multimode_subj; int update_roster; int utf8_mode = 0; -static bool Autoaway; static bool Curses; static bool log_win_on_top; static bool roster_win_on_right;