Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar-wayland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar-wayland
Commits
dba4294b
Commit
dba4294b
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Parse more xml attributes and verify invariants
parent
44c6b52e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/Wayland/Protocol/Core.hs
+6
-0
6 additions, 0 deletions
src/Quasar/Wayland/Protocol/Core.hs
src/Quasar/Wayland/Protocol/TH.hs
+47
-13
47 additions, 13 deletions
src/Quasar/Wayland/Protocol/TH.hs
with
53 additions
and
13 deletions
src/Quasar/Wayland/Protocol/Core.hs
+
6
−
0
View file @
dba4294b
...
...
@@ -28,6 +28,7 @@ module Quasar.Wayland.Protocol.Core (
setException
,
showObjectMessage
,
isNewId
,
-- * Message decoder operations
WireFormat
(
..
),
...
...
@@ -94,6 +95,11 @@ data ArgumentType
|
FdArgument
deriving
stock
(
Eq
,
Show
,
Lift
)
isNewId
::
ArgumentType
->
Bool
isNewId
(
NewIdArgument
_
)
=
True
isNewId
GenericNewIdArgument
=
True
isNewId
_
=
False
class
(
Eq
(
Argument
a
),
Show
(
Argument
a
))
=>
WireFormat
a
where
type
Argument
a
putArgument
::
Argument
a
->
PutM
()
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Wayland/Protocol/TH.hs
+
47
−
13
View file @
dba4294b
...
...
@@ -37,14 +37,16 @@ data MessageSpec = MessageSpec {
name
::
String
,
since
::
Maybe
Integer
,
opcode
::
Opcode
,
arguments
::
[
ArgumentSpec
]
arguments
::
[
ArgumentSpec
],
isDestructor
::
Bool
}
deriving
stock
Show
data
ArgumentSpec
=
ArgumentSpec
{
name
::
String
,
index
::
Integer
,
argType
::
ArgumentType
argType
::
ArgumentType
,
nullable
::
Bool
}
deriving
stock
Show
...
...
@@ -333,41 +335,73 @@ parseInterface element = do
}
parseRequest
::
MonadFail
m
=>
String
->
(
Opcode
,
Element
)
->
m
RequestSpec
parseRequest
x
y
=
RequestSpec
<$>
parseMessage
x
y
parseRequest
x
y
=
RequestSpec
<$>
parseMessage
True
x
y
parseEvent
::
MonadFail
m
=>
String
->
(
Opcode
,
Element
)
->
m
EventSpec
parseEvent
x
y
=
EventSpec
<$>
parseMessage
x
y
parseEvent
x
y
=
EventSpec
<$>
parseMessage
False
x
y
parseMessage
::
MonadFail
m
=>
Bool
->
String
->
(
Opcode
,
Element
)
->
m
MessageSpec
parseMessage
isRequest
interfaceName
(
opcode
,
element
)
=
do
let
isEvent
=
not
isRequest
parseMessage
::
MonadFail
m
=>
String
->
(
Opcode
,
Element
)
->
m
MessageSpec
parseMessage
interfaceName
(
opcode
,
element
)
=
do
name
<-
getAttr
"name"
element
let
description
=
interfaceName
<>
"."
<>
name
mtype
<-
peekAttr
"type"
element
since
<-
read
<<$>>
peekAttr
"since"
element
arguments
<-
mapM
parseArgument
$
zip
[
0
..
]
$
findChildren
(
qname
"arg"
)
element
arguments
<-
mapM
(
parseArgument
description
)
$
zip
[
0
..
]
$
findChildren
(
qname
"arg"
)
element
isDestructor
<-
case
mtype
of
Nothing
->
pure
False
Just
"destructor"
->
pure
True
Just
messageType
->
fail
$
"Unknown message type: "
<>
messageType
when
do
isEvent
&&
isDestructor
do
fail
$
"Event cannot be a destructor: "
<>
description
when
do
(
foldr
(
\
arg
->
if
isNewId
arg
.
argType
then
(
+
1
)
else
id
)
0
arguments
)
>
1
do
fail
$
"Message creates multiple objects: "
<>
description
forM_
arguments
\
arg
->
do
when
do
arg
.
argType
==
GenericNewIdArgument
&&
(
interfaceName
/=
"wl_registry"
||
name
/=
"bind"
)
do
fail
$
"Invalid
'
new_id
'
argument without
'
interface
'
attribute encountered on "
<>
interfaceName
<>
"."
<>
name
<>
" (only valid on wl_registry.bind)"
do
fail
$
"Invalid
\"
new_id
\"
argument without
\"
interface
\"
attribute encountered on "
<>
description
<>
" (only valid on wl_registry.bind)"
when
do
arg
.
argType
==
GenericObjectArgument
&&
(
interfaceName
/=
"wl_display"
||
name
/=
"error"
)
do
fail
$
"Invalid 'object' argument without 'interface' attribute encountered on "
<>
interfaceName
<>
"."
<>
name
<>
" (only valid on wl_display.error)"
do
fail
$
"Invalid
\"
object
\"
argument without
\"
interface
\"
attribute encountered on "
<>
description
<>
" (only valid on wl_display.error)"
pure
MessageSpec
{
name
,
since
,
opcode
,
arguments
arguments
,
isDestructor
}
parseArgument
::
forall
m
.
MonadFail
m
=>
(
Integer
,
Element
)
->
m
ArgumentSpec
parseArgument
(
index
,
element
)
=
do
parseArgument
::
forall
m
.
MonadFail
m
=>
String
->
(
Integer
,
Element
)
->
m
ArgumentSpec
parseArgument
messageDescription
(
index
,
element
)
=
do
name
<-
getAttr
"name"
element
argTypeStr
<-
getAttr
"type"
element
interface
<-
peekAttr
"interface"
element
argType
<-
parseArgumentType
argTypeStr
interface
let
description
=
messageDescription
<>
"."
<>
name
nullable
<-
peekAttr
"allow-null"
element
>>=
\
case
Just
"true"
->
pure
True
Just
"false"
->
pure
False
Just
x
->
fail
$
"Invalid value for attribute
\"
allow-null
\"
on "
<>
description
<>
": "
<>
x
Nothing
->
pure
False
pure
ArgumentSpec
{
name
,
index
,
argType
argType
,
nullable
}
where
parseArgumentType
::
String
->
Maybe
String
->
m
ArgumentType
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment