~ubuntu-branches/debian/sid/glib2.0/sid

« back to all changes in this revision

Viewing changes to gio/gtlsdatabase.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 06:25:57 UTC
  • mfrom: (1.27.14) (3.1.181 experimental)
  • Revision ID: package-import@ubuntu.com-20130508062557-i7gbku66mls70gi2
Tags: 2.36.1-2
Merge experimental branch, upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "gasyncresult.h"
28
28
#include "gcancellable.h"
29
29
#include "glibintl.h"
30
 
#include "gsimpleasyncresult.h"
31
30
#include "gsocketconnectable.h"
 
31
#include "gtask.h"
32
32
#include "gtlscertificate.h"
33
33
#include "gtlsinteraction.h"
34
34
 
89
89
  GSocketConnectable *identity;
90
90
  GTlsInteraction *interaction;
91
91
  GTlsDatabaseVerifyFlags flags;
92
 
  GTlsCertificateFlags verify_result;
93
92
} AsyncVerifyChain;
94
93
 
95
94
static void
104
103
}
105
104
 
106
105
static void
107
 
async_verify_chain_thread (GSimpleAsyncResult *res,
108
 
                           GObject            *object,
109
 
                           GCancellable       *cancellable)
 
106
async_verify_chain_thread (GTask         *task,
 
107
                           gpointer       object,
 
108
                           gpointer       task_data,
 
109
                           GCancellable  *cancellable)
110
110
{
111
 
  AsyncVerifyChain *args = g_simple_async_result_get_op_res_gpointer (res);
 
111
  AsyncVerifyChain *args = task_data;
 
112
  GTlsCertificateFlags verify_result;
112
113
  GError *error = NULL;
113
114
 
114
 
  args->verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
115
 
                                                     args->chain,
116
 
                                                     args->purpose,
117
 
                                                     args->identity,
118
 
                                                     args->interaction,
119
 
                                                     args->flags,
120
 
                                                     cancellable,
121
 
                                                     &error);
122
 
 
 
115
  verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
 
116
                                               args->chain,
 
117
                                               args->purpose,
 
118
                                               args->identity,
 
119
                                               args->interaction,
 
120
                                               args->flags,
 
121
                                               cancellable,
 
122
                                               &error);
123
123
  if (error)
124
 
      g_simple_async_result_take_error (res, error);
 
124
    g_task_return_error (task, error);
 
125
  else
 
126
    g_task_return_int (task, (gssize)verify_result);
125
127
}
126
128
 
127
129
static void
135
137
                                        GAsyncReadyCallback     callback,
136
138
                                        gpointer                user_data)
137
139
{
138
 
  GSimpleAsyncResult *res;
 
140
  GTask *task;
139
141
  AsyncVerifyChain *args;
140
142
 
141
143
  args = g_slice_new0 (AsyncVerifyChain);
145
147
  args->interaction = interaction ? g_object_ref (interaction) : NULL;
146
148
  args->flags = flags;
147
149
 
148
 
  res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
149
 
                                   g_tls_database_real_verify_chain_async);
150
 
  g_simple_async_result_set_op_res_gpointer (res, args, async_verify_chain_free);
151
 
  g_simple_async_result_run_in_thread (res, async_verify_chain_thread,
152
 
                                       G_PRIORITY_DEFAULT, cancellable);
153
 
  g_object_unref (res);
 
150
  task = g_task_new (self, cancellable, callback, user_data);
 
151
  g_task_set_task_data (task, args, async_verify_chain_free);
 
152
  g_task_run_in_thread (task, async_verify_chain_thread);
 
153
  g_object_unref (task);
154
154
}
155
155
 
156
156
static GTlsCertificateFlags
158
158
                                         GAsyncResult          *result,
159
159
                                         GError               **error)
160
160
{
161
 
  AsyncVerifyChain *args;
162
 
 
163
 
  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), G_TLS_CERTIFICATE_GENERIC_ERROR);
164
 
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
165
 
                        g_tls_database_real_verify_chain_async), FALSE);
166
 
 
167
 
  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
 
161
  GTlsCertificateFlags ret;
 
162
 
 
163
  g_return_val_if_fail (g_task_is_valid (result, self), G_TLS_CERTIFICATE_GENERIC_ERROR);
 
164
 
 
165
  ret = (GTlsCertificateFlags)g_task_propagate_int (G_TASK (result), error);
 
166
  if (ret == (GTlsCertificateFlags)-1)
168
167
    return G_TLS_CERTIFICATE_GENERIC_ERROR;
169
 
 
170
 
  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
171
 
  return args->verify_result;
 
168
  else
 
169
    return ret;
172
170
}
173
171
 
174
172
typedef struct {
175
173
  gchar *handle;
176
174
  GTlsInteraction *interaction;
177
175
  GTlsDatabaseLookupFlags flags;
178
 
  GTlsCertificate *result;
179
176
} AsyncLookupCertificateForHandle;
180
177
 
181
178
static void
185
182
 
186
183
  g_free (args->handle);
187
184
  g_clear_object (&args->interaction);
188
 
  g_clear_object (&args->result);
189
185
  g_slice_free (AsyncLookupCertificateForHandle, args);
190
186
}
191
187
 
192
188
static void
193
 
async_lookup_certificate_for_handle_thread (GSimpleAsyncResult *res,
194
 
                                            GObject            *object,
195
 
                                            GCancellable       *cancellable)
 
189
async_lookup_certificate_for_handle_thread (GTask         *task,
 
190
                                            gpointer       object,
 
191
                                            gpointer       task_data,
 
192
                                            GCancellable  *cancellable)
196
193
{
197
 
  AsyncLookupCertificateForHandle *args = g_simple_async_result_get_op_res_gpointer (res);
 
194
  AsyncLookupCertificateForHandle *args = task_data;
 
195
  GTlsCertificate *result;
198
196
  GError *error = NULL;
199
197
 
200
 
  args->result = g_tls_database_lookup_certificate_for_handle (G_TLS_DATABASE (object),
201
 
                                                               args->handle,
202
 
                                                               args->interaction,
203
 
                                                               args->flags,
204
 
                                                               cancellable,
205
 
                                                               &error);
206
 
 
207
 
  if (error)
208
 
      g_simple_async_result_take_error (res, error);
 
198
  result = g_tls_database_lookup_certificate_for_handle (G_TLS_DATABASE (object),
 
199
                                                         args->handle,
 
200
                                                         args->interaction,
 
201
                                                         args->flags,
 
202
                                                         cancellable,
 
203
                                                         &error);
 
204
  if (result)
 
205
    g_task_return_pointer (task, result, g_object_unref);
 
206
  else
 
207
    g_task_return_error (task, error);
209
208
}
210
209
 
211
210
static void
217
216
                                                         GAsyncReadyCallback     callback,
218
217
                                                         gpointer                user_data)
219
218
{
220
 
  GSimpleAsyncResult *res;
 
219
  GTask *task;
221
220
  AsyncLookupCertificateForHandle *args;
222
221
 
223
 
  g_return_if_fail (callback != NULL);
224
 
 
225
222
  args = g_slice_new0 (AsyncLookupCertificateForHandle);
226
223
  args->handle = g_strdup (handle);
227
224
  args->interaction = interaction ? g_object_ref (interaction) : NULL;
228
225
 
229
 
  res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
230
 
                                   g_tls_database_real_lookup_certificate_for_handle_async);
231
 
  g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_for_handle_free);
232
 
  g_simple_async_result_run_in_thread (res, async_lookup_certificate_for_handle_thread,
233
 
                                       G_PRIORITY_DEFAULT, cancellable);
234
 
  g_object_unref (res);
 
226
  task = g_task_new (self, cancellable, callback, user_data);
 
227
  g_task_set_task_data (task, args, async_lookup_certificate_for_handle_free);
 
228
  g_task_run_in_thread (task, async_lookup_certificate_for_handle_thread);
 
229
  g_object_unref (task);
235
230
}
236
231
 
237
232
static GTlsCertificate*
239
234
                                                          GAsyncResult          *result,
240
235
                                                          GError               **error)
241
236
{
242
 
  AsyncLookupCertificateForHandle *args;
243
 
  GTlsCertificate *certificate;
244
 
 
245
 
  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
246
 
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
247
 
                        g_tls_database_real_lookup_certificate_for_handle_async), FALSE);
248
 
 
249
 
  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
250
 
    return NULL;
251
 
 
252
 
  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
253
 
  certificate = args->result;
254
 
  args->result = NULL;
255
 
  return certificate;
 
237
  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
 
238
 
 
239
  return g_task_propagate_pointer (G_TASK (result), error);
256
240
}
257
241
 
258
242
 
260
244
  GTlsCertificate *certificate;
261
245
  GTlsInteraction *interaction;
262
246
  GTlsDatabaseLookupFlags flags;
263
 
  GTlsCertificate *issuer;
264
247
} AsyncLookupCertificateIssuer;
265
248
 
266
249
static void
270
253
 
271
254
  g_clear_object (&args->certificate);
272
255
  g_clear_object (&args->interaction);
