jid

package
v0.0.111-test1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: GPL-3.0 Imports: 5 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidBareJID

func ValidBareJID(s string) bool

ValidBareJID returns true if the given string is a valid bare JID. This function will true for full JIDs as well as bare JIDs

func ValidDomain

func ValidDomain(s string) bool

ValidDomain returns true if the given string is a valid domain part for a JID

func ValidDomainWithResource

func ValidDomainWithResource(s string) bool

ValidDomainWithResource returns true if the given string a valid domain with resource part. This wil return true for a full JID, as well as a domain with JID

func ValidFullJID

func ValidFullJID(s string) bool

ValidFullJID returns true if the given string is a valid full JID

func ValidJID

func ValidJID(s string) bool

ValidJID returns true if the given string is any of the possible JID types

func ValidLocal

func ValidLocal(s string) bool

ValidLocal checks whether the given string is a valid local part of a JID A localpart is defined to be any string of length 1 to 1023, matching the UsernameCaseMapped profile from RFC7613, and excluding a few more characters

func ValidResource

func ValidResource(s string) bool

ValidResource returns true if the given string is a valid resource part for a JID. Note that a resource part is allowed to contain / and @ characters

func WithAndWithout

func WithAndWithout(peer Any) (WithResource, WithoutResource)

WithAndWithout will return the JID with the resource, and without the resource

Types

type Any

type Any interface {
	// Host will always return the domain component, since all JIDs have one
	Host() Domain
	// String will return the natural string representation of the JID
	String() string
	// WithResource will return a new JID containing the resource component specified. If the JID already had a resource, it will be replaced
	WithResource(Resource) WithResource
	// MaybeWithResource will act like WithResource, if the argument is anything but a blank resource.
	// Otherwise it will return itself without a resource
	MaybeWithResource(Resource) Any
	// NoResource will ensure that the JID returned doesn't have a resource
	NoResource() WithoutResource
	// Potential resource returns the resource if one exists, or the blank resource otherwise
	PotentialResource() Resource
	// PotentialSplit will return the result of calling WithoutResource and PotentialResource
	PotentialSplit() (WithoutResource, Resource)
	// Valid returns true if this is a valid JID
	Valid() bool
}

Any represents any valid JID, including just a hostname, a bare jid, and a jid with a resource

func Parse

func Parse(j string) Any

Parse will parse the given string and return the most specific JID type that matches it In general, it is a good idea to check that the returned result is valid before using it by calling Valid()

type Bare

type Bare interface {
	WithoutResource
	WithLocal
	WithBare
}

Bare represents a JID containing both a local component and a host component, but no resource component. A Bare is an Any

func NewBare

func NewBare(local Local, domain Domain) Bare

NewBare accept a domain and a local and creates a valid resource

func NewBareFromStrings

func NewBareFromStrings(local, domain string) Bare

NewBareFromStrings generate a new Bare from local and domain as strings

func ParseBare

func ParseBare(s string) Bare

ParseBare returns a bare JID. It will fail if the given string isn't at least a bare

func TryParseBare

func TryParseBare(s string) (Bare, bool)

TryParseBare returns a bare JID if it can.

type Domain

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

Domain represents the domain part of a JID

func NewDomain

func NewDomain(s string) Domain

NewDomain returns a new domain if possible

func ParseDomain

func ParseDomain(s string) Domain

ParseDomain returns a domain part of a JID. It will fail if the given string isn't at least a domain This will parse the full string as a JID and _extract_ the domain part, This is in comparison to NewDomain that will try to create a new Domain object from the given string

func (Domain) AddLocal

func (j Domain) AddLocal(l Local) Bare

AddLocal returns a Bare, combining this domain with a Local

func (Domain) Host

func (j Domain) Host() Domain

Host implements Any

func (Domain) MaybeWithResource

func (j Domain) MaybeWithResource(r Resource) Any

MaybeWithResource implements WithoutResource

func (Domain) NoResource

func (j Domain) NoResource() WithoutResource

NoResource implements Any

func (Domain) PotentialResource

func (j Domain) PotentialResource() Resource

PotentialResource implements Any

func (Domain) PotentialSplit

func (j Domain) PotentialSplit() (WithoutResource, Resource)

PotentialSplit implements Any

func (Domain) String

func (j Domain) String() string

String implements Any

func (Domain) Valid

func (j Domain) Valid() bool

Valid returns true if this object is valid

func (Domain) WithResource

func (j Domain) WithResource(r Resource) WithResource

WithResource implements WithoutResource

type Full

type Full interface {
	WithResource
	WithLocal
	WithBare
}

Full represents a JID containing a local, host and resource component. A Full is a Bare and an Any

func NewFull

func NewFull(local Local, domain Domain, resource Resource) Full

NewFull creates a full JID from the different parts of a JID

func ParseFull

func ParseFull(s string) Full

ParseFull returns a full JID. It will fail if the given string isn't at least a full

func TryParseFull

func TryParseFull(s string) (Full, bool)

TryParseFull returns a full JID if it can.

type Local

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

Local represents the local part of a JID

func MaybeLocal

func MaybeLocal(j Any) Local

MaybeLocal returns the local part of a JID if it has one, otherwise empty

func NewLocal

func NewLocal(s string) Local

NewLocal returns a new local if possible

func (Local) String

func (j Local) String() string

String implements Local

func (Local) Valid

func (j Local) Valid() bool

Valid returns true if this object is valid

type Resource

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

Resource represents the resource part of a JID

func NewResource

func NewResource(s string) Resource

NewResource returns a new resource if possible

func (Resource) String

func (j Resource) String() string

String implements Resource

func (Resource) Valid

func (j Resource) Valid() bool

Valid returns true if this object is valid

type WithBare

type WithBare interface {
	// Bare will return the extracted bare jid from the original jid
	Bare() Bare
}

WithBare represents a JID that is a bare jid compatible

type WithLocal

type WithLocal interface {
	// Local returns the local part of the JID
	Local() Local
}

WithLocal represents a JID that has a Local port

type WithResource

type WithResource interface {
	Any
	// Resource will return the resource
	Resource() Resource
	// Split will return the JID split into the part without resource and the part with resource
	Split() (WithoutResource, Resource)
}

WithResource represents any valid JID that has a resource part

func R

func R(s string) WithResource

R returns a JID with resource. This method will fail if the object doesn't have a resource

type WithoutResource

type WithoutResource interface {
	Any
	// contains filtered or unexported methods
}

WithoutResource represents any valid JID that does not have a resource part

func NR

func NR(s string) WithoutResource

NR returns a JID without a resource

Jump to

Keyboard shortcuts

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