summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-10-31 11:11:53 -0600
committertjpcc <tjp@ctrl-c.club>2023-10-31 11:15:08 -0600
commit1a3ec70d3f0b7d62e570f3b85aa7e0e034a2cc7b (patch)
tree08e3f9dfc1260cb324625b6437b0254fee89e5bd /parse.go
parent9d102cb910fe9687b94235da04125329cd787054 (diff)
move 'auth' to a modifier
fixes #12
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go56
1 files changed, 33 insertions, 23 deletions
diff --git a/parse.go b/parse.go
index c93e33e..f97cf83 100644
--- a/parse.go
+++ b/parse.go
@@ -120,12 +120,12 @@ func Parse(input io.ReadCloser) (*Configuration, error) {
for i := range servers {
for j := range servers[i].Routes {
- if name := servers[i].Routes[j].authName; name != "" {
+ if name := servers[i].Routes[j].Modifiers.authName; name != "" {
auth, ok := auths[name]
if !ok {
return nil, fmt.Errorf("auth '%s' not found", name)
}
- servers[i].Routes[j].Auth = auth
+ servers[i].Routes[j].Modifiers.Auth = auth
}
if name := servers[i].Routes[j].Modifiers.titanName; name != "" {
@@ -312,7 +312,7 @@ func validateRoute(serverType string, dir *RouteDirective) error {
if serverType == "finger" && dir.Type != "static" && dir.Type != "cgi" {
return fmt.Errorf("finger servers don't support '%s' directives", dir.Type)
}
- if serverType == "finger" && dir.authName != "" {
+ if serverType == "finger" && dir.Modifiers.authName != "" {
return errors.New("finger servers don't support 'auth' clauses")
}
if serverType != "finger" && dir.URLPath == "" {
@@ -381,33 +381,28 @@ func parseRouteDirective(line string) (RouteDirective, error) {
return dir, nil
}
- word, rest, found := strings.Cut(rest, " ")
- if found && word == "at" {
- var urlpath string
- urlpath, rest, _ = strings.Cut(rest, " ")
- dir.URLPath = urlpath
- } else if found {
- rest = word + " " + rest
- }
-
- for rest != "" {
+ var word string
+ for {
word, rest, found = strings.Cut(rest, " ")
if !found {
- return dir, fmt.Errorf("invalid '%s' directive", tag)
+ return dir, nil
}
- var err error
- if word == "with" {
+ switch word {
+ case "at":
+ var urlpath string
+ urlpath, rest, _ = strings.Cut(rest, " ")
+ dir.URLPath = urlpath
+ case "with":
+ var err error
dir.Modifiers, rest, err = parseModifiers(rest)
- } else if word == "auth" {
- dir.authName, rest, err = parseAuth(rest)
- }
- if err != nil {
- return dir, err
+ if err != nil {
+ return dir, err
+ }
+ default:
+ return dir, fmt.Errorf("invalid '%s' directive", tag)
}
}
-
- return dir, nil
}
func parseModifiers(text string) (Modifiers, string, error) {
@@ -471,6 +466,21 @@ func parseModifiers(text string) (Modifiers, string, error) {
mod.ExtendedGophermap = true
case "autoatom":
mod.AutoAtom = true
+ case "auth":
+ if sep != " " {
+ return mod, "", errors.New("invalid 'auth' clause")
+ }
+ text = strings.TrimLeft(text, " \t")
+ idx = strings.IndexAny(text, " \t,")
+ if idx == 0 {
+ return mod, "", errors.New("invalid 'auth' clause")
+ } else if idx < 0 {
+ mod.authName = text
+ text = ""
+ } else {
+ mod.authName = text[0:idx]
+ text = text[idx+1:]
+ }
case "titan":
if sep != " " {
return mod, "", errors.New("invalid 'titan' clause")