Annotation of embedaddon/strongswan/src/libpttls/sasl/sasl_mechanism.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2013 Martin Willi
        !             3:  * Copyright (C) 2013 revosec AG
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "sasl_mechanism.h"
        !            17: 
        !            18: #include "sasl_plain/sasl_plain.h"
        !            19: 
        !            20: /**
        !            21:  * Available SASL mechanisms.
        !            22:  */
        !            23: static struct {
        !            24:        char *name;
        !            25:        bool server;
        !            26:        sasl_mechanism_constructor_t create;
        !            27: } mechs[] = {
        !            28:        { "PLAIN",              TRUE,   (sasl_mechanism_constructor_t)sasl_plain_create },
        !            29:        { "PLAIN",              FALSE,  (sasl_mechanism_constructor_t)sasl_plain_create },
        !            30: };
        !            31: 
        !            32: /**
        !            33:  * See header.
        !            34:  */
        !            35: sasl_mechanism_t *sasl_mechanism_create(char *name, identification_t *client)
        !            36: {
        !            37:        int i;
        !            38: 
        !            39:        for (i = 0; i < countof(mechs); i++)
        !            40:        {
        !            41:                if (streq(mechs[i].name, name) && mechs[i].server == (client == NULL))
        !            42:                {
        !            43:                        return mechs[i].create(name, client);
        !            44:                }
        !            45:        }
        !            46:        return NULL;
        !            47: }
        !            48: 
        !            49: /**
        !            50:  * SASL mechanism enumerator
        !            51:  */
        !            52: typedef struct {
        !            53:        /** implements enumerator_t */
        !            54:        enumerator_t public;
        !            55:        /** looking for client or server? */
        !            56:        bool server;
        !            57:        /** position in mechs[] */
        !            58:        int i;
        !            59: } mech_enumerator_t;
        !            60: 
        !            61: METHOD(enumerator_t, mech_enumerate, bool,
        !            62:        mech_enumerator_t *this, va_list args)
        !            63: {
        !            64:        char **name;
        !            65: 
        !            66:        VA_ARGS_VGET(args, name);
        !            67:        while (this->i < countof(mechs))
        !            68:        {
        !            69:                if (mechs[this->i].server == this->server)
        !            70:                {
        !            71:                        *name = mechs[this->i].name;
        !            72:                        this->i++;
        !            73:                        return TRUE;
        !            74:                }
        !            75:                this->i++;
        !            76:        }
        !            77:        return FALSE;
        !            78: }
        !            79: 
        !            80: /**
        !            81:  * See header.
        !            82:  */
        !            83: enumerator_t* sasl_mechanism_create_enumerator(bool server)
        !            84: {
        !            85:        mech_enumerator_t *enumerator;
        !            86: 
        !            87:        INIT(enumerator,
        !            88:                .public = {
        !            89:                        .enumerate = enumerator_enumerate_default,
        !            90:                        .venumerate = _mech_enumerate,
        !            91:                        .destroy = (void*)free,
        !            92:                },
        !            93:                .server = server,
        !            94:        );
        !            95:        return &enumerator->public;
        !            96: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>