# HG changeset patch # User William Ehlhardt # Date 1182304075 0 # Node ID dc7e7b8bdc8c0a4d6faa0b44678c6c3a3c3159f3 # Parent a4336814bfd425af764c3f56f7064ce352ec6740 - Add chunks of the certificate scheme registration interface diff -r a4336814bfd4 -r dc7e7b8bdc8c libpurple/certificate.c --- a/libpurple/certificate.c Tue Jun 19 18:27:07 2007 +0000 +++ b/libpurple/certificate.c Wed Jun 20 01:47:55 2007 +0000 @@ -29,9 +29,51 @@ #include #include "certificate.h" +#include "debug.h" /** List holding pointers to all registered certificate schemes */ -GList *cert_schemes = NULL; +static GList *cert_schemes = NULL; + +PurpleCertificateScheme * +purple_certificate_find_scheme(const gchar *name) +{ + PurpleCertificateScheme *scheme = NULL; + GList *l; + + g_return_val_if_fail(name, NULL); + + /* Traverse the list of registered schemes and locate the + one whose name matches */ + for(l = cert_schemes; l; l = l->next) { + scheme = (PurpleCertificateScheme *)(l->data); + + /* Name matches? that's our man */ + if(!g_ascii_strcasecmp(scheme->name, name)) + return scheme; + } + purple_debug_warning("certificate", + "CertificateScheme %s requested but not found.\n", + name); + /* TODO: Signalling and such? */ + + return NULL; +} +gboolean +purple_certificate_register_scheme(PurpleCertificateScheme *scheme) +{ + g_return_val_if_fail(scheme != NULL, FALSE); + + /* Make sure no scheme is registered with the same name */ + if (purple_certificate_find_scheme(scheme->name) != NULL) { + return FALSE; + } + + /* Okay, we're golden. Register it. */ + cert_schemes = g_list_append(cert_schemes, scheme); + + /* TODO: Signalling and such? */ + return TRUE; +} diff -r a4336814bfd4 -r dc7e7b8bdc8c libpurple/certificate.h --- a/libpurple/certificate.h Tue Jun 19 18:27:07 2007 +0000 +++ b/libpurple/certificate.h Wed Jun 20 01:47:55 2007 +0000 @@ -101,6 +101,24 @@ /*****************************************************************************/ /*@{*/ +/** Look up a registered CertificateScheme by name + * @param name The scheme name. Case insensitive. + * @return Pointer to the located Scheme, or NULL if it isn't found. + */ +PurpleCertificateScheme * +purple_certificate_find_scheme(const gchar *name); + +/** Register a CertificateScheme with libpurple + * + * No two schemes can be registered with the same name; this function enforces + * that. + * + * @param scheme Pointer to the scheme to register. + * @return TRUE if the scheme was successfully added, otherwise FALSE + */ +gboolean +purple_certificate_register_scheme(PurpleCertificateScheme *scheme); + /* TODO: ADD STUFF HERE */ /*@}*/