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)
149 for(i = 0; i < item->
ngroups; 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;
208 char *str, *group, filter[4096];
209 const char *fetchkey;
210 int i,j,gpos,found,
delete,checksm,tmp_to,tmp_from,tmp_do_change;
217 if(user->
roster == NULL) {
233 if( storage_get(user->
sm->
st, (roster_publish->
dbtable ? roster_publish->
dbtable :
"published-roster"), fetchkey, NULL, &os) == st_SUCCESS ) {
234 if(os_iter_first(os)) {
238 o = os_iter_object(os);
239 if(os_object_get_str(os, o,
"jid", &str)) {
242 _roster_publish_active_cache_t active_cached = 0;
255 strcmp(jid->domain, roster_publish->
removedomain) == 0 ) {
267 if( active_cached != NULL ) {
272 if( active_cached->
active ) {
283 if( userinsm == -1 ) {
286 active_cached->
time = time(NULL);
289 if(storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS
290 && os_iter_first(os_active)) {
293 o_active = os_iter_object(os_active);
294 os_object_get_time(os_active, o_active,
"time", &active_cached->
active);
302 active_cached->
active = 0;
319 if( checksm && !userinsm ) {
327 if(item->jid == NULL) {
334 os_object_get_str(os, o,
"group", &str);
344 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
345 item->groups[item->ngroups] = group;
348 if(os_object_get_str(os, o,
"name", &str))
349 item->name = strdup(str);
351 os_object_get_bool(os, o,
"to", &item->to);
352 os_object_get_bool(os, o,
"from", &item->from);
353 os_object_get_int(os, o,
"ask", &item->ask);
355 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);
361 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
365 ( (checksm && !userinsm) ||
366 (!checksm && storage_get(user->
sm->
st,
"active",
jid_user(jid), NULL, &os_active) == st_SUCCESS && os_iter_first(os_active))
377 ofe = os_object_new(osfe);
378 os_object_put_time(ofe,
"time", &tfe);
387 if( checksm && !userinsm ) {
389 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
390 storage_delete(user->
sm->
st,
"roster-items",
jid_user(user->
jid), filter);
391 snprintf(filter, 4096,
"(jid=%s)",
jid_full(jid));
392 storage_delete(user->
sm->
st,
"roster-groups",
jid_user(user->
jid), filter);
398 if( roster_publish->
fixsubs ) {
400 os_object_get_bool(os, o,
"to", &tmp_to);
401 os_object_get_bool(os, o,
"from", &tmp_from);
402 if( item->to != tmp_to || item->from != tmp_from ) {
404 item->from = tmp_from;
412 if(os_object_get_str(os, o,
"name", &str)) {
418 if( strcmp(item->name,str) != 0 ) {
422 if( tmp_do_change ) {
424 item->name = strdup(str);
435 os_object_get_str(os, o,
"group", &str);
439 log_write(user->
sm->
log, LOG_ERR,
"roster_publish: unknown published group id '%s' for %s",str,
jid_full(item->jid));
447 for(i = 0; i < item->ngroups; i++) {
448 if( strcmp(item->groups[i],group) == 0 ) {
467 if( strcmp(item->groups[i]+gpos,roster_publish->
groupsuffix) == 0 ) {
474 free(item->groups[i]);
475 for(j = i; j < item->ngroups-1; j++) {
476 item->groups[j]=item->groups[j+1];
479 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups));
485 item->groups = realloc(item->groups,
sizeof(
char *) * (item->ngroups + 1));
486 item->groups[item->ngroups] = group;
497 }
while(os_iter_next(os));
519 free(roster_publish);
526 if(mod->
init)
return 0;