concurrent session for a user logs in, or when the last
session logs out. Also handle stealth mode semantics.
CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP);
CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN);
CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT);
CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP);
CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN);
CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT);
+ CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH);
+ CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH);
#else
lprintf(CTDL_INFO, "This server is missing the Expat XML parser. Jabber service will be disabled.\n");
#endif
#else
lprintf(CTDL_INFO, "This server is missing the Expat XML parser. Jabber service will be disabled.\n");
#endif
void xmpp_presence_notify(char *presence_jid, char *presence_type) {
struct CitContext *cptr;
static int unsolicited_id;
void xmpp_presence_notify(char *presence_jid, char *presence_type) {
struct CitContext *cptr;
static int unsolicited_id;
+ int visible_sessions = 0;
+ int aide = (CC->user.axlevel >= 6);
+
+ if (IsEmptyStr(presence_jid)) return;
- /* FIXME subject this to the same conditions as above */
+ /* Count the visible sessions for this user */
+ for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
+ if ( (!strcasecmp(cptr->cs_inet_email, presence_jid))
+ && (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
+ ) {
+ ++visible_sessions;
+ }
+ }
- /* FIXME make sure don't do this for multiple logins of the same user (login)
- * or until the last concurrent login is logged out (logout)
- */
+ lprintf(CTDL_DEBUG, "%d sessions for <%s> are now visible to session %d\n",
+ visible_sessions, presence_jid, CC->cs_pid);
- if (IsEmptyStr(presence_jid)) return;
- lprintf(CTDL_DEBUG, "Sending presence info about <%s> to session %d\n", presence_jid, CC->cs_pid);
+ if ( (strcasecmp(presence_type, "unavailable")) && (visible_sessions == 1) ) {
+ lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged in\n", CC->cs_pid, presence_jid);
- /* Transmit an unsolicited roster update if the presence is anything other than "unavailable" */
- if (strcasecmp(presence_type, "unavailable")) {
+ /* Do an unsolicited roster update that adds a new contact. */
for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
if (!strcasecmp(cptr->cs_inet_email, presence_jid)) {
cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
if (!strcasecmp(cptr->cs_inet_email, presence_jid)) {
cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
+
+ /* Transmit presence information */
+ cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
- /* Now transmit unsolicited presence information */
- cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
+ if ( (!strcasecmp(presence_type, "unavailable")) && (visible_sessions == 0) ) {
+ lprintf(CTDL_DEBUG, "Telling session %d that <%s> logged out\n", CC->cs_pid, presence_jid);
+
+ /* Transmit non-presence information */
+ cprintf("<presence type=\"%s\" from=\"%s\"></presence>", presence_type, presence_jid);
- /* For "unavailable" we do an unsolicited roster update that deletes the contact. */
- if (!strcasecmp(presence_type, "unavailable")) {
+ /* Do an unsolicited roster update that deletes the contact. */
cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
cprintf("<query xmlns=\"jabber:iq:roster\">");
cprintf("<item jid=\"%s\" subscription=\"remove\">", presence_jid);
cprintf("<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
cprintf("<query xmlns=\"jabber:iq:roster\">");
cprintf("<item jid=\"%s\" subscription=\"remove\">", presence_jid);
if (requested_mode == 1) {
CC->cs_flags = CC->cs_flags | CS_STEALTH;
if (requested_mode == 1) {
CC->cs_flags = CC->cs_flags | CS_STEALTH;
+ PerformSessionHooks(EVT_STEALTH);
}
if (requested_mode == 0) {
CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
}
if (requested_mode == 0) {
CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
+ PerformSessionHooks(EVT_UNSTEALTH);
}
cprintf("%d %d\n", CIT_OK,
}
cprintf("%d %d\n", CIT_OK,
#define EVT_CMD 6 /* Called after each server command */
#define EVT_RWHO 7 /* An RWHO command is being executed */
#define EVT_ASYNC 8 /* Doing asynchronous messages */
#define EVT_CMD 6 /* Called after each server command */
#define EVT_RWHO 7 /* An RWHO command is being executed */
#define EVT_ASYNC 8 /* Doing asynchronous messages */
+#define EVT_STEALTH 9 /* Entering stealth mode */
+#define EVT_UNSTEALTH 10 /* Exiting stealth mode */
#define EVT_TIMER 50 /* Timer events are called once per minute
and are not tied to any session */
#define EVT_TIMER 50 /* Timer events are called once per minute
and are not tied to any session */