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; }
/** * 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; }
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; }
/* util for making presence packets */ xmlnode jutil_presnew(int type, char *to, char *status) { xmlnode pres; pres = xmlnode_new_tag("presence"); switch(type) { case JPACKET__SUBSCRIBE: xmlnode_put_attrib(pres,"type","subscribe"); break; case JPACKET__UNSUBSCRIBE: xmlnode_put_attrib(pres,"type","unsubscribe"); break; case JPACKET__SUBSCRIBED: xmlnode_put_attrib(pres,"type","subscribed"); break; case JPACKET__UNSUBSCRIBED: xmlnode_put_attrib(pres,"type","unsubscribed"); break; case JPACKET__PROBE: xmlnode_put_attrib(pres,"type","probe"); break; case JPACKET__UNAVAILABLE: xmlnode_put_attrib(pres,"type","unavailable"); break; } if(to != NULL) xmlnode_put_attrib(pres,"to",to); if(status != NULL) xmlnode_insert_cdata(xmlnode_insert_tag(pres,"status"),status,strlen(status)); return pres; }
/* 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); } }
/* 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); }
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(×tamp); 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; }
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; }
/* * 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; }
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); }
/* 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; }
/* 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; }
xmlnode mod_browse_get(mapi m, jid id) { xmlnode browse, x; if (id == NULL) /* use the user id as a backup */ id = m->user->id; /* get main account browse */ if ((browse = xdb_get(m->si->xc, id, NS_BROWSE)) == NULL) { /* no browse is set up yet, we must create one for this user! */ if (id->resource == NULL) { /* a user is only the user@host */ browse = xmlnode_new_tag("user"); /* get the friendly name for this user from somewhere */ if ((x = xdb_get(m->si->xc, m->user->id, NS_VCARD)) != NULL) xmlnode_put_attrib(browse, "name", xmlnode_get_tag_data(x, "FN")); else if ((x = xdb_get(m->si->xc, m->user->id, NS_REGISTER)) != NULL) xmlnode_put_attrib(browse, "name", xmlnode_get_tag_data(x, "name")); xmlnode_free(x); } else { /* everything else is generic unless set by the user */ browse = xmlnode_new_tag("item"); } xmlnode_put_attrib(browse, "xmlns", NS_BROWSE); xmlnode_put_attrib(browse, "jid", jid_full(id)); xdb_set(m->si->xc, id, NS_BROWSE, browse); } return browse; }
/* 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); }
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; }
/* * creates a new jabber:x:data form * returns the node created added */ xmlnode form_new(xmlnode parent,const char *title,const char *instructions){ xmlnode form,tag; if (parent) form=xmlnode_insert_tag(parent,"x"); else form=xmlnode_new_tag("x"); xmlnode_put_attrib(form,"xmlns","jabber:x:data"); xmlnode_put_attrib(form,"type","form"); tag=xmlnode_insert_tag(form,"title"); xmlnode_insert_cdata(tag,title,-1); tag=xmlnode_insert_tag(form,"instructions"); xmlnode_insert_cdata(tag,instructions,-1); return form; }
/* produce full duplicate of x with a new pool, x must be a tag! */ xmlnode xmlnode_dup(xmlnode x) { xmlnode x2; if(x == NULL) return NULL; x2 = xmlnode_new_tag(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; }
int presence_send_subscribe(struct stream_s *stream,const char *from,const char *to){ xmlnode pres; pres=xmlnode_new_tag("presence"); 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); } xmlnode_put_attrib(pres,"to",to); xmlnode_put_attrib(pres,"type","subscribe"); stream_write(stream,pres); xmlnode_free(pres); return 0; }
int presence_send(struct stream_s *stream,const char *from, const char *to,int available,const char *show, const char *status,GTime timestamp){ xmlnode pres; xmlnode n; pres=xmlnode_new_tag("presence"); 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); } xmlnode_put_attrib(pres,"to",to); if (available==-1) xmlnode_put_attrib(pres,"type","invisible"); else if (!available) xmlnode_put_attrib(pres,"type","unavailable"); if (show){ n=xmlnode_insert_tag(pres,"show"); xmlnode_insert_cdata(n,show,-1); } if (status){ n=xmlnode_insert_tag(pres,"status"); xmlnode_insert_cdata(n,string_from_gg(status),-1); } if (timestamp){ struct tm *tm; time_t ttime = timestamp; char buf[101]; n=xmlnode_insert_tag(pres,"x"); xmlnode_put_attrib(n,"xmlns","jabber:x:delay"); tm=gmtime(&ttime); strftime(buf,100,"%Y%m%dT%H:%M:%S",tm); xmlnode_put_attrib(n,"stamp",buf); xmlnode_insert_cdata(n,"Presence update time",-1); } stream_write(stream,pres); xmlnode_free(pres); return 0; }
/** * 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; }
void expat_startElement(void* userdata, const char* name, const char** atts) { /* get the xmlnode pointed to by the userdata */ xmlnode *x = userdata; xmlnode current = *x; if (current == NULL) { /* allocate a base node */ current = xmlnode_new_tag(name); xmlnode_put_expat_attribs(current, atts); *x = current; } else { *x = xmlnode_insert_tag(current, name); xmlnode_put_expat_attribs(*x, atts); } }
void jabber_stream_start(Stream *s,xmlnode x){ char hashbuf[50]; char *str; xmlnode tag; if (jabber_state!=JS_NONE){ g_warning(N_("unexpected <stream:stream/>")); return; } stream_id=xmlnode_get_attrib(x,"id"); str=g_strdup_printf("%s%s",stream_id,secret); shahash_r(str,hashbuf); g_free(str); tag=xmlnode_new_tag("handshake"); xmlnode_insert_cdata(tag,hashbuf,-1); stream_write(s,tag); xmlnode_free(tag); jabber_state=JS_HANDSHAKE; }
void at_auth_subscribe(ati ti, jpacket jp) { /* Here we actually subscribe to the user */ xmlnode x; jid jnew; x = xmlnode_new_tag("presence"); jnew = jid_new(xmlnode_pool(x), ti->i->id); jid_set(jnew, "registered", JID_RESOURCE); log_debug(ZONE, "[AIM] Subscribing to %s presence\n", jid_full(jp->from)); xmlnode_put_attrib(x, "to", jid_full(jp->from)); xmlnode_put_attrib(x, "from", jid_full(jnew)); xmlnode_put_attrib(x, "type", "subscribe"); at_deliver(ti,x); return; }
void _at_shutdown(xht x, const char *key, void *data, void *arg) { ati ti = (ati)arg; at_session s = (at_session)data; xmlnode message; message = xmlnode_new_tag("message"); xmlnode_put_attrib(message, "from", jid_full(s->from)); xmlnode_put_attrib(message,"type", "error"); xmlnode_put_attrib(message, "to", jid_full(s->cur)); xmlnode_insert_cdata(xmlnode_insert_tag(message, "error"), "AIM Transport shutting down.", -1); xmlnode_put_attrib(xmlnode_get_tag(message, "error"), "code", "502"); at_deliver(ti,message); at_session_end(s); iconv_close( fromutf8 ); iconv_close( toutf8 ); return; }
xmlnode jutil_iqnew2(int type) //create iq packet w/o query tag, required for later patches, such as file transfer, send version and etc. { xmlnode iq; iq = xmlnode_new_tag("iq"); switch(type) { case JPACKET__GET: xmlnode_put_attrib(iq,"type","get"); break; case JPACKET__SET: xmlnode_put_attrib(iq,"type","set"); break; case JPACKET__RESULT: xmlnode_put_attrib(iq,"type","result"); break; case JPACKET__ERROR: xmlnode_put_attrib(iq,"type","error"); break; } return iq; }
/** * utility for making IQ stanzas, that contain a <query/> element in a different namespace * * @note In traditional Jabber protocols the element inside an iq element has the name "query". * This util is not able to create IQ stanzas that contain a query which a element that does * not have the name "query" * * @param type the type of the iq stanza (one of JPACKET__GET, JPACKET__SET, JPACKET__RESULT, JPACKET__ERROR) * @param ns the namespace of the <query/> element * @return the created xmlnode */ xmlnode jutil_iqnew(int type, char *ns) { xmlnode iq; iq = xmlnode_new_tag("iq"); switch (type) { case JPACKET__GET: xmlnode_put_attrib(iq, "type", "get"); break; case JPACKET__SET: xmlnode_put_attrib(iq, "type", "set"); break; case JPACKET__RESULT: xmlnode_put_attrib(iq, "type", "result"); break; case JPACKET__ERROR: xmlnode_put_attrib(iq, "type", "error"); break; } xmlnode_put_attrib(xmlnode_insert_tag(iq, "query"), "xmlns", ns); return iq; }
void get_roster_done(Session *s,struct gg_event *e){ char **results; char *body=NULL; char *jid; xmlnode roster; xmlnode msg; xmlnode n; int i; if(!e->event.userlist.reply){ message_send(s->s,NULL,s->user->jid,1,_("Roster empty."),0); return; } message_send(s->s,NULL,s->user->jid,0,_("Roster received."),0); msg=xmlnode_new_tag("message"); jid=jid_my_registered(); xmlnode_put_attrib(msg,"from",jid); g_free(jid); xmlnode_put_attrib(msg,"to",s->user->jid); n=xmlnode_insert_tag(msg,"body"); roster=xmlnode_insert_tag(msg,"x"); xmlnode_put_attrib(roster,"xmlns","jabber:x:roster"); body=g_strdup(""); results=g_strsplit(e->event.userlist.reply,"\r\n",0); for(i=0;results[i];i++){ char **cinfo; char *t,*jid; char *name=NULL; int j,uin; xmlnode item,tag; cinfo=g_strsplit(results[i],";",0); for(j=0;cinfo[j];j++); if (j<7){ g_strfreev(cinfo); continue; } uin=atoi(cinfo[6]); item=xmlnode_insert_tag(roster,"item"); t=g_strconcat(body,"\n",NULL); g_free(body); body=t; t=g_strdup_printf("%sUin: %u\n",body,uin); g_free(body); body=t; if (cinfo[2] && cinfo[2][0]){ t=g_strdup_printf("%sNick: %s\n",body,cinfo[2]); g_free(body); body=t; if (name==NULL) name=g_strdup(cinfo[2]); } if (cinfo[0] && cinfo[0][0]){ t=g_strdup_printf("%sFirst name: %s\n",body,cinfo[0]); g_free(body); body=t; if (name==NULL) name=g_strdup(cinfo[0]); } if (cinfo[1] && cinfo[1][0]){ t=g_strdup_printf("%sLast name: %s\n",body,cinfo[1]); g_free(body); body=t; if (name==NULL) name=g_strdup(cinfo[1]); } if (cinfo[3] && cinfo[3][0]){ t=g_strdup_printf("%sDisplay: %s\n",body,cinfo[3]); g_free(body); body=t; if (name) g_free(name); name=g_strdup(cinfo[3]); } if (cinfo[4] && cinfo[4][0]){ t=g_strdup_printf("%sPhone: %s\n",body,cinfo[4]); g_free(body); body=t; } if (cinfo[5] && cinfo[5][0]){ t=g_strdup_printf("%sGroup: %s\n",body,cinfo[5]); g_free(body); body=t; tag=xmlnode_insert_tag(item,"group"); xmlnode_insert_cdata(n,string_from_gg(cinfo[5]),-1); } if (cinfo[7] && cinfo[7][0]){ t=g_strdup_printf("%sE-mail: %s\n",body,cinfo[7]); g_free(body); body=t; } jid=jid_build(uin); xmlnode_put_attrib(item,"jid",jid); g_free(jid); if (name==NULL) name=g_strdup_printf("%u",uin); xmlnode_put_attrib(item,"name",string_from_gg(name)); g_free(name); g_strfreev(cinfo); } g_strfreev(results); xmlnode_insert_cdata(n,string_from_gg(body),-1); stream_write(s->s,msg); xmlnode_free(msg); }
xmlnode xdbsql_roomoutcast_get(XdbSqlDatas * self, const char *room) { xmlnode node = NULL; /* return from this function */ xmlnode query; /* query node */ xmlnode element, reason; query_def qd; /* the query definition */ XdbSqlResult *result; /* pointer to database result */ int first = 1; int ndx_userid, ndx_reason, ndx_responsibleid, ndx_responsiblenick; if (!room) { /* the room was not specified - we have to bug off */ log_error(NULL, "[xdbsql_roomoutcast_get] room not specified"); return NULL; } /* Get the query definitions */ query = xdbsql_query_get(self, "roomoutcast-get"); if (!query) { log_error(NULL, "--!!-- WTF? roomoutcast-get query not found?"); return NULL; } /* Load roomoutcast elements */ /* Build the query string. */ qd = xdbsql_querydef_init(self, query); xdbsql_querydef_setvar(qd, "room", room); /* Execute the query! */ result = sqldb_query(self, xdbsql_querydef_finalize(qd)); xdbsql_querydef_free(qd); if (!result) { log_error(NULL, "[xdbsql_roomoutcast_get] query failed : %s", sqldb_error(self)); return NULL; } /* get the results from the query */ if (!sqldb_use_result(result)) { log_error(NULL, "[xdbsql_roomoutcast_get] result fetch failed : %s", sqldb_error(self)); return NULL; } node = xmlnode_new_tag("list"); /* Initialize the return value. */ while (sqldb_next_tuple(result) != 0) { /* look for all room entries and add them to our output tree */ if (first) { /* initialize the column mapping indexes */ col_map map = xdbsql_colmap_init(query); ndx_userid = xdbsql_colmap_index(map, "userid"); ndx_reason = xdbsql_colmap_index(map, "reason"); ndx_responsibleid = xdbsql_colmap_index(map, "responsibleid"); ndx_responsiblenick = xdbsql_colmap_index(map, "responsiblenick"); xdbsql_colmap_free(map); first = 0; } element = xmlnode_insert_tag(node, "item"); xmlnode_put_attrib(element, "jid", sqldb_get_value(result, ndx_userid)); reason = xmlnode_insert_tag(element, "reason"); xmlnode_insert_cdata(reason, sqldb_get_value(result, ndx_reason), -1); xmlnode_put_attrib(reason, "actor", sqldb_get_value(result, ndx_responsibleid)); xmlnode_put_attrib(reason, "nick", sqldb_get_value(result, ndx_responsiblenick)); } sqldb_free_result(result); return node; }
void mt_ns_not(mpacket mp, session s) { int i = 0; xmlnode msg, oob1, oob2; /* message body spool*/ pool p = pool_new(); spool sp = spool_new(p); /* parsing the message... */ xmlnode notification, msgtag, action, subscr, body, text; spool action_url = spool_new(p); spool subscr_url = spool_new(p); char *chunk, *fixedchunk, *notification_id, *msg_id, *bodytext; if (s->ti->inbox_headlines == 0) return; /* grab the <notification/> chunk */ for(i = 2; i < mp->count; i++) { spool_add(sp, mt_packet_data(mp,i)); } 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"),"MSN Alert",-1); /* Parse the alert -- there's probably better ways to do this */ chunk = spool_print(sp); log_debug(ZONE, "chunk from spool_print: \"%s\"", chunk); fixedchunk = mt_fix_amps(p, chunk); log_debug(ZONE, "fixedchunk: \"%s\"", fixedchunk); // Get the notification ID notification = xmlnode_str(fixedchunk, strlen(fixedchunk)); notification_id = xmlnode_get_attrib(notification, "id"); log_debug(ZONE, "notification - %X\nn_id - %s", notification, notification_id); // Get the message ID msgtag = xmlnode_get_tag(notification, "MSG"); msg_id = xmlnode_get_attrib(msgtag, "id"); // Get the action URL action = xmlnode_get_tag(msgtag, "ACTION"); spool_add(action_url, xmlnode_get_attrib(action, "url")); spool_add(action_url, "¬ification="); spool_add(action_url, notification_id); spool_add(action_url, "&message_id="); spool_add(action_url, msg_id); spool_add(action_url, "&agent=messenger"); // Get the subscription URL subscr = xmlnode_get_tag(msgtag, "SUBSCR"); spool_add(subscr_url, xmlnode_get_attrib(subscr, "url")); spool_add(subscr_url, "¬ification="); spool_add(subscr_url, notification_id); spool_add(subscr_url, "&message_id="); spool_add(subscr_url, msg_id); spool_add(subscr_url, "&agent=messenger"); // Get the body body = xmlnode_get_tag(msgtag, "BODY"); text = xmlnode_get_tag(body, "TEXT"); bodytext = xmlnode_get_data(text); /* Finished parsing the XML */ // Insert the body xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),bodytext,-1); // Insert the action URL oob1 = xmlnode_insert_tag(msg,"x"); xmlnode_put_attrib(oob1,"xmlns","jabber:x:oob"); xmlnode_insert_cdata(xmlnode_insert_tag(oob1,"url"),spool_print(action_url),-1); xmlnode_insert_cdata(xmlnode_insert_tag(oob1,"desc"),"More information on this alert",-1); // Insert the subscription URL oob2 = xmlnode_insert_tag(msg,"x"); xmlnode_put_attrib(oob2,"xmlns","jabber:x:oob"); xmlnode_insert_cdata(xmlnode_insert_tag(oob2,"url"),spool_print(subscr_url),-1); xmlnode_insert_cdata(xmlnode_insert_tag(oob2,"desc"),"Manage subscriptions to alerts",-1); mt_deliver(s->ti,msg); xmlnode_free(notification); pool_free(p); }
int user_save(User *u){ FILE *f; char *fn; char *str; char *njid; int r; xmlnode xml,tag,ctag,userlist; g_assert(u!=NULL); str=strchr(u->jid,'/'); g_assert(str==NULL); if (!u->confirmed){ g_message(L_("Not saving user '%s' - account not confirmed."),u->jid); return -1; } g_debug(L_("Saving user '%s'"),u->jid); njid=jid_normalized(u->jid,0); g_assert(njid!=NULL); fn=g_strdup_printf("%s.new",njid); f=fopen(fn,"w"); if (!f){ g_warning(L_("Couldn't open '%s': %s"),fn,g_strerror(errno)); g_free(fn); g_free(njid); return -1; } xml=xmlnode_new_tag("user"); tag=xmlnode_insert_tag(xml,"version"); str=g_strdup_printf("%08x",USER_FILE_FORMAT_VERSION); xmlnode_put_attrib(tag,"file_format",str); g_free(str); tag=xmlnode_insert_tag(xml,"jid"); xmlnode_insert_cdata(tag,u->jid,-1); set_subscribe(tag, u->subscribe); tag=xmlnode_insert_tag(xml,"uin"); str=g_strdup_printf("%lu",(unsigned long)u->uin); xmlnode_insert_cdata(tag,str,-1); g_free(str); tag=xmlnode_insert_tag(xml,"password"); xmlnode_insert_cdata(tag,u->password,-1); if (u->last_sys_msg>0){ tag=xmlnode_insert_tag(xml,"last_sys_msg"); str=g_strdup_printf("%i",u->last_sys_msg); xmlnode_insert_cdata(tag,str,-1); g_free(str); } if (u->invisible) tag=xmlnode_insert_tag(xml,"invisible"); if (u->friends_only) tag=xmlnode_insert_tag(xml,"friendsonly"); if (u->ignore_unknown) tag=xmlnode_insert_tag(xml,"ignore_unknown"); if (u->locale){ tag=xmlnode_insert_tag(xml,"locale"); xmlnode_insert_cdata(tag,u->locale,-1); } if (u->status){ tag=xmlnode_insert_tag(xml,"status"); xmlnode_insert_cdata(tag,to_utf8(u->status),-1); } if (u->contacts){ GList *it; Contact *c; userlist=xmlnode_insert_tag(xml,"userlist"); for(it=g_list_first(u->contacts);it;it=it->next){ c=(Contact *)it->data; ctag=xmlnode_insert_tag(userlist,"contact"); str=g_strdup_printf("%lu",(unsigned long)c->uin); xmlnode_put_attrib(ctag,"uin",str); if (c->ignored) xmlnode_put_attrib(ctag,"ignored","ignored"); if (c->blocked) xmlnode_put_attrib(ctag,"blocked","blocked"); set_subscribe(ctag, c->subscribe); g_free(str); } } str=xmlnode2str(xml); r=fputs(str,f); if (r<0){ g_warning(L_("Couldn't save '%s': %s"),u->jid,g_strerror(errno)); fclose(f); unlink(fn); xmlnode_free(xml); g_free(fn); g_free(njid); return -1; } fclose(f); r=unlink(njid); if (r && errno!=ENOENT){ g_warning(L_("Couldn't unlink '%s': %s"),njid,g_strerror(errno)); xmlnode_free(xml); g_free(fn); g_free(njid); return -1; } r=rename(fn,njid); if (r){ g_warning(L_("Couldn't rename '%s' to '%s': %s"),fn,u->jid,g_strerror(errno)); xmlnode_free(xml); g_free(fn); g_free(njid); return -1; } xmlnode_free(xml); g_free(fn); g_free(njid); return 0; }