gntp

package
v0.0.0-...-75f61f4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 28 Imported by: 1

Documentation

Overview

Package gntp implements the Growl Notification Transport Protocol version 1.0.

See http://www.growlforwindows.com/gfw/help/gntp.aspx for details.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProtocol   = errors.New("notify: protocol error")
	ErrHash       = errors.New("notify: unknown hash algorithm")
	ErrEncryption = errors.New("notify: unknown encryption algorithm")
	ErrKeyLength  = errors.New("notify: key length is too short")
	ErrPassword   = errors.New("notify: incorrect password")
	ErrPKCS7      = errors.New("notify: invalid PKCS #7 padding")
)

Functions

func NewNotifier

func NewNotifier(c *Client) notify.Notifier

NewNotifier returns a new Notifier.

Register supports following icon types:

  • string
  • []byte
  • image.Image
  • io.Reader

Register accepts following keys and values types:

  • gntp:display-name string
  • gntp:enabled bool
  • gntp:sticky bool
  • gntp:priority int

Types

type Callback

type Callback struct {
	Name        string
	ID          string
	Result      Result
	Timestamp   time.Time
	Context     string
	ContextType string
	Header      textproto.MIMEHeader
}

Callback represents a GNTP callback

type Client

type Client struct {
	Server              string
	Name                string
	Icon                Icon
	Password            string
	HashAlgorithm       HashAlgorithm
	EncryptionAlgorithm EncryptionAlgorithm

	// Custom Headers and App-Specific Headers
	Header map[string]interface{}

	Callback chan *Callback
	// contains filtered or unexported fields
}

Client is a GNTP client.

func New

func New() *Client

New returns a new Client.

func (*Client) Notify

func (c *Client) Notify(n *Notification) (*Response, error)

Notify sends a NOTIFY request to the server.

A NOTIFY request does not use the DisplayName and Enabled fields of the Notification.

func (*Client) Register

func (c *Client) Register(n []*Notification) (*Response, error)

Register sends a REGISTER request to the server.

A REGISTER request only uses the Name, DisplayName, Enabled, and Icon fields of the Notification.

func (*Client) Reset

func (c *Client) Reset()

Reset closes connections that are waiting for socket callback.

type EncryptionAlgorithm

type EncryptionAlgorithm int

EncryptionAlgorithm represents an encryption algorithm of the GNTP protocol.

const (
	NONE EncryptionAlgorithm = iota
	DES
	TDES // 3DES
	AES
)

List of encryption algorithms for the GNTP protocol.

func (EncryptionAlgorithm) New

func (ea EncryptionAlgorithm) New(key []byte) (cipher.Block, error)

New returns a new cipher.Block.

func (EncryptionAlgorithm) String

func (ea EncryptionAlgorithm) String() string

type Error

type Error struct {
	Code        ErrorCode
	Description string
	Header      textproto.MIMEHeader
}

Error represents a GNTP error.

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents an Error-Code value.

const (
	TimedOut               ErrorCode = 200
	NetworkFailure         ErrorCode = 201
	InvalidRequest         ErrorCode = 300
	UnknownProtocol        ErrorCode = 301
	UnknownProtocolVersion ErrorCode = 302
	RequiredHeaderMissing  ErrorCode = 303
	NotAuthorized          ErrorCode = 400
	UnknownApplication     ErrorCode = 401
	UnknownNotification    ErrorCode = 402
	AlreadyProcessed       ErrorCode = 403
	NotificationDisabled   ErrorCode = 404
	InternalServerError    ErrorCode = 500
)

List of Error-Code values.

func (ErrorCode) Description

func (code ErrorCode) Description() string

Description returns an Error-Description of the Error-Code. It returns the empty string if the code is unknown.

type HashAlgorithm

type HashAlgorithm int

HashAlgorithm represents a hash algorithm of the GNTP protocol.

const (
	MD5 HashAlgorithm = iota
	SHA1
	SHA256
	SHA512
)

List of hash algorithms for the GNTP protocol.

func (HashAlgorithm) New

func (ha HashAlgorithm) New() (h hash.Hash, err error)

New returns a new hash.Hash.

func (HashAlgorithm) String

func (i HashAlgorithm) String() string

type Icon

type Icon interface{}

Icon represents an icon and which supports following types:

  • string
  • []byte
  • image.Image
  • io.Reader

type Info

type Info struct {
	Version             string
	MessageType         string
	EncryptionAlgorithm EncryptionAlgorithm
	IV                  []byte
	HashAlgorithm       HashAlgorithm
	KeyHash             []byte
	Salt                []byte
	// contains filtered or unexported fields
}

Info represents a GNTP information line.

func ParseInfo

func ParseInfo(l, password string) (i *Info, err error)

ParseInfo parses a GNTP information line.

func (*Info) Decrypt

func (i *Info) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts the specified data and removes the PKCS #7 padding.

func (*Info) Encrypt

func (i *Info) Encrypt(data []byte) []byte

Encrypt encrypts the specified data with the PKCS #7 padding.

func (*Info) SetPassword

func (i *Info) SetPassword(password string) (err error)

SetPassword updates the IV, KeyHash, and Salt based on the specified password. Their resulting values are dependent on the values of EncryptionAlgorithm and HashAlgorithm fields.

func (*Info) String

func (i *Info) String() string

type Notification

type Notification struct {
	Name                string
	DisplayName         string
	Enabled             bool
	ID                  string
	Title               string
	Text                string
	Sticky              bool
	Priority            int
	Icon                Icon
	CoalescingID        string
	CallbackContext     string
	CallbackContextType string
	CallbackTarget      string
}

Notification represents a notification.

type Response

type Response struct {
	Action string
	ID     string
	Header textproto.MIMEHeader
}

Response represents a GNTP response.

type Result

type Result int

Result represents a result of the GNTP callback.

const (
	CLICKED Result = 1 + iota
	CLOSED
	TIMEOUT
)

List of results for the GNTP callback.

func (Result) String

func (i Result) String() string

Jump to

Keyboard shortcuts

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