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

session js_session_new ( jsmi  si,
dpacket  dp 
)

create a new session, register the resource for it (initiated by the old c2s-sm-protocol)

Sets up all the data associated with a new session, then notify all modules that registered for e_SESSION about the newly created session

Parameters:
si the session manager instance data
dp the packet we received from the c2s instance, that requested the new session
Returns:
a pointer to the new session (NULL if input data is invalid)

Definition at line 160 of file sessions.cc.

References _js_create_session_id(), _js_session_start(), session_struct::aux_data, session_struct::c_in, session_struct::c_out, es_LAST, session_struct::events, session_struct::exit_flag, session_struct::id, dpacket_struct::id, j_strcmp(), js_session_end(), js_session_free_aux_data(), js_user(), jutil_presnew(), mtq_new(), mtq_send(), session_struct::next, session_struct::p, pmalloco(), pool_cleanup(), session_struct::presence, session_struct::priority, pstrdup(), session_struct::q, session_struct::res, session_struct::roster, session_struct::route, udata_struct::sessions, session_struct::si, session_struct::sid, session_struct::u, dpacket_struct::x, xhash_new(), xmlnode_get_attrib_ns(), and xmlnode_put_attrib_ns().

Referenced by _js_routed_session_packet().

                                            {
    pool p;         /* a memory pool for the session */
    session s, cur;      /* the session being created */
    int i;
    udata u;
    char session_id[9];

    /* screen out illegal calls */
    if(dp == NULL || dp->id->user == NULL || dp->id->resource == NULL || xmlnode_get_attrib_ns(dp->x, "from", NULL) == NULL || (u = js_user(si, dp->id, NULL)) == NULL)
        return NULL;

    log_debug2(ZONE, LOGT_SESSION, "session_create %s", jid_full(dp->id));

    /* create session */
    p = pool_heap(2*1024);
    s = static_cast<session>(pmalloco(p, sizeof(struct session_struct)));
    s->p = p;
    s->si = si;

    /* create aux_data hash */
    s->aux_data = xhash_new(17);
    pool_cleanup(s->p, js_session_free_aux_data, s);

    /* save authorative remote session id */
    s->sid = jid_new(p, xmlnode_get_attrib_ns(dp->x, "from", NULL));

    /* session identity */
    s->id = jid_new(p, jid_full(dp->id));
    s->route = jid_new(p, jid_full(dp->id));
    _js_create_session_id(session_id, NULL);
    jid_set(s->route, session_id, JID_RESOURCE);
    s->res = pstrdup(p, dp->id->resource);
    s->u = u;

    /* default settings */
    s->exit_flag = 0;
    s->roster = 0;
    s->priority = -129;
    s->presence = jutil_presnew(JPACKET__UNAVAILABLE,NULL,NULL);
    xmlnode_put_attrib_ns(s->presence, "from", NULL, NULL, jid_full(s->id));
    s->c_in = s->c_out = 0;
    s->q = mtq_new(s->p);
    for (i = 0; i < es_LAST; i++)
        s->events[i] = NULL;

    /* remove any other session w/ this resource */
    for (cur = u->sessions; cur != NULL; cur = cur->next)
        if (j_strcmp(dp->id->resource, cur->res) == 0)
            js_session_end(cur, N_("Replaced by new connection"));

    /* make sure we're linked with the user */
    s->next = s->u->sessions;
    s->u->sessions = s;
    /*
    s->u->scount++;
    */

    /* start it */
    mtq_send(s->q, s->p, _js_session_start, (void *)s);

    return s;
}


Generated by  Doxygen 1.6.0   Back to index