From f7b1e7ecb224aff66bbe67c28649890514b0b730 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 20 Apr 2016 22:10:37 +0200 Subject: [PATCH 01/30] Add params for presence and disco info - Add Show, Status, Photo and Nick into presence stanza - Add Node attribute into DiscoInfo payload --- src/xmpp/disco.go | 18 ++++++++++-------- src/xmpp/stanza.go | 13 +++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/xmpp/disco.go b/src/xmpp/disco.go index d9dea7f..3951d8b 100644 --- a/src/xmpp/disco.go +++ b/src/xmpp/disco.go @@ -6,8 +6,8 @@ import ( ) const ( - nsDiscoInfo = "http://jabber.org/protocol/disco#info" - nsDiscoItems = "http://jabber.org/protocol/disco#items" + NsDiscoInfo = "http://jabber.org/protocol/disco#info" + NsDiscoItems = "http://jabber.org/protocol/disco#items" ) // Service Discovery (XEP-0030) protocol. "Wraps" XMPP instance to provide a @@ -19,6 +19,7 @@ type Disco struct { // Iq get/result payload for "info" requests. type DiscoInfo struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#info query"` + Node string `xml:"node,attr"` Identity []DiscoIdentity `xml:"identity"` Feature []DiscoFeature `xml:"feature"` } @@ -38,6 +39,7 @@ type DiscoFeature struct { // Iq get/result payload for "items" requests. type DiscoItems struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` + Node string `xml:"node,attr"` Item []DiscoItem `xml:"item"` } @@ -49,13 +51,13 @@ type DiscoItem struct { } // Request information about the service identified by 'to'. -func (disco *Disco) Info(to string, from string) (*DiscoInfo, error) { +func (disco *Disco) Info(to, from string) (*DiscoInfo, error) { if from == "" { from = disco.XMPP.JID.Full() } - req := &Iq{Id: UUID4(), Type: "get", To: to, From: from} + req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from} req.PayloadEncode(&DiscoInfo{}) resp, err := disco.XMPP.SendRecv(req) @@ -72,14 +74,14 @@ func (disco *Disco) Info(to string, from string) (*DiscoInfo, error) { } // Request items in the service identified by 'to'. -func (disco *Disco) Items(to string, from string) (*DiscoItems, error) { +func (disco *Disco) Items(to, from, node string) (*DiscoItems, error) { if from == "" { from = disco.XMPP.JID.Full() } - req := &Iq{Id: UUID4(), Type: "get", To: to, From: from} - req.PayloadEncode(&DiscoItems{}) + req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from} + req.PayloadEncode(&DiscoItems{Node: node}) resp, err := disco.XMPP.SendRecv(req) if err != nil { @@ -94,7 +96,7 @@ func (disco *Disco) Items(to string, from string) (*DiscoItems, error) { return items, err } -var discoNamespacePrefix = strings.Split(nsDiscoInfo, "#")[0] +var discoNamespacePrefix = strings.Split(NsDiscoInfo, "#")[0] // Matcher instance to match stanzas with a disco payload. var DiscoPayloadMatcher = MatcherFunc( diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 584793d..dd51f7f 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -6,6 +6,15 @@ import ( "fmt" ) + +const ( + IqTypeGet = "get" + IqTypeSet = "set" + IqTypeResult = "result" + IqTypeError = "error" +) + + // XMPP stanza. type Iq struct { XMLName xml.Name `xml:"iq"` @@ -72,6 +81,10 @@ type Presence struct { Type string `xml:"type,attr,omitempty"` To string `xml:"to,attr,omitempty"` From string `xml:"from,attr,omitempty"` + Show string `xml:"show"` // away, chat, dnd, xa + Status string `xml:"status"` // sb []clientText + Photo string `xml:"photo,omitempty"` // Avatar + Nick string `xml:"nick,omitempty"` // Nickname } // XMPP . May occur as a top-level stanza or embedded in another From e82f10fe4835d9f0154438b35496610371421ad1 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 20 Apr 2016 22:16:31 +0200 Subject: [PATCH 02/30] Add XEP-0092 (Software version) --- src/xmpp/disco.go | 2 +- src/xmpp/softwareVersion.go | 17 +++++++++++++++++ src/xmpp/stanza.go | 10 ++++------ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/xmpp/softwareVersion.go diff --git a/src/xmpp/disco.go b/src/xmpp/disco.go index 3951d8b..cf1bdcf 100644 --- a/src/xmpp/disco.go +++ b/src/xmpp/disco.go @@ -39,7 +39,7 @@ type DiscoFeature struct { // Iq get/result payload for "items" requests. type DiscoItems struct { XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"` - Node string `xml:"node,attr"` + Node string `xml:"node,attr"` Item []DiscoItem `xml:"item"` } diff --git a/src/xmpp/softwareVersion.go b/src/xmpp/softwareVersion.go new file mode 100644 index 0000000..4e22cbf --- /dev/null +++ b/src/xmpp/softwareVersion.go @@ -0,0 +1,17 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NsJabberClient = "jabber:iq:version" +) + +// XEP-0092 Software Version +type SoftwareVersion struct { + XMLName xml.Name `xml:"jabber:iq:version query"` + Name string `xml:"name,omitempty"` + Version string `xml:"version,omitempty"` + OS string `xml:"os,omitempty"` +} diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index dd51f7f..37f3270 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -6,7 +6,6 @@ import ( "fmt" ) - const ( IqTypeGet = "get" IqTypeSet = "set" @@ -14,7 +13,6 @@ const ( IqTypeError = "error" ) - // XMPP stanza. type Iq struct { XMLName xml.Name `xml:"iq"` @@ -81,10 +79,10 @@ type Presence struct { Type string `xml:"type,attr,omitempty"` To string `xml:"to,attr,omitempty"` From string `xml:"from,attr,omitempty"` - Show string `xml:"show"` // away, chat, dnd, xa - Status string `xml:"status"` // sb []clientText - Photo string `xml:"photo,omitempty"` // Avatar - Nick string `xml:"nick,omitempty"` // Nickname + Show string `xml:"show"` // away, chat, dnd, xa + Status string `xml:"status"` // sb []clientText + Photo string `xml:"photo,omitempty"` // Avatar + Nick string `xml:"nick,omitempty"` // Nickname } // XMPP . May occur as a top-level stanza or embedded in another From e0e253ce4bab759c8fca73f7afa37fbdff16f1c5 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 20 Apr 2016 22:19:59 +0200 Subject: [PATCH 03/30] Add Ad-Hoc command --- src/xmpp/ad-hoc.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/xmpp/uuid.go | 13 +++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/xmpp/ad-hoc.go diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go new file mode 100644 index 0000000..bf05109 --- /dev/null +++ b/src/xmpp/ad-hoc.go @@ -0,0 +1,68 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NodeAdHocCommand = "http://jabber.org/protocol/commands" + + ActionAdHocExecute = "execute" + ActionAdHocNext = "next" + ActionAdHocCancel = "cancel" + + StatusAdHocExecute = "execute" + StatusAdHocCompleted = "completed" + StatusAdHocCanceled = "canceled" + + TypeAdHocForm = "form" + TypeAdHocResult = "result" + TypeAdHocSubmit = "submit" + + TypeAdHocListSingle = "list-single" + TypeAdHocListMulti = "list-multi" + + TypeAdHocNoteInfo = "info" + TypeAdHocNoteWarning = "warn" + TypeAdHocNoteError = "error" + + TypeAdHocFieldListMulti = "list-multi" + TypeAdHocFieldListSingle = "list-single" + TypeAdHocFieldTextSingle = "text-single" + TypeAdHocFieldJidSingle = "jid-single" +) + +type AdHocCommand struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"` + Node string `xml:"node,attr"` + Action string `xml:"action,attr"` + SessionId string `xml:"sessionid,attr"` + Status string `xml:"status,attr"` + XForm AdHocXForm `xml:"x"` + Note AdHocNote `xml:"note,omitempty"` +} + +type AdHocXForm struct { + XMLName xml.Name `xml:"jabber:x:data x"` + Type string `xml:"type,attr"` + Title string `xml:"title"` + Instructions string `xml:"instructions"` + Fields []AdHocField `xml:"field"` +} + +type AdHocField struct { + Var string `xml:"var,attr"` + Label string `xml:"label,attr"` + Type string `xml:"type,attr"` + Options []AdHocFieldOption `xml:"option"` + Value string `xml:"value,omitempty"` +} + +type AdHocFieldOption struct { + Value string `xml:"value"` +} + +type AdHocNote struct { + Type string `xml:"type,attr"` + Value string `xml:",innerxml"` +} diff --git a/src/xmpp/uuid.go b/src/xmpp/uuid.go index 14d866f..2d8779d 100644 --- a/src/xmpp/uuid.go +++ b/src/xmpp/uuid.go @@ -15,3 +15,16 @@ func UUID4() string { uuid[8] = (uuid[8] &^ 0x40) | 0x80 return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]) } + +func SessionId() string { + var strSize = 15 + var dictionary string + dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + + var bytes = make([]byte, strSize) + rand.Read(bytes) + for k, v := range bytes { + bytes[k] = dictionary[v%byte(len(dictionary))] + } + return string(bytes) +} From 8f21af2b45f4d449e78dfe5eff0ec99aac9f8243 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 20 Apr 2016 22:24:38 +0200 Subject: [PATCH 04/30] Add vcard support --- src/xmpp/vcard.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/xmpp/vcard.go diff --git a/src/xmpp/vcard.go b/src/xmpp/vcard.go new file mode 100644 index 0000000..06ba65b --- /dev/null +++ b/src/xmpp/vcard.go @@ -0,0 +1,15 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NsVCardTemp = "vcard-temp" +) + +// XEP-0054 vCard +type VCard struct { + XMLName xml.Name `xml:"vcard-temp vCard"` + // TODO Must complete truct +} From 23e93d518b693a2ce89777d7fcd49e41ec3377db Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 18 May 2016 19:13:27 +0200 Subject: [PATCH 05/30] Fix typo --- src/xmpp/ad-hoc.go | 2 +- src/xmpp/disco.go | 4 ++-- src/xmpp/softwareVersion.go | 2 +- src/xmpp/stanza.go | 8 ++++---- src/xmpp/uuid.go | 16 +++++++++------- src/xmpp/vcard.go | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go index bf05109..028bee1 100644 --- a/src/xmpp/ad-hoc.go +++ b/src/xmpp/ad-hoc.go @@ -36,7 +36,7 @@ type AdHocCommand struct { XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"` Node string `xml:"node,attr"` Action string `xml:"action,attr"` - SessionId string `xml:"sessionid,attr"` + SessionID string `xml:"sessionid,attr"` Status string `xml:"status,attr"` XForm AdHocXForm `xml:"x"` Note AdHocNote `xml:"note,omitempty"` diff --git a/src/xmpp/disco.go b/src/xmpp/disco.go index cf1bdcf..28f681b 100644 --- a/src/xmpp/disco.go +++ b/src/xmpp/disco.go @@ -6,8 +6,8 @@ import ( ) const ( - NsDiscoInfo = "http://jabber.org/protocol/disco#info" - NsDiscoItems = "http://jabber.org/protocol/disco#items" + NSDiscoInfo = "http://jabber.org/protocol/disco#info" + NSDiscoItems = "http://jabber.org/protocol/disco#items" ) // Service Discovery (XEP-0030) protocol. "Wraps" XMPP instance to provide a diff --git a/src/xmpp/softwareVersion.go b/src/xmpp/softwareVersion.go index 4e22cbf..a2fc7d5 100644 --- a/src/xmpp/softwareVersion.go +++ b/src/xmpp/softwareVersion.go @@ -5,7 +5,7 @@ import ( ) const ( - NsJabberClient = "jabber:iq:version" + NSJabberClient = "jabber:iq:version" ) // XEP-0092 Software Version diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 37f3270..8411b07 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -7,10 +7,10 @@ import ( ) const ( - IqTypeGet = "get" - IqTypeSet = "set" - IqTypeResult = "result" - IqTypeError = "error" + IQTypeGet = "get" + IQTypeSet = "set" + IQTypeResult = "result" + IQTypeError = "error" ) // XMPP stanza. diff --git a/src/xmpp/uuid.go b/src/xmpp/uuid.go index 2d8779d..a18e661 100644 --- a/src/xmpp/uuid.go +++ b/src/xmpp/uuid.go @@ -5,6 +5,10 @@ import ( "fmt" ) +const ( + dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +) + // Generate a UUID4. func UUID4() string { uuid := make([]byte, 16) @@ -16,13 +20,11 @@ func UUID4() string { return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]) } -func SessionId() string { - var strSize = 15 - var dictionary string - dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - - var bytes = make([]byte, strSize) - rand.Read(bytes) +func SessionID() string { + var bytes = make([]byte, 15) + if _, err := rand.Read(bytes); err != nil { + panic(err) + } for k, v := range bytes { bytes[k] = dictionary[v%byte(len(dictionary))] } diff --git a/src/xmpp/vcard.go b/src/xmpp/vcard.go index 06ba65b..0fe9175 100644 --- a/src/xmpp/vcard.go +++ b/src/xmpp/vcard.go @@ -5,7 +5,7 @@ import ( ) const ( - NsVCardTemp = "vcard-temp" + NSVCardTemp = "vcard-temp" ) // XEP-0054 vCard From da8d10515435cd7eece4bf55f42e6ed3f44da5cd Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 18 May 2016 22:27:03 +0200 Subject: [PATCH 06/30] Fix missing change in disco --- src/xmpp/disco.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xmpp/disco.go b/src/xmpp/disco.go index 28f681b..32de1f7 100644 --- a/src/xmpp/disco.go +++ b/src/xmpp/disco.go @@ -57,7 +57,7 @@ func (disco *Disco) Info(to, from string) (*DiscoInfo, error) { from = disco.XMPP.JID.Full() } - req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from} + req := &Iq{Id: UUID4(), Type: IQTypeGet, To: to, From: from} req.PayloadEncode(&DiscoInfo{}) resp, err := disco.XMPP.SendRecv(req) @@ -80,7 +80,7 @@ func (disco *Disco) Items(to, from, node string) (*DiscoItems, error) { from = disco.XMPP.JID.Full() } - req := &Iq{Id: UUID4(), Type: IqTypeGet, To: to, From: from} + req := &Iq{Id: UUID4(), Type: IQTypeGet, To: to, From: from} req.PayloadEncode(&DiscoItems{Node: node}) resp, err := disco.XMPP.SendRecv(req) @@ -96,7 +96,7 @@ func (disco *Disco) Items(to, from, node string) (*DiscoItems, error) { return items, err } -var discoNamespacePrefix = strings.Split(NsDiscoInfo, "#")[0] +var discoNamespacePrefix = strings.Split(NSDiscoInfo, "#")[0] // Matcher instance to match stanzas with a disco payload. var DiscoPayloadMatcher = MatcherFunc( From 934c81ee39e3796dc8e6a07502fc7dcc3e040d77 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 20 Jun 2016 21:28:11 +0200 Subject: [PATCH 07/30] Add implementation of xep-0070 --- src/xmpp/httpAuth.go | 18 ++++++++++++++++++ src/xmpp/stanza.go | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 src/xmpp/httpAuth.go diff --git a/src/xmpp/httpAuth.go b/src/xmpp/httpAuth.go new file mode 100644 index 0000000..0e53ef6 --- /dev/null +++ b/src/xmpp/httpAuth.go @@ -0,0 +1,18 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSHTTPAuth = "http://jabber.org/protocol/http-auth" +) + + +// XEP-0070: Verifying HTTP Requests via XMPP +type Confirm struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/http-auth confirm"` + Id string `xml:"id,attr"` + Method string `xml:"method,attr"` + URL string `xml:"url,attr"` +} diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 8411b07..8717f3d 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -70,6 +70,9 @@ type Message struct { From string `xml:"from,attr,omitempty"` Subject string `xml:"subject,omitempty"` Body string `xml:"body,omitempty"` + Thread string `xml:"thread,omitempty"` + Error *Error `xml:"error"` + Confir *Confirm `xml:"confirm"` } // XMPP stanza. From 5b2aa0c077dff6d20d1faa56c8be4c9ab97b9b27 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 18 Jul 2016 18:18:18 +0200 Subject: [PATCH 08/30] Replace URL namespace in an ugly way to avoid unmarshal error --- src/xmpp/httpAuth.go | 9 ++++----- src/xmpp/stream.go | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/xmpp/httpAuth.go b/src/xmpp/httpAuth.go index 0e53ef6..0f9b21f 100644 --- a/src/xmpp/httpAuth.go +++ b/src/xmpp/httpAuth.go @@ -8,11 +8,10 @@ const ( NSHTTPAuth = "http://jabber.org/protocol/http-auth" ) - // XEP-0070: Verifying HTTP Requests via XMPP type Confirm struct { - XMLName xml.Name `xml:"http://jabber.org/protocol/http-auth confirm"` - Id string `xml:"id,attr"` - Method string `xml:"method,attr"` - URL string `xml:"url,attr"` + XMLName xml.Name `xml:"http://jabber.org/protocol/http-auth confirm"` + Id string `xml:"id,attr"` + Method string `xml:"method,attr"` + URL string `xml:"url,attr"` } diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 0919ed3..31bc7f2 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -163,6 +163,13 @@ func nextStartElement(dec *xml.Decoder) (*xml.StartElement, error) { } switch e := t.(type) { case xml.StartElement: + for i, _ := range e.Attr { + // Replace URL namespace to xml in order to avoid error on Unmarshal + // It's quite ugly, but working for now + if e.Attr[i].Name.Space == "http://www.w3.org/XML/1998/namespace" { + e.Attr[i].Name.Space = "xml" + } + } return &e, nil case xml.EndElement: log.Printf("EOF due to %s\n", e.Name) From 3f618b50f558dea6daf13c71a7def3a4371a40ea Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 18 Jul 2016 20:12:28 +0200 Subject: [PATCH 09/30] Add message type and error condition --- src/xmpp/stanza.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 8717f3d..a21b5d1 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -11,6 +11,10 @@ const ( IQTypeSet = "set" IQTypeResult = "result" IQTypeError = "error" + + MessageTypeNormal = "normal" + MessageTypeChat = "chat" + MessageTypeError = "error" ) // XMPP stanza. @@ -166,4 +170,6 @@ type ErrorCondition xml.Name // Stanza errors. var ( FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} + RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} + ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} ) From d90f7642e3cf572e0ce84383c35c62dbfabe0c5b Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sat, 23 Jul 2016 11:58:03 +0200 Subject: [PATCH 10/30] Add not authorized error condition --- src/xmpp/stanza.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index a21b5d1..33c4b0c 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -172,4 +172,5 @@ var ( FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} + NotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"} ) From 30ec9e14fb788c4a918aca189c4bbc7a80d28ecc Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sat, 23 Jul 2016 11:59:21 +0200 Subject: [PATCH 11/30] [fix] Add domain name in Stream to get TLS working --- src/xmpp/client.go | 2 +- src/xmpp/dns.go | 13 ++++++++++++- src/xmpp/stream.go | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 34941d8..8e5b817 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -115,7 +115,7 @@ func startTLS(stream *Stream, config *ClientConfig) error { return err } - tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify} + tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.connDomain} return stream.UpgradeTLS(&tlsConfig) } diff --git a/src/xmpp/dns.go b/src/xmpp/dns.go index 4b1d136..757ba38 100644 --- a/src/xmpp/dns.go +++ b/src/xmpp/dns.go @@ -27,7 +27,18 @@ func HomeServerAddrs(jid JID) (addr []string, err error) { // Build list of "host:port" strings. for _, a := range addrs { - addr = append(addr, fmt.Sprintf("%s:%d", a.Target, a.Port)) + target := parseTargetDomainName(a.Target) + addr = append(addr, fmt.Sprintf("%s:%d", target, a.Port)) + } + return +} + +// Remove the last dot in the domain name if exist +func parseTargetDomainName(domainName string) (ret string) { + if domainName[len(domainName)-1] == '.' { + ret = parseTargetDomainName(domainName[:len(domainName)-1]) + } else { + ret = domainName } return } diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 31bc7f2..b1cd8d5 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -7,6 +7,7 @@ import ( "io" "log" "net" + "strings" ) // Stream configuration. @@ -24,6 +25,7 @@ type Stream struct { config *StreamConfig stanzaBuf string incomingNamespace nsMap + connDomain string } // Create a XML stream connection. A Steam is used by an XMPP instance to @@ -41,7 +43,7 @@ func NewStream(addr string, config *StreamConfig) (*Stream, error) { return nil, err } - stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config} + stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config, connDomain: strings.SplitN(addr, ":", 2)[0]} if err := stream.send([]byte("")); err != nil { return nil, err From d4c5b8f4dadc06dffee9e3f8b71aa4c2bff9abe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 11 Aug 2016 11:28:46 +0200 Subject: [PATCH 12/30] =?UTF-8?q?Rename=20the=20ad-hoc=20status=20?= =?UTF-8?q?=E2=80=9Cexecute=E2=80=9D=20into=20=E2=80=9Cexecuting=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From http://xmpp.org/extensions/xep-0050.html#desc-command only “executing” is valid. --- src/xmpp/ad-hoc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go index 028bee1..2466408 100644 --- a/src/xmpp/ad-hoc.go +++ b/src/xmpp/ad-hoc.go @@ -11,7 +11,7 @@ const ( ActionAdHocNext = "next" ActionAdHocCancel = "cancel" - StatusAdHocExecute = "execute" + StatusAdHocExecute = "executing" StatusAdHocCompleted = "completed" StatusAdHocCanceled = "canceled" From 8b007c8bc8949b243533659f477d38ced9d74d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 11 Aug 2016 11:29:41 +0200 Subject: [PATCH 13/30] Add text-private in the possible ad-hoc field types --- src/xmpp/ad-hoc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go index 2466408..182089b 100644 --- a/src/xmpp/ad-hoc.go +++ b/src/xmpp/ad-hoc.go @@ -30,6 +30,7 @@ const ( TypeAdHocFieldListSingle = "list-single" TypeAdHocFieldTextSingle = "text-single" TypeAdHocFieldJidSingle = "jid-single" + TypeAdHocFieldTextPrivate = "text-private" ) type AdHocCommand struct { From 72135514fcb1e3ad5c5e8f35f76b8e2f3c9370f9 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 15 Aug 2016 22:37:28 +0200 Subject: [PATCH 14/30] Fix certificat domain check in case of SRV --- src/xmpp/ad-hoc.go | 8 ++++---- src/xmpp/client.go | 2 +- src/xmpp/stream.go | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go index 182089b..95e1f00 100644 --- a/src/xmpp/ad-hoc.go +++ b/src/xmpp/ad-hoc.go @@ -26,10 +26,10 @@ const ( TypeAdHocNoteWarning = "warn" TypeAdHocNoteError = "error" - TypeAdHocFieldListMulti = "list-multi" - TypeAdHocFieldListSingle = "list-single" - TypeAdHocFieldTextSingle = "text-single" - TypeAdHocFieldJidSingle = "jid-single" + TypeAdHocFieldListMulti = "list-multi" + TypeAdHocFieldListSingle = "list-single" + TypeAdHocFieldTextSingle = "text-single" + TypeAdHocFieldJidSingle = "jid-single" TypeAdHocFieldTextPrivate = "text-private" ) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 8e5b817..a53d920 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -115,7 +115,7 @@ func startTLS(stream *Stream, config *ClientConfig) error { return err } - tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.connDomain} + tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.config.ConnectionDomain} return stream.UpgradeTLS(&tlsConfig) } diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index b1cd8d5..5ee18b5 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -17,6 +17,9 @@ type StreamConfig struct { // are either sent to the server or delivered to the application. It also // causes incoming stanzas to be XML-parsed a second time. LogStanzas bool + + // The dommain connection for certificat validation. + ConnectionDomain string } type Stream struct { @@ -25,7 +28,6 @@ type Stream struct { config *StreamConfig stanzaBuf string incomingNamespace nsMap - connDomain string } // Create a XML stream connection. A Steam is used by an XMPP instance to @@ -43,7 +45,10 @@ func NewStream(addr string, config *StreamConfig) (*Stream, error) { return nil, err } - stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config, connDomain: strings.SplitN(addr, ":", 2)[0]} + stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config} + if config.ConnectionDomain == "" { + config.ConnectionDomain = strings.SplitN(addr, ":", 2)[0] + } if err := stream.send([]byte("")); err != nil { return nil, err From 6859516f81098d97e9baa021d2ae534e50b15712 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sat, 20 Aug 2016 22:43:20 +0200 Subject: [PATCH 15/30] =?UTF-8?q?Add=20log=20when=20threads=20=C2=AB=C2=A0?= =?UTF-8?q?sender=C2=A0=C2=BB=20and=20=C2=AB=C2=A0receiver=C2=A0=C2=BB=20e?= =?UTF-8?q?nd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xmpp/xmpp.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 3137897..72d79db 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -169,6 +169,7 @@ func (x *XMPP) sender() { // Close the stream. Note: relies on common element name for all types of // XMPP connection. + log.Println("Close XMPP stream") x.stream.SendEnd(&xml.EndElement{xml.Name{"stream", "stream"}}) } @@ -214,6 +215,8 @@ func (x *XMPP) receiver() { x.In <- v } } + + log.Println("Close XMPP receiver") } // BUG(matt): Filter channels are not closed when the stream is closed. From 97363908e130a9c5485ae3f49b2fed205a426ca0 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 4 Sep 2016 14:49:59 +0200 Subject: [PATCH 16/30] Remove all log.Fatal() that make exit(1) any application that use this lib. --- src/xmpp/xmpp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 72d79db..dd07b4e 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -195,12 +195,12 @@ func (x *XMPP) receiver() { case "presence": v = &Presence{} default: - log.Fatal("Unexected element: %T %v", start, start) + log.Println("Error. Unexected element: %T %v", start, start) } err = x.stream.Decode(v, start) if err != nil { - log.Fatal(err) + log.Println("Error. Failed to decode element. ", err) } filtered := false From dacdc4ac04acc450e1d107f6e90c9ae3522ee1ff Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 4 Sep 2016 14:52:07 +0200 Subject: [PATCH 17/30] Add support for chatstates notification (XEP-0085) --- src/xmpp/chatStateNotification.go | 27 +++++++++++++++++++++++++++ src/xmpp/stanza.go | 9 ++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/xmpp/chatStateNotification.go diff --git a/src/xmpp/chatStateNotification.go b/src/xmpp/chatStateNotification.go new file mode 100644 index 0000000..e2b80b0 --- /dev/null +++ b/src/xmpp/chatStateNotification.go @@ -0,0 +1,27 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSChatStatesNotification = "http://jabber.org/protocol/chatstates" +) + +// XEP-0085: Chat States Notification + +type Active struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/chatstates active"` +} +type Composing struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/chatstates composing"` +} +type Paused struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/chatstates paused"` +} +type Inactive struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/chatstates inactive"` +} +type Gone struct { + XMLName xml.Name `xml:"http://jabber.org/protocol/chatstates gone"` +} diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 33c4b0c..632da6d 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -76,7 +76,14 @@ type Message struct { Body string `xml:"body,omitempty"` Thread string `xml:"thread,omitempty"` Error *Error `xml:"error"` - Confir *Confirm `xml:"confirm"` + + Confir *Confirm `xml:"confirm"` // XEP-0070 + + Active *Active `xml:"active"` // XEP-0085 + Composing *Composing `xml:"composing"` // XEP-0085 + Paused *Paused `xml:"paused"` // XEP-0085 + Inactive *Inactive `xml:"inactive"` // XEP-0085 + Gone *Gone `xml:"gone"` // XEP-0085 } // XMPP stanza. From a52f910d6245aa9bdd051dd42f8e45d1c889d5ba Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Thu, 15 Sep 2016 09:33:21 +0200 Subject: [PATCH 18/30] Add code error in Error struct. --- src/xmpp/stanza.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 632da6d..237999b 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -103,6 +103,7 @@ type Presence struct { // stanza, e.g. an . type Error struct { XMLName xml.Name `xml:"error"` + Code string `xml:"code,attr,omitempty"` Type string `xml:"type,attr"` Payload string `xml:",innerxml"` } @@ -141,6 +142,12 @@ func NewError(errorType string, condition ErrorCondition, text string) *Error { return &Error{Type: errorType, Payload: string(buf.Bytes())} } +func NewErrorWithCode(code, errorType string, condition ErrorCondition, text string) *Error { + err := NewError(errorType, condition, text) + err.Code = code + return err +} + // Return the error text from the payload, or "" if not present. func (e Error) Text() string { dec := xml.NewDecoder(bytes.NewBufferString(e.Payload)) @@ -176,8 +183,10 @@ type ErrorCondition xml.Name // Stanza errors. var ( - FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} - RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} - ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} - NotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"} + ErrorFeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} + ErrorRemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} + ErrorServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} + ErrorNotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"} + ErrorConflict = ErrorCondition{nsErrorStanzas, "conflict"} + ErrorNotAcceptable = ErrorCondition{nsErrorStanzas, "not-acceptable"} ) From eccf5059427bd59888e3d1b17d69a3fc0fdc2005 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Thu, 15 Sep 2016 09:33:54 +0200 Subject: [PATCH 19/30] Add In-Band Registration support. --- src/xmpp/register.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/xmpp/register.go diff --git a/src/xmpp/register.go b/src/xmpp/register.go new file mode 100644 index 0000000..6018d2d --- /dev/null +++ b/src/xmpp/register.go @@ -0,0 +1,29 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSRegister = "jabber:iq:register" +) + +// XEP-0077: In-Band Registration + +type RegisterQuery struct { + XMLName xml.Name `xml:"jabber:iq:register query"` + Instructions string `xml:"instructions"` + Username string `xml:"username"` + Password string `xml:"password"` + XForm AdHocXForm `xml:"x"` + Registered *RegisterRegistered `xmp:"registered"` + Remove *RegisterRemove `xmp:"remove"` +} + +type RegisterRegistered struct { + XMLName xml.Name `xml:"registered"` +} + +type RegisterRemove struct { + XMLName xml.Name `xml:"remove"` +} From f1443ca444b7566f69e0f9d2e0fe31a0d7c923c5 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 18 Sep 2016 07:38:18 +0200 Subject: [PATCH 20/30] Change position of close XMPP receiver log. --- src/xmpp/xmpp.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index dd07b4e..3be89a7 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -175,7 +175,10 @@ func (x *XMPP) sender() { func (x *XMPP) receiver() { - defer close(x.In) + defer func() { + log.Println("Close XMPP receiver") + close(x.In) + }() for { start, err := x.stream.Next() @@ -215,8 +218,7 @@ func (x *XMPP) receiver() { x.In <- v } } - - log.Println("Close XMPP receiver") } // BUG(matt): Filter channels are not closed when the stream is closed. + From 0aac61b1cc0251ed124ea5bcc0697e60ab3f3961 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 5 Oct 2016 21:22:32 +0200 Subject: [PATCH 21/30] Add error forbidden. --- src/xmpp/stanza.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 237999b..93431b7 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -189,4 +189,5 @@ var ( ErrorNotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"} ErrorConflict = ErrorCondition{nsErrorStanzas, "conflict"} ErrorNotAcceptable = ErrorCondition{nsErrorStanzas, "not-acceptable"} + ErrorForbidden = ErrorCondition{nsErrorStanzas, "forbidden"} ) From e4acd3d34934324d94a738f1168fe641c46c3129 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 5 Oct 2016 21:23:56 +0200 Subject: [PATCH 22/30] Add Close method on *XMPP. --- src/xmpp/xmpp.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 3be89a7..0da7d81 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -170,13 +170,14 @@ func (x *XMPP) sender() { // Close the stream. Note: relies on common element name for all types of // XMPP connection. log.Println("Close XMPP stream") - x.stream.SendEnd(&xml.EndElement{xml.Name{"stream", "stream"}}) + x.Close() } func (x *XMPP) receiver() { defer func() { log.Println("Close XMPP receiver") + x.Close() close(x.In) }() @@ -220,5 +221,9 @@ func (x *XMPP) receiver() { } } -// BUG(matt): Filter channels are not closed when the stream is closed. +func (x *XMPP) Close() { + log.Println("Close XMPP") + x.stream.SendEnd(&xml.EndElement{xml.Name{"stream", "stream"}}) +} +// BUG(matt): Filter channels are not closed when the stream is closed. From 7d5b58fc8db5be584e81c9123aaec2d7e6cb1f60 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 5 Oct 2016 21:24:36 +0200 Subject: [PATCH 23/30] Add support of ping (XEP-0199). --- src/xmpp/ping.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/xmpp/ping.go diff --git a/src/xmpp/ping.go b/src/xmpp/ping.go new file mode 100644 index 0000000..b6adfa0 --- /dev/null +++ b/src/xmpp/ping.go @@ -0,0 +1,13 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSPing = "urn:xmpp:ping" +) + +type Ping struct { + XMLName xml.Name `xml:"urn:xmpp:ping ping"` +} From 0490e0a087b9d67fc9e19fa6aa5c0768ef33337f Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Wed, 5 Oct 2016 21:26:42 +0200 Subject: [PATCH 24/30] Add support of Remote Roster Manager (XEP-0321). --- src/xmpp/remoteRosterManager.go | 21 +++++++++++++++++++++ src/xmpp/roster.go | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/xmpp/remoteRosterManager.go create mode 100644 src/xmpp/roster.go diff --git a/src/xmpp/remoteRosterManager.go b/src/xmpp/remoteRosterManager.go new file mode 100644 index 0000000..83ce91b --- /dev/null +++ b/src/xmpp/remoteRosterManager.go @@ -0,0 +1,21 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSRemoteRosterManager = "urn:xmpp:tmp:roster-management:0" + + RemoteRosterManagerTypeRequest = "request" + RemoteRosterManagerTypeAllowed = "allowed" + RemoteRosterManagerTypeRejected = "rejected" +) + +// XEP-0321: Remote Roster Manager + +type RemoteRosterManagerQuery struct { + XMLName xml.Name `xml:"urn:xmpp:tmp:roster-management:0 query"` + Reason string `xml:"reason,attr,omitempty"` + Type string `xml:"type,attr"` +} diff --git a/src/xmpp/roster.go b/src/xmpp/roster.go new file mode 100644 index 0000000..19272b9 --- /dev/null +++ b/src/xmpp/roster.go @@ -0,0 +1,26 @@ +package xmpp + +import ( + "encoding/xml" +) + +const ( + NSRoster = "jabber:iq:roster" + + RosterSubscriptionBoth = "both" + RosterSubscriptionFrom = "from" + RosterSubscriptionTo = "to" + RosterSubscriptionRemove = "remove" +) + +type RosterQuery struct { + XMLName xml.Name `xml:"jabber:iq:roster query"` + Items []RosterItem `xml:"item"` +} + +type RosterItem struct { + JID string `xml:"jid,attr"` + Name string `xml:"name,attr,omitempty"` + Subscription string `xml:"subscription,attr"` + Groupes []string `xml:"group"` +} From 4df4e9cec28ecb9bf31ebf192dba91276a4c9aa4 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sun, 13 Nov 2016 20:25:47 +0100 Subject: [PATCH 25/30] Add support for multi body in message with lang definition. --- src/xmpp/stanza.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index 93431b7..b26f3f3 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -67,15 +67,16 @@ func (iq *Iq) Response(type_ string) *Iq { // XMPP stanza. type Message struct { - XMLName xml.Name `xml:"message"` - Id string `xml:"id,attr,omitempty"` - Type string `xml:"type,attr,omitempty"` - To string `xml:"to,attr,omitempty"` - From string `xml:"from,attr,omitempty"` - Subject string `xml:"subject,omitempty"` - Body string `xml:"body,omitempty"` - Thread string `xml:"thread,omitempty"` - Error *Error `xml:"error"` + XMLName xml.Name `xml:"message"` + Id string `xml:"id,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + To string `xml:"to,attr,omitempty"` + From string `xml:"from,attr,omitempty"` + Subject string `xml:"subject,omitempty"` + Body []MessageBody `xml:"body,omitempty"` + Thread string `xml:"thread,omitempty"` + Error *Error `xml:"error"` + Lang string `xml:"xml:lang,attr,omitempty"` Confir *Confirm `xml:"confirm"` // XEP-0070 @@ -86,6 +87,11 @@ type Message struct { Gone *Gone `xml:"gone"` // XEP-0085 } +type MessageBody struct { + Lang string `xml:"xml:lang,attr,omitempty"` + Value string `xml:",innerxml"` +} + // XMPP stanza. type Presence struct { XMLName xml.Name `xml:"presence"` From 5cfc61169b8d932f6306ccc0e10fe0e563ad40b7 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 14 Nov 2016 17:43:04 +0100 Subject: [PATCH 26/30] Fix a small bug introduced in lang support. --- src/xmpp/stanza.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index b26f3f3..e112e6e 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -89,7 +89,7 @@ type Message struct { type MessageBody struct { Lang string `xml:"xml:lang,attr,omitempty"` - Value string `xml:",innerxml"` + Value string `xml:",chardata"` } // XMPP stanza. From 3125d02cf6b842700239ca67ef5b7f96951d28b7 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Tue, 21 Mar 2017 22:17:01 +0100 Subject: [PATCH 27/30] Remove useless function that already exist in strings pakage. --- src/xmpp/dns.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/xmpp/dns.go b/src/xmpp/dns.go index 757ba38..78397a4 100644 --- a/src/xmpp/dns.go +++ b/src/xmpp/dns.go @@ -3,6 +3,7 @@ package xmpp import ( "fmt" "net" + "strings" ) const ( @@ -27,18 +28,8 @@ func HomeServerAddrs(jid JID) (addr []string, err error) { // Build list of "host:port" strings. for _, a := range addrs { - target := parseTargetDomainName(a.Target) + target := strings.TrimRight(a.Target, ".") addr = append(addr, fmt.Sprintf("%s:%d", target, a.Port)) } return } - -// Remove the last dot in the domain name if exist -func parseTargetDomainName(domainName string) (ret string) { - if domainName[len(domainName)-1] == '.' { - ret = parseTargetDomainName(domainName[:len(domainName)-1]) - } else { - ret = domainName - } - return -} From b32173d11ee4d822df7b73704748802d4a9843ca Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Tue, 21 Mar 2017 22:18:23 +0100 Subject: [PATCH 28/30] Fix typo on Confirm message. --- src/xmpp/stanza.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/stanza.go b/src/xmpp/stanza.go index e112e6e..4d48bf1 100644 --- a/src/xmpp/stanza.go +++ b/src/xmpp/stanza.go @@ -78,7 +78,7 @@ type Message struct { Error *Error `xml:"error"` Lang string `xml:"xml:lang,attr,omitempty"` - Confir *Confirm `xml:"confirm"` // XEP-0070 + Confirm *Confirm `xml:"confirm"` // XEP-0070 Active *Active `xml:"active"` // XEP-0085 Composing *Composing `xml:"composing"` // XEP-0085 From 2d4531739aad3c1e29ad41da6272af15c17df214 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Tue, 21 Mar 2017 22:19:01 +0100 Subject: [PATCH 29/30] Fix typo. --- src/xmpp/stream.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 5ee18b5..d2dc777 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -18,7 +18,7 @@ type StreamConfig struct { // causes incoming stanzas to be XML-parsed a second time. LogStanzas bool - // The dommain connection for certificat validation. + // The dommain connection for certificate validation. ConnectionDomain string } From 6465ebd169f4d996519c45d541b04146975f9ea9 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Tue, 21 Mar 2017 22:21:01 +0100 Subject: [PATCH 30/30] go fmt --- src/xmpp/ping.go | 4 ++-- src/xmpp/remoteRosterManager.go | 6 +++--- src/xmpp/roster.go | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/xmpp/ping.go b/src/xmpp/ping.go index b6adfa0..a5f3180 100644 --- a/src/xmpp/ping.go +++ b/src/xmpp/ping.go @@ -5,9 +5,9 @@ import ( ) const ( - NSPing = "urn:xmpp:ping" + NSPing = "urn:xmpp:ping" ) type Ping struct { - XMLName xml.Name `xml:"urn:xmpp:ping ping"` + XMLName xml.Name `xml:"urn:xmpp:ping ping"` } diff --git a/src/xmpp/remoteRosterManager.go b/src/xmpp/remoteRosterManager.go index 83ce91b..4764680 100644 --- a/src/xmpp/remoteRosterManager.go +++ b/src/xmpp/remoteRosterManager.go @@ -7,9 +7,9 @@ import ( const ( NSRemoteRosterManager = "urn:xmpp:tmp:roster-management:0" - RemoteRosterManagerTypeRequest = "request" - RemoteRosterManagerTypeAllowed = "allowed" - RemoteRosterManagerTypeRejected = "rejected" + RemoteRosterManagerTypeRequest = "request" + RemoteRosterManagerTypeAllowed = "allowed" + RemoteRosterManagerTypeRejected = "rejected" ) // XEP-0321: Remote Roster Manager diff --git a/src/xmpp/roster.go b/src/xmpp/roster.go index 19272b9..8b9f126 100644 --- a/src/xmpp/roster.go +++ b/src/xmpp/roster.go @@ -5,7 +5,7 @@ import ( ) const ( - NSRoster = "jabber:iq:roster" + NSRoster = "jabber:iq:roster" RosterSubscriptionBoth = "both" RosterSubscriptionFrom = "from" @@ -14,13 +14,13 @@ const ( ) type RosterQuery struct { - XMLName xml.Name `xml:"jabber:iq:roster query"` - Items []RosterItem `xml:"item"` + XMLName xml.Name `xml:"jabber:iq:roster query"` + Items []RosterItem `xml:"item"` } type RosterItem struct { - JID string `xml:"jid,attr"` - Name string `xml:"name,attr,omitempty"` - Subscription string `xml:"subscription,attr"` - Groupes []string `xml:"group"` + JID string `xml:"jid,attr"` + Name string `xml:"name,attr,omitempty"` + Subscription string `xml:"subscription,attr"` + Groupes []string `xml:"group"` }