void con_room_sendwalk(gpointer key, gpointer data, gpointer arg) { xmlnode x = (xmlnode)arg; cnu to = (cnu)data; cnu from; xmlnode output; if(x == NULL || to == NULL) { log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE); return; } if (to->remote == 1) return; from = (cnu)xmlnode_get_vattrib(x,"cnu"); if(j_strcmp(xmlnode_get_name(x),"presence") == 0) { output = add_extended_presence(from, to, x, NULL, NULL, NULL); if(jid_cmp(to->realid,from->realid)==0) //own presence { add_status_code(output, STATUS_MUC_OWN_PRESENCE); } con_user_send(to, from, output); } else { con_user_send(to, from, xmlnode_dup(x)); /* Need to send duplicate */ } }
/** Tests comparing non-equal JIDs. */ void test_cmp12(void **state) { struct jid *a = jid_new_from_str("bbb"); struct jid *b = jid_new_from_str("ccc"); assert_int_not_equal(jid_cmp(a, b), 0); jid_del(a); jid_del(b); }
/** Tests comparing non-equal JIDs. */ void test_cmp9(void **state) { struct jid *a = jid_new_from_str("aaa@bbb/ccc"); struct jid *b = jid_new_from_str("aaa@ddd"); assert_int_not_equal(jid_cmp(a, b), 0); jid_del(a); jid_del(b); }
/** Tests comparing equal JIDs. */ void test_cmp4(void **state) { struct jid *a = jid_new_from_str("domain"); struct jid *b = jid_new_from_str("domain"); assert_int_equal(jid_cmp(a, b), 0); jid_del(a); jid_del(b); }
/** Tests comparing equal JIDs. */ void test_cmp1(void **state) { struct jid *a = jid_new_from_str("local@domain/resource"); struct jid *b = jid_new_from_str("local@domain/resource"); assert_int_equal(jid_cmp(a, b), 0); jid_del(a); jid_del(b); }
/** * util to check if someone knows about us * * checks if the JID id is contained in the JID list ids * * @param id the JabberID that should be checked * @param ids the list of JabberIDs * @return 1 if it is contained, 0 else */ int _mod_presence_search(jid id, jid ids) { jid cur; for (cur = ids; cur != NULL; cur = cur->next) if (jid_cmp(cur, id) == 0) return 1; return 0; }
/* child that handles packets from the user */ void _js_session_from(void *arg) { jpacket p = (jpacket) arg; session s = (session) (p->aux1); /* if this session is dead */ if (s->exit_flag) { /* send the packet into oblivion */ xmlnode_free(p->x); return; } /* at least we must have a valid packet */ if (p->type == JPACKET_UNKNOWN) { /* send an error back */ jutil_error(p->x, TERROR_BAD); jpacket_reset(p); js_session_to(s, p); return; } /* debug message */ log_debug("THREAD:SESSION:FROM received a packet!"); /* increment packet out count */ s->si->stats->packets_out++; s->c_out++; /* make sure we have our from set correctly for outgoing packets */ if (jid_cmpx(p->from, s->id, JID_USER | JID_SERVER) != 0) { /* nope, fix it */ xmlnode_put_attrib(p->x, "from", jid_full(s->id)); p->from = jid_new(p->p, jid_full(s->id)); } /* if you use to="yourself@yourhost" it's the same as not having a to, the modules use the NULL as a self-flag */ if (jid_cmp(p->to, s->uid) == 0) { /* xmlnode_hide_attrib(p->x,"to"); */ p->to = NULL; } /* let the modules have their heyday */ if (js_mapi_call(NULL, es_OUT, p, s->u, s)) return; /* no module handled it, so restore the to attrib to us */ if (p->to == NULL) { xmlnode_put_attrib(p->x, "to", jid_full(s->uid)); p->to = jid_new(p->p, jid_full(s->uid)); } js_post_out_main(s, p); /* pass these to the general delivery function */ // js_deliver(s->si, p); }
/** * remove a jid from a list, returning the new list * * @param id the JabberID that should be removed * @param ids the list of JabberIDs * @return the new list */ jid _mod_presence_whack(jid id, jid ids) { jid curr; if (id == NULL || ids == NULL) return NULL; /* check first */ if (jid_cmp(id, ids) == 0) return ids->next; /* check through the list, stopping at the previous list entry to a matching one */ for (curr = ids; curr != NULL && jid_cmp(curr->next, id) != 0; curr = curr->next); /* clip it out if found */ if (curr != NULL) curr->next = curr->next->next; return ids; }
/* session thread */ mreturn mod_presence_in(mapi m, void *arg) { modpres mp = (modpres) arg; xmlnode pres; if (m->packet->type != JPACKET_PRESENCE) return M_IGNORE; log_debug("incoming filter for %s", jid_full(m->s->id)); if (jpacket_subtype(m->packet) == JPACKET__PROBE) { /* reply with our presence */ if (m->s->presence == NULL) { log_debug("probe from %s and no presence to return", jid_full(m->packet->from)); } else if (!mp->invisible && js_trust(m->user, m->packet->from) && !_mod_presence_search(m->packet->from, mp->I)) { /* compliment of I in T */ log_debug("got a probe, responding to %s", jid_full(m->packet->from)); pres = xmlnode_dup(m->s->presence); xmlnode_put_attrib(pres, "to", jid_full(m->packet->from)); js_session_from(m->s, jpacket_new(pres)); } else if (mp->invisible && js_trust(m->user, m->packet->from) && _mod_presence_search(m->packet->from, mp->A)) { /* when invisible, intersection of A and T */ log_debug("got a probe when invisible, responding to %s", jid_full(m->packet->from)); pres = jutil_presnew(JPACKET__AVAILABLE, jid_full(m->packet->from), NULL); js_session_from(m->s, jpacket_new(pres)); } else { log_debug("%s attempted to probe by someone not qualified", jid_full(m->packet->from)); } xmlnode_free(m->packet->x); return M_HANDLED; } if (jid_cmp(m->packet->from, m->s->id) == 0) { /* this is our presence, don't send to ourselves */ xmlnode_free(m->packet->x); return M_HANDLED; } /* if a presence packet bounced, remove from the A list */ if (jpacket_subtype(m->packet) == JPACKET__ERROR) mp->A = _mod_presence_whack(m->packet->from, mp->A); /* doh! this is a user, they should see invisibles as unavailables */ if (jpacket_subtype(m->packet) == JPACKET__INVISIBLE) xmlnode_put_attrib(m->packet->x, "type", "unavailable"); return M_PASS; }