summaryrefslogtreecommitdiff
path: root/src/polkit/polkitauthorizationresult.c
blob: e9961c06ffc6833489667894040f0e7d04f06ba1 (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
198
199
/*
 * Copyright (C) 2008 Red Hat, Inc.
 *
 * 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 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., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: David Zeuthen <davidz@redhat.com>
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include "polkitauthorizationresult.h"
#include "polkitprivate.h"

/**
 * SECTION:polkitauthorizationresult
 * @title: PolkitAuthorizationResult
 * @short_description: Result for checking an authorization
 * @stability: Stable
 *
 * This class represents the result you get when checking for an authorization.
 */

struct _PolkitAuthorizationResult
{
  GObject parent_instance;

  _PolkitAuthorizationResult *real;

  PolkitDetails *details;
};

struct _PolkitAuthorizationResultClass
{
  GObjectClass parent_class;
};

G_DEFINE_TYPE (PolkitAuthorizationResult, polkit_authorization_result, G_TYPE_OBJECT);

static void
polkit_authorization_result_init (PolkitAuthorizationResult *authorization_result)
{
}

static void
polkit_authorization_result_finalize (GObject *object)
{
  PolkitAuthorizationResult *authorization_result;

  authorization_result = POLKIT_AUTHORIZATION_RESULT (object);

  g_object_unref (authorization_result->real);
  if (authorization_result->details != NULL)
    g_object_unref (authorization_result->details);

  if (G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize != NULL)
    G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize (object);
}

static void
polkit_authorization_result_class_init (PolkitAuthorizationResultClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->finalize = polkit_authorization_result_finalize;
}

PolkitAuthorizationResult  *
polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real)
{
  PolkitAuthorizationResult *authorization_result;

  authorization_result = POLKIT_AUTHORIZATION_RESULT (g_object_new (POLKIT_TYPE_AUTHORIZATION_RESULT, NULL));

  authorization_result->real = g_object_ref (real);

  return authorization_result;
}

_PolkitAuthorizationResult *
polkit_authorization_result_get_real (PolkitAuthorizationResult  *authorization_result)
{
  return g_object_ref (authorization_result->real);
}

/* ---------------------------------------------------------------------------------------------------- */

/**
 * polkit_authorization_result_new:
 * @is_authorized:
 * @is_challenge:
 * @details:
 *
 *
 *
 * Returns:
 **/
PolkitAuthorizationResult *
polkit_authorization_result_new (gboolean                   is_authorized,
                                 gboolean                   is_challenge,
                                 PolkitDetails             *details)
{
  PolkitAuthorizationResult *authorization_result;
  _PolkitAuthorizationResult *real;
  EggDBusHashMap *real_details;

  real_details = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
  if (details != NULL)
    {
      GHashTable *hash;
      GHashTableIter iter;
      gpointer key, value;

      hash = polkit_details_get_hash (details);
      if (hash != NULL)
        {
          g_hash_table_iter_init (&iter, hash);
          while (g_hash_table_iter_next (&iter, &key, &value))
            {
              egg_dbus_hash_map_insert (real_details, g_strdup (key), g_strdup (value));
            }
        }
    }

  real = _polkit_authorization_result_new (is_authorized, is_challenge, real_details);
  g_object_unref (real_details);

  authorization_result = polkit_authorization_result_new_for_real (real);

  g_object_unref (real);

  return authorization_result;
}

/**
 * polkit_authorization_result_get_is_authorized:
 * @result:
 *
 *
 *
 * Returns:
 **/
gboolean
polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result)
{
  return _polkit_authorization_result_get_is_authorized (result->real);
}

/**
 * polkit_authorization_result_get_is_challenge:
 * @result:
 *
 *
 *
 * Returns:
 **/
gboolean
polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
{
  return _polkit_authorization_result_get_is_challenge (result->real);
}

/**
 * polkit_authorization_result_get_details:
 * @result:
 *
 *
 *
 * Returns:
 **/
PolkitDetails *
polkit_authorization_result_get_details (PolkitAuthorizationResult *result)
{
  EggDBusHashMap *real_details;

  if (result->details != NULL)
    goto out;

  real_details = _polkit_authorization_result_get_details (result->real);
  if (real_details != NULL)
    result->details = result->details = polkit_details_new_for_hash (real_details->data);

 out:
  return result->details;
}