Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
b92cf048
Commit
b92cf048
authored
Jan 17, 2024
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement splitPath.
Use it for parsing special paths instead of ad hoc code.
parent
6455ae3a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
68 deletions
+59
-68
webserver/webserver.go
webserver/webserver.go
+25
-7
webserver/webserver_test.go
webserver/webserver_test.go
+29
-39
webserver/whip.go
webserver/whip.go
+5
-22
No files found.
webserver/webserver.go
View file @
b92cf048
...
...
@@ -300,24 +300,38 @@ func parseGroupName(prefix string, p string) string {
return
name
[
1
:
]
}
func
splitPath
(
pth
string
)
(
string
,
string
,
string
)
{
index
:=
strings
.
Index
(
pth
,
"/."
)
if
index
<
0
{
return
pth
,
""
,
""
}
index2
:=
strings
.
Index
(
pth
[
index
+
1
:
],
"/"
)
if
index2
<
0
{
return
pth
[
:
index
],
pth
[
index
+
1
:
],
""
}
return
pth
[
:
index
],
pth
[
index
+
1
:
index
+
1
+
index2
],
pth
[
index
+
1
+
index2
:
]
}
func
groupHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
redirect
(
w
,
r
)
{
return
}
if
strings
.
HasSuffix
(
r
.
URL
.
Path
,
"/.status.json"
)
{
_
,
kind
,
rest
:=
splitPath
(
r
.
URL
.
Path
)
if
kind
==
".status.json"
&&
rest
==
""
{
groupStatusHandler
(
w
,
r
)
return
}
dir
,
id
:=
parseWhip
(
r
.
URL
.
Path
)
if
dir
!=
""
{
if
id
==
""
{
}
else
if
kind
==
".whip"
{
if
rest
==
""
{
whipEndpointHandler
(
w
,
r
)
}
else
{
whipResourceHandler
(
w
,
r
)
}
return
}
else
if
kind
!=
""
{
notFound
(
w
)
return
}
name
:=
parseGroupName
(
"/group/"
,
r
.
URL
.
Path
)
...
...
@@ -369,7 +383,11 @@ func groupBase(r *http.Request) (string, error) {
}
func
groupStatusHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
pth
:=
path
.
Dir
(
r
.
URL
.
Path
)
pth
,
kind
,
rest
:=
splitPath
(
r
.
URL
.
Path
)
if
kind
!=
".status.json"
||
rest
!=
""
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
}
name
:=
parseGroupName
(
"/group/"
,
pth
)
if
name
==
""
{
notFound
(
w
)
...
...
webserver/webserver_test.go
View file @
b92cf048
...
...
@@ -22,42 +22,34 @@ func TestParseGroupName(t *testing.T) {
}
for
_
,
pg
:=
range
a
{
t
.
Run
(
pg
.
p
,
func
(
t
*
testing
.
T
)
{
g
:=
parseGroupName
(
"/group/"
,
pg
.
p
)
if
g
!=
pg
.
g
{
t
.
Errorf
(
"Path %v, got %v, expected %v"
,
pg
.
p
,
g
,
pg
.
g
)
}
})
g
:=
parseGroupName
(
"/group/"
,
pg
.
p
)
if
g
!=
pg
.
g
{
t
.
Errorf
(
"Path %v, got %v, expected %v"
,
pg
.
p
,
g
,
pg
.
g
)
}
}
}
func
TestParseWhip
(
t
*
testing
.
T
)
{
a
:=
[]
struct
{
p
,
d
,
b
string
}{
{
""
,
""
,
""
},
{
"/"
,
""
,
""
},
{
"/foo"
,
""
,
""
},
{
"/foo/"
,
""
,
""
},
{
"/foo/bar"
,
""
,
""
},
{
"/foo/bar/"
,
""
,
""
},
{
"/foo/bar/baz"
,
""
,
""
},
{
"/foo/bar/baz/"
,
""
,
""
},
{
"/foo/.whip"
,
"/foo/"
,
""
},
{
"/foo/.whip/"
,
"/foo/"
,
""
},
{
"/foo/.whip/bar"
,
"/foo/"
,
"bar"
},
{
"/foo/.whip/bar/"
,
"/foo/"
,
"bar"
},
{
"/foo/.whip/bar/baz"
,
""
,
""
},
{
"/foo/.whip/bar/baz/"
,
""
,
""
},
func
TestParseSplit
(
t
*
testing
.
T
)
{
a
:=
[]
struct
{
p
,
a
,
b
,
c
string
}{
{
""
,
""
,
""
,
""
},
{
"/a"
,
"/a"
,
""
,
""
},
{
"/a/.b"
,
"/a"
,
".b"
,
""
},
{
"/a/.b/"
,
"/a"
,
".b"
,
"/"
},
{
"/a/.b/c"
,
"/a"
,
".b"
,
"/c"
},
{
"/a/.b/c/"
,
"/a"
,
".b"
,
"/c/"
},
{
"/a/.b/c/d"
,
"/a"
,
".b"
,
"/c/d"
},
{
"/a/.b/c/d/"
,
"/a"
,
".b"
,
"/c/d/"
},
{
"/a/.b/c/d./"
,
"/a"
,
".b"
,
"/c/d./"
},
}
for
_
,
pdb
:=
range
a
{
t
.
Run
(
pdb
.
p
,
func
(
t
*
testing
.
T
)
{
d
,
b
:=
parseWhip
(
pdb
.
p
)
if
d
!=
pdb
.
d
||
b
!=
pdb
.
b
{
t
.
Errorf
(
"Path %v, got %v %v, expected %v %v"
,
pdb
.
p
,
d
,
b
,
pdb
.
d
,
pdb
.
b
)
}
})
for
_
,
pabc
:=
range
(
a
)
{
a
,
b
,
c
:=
splitPath
(
pabc
.
p
)
if
pabc
.
a
!=
a
||
pabc
.
b
!=
b
||
pabc
.
c
!=
c
{
t
.
Errorf
(
"Path %v, got %v, %v, %v, expected %v, %v, %v"
,
pabc
.
p
,
a
,
b
,
c
,
pabc
.
a
,
pabc
.
b
,
pabc
.
c
,
)
}
}
}
...
...
@@ -79,14 +71,12 @@ func TestParseBearerToken(t *testing.T) {
}
for
_
,
ab
:=
range
a
{
t
.
Run
(
ab
.
a
,
func
(
t
*
testing
.
T
)
{
b
:=
parseBearerToken
(
ab
.
a
)
if
b
!=
ab
.
b
{
t
.
Errorf
(
"Bearer token %v, got %v, expected %v"
,
ab
.
a
,
b
,
ab
.
b
,
)
}
})
b
:=
parseBearerToken
(
ab
.
a
)
if
b
!=
ab
.
b
{
t
.
Errorf
(
"Bearer token %v, got %v, expected %v"
,
ab
.
a
,
b
,
ab
.
b
,
)
}
}
}
...
...
webserver/whip.go
View file @
b92cf048
...
...
@@ -23,23 +23,6 @@ import (
"github.com/jech/galene/rtpconn"
)
func
parseWhip
(
pth
string
)
(
string
,
string
)
{
if
pth
!=
"/"
{
pth
=
strings
.
TrimSuffix
(
pth
,
"/"
)
}
dir
:=
path
.
Dir
(
pth
)
base
:=
path
.
Base
(
pth
)
if
base
==
".whip"
{
return
dir
+
"/"
,
""
}
if
path
.
Base
(
dir
)
==
".whip"
{
return
path
.
Dir
(
dir
)
+
"/"
,
base
}
return
""
,
""
}
var
idSecret
[]
byte
var
idCipher
cipher
.
Block
...
...
@@ -163,8 +146,8 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
return
}
pth
,
pthid
:=
parseWhip
(
r
.
URL
.
Path
)
if
pthid
!=
"
"
{
pth
,
kind
,
pthid
:=
splitPath
(
r
.
URL
.
Path
)
if
kind
!=
".whip"
||
pthid
!=
"/
"
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
return
...
...
@@ -282,13 +265,13 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
}
func
whipResourceHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
pth
,
obfuscated
:=
parseWhip
(
r
.
URL
.
Path
)
if
pth
==
""
||
obfuscated
==
""
{
pth
,
kind
,
rest
:=
splitPath
(
r
.
URL
.
Path
)
if
kind
!=
".whip"
||
rest
==
""
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
return
}
id
,
err
:=
deobfuscate
(
obfuscated
)
id
,
err
:=
deobfuscate
(
rest
[
1
:
]
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment