Beispiel #1
0
Datei: xmlnode.c Projekt: bcy/muc
xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node)
{
    xmlnode child;

    child = xmlnode_insert_tag(parent, xmlnode_get_name(node));
    if (xmlnode_has_attribs(node))
        xmlnode_insert_node(child, xmlnode_get_firstattrib(node));
    if (xmlnode_has_children(node))
        xmlnode_insert_node(child, xmlnode_get_firstchild(node));

    return child;
}
Beispiel #2
0
void aim_transport(instance i, xmlnode x)
{
    ati ti;
    xmlnode config;
	char *eightbitcode, *utf8code = "UTF-8", *latin1code = "CP1252";
    
    ti = pmalloco(i->p, sizeof(_ati));

    ti->i = i;
    ti->xc = xdb_cache(i);
    log_notice(i->id, "AIM-Transport starting up for instance %s...", i->id);
    
    config = xdb_get(ti->xc, jid_new(xmlnode_pool(x), "config@-internal"), "jabber:config:aimtrans");
    
    ti->vcard = xmlnode_new_tag_pool(i->p,"vCard");
    xmlnode_put_attrib(ti->vcard,"xmlns",NS_VCARD);
    xmlnode_insert_node(ti->vcard,xmlnode_get_firstchild(xmlnode_get_tag(config,"vCard")));

    ti->start_time = time(NULL);
    

    ti->session__list=xhash_new(101);
    ti->iq__callbacks = xhash_new(23);
    ti->pending__buddies = xhash_new(101);

    /* The aim.exe binary should not be necessary any more. */
    ti->aimbinarydir = pstrdup(i->p, xmlnode_get_tag_data(config, "aimbinarydir"));

	eightbitcode = pstrdup(i->p, xmlnode_get_tag_data(config, "charset"));
	if( eightbitcode == NULL )
	{
		log_notice( i->id, "Charset is not specified, using CP1252" );
		eightbitcode = latin1code;
	}

    xmlnode_free(config);

	fromutf8 = iconv_open(eightbitcode, utf8code);
	if(fromutf8 == (iconv_t)(-1))
	{
		log_error(i->id, "Conversion from %s to %s is not supported", utf8code, eightbitcode);
		raise(SIGINT);
	}
	toutf8 = iconv_open(utf8code, eightbitcode);
	if(toutf8 == (iconv_t)(-1))
	{
		log_error(i->id, "Conversion from %s to %s is not supported", eightbitcode, utf8code);
		raise(SIGINT);
	}

    ti->send_buf = NULL;
    ti->modname = NULL;

    pth_mutex_init(&ti->buddies_mutex);

    at_init_iqcbs(ti);

    register_phandler(i, o_DELIVER, at_phandler, ti);
    pool_cleanup(i->p, at_shutdown, (void*)i);
}
Beispiel #3
0
Datei: xmlnode.c Projekt: bcy/muc
xmlnode xmlnode_dup_pool(pool p, xmlnode x)
{
    xmlnode x2;

    if(x == NULL)
        return NULL;

    x2 = xmlnode_new_tag_pool(p, xmlnode_get_name(x));

    if (xmlnode_has_attribs(x))
        xmlnode_insert_node(x2, xmlnode_get_firstattrib(x));
    if (xmlnode_has_children(x))
        xmlnode_insert_node(x2, xmlnode_get_firstchild(x));

    return x2;
}
Beispiel #4
0
int at_iq_vcard(ati ti, jpacket jp)
{
    xmlnode data;
    at_session s;

    s = at_session_find_by_jid(ti, jp->from);

    if(jpacket_subtype(jp) != JPACKET__GET ||
      (s && ((!s->icq && jp->to->user) || (s->icq && s->icq_vcard_response))))
    {
        at_bounce(ti, jp, TERROR_BAD);
        return 1;
    }

    if(!jp->to->user)
    {
        xmlnode_insert_node(jutil_iqresult(jp->x),ti->vcard);
        at_deliver(ti,jp->x);
        return 1;
    }

    if(!s)
        return 0;

    jutil_iqresult(jp->x);
    jp->iq = data = xmlnode_insert_tag(jp->x,"vCard");
    xmlnode_put_attrib(data,"xmlns",NS_VCARD);
    xmlnode_put_attrib(data,"version","3.0");
    xmlnode_put_attrib(data,"prodid","-//HandGen//NONSGML vGen v1.0//EN");
    s->icq_vcard_response = jp;

    aim_icq_getsimpleinfo(s->ass,
                          jp->to->user);
    return 1;
}
Beispiel #5
0
mreturn mod_browse_server(mapi m, void *arg)
{
	xmlnode browse, query, x;

	if (m->packet->type != JPACKET_IQ)
		return M_IGNORE;
	if (jpacket_subtype(m->packet) != JPACKET__GET
	    || !NSCHECK(m->packet->iq, NS_BROWSE)
	    || m->packet->to->resource != NULL)
		return M_PASS;

	/* get data from the config file */
	if ((browse = js_config(m->si, "browse")) == NULL)
		return M_PASS;

	log_debug("handling browse query");

	/* build the result IQ */
	query =
	    xmlnode_insert_tag(jutil_iqresult(m->packet->x), "service");
	xmlnode_put_attrib(query, "xmlns", NS_BROWSE);
	xmlnode_put_attrib(query, "type", "jabber");
	xmlnode_put_attrib(query, "jid", m->packet->to->server);
	xmlnode_put_attrib(query, "name", xmlnode_get_data(js_config(m->si, "vCard/FN")));	/* pull name from the server vCard */

	/* copy in the configured services */
	xmlnode_insert_node(query, xmlnode_get_firstchild(browse));

	/* list the admin stuff */
	if (js_admin_jid(m->si, jid_user(m->packet->from), ADMIN_READ)) {
		x = xmlnode_insert_tag(query, "item");
		xmlnode_put_attrib(x, "jid",
				   spools(xmlnode_pool(x),
					  m->packet->to->server, "/admin",
					  xmlnode_pool(x)));
		xmlnode_put_attrib(x, "name", "Online Users");
		xmlnode_insert_cdata(xmlnode_insert_tag(query, "ns"),
				     NS_ADMIN, -1);
	}

	jpacket_reset(m->packet);
	js_deliver(m->si, m->packet);

	return M_HANDLED;
}
Beispiel #6
0
Datei: jcr_xdb.c Projekt: 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;
}
Beispiel #7
0
/** Start up transport. Read configuration, register callbacks. */
void icqtrans(instance i, xmlnode x)
{
    iti ti;
    pool p = i->p;
    xmlnode config;
    xmlnode cur;
	int check;

    log_debug(ZONE,"ICQ Transport, initializing for section '%s'",i->id);

    /* create new transport instance */
    ti = pmalloco(p,sizeof(_iti));
    ti->i = i;
    ti->xc = xdb_cache(i);

    config = xdb_get(ti->xc,jid_new(xmlnode_pool(x),"config@-internal"),"jabber:config:icqtrans");
    if (config == NULL)
    {
        log_error(i->id,"Configuration not found!");
        return;
    }

    ti->registration_instructions = pstrdup(p,xmlnode_get_tag_data(config,"instructions"));
    if (ti->registration_instructions == NULL)
    { 
        log_debug(i->id,"Registration instructions not found");
    }

    ti->search_instructions = pstrdup(p,xmlnode_get_tag_data(config,"search"));
    if (ti->search_instructions == NULL)
    {
        log_debug(i->id,"Search instructions not found");
    }

    ti->charset = pstrdup(p,xmlnode_get_tag_data(config,"charset"));
    if (ti->charset == NULL)
    {
	  log_debug(i->id,"Charset not specified, set default to %s ",DEFAULT_CHARSET);
	  ti->charset = pstrdup(p,DEFAULT_CHARSET);
    }

    _ucs2utf = iconv_open("UTF-8","UCS-2BE");

    _win2utf = iconv_open("UTF-8",ti->charset);
    if (_win2utf==(iconv_t)-1) {
      ti->charset = pstrdup(p,DEFAULT_CHARSET);
      _win2utf = iconv_open("UTF-8",ti->charset);
      if (_win2utf==(iconv_t)-1) {
        log_error(i->id,"Charset error!");
        return;
      }
    }

    _utf2win = iconv_open(ti->charset,"UTF-8");
    if (_utf2win ==(iconv_t)-1) {
      ti->charset = pstrdup(p,DEFAULT_CHARSET);
      _utf2win = iconv_open(ti->charset,"UTF-8");
      if (_utf2win ==(iconv_t)-1) {
        log_error(i->id,"Charset error!");
        return;
      }
    }

	log_notice("config","charset %s",ti->charset);
	
    ti->msg_chat = xmlnode_get_tag(config,"chat") ? 1 : 0;
	if (ti->msg_chat) {
	  log_notice("config","chat messages enabled");
	}
    ti->web_aware = xmlnode_get_tag(config,"web") ? 1 : 0;
	if (ti->web_aware) {
	  log_notice("config","web presence enabled");
	}
    ti->own_roster = xmlnode_get_tag(config,"own_roster") ? 1 : 0;
	if (ti->own_roster) {
	  log_notice("config","JIT will use own roster");
	}
    ti->no_jabber_roster = xmlnode_get_tag(config,"no_jabber_roster") ? 1 : 0;
	if (ti->no_jabber_roster) {
	  log_notice("config","JIT willn't get users from jabber roster");
	}
	ti->no_x_data = xmlnode_get_tag(config,"no_xdata") ? 1 : 0;
	if (ti->no_x_data) {
	  log_notice("config","JIT will not use xdata");
	}

    cur = xmlnode_get_tag(config,"sms");

    if (cur) {
      ti->sms_id = pstrdup(p,xmlnode_get_tag_data(cur,"host"));
      if (ti->sms_id) {
        ti->sms_show = jit_show2status(xmlnode_get_tag_data(cur,"show"));

        if (ti->sms_show==ICQ_STATUS_NOT_IN_LIST) {
          ti->sms_show = ICQ_STATUS_ONLINE;
        }
        
        log_notice("config","sms host %s show: %d",ti->sms_id,ti->sms_show);

        ti->sms_status = pstrdup(p,xmlnode_get_tag_data(cur,"status"));

        if (ti->sms_status) {
          log_debug(ZONE,"sms st %s ",ti->sms_status);
        }

        ti->sms_name = pstrdup(p,xmlnode_get_tag_data(cur,"name"));

	if (ti->sms_name) {
	  log_debug(ZONE,"sms name %s",ti->sms_name);
	}
      }
    }

    ti->count_file = pstrdup(p,xmlnode_get_tag_data(config,"user_count_file"));
    if (ti->count_file == NULL)  {
      ti->count_file = "icqcount";
    }

	log_notice("config","Using %s as count log file",ti->count_file);

    for (cur = xmlnode_get_firstchild(xmlnode_get_tag(config,"server"));
     cur != NULL;
     cur = xmlnode_get_nextsibling(cur)) {

      char * port;
      char * host;

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

      if ((port = xmlnode_get_attrib(cur,"port")) == NULL) continue;
   
      if ((host = xmlnode_get_data(cur)) == NULL) continue;

      ti->auth_hosts[ti->auth_hosts_count] = pstrdup(p,host);
      ti->auth_ports[ti->auth_hosts_count] = j_atoi(port,5190);
      log_debug(ZONE,"Host %s port %d at pos %d",
				ti->auth_hosts[ti->auth_hosts_count],
				ti->auth_ports[ti->auth_hosts_count],
				ti->auth_hosts_count);
      ti->auth_hosts_count++;

      if (ti->auth_hosts_count >= MAX_AUTH_HOSTS) break;
    }

    if (ti->auth_hosts_count == 0) {
      log_alert("err","No hosts to auth icq client !. Using default");
      ti->auth_hosts[ti->auth_hosts_count] = pstrdup(p,"205.188.179.233");
      ti->auth_ports[ti->auth_hosts_count] = 5190;
      ti->auth_hosts_count++;
    }

	/* add queue for unknown packets */
	ti->q = mtq_new(i->p);

    ti->sessions = wpxhash_new(j_atoi(xmlnode_get_tag_data(config,"prime"),509));
    ti->sessions_alt = wpxhash_new(j_atoi(xmlnode_get_tag_data(config,"prime"),509));
    SEM_INIT(ti->sessions_sem);
    ti->vcard = xmlnode_new_tag_pool(p,"vCard");

    xmlnode_put_attrib(ti->vcard,"xmlns",NS_VCARD);
    xmlnode_insert_node(ti->vcard,xmlnode_get_firstchild(xmlnode_get_tag(config,"vCard")));

    /* default 5 hours */
    ti->session_timeout = j_atoi(xmlnode_get_tag_data(config,"session_timeout"),18000);
	log_notice("config","session_timeout in sec : %d",ti->session_timeout);

    ti->reconnect = j_atoi(xmlnode_get_tag_data(config,"reconnects"),0);
    log_notice("config","Number of reconnects for session %d",ti->reconnect);

	check = j_atoi(xmlnode_get_tag_data(config,"session_check"),10);
    log_notice("config","JIT will check session every %d sec",check);
      
	//    ti->admin = xmlnode_dup(xmlnode_get_tag(config,"admin"));
    ti->start = time(NULL);

    /* Register callbacks */
    register_phandler(i,o_DELIVER,it_receive,(void *) ti);
    register_shutdown(it_shutdown,(void *) ti);

    /* Start up heartbeat thread */
    register_beat(check,it_sessions_check,(void *) ti);

    xmlnode_free(config);
}
Beispiel #8
0
void con_room_send_invite(cnu sender, xmlnode node)
{
  xmlnode result;
  xmlnode element;
  xmlnode invite;
  xmlnode pass;
  char *body, *user, *reason, *inviter;
  cnr room;
  pool p;

  if(sender == NULL || node == NULL) 
  {
    log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE);
    return;
  }

  log_debug(NAME, "[%s] Sending room invite", FZONE);

  room = sender->room;

  invite = xmlnode_get_tag(node, "invite");
  user = xmlnode_get_attrib(invite, "to");
  reason = xmlnode_get_tag_data(invite, "reason");

  p = xmlnode_pool(node);

  if(room->visible == 1)
  {
    inviter = jid_full(sender->realid);
  }
  else
  {
    inviter = jid_full(sender->localid);
  }

  xmlnode_put_attrib(invite, "from", inviter);
  xmlnode_hide_attrib(invite, "to");

  if(reason == NULL)
  {
    reason = spools(p, "None given", p);
  }

  body = spools(p, "You have been invited to the ", jid_full(room->id), " room by ", inviter, "\nReason: ", reason, p);

  result = jutil_msgnew("normal", user , "Invitation", body);
  xmlnode_put_attrib(result, "from", jid_full(room->id));

  xmlnode_insert_node(result, node);

  if(room->secret != NULL)
  {
    pass = xmlnode_get_tag(result, "x");
    xmlnode_insert_cdata(xmlnode_insert_tag(pass, "password"), room->secret, -1);
  }

  element = xmlnode_insert_tag(result, "x");
  xmlnode_put_attrib(element, "jid", jid_full(room->id));
  xmlnode_put_attrib(element, "xmlns", NS_X_CONFERENCE);
  xmlnode_insert_cdata(element, reason, -1);

  log_debug(NAME, "[%s] >>>%s<<<", FZONE, xmlnode2str(result));

  deliver(dpacket_new(result), NULL);
  return;

}
Beispiel #9
0
mreturn mod_browse_set(mapi m, void *arg)
{
	xmlnode browse, cur;
	jid id, to;

	if (m->packet->type != JPACKET_IQ)
		return M_IGNORE;
	if (!NSCHECK(m->packet->iq, NS_BROWSE)
	    || jpacket_subtype(m->packet) != JPACKET__SET)
		return M_PASS;
	if (m->packet->to != NULL)
		return M_PASS;	/* if its to someone other than ourselves */

	log_debug("handling set request %s", xmlnode2str(m->packet->iq));

	/* no to implies to ourselves */
	if (m->packet->to != NULL)
		to = m->packet->to;
	else
		to = m->user->id;

	/* if we set to a resource, we need to make sure that resource's browse is in the users browse */
	if (to->resource != NULL) {
		browse = mod_browse_get(m, to);	/* get our browse info */
		xmlnode_hide_attrib(browse, "xmlns");	/* don't need a ns as a child */
		for (cur = xmlnode_get_firstchild(browse); cur != NULL;
		     cur = xmlnode_get_nextsibling(cur))
			xmlnode_hide(cur);	/* erase all children */
		xdb_act(m->si->xc, m->user->id, NS_BROWSE, "insert", spools(m->packet->p, "?jid=", jid_full(to), m->packet->p), browse);	/* insert and match replace */
		xmlnode_free(browse);
	}

	/* get the id of the new browse item */
	if ((cur = xmlnode_get_firstchild(m->packet->iq)) == NULL
	    || (id =
		jid_new(m->packet->p,
			xmlnode_get_attrib(cur, "jid"))) == NULL) {
		js_bounce(m->si, m->packet->x, TERROR_NOTACCEPTABLE);
		return M_HANDLED;
	}

	/* insert the new item into the resource it was sent to */
	xmlnode_hide_attrib(cur, "xmlns");	/* just in case, to make sure it inserts */
	if (xdb_act
	    (m->si->xc, to, NS_BROWSE, "insert",
	     spools(m->packet->p, "?jid=", jid_full(id), m->packet->p),
	     cur)) {
		js_bounce(m->si, m->packet->x, TERROR_UNAVAIL);
		return M_HANDLED;
	}

	/* if the new data we're inserting is to one of our resources, update that resource's browse */
	if (jid_cmpx(m->user->id, id, JID_USER | JID_SERVER) == 0
	    && id->resource != NULL) {
		/* get the old */
		browse = mod_browse_get(m, id);
		/* transform the new one into the old one */
		xmlnode_put_attrib(cur, "xmlns", NS_BROWSE);
		xmlnode_insert_node(cur, xmlnode_get_firstchild(browse));
		xdb_set(m->si->xc, id, NS_BROWSE, cur);	/* replace the resource's browse w/ this one */
		xmlnode_free(browse);
	}

	/* send response to the user */
	jutil_iqresult(m->packet->x);
	jpacket_reset(m->packet);
	js_session_to(m->s, m->packet);

	return M_HANDLED;
}