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; }
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; }
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; }
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; }
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); }