xmppc

package module
v0.0.0-...-6e7897a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 15 Imported by: 0

README

XMPP Client in Go

This package provides a basic XMPP client implementation.

WARNING: This is an early stage project. Things will get broken.

Quick start

package main

import (
	"fmt"
	"github.com/cryptopunkscc/go-xmpp"
	"github.com/cryptopunkscc/go-xmppc"
)

var quit chan bool

type Handler struct {
	session xmppc.Session
}

func (h *Handler) Online(s xmppc.Session) {
	fmt.Println("Connected", s.JID())
	h.session = s
}

func (h *Handler) Offline(err error) {
	fmt.Println("Disconnected", err)
	quit <- true
}

func (h *Handler) HandleStanza(s xmpp.Stanza) {
	// Handle an incoming stanza here
}

func main() {
	quit := make(chan bool)
	err := xmppc.Open(&Handler{}, &xmppc.Config{
		JID:      "user@host.com",
		Password: "password",
	})
	if err != nil {
		panic(err)
	}
	<-quit
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleStanza

func HandleStanza(handler StanzaHandler, stanza xmpp.Stanza) bool

HandleStanza routes a stanza to a typed stanza handler

func Open

func Open(handler Handler, cfg *Config) error

Open opens a new session using provided config and routes session events to the provided handler

Types

type Authenticator

type Authenticator interface {
	Name() string
	Data() string
	Challenge(string) string
}

Authenticator defines an interface for SASL authentication

func NewPlainAuthenticator

func NewPlainAuthenticator(creds Credentials) Authenticator

NewPlainAuthenticator instantiates a PLAIN authenticator using provided credentials

func NewScramSHA1Authenticator

func NewScramSHA1Authenticator(creds Credentials) Authenticator

type Broadcast

type Broadcast struct {
	// contains filtered or unexported fields
}

Broadcast routes XMPP events to mutiple handlers

func (*Broadcast) Add

func (m *Broadcast) Add(h Handler)

Add adds a handler to the router

func (*Broadcast) HandleStanza

func (m *Broadcast) HandleStanza(stanza xmpp.Stanza)

HandleStanza routes a stanza

func (*Broadcast) Offline

func (m *Broadcast) Offline(e error)

Offline routes an Offline event

func (*Broadcast) Online

func (m *Broadcast) Online(s Session)

Online routes an Online event

type Callbacks

type Callbacks struct {
	Session
	// contains filtered or unexported fields
}

func (*Callbacks) Handle

func (c *Callbacks) Handle(s xmpp.Stanza) bool

func (*Callbacks) WriteIQ

func (c *Callbacks) WriteIQ(iq *xmpp.IQ, callback IQCallback) error

func (*Callbacks) WriteMessage

func (c *Callbacks) WriteMessage(msg *xmpp.Message, callback MessageCallback) error

func (*Callbacks) WritePresence

func (c *Callbacks) WritePresence(p *xmpp.Presence, callback PresenceCallback) error

type Config

type Config struct {
	JID      xmpp.JID
	Password string
}

Config represents XMPP client configuration

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents an XMPP connection

func Connect

func Connect(host string, jid xmpp.JID, password string) (*Conn, error)

Connect establishes a connection to the XMPP server

func (*Conn) Close

func (c *Conn) Close()

Close closes the XMPP connection

func (*Conn) Features

func (c *Conn) Features() *xmpp.Features

Features returns the current stream features

func (*Conn) JID

func (c *Conn) JID() xmpp.JID

JID returns JID the connection is bound to

func (*Conn) Read

func (c *Conn) Read() (interface{}, error)

Read reads the next XMPP message from the stream

func (*Conn) Write

func (c *Conn) Write(msg interface{}) error

Write writes an XMPP message to the stream

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials holds authentication information

type DNSResolver

type DNSResolver struct {
	// contains filtered or unexported fields
}

DNSResolver represents a DSN resolver

func NewDNSResolver

func NewDNSResolver(domain string) *DNSResolver

NewDNSResolver returns an instance of a DNSResolver

func (*DNSResolver) ClientAddress

func (r *DNSResolver) ClientAddress() string

ClientAddress resolves the address XMPP clients should connect to

func (*DNSResolver) ServerAddress

func (r *DNSResolver) ServerAddress() string

ServerAddress resolves the address XMPP servers should connect to

type Filter

type Filter interface {
	ApplyFilter(xmpp.Stanza) error
}

type Handler

type Handler interface {
	Online(Session)
	HandleStanza(xmpp.Stanza)
	Offline(error)
}

Handler defines an interface for XMPP event handlers

type IQCallback

type IQCallback func(*xmpp.IQ)

type MessageCallback

type MessageCallback func(*xmpp.Message)

type PlainAuth

type PlainAuth struct {
	Username string
	Password string
}

PlainAuth implements a plain SASL authentication

func (*PlainAuth) Challenge

func (auth *PlainAuth) Challenge(string) string

Challenge satisfies Authenticator interface. It returns an empty string since PLAIN mechanism doesn't support challenges.

func (*PlainAuth) Data

func (auth *PlainAuth) Data() string

Data returns authentication data encoded for PLAIN mechanism

func (*PlainAuth) Name

func (auth *PlainAuth) Name() string

Name returns the name of the authenticator

type PresenceCallback

type PresenceCallback func(*xmpp.Presence)

type ScramAuth

type ScramAuth struct {
	Username string
	Password string
	// contains filtered or unexported fields
}

func (*ScramAuth) Challenge

func (auth *ScramAuth) Challenge(challenge string) string

func (*ScramAuth) Data

func (auth *ScramAuth) Data() string

func (*ScramAuth) Name

func (auth *ScramAuth) Name() string

type Session

type Session interface {
	JID() xmpp.JID
	Write(xmpp.Stanza) error
	Close(error)
	AddFilter(Filter)
}

Session defines an interface for session

type StanzaHandler

type StanzaHandler interface{}

StanzaHandler defines an interface for specific stanza handler

type UniqueID

type UniqueID struct {
	// contains filtered or unexported fields
}

UniqueID holds the state of a unique id generator

func (*UniqueID) Next

func (s *UniqueID) Next() string

Next returns the next unique ID

Directories

Path Synopsis
components
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL