Beispiel #1
0
/* session thread */
mreturn mod_presence_avails(mapi m, void *arg)
{
	modpres mp = (modpres) arg;

	if (m->packet->type != JPACKET_PRESENCE)
		return M_IGNORE;

	if (m->packet->to == NULL)
		return M_PASS;

	log_debug("track presence sent to jids");

	/* handle invisibles: put in I and remove from A */
	if (jpacket_subtype(m->packet) == JPACKET__INVISIBLE) {
		if (mp->I == NULL)
			mp->I = jid_new(m->s->p, jid_full(m->packet->to));
		else
			jid_append(mp->I, m->packet->to);
		mp->A = _mod_presence_whack(m->packet->to, mp->A);
		return M_PASS;
	}

	/* ensure not invisible from before */
	mp->I = _mod_presence_whack(m->packet->to, mp->I);

	/* avails to A */
	if (jpacket_subtype(m->packet) == JPACKET__AVAILABLE)
		jid_append(mp->A, m->packet->to);

	/* unavails from A */
	if (jpacket_subtype(m->packet) == JPACKET__UNAVAILABLE)
		mp->A = _mod_presence_whack(m->packet->to, mp->A);

	return M_PASS;
}
Beispiel #2
0
/**
 * init the module, register callbacks
 *
 * builds a list of JabberIDs where presences should be blind carbon copied to.
 * (Enclosing each in a <bcc/> element, which are contained in one <presence/>
 * element in the session manager configuration.)
 *
 * registers mod_presence_session() as a callback, that gets notified on new sessions
 * and mod_presence_deliver() as a callback to deliver presence stanzas locally.
 *
 * @param si the session manager instance
 */
JSM_FUNC void mod_presence(jsmi si)
{
	xmlnode cfg = js_config(si, "presence");
	modpres_conf conf =
	    (modpres_conf) pmalloco(si->p, sizeof(_modpres_conf));

	log_debug("init");

	for (cfg = xmlnode_get_firstchild(cfg); cfg != NULL;
	     cfg = xmlnode_get_nextsibling(cfg)) {
		char *element_name = NULL;

		if (xmlnode_get_type(cfg) != NTYPE_TAG)
			continue;

		element_name = xmlnode_get_name(cfg);
		if (j_strcmp(element_name, "bcc") == 0) {
			if (conf->bcc == NULL)
				conf->bcc =
				    jid_new(si->p, xmlnode_get_data(cfg));
			else
				jid_append(conf->bcc,
					   jid_new(si->p,
						   xmlnode_get_data(cfg)));
		} else if (j_strcmp(element_name, "presence2xdb") == 0) {
			conf->pres_to_xdb++;
		}
	}

	js_mapi_register(si, e_DELIVER, mod_presence_deliver, NULL);
	js_mapi_register(si, e_SESSION, mod_presence_session,
			 (void *) conf);
}
Beispiel #3
0
xht aci_load(sm_t sm)
{
    xht acls;
    int aelem, jelem, attr;
    char type[33];
    jid_t list, jid;

    log_debug(ZONE, "loading aci");

    acls = xhash_new(51);

    if((aelem = nad_find_elem(sm->config->nad, 0, -1, "aci", 1)) < 0)
        return acls;

    aelem = nad_find_elem(sm->config->nad, aelem, -1, "acl", 1);
    while(aelem >= 0)
    {
        list = NULL;

        if((attr = nad_find_attr(sm->config->nad, aelem, -1, "type", NULL)) < 0)
        {
            aelem = nad_find_elem(sm->config->nad, aelem, -1, "acl", 0);
            continue;
        }

        snprintf(type, 33, "%.*s", NAD_AVAL_L(sm->config->nad, attr), NAD_AVAL(sm->config->nad, attr));

        log_debug(ZONE, "building list for '%s'", type);

        jelem = nad_find_elem(sm->config->nad, aelem, -1, "jid", 1);
        while(jelem >= 0)
        {
            if(NAD_CDATA_L(sm->config->nad, jelem) > 0)
            {
                jid = jid_new(NAD_CDATA(sm->config->nad, jelem), NAD_CDATA_L(sm->config->nad, jelem));
                list = jid_append(list, jid);
                
                log_debug(ZONE, "added '%s'", jid_user(jid));

                jid_free(jid);
            }

            jelem = nad_find_elem(sm->config->nad, jelem, -1, "jid", 0);
        }

        if(list != NULL) {
            xhash_put(acls, pstrdup(xhash_pool(acls), type), (void *) list);
        }

        aelem = nad_find_elem(sm->config->nad, aelem, -1, "acl", 0);
    }

    return acls;
}
Beispiel #4
0
/* we should be last in the list of modules */
JSM_FUNC void mod_log(jsmi si)
{
	xmlnode cfg = js_config(si, "archive");
	jid svcs = NULL;

	log_debug("mod_log init");

	/* look for archiving service too */
	for (cfg = xmlnode_get_firstchild(cfg); cfg != NULL;
	     cfg = xmlnode_get_nextsibling(cfg)) {
		if (xmlnode_get_type(cfg) != NTYPE_TAG
		    || j_strcmp(xmlnode_get_name(cfg), "service") != 0)
			continue;
		if (svcs == NULL)
			svcs = jid_new(si->p, xmlnode_get_data(cfg));
		else
			jid_append(svcs,
				   jid_new(si->p, xmlnode_get_data(cfg)));
	}

	js_mapi_register(si, e_SESSION, mod_log_session, (void *) svcs);
}