diff --git a/example/example.go b/example/example.go index cb6911d..5702a74 100644 --- a/example/example.go +++ b/example/example.go @@ -5,7 +5,6 @@ import ( "fmt" "flag" "github.com/mattn/go-xmpp" - "github.com/mattn/go-iconv" "log" "os" "strings" @@ -14,26 +13,7 @@ import ( var server = flag.String("server", "talk.google.com:443", "server") var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") - -func fromUTF8(s string) string { - ic, err := iconv.Open("char", "UTF-8") - if err != nil { - return s - } - defer ic.Close() - ret, _ := ic.Conv(s) - return ret -} - -func toUTF8(s string) string { - ic, err := iconv.Open("UTF-8", "char") - if err != nil { - return s - } - defer ic.Close() - ret, _ := ic.Conv(s) - return ret -} +var notls = flag.Bool("notls", false, "No TLS") func main() { flag.Usage = func() { @@ -46,7 +26,13 @@ func main() { flag.Usage() } - talk, err := xmpp.NewClient(*server, *username, *password) + var talk *xmpp.Client + var err error + if *notls { + talk, err = xmpp.NewClientNoTLS(*server, *username, *password) + } else { + talk, err = xmpp.NewClient(*server, *username, *password) + } if err != nil { log.Fatal(err) } @@ -59,9 +45,9 @@ func main() { } switch v := chat.(type) { case xmpp.Chat: - fmt.Println(v.Remote, fromUTF8(v.Text)) + fmt.Println(v.Remote, v.Text) case xmpp.Presence: - fmt.Println(v.From, fromUTF8(v.Show)) + fmt.Println(v.From, v.Show) } } }() @@ -75,7 +61,7 @@ func main() { tokens := strings.SplitN(line, " ", 2) if len(tokens) == 2 { - talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: toUTF8(tokens[1])}) + talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]}) } } }