forked from byte-mug/fastnntp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structures.go
158 lines (129 loc) · 5.19 KB
/
structures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
MIT License
Copyright (c) 2017 Simon Schmidt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package fastnntp
import "sync"
type Group struct{
Group []byte
Number int64
Low int64
High int64
}
var pool_Group = sync.Pool{New: func()interface{} { return new(Group) }}
func pool_Group_put(g *Group) {
g.Group = nil
pool_Group.Put(g)
}
type GroupCaps interface {
GetGroup(g *Group) bool
ListGroup(g *Group,w *DotWriter,first,last int64)
CursorMoveGroup(g *Group,i int64,backward bool,id_buf []byte) (ni int64,id []byte,ok bool)
}
var pool_Article = sync.Pool{New: func()interface{} { return new(Article) }}
func pool_Article_put(g *Article) {
g.MessageId = nil
g.Group = nil
pool_Article.Put(g)
}
type Article struct{
MessageId []byte
Group []byte
Number int64
HasId bool
HasNum bool
}
var pool_ArticleRange = sync.Pool{New: func()interface{} { return new(ArticleRange) }}
func pool_ArticleRange_put(g *ArticleRange) {
g.MessageId = nil
g.Group = nil
pool_ArticleRange.Put(g)
}
type ArticleRange struct{
Article
LastNumber int64
}
type ArticleCaps interface {
// Every method (except WriteOverview) must set the message-id on success, if it is not given.
StatArticle(a *Article) bool
GetArticle(a *Article,head, body bool) func(w *DotWriter)
WriteOverview(ar *ArticleRange) func(w IOverview)
}
type PostingCaps interface{
CheckPostId(id []byte) (wanted bool, possible bool)
CheckPost() (possible bool)
PerformPost(id []byte, r *DotReader) (rejected bool,failed bool)
}
type GroupListingCaps interface{
// Performs a List-Active action.
// the argument 'wm' may be nil.
ListGroups(wm *WildMat, ila IListActive) bool
}
// Privilege for a user.
type LoginPriv uint
const(
LoginPriv_Post LoginPriv = iota
)
// NNTP Authentication.
// Documented outside RFC 3977 --> RFC 4643
type LoginCaps interface{
// This Method SHOULD return true, if authentication has already occurred.
AuthinfoDone(h *Handler) bool
// Checks a privilege. Returns true if it is allowed.
AuthinfoCheckPrivilege(p LoginPriv,h *Handler) bool
// This Method returns true, if the combination of username is accepted without password.
// The method can optionally return a new Handler object in place of the old one.
AuthinfoUserOny(user []byte, oldh *Handler) (bool,*Handler)
// This Method returns true, if the combination of username and password is accepted.
AuthinfoUserPass(user, password []byte, oldh *Handler) (bool,*Handler)
}
type Handler struct {
GroupCaps
ArticleCaps
PostingCaps
GroupListingCaps
LoginCaps
}
func (h *Handler) fill() {
if h.GroupCaps==nil { h.GroupCaps = DefaultCaps }
if h.ArticleCaps==nil { h.ArticleCaps = DefaultCaps }
if h.PostingCaps==nil { h.PostingCaps = DefaultCaps }
if h.GroupListingCaps==nil { h.GroupListingCaps = DefaultCaps }
if h.LoginCaps==nil { h.LoginCaps = DefaultCaps }
}
var DefaultCaps = new(defCaps)
type defCaps struct {}
// GroupCaps
func (d *defCaps) GetGroup(g *Group) bool { return false }
func (d *defCaps) ListGroup(g *Group,w *DotWriter,first,last int64) { }
func (d *defCaps) CursorMoveGroup(g *Group,i int64,backward bool, id_buf []byte) (ni int64,id []byte,ok bool) { ok = false; return }
// ArticleCaps
func (d *defCaps) StatArticle(a *Article) bool { return false }
func (d *defCaps) GetArticle(a *Article,head, body bool) func(w *DotWriter) { return nil }
func (d *defCaps) WriteOverview(ar *ArticleRange) func(w IOverview) { return nil }
// PostingCaps
func (d *defCaps) CheckPostId(id []byte) (wanted bool, possible bool) { return }
func (d *defCaps) CheckPost() (possible bool) { return }
func (d *defCaps) PerformPost(id []byte, r *DotReader) (rejected bool,failed bool) { return true,true }
// GroupListingCaps
func (d *defCaps) ListGroups(wm *WildMat, ila IListActive) bool { return false }
// LoginCaps
func (d *defCaps) AuthinfoDone(h *Handler) bool { return true }
func (d *defCaps) AuthinfoCheckPrivilege(p LoginPriv,h *Handler) bool { return true }
func (d *defCaps) AuthinfoUserOny(user []byte, oldh *Handler) (bool,*Handler) { return false,nil }
func (d *defCaps) AuthinfoUserPass(user, password []byte, oldh *Handler) (bool,*Handler) { return false,nil }