packagemainimport("../xmpp""crypto/tls""encoding/xml""flag""fmt""log""os""strings")typeStdLoggerstruct{}func(s*StdLogger)Log(v...interface{}){log.Println(v...)}func(s*StdLogger)Logf(fmtstring,v...interface{}){log.Printf(fmt,v...)}funcinit(){logger:=&StdLogger{}// xmpp.Debug = loggerxmpp.Info=loggerxmpp.Warn=logger}// Demonstrate the API, and allow the user to interact with an XMPP// server via the terminal.funcmain(){varjidxmpp.JIDflag.Var(&jid,"jid","JID to log in as")varpw*string=flag.String("pw","","password")flag.Parse()ifjid.Domain==""||*pw==""{flag.Usage()os.Exit(2)}stat:=make(chanxmpp.Status)gofunc(){fors:=rangestat{log.Printf("connection status %d",s)}}()tlsConf:=tls.Config{InsecureSkipVerify:true}c,err:=xmpp.NewClient(&jid,*pw,tlsConf,nil,xmpp.Presence{},stat)iferr!=nil{log.Fatalf("NewClient(%v): %v",jid,err)}deferclose(c.Send)gofunc(ch<-chanxmpp.Stanza){forobj:=rangech{fmt.Printf("s: %v\n",obj)}fmt.Println("done reading")}(c.Recv)roster:=c.Roster.Get()fmt.Printf("%d roster entries:\n",len(roster))fori,entry:=rangeroster{fmt.Printf("%d: %v\n",i,entry)}p:=make([]byte,1024)for{nr,_:=os.Stdin.Read(p)ifnr==0{break}s:=string(p)dec:=xml.NewDecoder(strings.NewReader(s))t,err:=dec.Token()iferr!=nil{fmt.Printf("token: %s\n",err)break}varse*xml.StartElementvarokboolifse,ok=t.(*xml.StartElement);!ok{fmt.Println("Couldn't find start element")break}varstanxmpp.Stanzaswitchse.Name.Local{case"iq":stan=&xmpp.Iq{}case"message":stan=&xmpp.Message{}case"presence":stan=&xmpp.Presence{}default:fmt.Println("Can't parse non-stanza.")continue}err=dec.Decode(stan)iferr==nil{c.Send<-stan}else{fmt.Printf("Parse error: %v\n",err)break}}fmt.Println("done sending")}