diff options
author | Martin Willi <martin@revosec.ch> | 2013-02-26 14:54:36 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2013-02-28 16:46:07 +0100 |
commit | 4a801beb3e94a0ae19634b66fe58c867c71a9b75 (patch) | |
tree | 558930d3a2d87fb469d1b42a5f8698ab1ef9ec3c /src/libpttls/sasl/sasl_mechanism.c | |
parent | 806126eab2b0a0b0170a6eef70a30856f4fc947f (diff) | |
download | strongswan-4a801beb3e94a0ae19634b66fe58c867c71a9b75.tar.bz2 strongswan-4a801beb3e94a0ae19634b66fe58c867c71a9b75.tar.xz |
Define an interface for SASL mechanisms and provide a static factory
Diffstat (limited to 'src/libpttls/sasl/sasl_mechanism.c')
-rw-r--r-- | src/libpttls/sasl/sasl_mechanism.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/libpttls/sasl/sasl_mechanism.c b/src/libpttls/sasl/sasl_mechanism.c new file mode 100644 index 000000000..4e0f876be --- /dev/null +++ b/src/libpttls/sasl/sasl_mechanism.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2013 Martin Willi + * Copyright (C) 2013 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program 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 General Public License + * for more details. + */ + +#include "sasl_mechanism.h" + +/** + * Available SASL mechanisms. + */ +static struct { + char *name; + bool server; + sasl_mechanism_constructor_t create; +} mechs[] = { +}; + +/** + * See header. + */ +sasl_mechanism_t *sasl_mechanism_create(char *name, identification_t *client) +{ + int i; + + for (i = 0; i < countof(mechs); i++) + { + if (streq(mechs[i].name, name) && mechs[i].server == (client == NULL)) + { + return mechs[i].create(name, client); + } + } + return NULL; +} + +/** + * SASL mechanism enumerator + */ +typedef struct { + /** implements enumerator_t */ + enumerator_t public; + /** looking for client or server? */ + bool server; + /** position in mechs[] */ + int i; +} mech_enumerator_t; + +METHOD(enumerator_t, mech_enumerate, bool, + mech_enumerator_t *this, char **name) +{ + while (this->i < countof(mechs)) + { + if (mechs[this->i].server == this->server) + { + *name = mechs[this->i].name; + this->i++; + return TRUE; + } + this->i++; + } + return FALSE; +} + +/** + * See header. + */ +enumerator_t* sasl_mechanism_create_enumerator(bool server) +{ + mech_enumerator_t *enumerator; + + INIT(enumerator, + .public = { + .enumerate = (void*)_mech_enumerate, + .destroy = (void*)free, + }, + .server = server, + ); + return &enumerator->public; +} |