jabberd14  1.6.2
Functions
sessions.cc File Reference

handle messages to and from user sessions More...

#include "jsm.h"

Functions

void _js_session_start (void *arg)
void _js_session_to (void *arg)
void _js_session_from (void *arg)
void _js_session_end (void *arg)
void js_session_route (session s, xmlnode in)
void js_session_free_aux_data (void *arg)
session js_session_new (jsmi si, dpacket dp)
session js_sc_session_new (jsmi si, dpacket dp, xmlnode sc_session)
void js_session_end (session s, char *reason)
session js_session_get (udata user, char const *res)
session js_session_primary (udata user)
void js_session_to (session s, jpacket p)
void js_session_from (session s, jpacket p)

Detailed Description

handle messages to and from user sessions


Function Documentation

void _js_session_end ( void *  arg)

child that cleans up a session

Notify the responsible c2s instance about the closed session. Call the modules that registered for the es_END event, to notify them about the closed session

Parameters:
argthe session, that is closing

References es_END, js_mapi_call(), js_session_route(), log_debug2, LOGT_SESSION, session_struct::p, pool_free(), session_struct::presence, udata_struct::ref, session_struct::sid, session_struct::u, and xmlnode_free().

Referenced by js_session_end().

void _js_session_from ( void *  arg)

Child that handles packets we just received from the client connection manager from one of our users

It is checked first if the packet is of a known type, if not it gets rejected. For known packets it is first tried if one of the registered modules for es_OUT handles the packet, iff none of the modules handles the packet, it is further passed to js_deliver().

Parameters:
argthe packet we just received

References session_struct::c_out, es_OUT, session_struct::exit_flag, history_storage_conf::general, jsmi_struct::history_sent, udata_struct::id, session_struct::id, jid_cmp(), jid_cmpx(), jid_full(), jid_new(), jid_user_pool(), jpacket_reset(), jpacket_subtype(), js_deliver(), js_mapi_call(), js_session_to(), jutil_error_xmpp(), log_debug2, LOGT_DELIVER, session_struct::si, history_storage_conf::special, jsmi_struct::std_namespace_prefixes, session_struct::u, jsmi_struct::xc, xdb_act_path(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_list_item(), xmlnode_get_tags(), xmlnode_hide_attrib_ns(), and xmlnode_put_attrib_ns().

Referenced by js_session_from().

void _js_session_start ( void *  arg)

child that starts a session

Calles all registered modules for the event e_SESSION and notifies them about the newly created session

Parameters:
argthe newly created session

References e_SESSION, js_mapi_call(), session_struct::si, session_struct::started, and session_struct::u.

Referenced by js_sc_session_new(), and js_session_new().

void _js_session_to ( void *  arg)

child that handles packets to a specified resource (session) of a user

It is checked if the session the packet is addressed to has the exit_flag set, if so it is sent back (?) to js_deliver(). If the exit_flag is not set it is first tried if one of the registered callbacks for es_IN handles the packet. Iff not the exit_flag is checked again (and probably the packet sent back to js_deliver()) and if it is still not set, the packet is passed to js_session_route() which delivers it to the c2s for sending it to the connection related to the session.

Parameters:
argthe packet

References session_struct::c_in, es_FILTER_IN, es_IN, session_struct::exit_flag, history_storage_conf::general, jsmi_struct::history_recv, udata_struct::id, jid_full(), jpacket_subtype(), js_deliver(), js_mapi_call(), js_session_route(), log_debug2, LOGT_DELIVER, history_storage_conf::offline, PACKET_FROM_OFFLINE_MAGIC, PACKET_PASS_FILTERS_MAGIC, session_struct::si, history_storage_conf::special, jsmi_struct::std_namespace_prefixes, session_struct::u, jsmi_struct::xc, xdb_act(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_list_item(), xmlnode_get_tags(), xmlnode_hide_attrib_ns(), and xmlnode_put_attrib_ns().

Referenced by js_session_to().

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:
sithe session manager instance data
dpthe packet we received from the c2s instance, that requested the new session
sc_sessionthe xmlnode containing the sc:session element
Returns:
a pointer to the new session (NULL if input data is invalid)

References _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(), jid_full(), jid_new(), js_session_end(), js_session_free_aux_data(), js_user(), jutil_presnew(), log_debug2, LOGT_SESSION, 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().

void js_session_end ( session  s,
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:
sthe session, that is closing
reasontextual reason for the shutdown

References _js_session_end(), session_struct::exit_flag, session_struct::id, j_strcmp(), jid_full(), jutil_presnew(), log_debug2, LOGT_SESSION, 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(), js_sc_session_new(), and js_session_new().

void js_session_free_aux_data ( void *  arg)

delete the aux hash if a session structure is freed

References session_struct::aux_data, and xhash_free().

Referenced by js_sc_session_new(), and js_session_new().

void js_session_from ( session  s,
jpacket  p 
)

handle normal stanzas received inside a <route/> stanza from jabberd. These are packets we get from the client connection manager, that are from one of our users.

Pass them to _js_session_from() to get executed by an own execution thread.

Parameters:
sthe session of the user
pthe received packet

References _js_session_from(), log_debug, mtq_send(), and session_struct::q.

Referenced by _js_routed_packet().

session js_session_get ( udata  user,
char const *  res 
)

find the session for a given resource

Given a user and a resource, find the corresponding session if the user is logged in. Otherweise return NULL.

Parameters:
userthe user's udata record
resthe resource to search for
Returns:
a pointer to the session if the user is logged in, NULL if the user isn't logged in on this resource

References j_strcmp(), j_strlen(), j_strncmp(), session_struct::next, session_struct::res, and udata_struct::sessions.

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:
sithe session manager instance data
dpthe 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)

References _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(), jid_full(), jid_new(), jid_set(), js_session_end(), js_session_free_aux_data(), js_user(), jutil_presnew(), log_debug2, LOGT_SESSION, 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().

find the primary session for the user

Scan through the user's sessions to find the session with the highest priority and return a pointer to it.

Parameters:
userthe user to find the highest session for
Returns:
pointer to the primary session if the user is logged in with at least priority 0, NULL if there is no active session with a priority of at least 0

References session_struct::next, session_struct::priority, and udata_struct::sessions.

void js_session_route ( session  s,
xmlnode  in 
)

deliver a packet to the client connection manager responsible for the session

The packet is wrapped inside a <route/> element and routed to the client connection manager, that handles the connection for the sepcified session. If the xmlnode in is NULL, a <route type='error'/> stanza is sent to the client connection manager, signalling that the session is not valid anymore.

Parameters:
sthe session to which the packet should be routed to
inthe stanza that should be routed to the c2s for the session

References deliver(), dpacket_new(), jsmi_struct::i, jid_full(), messages_get(), session_struct::presence, session_struct::route, session_struct::sc_c2s, session_struct::sc_sm, session_struct::si, session_struct::sid, xmlnode_get_lang(), xmlnode_insert_tag_ns(), xmlnode_new_tag_ns(), xmlnode_put_attrib_ns(), and xmlnode_wrap_ns().

Referenced by _js_session_end(), and _js_session_to().

void js_session_to ( session  s,
jpacket  p 
)

handle packets addresses to a specific resource (session) of a user

pass them to _js_session_to() ...

Parameters:
sthe session the packet is addressed to
pthe packet

References _js_session_to(), log_debug, mtq_send(), and session_struct::q.

Referenced by _js_session_from().