86 _roster_publish_group_cache_t group_cached;
89 if(!groupid)
return groupid;
96 if( group_cached != NULL ) {
98 log_debug(
ZONE,
"group cache: expiring cached value for %s",groupid);
102 log_debug(
ZONE,
"group cache: returning cached value for %s",groupid);
113 if(storage_get(sm->
st,
"published-roster-groups", groupid, NULL, &os) == st_SUCCESS && os_iter_first(os)) {
114 o = os_iter_object(os);
115 os_object_get_str(os, o,
"groupname", &str);
124 log_debug(
ZONE,
"group cache: updating cache value for %s",groupid);
126 group_cached->
time = time(NULL);
127 group_cached->
groupid = strdup(groupid);
146 if(item->
name != NULL)
147 free((
void*)item->
name);
149 for(i = 0; i < item->
ngroups; i++)
150 free((
void*)item->
groups[i]);
165 o = os_object_new(os);
167 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
169 if(item->
name != NULL)
170 os_object_put(o,
"name", item->
name, os_type_STRING);
172 os_object_put(o,
"to", &item->
to, os_type_BOOLEAN);
173 os_object_put(o,
"from", &item->
from, os_type_BOOLEAN);
174 os_object_put(o,
"ask", &item->
ask, os_type_INTEGER);
176 snprintf(filter, 4096,
"(jid=%s)",
jid_full(item->
jid));
178 storage_replace(user->
sm->
st,
"roster-items",
jid_user(user->
jid), filter, os);
182 snprintf(filter, 4096,
"(jid=%s)",
jid_full(item->
jid));
185 storage_delete(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter);
191 for(i = 0; i < item->
ngroups; i++) {
192 o = os_object_new(os);
194 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
195 os_object_put(o,
"group", item->
groups[i], os_type_STRING);
198 storage_replace(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter, os);
207 os_object_t o, o_active;
211 const char *fetchkey;
212 int i,j,gpos,found,
delete,checksm,tmp_to,tmp_from,tmp_do_change;
219 if(user->
roster == NULL) {
235 if( storage_get(user->
sm->
st, (roster_publish->
dbtable ? roster_publish->
dbtable :
"published-roster"), fetchkey, NULL, &os) == st_SUCCESS ) {
236 if(os_iter_first(os)) {
240 o = os_iter_object(os);
241 if(os_object_get_str(os, o,
"jid", &str)) {
244 _roster_publish_active_cache_t active_cached = 0;
257 strcmp(jid->domain, roster_publish->
removedomain) == 0 ) {
269 if( active_cached != NULL ) {
274 if( active_cached->
active ) {
285 if( userinsm == -1 ) {
288 active_cached->
time = time(NULL);
291 if(storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS
292 && os_iter_first(os_active)) {
295 o_active = os_iter_object(os_active);
296 os_object_get_time(os_active, o_active,
"time", &active_cached->
active);
304 active_cached->
active = 0;
321 if( checksm && !userinsm ) {
329 if(item->jid == NULL) {
336 os_object_get_str(os, o,
"group", &str);
346 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
347 item->groups[item->ngroups] = group;
350 if(os_object_get_str(os, o,
"name", &str))
351 item->name = strdup(str);
353 os_object_get_bool(os, o,
"to", &item->to);
354 os_object_get_bool(os, o,
"from", &item->from);
355 os_object_get_int(os, o,
"ask", &item->ask);
357 log_debug(
ZONE,
"adding %s to roster from template (to %d from %d ask %d name %s)",
jid_full(item->jid), item->to, item->from, item->ask, item->name);
363 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
367 ( (checksm && !userinsm) ||
368 (!checksm && storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS && os_iter_first(os_active))
379 ofe = os_object_new(osfe);
380 os_object_put_time(ofe,
"time", &tfe);
389 if( checksm && !userinsm ) {
391 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
392 storage_delete(user->
sm->
st,
"roster-items",
jid_user(user->
jid), filter);
393 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
394 storage_delete(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter);
400 if( roster_publish->
fixsubs ) {
402 os_object_get_bool(os, o,
"to", &tmp_to);
403 os_object_get_bool(os, o,
"from", &tmp_from);
404 if( item->to != tmp_to || item->from != tmp_from ) {
406 item->from = tmp_from;
414 if(os_object_get_str(os, o,
"name", &str)) {
420 if( strcmp(item->name,str) != 0 ) {
424 if( tmp_do_change ) {
426 item->name = strdup(str);
437 os_object_get_str(os, o,
"group", &str);
441 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
449 for(i = 0; i < item->ngroups; i++) {
450 if( strcmp(item->groups[i],group) == 0 ) {
469 if( strcmp(item->groups[i]+gpos,roster_publish->
groupsuffix) == 0 ) {
476 free((
void*)item->groups[i]);
477 for(j = i; j < item->ngroups-1; j++) {
478 item->groups[j]=item->groups[j+1];
481 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups));
487 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
488 item->groups[item->ngroups] = group;
499 }
while(os_iter_next(os));
521 free(roster_publish);
528 if(mod->
init)
return 0;
xht roster
roster for this user (key is full jid of item, value is item_t)
data structures and prototypes for the session manager
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
const char * jid_user(jid_t jid)
expand and return the user
static int _roster_publish_user_load(mod_instance_t mi, user_t user)
publish the roster from the database
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
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,...)
int ask
pending subscription (0 == none, 1 == subscribe, 2 == unsubscribe)
int j_atoi(const char *a, int def)
int(* user_load)(mod_instance_t mi, user_t user)
user-load handler
static void _roster_publish_free_active_cache_walker(const char *key, int keylen, void *val, void *arg)
static void _roster_publish_save_item(user_t user, item_t item)
static const char * _roster_publish_get_group_name(sm_t sm, roster_publish_t rp, const char *groupid)
module_t mod
module that this is an instance of
void * private
module private data
storage_t st
storage subsystem
session manager global context
void jid_free(jid_t jid)
free a jid
void xhash_put(xht h, const char *key, void *val)
int ngroups
number of groups in groups array
struct _roster_publish_st * roster_publish_t
const char ** groups
groups this item is in
void xhash_zap(xht h, const char *key)
struct item_st * item_t
roster items
static void _roster_publish_free_group_cache_walker(const char *key, int keylen, void *val, void *arg)
void xhash_walk(xht h, xhash_walker w, void *arg)
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)
jid_t jid
user jid (user@host)
void * xhash_get(xht h, const char *key)
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
static void _roster_publish_free(module_t mod)
struct _roster_publish_group_cache_st * _roster_publish_group_cache_t
struct _roster_publish_active_cache_st * _roster_publish_active_cache_t
const char * removedomain
const char * name
display name
static void _roster_publish_free_walker(xht roster, const char *key, void *val, void *arg)