273
 
  g_clear_object (&args->issuer);
274
256
  g_slice_free (AsyncLookupCertificateIssuer, args);
275
257
}
276
258
 
277
259
static void
278
 
async_lookup_certificate_issuer_thread (GSimpleAsyncResult *res,
279
 
                            GObject            *object,
280
 
                            GCancellable       *cancellable)
 
260
async_lookup_certificate_issuer_thread (GTask         *task,
 
261
                                        gpointer       object,
 
262
                                        gpointer       task_data,
 
263
                                        GCancellable  *cancellable)
281
264
{
282
 
  AsyncLookupCertificateIssuer *args = g_simple_async_result_get_op_res_gpointer (res);
 
265
  AsyncLookupCertificateIssuer *args = task_data;
 
266
  GTlsCertificate *issuer;
283
267
  GError *error = NULL;
284
268
 
285
 
  args->issuer = g_tls_database_lookup_certificate_issuer (G_TLS_DATABASE (object),
286
 
                                                           args->certificate,
287
 
                                                           args->interaction,
288
 
                                                           args->flags,
289
 
                                                           cancellable,
290
 
                                                           &error);
291
 
 
292
 
  if (error)
293
 
      g_simple_async_result_take_error (res, error);
 
269
  issuer = g_tls_database_lookup_certificate_issuer (G_TLS_DATABASE (object),
 
270
                                                     args->certificate,
 
271
                                                     args->interaction,
 
272
                                                     args->flags,
 
273
                                                     cancellable,
 
274
                                                     &error);
 
275
  if (issuer)
 
276
    g_task_return_pointer (task, issuer, g_object_unref);
 
277
  else
 
278
    g_task_return_error (task, error);
294
279
}
295
280
 
296
281
static void
302
287
                                                     GAsyncReadyCallback     callback,
303
288
                                                     gpointer                user_data)
304
289
{
305
 
  GSimpleAsyncResult *res;
 
290
  GTask *task;
306
291
  AsyncLookupCertificateIssuer *args;
307
292
 
308
 
  g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
309
 
  g_return_if_fail (callback != NULL);
310
 
 
311
293
  args = g_slice_new0 (AsyncLookupCertificateIssuer);
312
294
  args->certificate = g_object_ref (certificate);
313
295
  args->flags = flags;
314
296
  args->interaction = interaction ? g_object_ref (interaction) : NULL;
315
297
 
316
 
  res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
317
 
                                   g_tls_database_real_lookup_certificate_issuer_async);
318
 
  g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_issuer_free);
319
 
  g_simple_async_result_run_in_thread (res, async_lookup_certificate_issuer_thread,
320
 
                                       G_PRIORITY_DEFAULT, cancellable);
321
 
  g_object_unref (res);
 
298
  task = g_task_new (self, cancellable, callback, user_data);
 
299
  g_task_set_task_data (task, args, async_lookup_certificate_issuer_free);
 
300
  g_task_run_in_thread (task, async_lookup_certificate_issuer_thread);
 
301
  g_object_unref (task);
322
302
}
323
303
 
324
 
static GTlsCertificate*
 
304
static GTlsCertificate *
325
305
g_tls_database_real_lookup_certificate_issuer_finish (GTlsDatabase          *self,
326
306
                                                      GAsyncResult          *result,
327
307
                                                      GError               **error)
328
308
{
329
 
  AsyncLookupCertificateIssuer *args;
330
 
  GTlsCertificate *issuer;
331
 
 
332
 
  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
333
 
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
334
 
                        g_tls_database_real_lookup_certificate_issuer_async), FALSE);
335
 
 
336
 
  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
337
 
    return NULL;
338
 
 
339
 
  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
340
 
  issuer = args->issuer;
341
 
  args->issuer = NULL;
342
 
  return issuer;
 
309
  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
 
310
 
 
311
  return g_task_propagate_pointer (G_TASK (result), error);
343
312
}
344
313
 
345
314
typedef struct {
346
315
  GByteArray *issuer;
347
316
  GTlsInteraction *interaction;
348
317
  GTlsDatabaseLookupFlags flags;
349
 
  GList *results;
350
318
} AsyncLookupCertificatesIssuedBy;
351
319
 
352
320
static void
353
321
async_lookup_certificates_issued_by_free (gpointer data)
354
322
{
355
323
  AsyncLookupCertificatesIssuedBy *args = data;
356
 
  GList *l;
357
324
 
358
325
  g_byte_array_unref (args->issuer);
359
326
  g_clear_object (&args->interaction);
360
 
  for (l = args->results; l; l = g_list_next (l))
361
 
    g_object_unref (l->data);
362
 
  g_list_free (args->results);
363
327
  g_slice_free (AsyncLookupCertificatesIssuedBy, args);
364
328
}
365
329
 
