[PATCH wayland] protocol: validate the protocol against a dtd

Peter Hutterer peter.hutterer at who-t.net
Thu Sep 19 04:30:15 PDT 2013


The scanner is not very forgiving if the protocol doesn't match it's
expectations and crashes without much of a notice. Thus, validate the protocol
against a DTD.

Move the protocol subdir forward so we validate first before trying anything
else, and install the DTD so we can validate weston's protocols as well.
---
 Makefile.am          |  3 ++-
 configure.ac         |  3 +++
 protocol/Makefile.am | 11 +++++++++++
 protocol/wayland.dtd | 29 +++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 protocol/wayland.dtd

diff --git a/Makefile.am b/Makefile.am
index ddf39d1..5b1b42f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ if BUILD_DOCS
 doc_subdir = doc
 endif
 
-SUBDIRS = src protocol $(doc_subdir) tests cursor
+SUBDIRS = protocol src $(doc_subdir) tests cursor
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
@@ -10,3 +10,4 @@ aclocaldir = $(datadir)/aclocal
 dist_aclocal_DATA = wayland-scanner.m4
 
 dist_pkgdata_DATA = wayland-scanner.mk
+
diff --git a/configure.ac b/configure.ac
index 5acbeef..2393b88 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,9 @@ fi
 AC_PATH_PROG(XSLTPROC, xsltproc)
 AM_CONDITIONAL([HAVE_XSLTPROC], [test "x$XSLTPROC" != "x"])
 
+AC_PATH_PROG(XMLLINT, xmllint)
+AM_CONDITIONAL([HAVE_XMLLINT], [test "x$XMLLINT" != "x"])
+
 AC_MSG_CHECKING([for docbook manpages stylesheet])
 MANPAGES_STYLESHEET=http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
 AC_PATH_PROGS_FEATURE_CHECK([XSLTPROC_TMP], [xsltproc],
diff --git a/protocol/Makefile.am b/protocol/Makefile.am
index 08690b3..f266ec6 100644
--- a/protocol/Makefile.am
+++ b/protocol/Makefile.am
@@ -1 +1,12 @@
 EXTRA_DIST = wayland.xml
+
+dist_pkgdata_DATA = wayland.dtd
+
+if HAVE_XMLLINT
+validate: wayland.xml
+	$(AM_V_GEN)$(XMLLINT) --noout --dtdvalid $(srcdir)/wayland.dtd $^
+
+all-local: validate
+
+.PHONY: validate
+endif
diff --git a/protocol/wayland.dtd b/protocol/wayland.dtd
new file mode 100644
index 0000000..b8b1573
--- /dev/null
+++ b/protocol/wayland.dtd
@@ -0,0 +1,29 @@
+<!ELEMENT protocol (copyright?, interface+)>
+  <!ATTLIST protocol name CDATA #REQUIRED>
+<!ELEMENT copyright (#PCDATA)>
+<!ELEMENT interface (description?,(request|event|enum)+)>
+  <!ATTLIST interface name CDATA #REQUIRED>
+  <!ATTLIST interface version CDATA #REQUIRED>
+<!ELEMENT request (description?,arg*)>
+  <!ATTLIST request name CDATA #REQUIRED>
+  <!ATTLIST request type CDATA #IMPLIED>
+  <!ATTLIST request since CDATA #IMPLIED>
+<!ELEMENT event (description?,arg*)>
+  <!ATTLIST event name CDATA #REQUIRED>
+  <!ATTLIST event since CDATA #IMPLIED>
+<!ELEMENT enum (description?,entry*)>
+  <!ATTLIST enum name CDATA #REQUIRED>
+  <!ATTLIST enum since CDATA #IMPLIED>
+<!ELEMENT entry (description?)>
+  <!ATTLIST entry name CDATA #REQUIRED>
+  <!ATTLIST entry value CDATA #REQUIRED>
+  <!ATTLIST entry summary CDATA #IMPLIED>
+  <!ATTLIST entry since CDATA #IMPLIED>
+<!ELEMENT arg (description?)>
+  <!ATTLIST arg name CDATA #REQUIRED>
+  <!ATTLIST arg type CDATA #REQUIRED>
+  <!ATTLIST arg summary CDATA #IMPLIED>
+  <!ATTLIST arg interface CDATA #IMPLIED>
+  <!ATTLIST arg allow-null CDATA #IMPLIED>
+<!ELEMENT description (#PCDATA)>
+  <!ATTLIST description summary CDATA #REQUIRED>
-- 
1.8.3.1



More information about the wayland-devel mailing list