From a79a0e59ef612625c500d48bb2ef026f07ab927d Mon Sep 17 00:00:00 2001 From: Jesse Kuang Date: Fri, 11 Jan 2019 12:02:02 +0800 Subject: [PATCH] remove GNUmakefile .gitignore mv new example.go to other repo --- .gitignore | 25 -------- GNUmakefile | 31 ---------- _example/example.go | 148 ++------------------------------------------ 3 files changed, 5 insertions(+), 199 deletions(-) delete mode 100644 .gitignore delete mode 100644 GNUmakefile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 69a7a03..0000000 --- a/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.swp -bin/ diff --git a/GNUmakefile b/GNUmakefile deleted file mode 100644 index be4b08c..0000000 --- a/GNUmakefile +++ /dev/null @@ -1,31 +0,0 @@ -# -# Makefile for hookAPI -# -# switches: -# define the ones you want in the CFLAGS definition... -# -# TRACE - turn on tracing/debugging code -# -# -# -# - -# Version for distribution -VER=1_0r1 - -MAKEFILE=GNUmakefile - -# We Use Compact Memory Model - -all: bin/example - @[ -d bin ] || exit - -bin/example: _example/example.go xmpp.go xmpp_get_info.go - @[ -d bin ] || mkdir bin - go build -o $@ _example/example.go - @strip $@ || echo "example OK" - -clean: - -distclean: clean - @rm -rf bin diff --git a/_example/example.go b/_example/example.go index 844de9f..136af5a 100644 --- a/_example/example.go +++ b/_example/example.go @@ -3,41 +3,23 @@ package main import ( "bufio" "crypto/tls" - "encoding/xml" "flag" "fmt" - "github.com/kjx98/go-xmpp" + "github.com/mattn/go-xmpp" "log" "os" - "runtime" "strings" - "time" ) -var server = flag.String("server", "", "server") +var server = flag.String("server", "talk.google.com:443", "server") var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") var status = flag.String("status", "xa", "status") var statusMessage = flag.String("status-msg", "I for one welcome our new codebot overlords.", "status message") -var notls = flag.Bool("notls", true, "No TLS") +var notls = flag.Bool("notls", false, "No TLS") var debug = flag.Bool("debug", false, "debug output") var session = flag.Bool("session", false, "use server session") -type rosterItem struct { - XMLName xml.Name `xml:"item"` - Jid string `xml:"jid,attr"` - Name string `xml:"name,attr"` - Subscription string `xml:"subscription,attr"` - Group []string `"xml:"group"` -} - -type contactType struct { - Jid string - Name string - Subscription string - Online bool -} - func serverName(host string) string { return strings.Split(host, ":")[0] } @@ -62,10 +44,6 @@ func main() { ServerName: serverName(*server), InsecureSkipVerify: false, } - } else { - xmpp.DefaultConfig = tls.Config{ - InsecureSkipVerify: true, - } } var talk *xmpp.Client @@ -77,7 +55,6 @@ func main() { Debug: *debug, Session: *session, Status: *status, - Resource: "bot", StatusMessage: *statusMessage, } @@ -86,7 +63,6 @@ func main() { if err != nil { log.Fatal(err) } - loginTime := time.Now() go func() { for { @@ -96,130 +72,18 @@ func main() { } switch v := chat.(type) { case xmpp.Chat: - if v.Type == "roster" { - fmt.Println("roster", v.Roster) - } else { - for _, element := range v.OtherElem { - if element.XMLName.Space == "jabber:x:conference" { - // if not join - talk.JoinMUCNoHistory(v.Remote, "bot") - } - // composing, paused, active - if element.XMLName.Space == - "http://jabber.org/protocol/chatstates" && - element.XMLName.Local == "composing" { - fmt.Println(v.Remote, "is composing") - } - } - if strings.TrimSpace(v.Text) != "" { - fmt.Println(v.Remote, v.Text) - } - } + fmt.Println(v.Remote, v.Text) case xmpp.Presence: - switch v.Type { - case "subscribe": - // Approve all subscription - fmt.Printf("Presence: %s Approve %s subscription\n", - v.To, v.From) - talk.ApproveSubscription(v.From) - talk.RequestSubscription(v.From) - case "unsubscribe": - fmt.Printf("Presence: %s Revoke %s subscription\n", - v.To, v.From) - talk.RevokeSubscription(v.From) - default: - fmt.Printf("Presence: %s %s Type(%s)\n", v.From, v.Show, v.Type) - } - case xmpp.Roster, xmpp.Contact: - // TODO: update local roster - fmt.Println("Roster/Contact:", v) - case xmpp.IQ: - // ping ignore - switch v.QueryName.Space { - case "jabber:iq:version": - if err := talk.RawVersion(v.To, v.From, v.ID, - "0.1", runtime.GOOS); err != nil { - fmt.Println("RawVersion:", err) - } - continue - case "jabber:iq:last": - tt := time.Now().Sub(loginTime) - last := int(tt.Seconds()) - if err := talk.RawLast(v.To, v.From, v.ID, last); err != nil { - fmt.Println("RawLast:", err) - } - continue - case "urn:xmpp:time": - if err := talk.RawIQtime(v.To, v.From, v.ID); err != nil { - fmt.Println("RawIQtime:", err) - } - continue - case "jabber:iq:roster": - var item rosterItem - if v.Type != "result" && v.Type != "set" { - // only result and set processed - fmt.Println("jabber:iq:roster, type:", v.Type) - continue - } - vv := strings.Split(v.Query, "/>") - for _, ss := range vv { - if strings.TrimSpace(ss) == "" { - continue - } - ss += "/>" - if err := xml.Unmarshal([]byte(ss), &item); err != nil { - fmt.Println("unmarshal roster : ", err) - continue - } else { - if item.Subscription == "remove" { - continue - } - /* - //may loop whiel presence is unavailable - if item.Subscription == "from" { - fmt.Printf("%s Approve %s subscription\n", - v.To, item.Jid) - talk.RequestSubscription(item.Jid) - } - */ - fmt.Printf("roster item %s subscription(%s), %v\n", - item.Jid, item.Subscription, item.Group) - if v.Type == "set" && item.Subscription == "both" { - // shall we check presence unavailable - pr := xmpp.Presence{From: v.To, To: item.Jid, - Show: "xa"} - talk.SendPresence(pr) - } - } - } - continue - } - if v.Type == "result" && v.ID == "c2s1" { - fmt.Printf("Got pong from %s to %s\n", v.From, v.To) - } else { - fmt.Printf("Got from %s to %s IQ, tag: (%v), query(%s)\n", - v.From, v.To, v.QueryName, v.Query) - } - default: - fmt.Printf("def: %v\n", v) + fmt.Println(v.From, v.Show) } } }() - // get roster first - talk.Roster() - //talk.RevokeSubscription("wkpb@hot-chilli.net") - //talk.SendOrg("") - // test conf - talk.JoinMUCNoHistory("test@conference.jabb3r.org", "bot") for { in := bufio.NewReader(os.Stdin) line, err := in.ReadString('\n') if err != nil { continue } - if len(line) >= 4 && line[:4] == "quit" { - break - } line = strings.TrimRight(line, "\n") tokens := strings.SplitN(line, " ", 2) @@ -227,6 +91,4 @@ func main() { talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]}) } } - talk.SendOrg("