Esempio n. 1
0
mreturn mod_browse_reply(mapi m, void *arg)
{
	xmlnode browse, ns, cur;
	session s;

	if (m->packet->type != JPACKET_IQ)
		return M_IGNORE;
	if (!NSCHECK(m->packet->iq, NS_BROWSE))
		return M_PASS;

	/* first, is this a valid request? */
	switch (jpacket_subtype(m->packet)) {
	case JPACKET__RESULT:
	case JPACKET__ERROR:
		return M_PASS;
	case JPACKET__SET:
		js_bounce(m->si, m->packet->x, TERROR_NOTALLOWED);
		return M_HANDLED;
	}

	log_debug("handling query for user %s", m->user->user);

	/* get this dudes browse info */
	browse = mod_browse_get(m, m->packet->to);

	/* insert the namespaces */
	ns = xdb_get(m->si->xc, m->packet->to, NS_XDBNSLIST);
	for (cur = xmlnode_get_firstchild(ns); cur != NULL;
	     cur = xmlnode_get_nextsibling(cur))
		if (xmlnode_get_attrib(cur, "type") == NULL)
			xmlnode_insert_tag_node(browse, cur);	/* only include the generic <ns>foo</ns> */
	xmlnode_free(ns);

	/* include any connected resources if there's a s10n from them */
	if (js_trust(m->user, m->packet->from)) {
		SEM_LOCK(m->user->sem);
		for (s = m->user->sessions; s != NULL; s = s->next) {
			/* if(s->priority < 0) continue; *** include all resources I guess */
			if (xmlnode_get_tag
			    (browse,
			     spools(m->packet->p, "?jid=", jid_full(s->id),
				    m->packet->p)) != NULL)
				continue;	/* already in the browse result */
			cur = xmlnode_insert_tag(browse, "user");
			xmlnode_put_attrib(cur, "type", "client");
			xmlnode_put_attrib(cur, "jid", jid_full(s->id));
		}
		SEM_UNLOCK(m->user->sem);
	}

	/* XXX include iq:filter forwards */

	jutil_iqresult(m->packet->x);
	jpacket_reset(m->packet);
	xmlnode_insert_tag_node(m->packet->x, browse);
	js_deliver(m->si, m->packet);

	xmlnode_free(browse);
	return M_HANDLED;
}
Esempio n. 2
0
/* actually deliver the xdb request */
void xdb_deliver(instance i, xdbcache xc, int another_thread)
{
    xmlnode x;
    char ids[15];

    x = xmlnode_new_tag("xdb");

    if(xc->set)
    {
        xmlnode_put_attrib(x,"type","set");
        xmlnode_insert_tag_node(x,xc->data); /* copy in the data */
        if(xc->act != NULL)
            xmlnode_put_attrib(x,"action",xc->act);
        if(xc->match != NULL)
            xmlnode_put_attrib(x,"match",xc->match);
    }
	else {
	  xmlnode_put_attrib(x,"type","get");
	}
    xmlnode_put_attrib(x,"to",jid_full(xc->owner));
    xmlnode_put_attrib(x,"from",i->id);
    xmlnode_put_attrib(x,"ns",xc->ns);
    sprintf(ids,"%d",xc->id);
    xmlnode_put_attrib(x,"id",ids); /* to track response */

	if (another_thread) {
	  xdb_resend cur = pmalloco(xmlnode_pool(x),sizeof(_xdb_resend));
	  cur->x = x;
	  cur->i = i;
	  mtq_send(NULL,NULL,resend_xdb,(void *)cur);
	}
	else {
	  deliver(dpacket_new(x), i);
	}
}
Esempio n. 3
0
File: jcr_xdb.c Progetto: bcy/muc
/**
 * A replacement for xdb_set
 * returns 0 if the set succeeded, 1 if not
*/
int xdb_set(void *noop, jid fn, char *ns, xmlnode x) {
  extern jcr_instance jcr;
  char buf[512];
  xmlnode n, s, xdb;
  int rc;

  n = xdb_get(noop, fn, NULL);

  if (n == NULL) {
    memset(buf, 0, 512);
    snprintf(buf, 511, "%s/%s.xml", jcr->spool_dir, fn->user);
    xdb = xmlnode_new_tag("xdb");
    if (ns != NULL)
      xmlnode_put_attrib(x, "xdbns", ns);
//  log_debug(JDBG, "node not found, creating %s", xmlnode2str(x));
    xmlnode_insert_node(xdb, x);
//  log_debug(JDBG, "\nwriting '%s'\n\n", xmlnode2str(xdb));
    rc = xmlnode2file(buf, xdb);
    xmlnode_free(xdb);
    return rc;
  } else {
    s = NULL;
//  log_debug(JDBG, "node found '%s'", xmlnode2str(n));
    if (ns == NULL) {
      s = xmlnode_get_tag(n, xmlnode_get_name(x));
    } else {
      memset(buf, 0, 512);
      snprintf(buf, 511, "%s?xdbns=%s", xmlnode_get_name(x), ns);
//    log_debug(JDBG, "search for '%s'", buf);
      s = xmlnode_get_tag(n, buf);
    }
//  log_debug(JDBG, "removing '%s'", xmlnode2str(s));
    xmlnode_hide(s);
    if (ns != NULL)
      xmlnode_put_attrib(x, "xdbns", ns);
    xmlnode_insert_tag_node(n, x);
  }
  snprintf(buf, 511, "%s/%s.xml", jcr->spool_dir, fn->user);
  rc = xmlnode2file(buf, n);
  xmlnode_free(n);
  log_debug(JDBG, "xdb_set: rc == %d", rc);
  return 0;
}
Esempio n. 4
0
File: xmlnode.c Progetto: bcy/muc
/* places copy of node and node's siblings in parent */
void xmlnode_insert_node(xmlnode parent, xmlnode node)
{
    if(node == NULL || parent == NULL)
        return;

    while(node != NULL)
    {
        switch(xmlnode_get_type(node))
        {
        case NTYPE_ATTRIB:
            xmlnode_put_attrib(parent, xmlnode_get_name(node), xmlnode_get_data(node));
            break;
        case NTYPE_TAG:
            xmlnode_insert_tag_node(parent, node);
            break;
        case NTYPE_CDATA:
            xmlnode_insert_cdata(parent, xmlnode_get_data(node), xmlnode_get_datasz(node));
        }
        node = xmlnode_get_nextsibling(node);
    }
}