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

session js_sc_session_new ( jsmi  si,
dpacket  dp,
xmlnode  sc_session 
)

create a new session, that was signaled by the c2s with the session control 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
sc_session the xmlnode containing the sc:session element
Returns:
a pointer to the new session (NULL if input data is invalid)

Definition at line 234 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, dpacket_struct::id, session_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(), pool_free(), session_struct::presence, session_struct::priority, pstrdup(), session_struct::q, session_struct::res, session_struct::roster, session_struct::route, session_struct::sc_c2s, jsmi_struct::sc_sessions, session_struct::sc_sm, udata_struct::sessions, session_struct::si, session_struct::sid, session_struct::u, dpacket_struct::x, xhash_new(), xhash_put(), xmlnode_get_attrib_ns(), and xmlnode_put_attrib_ns().

Referenced by _js_routed_session_control_packet().

                                                                   {
    const char *c2s_id = NULL;
    udata u = NULL;
    jid user_id = NULL;
    pool p = NULL;
    char sm_id[9];
    session s = NULL;      /* the session being created */
    session cur = NULL;    /* for iteration */
    int i = 0;

    /* sanity checks */
    if (si == NULL || dp == NULL || sc_session == NULL)
      return NULL;

    /* we need to know where to send session packets to */
    if (xmlnode_get_attrib_ns(dp->x, "from", NULL) == NULL)
      return NULL;

    /* get the reference on the c2s */
    c2s_id = xmlnode_get_attrib_ns(sc_session, "c2s", NS_SESSION);
    if (c2s_id == NULL)
      return NULL;

    /* create memory pool for this session */
    p = pool_heap(2*1024);

    /* get the user id of the owner of new session */
    user_id = jid_new(p, xmlnode_get_attrib_ns(sc_session, "target", NULL));
    if (user_id == NULL) {
      pool_free(p);
      return NULL;
    }
    log_debug2(ZONE, LOGT_SESSION, "js_sc_session_new for %s", jid_full(user_id));

    /* get the user */
    u = js_user(si, user_id, NULL);
    if (u == NULL) {
      pool_free(p);
      return NULL;
    }

    /* create session */
    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);

    s->id = user_id;
    s->res = user_id->resource;
    s->u = u;
    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);
    s->sc_c2s = pstrdup(p, c2s_id);
    _js_create_session_id(sm_id, s->si->sc_sessions);
    s->sc_sm = pstrdup(p, sm_id);
    for(i = 0; i < es_LAST; i++)
        s->events[i] = NULL;

    /* store routing information */
    s->sid = jid_new(p, xmlnode_get_attrib_ns(dp->x, "from", NULL));
    s->route = jid_new(p, jid_full(dp->id));

    /* 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++;
    */

    /* insert in the hash of sc session to find the right session in an action='end' request */
    xhash_put(s->si->sc_sessions, s->sc_sm, u);

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

    return s;
}


Generated by  Doxygen 1.6.0   Back to index