nntp

package module
v0.0.0-...-dcbe062 Latest Latest
Warning

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

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

README

go nntp

I needed a way to gate some web services into traditional readers. I wrote an NNTP client and server.

I'm still working on coming up with the exact right interfaces, but take a look at the couchserver example to see what it takes to build a custom NNTP server with your own backend.

Documentation

Overview

Package nntp implements the Network News Transfer Protocol as defined in RFC 3977.

Index

Constants

View Source
const (
	Unknown             = PostingStatus(0)
	PostingPermitted    = PostingStatus('y')
	PostingNotPermitted = PostingStatus('n')
	PostingModerated    = PostingStatus('m')
)

Variables

View Source
var ErrAuthRejected = &Error{452, "authorization rejected"}

ErrAuthRejected is returned for invalid authentication.

View Source
var ErrAuthRequired = &Error{450, "authorization required"}

ErrAuthRequired is returned to indicate authentication is required to proceed.

View Source
var ErrInvalidArticleNumber = &Error{423, "No article with that number"}

ErrInvalidArticleNumber is returned when an article is requested that can't be found.

View Source
var ErrInvalidMessageID = &Error{430, "No article with that message-id"}

ErrInvalidMessageID is returned when a message is requested that can't be found.

View Source
var ErrNoCurrentArticle = &Error{420, "Current article number is invalid"}

ErrNoCurrentArticle is returned when a command is executed that requires a current article when one has not been selected.

View Source
var ErrNoGroupSelected = &Error{412, "No newsgroup selected"}

ErrNoSuchGroup is returned for a request that requires a current group when none has been selected.

View Source
var ErrNoSuchGroup = &Error{411, "No such newsgroup"}

ErrNoSuchGroup is returned for a request for a group that can't be found.

View Source
var ErrNotAuthenticated = &Error{480, "authentication required"}

ErrNotAuthenticated is returned when a command is issued that requires authentication, but authentication was not provided.

View Source
var ErrNotWanted = &Error{435, "Article not wanted"}

ErrNotWanted is returned when an attempt to post an article is rejected due the server not wanting the article.

View Source
var ErrPostingFailed = &Error{441, "posting failed"}

ErrPostingFailed is returned when an attempt to post an article fails.

View Source
var ErrPostingNotPermitted = &Error{440, "posting not permitted"}

ErrPostingNotPermitted is returned as the response to an attempt to post an article where posting is not permitted.

View Source
var ErrSyntax = &Error{501, "not supported, or syntax error"}

ErrSyntax is returned when a command can't be parsed.

View Source
var ErrUnknownCommand = &Error{500, "Unknown command"}

ErrUnknownCommand is returned for unknown comands.

Functions

This section is empty.

Types

type Article

type Article struct {
	// The article's headers
	Header textproto.MIMEHeader
	// The article's body
	Body io.Reader
	// Number of bytes in the article body (used by OVER/XOVER)
	Bytes int
	// Number of lines in the article body (used by OVER/XOVER)
	Lines int
}

An Article that may appear in one or more groups.

func (*Article) MessageID

func (a *Article) MessageID() string

MessageID provides convenient access to the article's Message ID.

type Backend

type Backend interface {
	ListGroups(max int) ([]*Group, error)
	GetGroup(name string) (*Group, error)
	GetArticle(g *Group, id string) (*Article, error)
	GetArticles(g *Group, from, to int64) ([]NumberedArticle, error)
	Authorized() bool
	// Authenticate and optionally swap out the backend for this session.
	// You may return nil to continue using the same backend.
	Authenticate(user, pass string) (Backend, error)
	AllowPost() bool
	Post(article *Article) error
}

The Backend that provides the things and does the stuff.

type Error

type Error struct {
	Code int
	Msg  string
}

An NNTPError is a coded NNTP error message.

func (*Error) Error

func (e *Error) Error() string

type Group

type Group struct {
	Name        string
	Description string
	Count       int64
	High        int64
	Low         int64
	Posting     PostingStatus
}

Group represents a newsgroup.

type Handler

type Handler func(args []string, s *session, c *textproto.Conn) error

Handler is a low-level protocol handler

type NumberedArticle

type NumberedArticle struct {
	Num     int64
	Article *Article
}

A NumberedArticle provides local sequence nubers to articles When listing articles in a group.

type PostingStatus

type PostingStatus byte

PostingStatus type for groups.

func (PostingStatus) String

func (ps PostingStatus) String() string

type Server

type Server struct {
	// Handlers are dispatched by command name.
	Handlers map[string]Handler
	// The backend (your code) that provides data
	Backend Backend
	// contains filtered or unexported fields
}

The Server handle.

func NewServer

func NewServer(backend Backend) *Server

NewServer builds a new server handle request to a backend.

func (*Server) Process

func (s *Server) Process(nc net.Conn)

Process an NNTP session.

Directories

Path Synopsis
Package nntpclient provides an NNTP Client.
Package nntpclient provides an NNTP Client.
examples

Jump to

Keyboard shortcuts

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