@@ -97,7 +97,7 @@ type lex struct {
97
97
comment string // any comment text seen
98
98
}
99
99
100
- // Tokens are returned when a zone file is parsed.
100
+ // * Tokens are returned when a zone file is parsed.
101
101
type Token struct {
102
102
RR // the scanned resource record when error is not nil
103
103
Error * ParseError // when an error occured, this has the error specifics
@@ -124,7 +124,7 @@ func ReadRR(q io.Reader, filename string) (RR, error) {
124
124
return r .RR , nil
125
125
}
126
126
127
- // ParseZone reads a RFC 1035 style one from r. It returns Tokens on the
127
+ // ParseZone reads a RFC 1035 style one from r. It returns * Tokens on the
128
128
// returned channel, which consist out the parsed RR, a potential comment or an error.
129
129
// If there is an error the RR is nil. The string file is only used
130
130
// in error reporting. The string origin is used as the initial origin, as
@@ -147,17 +147,17 @@ func ReadRR(q io.Reader, filename string) (RR, error) {
147
147
//
148
148
// The text "; this is comment" is returned in Token.Comment . Comments inside the
149
149
// RR are discarded. Comments on a line by themselves are discarded too.
150
- func ParseZone (r io.Reader , origin , file string ) chan Token {
150
+ func ParseZone (r io.Reader , origin , file string ) chan * Token {
151
151
return parseZoneHelper (r , origin , file , 10000 )
152
152
}
153
153
154
- func parseZoneHelper (r io.Reader , origin , file string , chansize int ) chan Token {
155
- t := make (chan Token , chansize )
154
+ func parseZoneHelper (r io.Reader , origin , file string , chansize int ) chan * Token {
155
+ t := make (chan * Token , chansize )
156
156
go parseZone (r , origin , file , t , 0 )
157
157
return t
158
158
}
159
159
160
- func parseZone (r io.Reader , origin , f string , t chan Token , include int ) {
160
+ func parseZone (r io.Reader , origin , f string , t chan * Token , include int ) {
161
161
defer func () {
162
162
if include == 0 {
163
163
close (t )
@@ -182,7 +182,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
182
182
}
183
183
origin = Fqdn (origin )
184
184
if _ , ok := IsDomainName (origin ); ! ok {
185
- t <- Token {Error : & ParseError {f , "bad initial origin name" , lex {}}}
185
+ t <- & Token {Error : & ParseError {f , "bad initial origin name" , lex {}}}
186
186
return
187
187
}
188
188
@@ -193,7 +193,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
193
193
for l := range c {
194
194
// Lexer spotted an error already
195
195
if l .err == true {
196
- t <- Token {Error : & ParseError {f , l .token , l }}
196
+ t <- & Token {Error : & ParseError {f , l .token , l }}
197
197
return
198
198
199
199
}
@@ -218,7 +218,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
218
218
}
219
219
_ , ok := IsDomainName (l .token )
220
220
if ! ok {
221
- t <- Token {Error : & ParseError {f , "bad owner name" , l }}
221
+ t <- & Token {Error : & ParseError {f , "bad owner name" , l }}
222
222
return
223
223
}
224
224
prevName = h .Name
@@ -244,7 +244,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
244
244
// line except the RR type
245
245
case _STRING : // First thing on the is the ttl
246
246
if ttl , ok := stringToTtl (l .token ); ! ok {
247
- t <- Token {Error : & ParseError {f , "not a TTL" , l }}
247
+ t <- & Token {Error : & ParseError {f , "not a TTL" , l }}
248
248
return
249
249
} else {
250
250
h .Ttl = ttl
@@ -254,18 +254,18 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
254
254
st = _EXPECT_ANY_NOTTL_BL
255
255
256
256
default :
257
- t <- Token {Error : & ParseError {f , "syntax error at beginning" , l }}
257
+ t <- & Token {Error : & ParseError {f , "syntax error at beginning" , l }}
258
258
return
259
259
}
260
260
case _EXPECT_DIRINCLUDE_BL :
261
261
if l .value != _BLANK {
262
- t <- Token {Error : & ParseError {f , "no blank after $INCLUDE-directive" , l }}
262
+ t <- & Token {Error : & ParseError {f , "no blank after $INCLUDE-directive" , l }}
263
263
return
264
264
}
265
265
st = _EXPECT_DIRINCLUDE
266
266
case _EXPECT_DIRINCLUDE :
267
267
if l .value != _STRING {
268
- t <- Token {Error : & ParseError {f , "expecting $INCLUDE value, not this..." , l }}
268
+ t <- & Token {Error : & ParseError {f , "expecting $INCLUDE value, not this..." , l }}
269
269
return
270
270
}
271
271
neworigin := origin // There may be optionally a new origin set after the filename, if not use current one
@@ -275,7 +275,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
275
275
l := <- c
276
276
if l .value == _STRING {
277
277
if _ , ok := IsDomainName (l .token ); ! ok {
278
- t <- Token {Error : & ParseError {f , "bad origin name" , l }}
278
+ t <- & Token {Error : & ParseError {f , "bad origin name" , l }}
279
279
return
280
280
}
281
281
// a new origin is specified.
@@ -292,59 +292,59 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
292
292
case _NEWLINE , _EOF :
293
293
// Ok
294
294
default :
295
- t <- Token {Error : & ParseError {f , "garbage after $INCLUDE" , l }}
295
+ t <- & Token {Error : & ParseError {f , "garbage after $INCLUDE" , l }}
296
296
return
297
297
}
298
298
// Start with the new file
299
299
r1 , e1 := os .Open (l .token )
300
300
if e1 != nil {
301
- t <- Token {Error : & ParseError {f , "failed to open `" + l .token + "'" , l }}
301
+ t <- & Token {Error : & ParseError {f , "failed to open `" + l .token + "'" , l }}
302
302
return
303
303
}
304
304
if include + 1 > 7 {
305
- t <- Token {Error : & ParseError {f , "too deeply nested $INCLUDE" , l }}
305
+ t <- & Token {Error : & ParseError {f , "too deeply nested $INCLUDE" , l }}
306
306
return
307
307
}
308
308
parseZone (r1 , l .token , neworigin , t , include + 1 )
309
309
st = _EXPECT_OWNER_DIR
310
310
case _EXPECT_DIRTTL_BL :
311
311
if l .value != _BLANK {
312
- t <- Token {Error : & ParseError {f , "no blank after $TTL-directive" , l }}
312
+ t <- & Token {Error : & ParseError {f , "no blank after $TTL-directive" , l }}
313
313
return
314
314
}
315
315
st = _EXPECT_DIRTTL
316
316
case _EXPECT_DIRTTL :
317
317
if l .value != _STRING {
318
- t <- Token {Error : & ParseError {f , "expecting $TTL value, not this..." , l }}
318
+ t <- & Token {Error : & ParseError {f , "expecting $TTL value, not this..." , l }}
319
319
return
320
320
}
321
321
if e , _ := slurpRemainder (c , f ); e != nil {
322
- t <- Token {Error : e }
322
+ t <- & Token {Error : e }
323
323
return
324
324
}
325
325
if ttl , ok := stringToTtl (l .token ); ! ok {
326
- t <- Token {Error : & ParseError {f , "expecting $TTL value, not this..." , l }}
326
+ t <- & Token {Error : & ParseError {f , "expecting $TTL value, not this..." , l }}
327
327
return
328
328
} else {
329
329
defttl = ttl
330
330
}
331
331
st = _EXPECT_OWNER_DIR
332
332
case _EXPECT_DIRORIGIN_BL :
333
333
if l .value != _BLANK {
334
- t <- Token {Error : & ParseError {f , "no blank after $ORIGIN-directive" , l }}
334
+ t <- & Token {Error : & ParseError {f , "no blank after $ORIGIN-directive" , l }}
335
335
return
336
336
}
337
337
st = _EXPECT_DIRORIGIN
338
338
case _EXPECT_DIRORIGIN :
339
339
if l .value != _STRING {
340
- t <- Token {Error : & ParseError {f , "expecting $ORIGIN value, not this..." , l }}
340
+ t <- & Token {Error : & ParseError {f , "expecting $ORIGIN value, not this..." , l }}
341
341
return
342
342
}
343
343
if e , _ := slurpRemainder (c , f ); e != nil {
344
- t <- Token {Error : e }
344
+ t <- & Token {Error : e }
345
345
}
346
346
if _ , ok := IsDomainName (l .token ); ! ok {
347
- t <- Token {Error : & ParseError {f , "bad origin name" , l }}
347
+ t <- & Token {Error : & ParseError {f , "bad origin name" , l }}
348
348
return
349
349
}
350
350
if l .token [l .length - 1 ] != '.' {
@@ -359,23 +359,23 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
359
359
st = _EXPECT_OWNER_DIR
360
360
case _EXPECT_DIRGENERATE_BL :
361
361
if l .value != _BLANK {
362
- t <- Token {Error : & ParseError {f , "no blank after $GENERATE-directive" , l }}
362
+ t <- & Token {Error : & ParseError {f , "no blank after $GENERATE-directive" , l }}
363
363
return
364
364
}
365
365
st = _EXPECT_DIRGENERATE
366
366
case _EXPECT_DIRGENERATE :
367
367
if l .value != _STRING {
368
- t <- Token {Error : & ParseError {f , "expecting $GENERATE value, not this..." , l }}
368
+ t <- & Token {Error : & ParseError {f , "expecting $GENERATE value, not this..." , l }}
369
369
return
370
370
}
371
371
if e := generate (l , c , t , origin ); e != "" {
372
- t <- Token {Error : & ParseError {f , e , l }}
372
+ t <- & Token {Error : & ParseError {f , e , l }}
373
373
return
374
374
}
375
375
st = _EXPECT_OWNER_DIR
376
376
case _EXPECT_OWNER_BL :
377
377
if l .value != _BLANK {
378
- t <- Token {Error : & ParseError {f , "no blank after owner" , l }}
378
+ t <- & Token {Error : & ParseError {f , "no blank after owner" , l }}
379
379
return
380
380
}
381
381
st = _EXPECT_ANY
@@ -389,26 +389,26 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
389
389
st = _EXPECT_ANY_NOCLASS_BL
390
390
case _STRING : // TTL is this case
391
391
if ttl , ok := stringToTtl (l .token ); ! ok {
392
- t <- Token {Error : & ParseError {f , "not a TTL" , l }}
392
+ t <- & Token {Error : & ParseError {f , "not a TTL" , l }}
393
393
return
394
394
} else {
395
395
h .Ttl = ttl
396
396
// defttl = ttl // don't set the defttl here
397
397
}
398
398
st = _EXPECT_ANY_NOTTL_BL
399
399
default :
400
- t <- Token {Error : & ParseError {f , "expecting RR type, TTL or class, not this..." , l }}
400
+ t <- & Token {Error : & ParseError {f , "expecting RR type, TTL or class, not this..." , l }}
401
401
return
402
402
}
403
403
case _EXPECT_ANY_NOCLASS_BL :
404
404
if l .value != _BLANK {
405
- t <- Token {Error : & ParseError {f , "no blank before class" , l }}
405
+ t <- & Token {Error : & ParseError {f , "no blank before class" , l }}
406
406
return
407
407
}
408
408
st = _EXPECT_ANY_NOCLASS
409
409
case _EXPECT_ANY_NOTTL_BL :
410
410
if l .value != _BLANK {
411
- t <- Token {Error : & ParseError {f , "no blank before TTL" , l }}
411
+ t <- & Token {Error : & ParseError {f , "no blank before TTL" , l }}
412
412
return
413
413
}
414
414
st = _EXPECT_ANY_NOTTL
@@ -421,14 +421,14 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
421
421
h .Rrtype = l .torc
422
422
st = _EXPECT_RDATA
423
423
default :
424
- t <- Token {Error : & ParseError {f , "expecting RR type or class, not this..." , l }}
424
+ t <- & Token {Error : & ParseError {f , "expecting RR type or class, not this..." , l }}
425
425
return
426
426
}
427
427
case _EXPECT_ANY_NOCLASS :
428
428
switch l .value {
429
429
case _STRING : // TTL
430
430
if ttl , ok := stringToTtl (l .token ); ! ok {
431
- t <- Token {Error : & ParseError {f , "not a TTL" , l }}
431
+ t <- & Token {Error : & ParseError {f , "not a TTL" , l }}
432
432
return
433
433
} else {
434
434
h .Ttl = ttl
@@ -439,18 +439,18 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
439
439
h .Rrtype = l .torc
440
440
st = _EXPECT_RDATA
441
441
default :
442
- t <- Token {Error : & ParseError {f , "expecting RR type or TTL, not this..." , l }}
442
+ t <- & Token {Error : & ParseError {f , "expecting RR type or TTL, not this..." , l }}
443
443
return
444
444
}
445
445
case _EXPECT_RRTYPE_BL :
446
446
if l .value != _BLANK {
447
- t <- Token {Error : & ParseError {f , "no blank before RR type" , l }}
447
+ t <- & Token {Error : & ParseError {f , "no blank before RR type" , l }}
448
448
return
449
449
}
450
450
st = _EXPECT_RRTYPE
451
451
case _EXPECT_RRTYPE :
452
452
if l .value != _RRTYPE {
453
- t <- Token {Error : & ParseError {f , "unknown RR type" , l }}
453
+ t <- & Token {Error : & ParseError {f , "unknown RR type" , l }}
454
454
return
455
455
}
456
456
h .Rrtype = l .torc
@@ -463,10 +463,10 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
463
463
if e .lex .token == "" && e .lex .value == 0 {
464
464
e .lex = l // Uh, dirty
465
465
}
466
- t <- Token {Error : e }
466
+ t <- & Token {Error : e }
467
467
return
468
468
}
469
- t <- Token {RR : r , Comment : c1 }
469
+ t <- & Token {RR : r , Comment : c1 }
470
470
st = _EXPECT_OWNER_DIR
471
471
}
472
472
}
0 commit comments