Pārlūkot izejas kodu

ревизия импортов

kpmy 9 gadi atpakaļ
vecāks
revīzija
d459917b49

+ 1 - 1
README.md

@@ -1,2 +1,2 @@
 # xep
-golang xmpp client
+golang@c.j.r chat-bot

+ 0 - 66
c2s/actors/act.go

@@ -1,66 +0,0 @@
-package actors
-
-import (
-	"sync"
-	"xep/c2s/stream"
-)
-
-type Continue interface {
-	Do(func(stream.Stream) error, ...func(error)) Continue
-	Run()
-}
-
-type step struct {
-	s   stream.Stream
-	act func(stream.Stream) error
-	err func(error)
-}
-
-type cont struct {
-	s     stream.Stream
-	steps []step
-}
-
-func With(s stream.Stream) Continue {
-	return &cont{s: s}
-}
-
-func (c *cont) Do(fn func(stream.Stream) error, err ...func(error)) Continue {
-	s := step{s: c.s}
-	s.act = fn
-	if len(err) > 0 {
-		s.err = err[0]
-	}
-	c.steps = append(c.steps, s)
-	return c
-}
-
-func (c *cont) Run() {
-	var next *cont
-	var this *step
-	if len(c.steps) > 0 {
-		this = &c.steps[0]
-	}
-	if len(c.steps) > 1 {
-		next = &cont{s: c.s}
-		next.steps = c.steps[1:]
-	}
-	if this != nil {
-		wg := &sync.WaitGroup{}
-		wg.Add(1)
-		go func(this *step, next *cont) {
-			if err := this.act(this.s); err == nil {
-				if next != nil {
-					next.Run()
-				}
-				wg.Done()
-			} else if this.err != nil {
-				this.err(err)
-				wg.Done()
-			} else {
-				panic(err)
-			}
-		}(this, next)
-		wg.Wait()
-	}
-}

+ 0 - 38
c2s/actors/steps/auth.go

@@ -1,38 +0,0 @@
-package steps
-
-import (
-	"bytes"
-	"log"
-	"reflect"
-	"xep/c2s/stream"
-	"xep/entity"
-	"xep/units"
-)
-
-type PlainAuth struct {
-	Client *units.Client
-	Pwd    string
-}
-
-func (p *PlainAuth) Act() func(stream.Stream) error {
-	return func(s stream.Stream) (err error) {
-		auth := &entity.PlainAuth{}
-		*auth = entity.PlainAuthPrototype
-		auth.Init(p.Client.Name, p.Pwd)
-		if err = s.Write(entity.ProduceStatic(auth)); err == nil {
-			s.Ring(func(b *bytes.Buffer) (done bool) {
-				var _e entity.Entity
-				if _e, err = entity.ConsumeStatic(b); err == nil {
-					switch e := _e.(type) {
-					case *entity.Success:
-						done = true
-					default:
-						log.Println(reflect.TypeOf(e))
-					}
-				}
-				return
-			}, 0)
-		}
-		return
-	}
-}

+ 0 - 63
c2s/actors/steps/bind.go

@@ -1,63 +0,0 @@
-package steps
-
-import (
-	"bytes"
-	"log"
-	"reflect"
-	"xep/c2s/stream"
-	"xep/entity"
-)
-
-type Bind struct {
-	Rsrc string
-}
-
-func (b *Bind) Act() func(s stream.Stream) error {
-	return func(s stream.Stream) (err error) {
-		bind := &entity.Bind{}
-		*bind = entity.BindPrototype
-		bind.Resource = b.Rsrc
-		iq := entity.IQ(entity.SET, bind)
-		if err = s.Write(entity.ProduceStatic(iq)); err == nil {
-			s.Ring(func(b *bytes.Buffer) (done bool) {
-				var _e entity.Entity
-				if _e, err = entity.ConsumeStatic(b); err == nil {
-					switch e := _e.(type) {
-					case *entity.Iq:
-						switch {
-						case e.Id == iq.Id && e.Type == entity.RESULT:
-							stream.Bind(s, e.Inner.(*entity.Bind).Jid)
-							done = true
-						}
-					default:
-						log.Println(reflect.TypeOf(e))
-					}
-				}
-				return
-			}, 0)
-		}
-		return
-	}
-}
-
-func Session(s stream.Stream) (err error) {
-	iq := entity.IQ(entity.SET, &entity.SessionPrototype)
-	if err = s.Write(entity.ProduceStatic(iq)); err == nil {
-		s.Ring(func(b *bytes.Buffer) (done bool) {
-			var _e entity.Entity
-			if _e, err = entity.ConsumeStatic(b); err == nil {
-				switch e := _e.(type) {
-				case *entity.Iq:
-					switch {
-					case e.Id == iq.Id && e.Type == entity.RESULT:
-						done = true
-					}
-				default:
-					log.Println(reflect.TypeOf(e))
-				}
-			}
-			return
-		}, 0)
-	}
-	return
-}

