Ejemplo n.º 1
0
/* Coprocess functionality */
void dnsrv_child_process_xstream_io(int type, xmlnode x, void* args)
{
     dns_io di = (dns_io)args;
     char*  hostname;
     char*  str = NULL;
     dns_resend_list iternode = NULL;

     if (type == XSTREAM_NODE)
     {
          /* Get the hostname out... */
          hostname = xmlnode_get_data(x);
          log_debug(ZONE, "dnsrv: Recv'd lookup request for %s", hostname);
          if (hostname != NULL)
          {
               /* For each entry in the svclist, try and resolve using
                  the specified service and resend it to the specified host */
               iternode = di->svclist;
               while (iternode != NULL)
               {
                    str = srv_lookup(x->p, iternode->service, hostname);
                    if (str != NULL)
                    {
                         log_debug(ZONE, "Resolved %s(%s): %s\tresend to:%s", hostname, iternode->service, str, iternode->host);
                         xmlnode_put_attrib(x, "ip", str);
                         xmlnode_put_attrib(x, "to", iternode->host);
                         break;
                    }
                    iternode = iternode->next;
               }
               str = xmlnode2str(x);
               write(di->out, str, strlen(str));
          }
     }
     xmlnode_free(x);
}
Ejemplo n.º 2
0
/* bounces packet for unknown users with the appropriate error */
void mt_unknown_bounce(void *arg)
{
    jpacket jp = (jpacket) arg;
    mti ti = (mti) jp->aux1;
    xmlnode reg;

    lowercase(jp->from->user);
    lowercase(jp->from->server);

    if ((reg = xdb_get(ti->xc,mt_xdb_id(jp->p,jp->from,jp->to->server),NS_REGISTER)) != NULL)
    {
        xmlnode p = xmlnode_new_tag("presence");
        xmlnode_put_attrib(p,"to",jid_full(jp->from));
        xmlnode_put_attrib(p,"from",jp->to->server);
        xmlnode_put_attrib(p,"type","probe");

        mt_deliver(ti,p);

        jutil_error(jp->x,TERROR_NOTFOUND);
        xmlnode_free(reg);
    }
    else
        jutil_error(jp->x,TERROR_REGISTER);

    mt_deliver(ti,jp->x);
}
Ejemplo n.º 3
0
/**
 * utility for making message stanzas
 *
 * @param type the type of the message (as a string!)
 * @param to the recipient of the message
 * @param subj the subject of the message (NULL for no subject element)
 * @param body the body of the message
 * @return the xmlnode containing the new message stanza
 */
