52 int nitems, eitem, ajid, as10n, aname, egroup;
60 if(st.st_mtime <= tr->
mtime)
63 tr->
mtime = st.st_mtime;
76 fseek(f, 0, SEEK_END);
78 fseek(f, 0, SEEK_SET);
80 buf = (
char *) malloc(
sizeof(
char) * size);
82 if (fread(buf, 1, size, f) != size || ferror(f)) {
83 log_write(tr->
sm->
log, LOG_ERR,
"couldn't read from roster template %s: %s", tr->
filename, strerror(errno));
101 log_write(tr->
sm->
log, LOG_NOTICE,
"roster template has no elements");
109 log_write(tr->
sm->
log, LOG_ERR,
"roster template has item with no jid, skipping");
116 if(item->
jid == NULL) {
117 log_write(tr->
sm->
log, LOG_ERR,
"roster template has item with invalid jid, skipping");
129 item->
to = item->
from = 1;
139 log_write(tr->
sm->
log, LOG_ERR,
"roster template has zero-length group, skipping");
143 item->
groups = (
const char **) realloc(item->
groups,
sizeof(
char *) * (item->
ngroups + 1));
162 log_write(tr->
sm->
log, LOG_NOTICE,
"loaded %d items from roster template", nitems);
177 o = os_object_new(os);
179 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
181 if(item->
name != NULL)
182 os_object_put(o,
"name", item->
name, os_type_STRING);
184 os_object_put(o,
"to", &item->
to, os_type_BOOLEAN);
185 os_object_put(o,
"from", &item->
from, os_type_BOOLEAN);
186 os_object_put(o,
"ask", &item->
ask, os_type_INTEGER);
190 storage_replace(sm->
st,
"roster-items",
jid_user(jid), filter, os);
197 storage_delete(sm->
st,
"roster-groups",
jid_user(jid), filter);
203 for(i = 0; i < item->
ngroups; i++) {
204 o = os_object_new(os);
206 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
207 os_object_put(o,
"group", item->
groups[i], os_type_STRING);
210 storage_replace(sm->
st,
"roster-groups",
jid_user(jid), filter, os);
223 log_debug(
ZONE,
"populating roster with items from template");
227 xhv.item_val = &item;
239 if(tr->
items != NULL)
247 const char *filename;
250 if(mod->
init)
return 0;
data structures and prototypes for the session manager
#define NAD_CDATA_L(N, E)
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
static int _template_roster_user_create(mod_instance_t mi, jid_t jid)
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
config_t config
config context
int init
number of times the module intialiser has been called
void log_write(log_t log, int level, const char *msgfmt,...)
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
int ask
pending subscription (0 == none, 1 == subscribe, 2 == unsubscribe)
int xhash_iter_next(xht h)
static int _template_roster_reload(template_roster_t tr)
void pool_cleanup(pool_t p, pool_cleanup_t f, void *arg)
public cleanup utils, insert in a way that they are run FIFO, before mem frees
module_t mod
module that this is an instance of
int(* user_create)(mod_instance_t mi, jid_t jid)
user-create handler
void * private
module private data
void * pmalloco(pool_t p, int size)
easy safety utility (for creating blank mem for structs, etc)
nad_t nad_parse(const char *buf, int len)
create a nad from raw xml
char * pstrdupx(pool_t p, const char *src, int len)
use given size
storage_t st
storage subsystem
session manager global context
void jid_free(jid_t jid)
free a jid
static void _template_roster_save_item(sm_t sm, jid_t jid, item_t item)
!!! this is a cut & paste of _roster_save_time - break it out
void xhash_put(xht h, const char *key, void *val)
int ngroups
number of groups in groups array
int xhash_iter_get(xht h, const char **key, int *keylen, void **val)
const char ** groups
groups this item is in
struct item_st * item_t
roster items
int xhash_iter_first(xht h)
iteration
void(* free)(module_t mod)
called when module is freed
int from
subscription to this item (they get presence FROM us, they send presence TO us)
pool_t xhash_pool(xht h)
get our pool
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
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
struct _template_roster_st * template_roster_t
static void _template_roster_free(module_t mod)
const char * name
display name