+ 0 - 70
c2s/actors/steps/first.go

@@ -1,70 +0,0 @@
-package steps
-
-import (
-	"bytes"
-	"errors"
-	"fmt"
-	"log"
-	"reflect"
-	"strings"
-	"xep/c2s/stream"
-	"xep/entity"
-)
-
-func Starter(s stream.Stream) (err error) {
-	if err = s.Write(entity.Open(s.Server()).Produce()); err == nil {
-		s.Ring(func(b *bytes.Buffer) (done bool) {
-			_e, e := entity.ConsumeStatic(b)
-			if _e != nil {
-				switch e := _e.(type) {
-				case *entity.Stream:
-					s.Id(e.Id)
-					done = true
-				default:
-					log.Println(reflect.TypeOf(e))
-				}
-			} else if e == nil {
-				err = errors.New(fmt.Sprint("unknown entity ", string(b.Bytes())))
-			} else {
-				err = e
-			}
-			return
-		}, 0)
-	}
-	return
-}
-
-type Negotiation struct {
-	AuthMechanisms []string
-}
-
-func (n *Negotiation) Act() func(stream.Stream) error {
-	return func(s stream.Stream) (err error) {
-		s.Ring(func(b *bytes.Buffer) (done bool) {
-			var _e entity.Entity
-			if _e, err = entity.ConsumeStatic(b); err == nil {
-				switch e := _e.(type) {
-				case *entity.Features:
-					n.AuthMechanisms = e.Mechanisms
-					done = true
-				default:
-					log.Println(reflect.TypeOf(e))
-				}
-			}
-			return
-		}, 0)
-		return
-	}
-}
-
-func (n *Negotiation) HasMechanism(mech string) (ok bool) {
-	if n.AuthMechanisms != nil {
-		for _, v := range n.AuthMechanisms {
-			if strings.ToLower(v) == strings.ToLower(mech) {
-				ok = true
-				break
-			}
-		}
-	}
-	return
-}

+ 0 - 20
c2s/actors/steps/presence.go

@@ -1,20 +0,0 @@
-package steps
-
-import (
-	"xep/c2s/stream"
-	"xep/entity"
-)
-
-func InitialPresence(s stream.Stream) (err error) {
-	err = s.Write(entity.ProduceStatic(&entity.PresencePrototype))
-	return
-}
-
-func PresenceTo(jid string) func(stream.Stream) error {
-	return func(s stream.Stream) error {
-		pr := &entity.Presence{}
-		*pr = entity.PresencePrototype
-		pr.To = jid
-		return s.Write(entity.ProduceStatic(pr))
-	}
-}

+ 0 - 148
c2s/stream/stream.go

