Browse Source

Hide less interesting bits

maze 8 months ago
parent
commit
400b30e58c
3 changed files with 43 additions and 58 deletions
  1. 4
    4
      filter.go
  2. 32
    32
      imsg.go
  3. 7
    22
      table.go

+ 4
- 4
filter.go View File

@@ -178,7 +178,7 @@ type Filter struct {
178 178
 	Version uint32
179 179
 
180 180
 	c net.Conn
181
-	m *Message
181
+	m *message
182 182
 
183 183
 	hooks   int
184 184
 	flags   int
@@ -190,7 +190,7 @@ type Filter struct {
190 190
 func (f *Filter) Register() error {
191 191
 	var err error
192 192
 	if f.m == nil {
193
-		f.m = new(Message)
193
+		f.m = new(message)
194 194
 	}
195 195
 	if f.c == nil {
196 196
 		if f.c, err = newConn(0); err != nil {
@@ -274,7 +274,7 @@ func (f *Filter) Serve() error {
274 274
 	}
275 275
 
276 276
 	if f.m == nil {
277
-		f.m = new(Message)
277
+		f.m = new(message)
278 278
 	}
279 279
 	if f.session == nil {
280 280
 		if f.session, err = lru.New(1024); err != nil {
@@ -488,7 +488,7 @@ func (f *Filter) respond(s *Session, status, code int, line string) error {
488 488
 		return nil
489 489
 	}
490 490
 
491
-	m := new(Message)
491
+	m := new(message)
492 492
 	m.Header.Type = typeFilterResponse
493 493
 	m.PutTypeID(s.qid)
494 494
 	m.PutTypeInt(s.qtype)

+ 32
- 32
imsg.go View File

@@ -20,8 +20,8 @@ const (
20 20
 	maxDomainPartSize = (255 + 1)
21 21
 )
22 22
 
23
-// MessageHeader is the header of an imsg frame (struct imsg_hdr)
24
-type MessageHeader struct {
23
+// messageHeader is the header of an imsg frame (struct imsg_hdr)
24
+type messageHeader struct {
25 25
 	Type   uint32
26 26
 	Len    uint16
27 27
 	Flags  uint16
@@ -30,10 +30,10 @@ type MessageHeader struct {
30 30
 }
31 31
 
32 32
 // message implements OpenBSD imsg
33
-type Message struct {
34
-	Header MessageHeader
33
+type message struct {
34
+	Header messageHeader
35 35
 
36
-	// Data is the Message payload.
36
+	// Data is the message payload.
37 37
 	Data []byte
38 38
 
39 39
 	// rpos is the read position in the current Data
@@ -43,7 +43,7 @@ type Message struct {
43 43
 	buf []byte
44 44
 }
45 45
 
46
-func (m *Message) reset() {
46
+func (m *message) reset() {
47 47
 	m.Header.Type = 0
48 48
 	m.Header.Len = 0
49 49
 	m.Header.Flags = 0
@@ -56,7 +56,7 @@ func (m *Message) reset() {
56 56
 
57 57
 // ReadFrom reads a message from the specified net.Conn, parses the header and
58 58
 // reads the data payload.
59
-func (m *Message) ReadFrom(r io.Reader) error {
59
+func (m *message) ReadFrom(r io.Reader) error {
60 60
 	m.reset()
61 61
 
62 62
 	head := make([]byte, imsgHeaderSize)
@@ -81,7 +81,7 @@ func (m *Message) ReadFrom(r io.Reader) error {
81 81
 }
82 82
 
83 83
 // WriteTo marshals the message to wire format and sends it to the net.Conn
84
-func (m *Message) WriteTo(w io.Writer) error {
84
+func (m *message) WriteTo(w io.Writer) error {
85 85
 	m.Header.Len = uint16(len(m.Data)) + imsgHeaderSize
86 86
 
87 87
 	buf := new(bytes.Buffer)
@@ -96,7 +96,7 @@ func (m *Message) WriteTo(w io.Writer) error {
96 96
 	return err
97 97
 }
98 98
 
99
-func (m *Message) GetInt() (int, error) {
99
+func (m *message) GetInt() (int, error) {
100 100
 	if m.rpos+4 > len(m.Data) {
101 101
 		return 0, io.ErrShortBuffer
102 102
 	}
@@ -105,7 +105,7 @@ func (m *Message) GetInt() (int, error) {
105 105
 	return int(i), nil
106 106
 }
107 107
 
108
-func (m *Message) GetUint32() (uint32, error) {
108
+func (m *message) GetUint32() (uint32, error) {
109 109
 	if m.rpos+4 > len(m.Data) {
110 110
 		return 0, io.ErrShortBuffer
111 111
 	}
@@ -114,7 +114,7 @@ func (m *Message) GetUint32() (uint32, error) {
114 114
 	return u, nil
115 115
 }
116 116
 
117
-func (m *Message) GetSize() (uint64, error) {
117
+func (m *message) GetSize() (uint64, error) {
118 118
 	if m.rpos+8 > len(m.Data) {
119 119
 		return 0, io.ErrShortBuffer
120 120
 	}
@@ -123,7 +123,7 @@ func (m *Message) GetSize() (uint64, error) {
123 123
 	return u, nil
124 124
 }
125 125
 
126
-func (m *Message) GetString() (string, error) {
126
+func (m *message) GetString() (string, error) {
127 127
 	o := bytes.IndexByte(m.Data[m.rpos:], 0)
128 128
 	if o < 0 {
129 129
 		return "", errors.New("imsg: string not NULL-terminated")
@@ -134,7 +134,7 @@ func (m *Message) GetString() (string, error) {
134 134
 	return s, nil
135 135
 }
136 136
 
137
-func (m *Message) GetID() (uint64, error) {
137
+func (m *message) GetID() (uint64, error) {
138 138
 	if m.rpos+8 > len(m.Data) {
139 139
 		return 0, io.ErrShortBuffer
140 140
 	}
@@ -176,7 +176,7 @@ func (sa Sockaddr) String() string {
176 176
 	return fmt.Sprintf("%s:%d", sa.IP(), sa.Port())
177 177
 }
178 178
 
179
-func (m *Message) GetSockaddr() (net.Addr, error) {
179
+func (m *message) GetSockaddr() (net.Addr, error) {
180 180
 	s, err := m.GetSize()
181 181
 	if err != nil {
182 182
 		return nil, err
@@ -192,7 +192,7 @@ func (m *Message) GetSockaddr() (net.Addr, error) {
192 192
 	return a, nil
193 193
 }
194 194
 
195
-func (m *Message) GetMailaddr() (user, domain string, err error) {
195
+func (m *message) GetMailaddr() (user, domain string, err error) {
196 196
 	var buf [maxLocalPartSize + maxDomainPartSize]byte
197 197
 	if maxLocalPartSize+maxDomainPartSize > len(m.Data[m.rpos:]) {
198 198
 		return "", "", io.ErrShortBuffer
@@ -204,7 +204,7 @@ func (m *Message) GetMailaddr() (user, domain string, err error) {
204 204
 	return
205 205
 }
206 206
 
207
-func (m *Message) GetType(t uint8) error {
207
+func (m *message) GetType(t uint8) error {
208 208
 	if m.rpos >= len(m.Data) {
209 209
 		return io.ErrShortBuffer
210 210
 	}
@@ -217,102 +217,102 @@ func (m *Message) GetType(t uint8) error {
217 217
 	return nil
218 218
 }
219 219
 
220
-func (m *Message) GetTypeInt() (int, error) {
220
+func (m *message) GetTypeInt() (int, error) {
221 221
 	if err := m.GetType(mINT); err != nil {
222 222
 		return 0, err
223 223
 	}
224 224
 	return m.GetInt()
225 225
 }
226 226
 
227
-func (m *Message) GetTypeUint32() (uint32, error) {
227
+func (m *message) GetTypeUint32() (uint32, error) {
228 228
 	if err := m.GetType(mUINT32); err != nil {
229 229
 		return 0, err
230 230
 	}
231 231
 	return m.GetUint32()
232 232
 }
233 233
 
234
-func (m *Message) GetTypeSize() (uint64, error) {
234
+func (m *message) GetTypeSize() (uint64, error) {
235 235
 	if err := m.GetType(mSIZET); err != nil {
236 236
 		return 0, err
237 237
 	}
238 238
 	return m.GetSize()
239 239
 }
240 240
 
241
-func (m *Message) GetTypeString() (string, error) {
241
+func (m *message) GetTypeString() (string, error) {
242 242
 	if err := m.GetType(mSTRING); err != nil {
243 243
 		return "", err
244 244
 	}
245 245
 	return m.GetString()
246 246
 }
247 247
 
248
-func (m *Message) GetTypeID() (uint64, error) {
248
+func (m *message) GetTypeID() (uint64, error) {
249 249
 	if err := m.GetType(mID); err != nil {
250 250
 		return 0, err
251 251
 	}
252 252
 	return m.GetID()
253 253
 }
254 254
 
255
-func (m *Message) GetTypeSockaddr() (net.Addr, error) {
255
+func (m *message) GetTypeSockaddr() (net.Addr, error) {
256 256
 	if err := m.GetType(mSOCKADDR); err != nil {
257 257
 		return nil, err
258 258
 	}
259 259
 	return m.GetSockaddr()
260 260
 }
261 261
 
262
-func (m *Message) GetTypeMailaddr() (user, domain string, err error) {
262
+func (m *message) GetTypeMailaddr() (user, domain string, err error) {
263 263
 	if err = m.GetType(mMAILADDR); err != nil {
264 264
 		return
265 265
 	}
266 266
 	return m.GetMailaddr()
267 267
 }
268 268
 
269
-func (m *Message) PutInt(v int) {
269
+func (m *message) PutInt(v int) {
270 270
 	var b [4]byte
271 271
 	binary.LittleEndian.PutUint32(b[:], uint32(v))
272 272
 	m.Data = append(m.Data, b[:]...)
273 273
 	m.Header.Len += 4
274 274
 }
275 275
 
276
-func (m *Message) PutUint32(v uint32) {
276
+func (m *message) PutUint32(v uint32) {
277 277
 	var b [4]byte
278 278
 	binary.LittleEndian.PutUint32(b[:], v)
279 279
 	m.Data = append(m.Data, b[:]...)
280 280
 	m.Header.Len += 4
281 281
 }
282 282
 
283
-func (m *Message) PutString(s string) {
283
+func (m *message) PutString(s string) {
284 284
 	m.Data = append(m.Data, append([]byte(s), 0)...)
285 285
 	m.Header.Len += uint16(len(s)) + 1
286 286
 }
287 287
 
288
-func (m *Message) PutID(id uint64) {
288
+func (m *message) PutID(id uint64) {
289 289
 	var b [8]byte
290 290
 	binary.LittleEndian.PutUint64(b[:], id)
291 291
 	m.Data = append(m.Data, b[:]...)
292 292
 	m.Header.Len += 8
293 293
 }
294 294
 
295
-func (m *Message) PutType(t uint8) {
295
+func (m *message) PutType(t uint8) {
296 296
 	m.Data = append(m.Data, t)
297 297
 	m.Header.Len += 1
298 298
 }
299 299
 
300
-func (m *Message) PutTypeInt(v int) {
300
+func (m *message) PutTypeInt(v int) {
301 301
 	m.PutType(mINT)
302 302
 	m.PutInt(v)
303 303
 }
304 304
 
305
-func (m *Message) PutTypeUint32(v uint32) {
305
+func (m *message) PutTypeUint32(v uint32) {
306 306
 	m.PutType(mUINT32)
307 307
 	m.PutUint32(v)
308 308
 }
309 309
 
310
-func (m *Message) PutTypeString(s string) {
310
+func (m *message) PutTypeString(s string) {
311 311
 	m.PutType(mSTRING)
312 312
 	m.PutString(s)
313 313
 }
314 314
 
315
-func (m *Message) PutTypeID(id uint64) {
315
+func (m *message) PutTypeID(id uint64) {
316 316
 	m.PutType(mID)
317 317
 	m.PutID(id)
318 318
 }

+ 7
- 22
table.go View File

@@ -39,21 +39,6 @@ func procTableName(t uint32) string {
39 39
 	return fmt.Sprintf("UNKNOWN %d", t)
40 40
 }
41 41
 
42
-// Table services.
43
-const (
44
-	TableAlias       = 0x001 /* returns struct expand	*/
45
-	TableDomain      = 0x002 /* returns struct destination	*/
46
-	TableCredentials = 0x004 /* returns struct credentials	*/
47
-	TableNetAddr     = 0x008 /* returns struct netaddr	*/
48
-	TableUserInfo    = 0x010 /* returns struct userinfo	*/
49
-	TableSource      = 0x020 /* returns struct source	*/
50
-	TableMailAddr    = 0x040 /* returns struct mailaddr	*/
51
-	TableAddrName    = 0x080 /* returns struct addrname	*/
52
-	TableMailAddrMap = 0x100 /* returns struct maddrmap	*/
53
-	TableRelayHost   = 0x200 /* returns struct relayhost	*/
54
-	TableString      = 0x400
55
-)
56
-
57 42
 // Table implements the OpenSMTPD table API
58 43
 type Table struct {
59 44
 	// Update callback
@@ -72,7 +57,7 @@ type Table struct {
72 57
 	Close func() error
73 58
 
74 59
 	c      net.Conn
75
-	m      *Message
60
+	m      *message
76 61
 	closed bool
77 62
 }
78 63
 
@@ -83,7 +68,7 @@ func (t *Table) Serve() error {
83 68
 		return err
84 69
 	}
85 70
 
86
-	t.m = new(Message)
71
+	t.m = new(message)
87 72
 
88 73
 	for !t.closed {
89 74
 		if err = t.m.ReadFrom(t.c); err != nil {
@@ -137,7 +122,7 @@ func (t *Table) dispatch() (err error) {
137 122
 
138 123
 		debugf("table: version=%d name=%q\n", version, name)
139 124
 
140
-		m := new(Message)
125
+		m := new(message)
141 126
 		m.Header.Type = procTableOK
142 127
 		m.Header.Len = imsgHeaderSize
143 128
 		m.Header.PID = uint32(os.Getpid())
@@ -154,7 +139,7 @@ func (t *Table) dispatch() (err error) {
154 139
 			}
155 140
 		}
156 141
 
157
-		m := new(Message)
142
+		m := new(message)
158 143
 		m.Header.Type = procTableOK
159 144
 		m.PutInt(r)
160 145
 		if err = m.WriteTo(t.c); err != nil {
@@ -199,7 +184,7 @@ func (t *Table) dispatch() (err error) {
199 184
 
200 185
 		log.Printf("table_check: result=%d\n", r)
201 186
 
202
-		m := new(Message)
187
+		m := new(message)
203 188
 		m.Header.Type = procTableOK
204 189
 		m.Header.PID = uint32(os.Getpid())
205 190
 		m.PutInt(r)
@@ -233,7 +218,7 @@ func (t *Table) dispatch() (err error) {
233 218
 			}
234 219
 		}
235 220
 
236
-		m := new(Message)
221
+		m := new(message)
237 222
 		m.Header.Type = procTableOK
238 223
 		m.Header.PID = uint32(os.Getpid())
239 224
 		if val == "" {
@@ -267,7 +252,7 @@ func (t *Table) dispatch() (err error) {
267 252
 			}
268 253
 		}
269 254
 
270
-		m := new(Message)
255
+		m := new(message)
271 256
 		m.Header.Type = procTableOK
272 257
 		m.Header.PID = uint32(os.Getpid())
273 258
 		if val == "" {

Loading…
Cancel
Save