Annotation of embedaddon/strongswan/src/libstrongswan/credentials/sets/callback_cred.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2010 Martin Willi
                      3:  * Copyright (C) 2010 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 "callback_cred.h"
                     17: 
                     18: typedef struct private_callback_cred_t private_callback_cred_t;
                     19: 
                     20: /**
                     21:  * Private data of an callback_cred_t object.
                     22:  */
                     23: struct private_callback_cred_t {
                     24: 
                     25:        /**
                     26:         * Public callback_cred_t interface.
                     27:         */
                     28:        callback_cred_t public;
                     29: 
                     30:        /**
                     31:         * Callback of this set, for all types, and generic
                     32:         */
                     33:        union {
                     34:                void *generic;
                     35:                callback_cred_shared_cb_t shared;
                     36:        } cb;
                     37: 
                     38:        /**
                     39:         * Data to pass to callback
                     40:         */
                     41:        void *data;
                     42: };
                     43: 
                     44: /**
                     45:  * Shared key enumerator on callbacks
                     46:  */
                     47: typedef struct {
                     48:        /* implements enumerator_t */
                     49:        enumerator_t public;
                     50:        /* backref to this */
                     51:        private_callback_cred_t *this;
                     52:        /* type if requested key */
                     53:        shared_key_type_t type;
                     54:        /* own identity to match */
                     55:        identification_t *me;
                     56:        /* other identity to match */
                     57:        identification_t *other;
                     58:        /* current shared key */
                     59:        shared_key_t *current;
                     60: } shared_enumerator_t;
                     61: 
                     62: METHOD(enumerator_t, shared_enumerate, bool,
                     63:        shared_enumerator_t *this, va_list args)
                     64: {
                     65:        shared_key_t **out;
                     66:        id_match_t *match_me, *match_other;
                     67: 
                     68:        VA_ARGS_VGET(args, out, match_me, match_other);
                     69:        DESTROY_IF(this->current);
                     70:        this->current = this->this->cb.shared(this->this->data, this->type,
                     71:                                                                this->me, this->other, match_me, match_other);
                     72:        if (this->current)
                     73:        {
                     74:                *out = this->current;
                     75:                return TRUE;
                     76:        }
                     77:        return FALSE;
                     78: }
                     79: 
                     80: METHOD(enumerator_t, shared_destroy, void,
                     81:        shared_enumerator_t *this)
                     82: {
                     83:        DESTROY_IF(this->current);
                     84:        free(this);
                     85: }
                     86: 
                     87: METHOD(credential_set_t, create_shared_enumerator, enumerator_t*,
                     88:        private_callback_cred_t *this, shared_key_type_t type,
                     89:        identification_t *me, identification_t *other)
                     90: {
                     91:        shared_enumerator_t *enumerator;
                     92: 
                     93:        INIT(enumerator,
                     94:                .public = {
                     95:                        .enumerate = enumerator_enumerate_default,
                     96:                        .venumerate = _shared_enumerate,
                     97:                        .destroy = _shared_destroy,
                     98:                },
                     99:                .this = this,
                    100:                .type = type,
                    101:                .me = me,
                    102:                .other = other,
                    103:        );
                    104:        return &enumerator->public;
                    105: }
                    106: 
                    107: METHOD(callback_cred_t, destroy, void,
                    108:        private_callback_cred_t *this)
                    109: {
                    110:        free(this);
                    111: }
                    112: 
                    113: /**
                    114:  * Create a generic callback credential set
                    115:  */
                    116: static private_callback_cred_t* create_generic(void *cb, void *data)
                    117: {
                    118:        private_callback_cred_t *this;
                    119: 
                    120:        INIT(this,
                    121:                .public = {
                    122:                        .set = {
                    123:                                .create_shared_enumerator = (void*)return_null,
                    124:                                .create_private_enumerator = (void*)return_null,
                    125:                                .create_cert_enumerator = (void*)return_null,
                    126:                                .create_cdp_enumerator  = (void*)return_null,
                    127:                                .cache_cert = (void*)nop,
                    128:                        },
                    129:                        .destroy = _destroy,
                    130:                },
                    131:                .cb.generic = cb,
                    132:                .data = data,
                    133:        );
                    134:        return this;
                    135: }
                    136: 
                    137: /**
                    138:  * See header
                    139:  */
                    140: callback_cred_t *callback_cred_create_shared(callback_cred_shared_cb_t cb,
                    141:                                                                                         void *data)
                    142: {
                    143:        private_callback_cred_t *this = create_generic(cb, data);
                    144: 
                    145:        this->public.set.create_shared_enumerator = _create_shared_enumerator;
                    146: 
                    147:        return &this->public;
                    148: }

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