@@ -1,148 +0,0 @@
-package stream
-
-import (
-	"bytes"
-	"errors"
-	"github.com/kpmy/ypk/halt"
-	"hash/adler32"
-	"log"
-	"net"
-	"reflect"
-	"time"
-	"xep/tools/srv"
-	"xep/units"
-)
-
-type Stream interface {
-	Server() *units.Server
-	Write(*bytes.Buffer) error
-	Ring(func(*bytes.Buffer) bool, time.Duration)
-	Id(...string) string
-}
-
-type wrapperStream struct {
-	base Stream
-}
-
-func (w *wrapperStream) Write(b *bytes.Buffer) error { return w.base.Write(b) }
-
-func (w *wrapperStream) Ring(fn func(*bytes.Buffer) bool, t time.Duration) {
-	w.base.Ring(fn, t)
-}
-
-func (w *wrapperStream) Server() *units.Server { return w.base.Server() }
-
-func (w *wrapperStream) Id(s ...string) string { return w.base.Id(s...) }
-
-type dummyStream struct {
-	to *units.Server
-}
-
-func (d *dummyStream) Ring(func(*bytes.Buffer) bool, time.Duration) { panic(126) }
-func (d *dummyStream) Write(b *bytes.Buffer) error                  { panic(126) }
-func (d *dummyStream) Server() *units.Server                        { return d.to }
-func (d *dummyStream) Id(...string) string                          { return "" }
-
-type xmppStream struct {
-	to   *units.Server
-	conn net.Conn
-	ctrl chan bool
-	data chan pack
-	id   string
-	jid  string
-}
-
-type pack struct {
-	data []byte
-	hash uint32
-}
-
-func (x *xmppStream) Id(s ...string) string {
-	if len(s) > 0 {
-		x.id = s[0]
-	}
-	return x.id
-}
-func (x *xmppStream) Server() *units.Server { return x.to }
-
-func (x *xmppStream) Write(b *bytes.Buffer) (err error) {
-	log.Println("OUT")
-	log.Println(string(b.Bytes()))
-	log.Println()
-	_, err = x.conn.Write(b.Bytes())
-	return
-}
-
-func (x *xmppStream) Ring(fn func(*bytes.Buffer) bool, timeout time.Duration) {
-	timed := make(chan bool)
-	if timeout > 0 {
-		go func() {
-			<-time.NewTimer(timeout).C
-			timed <- true
-		}()
-	}
-	for stop := false; !stop; {
-		select {
-		case p := <-x.data:
-			done := fn(bytes.NewBuffer(p.data))
-			if !done {
-				x.data <- pack{data: p.data, hash: p.hash}
-			} else {
-				stop = true
-			}
-		case <-timed:
-			stop = true
-		}
-	}
-}
-
-func New(to *units.Server) Stream {
-	return &wrapperStream{base: &dummyStream{to: to}}
-}
-
-func Bind(_s Stream, jid string) {
-	switch w := _s.(type) {
-	case *wrapperStream:
-		switch s := w.base.(type) {
-		case *xmppStream:
-			s.jid = jid
-		}
-	}
-}
-
-func Dial(_s Stream) (err error) {
-	switch w := _s.(type) {
-	case *wrapperStream:
-		switch s := w.base.(type) {
-		case *dummyStream:
-			x := &xmppStream{to: s.to}
-			var (
-				host, port string
-			)
-			if host, port, err = srv.Resolve(x.to); err == nil {
-				if x.conn, err = net.Dial("tcp", host+":"+port); err == nil {
-					x.ctrl = make(chan bool)
-					x.data = make(chan pack, 256)
-					go func(stream *xmppStream) {
-						<-stream.ctrl
-						stream.conn.Close()
-					}(x)
-					go func(stream *xmppStream) {
-						for data := range spl1t(stream.conn) {
-							log.Println("SPLIT")
-							log.Println(string(data))
-							log.Println()
-							stream.data <- pack{data: data, hash: adler32.Checksum(data)}
-						}
-					}(x)
-					w.base = x
-				}
-			}
-		default:
-			err = errors.New("already connected")
-		}
-	default:
-		halt.As(100, reflect.TypeOf(_s))
-	}
-	return
-}

+ 0 - 82
c2s/stream/xml.go

@@ -1,82 +0,0 @@
-package stream
-
-import (
-	"bytes"
-	"encoding/xml"
-	"github.com/kpmy/ypk/halt"
-	"io"
-	"reflect"
-)
-
-func spl1t(bunch io.Reader) (ret chan []byte) {
-	ret = make(chan []byte)
-	go func() {
-		d := xml.NewDecoder(bunch)
-		d.Strict = false
-		var (
-			_t  xml.Token
-			err error
-			buf *bytes.Buffer
-			e   *xml.Encoder
-		)
-		init := func() {
-			buf = bytes.NewBuffer(nil)
-			e = xml.NewEncoder(buf)
-		}
-		flush := func() {
-			e.Flush()
-			if buf.Len() > 0 {
-				ret <- buf.Bytes()
-			}
-			init()
-		}
-		join := func(n xml.Name) (ret string) {
-			if n.Space != "" {
-				ret = n.Space + ":"
-			}
-			ret = ret + n.Local
-			return
-		}
-		depth := 0
-		init()
-		for stop := false; !stop && err == nil; {
-			if _t, err = d.RawToken(); err == nil {
-				switch t := _t.(type) {
-				case xml.ProcInst:
-					e.EncodeToken(t.Copy())
-				case xml.StartElement:
-					tt := t.Copy()
-					tt.Name = xml.Name{Local: join(t.Name)}
-					var tmp []xml.Attr
-					for _, a := range tt.Attr {
-						a.Name = xml.Name{Local: join(a.Name)}
-						tmp = append(tmp, a)
-					}
-					tt.Attr = tmp
-					e.EncodeToken(tt)
-					if tt.Name.Local == "stream:stream" {
-						depth--
-						flush()
-					}
-					depth++
-				case xml.EndElement:
-					tt := t
-					tt.Name = xml.Name{Local: join(t.Name)}
-					e.EncodeToken(tt)
-					depth--
-					if depth == 0 {
-						flush()
-					}
-				case xml.CharData:
-					e.EncodeToken(t)
-				default:
-					halt.As(100, reflect.TypeOf(t))
-				}
-			} else {
-				flush()
-			}
-		}
-		close(ret)
-	}()
-	return
-}

+ 0 - 25
entity/bind-session.go

@@ -1,25 +0,0 @@
-package entity
-
-import (
-	"encoding/xml"
-)
-
-type Bind struct {
-	XMLName  xml.Name
-	Xmlns    string `xml:"xmlns,attr"`
-	Resource string `xml:"resource"`
-	Jid      string `xml:"jid"`
-}
-
-func (b *Bind) Init(rsrc string) {
-	b.Resource = rsrc
-}
-
-var BindPrototype = Bind{XMLName: xml.Name{Local: "bind"}, Xmlns: "urn:ietf:params:xml:ns:xmpp-bind"}
-
-type Session struct {
-	XMLName xml.Name
-	Xmlns   string `xml:"xmlns,attr"`
-}
-
-var SessionPrototype = Session{XMLName: xml.Name{Local: "session"}, Xmlns: "urn:ietf:params:xml:ns:xmpp-session"}

+ 0 - 29
entity/dyn/dyn.go

@@ -1,29 +0,0 @@
-package dyn
-
-import (
-	"math/rand"
-	"strconv"
-	"xep/entity"
-	"xep/tools/dom"
-)
-
-const (
-	PRESENCE = "presence"
-	IQ       = "iq"
-	MESSAGE  = "message"
-	TYPE     = "type"
-	ID       = "id"
-	BODY     = "body"
-	TO       = "to"
-)
-
-func NewMessage(typ entity.MessageType, to string, body string) (ret dom.Element) {
-	ret = dom.Elem(MESSAGE)
-	ret.Attr(TYPE, string(typ))
-	ret.Attr(ID, strconv.FormatInt(int64(rand.Intn(0xffffff)), 16))
-	ret.Attr(TO, to)
-	b := dom.Elem(BODY)
-	b.AppendChild(dom.Txt(body))
-	ret.AppendChild(b)
-	return
-}

+ 0 - 185
entity/entity.go

@@ -1,185 +0,0 @@
-package entity
-
-import (
-	"bytes"
-	"encoding/xml"
-	"errors"
-	"fmt"
-	"github.com/kpmy/ypk/halt"
-	"io"
-	"reflect"
-	"strings"
-	"xep/tools/dom"
-	"xep/units"
-)
-
-func ProduceStatic(i interface{}) *bytes.Buffer {
-	if data, err := xml.Marshal(i); err == nil {
-		return bytes.NewBuffer(data)
-	} else {
-		panic(err)
-	}
-}
-
-func ConsumeStatic(b *bytes.Buffer) (ret Entity, err error) {
-	d := &dumb{buf: b}
-	if err = xml.NewDecoder(d.buf).Decode(d); err == nil {
-		ret = d.x
-	}
-	return
-}
-
-func Decode(b *bytes.Buffer) (ret Entity, err error) {
-	dd := &domm{buf: b}
-	if err = dd.Unmarshal(); err == nil {
-		ret = dd
-	}
-	return
-}
-
-func Encode(el dom.Element) *bytes.Buffer {
-	dd := &domm{model: el}
-	return dd.Produce()
-}
-
-type Entity interface {
-	Model() dom.Element
-	Produce() *bytes.Buffer
-}
-
-type domm struct {
-	buf   *bytes.Buffer
-	model dom.Element
-}
-
-func (x *domm) Model() dom.Element {
-	return x.model
-}
-
-func (x *domm) Produce() (ret *bytes.Buffer) {
-	if data, err := xml.Marshal(x); err == nil {
-		ret = bytes.NewBuffer(data)
-	} else {
-		halt.As(100, ret)
-	}
-	return
-}
-
-func (x *domm) Unmarshal() (err error) {
-	d := xml.NewDecoder(x.buf)
-	var _t xml.Token
-	var this dom.Element
-	for stop := false; !stop && err == nil; {
-		if _t, err = d.RawToken(); err == nil {
-			switch t := _t.(type) {
-			case xml.StartElement:
-				el := dom.Elem(dom.ThisName(t.Name))
-				if x.model == nil {
-					x.model = el
-					this = el
-				} else {
-					this.AppendChild(el)
-					this = el
-				}
-				for _, a := range t.Attr {
-					this.Attr(dom.ThisName(a.Name), a.Value)
-				}
-			case xml.CharData:
-				if this != nil {
-					this.AppendChild(dom.Txt(string(t)))
-				} else {
-					stop = true
-				}
-			case xml.EndElement:
-				if this != nil {
-					if p := this.Parent(); p != nil {
-						this = p.(dom.Element)
-					} else {
-						stop = true
-					}
-				} else {
-					stop = true
-				}
-			case nil:
-			default:
-				halt.As(100, reflect.TypeOf(t))
-			}
-		}
-	}
-	return
-}
-
-func (x *domm) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) {
-	start.Name.Local = x.model.Name()
-	for k, v := range x.model.AttrAsMap() {
-		start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: k}, Value: v})
-	}
-	e.EncodeToken(start)
-	for _, _l := range x.model.Children() {
-		switch l := _l.(type) {
-		case dom.Element:
-			child := &domm{}
-			child.model = l
-			e.Encode(child)
-		case dom.Text:
-			e.EncodeToken(xml.CharData(l.Data()))
-		default:
-			halt.As(100, reflect.TypeOf(l))
-		}
-	}
-	e.EncodeToken(start.End())
-	return
-}
-
-type dumb struct {
-	buf *bytes.Buffer
-	x   Entity
-}
-
-func (x *dumb) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
-	if fact, ok := ns[start.Name]; ok {
-		x.x = fact(x.buf)
-		d.DecodeElement(x.x, &start)
-	} else {
-		err = errors.New(fmt.Sprint("unknown entity ", start.Name))
-	}
-	return
-}
-
-func (d *dumb) Produce() *bytes.Buffer {
-	return d.buf
-}
-
-func (d *dumb) Model() dom.Element {
-	panic(126)
-}
-
-func Open(s *units.Server) Entity {
-	buf := bytes.NewBuffer([]byte(xml.Header))
-	st := stream
-	st.To = s.Name
-	data := ProduceStatic(st)
-	pre := strings.TrimSuffix(string(data.Bytes()), "</stream:stream>")
-	io.Copy(buf, bytes.NewBufferString(pre))
-	return &dumb{buf: buf}
-}
-
-var ns map[xml.Name]func(*bytes.Buffer) Entity
-
-func init() {
-	ns = make(map[xml.Name]func(*bytes.Buffer) Entity)
-
-	ns[xml.Name{Space: "http://etherx.jabber.org/streams", Local: "stream"}] = func(buf *bytes.Buffer) Entity {
-		s := stream
-		buf.WriteString("</stream:stream>")
-		return &s
-	}
-
-	ns[xml.Name{Space: "stream", Local: "features"}] = func(*bytes.Buffer) Entity { return &Features{} }
-
-	ns[xml.Name{Space: "urn:ietf:params:xml:ns:xmpp-sasl", Local: "success"}] = func(*bytes.Buffer) Entity { return &Success{} }
-
-	ns[xml.Name{Local: "iq"}] = func(*bytes.Buffer) Entity { return &Iq{} }
-
-	ns[xml.Name{Local: "message"}] = func(*bytes.Buffer) Entity { return &Message{} }
-}

