130 zebra_item_t zitem, scan;
149 if(storage_get(user->
sm->
st,
"privacy-items",
jid_user(user->
jid), NULL, &os) == st_SUCCESS) {
150 if(os_iter_first(os))
152 o = os_iter_object(os);
155 if(!os_object_get_str(os, o,
"list", &str)) {
182 if(os_object_get_str(os, o,
"type", &str))
199 if(!os_object_get_str(os, o,
"value", &str)) {
200 log_debug(
ZONE,
"no value on non-fall-through item, dropping this item");
204 switch(zitem->
type) {
208 if(zitem->
jid == NULL) {
209 log_debug(
ZONE,
"invalid jid '%s' on item, dropping this item", str);
227 if(strcmp(str,
"to") == 0)
229 else if(strcmp(str,
"from") == 0)
231 else if(strcmp(str,
"both") == 0)
232 zitem->
to = zitem->
from = 1;
233 else if(strcmp(str,
"none") != 0) {
234 log_debug(
ZONE,
"invalid value '%s' on s10n item, dropping this item", str);
249 os_object_get_bool(os, o,
"deny", &zitem->
deny);
256 os_object_get_int(os, o,
"order", &(zitem->
order));
259 os_object_get_int(os, o,
"block", (
int*) &(zitem->
block));
263 for(scan = zlist->
items; scan != NULL; scan = scan->
next)
269 if(zlist->
last == NULL)
280 if(zlist->
items == scan) {
282 zlist->
items = zitem;
291 }
while(os_iter_next(os));
297 if(storage_get(user->
sm->
st,
"privacy-default",
jid_user(user->
jid), NULL, &os) == st_SUCCESS) {
298 if(os_iter_first(os))
300 o = os_iter_object(os);
302 if(os_object_get_str(os, o,
"default", &str)) {
310 }
while(os_iter_next(os));
325 log_debug(
ZONE,
"running match on list %s for %s (packet type 0x%x) (%s)", zlist->
name,
jid_full(jid), ptype, in ?
"incoming" :
"outgoing");
328 for(scan = zlist->
items; scan != NULL; scan = scan->
next) {
338 snprintf(domres,
sizeof(domres) /
sizeof(domres[0]),
"%s/%s", jid->
domain, jid->
resource);
357 for(i = 0; i < ritem->
ngroups; i++)
410 zebra_list_t zlist = NULL;
413 if(pkt->
to == NULL || pkt->
to->
node[0] ==
'\0')
451 log_debug(
ZONE,
"denying incoming packet based on privacy policy");
468 zebra_list_t zlist = NULL;
506 log_debug(
ZONE,
"denying outgoing packet based on privacy policy");
528 int ns, query, list, item;
539 for(zitem = zlist->
items; zitem != NULL; zitem = zitem->
next) {
542 switch(zitem->
type) {
556 if(zitem->
to == 1 && zitem->
from == 1)
558 else if(zitem->
to == 1)
560 else if(zitem->
from == 1)
576 snprintf(order, 14,
"%d", zitem->
order);
612 jid_t notify_jid = NULL;
614 for(scan = zlist->
items; scan != NULL; scan = scan->
next) {
616 if(zlist->
items == scan) {
618 if(zlist->
items != NULL)
621 assert(scan->
prev != NULL);
623 if(scan->
next != NULL)
627 if (zlist->
last == scan)
631 sprintf(filter,
"(&(list=%zu:%s)(type=3:jid)(value=%zu:%s))",
633 storage_delete(st,
"privacy-items",
jid_user(user->
jid), filter);
636 notify_jid = scan->
jid;
644 if(notify_jid != NULL &&
pres_trust(user, notify_jid))
645 for(sscan = user->
sessions; sscan != NULL; sscan = sscan->
next) {
660 int ns, query, list, name, active, def, item, type, value, action, order, blocking, jid, push = 0;
661 char corder[14], str[256], filter[1024];
663 zebra_list_t zlist, old;
665 zebra_item_t zitem, scan;
727 o = os_object_new(os);
728 os_object_put(o,
"default", zlist->
name, os_type_STRING);
731 if(ret != st_SUCCESS)
734 log_debug(
ZONE,
"blocking created '%s' privacy list and set it default", zlist->
name);
769 for(scan = zlist->
items; scan != NULL; scan = scan->
next)
801 if(zlist->
last == NULL) {
806 zlist->
items = zitem;
811 o = os_object_new(os);
812 os_object_put(o,
"list", zlist->
name, os_type_STRING);
813 os_object_put(o,
"type",
"jid", os_type_STRING);
814 os_object_put(o,
"value",
jid_full(zitem->
jid), os_type_STRING);
815 os_object_put(o,
"deny", &zitem->
deny, os_type_BOOLEAN);
816 os_object_put(o,
"order", &zitem->
order, os_type_INTEGER);
817 os_object_put(o,
"block", &zitem->
block, os_type_INTEGER);
820 if(ret != st_SUCCESS) {
830 if(scan != NULL && scan->
deny) {
849 result =
pkt_create(pkt->
sm,
"iq",
"result", NULL, NULL);
861 if(result->
from != NULL) {
881 result =
pkt_create(pkt->
sm,
"iq",
"result", NULL, NULL);
891 for(zitem = zlist->
items; zitem != NULL; zitem = zitem->
next) {
925 if((list < 0 && active < 0 && def < 0) || (list >= 0 && (active >=0 || def >= 0)))
966 if(action < 0 || order < 0 || (type >= 0 && value < 0)) {
976 o = os_object_new(os);
977 os_object_put(o,
"list", zlist->
name, os_type_STRING);
985 if(zitem->
jid == NULL) {
996 os_object_put(o,
"type",
"jid", os_type_STRING);
997 os_object_put(o,
"value",
jid_full(zitem->
jid), os_type_STRING);
1009 os_object_put(o,
"type",
"group", os_type_STRING);
1010 os_object_put(o,
"value", zitem->
group, os_type_STRING);
1016 os_object_put(o,
"type",
"subscription", os_type_STRING);
1020 os_object_put(o,
"value",
"to", os_type_STRING);
1023 os_object_put(o,
"value",
"from", os_type_STRING);
1025 zitem->
to = zitem->
from = 1;
1026 os_object_put(o,
"value",
"both", os_type_STRING);
1028 os_object_put(o,
"value",
"none", os_type_STRING);
1054 os_object_put(o,
"deny", &zitem->
deny, os_type_BOOLEAN);
1059 zitem->
order = atoi(corder);
1061 os_object_put(o,
"order", &zitem->
order, os_type_INTEGER);
1080 os_object_put(o,
"block", &zitem->
block, os_type_INTEGER);
1083 for(scan = zlist->
items; scan != NULL; scan = scan->
next)
1089 if(zlist->
last == NULL)
1094 zlist->
last = zitem;
1100 if(zlist->
items == scan) {
1102 zlist->
items = zitem;
1117 sprintf(filter,
"(list=%zu:%s)", strlen(zlist->
name), zlist->
name);
1123 if(ret != st_SUCCESS) {
1132 if(zlist->
items == NULL) {
1168 o = os_object_new(os);
1170 os_object_put(o,
"default", zlist->
name, os_type_STRING);
1176 log_debug(
ZONE,
"default list is now '%s'", (zlist != NULL) ? zlist->
name :
"(NONE)");
1197 log_debug(
ZONE,
"request to make list '%s' active, but there's no such list", str);
1222 log_debug(
ZONE,
"request to make list '%s' default, but there's no such list");
1229 o = os_object_new(os);
1231 os_object_put(o,
"default", zlist->
name, os_type_STRING);
1242 result =
pkt_create(pkt->
sm,
"iq",
"result", NULL, NULL);
1263 result =
pkt_create(pkt->
sm,
"iq",
"result", NULL, NULL);
1295 if(z->
def != NULL) {
1314 storage_delete(mi->
sm->
st,
"privacy-items",
jid_user(jid), NULL);
1315 storage_delete(mi->
sm->
st,
"privacy-default",
jid_user(jid), NULL);
1326 if (mod->
init)
return 0;
pkt_t pkt_error(pkt_t pkt, int err)
user_t user
user this session belongs to
xht roster
roster for this user (key is full jid of item, value is item_t)
pkt_type_t type
packet type
int sm_register_ns(sm_t sm, const char *uri)
register a new global ns
jid_t jid
session jid (user@host/res)
data structures and prototypes for the session manager
int nad_insert_elem(nad_t nad, int parent, int ns, const char *name, const char *cdata)
shove in a new child elem after the given one
pkt_t pres
copy of the last presence packet we received
void sm_unregister_ns(sm_t sm, const char *uri)
unregister a global ns
mod_ret_t(* out_router)(mod_instance_t mi, pkt_t pkt)
out-router handler
const char * jid_user(jid_t jid)
expand and return the user
struct zebra_item_st * zebra_item_t
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
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
void * xhash_getx(xht h, const char *key, int len)
static void _privacy_lists_result_builder(const char *name, int namelen, void *val, void *arg)
add a list to the return packet
int init
number of times the module intialiser has been called
jid_t A
list of jids that this session has sent directed presence to
static mod_ret_t _privacy_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt)
list management requests
void ** module_data
per-session module data
#define stanza_err_FEATURE_NOT_IMPLEMENTED
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
pkt_t pkt_dup(pkt_t pkt, const char *to, const char *from)
duplicate pkt, replacing addresses
SM_API user_t user_load(sm_t sm, jid_t jid)
fetch user data
mod_ret_t(* in_router)(mod_instance_t mi, pkt_t pkt)
in-router handler
void pkt_id_new(pkt_t pkt)
create an id value for new iq packets
static void _privacy_user_free(zebra_t *z)
int xhash_iter_next(xht h)
int pres_trust(user_t user, jid_t jid)
see if the jid is trusted (ie in the roster with s10n="from" or "both")
static mod_ret_t _privacy_in_router(mod_instance_t mi, pkt_t pkt)
check incoming packets
pool_t p
memory pool this session is allocated off
static void _privacy_result_builder(xht zhash, const char *name, void *val, void *arg)
add a list to the return packet
sess_t next
next session (in a list of sessions)
void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen)
create, update, or zap any matching attr on this elem
sess_t top
top priority session
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
mod_ret_t(* in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt)
in-sess handler
pool_t p
memory pool this user is allocated off
sess_t sessions
list of action sessions
module_t mod
module that this is an instance of
jid_t from
packet addressing (not used for routing)
void feature_unregister(sm_t sm, const char *feature)
unregister feature
packet summary data wrapper
void * pmalloco(pool_t p, int size)
easy safety utility (for creating blank mem for structs, etc)
int jid_search(jid_t list, jid_t jid)
util to search through jids
char * pstrdupx(pool_t p, const char *src, int len)
use given size
storage_t st
storage subsystem
nad_t nad
nad of the entire packet
void jid_free(jid_t jid)
free a jid
void xhash_put(xht h, const char *key, void *val)
static mod_ret_t _privacy_out_router(mod_instance_t mi, pkt_t pkt)
check outgoing packets
zebra data for a single user
#define stanza_err_BAD_REQUEST
int ngroups
number of groups in groups array
struct pkt_st * pkt_t
packet summary data wrapper
int xhash_iter_get(xht h, const char **key, int *keylen, void **val)
const char ** groups
groups this item is in
void pkt_id(pkt_t src, pkt_t dest)
convenience - copy the packet id from src to dest
int jid_compare_full(jid_t a, jid_t b)
compare two full jids
void pkt_router(pkt_t pkt)
void xhash_zap(xht h, const char *key)
static void _unblock_jid(user_t user, storage_t st, zebra_list_t zlist, jid_t jid)
remove jid deny ocurrences from the privacy list, unblock all if no jid given to match, then update unblocked contact with presence information
void feature_register(sm_t sm, const char *feature)
register a feature
sess_t sess_match(user_t user, const char *resource)
match a session by resource
static void _privacy_free_z(zebra_t z)
packet was unhandled, should be passed to the next module
#define stanza_err_ITEM_NOT_FOUND
packet was handled (and freed)
There is one instance of this struct per user who is logged in to this c2s instance.
int(* user_load)(mod_instance_t mi, user_t user)
user-load handler
struct privacy_st * privacy_t
int xhash_iter_first(xht h)
iteration
void xhash_walk(xht h, xhash_walker w, void *arg)
struct zebra_st * zebra_t
void(* user_delete)(mod_instance_t mi, jid_t jid)
user-delete handler
int available
true if this session is available
int from
subscription to this item (they get presence FROM us, they send presence TO us)
char * pstrdup(pool_t p, const char *src)
XXX efficient: move this to const char * and then loop throug the existing heaps to see if src is wit...
#define stanza_err_NOT_ACCEPTABLE
jid_t jid
user jid (user@host)
void * xhash_get(xht h, const char *key)
static int _privacy_action(user_t user, zebra_list_t zlist, jid_t jid, pkt_type_t ptype, int in)
returns 0 if the packet should be allowed, otherwise 1
static int _privacy_user_load(mod_instance_t mi, user_t user)
struct zebra_list_st * zebra_list_t
jid_t E
list of jids that bounced presence updates we sent them
void(* free)(module_t mod)
called when module is freed
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
void ** module_data
per-user module data
pool - base node for a pool.
pkt_t pkt_create(sm_t sm, const char *elem, const char *type, const char *to, const char *from)
static void _privacy_free(module_t mod)
mod_ret_t
module return values
static void _privacy_user_delete(mod_instance_t mi, jid_t jid)
#define stanza_err_INTERNAL_SERVER_ERROR
void pkt_sess(pkt_t pkt, sess_t sess)
DLLEXPORT int module_init(mod_instance_t mi, const char *arg)
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope