summaryrefslogtreecommitdiff
path: root/gdata/gdata-authorization-domain.c
blob: af067be3f560c9bcc02cfb076930db77fc5e1e21 (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
191
192
193
194
195
196
197
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * GData Client
 * Copyright (C) Philip Withnall 2011 <philip@tecnocode.co.uk>
 *
 * GData Client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GData Client 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gdata-authorization-domain
 * @short_description: GData authorization domain
 * @stability: Unstable
 * @include: gdata/gdata-authorization-domain.h
 *
 * A #GDataAuthorizationDomain represents a single data domain which a user can authorize libgdata to access. This might be a domain covering the
 * whole of the user's Google Contacts account, for example. Typically, #GDataService<!-- -->s map to #GDataAuthorizationDomains in a one-to-one
 * fashion, though some services (such as #GDataDocumentsService) use multiple authorization domains.
 *
 * The #GDataAuthorizationDomains<!-- -->s used by a service can be retrieved using gdata_service_get_authorization_domains(). The set of domains
 * used by a given service is static and will never change at runtime.
 *
 * #GDataAuthorizationDomain<!-- -->s are used by a #GDataAuthorizer instance to request authorization to interact with data in those domains when
 * first authenticating and authorizing with the online service. Typically, a given #GDataAuthorizer will be passed a set of domains (or a service
 * type, from which it can retrieve the service's set of domains) at construction time, and will use those domains when initially asking the user for
 * authorization and whenever the authorization is refreshed afterwards. It's not expected that the set of domains used by a #GDataAuthorizer will
 * change after construction time.
 *
 * Note that it's not expected that #GDataAuthorizationDomain<!-- -->s will have to be constructed manually. All #GDataService<!-- -->s should provide
 * accessor functions to return instances of all the authorization domains they support.
 *
 * Since: 0.9.0
 */

#include <glib.h>

#include "gdata-authorization-domain.h"

static void finalize (GObject *object);
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);

struct _GDataAuthorizationDomainPrivate {
	gchar *service_name;
	gchar *scope;
};

enum {
	PROP_SERVICE_NAME = 1,
	PROP_SCOPE,
};

G_DEFINE_TYPE (GDataAuthorizationDomain, gdata_authorization_domain, G_TYPE_OBJECT)

static void
gdata_authorization_domain_class_init (GDataAuthorizationDomainClass *klass)
{
	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

	g_type_class_add_private (klass, sizeof (GDataAuthorizationDomainPrivate));

	gobject_class->get_property = get_property;
	gobject_class->set_property = set_property;
	gobject_class->finalize = finalize;

	/**
	 * GDataAuthorizationDomain:service-name:
	 *
	 * The name of the service which contains the authorization domain, as enumerated in the
	 * <ulink type="http" url="http://code.google.com/apis/documents/faq_gdata.html#clientlogin">online documentation</ulink>.
	 *
	 * Since: 0.9.0
	 */
	g_object_class_install_property (gobject_class, PROP_SERVICE_NAME,
	                                 g_param_spec_string ("service-name",
	                                                      "Service name", "The name of the service which contains the authorization domain.",
	                                                      NULL,
	                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

	/**
	 * GDataAuthorizationDomain:scope:
	 *
	 * A URI detailing the scope of the authorization domain, as enumerated in the
	 * <ulink type="http" url="http://code.google.com/apis/documents/faq_gdata.html#AuthScopes">online documentation</ulink>.
	 *
	 * Since: 0.9.0
	 */
	g_object_class_install_property (gobject_class, PROP_SCOPE,
	                                 g_param_spec_string ("scope",
	                                                      "Scope", "A URI detailing the scope of the authorization domain.",
	                                                      NULL,
	                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}

static void
gdata_authorization_domain_init (GDataAuthorizationDomain *self)
{
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_AUTHORIZATION_DOMAIN, GDataAuthorizationDomainPrivate);
}

static void
finalize (GObject *object)
{
	GDataAuthorizationDomainPrivate *priv = GDATA_AUTHORIZATION_DOMAIN (object)->priv;

	g_free (priv->service_name);
	g_free (priv->scope);

	/* Chain up to the parent class */
	G_OBJECT_CLASS (gdata_authorization_domain_parent_class)->finalize (object);
}

static void
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
	GDataAuthorizationDomainPrivate *priv = GDATA_AUTHORIZATION_DOMAIN (object)->priv;

	switch (property_id) {
		case PROP_SERVICE_NAME:
			g_value_set_string (value, priv->service_name);
			break;
		case PROP_SCOPE:
			g_value_set_string (value, priv->scope);
			break;
		default:
			/* We don't have any other property... */
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
			break;
	}
}

static void
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
	GDataAuthorizationDomainPrivate *priv = GDATA_AUTHORIZATION_DOMAIN (object)->priv;

	switch (property_id) {
		/* Construct only */
		case PROP_SERVICE_NAME:
			priv->service_name = g_value_dup_string (value);
			break;
		/* Construct only */
		case PROP_SCOPE:
			priv->scope = g_value_dup_string (value);
			break;
		default:
			/* We don't have any other property... */
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
			break;
	}
}

/**
 * gdata_authorization_domain_get_service_name:
 * @self: a #GDataAuthorizationDomain
 *
 * Returns the name of the service containing the authorization domain. See #GDataAuthorizationDomain:service-name for more details.
 *
 * Return value: name of the service containing the authorization domain
 *
 * Since: 0.9.0
 */
const gchar *
gdata_authorization_domain_get_service_name (GDataAuthorizationDomain *self)
{
	g_return_val_if_fail (GDATA_IS_AUTHORIZATION_DOMAIN (self), NULL);

	return self->priv->service_name;
}

/**
 * gdata_authorization_domain_get_scope:
 * @self: a #GDataAuthorizationDomain
 *
 * Returns a URI detailing the scope of the authorization domain. See #GDataAuthorizationDomain:scope for more details.
 *
 * Return value: URI detailing the scope of the authorization domain
 *
 * Since: 0.9.0
 */
const gchar *
gdata_authorization_domain_get_scope (GDataAuthorizationDomain *self)
{
	g_return_val_if_fail (GDATA_IS_AUTHORIZATION_DOMAIN (self), NULL);

	return self->priv->scope;
}