summaryrefslogtreecommitdiff
path: root/common/flatpak-json-private.h
blob: 20b7b8e52664e2111b7a8be3f4249d1a64d9bb8f (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
/*
 * Copyright © 2016 Red Hat, Inc
 *
 * This program 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Alexander Larsson <alexl@redhat.com>
 */

#ifndef __FLATPAK_JSON_H__
#define __FLATPAK_JSON_H__

#include <json-glib/json-glib.h>

G_BEGIN_DECLS

#define FLATPAK_TYPE_JSON flatpak_json_get_type ()

typedef struct _FlatpakJsonProp FlatpakJsonProp;

typedef enum {
  FLATPAK_JSON_PROP_TYPE_PARENT,
  FLATPAK_JSON_PROP_TYPE_INT64,
  FLATPAK_JSON_PROP_TYPE_BOOL,
  FLATPAK_JSON_PROP_TYPE_STRING,
  FLATPAK_JSON_PROP_TYPE_STRUCT,
  FLATPAK_JSON_PROP_TYPE_STRUCTV,
  FLATPAK_JSON_PROP_TYPE_STRV,
  FLATPAK_JSON_PROP_TYPE_STRMAP,
  FLATPAK_JSON_PROP_TYPE_BOOLMAP,
} FlatpakJsonPropType;

typedef enum {
  FLATPAK_JSON_PROP_FLAGS_NONE = 0,
  FLATPAK_JSON_PROP_FLAGS_OPTIONAL = 1 << 0,
  FLATPAK_JSON_PROP_FLAGS_STRICT = 1 << 1,
  FLATPAK_JSON_PROP_FLAGS_MANDATORY = 1 << 2,
} FlatpakJsonPropFlags;


struct _FlatpakJsonProp
{
  const char          *name;
  gsize                offset;
  FlatpakJsonPropType  type;
  gpointer             type_data;
  gpointer             type_data2;
  FlatpakJsonPropFlags flags;
};

#define FLATPAK_JSON_STRING_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRING }
#define FLATPAK_JSON_MANDATORY_STRING_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRING, 0, 0, FLATPAK_JSON_PROP_FLAGS_MANDATORY }
#define FLATPAK_JSON_INT64_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_INT64 }
#define FLATPAK_JSON_BOOL_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_BOOL }
#define FLATPAK_JSON_STRV_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRV }
#define FLATPAK_JSON_STRMAP_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRMAP }
#define FLATPAK_JSON_BOOLMAP_PROP(_struct, _field, _name) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_BOOLMAP }
#define FLATPAK_JSON_STRUCT_PROP(_struct, _field, _name, _props) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props}
#define FLATPAK_JSON_OPT_STRUCT_PROP(_struct, _field, _name, _props) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props, 0, FLATPAK_JSON_PROP_FLAGS_OPTIONAL}
#define FLATPAK_JSON_STRICT_STRUCT_PROP(_struct, _field, _name, _props) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props, 0, FLATPAK_JSON_PROP_FLAGS_STRICT}
#define FLATPAK_JSON_MANDATORY_STRICT_STRUCT_PROP(_struct, _field, _name, _props) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCT, (gpointer) _props, 0, FLATPAK_JSON_PROP_FLAGS_STRICT | FLATPAK_JSON_PROP_FLAGS_MANDATORY}
#define FLATPAK_JSON_PARENT_PROP(_struct, _field, _props) \
  { "parent", G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_PARENT, (gpointer) _props}
#define FLATPAK_JSON_STRUCTV_PROP(_struct, _field, _name, _props) \
  { _name, G_STRUCT_OFFSET (_struct, _field), FLATPAK_JSON_PROP_TYPE_STRUCTV, (gpointer) _props, (gpointer) sizeof (**((_struct *) 0)->_field) }
#define FLATPAK_JSON_LAST_PROP { NULL }

G_DECLARE_DERIVABLE_TYPE (FlatpakJson, flatpak_json, FLATPAK, JSON, GObject)

struct _FlatpakJsonClass
{
  GObjectClass     parent_class;

  FlatpakJsonProp *props;
  const char      *mediatype;
};

FlatpakJson *flatpak_json_from_node (JsonNode *node,
                                     GType     type,
                                     GError  **error);
JsonNode   *flatpak_json_to_node (FlatpakJson *self);
FlatpakJson *flatpak_json_from_bytes (GBytes  *bytes,
                                      GType    type,
                                      GError **error);
FlatpakJson *flatpak_json_from_stream (GInputStream *stream,
                                       GType         type,
                                       GCancellable *cancellable,
                                       GError      **error);
GBytes     *flatpak_json_to_bytes (FlatpakJson *self);

G_END_DECLS

#endif /* __FLATPAK_JSON_H__ */