52 char timestamp[18], telem[5];
56 memset(&tm, 0,
sizeof(
struct tm));
61 if((ret = storage_get(mod->
mm->
sm->
st,
"motd-message", domain, NULL, &os)) == st_SUCCESS) {
63 o = os_iter_object(os);
64 if(os_object_get_nad(os, o,
"xml", &nad)) {
73 telem[0] = timestamp[0];
74 telem[1] = timestamp[1];
75 telem[2] = timestamp[2];
76 telem[3] = timestamp[3];
78 tm.tm_year = atoi(telem) - 1900;
81 telem[0] = timestamp[4];
82 telem[1] = timestamp[5];
84 tm.tm_mon = atoi(telem) - 1;
87 telem[0] = timestamp[6];
88 telem[1] = timestamp[7];
89 tm.tm_mday = atoi(telem);
92 telem[0] = timestamp[9];
93 telem[1] = timestamp[10];
94 tm.tm_hour = atoi(telem);
97 telem[0] = timestamp[12];
98 telem[1] = timestamp[13];
99 tm.tm_min = atoi(telem);
102 telem[0] = timestamp[15];
103 telem[1] = timestamp[16];
104 tm.tm_sec = atoi(telem);
106 data->
t = timegm(&tm);
113 if(data->
tos != NULL)
115 data->
tos = os_new();
116 os_object_put(os_object_new(data->
tos),
"time", &data->
t, os_type_INTEGER);
129 if(data->
nad == NULL) {
133 if(data->
nad == NULL)
141 storage_get(sess->
user->
sm->
st,
"motd-times",
jid_user(sess->
jid), NULL, &os) == st_SUCCESS) {
143 o = os_iter_object(os);
144 os_object_get_time(os, o,
"time", &t);
180 for(sess = user->
sessions; sess != NULL; sess = sess->
next) {
248 store =
pkt_dup(pkt, NULL, NULL);
254 o = os_object_new(os);
256 os_object_put(o,
"xml", store->nad, os_type_NAD);
259 ret = storage_replace(mod->
mm->
sm->
st,
"motd-message", pkt->
to->
domain, NULL, os);
276 if(data->
nad != NULL)
278 data->
nad = store->nad;
285 if(data->
tos != NULL)
287 data->
tos = os_new();
288 os_object_put(os_object_new(data->
tos),
"time", &t, os_type_INTEGER);
291 else if(strcmp(&(pkt->
to->
resource[8]),
"/online") != 0) {
314 storage_delete(mi->
sm->
st,
"motd-times",
jid_user(jid), NULL);
321 if(data->
tos != NULL) os_free(data->
tos);
329 if(mod->
init)
return 0;
mod_ret_t(* pkt_sm)(mod_instance_t mi, pkt_t pkt)
pkt-sm handler
user_t user
user this session belongs to
pkt_type_t type
packet type
jid_t jid
session jid (user@host/res)
data structures and prototypes for the session manager
static mod_ret_t _announce_pkt_sm(mod_instance_t mi, pkt_t pkt)
int pri
current priority of this session
const char * jid_user(jid_t jid)
expand and return the user
const char * jid_full(jid_t jid)
expand and return the full
jid_t jid_new(const char *id, int len)
make a new jid
single instance of a module in a chain
int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth)
locate the next elem at a given depth with an optional matching name
int init
number of times the module intialiser has been called
#define stanza_err_FEATURE_NOT_IMPLEMENTED
pkt_t pkt_dup(pkt_t pkt, const char *to, const char *from)
duplicate pkt, replacing addresses
#define stanza_err_FORBIDDEN
void nad_free(nad_t nad)
free that nad
nad_t nad_copy(nad_t nad)
copy a nad
xht users
pointers to currently loaded users (key is user@domain)
sess_t next
next session (in a list of sessions)
void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen)
create, update, or zap any matching attr on this elem
pkt_t pkt_new(sm_t sm, nad_t nad)
sess_t top
top priority session
static void _announce_user_delete(mod_instance_t mi, jid_t jid)
jid_t jid_reset_components(jid_t jid, const char *node, const char *domain, const char *resource)
build a jid from components
sess_t sessions
list of action sessions
module_t mod
module that this is an instance of
jid_t from
packet addressing (not used for routing)
static mod_ret_t _announce_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
void * private
module private data
packet summary data wrapper
storage_t st
storage subsystem
nad_t nad
nad of the entire packet
void jid_free(jid_t jid)
free a jid
int aci_check(xht aci, const char *type, const char *name)
see if a username is in an acl
mod_ret_t(* in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt)
in-sess handler
void pkt_router(pkt_t pkt)
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
void(* user_delete)(mod_instance_t mi, jid_t jid)
user-delete handler
packet was unhandled, should be passed to the next module
packet was handled (and freed)
There is one instance of this struct per user who is logged in to this c2s instance.
struct moddata_st * moddata_t
void xhash_walk(xht h, xhash_walker w, void *arg)
static void _announce_free(module_t mod)
void(* free)(module_t mod)
called when module is freed
int available
true if this session is available
void nad_drop_elem(nad_t nad, int elem)
remove an element (and its subelements)
void pkt_delay(pkt_t pkt, time_t t, const char *from)
add an x:delay stamp
jid_t jid
user jid (user@host)
xht acls
access control lists (key is list name, value is jid_t list)
int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val)
get a matching attr on this elem, both name and optional val
void ** module_data
per-user module data
pkt_t pkt_create(sm_t sm, const char *elem, const char *type, const char *to, const char *from)
mod_ret_t
module return values
static void _announce_load(module_t mod, moddata_t data, const char *domain)
static void _announce_broadcast_user(const char *key, int keylen, void *val, void *arg)
#define stanza_err_INTERNAL_SERVER_ERROR
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope