ircmsg

package
v0.0.0-...-f5e0f87 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: ISC Imports: 4 Imported by: 0

Documentation

Overview

Package ircmsg helps parse and create lines for IRC connections.

Index

Constants

View Source
const (
	// "The size limit for message tags is 8191 bytes, including the leading
	//  '@' (0x40) and trailing space ' ' (0x20) characters."
	MaxlenTags = 8191

	// MaxlenTags - ('@' + ' ')
	MaxlenTagData = MaxlenTags - 2

	// "Clients MUST NOT send messages with tag data exceeding 4094 bytes,
	//  this includes tags with or without the client-only prefix."
	MaxlenClientTagData = 4094

	// "Servers MUST NOT add tag data exceeding 4094 bytes to messages."
	MaxlenServerTagData = 4094

	// '@' + MaxlenClientTagData + ' '
	// this is the analogue of MaxlenTags when the source of the message is a client
	MaxlenTagsFromClient = MaxlenClientTagData + 2
)

Variables

View Source
var (
	// ErrorLineIsEmpty indicates that the given IRC line was empty.
	ErrorLineIsEmpty = errors.New("Line is empty")

	// ErrorLineContainsBadChar indicates that the line contained invalid characters
	ErrorLineContainsBadChar = errors.New("Line contains invalid characters")

	// ErrorBodyTooLong indicates that the message body exceeded the specified
	// length limit (typically 512 bytes). This error is non-fatal; if encountered
	// when parsing a message, the message is parsed up to the length limit, and
	// if encountered when serializing a message, the message is truncated to the limit.
	ErrorBodyTooLong = errors.New("Line body exceeded the specified length limit; outgoing messages will be truncated")

	// ErrorTagsTooLong indicates that the message exceeded the maximum tag length
	// (the specified response on the server side is 417 ERR_INPUTTOOLONG).
	ErrorTagsTooLong = errors.New("Line could not be processed because its tag data exceeded the length limit")

	// ErrorInvalidTagContent indicates that a tag name or value was invalid
	ErrorInvalidTagContent = errors.New("Line could not be processed because it contained an invalid tag name or value")

	// ErrorCommandMissing indicates that an IRC message was invalid because it lacked a command.
	ErrorCommandMissing = errors.New("IRC messages MUST have a command")

	// ErrorBadParam indicates that an IRC message could not be serialized because
	// its parameters violated the syntactic constraints on IRC parameters:
	// non-final parameters cannot be empty, contain a space, or start with `:`.
	ErrorBadParam = errors.New("Cannot have an empty param, a param with spaces, or a param that starts with ':' before the last parameter")
)

Functions

func EscapeTagValue

func EscapeTagValue(inString string) string

EscapeTagValue takes a value, and returns an escaped message tag value.

This function is automatically used when lines are created from an Message, so you don't need to call it yourself before creating a line.

func UnescapeTagValue

func UnescapeTagValue(inString string) string

UnescapeTagValue takes an escaped message tag value, and returns the raw value.

This function is automatically used when lines are interpreted by ParseLine, so you don't need to call it yourself after parsing a line.

Types

type Message

type Message struct {
	Prefix  string
	Command string
	Params  []string
	// contains filtered or unexported fields
}

Message represents an IRC message, as defined by the RFCs and as extended by the IRCv3 Message Tags specification with the introduction of message tags.

func MakeMessage

func MakeMessage(tags map[string]string, prefix string, command string, params ...string) (ircmsg Message)

MakeMessage provides a simple way to create a new Message.

func ParseLine

func ParseLine(line string) (ircmsg Message, err error)

ParseLine creates and returns a message from the given IRC line.

func ParseLineStrict

func ParseLineStrict(line string, fromClient bool, truncateLen int) (ircmsg Message, err error)

ParseLineStrict creates and returns an Message from the given IRC line, taking the maximum length into account and truncating the message as appropriate. If fromClient is true, it enforces the client limit on tag data length (4094 bytes), allowing the server to return ERR_INPUTTOOLONG as appropriate. If truncateLen is nonzero, it is the length at which the non-tag portion of the message is truncated.

func (*Message) AllTags

func (msg *Message) AllTags() (result map[string]string)

AllTags returns all tags as a single map.

func (*Message) ClientOnlyTags

func (msg *Message) ClientOnlyTags() map[string]string

ClientOnlyTags returns the client-only tags (the tags with the + prefix). The returned map may be internal storage of the Message object and should not be modified.

func (*Message) DeleteTag

func (msg *Message) DeleteTag(tagName string)

DeleteTag deletes a tag.

func (*Message) ForceTrailing

func (msg *Message) ForceTrailing()

ForceTrailing ensures that when the message is serialized, the final parameter will be encoded as a "trailing parameter" (preceded by a colon). This is almost never necessary and should not be used except when having to interact with broken implementations that don't correctly interpret IRC messages.

func (*Message) GetTag

func (msg *Message) GetTag(tagName string) (present bool, value string)

GetTag returns whether a tag is present, and if so, what its value is.

func (*Message) HasTag

func (msg *Message) HasTag(tagName string) (present bool)

HasTag returns whether a tag is present.

func (*Message) Line

func (ircmsg *Message) Line() (result string, err error)

Line returns a sendable line created from an Message.

func (*Message) LineBytes

func (ircmsg *Message) LineBytes() (result []byte, err error)

LineBytes returns a sendable line created from an Message.

func (*Message) LineBytesStrict

func (ircmsg *Message) LineBytesStrict(fromClient bool, truncateLen int) ([]byte, error)

LineBytesStrict returns a sendable line, as a []byte, created from an Message. fromClient controls whether the server-side or client-side tag length limit is enforced. If truncateLen is nonzero, it is the length at which the non-tag portion of the message is truncated.

func (*Message) SetTag

func (msg *Message) SetTag(tagName, tagValue string)

SetTag sets a tag.

func (*Message) UpdateTags

func (msg *Message) UpdateTags(tags map[string]string)

UpdateTags is a convenience to set multiple tags at once.

Jump to

Keyboard shortcuts

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