summaryrefslogtreecommitdiffstats
path: root/secret-service/tools/resolve-type.xsl
blob: a37f2af7899680db1e9a6be848ff937ea5d0c77c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
  xmlns:html="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="tp html">

<!--
    Helper templates for Telepathy D-Bus Introspection conversion.

    Copyright (C) 2009 Michael Leupold <lemma@confuego.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-->

    <!-- Resolve the type a node has. This will first look at tp:type and
        - if not found - use the type attribute -->
    <xsl:template name="ResolveType">
        <xsl:param name="node"/>
        <xsl:variable name="unstripped">
            <xsl:choose>
                <xsl:when test="$node//@tp:type">
                    <xsl:call-template name="TpType">
                        <xsl:with-param name="type" select="$node//@tp:type"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="$node//@type">
                    <xsl:call-template name="DBusType">
                        <xsl:with-param name="type" select="$node//@type"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:message terminate="yes">
                        Node doesn't contain a type.
                    </xsl:message>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="translate(translate($unstripped, ' ', ''), '&#xa;', '')"/>
    </xsl:template>

    <!-- Map a D-Bus type to its EggDBus counterpart -->
    <xsl:template name="DBusType">
        <xsl:param name="type"/>
        <xsl:choose>
            <xsl:when test="$type='o'">ObjectPath</xsl:when>
            <xsl:when test="$type='s'">String</xsl:when>
            <xsl:when test="$type='y'">Byte</xsl:when>
            <xsl:when test="$type='b'">Boolean</xsl:when>
            <xsl:when test="$type='n'">Int16</xsl:when>
            <xsl:when test="$type='q'">UInt16</xsl:when>
            <xsl:when test="$type='i'">Int32</xsl:when>
            <xsl:when test="$type='u'">UInt32</xsl:when>
            <xsl:when test="$type='x'">Int64</xsl:when>
            <xsl:when test="$type='t'">UInt64</xsl:when>
            <xsl:when test="$type='d'">Double</xsl:when>
            <xsl:when test="$type='g'">Signature</xsl:when>
            <xsl:when test="$type='v'">Variant</xsl:when>
            <xsl:when test="starts-with($type, 'a{')">
                Dict&lt;
                <xsl:call-template name="DBusType">
                    <xsl:with-param name="type" select="substring($type, 3, 1)"/>
                </xsl:call-template>
                ,
                <xsl:call-template name="DBusType">
                    <xsl:with-param name="type" select="substring($type, 4, 1)"/>
                </xsl:call-template>
                &gt;
            </xsl:when>
            <xsl:when test="starts-with($type, 'a')">
                Array&lt;
                <xsl:call-template name="DBusType">
                    <xsl:with-param name="type" select="substring($type, 2)"/>
                </xsl:call-template>
                &gt;
            </xsl:when>
            <!-- TODO: doesn't implement dict-entries and structs -->
            <xsl:otherwise>
                <xsl:message terminate="yes">
                    Unknown DBus Type <xsl:value-of select="$type"/>
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- Resolve tp:type attributes by searching for matching tp:struct
            and tp:mapping elements -->
    <xsl:template name="TpType">
        <xsl:param name="type"/>
        <xsl:choose>
            <xsl:when test="/tp:spec/tp:struct[@name=$type]">
                <xsl:value-of select="$type"/>
            </xsl:when>
            <xsl:when test="/tp:spec/tp:mapping[@name=$type]">
                Dict&lt;
                <xsl:call-template name="ResolveType">
                    <xsl:with-param name="node" select="/tp:spec/tp:mapping[@name=$type]/tp:member[@name='Key']"/>
                </xsl:call-template>,
                <xsl:call-template name="ResolveType">
                    <xsl:with-param name="node" select="/tp:spec/tp:mapping[@name=$type]/tp:member[@name='Value']"/>
                </xsl:call-template>
                &gt;
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="yes">
                    Unspecified type <xsl:value-of select="$type"/>.
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>