xmlnode jutil_msgnew(char *type, char *to, char *subj, char *body)
{
	xmlnode msg;

	msg = xmlnode_new_tag("message");

	if (type != NULL) {
		xmlnode_put_attrib(msg, "type", type);
	}

	if (to != NULL) {
		xmlnode_put_attrib(msg, "to", to);
	}

	if (subj != NULL) {
		xmlnode_insert_cdata(xmlnode_insert_tag(msg, "subject"),
				     subj, strlen(subj));
	}

	if (body != NULL) {
		xmlnode_insert_cdata(xmlnode_insert_tag(msg, "body"), body,
				     strlen(body));
	}

	return msg;
}
Ejemplo n.º 4
0
int message_send_error(struct stream_s *stream,const char *from,
		const char *to,const char *body,int code,const char *str){
xmlnode msg;
xmlnode n;
char *s;

	msg=xmlnode_new_tag("message");
	if (from!=NULL)
		xmlnode_put_attrib(msg,"from",from);
	else{
		char *jid;
		jid=jid_my_registered();
		xmlnode_put_attrib(msg,"from",jid);
		g_free(jid);
	}
	xmlnode_put_attrib(msg,"to",to);
	xmlnode_put_attrib(msg,"type","error");
	s=g_strdup_printf("%03u",code);
	xmlnode_put_attrib(msg,"code",s);
	g_free(s);
	n=xmlnode_insert_tag(msg,"error");
	xmlnode_insert_cdata(n,str,-1);
	if (body){
		n=xmlnode_insert_tag(msg,"body");
		xmlnode_insert_cdata(n,body,-1);
	}
	stream_write(stream,msg);
	xmlnode_free(msg);
	return 0;
}
Ejemplo n.º 5
0
int presence_send_error(struct stream_s *stream,const char *from,const char *to,
				int code,const char *string){
xmlnode pres;
xmlnode error;
char *jid;
char *str;

	pres=xmlnode_new_tag("presence");
	jid=jid_my_registered();
	if (from!=NULL)
		xmlnode_put_attrib(pres,"from",from);
	else{
		char *jid;
		jid=jid_my_registered();
		xmlnode_put_attrib(pres,"from",jid);
		g_free(jid);
	}
	g_free(jid);
	xmlnode_put_attrib(pres,"to",to);
	xmlnode_put_attrib(pres,"type","error");
	error=xmlnode_insert_tag(pres,"error");
	if (code>0){
		str=g_strdup_printf("%03u",(unsigned)code);
		xmlnode_put_attrib(error,"code",str);
		g_free(str);
	}
	xmlnode_insert_cdata(error,string,-1);

	stream_write(stream,pres);
	xmlnode_free(pres);
	return 0;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
int message_send_subject(struct stream_s *stream,const char *from,
		const char *to,const char *subject,const char *message,time_t timestamp){
xmlnode msg;
xmlnode n;
struct tm *tm;
char buf[101];

	msg=xmlnode_new_tag("message");
	if (from!=NULL)
		xmlnode_put_attrib(msg,"from",from);
	else{
		char *jid;
		jid=jid_my_registered();
		xmlnode_put_attrib(msg,"from",jid);
		g_free(jid);
	}
	xmlnode_put_attrib(msg,"to",to);
	n=xmlnode_insert_tag(msg,"subject");
	xmlnode_insert_cdata(n,subject,-1);
	n=xmlnode_insert_tag(msg,"body");
	xmlnode_insert_cdata(n,message,-1);
	if (timestamp){
		n=xmlnode_insert_tag(msg,"x");
		xmlnode_put_attrib(n,"xmlns","jabber:x:delay");
		tm=gmtime(&timestamp);
		strftime(buf,100,"%Y%m%dT%H:%M:%S",tm);
		xmlnode_put_attrib(n,"stamp",buf);
		xmlnode_insert_cdata(n,"Delayed message",-1);
	}
	stream_write(stream,msg);
	xmlnode_free(msg);
	return 0;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
result base_to_deliver(instance id, dpacket p, void *arg)
{
	char *log_data = xmlnode_get_data(p->x);
	char *subject;
	xmlnode message;

	if (log_data == NULL)
		return r_ERR;

	message = xmlnode_new_tag("message");

	xmlnode_insert_cdata(xmlnode_insert_tag(message, "body"), log_data,
			     -1);
	subject =
	    spools(xmlnode_pool(message), "Log Packet from ",
		   xmlnode_get_attrib(p->x, "from"),
		   xmlnode_pool(message));
	xmlnode_insert_cdata(xmlnode_insert_tag(message, "thread"),
			     shahash(subject), -1);
	xmlnode_insert_cdata(xmlnode_insert_tag(message, "subject"),
			     subject, -1);
	xmlnode_put_attrib(message, "from",
			   xmlnode_get_attrib(p->x, "from"));
	xmlnode_put_attrib(message, "to", (char *) arg);

	deliver(dpacket_new(message), id);
	pool_free(p->p);

	return r_DONE;
}
Ejemplo n.º 10
0
void jutil_tofrom(xmlnode x)
{
    char *to, *from;

    to = xmlnode_get_attrib(x,"to");
    from = xmlnode_get_attrib(x,"from");
    xmlnode_put_attrib(x,"from",to);
    xmlnode_put_attrib(x,"to",from);
}
Ejemplo n.º 11
0
mreturn mod_roster_auto_in_s10n(mapi m, void *arg)
{
	xmlnode reply, x;

	log_debug("AUTO ROSTER");

	//in not s10n
	if (m->packet->type != JPACKET_S10N)
		return M_IGNORE;
	//if no to
	if (m->packet->to == NULL)
		return M_PASS;
	//if from me
	if (jid_cmpx(m->s->uid, m->packet->from, JID_USER | JID_SERVER) ==
	    0)
		return M_PASS;

	log_debug("handling incoming s10n");

	switch (jpacket_subtype(m->packet)) {
	case JPACKET__SUBSCRIBE:
		log_debug("SUBSCRIBE");
		reply =
		    jutil_presnew(JPACKET__SUBSCRIBED,
				  jid_full(m->packet->from), NULL);
		js_session_from(m->s, jpacket_new(reply));
		reply =
		    jutil_presnew(JPACKET__SUBSCRIBE,
				  jid_full(m->packet->from), NULL);
		js_session_from(m->s, jpacket_new(reply));
		break;
	case JPACKET__SUBSCRIBED:
		break;
	case JPACKET__UNSUBSCRIBE:
		log_debug("UNSUBSCRIBE");
		//reply = jutil_presnew(JPACKET__UNSUBSCRIBED, jid_full(m->packet->from),NULL);
		//js_session_from(m->s, jpacket_new(reply));
		//remove account.
		reply = jutil_iqnew(JPACKET__SET, NS_ROSTER);
		x = xmlnode_get_tag(reply, "query");
		x = xmlnode_insert_tag(x, "item");
		xmlnode_put_attrib(x, "jid",
				   jid_full(jid_user(m->packet->from)));
		xmlnode_put_attrib(x, "subscription", "remove");
		js_session_from(m->s, jpacket_new(reply));

		// reply = jutil_iqnewpresnew(JPACKET__UNSUBSCRIBE, jid_full(m->packet->from),NULL);
		// js_session_from(m->s, jpacket_new(reply));
		break;
	case JPACKET__UNSUBSCRIBED:
		break;
	}

	xmlnode_free(m->packet->x);
	return M_HANDLED;
}
Ejemplo n.º 12
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);
}
Ejemplo n.º 13
0
/*
 * creates a new jabber:x:data result form
 * returns the node created added
 */
xmlnode form_new_result(const char *title){
xmlnode form,tag;

	form=xmlnode_new_tag("x");
	xmlnode_put_attrib(form,"xmlns","jabber:x:data");
	xmlnode_put_attrib(form,"type","result");
	tag=xmlnode_insert_tag(form,"title");
	xmlnode_insert_cdata(tag,title,-1);
	return form;
}
Ejemplo n.º 14
0
void jutil_delay(xmlnode msg, char *reason)
{
    xmlnode delay;

    delay = xmlnode_insert_tag(msg,"x");
    xmlnode_put_attrib(delay,"xmlns",NS_DELAY);
    xmlnode_put_attrib(delay,"from",xmlnode_get_attrib(msg,"to"));
    xmlnode_put_attrib(delay,"stamp",jutil_timestamp());
    if(reason != NULL)
        xmlnode_insert_cdata(delay,reason,strlen(reason));
}
Ejemplo n.º 15
0
Archivo: ns.c Proyecto: Doap/transports
void mt_ns_msg(mpacket mp, session s)
{
    xmlnode msg, oob;
    char *body, *ctype, *ptr;
    /* message body spool*/
    pool p = pool_new();
    spool sp = spool_new(p);      

    if (s->ti->inbox_headlines == 0)
        return;

    ctype = strchr(mt_packet_data(mp,5),':') + 2;
    body = mt_packet_data(mp,mp->count - 1);

    /* this message is a Hotmail inbox notification */
    if ((strncmp(ctype,"text/x-msmsgsinitialemailnotification",37) != 0) &&
        (strncmp(ctype,"text/x-msmsgsemailnotification",30) != 0))
        return;
   
    /* Fede <*****@*****.**> */
    /* cut off the junk at the end */
    if ((ptr = strstr(body,"Inbox-URL")) != NULL) {
       *ptr = '\0';
       spool_add(sp,body);   
    } else {       
       if ((ptr = strstr(body,"From:")) != NULL) {
          char *p = strchr(ptr, '\r');	  
	  *p = '\0';
	  spooler(sp,"Mail from: ", ptr + 6,sp);
	  body = p + 1;
       }
       if ((ptr = strstr(body,"From-Addr:")) != NULL) {
          *strchr(ptr, '\r') = '\0';
	  spooler(sp," <",ptr + 11,">",sp);
       }       
    }
    
    msg = xmlnode_new_tag("message");
    xmlnode_put_attrib(msg,"to",jid_full(s->id));
    xmlnode_put_attrib(msg,"from",s->host);
    xmlnode_put_attrib(msg,"type","headline");

    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"subject"),"Hotmail",-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),spool_print(sp),-1);

    oob = xmlnode_insert_tag(msg,"x");
    xmlnode_put_attrib(oob,"xmlns","jabber:x:oob");
    xmlnode_insert_cdata(xmlnode_insert_tag(oob,"url"),"http://www.hotmail.com/cgi-bin/folders",-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(oob,"desc"),"Login to your Hotmail e-mail account",-1);

    mt_deliver(s->ti,msg);
   
    pool_free(p);
}
Ejemplo n.º 16
0
/* util for making stream packets */
xmlnode jutil_header(char* xmlns, char* server)
{
     xmlnode result;
     if ((xmlns == NULL)||(server == NULL))
	  return NULL;
     result = xmlnode_new_tag("stream:stream");
     xmlnode_put_attrib(result, "xmlns:stream", "http://etherx.jabber.org/streams");
     xmlnode_put_attrib(result, "xmlns", xmlns);
     xmlnode_put_attrib(result, "to", server);

     return result;
}
Ejemplo n.º 17
0
int at_iq_gateway(ati ti, jpacket jp)
{
    if(jp->to->user != NULL)
    {
        at_bounce(ti, jp, TERROR_NOTALLOWED);
        return 1;
    }

    
    switch(jpacket_subtype(jp))
    {
        case JPACKET__GET:
        {
            xmlnode q;

            jutil_iqresult(jp->x);

            q = xmlnode_insert_tag(jp->x,"query");
            xmlnode_put_attrib(q,"xmlns",NS_GATEWAY);
            xmlnode_insert_cdata(xmlnode_insert_tag(q,"desc"),"Enter the user's screenname",-1);
            xmlnode_insert_tag(q,"prompt");

            break;
        }

        case JPACKET__SET:
        {
            char *user, *id;
    
            user = xmlnode_get_tag_data(jp->iq,"prompt");
            id = user ? spools(jp->p,at_normalize(user),"@",jp->to->server,jp->p) : NULL;
            if (id)
            {
                xmlnode q;

                jutil_iqresult(jp->x);
        
                q = xmlnode_insert_tag(jp->x,"query");
                xmlnode_put_attrib(q,"xmlns",NS_GATEWAY);
                xmlnode_insert_cdata(xmlnode_insert_tag(q,"prompt"),id,-1);
            }
            else
                jutil_error(jp->x,TERROR_BAD);
            break;
        }
        default:
            jutil_error(jp->x,TERROR_BAD);
            break;
    }
    
    at_deliver(ti,jp->x);
    return 1;
}
Ejemplo n.º 18
0
void dnsrv_resend(xmlnode pkt, char *ip, char *to)
{
    if(ip != NULL)
    {
         pkt = xmlnode_wrap(pkt,"route");
         xmlnode_put_attrib(pkt, "to", to);
         xmlnode_put_attrib(pkt, "ip", ip);
    }else{
         jutil_error(pkt, (terror){502, "Unable to resolve hostname."});
         xmlnode_put_attrib(pkt, "iperror", "");
    }
    deliver(dpacket_new(pkt),NULL);
}
Ejemplo n.º 19
0
/* util for making message receipt packets */
xmlnode jutil_receiptnew(const char *to, const char *id)
{
    xmlnode msg;

    msg = xmlnode_new_tag("message");
    xmlnode_put_attrib (msg, "to", to);
	if(id != NULL)
		xmlnode_put_attrib (msg, "id", id);

    xmlnode_put_attrib(xmlnode_insert_tag (msg, "received"), "xmlns", "urn:xmpp:receipts");

    return msg;
}
Ejemplo n.º 20
0
int at_iq_last(ati ti, jpacket jp)
{
    xmlnode last;
    xmlnode q;
    char str[10];

    /* XXX I can do last if I track logouts in the XDB... not too hard */
    if(jpacket_subtype(jp) != JPACKET__GET)
    {
        at_bounce(ti, jp, TERROR_BAD);
        return 1;
    }

    if(jp->to->user != NULL)
    {
        at_session s;
        at_buddy buddy;
        char *res;

        s = at_session_find_by_jid(ti, jp->from);
        if(s == NULL)
        {
            at_bounce(ti, jp, TERROR_REGISTER);
            return 1;
        }
        buddy = xhash_get(s->buddies, jp->to->user);
        if(buddy == NULL)
        {
            at_bounce(ti, jp, TERROR_BAD);
            return 1;
        }
         
        jutil_iqresult(jp->x);
        last = xmlnode_insert_tag(jp->x, "query");
        xmlnode_put_attrib(last,"xmlns",NS_LAST);
        sprintf(str, "%d", buddy->idle_time);
        xmlnode_put_attrib(last, "seconds", str);
        at_deliver(ti,jp->x);

        return 1;
    }

    jutil_iqresult(jp->x);
    last = xmlnode_insert_tag(jp->x, "query");
    xmlnode_put_attrib(last,"xmlns",NS_LAST);
    sprintf(str, "%d", time(NULL) - ti->start_time);
    xmlnode_put_attrib(last,"seconds", str);
    at_deliver(ti,jp->x);

    return 1;
}
Ejemplo n.º 21
0
/*
 * adds a field declaration to a jabber:x:data report
 * returns the field added
 */
xmlnode form_add_result_field(xmlnode form,const char *var,const char *label,const char *type){
xmlnode rep,field;

	rep=xmlnode_get_tag(form,"reported");
	if (rep==NULL){
		rep=xmlnode_insert_tag(form,"reported");
	}
	field=xmlnode_insert_tag(rep,"field");
	xmlnode_put_attrib(field,"var",var);
	xmlnode_put_attrib(field,"label",label);
	if (type!=NULL)
		xmlnode_put_attrib(field,"type",type);
	return field;
}
Ejemplo n.º 22
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);
	}
}
Ejemplo n.º 23
0
void con_room_leaveall(gpointer key, gpointer data, gpointer arg)
{
  cnu user = (cnu)data;
  xmlnode info = (xmlnode)arg;
  char *alt, *reason;
  xmlnode presence;
  xmlnode tag;
  xmlnode element;
  xmlnode node;
  xmlnode destroy;

  log_debug(NAME, "[%s] reason :  %s", FZONE, xmlnode2str(info));
  if(user == NULL) 
  {
    log_warn(NAME, "[%s] Aborting - NULL user attribute found", FZONE);
    return;
  }
  
  if (user->remote == 1)
    return;

  presence = jutil_presnew(JPACKET__UNAVAILABLE, NULL, NULL);
  tag = xmlnode_insert_tag(presence,"x");
  xmlnode_put_attrib(tag, "xmlns", NS_MUC_USER);

  element = xmlnode_insert_tag(tag, "item");
  xmlnode_put_attrib(element, "role", "none");
  xmlnode_put_attrib(element, "affiliation", "none");

  if (info != NULL)
  {
    destroy = xmlnode_insert_tag(tag, "destroy");
    reason = xmlnode_get_tag_data(info, "reason");
    node = xmlnode_insert_tag(destroy, "reason");

    if(reason != NULL)
    {
      xmlnode_insert_cdata(node, reason, -1);
    }

    alt = xmlnode_get_attrib(info, "jid");

    if (alt != NULL)
    {
      xmlnode_put_attrib(destroy, "jid", alt);
    }
  }

  con_user_send(user, user, presence);
}
Ejemplo n.º 24
0
/* delivers a route packet to all listeners for this session */
static void js_session_route(session s, xmlnode in)
{
	/* NULL means this is an error from the session ending */
	if (in == NULL) {
		in = xmlnode_new_tag("route");
		xmlnode_put_attrib(in, "type", "error");
		xmlnode_put_attrib(in, "error", "Disconnected");
	} else {
		in = xmlnode_wrap(in, "route");
	}

	xmlnode_put_attrib(in, "from", jid_full(s->route));
	xmlnode_put_attrib(in, "to", jid_full(s->sid));
	deliver(dpacket_new(in), s->si->i);
}
Ejemplo n.º 25
0
void jutil_error(xmlnode x, terror E)
{
    xmlnode err;
    char code[4];

    xmlnode_put_attrib(x,"type","error");
    err = xmlnode_insert_tag(x,"error");

    snprintf(code,4,"%d",E.code);
    xmlnode_put_attrib(err,"code",code);
    if(E.msg != NULL)
        xmlnode_insert_cdata(err,E.msg,strlen(E.msg));

    jutil_tofrom(x);
}
Ejemplo n.º 26
0
/*
 * adds a field to a jabber:x:data form
 * returns the field added
 */
