Annotation of embedaddon/strongswan/src/libimcv/seg/seg_contract_manager.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2014 Andreas Steffen
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             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 "seg_contract_manager.h"
        !            17: 
        !            18: typedef struct private_seg_contract_manager_t private_seg_contract_manager_t;
        !            19: 
        !            20: /**
        !            21:  * Private data of a seg_contract_manager_t object.
        !            22:  *
        !            23:  */
        !            24: struct private_seg_contract_manager_t {
        !            25: 
        !            26:        /**
        !            27:         * Public seg_contract_manager_t interface.
        !            28:         */
        !            29:        seg_contract_manager_t public;
        !            30: 
        !            31:        /**
        !            32:         * List of PA-TNC segmentation contracts
        !            33:         */
        !            34:        linked_list_t *contracts;
        !            35: 
        !            36: };
        !            37: 
        !            38: METHOD(seg_contract_manager_t, add_contract, void,
        !            39:        private_seg_contract_manager_t *this, seg_contract_t *contract)
        !            40: {
        !            41:        this->contracts->insert_last(this->contracts, contract);
        !            42: }
        !            43: 
        !            44: METHOD(seg_contract_manager_t, get_contract, seg_contract_t*,
        !            45:        private_seg_contract_manager_t *this, pen_type_t msg_type, bool is_issuer,
        !            46:        TNC_UInt32 id)
        !            47: {
        !            48:        enumerator_t *enumerator;
        !            49:        seg_contract_t *contract, *found = NULL;
        !            50: 
        !            51:        enumerator = this->contracts->create_enumerator(this->contracts);
        !            52:        while (enumerator->enumerate(enumerator, &contract))
        !            53:        {
        !            54:                if (contract->is_issuer(contract) == is_issuer &&
        !            55:                        pen_type_equals(contract->get_msg_type(contract), msg_type) &&
        !            56:                        id == (is_issuer ? contract->get_responder(contract) :
        !            57:                                                           contract->get_issuer(contract)))
        !            58:                {
        !            59:                        found = contract;
        !            60:                        break;
        !            61:                }
        !            62:        }
        !            63:        enumerator->destroy(enumerator);
        !            64: 
        !            65:        return found;
        !            66: }
        !            67: 
        !            68: METHOD(seg_contract_manager_t, destroy, void,
        !            69:        private_seg_contract_manager_t *this)
        !            70: {
        !            71:        this->contracts->destroy_offset(this->contracts,
        !            72:                                                                        offsetof(seg_contract_t, destroy));
        !            73:        free(this);
        !            74: }
        !            75: 
        !            76: /**
        !            77:  * See header
        !            78:  */
        !            79: seg_contract_manager_t *seg_contract_manager_create(void)
        !            80: {
        !            81:        private_seg_contract_manager_t *this;
        !            82: 
        !            83:        INIT(this,
        !            84:                .public = {
        !            85:                        .add_contract = _add_contract,
        !            86:                        .get_contract = _get_contract,
        !            87:                        .destroy = _destroy,
        !            88:                },
        !            89:                .contracts = linked_list_create(),
        !            90:        );
        !            91: 
        !            92:        return &this->public;
        !            93: }
        !            94: 

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