From ec68a04554acd448e546f0119c059c18ca404aa2 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Thu, 11 Jan 2018 22:15:54 +0100 Subject: [PATCH] Component skeleton --- cmd/xmpp_component/xmpp_component.go | 7 ++++++ component.go | 37 ++++++++++++++++++++++++++++ ns.go | 13 +++++----- 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 cmd/xmpp_component/xmpp_component.go create mode 100644 component.go diff --git a/cmd/xmpp_component/xmpp_component.go b/cmd/xmpp_component/xmpp_component.go new file mode 100644 index 0000000..65c0e4b --- /dev/null +++ b/cmd/xmpp_component/xmpp_component.go @@ -0,0 +1,7 @@ +package main + +import "fluux.io/xmpp" + +func main() { + xmpp.Open("test") +} diff --git a/component.go b/component.go new file mode 100644 index 0000000..d457d88 --- /dev/null +++ b/component.go @@ -0,0 +1,37 @@ +package xmpp + +import ( + "fmt" + "net" + "time" +) + +const componentStreamOpen = "" + +// Component implements an XMPP extension allowing to extend XMPP server +// using external components. Component specifications are defined +// in XEP-0114, XEP-0355 and XEP-0356. +type Component struct { + // TCP level connection + conn net.Conn +} + +// TODO Helper to prepare connection string +func Open(connStr string) error { + var conn net.Conn + var err error + + if conn, err = net.DialTimeout("tcp", "localhost:8888", time.Duration(5)*time.Second); err != nil { + return err + } + + // TODO send stream open and check for reply + // Send stream open tag + componentHost := "mqtt.localhost" + if _, err := fmt.Fprintf(conn, componentStreamOpen, componentHost, NSComponent, NSStream); err != nil { + fmt.Println("Cannot send stream open.") + return err + } + + return nil +} diff --git a/ns.go b/ns.go index 9b3bdac..9cd162c 100644 --- a/ns.go +++ b/ns.go @@ -1,10 +1,11 @@ package xmpp // import "fluux.io/xmpp" const ( - NSStream = "http://etherx.jabber.org/streams" - nsTLS = "urn:ietf:params:xml:ns:xmpp-tls" - nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl" - nsBind = "urn:ietf:params:xml:ns:xmpp-bind" - nsSession = "urn:ietf:params:xml:ns:xmpp-session" - NSClient = "jabber:client" + NSStream = "http://etherx.jabber.org/streams" + nsTLS = "urn:ietf:params:xml:ns:xmpp-tls" + nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl" + nsBind = "urn:ietf:params:xml:ns:xmpp-bind" + nsSession = "urn:ietf:params:xml:ns:xmpp-session" + NSClient = "jabber:client" + NSComponent = "jabber:component:accept" )