node

package
v0.0.0-...-3b98bfd Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStringPullParser

func NewStringPullParser(xmpp string) (*xpp.XMLPullParser, error)

Creates a new XMLPullParser for a given string.

Types

type InitialStreamTag

type InitialStreamTag struct {
	// The IP address of the connected client
	ClientIp string

	// The attributes in the <k stanza
	Attributes map[string]string

	// The raw stanza received from the client
	RawStanza string

	// True if the client is authenticating with Kik using credentials
	IsAuth bool

	// if IsAuth == true, this is not nil, otherwise it is nil
	Jid *datatypes.FullJid

	// The device ID in use by the client, not nil
	DeviceId datatypes.KikDeviceId

	// The version name in use by the client, not nil
	Version string

	// Optional interface IP specified by the client
	InterfaceIp *string

	// Optional API key specified by the client
	ApiKey *string
}

Describes a bind request from the client

func ParseInitialStreamTag

func ParseInitialStreamTag(conn net.Conn) (*InitialStreamTag, bool, error)

Parses and verifies the initial stream tag from the client. If the error returned is nil, the parsing succeeded, and the other return values must be ignored. Returns: InitialStreamTag, shouldBanIp, error

func (InitialStreamTag) KikHost

func (k InitialStreamTag) KikHost() (*string, error)

Returns the corresponding XMPP host name based on the connecting client info. Kik uses different host names dependent on the OS and client version. error is not nil if the client supplies an invalid version number.

func (InitialStreamTag) UserId

func (k InitialStreamTag) UserId() string

Returns a unique identifier for the connecting client. For authed connections, this is the JID For anon connections, this is the Device ID (with prefix)

type KikInitialStreamResponse

type KikInitialStreamResponse struct {
	// True if Kik returned success on bind
	IsOk bool

	// The timestamp of the Kik server, used to sync the local time of our server and connecting clients.
	// If the client is binding pre-auth (anon="1"), the timestamp will be 0 and should be ignored.
	Timestamp int64

	// The raw stanza received from Kik.
	RawStanza string
}

Describes a bind response from Kik

func ParseInitialStreamResponse

func ParseInitialStreamResponse(input NodeInputStream) (*KikInitialStreamResponse, error)

func (KikInitialStreamResponse) GenerateServerResponse

func (response KikInitialStreamResponse) GenerateServerResponse(customBanner bool) string

type LoggingBufferedReader

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

Sits on top of the real reader so we can log the raw XMPP

func (*LoggingBufferedReader) ClearBuffer

func (r *LoggingBufferedReader) ClearBuffer()

func (*LoggingBufferedReader) GetBuffer

func (r *LoggingBufferedReader) GetBuffer() []byte

func (*LoggingBufferedReader) Read

func (r *LoggingBufferedReader) Read(p []byte) (n int, err error)

type Node

type Node struct {
	Attributes map[string]string
	Children   []Node
	Name       string
	Text       string
}

func ParseNextNode

func ParseNextNode(parser *xpp.XMLPullParser) (*Node, error)

Reads the next Node from the XMLPull Parser. Parser must be positioned on a StartTag.

func ParseStreamHeader

func ParseStreamHeader(xmpp string) (*Node, error)

Parses an initial stream header from a string. Stream headers must not be self-closing.

func ParseXmppString

func ParseXmppString(xmpp string) (*Node, error)

Parse an XMPP string Note that this will return an error if all tags are not properly closed.

func (Node) Find

func (n Node) Find(name string) *Node

Finds the first matching child by its name. Returns nil if not found.

func (Node) FindAll

func (n Node) FindAll(name string) (ret []Node)

Finds all matching children by name.

func (Node) FindLast

func (n Node) FindLast(name string) *Node

Finds the last matching child by its name. Returns nil if not found.

func (Node) Get

func (n Node) Get(key string) string

Finds an attribute value by its name. Returns an empty string if not found.

func (Node) HasAttribute

func (n Node) HasAttribute(key string) bool

Returns true if the Node contains the attribute key.

func (Node) HasTag

func (n Node) HasTag(name string) bool

Returns true if there is a child with the same name as the parameter.

type NodeInputStream

type NodeInputStream struct {
	Reader *LoggingBufferedReader
	Parser xpp.XMLPullParser
}

func NewNodeInputStream

func NewNodeInputStream(connection net.Conn) NodeInputStream

Create a XMLPullParser for a long-lived input stream.

func (NodeInputStream) ReadNextStanza

func (input NodeInputStream) ReadNextStanza() (*Node, *[]byte, error)

Read the next stanza from the input stream.

If an error is encountered, node and string will be nil.

If successful, the node object and the raw stanza will be returned in the first two values.

type NodeWriter

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

Simplifies stanza creation.

func NewNodeWriter

func NewNodeWriter() NodeWriter

func (NodeWriter) Attribute

func (w NodeWriter) Attribute(name string, value string) NodeWriter

Writes an attribute. Writer must be positioned on a StartTag.

func (NodeWriter) AttributeIf

func (w NodeWriter) AttributeIf(name string, value *string) NodeWriter

Writes an attribute. Writer must be positioned on a StartTag. No-op if value is nil.

func (NodeWriter) EmptyTag

func (w NodeWriter) EmptyTag(name string) NodeWriter

Writes StartTag, then EndTag. Serialized as <foo></foo>

func (NodeWriter) EndAllFlush

func (w NodeWriter) EndAllFlush()

Closes all open tags.

func (NodeWriter) EndTag

func (w NodeWriter) EndTag(name string) NodeWriter

Ends a tag that was previously opened via StartTag.

func (NodeWriter) StartTag

func (w NodeWriter) StartTag(name string) NodeWriter

Begins a tag.

func (NodeWriter) String

func (w NodeWriter) String() string

Returns the serialized XML. This function panics if the xmlwriter encountered an error when writing, which occurs if the caller uses functions in a wrong order (i.e. end tag without start tag)

func (NodeWriter) TagText

func (w NodeWriter) TagText(name string, value string) NodeWriter

Writes StartTag, Text, then EndTag.

func (NodeWriter) TagTextIf

func (w NodeWriter) TagTextIf(name string, value *string) NodeWriter

Writes StartTag, Text, then EndTag. Does nothing if value is nil.

func (NodeWriter) Text

func (w NodeWriter) Text(text string) NodeWriter

Writes text. Caller must have called StartTag or Attribute prior to calling this.

Jump to

Keyboard shortcuts

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