+ 0 - 33
entity/misc.go

@@ -1,33 +0,0 @@
-package entity
-
-import (
-	"bytes"
-	"encoding/xml"
-	"strings"
-	"xep/tools/dom"
-)
-
-func setAttr(start *xml.StartElement, name, value string) {
-	a := xml.Attr{}
-	a.Name.Local = name
-	a.Value = value
-	start.Attr = append(start.Attr, a)
-}
-
-func getAttr(start *xml.StartElement, name string) (value string) {
-	for _, v := range start.Attr {
-		if strings.ToLower(v.Name.Local) == strings.ToLower(name) {
-			value = v.Value
-			break
-		}
-	}
-	return
-}
-
-type dumbProducer struct{}
-
-func (d *dumbProducer) Produce() *bytes.Buffer { panic(126) }
-
-func (d *dumbProducer) Model() dom.Element {
-	panic(126)
-}

+ 0 - 29
entity/sasl-auth.go

@@ -1,29 +0,0 @@
-package entity
-
-import (
-	"bytes"
-	"encoding/base64"
-	"encoding/xml"
-)
-
-type PlainAuth struct {
-	XMLName   xml.Name
-	Xmlns     string `xml:"xmlns,attr"`
-	Mechanism string `xml:"mechanism,attr"`
-	Data      string `xml:",chardata"`
-}
-
-type Success struct {
-	dumbProducer
-}
-
-func (p *PlainAuth) Init(user, pwd string) {
-	data := bytes.NewBuffer([]byte(user + ":" + pwd))
-	data.WriteByte(0)
-	data.Write([]byte(user))
-	data.WriteByte(0)
-	data.Write([]byte(pwd))
-	p.Data = base64.StdEncoding.EncodeToString(data.Bytes())
-}
-
-var PlainAuthPrototype = PlainAuth{XMLName: xml.Name{Local: "auth"}, Xmlns: "urn:ietf:params:xml:ns:xmpp-sasl", Mechanism: "PLAIN"}

+ 0 - 6
entity/stream-features.go

@@ -1,6 +0,0 @@
-package entity
-
-type Features struct {
-	Mechanisms []string `xml:"mechanisms>mechanism"`
-	dumbProducer
-}

+ 0 - 35
entity/stream-stream.go

@@ -1,35 +0,0 @@
-package entity
-
-import (
-	"encoding/xml"
-	"errors"
-	"fmt"
-)
-
-type Stream struct {
-	XMLName xml.Name
-	Xmlns   string `xml:"xmlns,attr,omitempty"`
-	Version string `xml:"version,attr,omitempty"`
-	Stream  string `xml:"xmlns:stream,attr,omitempty"`
-	To      string `xml:"to,attr,omitempty"`
-	Id      string `xml:"-"`
-	dumbProducer
-}
-
-var stream Stream = Stream{XMLName: xml.Name{Local: "stream:stream"}, Version: "1.0", Xmlns: "jabber:client", Stream: "http://etherx.jabber.org/streams"}
-
-func (s *Stream) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
-	s.Id = getAttr(&start, "id")
-	var _t xml.Token
-	for stop := false; err == nil && !stop; {
-		if _t, err = d.Token(); err == nil {
-			switch t := _t.(type) {
-			case xml.EndElement:
-				stop = (start.Name == t.Name)
-			default:
-				err = errors.New(fmt.Sprint("unhandled ", t))
-			}
-		}
-	}
-	return
-}

+ 0 - 99
entity/xmpp-stanza.go

@@ -1,99 +0,0 @@
-package entity
-
-import (
-	"encoding/xml"
-	"github.com/kpmy/ypk/fn"
-	"math/rand"
-	"strconv"
-)
-
-type IqType string
-
-const (
-	SET    IqType = "set"
-	RESULT IqType = "result"
-)
-
-type MessageType string
-
-const (
-	GROUPCHAT MessageType = "groupchat"
-)
-
-type Iq struct {
-	XMLName xml.Name
-	Id      string      `xml:"id,attr,omitempty"`
-	Type    IqType      `xml:"type,attr"`
-	Inner   interface{} `xml:"iq"`
-	dumbProducer
-}
-
-func (i *Iq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
-	i.Id = getAttr(&start, "id")
-	i.Type = IqType(getAttr(&start, "type"))
-	var _t xml.Token
-	for stop := false; !stop && err == nil; {
-		_t, err = d.Token()
-		switch t := _t.(type) {
-		case xml.StartElement:
-			if fact, ok := us[t.Name]; ok {
-				i.Inner = fact()
-			}
-			if !fn.IsNil(i.Inner) {
-				d.DecodeElement(i.Inner, &t)
-			} else {
-				//halt.As(100, t.Name)
-			}
-		case xml.EndElement:
-			stop = t.Name == start.Name
-		default:
-			//halt.As(100, reflect.TypeOf(t))
-		}
-	}
-	return
-}
-
-var iq = Iq{XMLName: xml.Name{Local: "iq"}}
-
-func IQ(typ IqType, user interface{}) *Iq {
-	i := &Iq{}
-	*i = iq
-	i.Type = typ
-	i.Inner = user
-	i.Id = strconv.FormatInt(int64(rand.Intn(0xffffff)), 16)
-	return i
-}
-
-type Presence struct {
-	XMLName xml.Name
-	To      string `xml:"to,attr,omitempty"`
-}
-
-var PresencePrototype = Presence{XMLName: xml.Name{Local: "presence"}}
-
-type Message struct {
-	XMLName xml.Name
-	dumbProducer
-	Body string      `xml:"body,omitempty"`
-	From string      `xml:"from,attr,omitempty"`
-	To   string      `xml:"to,attr,omitempty"`
-	Type MessageType `xml:"type,attr,omitempty"`
-	Id   string      `xml:"id,attr,omitempty"`
-}
-
-var MessagePrototype = Message{XMLName: xml.Name{Local: "message"}}
-
-func MSG(typ MessageType) *Message {
-	m := &Message{}
-	*m = MessagePrototype
-	m.Type = typ
-	m.Id = strconv.FormatInt(int64(rand.Intn(0xffffff)), 16)
-	return m
-}
-
-var us map[xml.Name]func() interface{}
-
-func init() {
-	us = make(map[xml.Name]func() interface{})
-	us[xml.Name{Space: "urn:ietf:params:xml:ns:xmpp-bind", Local: "bind"}] = func() interface{} { return &Bind{} }
-}

+ 2 - 2
muc-client/luaexecutor/executor.go → luaexecutor/executor.go

@@ -3,10 +3,10 @@ package luaexecutor
 import (
 	"fmt"
 	"github.com/kpmy/go-lua"
+	"github.com/kpmy/xippo/c2s/stream"
+	"github.com/kpmy/xippo/entity"
 	"sync"
 	"time"
-	"xep/c2s/stream"
-	"xep/entity"
 )
 
 const sleepDuration time.Duration = 1 * time.Second

+ 8 - 9
muc-client/main.go → main.go

@@ -4,6 +4,12 @@ import (
 	"flag"
 	"github.com/ivpusic/golog"
 	//	"github.com/skratchdot/open-golang/open"
+	"github.com/kpmy/xippo/c2s/actors"
+	"github.com/kpmy/xippo/c2s/actors/steps"
+	"github.com/kpmy/xippo/c2s/stream"
+	"github.com/kpmy/xippo/entity"
+	"github.com/kpmy/xippo/entity/dyn"
+	"github.com/kpmy/xippo/units"
 	"html/template"
 	"log"
 	"math/rand"
@@ -13,15 +19,8 @@ import (
 	"strings"
 	"sync"
 	"time"
-	"xep/c2s/actors"
-	"xep/c2s/actors/steps"
-	"xep/c2s/stream"
-	"xep/entity"
-	"xep/entity/dyn"
-	"xep/muc-client/luaexecutor"
-	"xep/muc-client/muc"
-
-	"xep/units"
+	"xep/luaexecutor"
+	"xep/muc"
 )
 
 const (

+ 3 - 3
muc-client/misc.go → misc.go

@@ -2,11 +2,11 @@ package main
 
 import (
 	"bytes"
+	"github.com/kpmy/xippo/entity"
+	"github.com/kpmy/xippo/entity/dyn"
+	"github.com/kpmy/xippo/tools/dom"
 	"gopkg.in/xmlpath.v2"
 	"log"
-	"xep/entity"
-	"xep/entity/dyn"
-	"xep/tools/dom"
 )
 
 func conv(fn func(entity.Entity)) func(*bytes.Buffer) bool {

+ 0 - 0
muc-client/muc/user-mapping.go → muc/user-mapping.go


+ 0 - 0
muc-client/neo.go → neo.go


+ 0 - 0
muc-client/static/css/default.css → static/css/default.css


+ 0 - 0
muc-client/static/user-mapping.json → static/user-mapping.json


+ 0 - 102
tools/dom/node.go

@@ -1,102 +0,0 @@
-package dom
-
-import (
-	"encoding/xml"
-	"fmt"
-	"github.com/kpmy/ypk/assert"
-)
-
-type (
-	Leaf interface {
-		Parent(...Node) Node
-	}
-
-	Text interface {
-		Leaf
-		Data() string
-	}
-
-	Node interface {
-		Leaf
-		AppendChild(Leaf)
-		Children() []Leaf
-	}
-
-	Element interface {
-		Attr(name string, set ...string) (get string)
-		AttrAsMap() map[string]string
-		Node
-		Name() string
-	}
-
-	elem struct {
-		a map[string]string
-		l []Leaf
-		n string
-		p Node
-	}
-
-	txt struct {
-		d string
-		p Node
-	}
-)
-
-func (e *elem) String() string {
-	return fmt.Sprint("<", e.n, " ", e.a, ">", e.l, "</", e.n, ">")
-}
-
-func (e *elem) AppendChild(l Leaf) {
-	e.l = append(e.l, l)
-	l.Parent(e)
-}
-
-func (e *elem) Attr(name string, set ...string) (get string) {
-	assert.For(name != "", 20)
-	if e.a == nil {
-		e.a = make(map[string]string)
-	}
-	if len(set) > 0 {
-		e.a[name] = set[0]
-	}
-	return e.a[name]
-}
-
-func (e *elem) Name() string { return e.n }
-
-func (e *elem) AttrAsMap() map[string]string { return e.a }
-
-func (e *elem) Children() []Leaf { return e.l }
-
-func (e *elem) Parent(p ...Node) Node {
-	if len(p) > 0 {
-		e.p = p[0]
-	}
-	return e.p
-}
-
-func Elem(name string) Element {
-	return &elem{n: name}
-}
-
-func (t *txt) String() string { return t.d }
-func (t *txt) Data() string   { return t.d }
-
-func (t *txt) Parent(p ...Node) Node {
-	if len(p) > 0 {
-		t.p = p[0]
-	}
-	return t.p
-}
-
-func Txt(data string) Text {
-	return &txt{d: data}
-}
-
-func ThisName(n xml.Name) string {
-	if n.Space != "" {
-		return n.Space + ":" + n.Local
-	} else {
-		return n.Local
-	}
-}

+ 0 - 9
tools/srv/srv.go

@@ -1,9 +0,0 @@
-package srv
-
-import (
-	"xep/units"
-)
-
-func Resolve(s *units.Server) (host, port string, err error) {
-	return s.Name, "5222", nil
-}

+ 0 - 0
muc-client/tpl/log.tpl → tpl/log.tpl


+ 0 - 0
muc-client/tpl/stat.tpl → tpl/stat.tpl


+ 0 - 20
units/units.go

@@ -1,20 +0,0 @@
-package units
-
-import (
-	"github.com/kpmy/ypk/assert"
-)
-
-type Server struct {
-	Name string
-}
-
-type Client struct {
-	Name   string
-	Server *Server
-}
-
-func Bare2Full(bare string, rsrc string) string {
-	assert.For(bare != "", 20)
-	assert.For(rsrc != "", 21)
-	return bare + "/" + rsrc
-}