Logo Search packages:      
Sourcecode: jabberd14 version File versions  Download package

void js_session_end ( session  s,
const char *  reason 
)

shut down the session

This function gets called when the user disconnects or when the server shuts down. It changes the user's presence to offline, cleans up the session data and notifies all registered modules for the es_END event about the closed session

Parameters:
s the session, that is closing
reason textual reason for the shutdown

Definition at line 335 of file sessions.cc.

References _js_session_end(), session_struct::exit_flag, session_struct::id, j_strcmp(), jutil_presnew(), messages_get(), mtq_send(), session_struct::next, session_struct::p, session_struct::presence, session_struct::priority, session_struct::q, udata_struct::ref, jsmi_struct::sc_sessions, session_struct::sc_sm, udata_struct::sessions, session_struct::si, session_struct::u, xhash_zap(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_lang(), and xmlnode_put_attrib_ns().

Referenced by __jsm_shutdown(), _js_routed_error_packet(), _js_routed_session_control_packet(), _jsm_deserialize_session(), js_sc_session_new(), and js_session_new().

                                                   {
    xmlnode x;      /* new presence data */
    session cur;    /* used to iterate over the user's session list
                       when removing the session from the list */

    /* ignore illegal calls */
    if (s == NULL || s->exit_flag == 1 || reason == NULL)
        return;

    /* log the reason the session ended */
    log_debug2(ZONE, LOGT_SESSION, "end %d '%s'", s, reason);

    /* flag the session to exit ASAP */
    s->exit_flag = 1;

    /* make sure we're not the primary session */
    s->priority = -129;

    /* if the last known presence was available, update it */
    if (s->presence != NULL && j_strcmp(xmlnode_get_attrib_ns(s->presence, "type", NULL), "unavailable") != 0) {

        /* create a new presence packet with the reason the user is unavailable */
        x = jutil_presnew(JPACKET__UNAVAILABLE, NULL, messages_get(xmlnode_get_lang(s->presence), reason));
        xmlnode_put_attrib_ns(x, "from", NULL, NULL, jid_full(s->id));

        /* free the old presence packet */
        xmlnode_free(s->presence);

        /* install the presence */
        s->presence = x;

    }

    /*
     * remove this session from the user's session list --
     * first check if this session is at the head of the list
     */
    if (s == s->u->sessions) {
        /* yup, just bump up the next session */
        s->u->sessions = s->next;
    } else {
        /* no, we have to traverse the list to find it */
        for (cur = s->u->sessions; cur->next != s; cur = cur->next)
          /* do nothing in iteration */;
        cur->next = s->next;
    }

    /* we don't have to find this session for session end requests anymore */
    if (s->sc_sm != NULL) {
      xhash_zap(s->si->sc_sessions, s->sc_sm);
    }

    /* so it doesn't get freed */
    s->u->ref++;

    /* tell it to exit */
    mtq_send(s->q, s->p, _js_session_end, (void *)s);
}


Generated by  Doxygen 1.6.0   Back to index