comparison libpurple/certificate.c @ 18971:898e2bd70f23

- Add find, register, and unregister for CertificatePools
author William Ehlhardt <williamehlhardt@gmail.com>
date Thu, 28 Jun 2007 23:21:50 +0000
parents 7b03727b10b4
children 486563a6bb5c
comparison
equal deleted inserted replaced
18970:3d63bd78675d 18971:898e2bd70f23
36 36
37 /** List holding pointers to all registered certificate schemes */ 37 /** List holding pointers to all registered certificate schemes */
38 static GList *cert_schemes = NULL; 38 static GList *cert_schemes = NULL;
39 /** List of registered Verifiers */ 39 /** List of registered Verifiers */
40 static GList *cert_verifiers = NULL; 40 static GList *cert_verifiers = NULL;
41 /** List of registered Pools */
42 static GList *cert_pools = NULL;
41 43
42 void 44 void
43 purple_certificate_verify (PurpleCertificateVerifier *verifier, 45 purple_certificate_verify (PurpleCertificateVerifier *verifier,
44 const gchar *subject_name, GList *cert_chain, 46 const gchar *subject_name, GList *cert_chain,
45 PurpleCertificateVerifiedCallback cb, 47 PurpleCertificateVerifiedCallback cb,
391 393
392 cert_verifiers = g_list_remove(cert_verifiers, vr); 394 cert_verifiers = g_list_remove(cert_verifiers, vr);
393 395
394 return TRUE; 396 return TRUE;
395 } 397 }
398
399 PurpleCertificatePool *
400 purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name)
401 {
402 PurpleCertificatePool *pool = NULL;
403 GList *l;
404
405 g_return_val_if_fail(scheme_name, NULL);
406 g_return_val_if_fail(pool_name, NULL);
407
408 /* Traverse the list of registered pools and locate the
409 one whose name matches */
410 for(l = cert_pools; l; l = l->next) {
411 pool = (PurpleCertificatePool *)(l->data);
412
413 /* Scheme and name match? */
414 if(!g_ascii_strcasecmp(pool->scheme_name, scheme_name) &&
415 !g_ascii_strcasecmp(pool->name, pool_name))
416 return pool;
417 }
418
419 purple_debug_warning("certificate",
420 "CertificatePool %s, %s requested but not found.\n",
421 scheme_name, pool_name);
422
423 /* TODO: Signalling and such? */
424
425 return NULL;
426
427 }
428
429
430 gboolean
431 purple_certificate_register_pool(PurpleCertificatePool *pool)
432 {
433 gboolean success = FALSE;
434 g_return_val_if_fail(pool, FALSE);
435 g_return_val_if_fail(pool->scheme_name, FALSE);
436 g_return_val_if_fail(pool->name, FALSE);
437 g_return_val_if_fail(pool->fullname, FALSE);
438
439 /* Make sure no pools are registered under this name */
440 if (purple_certificate_find_pool(pool->scheme_name, pool->name)) {
441 return FALSE;
442 }
443
444 /* Initialize the pool if needed */
445 if (pool->init) {
446 success = pool->init(pool);
447 } else {
448 success = TRUE;
449 }
450
451 if (success) {
452 /* Register the Pool */
453 cert_pools = g_list_prepend(cert_pools, pool);
454
455 return TRUE;
456 } else {
457 return FALSE;
458 }
459
460 /* Control does not reach this point */
461 }
462
463 gboolean
464 purple_certificate_unregister_pool(PurpleCertificatePool *pool)
465 {
466 /* TODO: Better error checking? */
467 if (NULL == pool) {
468 purple_debug_warning("certificate",
469 "Attempting to unregister NULL pool\n");
470 return FALSE;
471 }
472
473 /* Check that the pool is registered */
474 if (!g_list_find(cert_pools, pool)) {
475 purple_debug_warning("certificate",
476 "Pool to unregister isn't registered!\n");
477
478 return FALSE;
479 }
480
481 /* Uninit the pool if needed */
482 if (pool->uninit) {
483 pool->uninit(pool);
484 }
485
486 cert_pools = g_list_remove(cert_pools, pool);
487
488 /* TODO: Signalling? */
489
490 return TRUE;
491 }