Debian Codegraph @

govirt/ovirt-rest-call.c

raw symbols SCIP
1 /*
2 * ovirt-rest-call.c: oVirt librest call proxy
3 *
4 * Copyright (C) 2012, 2013 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 * Author: Christophe Fergeau <[email protected]>
21 */
22
23 #include <config.h>
24
25 #include <rest/rest-params.h>
26
27 #include "ovirt-proxy.h"
28 #include "ovirt-proxy-private.h"
29 #include "ovirt-rest-call.h"
30 #include "ovirt-rest-call-error.h"
31 #include "ovirt-utils.h"
32
33 struct _OvirtRestCallPrivate {
34 char *href;
35 };
36
37
38 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(OvirtRestCall, ovirt_rest_call, REST_TYPE_PROXY_CALL);
39
40
41 enum {
42 PROP_0,
43 PROP_METHOD,
44 PROP_HREF,
45 };
46
47
48 GQuark ovirt_rest_call_error_quark(void)
49 {
50 return g_quark_from_static_string("ovirt-rest-call");
51 }
52
53
54 static void ovirt_rest_call_get_property(GObject *object,
55 guint prop_id,
56 GValue *value,
57 GParamSpec *pspec)
58 {
59 OvirtRestCall *call = OVIRT_REST_CALL(object);
60
61 switch (prop_id) {
62 case PROP_METHOD: {
63 const char *method;
64
65 method = rest_proxy_call_get_method(REST_PROXY_CALL(call));
66 g_value_set_string(value, method);
67 break;
68 }
69 case PROP_HREF:
70 g_value_set_string(value, call->priv->href);
71 break;
72 default:
73 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
74 }
75 }
76
77
78 static void ovirt_rest_call_set_property(GObject *object,
79 guint prop_id,
80 const GValue *value,
81 GParamSpec *pspec)
82 {
83 OvirtRestCall *call = OVIRT_REST_CALL(object);
84
85 switch (prop_id) {
86 case PROP_METHOD:
87 rest_proxy_call_set_method(REST_PROXY_CALL(call),
88 g_value_get_string(value));
89 break;
90 case PROP_HREF:
91 g_free(call->priv->href);
92 call->priv->href = g_value_dup_string(value);
93 rest_proxy_call_set_function(REST_PROXY_CALL(call), call->priv->href);
94 break;
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void ovirt_rest_call_finalize(GObject *object)
102 {
103 OvirtRestCall *call = OVIRT_REST_CALL(object);
104
105 g_free(call->priv->href);
106
107 G_OBJECT_CLASS(ovirt_rest_call_parent_class)->finalize(object);
108 }
109
110
111 static void ovirt_rest_call_constructed(GObject *object)
112 {
113 OvirtProxy *proxy;
114
115 G_OBJECT_CLASS(ovirt_rest_call_parent_class)->constructed(object);
116
117 g_object_get(object, "proxy", &proxy, NULL);
118 if (proxy != NULL) {
119 gboolean admin;
120 g_object_get(G_OBJECT(proxy), "admin", &admin, NULL);
121 if (admin) {
122 rest_proxy_call_add_header(REST_PROXY_CALL(object), "Filter", "false");
123 } else {
124 rest_proxy_call_add_header(REST_PROXY_CALL(object), "Filter", "true");
125 }
126 ovirt_proxy_append_additional_headers(proxy, REST_PROXY_CALL(object));
127
128 g_object_unref(proxy);
129 }
130 }
131
132
133 static void ovirt_rest_call_class_init(OvirtRestCallClass *klass)
134 {
135 GObjectClass *object_class = G_OBJECT_CLASS(klass);
136 GParamSpec *param_spec;
137
138 object_class->get_property = ovirt_rest_call_get_property;
139 object_class->set_property = ovirt_rest_call_set_property;
140 object_class->constructed = ovirt_rest_call_constructed;
141 object_class->finalize = ovirt_rest_call_finalize;
142
143 param_spec = g_param_spec_string("method",
144 "Method",
145 "REST method for the call",
146 NULL,
147 G_PARAM_READWRITE |
148 G_PARAM_STATIC_STRINGS);
149 g_object_class_install_property(object_class,
150 PROP_METHOD,
151 param_spec);
152 param_spec = g_param_spec_string("href",
153 "Href",
154 "Resource Href",
155 NULL,
156 G_PARAM_READWRITE |
157 G_PARAM_STATIC_STRINGS);
158 g_object_class_install_property(object_class,
159 PROP_HREF,
160 param_spec);
161 }
162
163
164 static void ovirt_rest_call_init(G_GNUC_UNUSED OvirtRestCall *call)
165 {
166 call->priv = ovirt_rest_call_get_instance_private(call);
167 }