models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrUnrecognized                = "M_UNRECOGNIZED"
	ErrUnauthorized                = "M_UNAUTHORIZED"
	ErrForbidden                   = "M_FORBIDDEN"
	ErrBadJSON                     = "M_BAD_JSON"
	ErrNotJSON                     = "M_NOT_JSON"
	ErrUserInUse                   = "M_USER_IN_USE"
	ErrRoomInUse                   = "M_ROOM_IN_USE"
	ErrBadPagination               = "M_BAD_PAGINATION"
	ErrBadState                    = "M_BAD_STATE"
	ErrUnknown                     = "M_UNKNOWN"
	ErrNotFound                    = "M_NOT_FOUND"
	ErrMissingToken                = "M_MISSING_TOKEN"
	ErrUnknownToken                = "M_UNKNOWN_TOKEN"
	ErrGuestAccessForbidden        = "M_GUEST_ACCESS_FORBIDDEN"
	ErrLimitExceeded               = "M_LIMIT_EXCEEDED"
	ErrCaptchaNeeded               = "M_CAPTCHA_NEEDED"
	ErrCaptchaInvalid              = "M_CAPTCHA_INVALID"
	ErrMissingParam                = "M_MISSING_PARAM"
	ErrInvalidParam                = "M_INVALID_PARAM"
	ErrTooLarge                    = "M_TOO_LARGE"
	ErrExclusive                   = "M_EXCLUSIVE"
	ErrThreepidAuthFailed          = "M_THREEPID_AUTH_FAILED"
	ErrThreepidInUse               = "M_THREEPID_IN_USE"
	ErrThreepidNotFound            = "M_THREEPID_NOT_FOUND"
	ErrThreepidDenied              = "M_THREEPID_DENIED"
	ErrInvalidUsername             = "M_INVALID_USERNAME"
	ErrServerNotTrusted            = "M_SERVER_NOT_TRUSTED"
	ErrConsentNotGiven             = "M_CONSENT_NOT_GIVEN"
	ErrCannotLeaveServerNoticeRoom = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"
	ErrResourceLimitExceeded       = "M_RESOURCE_LIMIT_EXCEEDED"
	ErrUnsupportedRoomVersion      = "M_UNSUPPORTED_ROOM_VERSION"
	ErrIncompatibleRoomVersion     = "M_INCOMPATIBLE_ROOM_VERSION"
	ErrWrongRoomKeysVersion        = "M_WRONG_ROOM_KEYS_VERSION"
	ErrNoValidSession              = "M_NO_VALID_SESSION"
	ErrSessionExpiredCode          = "M_SESSION_EXPIRED"
	ErrSessionNotValidatedCode     = "M_SESSION_NOT_VALIDATED"
	ErrUnknownPeer                 = "M_UNKNOWN_PEER"
	ErrVerificationFailed          = "M_VERIFICATION_FAILED"
	ErrInvalidEmail                = "M_INVALID_EMAIL"
	ErrEmailSendError              = "M_EMAIL_SEND_ERROR"
	ErrIncorrectClientSecretCode   = "M_INCORRECT_CLIENT_SECRET"
)

matrix error codes

Variables

View Source
var ErrIncorrectClientSecret = errors.New("db: incorrect client secret")
View Source
var ErrIncorrectToken = errors.New("bad token")
View Source
var ErrNoMatchingSignature = errors.New("no matching signatures found")
View Source
var ErrNoSignature = errors.New("no signatures found")
View Source
var ErrSessionExpired = errors.New("db: session expired")
View Source
var ErrSessionNotValidated = errors.New("db: session not validated")

Functions

func EnsureParams

func EnsureParams(req *http.Request, args ...string) (map[string]string, error)

EnsureParams makes sure the query params are in params.

func FromMS

func FromMS(ms int64) time.Time

FromMS returns time.Time initialized from ms which is time in milliseconds since unix epoch.

func GenerateToken

func GenerateToken(medium string) string

func MS

func MS(ts *time.Time) int64

MS returns time as milliseconds since epoch.

func RandomString

func RandomString(length int) string

RandomString returns a nice looking random string.

func Seed

func Seed()

func Time

func Time() int64

Time returns the current time in milliseconds.

Types

type Association

type Association struct {
	ID          int64                  `json:"-"`
	Medium      string                 `json:"medium"`
	Address     string                 `json:"address"`
	MatrixID    string                 `json:"mxid"`
	Timestamp   int64                  `json:"ts"`
	NotBefore   int64                  `json:"notBefore"`
	NotAfter    int64                  `json:"notAfter"`
	ExtraFields map[string]interface{} `json:"-"`
}

func (*Association) ToMap

func (a *Association) ToMap() map[string]interface{}

type BulkLookupRequest

type BulkLookupRequest struct {
	Threepids [][]string `json:"threepids"`
}

type Data

type Data map[string]interface{}

Data is an arbitrary json object

type EphemeralPublicKey

type EphemeralPublicKey struct {
	ID          int64
	PublicKey   string
	VerifyCount int64
	UpdatedAt   time.Time
}

type Error

type Error struct {
	Code string `json:"errcode"`
	Err  string `json:"error"`
}

Error implements error interface, that wraps around the response from the matrix server.

func NewError

func NewError(code, err string) Error

NewError returns Error with errcode and error fields set to code and err respectively.

func (Error) Error

func (e Error) Error() string

type IDLookupResponse

type IDLookupResponse struct {
	// The 3pid address of the user being looked up, matching the address requested.
	Address string `json:"address"`
	Medium  string `json:"medium"`
	Mxid    string `json:"mxid"`
	// A unix timestamp before which the association is not known to be valid
	NotBefore int64 `json:"not_before"`
	// A unix timestamp after which the association is not known to be valid.
	NotAfter int64 `json:"not_after"`
	// The unix timestamp at which the association was verified.
	Timestamp int64 `json:"ts"`
	// The signatures of the verifying identity servers which show that the
	// association should be trusted, if you trust the verifying identity servers
	Signature map[string]map[string]string `json:"signature"`
}

IDLookupResponse is the response sent by identity server for /lookup request.

type InviteToken

type InviteToken struct {
	ID         int64
	Medium     string
	Address    string
	RoomID     string
	Sender     string
	Token      string
	ReceivedAt time.Time
	SentAt     time.Time
}

func (*InviteToken) ToMap

func (i *InviteToken) ToMap() map[string]interface{}

type Peer

type Peer struct {
	Name                string        `json:"name"`
	Port                sql.NullInt64 `json:"-"`
	JSONPort            int64         `json:"port,omitempty"`
	LastSentVersion     sql.NullInt64 `json:"-"`
	LastPokeSucceededAt sql.NullInt64 `json:"-"`

	// 1 is for active and 0 is for not active
	Active     int64             `json:"-"`
	PublicKeys map[string]string `json:"public_keys"`
}

type Profile

type Profile struct {
	ID          string `json:"user_id,omitempty"`
	DisplayName string `json:"displayname,omitempty"`
	AvatarURL   string `json:"avatar_url,omitempty"`
	LastChecked int64  `json:"last_check,omitempty"`
}

type PublicKey

type PublicKey struct {
	Key string `json:"public_key" example:"ed25519:0"`
}

PublicKey represent a publick key response object that is returned by the identity server.

type Query

type Query interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type SQL

type SQL interface {
	Query
	BeginTx(context.Context, *sql.TxOptions) (Tx, error)
}

type ServerVerifyKey

type ServerVerifyKey struct {
	Name      string
	From      string
	Timestamp int64
	VerifyKey []byte
}

type Success

type Success struct {
	Success bool `json:"success"`
}

type TokenSession

type TokenSession struct {
	ValidationSession
	SendAttemptNumber int64
}

type Tx

type Tx interface {
	Commit() error
	Rollback() error
	Query
}

type ValidPubKey

type ValidPubKey struct {
	Valid bool `json:"valid"`
}

ValidPubKey is a response object for valid public key.

type ValidationSession

type ValidationSession struct {
	ID                int64  `json:"-"`
	Medium            string `json:"medium"`
	Address           string `json:"address"`
	ClientSecret      string `json:"-"`
	Validated         int    `json:"-"`
	Mtime             int64  `json:"validated_at"`
	Token             string `json:"-"`
	SendAttemptNumber int64  `json:"-"`
}

Jump to

Keyboard shortcuts

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