xmlnode form_add_field(xmlnode form,const char *type,const char *var,
				const char *label,const char *val,int required){
xmlnode field,value;

	field=xmlnode_insert_tag(form,"field");
	xmlnode_put_attrib(field,"type",type);
	xmlnode_put_attrib(field,"var",var);
	if (required) xmlnode_insert_tag(field,"required");
	xmlnode_put_attrib(field,"label",label);
	if (val){
		value=xmlnode_insert_tag(field,"value");
		xmlnode_insert_cdata(value,val,-1);
	}
	return field;
}
Ejemplo n.º 27
0
int at_auth_user(ati ti, jpacket jp)
{
	char *name;
	char *pass;
    xmlnode res;
	at_session s;
    xmlnode x;

    /* get login data */
    x = at_xdb_get(ti, jp->from, AT_NS_AUTH);
    if(x == NULL)
    {
      /* convert pre-2003 (hashed) XDB files */
      at_xdb_convert(ti, xmlnode_get_attrib(jp->x,"origfrom"), jp->from);
      x = at_xdb_get(ti, jp->from, AT_NS_AUTH);
    }

    if(x == NULL)
    {
      xmlnode err, m;

      log_warn(ZONE, "[AT] No auth data for %s found", jid_full(jp->from));

      m = xmlnode_new_tag("message");

      xmlnode_put_attrib(m, "type", "error");
      xmlnode_put_attrib(m, "from", jid_full(jp->to));
      xmlnode_put_attrib(m, "to", jid_full(jp->from));

      err = xmlnode_insert_tag(m, "error");
      xmlnode_put_attrib(err, "code", "407");
      xmlnode_insert_cdata(err, "No logon data found", -1);

      at_deliver(ti,m);
      xmlnode_free(jp->x);

      return 1;
    }

    log_debug(ZONE,"[AT] logging in session");
    at_session_create(ti, x, jp);

    xmlnode_free(x);
    xmlnode_free(jp->x);

    return 1;

}
Ejemplo n.º 28
0
void con_room_forward_decline(cnr room, jpacket jp, xmlnode decline)
{
  cnu user;
  jid user_jid;
  if (room == NULL || decline == NULL || jp == NULL)
  {
    log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE);
    xmlnode_free(jp->x);
    return;
  }
  user_jid=jid_new(decline->p,xmlnode_get_attrib(decline,"to"));
  if ((room->invitation == 1 && !is_member(room, jp->from) && !is_owner(room, jp->from)) || user_jid == NULL)
  {
    log_warn(NAME, "[%s] Aborting - User is not allowed to send a decline", FZONE);
    jutil_error(jp->x, TERROR_MUC_OUTSIDE);
    deliver(dpacket_new(jp->x), NULL);
    return;
  }
  if (user_jid->resource == NULL) {
    log_warn(NAME, "[%s] Aborting - cannot send back decline, bare jid found", FZONE);
    return;
  }
  if (room->visible == 1)
  {
    user = g_hash_table_lookup(room->remote, jid_full(jid_fix(user_jid)));
  }
  else
  {
    user = g_hash_table_lookup(room->local, user_jid->resource);
  }

  if (user == NULL){
    log_warn(NAME, "[%s] Aborting - Decline recipient is not in the room", FZONE);
    jutil_error(jp->x, TERROR_MUC_OUTSIDE);
    deliver(dpacket_new(jp->x), NULL);
    return;
  }
  log_debug(NAME, "[%s] Sending invitation decline", FZONE);
  xmlnode_put_attrib(decline, "from", jid_full(jp->from));
  xmlnode_hide_attrib(decline, "to");
  xmlnode_put_attrib(jp->x, "to", jid_full(user->realid));
  xmlnode_put_attrib(jp->x, "from", jid_full(room->id));

  log_debug(NAME, "[%s] >>>%s<<<", FZONE, xmlnode2str(jp->x));

  deliver(dpacket_new(jp->x), NULL);
  return;
}
Ejemplo n.º 29
0
/* 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;
}
Ejemplo n.º 30
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);
}