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);
88 fseek(f, 0, SEEK_SET);
90 buf = (
char *) malloc(
sizeof(
char) * size);
92 if (fread(buf, 1, size, f) != size || ferror(f)) {
93 log_write(tr->
sm->
log, LOG_ERR,
"couldn't read from roster template %s: %s", tr->
filename, strerror(errno));
103 log_write(tr->
sm->
log, LOG_ERR,
"couldn't parse roster template");
111 log_write(tr->
sm->
log, LOG_NOTICE,
"roster template has no elements");
119 log_write(tr->
sm->
log, LOG_ERR,
"roster template has item with no jid, skipping");
126 if(item->
jid == NULL) {
127 log_write(tr->
sm->
log, LOG_ERR,
"roster template has item with invalid jid, skipping");
139 item->
to = item->
from = 1;
149 log_write(tr->
sm->
log, LOG_ERR,
"roster template has zero-length group, skipping");
153 item->
groups = (
const char **) realloc(item->
groups,
sizeof(
char *) * (item->
ngroups + 1));
172 log_write(tr->
sm->
log, LOG_NOTICE,
"loaded %d items from roster template", nitems);
187 o = os_object_new(os);
189 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
191 if(item->
name != NULL)
192 os_object_put(o,
"name", item->
name, os_type_STRING);
194 os_object_put(o,
"to", &item->
to, os_type_BOOLEAN);
195 os_object_put(o,
"from", &item->
from, os_type_BOOLEAN);
196 os_object_put(o,
"ask", &item->
ask, os_type_INTEGER);
213 for(i = 0; i < item->
ngroups; i++) {
214 o = os_object_new(os);
216 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
217 os_object_put(o,
"group", item->
groups[i], os_type_STRING);
233 log_debug(
ZONE,
"populating roster with items from template");
237 xhv.item_val = &item;
249 if(tr->
items != NULL)
257 const char *filename;
260 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
int nad_find_attr(nad_t nad, unsigned int elem, int ns, const char *name, const char *val)
get a matching attr on this elem, both name and optional val
single instance of a module in a chain
static int _template_roster_user_create(mod_instance_t mi, jid_t jid)
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
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 nad_find_elem(nad_t nad, unsigned int elem, int ns, const char *name, int depth)
locate the next elem at a given depth with an optional matching name
int xhash_iter_first(xht h)
iteration
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
void(* free)(module_t mod)
called when module is freed
struct _template_roster_st * template_roster_t
int(* user_create)(mod_instance_t mi, jid_t jid)
user-create handler
static void _template_roster_free(module_t mod)
const char * name
display name