# HG changeset patch # User William Ehlhardt # Date 1183072910 0 # Node ID 898e2bd70f236e3c54bac16dc9f412b4e353a6f4 # Parent 3d63bd78675d44542c748206224a74ca213b6c06 - Add find, register, and unregister for CertificatePools diff -r 3d63bd78675d -r 898e2bd70f23 libpurple/certificate.c --- a/libpurple/certificate.c Thu Jun 28 21:29:54 2007 +0000 +++ b/libpurple/certificate.c Thu Jun 28 23:21:50 2007 +0000 @@ -38,6 +38,8 @@ static GList *cert_schemes = NULL; /** List of registered Verifiers */ static GList *cert_verifiers = NULL; +/** List of registered Pools */ +static GList *cert_pools = NULL; void purple_certificate_verify (PurpleCertificateVerifier *verifier, @@ -393,3 +395,97 @@ return TRUE; } + +PurpleCertificatePool * +purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name) +{ + PurpleCertificatePool *pool = NULL; + GList *l; + + g_return_val_if_fail(scheme_name, NULL); + g_return_val_if_fail(pool_name, NULL); + + /* Traverse the list of registered pools and locate the + one whose name matches */ + for(l = cert_pools; l; l = l->next) { + pool = (PurpleCertificatePool *)(l->data); + + /* Scheme and name match? */ + if(!g_ascii_strcasecmp(pool->scheme_name, scheme_name) && + !g_ascii_strcasecmp(pool->name, pool_name)) + return pool; + } + + purple_debug_warning("certificate", + "CertificatePool %s, %s requested but not found.\n", + scheme_name, pool_name); + + /* TODO: Signalling and such? */ + + return NULL; + +} + + +gboolean +purple_certificate_register_pool(PurpleCertificatePool *pool) +{ + gboolean success = FALSE; + g_return_val_if_fail(pool, FALSE); + g_return_val_if_fail(pool->scheme_name, FALSE); + g_return_val_if_fail(pool->name, FALSE); + g_return_val_if_fail(pool->fullname, FALSE); + + /* Make sure no pools are registered under this name */ + if (purple_certificate_find_pool(pool->scheme_name, pool->name)) { + return FALSE; + } + + /* Initialize the pool if needed */ + if (pool->init) { + success = pool->init(pool); + } else { + success = TRUE; + } + + if (success) { + /* Register the Pool */ + cert_pools = g_list_prepend(cert_pools, pool); + + return TRUE; + } else { + return FALSE; + } + + /* Control does not reach this point */ +} + +gboolean +purple_certificate_unregister_pool(PurpleCertificatePool *pool) +{ + /* TODO: Better error checking? */ + if (NULL == pool) { + purple_debug_warning("certificate", + "Attempting to unregister NULL pool\n"); + return FALSE; + } + + /* Check that the pool is registered */ + if (!g_list_find(cert_pools, pool)) { + purple_debug_warning("certificate", + "Pool to unregister isn't registered!\n"); + + return FALSE; + } + + /* Uninit the pool if needed */ + if (pool->uninit) { + pool->uninit(pool); + } + + cert_pools = g_list_remove(cert_pools, pool); + + /* TODO: Signalling? */ + + return TRUE; +} diff -r 3d63bd78675d -r 898e2bd70f23 libpurple/certificate.h --- a/libpurple/certificate.h Thu Jun 28 21:29:54 2007 +0000 +++ b/libpurple/certificate.h Thu Jun 28 23:21:50 2007 +0000 @@ -452,12 +452,36 @@ * Unregister a CertificateVerifier with libpurple * * @param vr Verifier to unregister. - * @return TRUE if register succeeded, otherwise FALSE + * @return TRUE if unregister succeeded, otherwise FALSE */ gboolean purple_certificate_unregister_verifier(PurpleCertificateVerifier *vr); -/* TODO: ADD STUFF HERE */ +/** Look up a registered PurpleCertificatePool by scheme and name + * @param scheme_name Scheme name. Case insensitive. + * @param pool_name Pool name. Case insensitive. + * @return Pointer to the located Pool, or NULL if it isn't found. + */ +PurpleCertificatePool * +purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name); + +/** + * Register a CertificatePool with libpurple and call its init function + * + * @param pool Pool to register. + * @return TRUE if the register succeeded, otherwise FALSE + */ +gboolean +purple_certificate_register_pool(PurpleCertificatePool *pool); + +/** + * Unregister a CertificatePool with libpurple and call its uninit function + * + * @param pool Pool to unregister. + * @return TRUE if the unregister succeeded, otherwise FALSE + */ +gboolean +purple_certificate_unregister_pool(PurpleCertificatePool *pool); /*@}*/