366
330
static void
367
 
async_lookup_certificates_issued_by_thread (GSimpleAsyncResult *res,
368
 
                                            GObject            *object,
369
 
                                            GCancellable       *cancellable)
370
 
{
371
 
  AsyncLookupCertificatesIssuedBy *args = g_simple_async_result_get_op_res_gpointer (res);
 
331
async_lookup_certificates_free_certificates (gpointer data)
 
332
{
 
333
  GList *list = data;
 
334
 
 
335
  g_list_free_full (list, g_object_unref);
 
336
}
 
337
 
 
338
static void
 
339
async_lookup_certificates_issued_by_thread (GTask         *task,
 
340
                                            gpointer       object,
 
341
                                            gpointer       task_data,
 
342
                                            GCancellable  *cancellable)
 
343
{
 
344
  AsyncLookupCertificatesIssuedBy *args = task_data;
 
345
  GList *results;
372
346
  GError *error = NULL;
373
347
 
374
 
  args->results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
375
 
                                                                args->issuer,
376
 
                                                                args->interaction,
377
 
                                                                args->flags,
378
 
                                                                cancellable,
379
 
                                                                &error);
380
 
 
381
 
  if (error)
382
 
      g_simple_async_result_take_error (res, error);
 
348
  results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
 
349
                                                          args->issuer,
 
350
                                                          args->interaction,
 
351
                                                          args->flags,
 
352
                                                          cancellable,
 
353
                                                          &error);
 
354
  if (results)
 
355
    g_task_return_pointer (task, results, async_lookup_certificates_free_certificates);
 
356
  else
 
357
    g_task_return_error (task, error);
383
358
}
384
359
 
385
360
static void
391
366
                                                         GAsyncReadyCallback     callback,
392
367
                                                         gpointer                user_data)
393
368
{
394
 
  GSimpleAsyncResult *res;
 
369
  GTask *task;
395
370
  AsyncLookupCertificatesIssuedBy *args;
396
371
 
397
 
  g_return_if_fail (callback);
398
 
 
399
372
  args = g_slice_new0 (AsyncLookupCertificatesIssuedBy);
400
373
  args->issuer = g_byte_array_ref (issuer);
401
374
  args->flags = flags;
402
375
  args->interaction = interaction ? g_object_ref (interaction) : NULL;
403
376
 
404
 
  res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
405
 
                                   g_tls_database_real_lookup_certificates_issued_by_async);
406
 
  g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificates_issued_by_free);
407
 
  g_simple_async_result_run_in_thread (res, async_lookup_certificates_issued_by_thread,
408
 
                                       G_PRIORITY_DEFAULT, cancellable);
409
 
  g_object_unref (res);
 
377
  task = g_task_new (self, cancellable, callback, user_data);
 
378
  g_task_set_task_data (task, args, async_lookup_certificates_issued_by_free);
 
379
  g_task_run_in_thread (task, async_lookup_certificates_issued_by_thread);
 
380
  g_object_unref (task);
410
381
}
411
382
 
412
 
static GList*
 
383
static GList *
413
384
g_tls_database_real_lookup_certificates_issued_by_finish (GTlsDatabase          *self,
414
385
                                                          GAsyncResult          *result,
415
386
                                                          GError               **error)
416
387
{
417
 
  AsyncLookupCertificatesIssuedBy *args;
418
 
  GList *results;
419
 
 
420
 
  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
421
 
  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
422
 
                        g_tls_database_real_lookup_certificates_issued_by_async), FALSE);
423
 
 
424
 
  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
425
 
    return NULL;
426
 
 
427
 
  args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
428
 
  results = args->results;
429
 
  args->results = NULL;
430
 
  return results;
 
388
  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
 
389
 
 
390
  return g_task_propagate_pointer (G_TASK (result), error);
431
391
}
432
392
 
433
393
static void
948
908
 * Finish an asynchronous lookup of certificates. See
949
909
 * g_tls_database_lookup_certificates_issued_by() for more information.
950
910
 *
951
 
 * Return value: (transfer full): a newly allocated list of #GTlsCertificate objects.
952
 
 * Use g_object_unref() on each certificate, and g_list_free() on the release the list.
 
911
 * Return value: (transfer full) (element-type GTlsCertificate): a newly allocated list of #GTlsCertificate
 
912
 * objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list.
953
913
 *
954
914
 * Since: 2.30
955
915
 */