summaryrefslogtreecommitdiff
path: root/libgupnp/gupnp-types.c
blob: ba965bf252be64ab2f2ddc97873e42970a771b2e (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2007 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 * Copyright (C) 2006, 2007 OpenedHand Ltd.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */

/**
 * SECTION:gupnp-types
 * @short_description: Extra types for use when calling UPnP actions.
 *
 * These GTypes are used to marshal to and from string data to particular UPnP
 * types when invoking actions on a #GUPnPServiceProxy.
 */

#include <config.h>
#include <string.h>

#include "gupnp-types.h"
#include "gupnp-types-private.h"

static void
gupnp_string_type_to_string (const GValue *src_value,
                             GValue       *dest_value)
{
        const char *str;

        str = gupnp_value_get_string (src_value);

        g_value_set_string (dest_value, str);
}

static void
gupnp_string_to_string_type (const GValue *src_value,
                             GValue       *dest_value)
{
        const char *str;

        str = g_value_get_string (src_value);

        g_value_set_boxed (dest_value, str);
}

static GType
register_string_type (const char *name)
{
        GType type;

        type = g_boxed_type_register_static (
                                g_intern_static_string (name),
                                (GBoxedCopyFunc) g_strdup,
                                (GBoxedFreeFunc) g_free);
        g_value_register_transform_func (
                        type,
                        G_TYPE_STRING,
                        gupnp_string_type_to_string);
        g_value_register_transform_func (
                        G_TYPE_STRING,
                        type,
                        gupnp_string_to_string_type);

        return type;
}

GType
gupnp_bin_base64_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPBinBase64");

        return type;
}

GType
gupnp_bin_hex_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPBinHex");

        return type;
}

GType
gupnp_date_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPDate");

        return type;
}

GType
gupnp_date_time_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPDateTime");

        return type;
}

GType
gupnp_date_time_tz_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPDateTimeTZ");

        return type;
}

GType
gupnp_time_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPTime");

        return type;
}

GType
gupnp_time_tz_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPTimeTZ");

        return type;
}

GType
gupnp_uri_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPURI");

        return type;
}

GType
gupnp_uuid_get_type (void)
{
        static GType type = 0;

        if (!type)
                type = register_string_type ("GUPnPUUID");

        return type;
}

GType
gupnp_data_type_to_gtype (const char *data_type)
{
        if (g_ascii_strcasecmp ("UUID", data_type) == 0)
                return GUPNP_TYPE_UUID;
        else if (g_ascii_strcasecmp ("URI", data_type) == 0)
                return GUPNP_TYPE_URI;
        else if (g_ascii_strcasecmp ("time.tz", data_type) == 0)
                return GUPNP_TYPE_TIME_TZ;
        else if (g_ascii_strcasecmp ("dateTime.tz", data_type) == 0)
                return GUPNP_TYPE_DATE_TIME_TZ;
        else if (g_ascii_strcasecmp ("dateTime", data_type) == 0)
                return GUPNP_TYPE_DATE_TIME;
        else if (g_ascii_strcasecmp ("date", data_type) == 0)
                return GUPNP_TYPE_DATE;
        else if (g_ascii_strcasecmp ("time", data_type) == 0)
                return GUPNP_TYPE_TIME;
        else if (g_ascii_strcasecmp ("bin.base64", data_type) == 0)
                return GUPNP_TYPE_BIN_BASE64;
        else if (g_ascii_strcasecmp ("bin.hex", data_type) == 0)
                return GUPNP_TYPE_BIN_HEX;
        else
                return G_TYPE_INVALID;
}