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 if( os_object_get_str(os, o,
"groupname", &str) && str ) {
123 log_debug(
ZONE,
"group cache: updating cache value for %s",groupid);
125 group_cached->
time = time(NULL);
126 group_cached->
groupid = strdup(groupid);
145 if(item->
name != NULL)
146 free((
void*)item->
name);
148 for(i = 0; i < item->
ngroups; i++)
149 free((
void*)item->
groups[i]);
164 o = os_object_new(os);
166 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
168 if(item->
name != NULL)
169 os_object_put(o,
"name", item->
name, os_type_STRING);
171 os_object_put(o,
"to", &item->
to, os_type_BOOLEAN);
172 os_object_put(o,
"from", &item->
from, os_type_BOOLEAN);
173 os_object_put(o,
"ask", &item->
ask, os_type_INTEGER);
175 snprintf(filter, 4096,
"(jid=%s)",
jid_full(item->
jid));
177 storage_replace(user->
sm->
st,
"roster-items",
jid_user(user->
jid), filter, os);
181 snprintf(filter, 4096,
"(jid=%s)",
jid_full(item->
jid));
184 storage_delete(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter);
190 for(i = 0; i < item->
ngroups; i++) {
191 o = os_object_new(os);
193 os_object_put(o,
"jid",
jid_full(item->
jid), os_type_STRING);
194 os_object_put(o,
"group", item->
groups[i], os_type_STRING);
197 storage_replace(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter, os);
206 os_object_t o, o_active;
210 const char *fetchkey;
211 int i,j,gpos,found,
delete,checksm,tmp_to,tmp_from,tmp_do_change;
218 if(user->
roster == NULL) {
234 if( storage_get(user->
sm->
st, (roster_publish->
dbtable ? roster_publish->
dbtable :
"published-roster"), fetchkey, NULL, &os) == st_SUCCESS ) {
235 if(os_iter_first(os)) {
239 o = os_iter_object(os);
240 if(os_object_get_str(os, o,
"jid", &str)) {
256 strcmp(jid->domain, roster_publish->
removedomain) == 0 ) {
268 if( active_cached != NULL ) {
273 if( active_cached->
active ) {
284 if( userinsm == -1 ) {
287 active_cached->
time = time(NULL);
290 if(storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS
291 && os_iter_first(os_active)) {
294 o_active = os_iter_object(os_active);
295 os_object_get_time(os_active, o_active,
"time", &active_cached->
active);
303 active_cached->
active = 0;
320 if( checksm && !userinsm ) {
328 if(item->jid == NULL) {
335 os_object_get_str(os, o,
"group", &str);
345 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
346 item->groups[item->ngroups] = group;
349 if(os_object_get_str(os, o,
"name", &str))
350 item->name = strdup(str);
352 os_object_get_bool(os, o,
"to", &item->to);
353 os_object_get_bool(os, o,
"from", &item->from);
354 os_object_get_int(os, o,
"ask", &item->ask);
356 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);
362 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
366 ( (checksm && !userinsm) ||
367 (!checksm && storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS && os_iter_first(os_active))
378 ofe = os_object_new(osfe);
379 os_object_put_time(ofe,
"time", &tfe);
388 if( checksm && !userinsm ) {
390 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
391 storage_delete(user->
sm->
st,
"roster-items",
jid_user(user->
jid), filter);
392 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
393 storage_delete(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter);
399 if( roster_publish->
fixsubs ) {
401 os_object_get_bool(os, o,
"to", &tmp_to);
402 os_object_get_bool(os, o,
"from", &tmp_from);
403 if( item->to != tmp_to || item->from != tmp_from ) {
405 item->from = tmp_from;
413 if(os_object_get_str(os, o,
"name", &str)) {
419 if( strcmp(item->name,str) != 0 ) {
423 if( tmp_do_change ) {
425 item->name = strdup(str);
436 os_object_get_str(os, o,
"group", &str);
440 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
448 for(i = 0; i < item->ngroups; i++) {
449 if( strcmp(item->groups[i],group) == 0 ) {
468 if( strcmp(item->groups[i]+gpos,roster_publish->
groupsuffix) == 0 ) {
475 free((
void*)item->groups[i]);
476 for(j = i; j < item->ngroups-1; j++) {
477 item->groups[j]=item->groups[j+1];
480 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups));
486 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
487 item->groups[item->ngroups] = group;
498 }
while(os_iter_next(os));
520 free(roster_publish);
527 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)
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
int(* user_load)(mod_instance_t mi, user_t user)
user-load handler
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)
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
void(* free)(module_t mod)
called when module is freed
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)