Annotation of embedaddon/strongswan/src/libimcv/swima/swima_record.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2017 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 "swima_record.h"
        !            17: #include "swima_data_model.h"
        !            18: 
        !            19: typedef struct private_swima_record_t private_swima_record_t;
        !            20: 
        !            21: /**
        !            22:  * Private data of a swima_record_t object.
        !            23:  *
        !            24:  */
        !            25: struct private_swima_record_t {
        !            26: 
        !            27:        /**
        !            28:         * Public swima_record_t interface.
        !            29:         */
        !            30:        swima_record_t public;
        !            31: 
        !            32:        /**
        !            33:         * Record ID
        !            34:         */
        !            35:        uint32_t record_id;
        !            36: 
        !            37:        /**
        !            38:         * Software Identity
        !            39:         */
        !            40:        chunk_t sw_id;
        !            41: 
        !            42:        /**
        !            43:         * Optional Software Locator
        !            44:         */
        !            45:        chunk_t sw_locator;
        !            46: 
        !            47:        /**
        !            48:         * Data Model
        !            49:         */
        !            50:        pen_type_t data_model;
        !            51: 
        !            52:        /**
        !            53:         * Source ID
        !            54:         */
        !            55:        uint8_t source_id;
        !            56: 
        !            57:        /**g
        !            58:         * Optional Software Inventory Evidence Record
        !            59:         */
        !            60:        chunk_t record;
        !            61: 
        !            62:        /**
        !            63:         * Reference count
        !            64:         */
        !            65:        refcount_t ref;
        !            66: };
        !            67: 
        !            68: METHOD(swima_record_t, get_record_id, uint32_t,
        !            69:        private_swima_record_t *this)
        !            70: {
        !            71:        return this->record_id;
        !            72: }
        !            73: 
        !            74: METHOD(swima_record_t, get_sw_id, chunk_t,
        !            75:        private_swima_record_t *this, chunk_t *sw_locator)
        !            76: {
        !            77:        if (sw_locator)
        !            78:        {
        !            79:                *sw_locator = this->sw_locator;
        !            80:        }
        !            81:        return this->sw_id;
        !            82: }
        !            83: 
        !            84: METHOD(swima_record_t, set_data_model, void,
        !            85:        private_swima_record_t *this, pen_type_t data_model)
        !            86: {
        !            87:        this->data_model = data_model;
        !            88: }
        !            89: 
        !            90: METHOD(swima_record_t, get_data_model, pen_type_t,
        !            91:        private_swima_record_t *this)
        !            92: {
        !            93:        return this->data_model;
        !            94: }
        !            95: 
        !            96: METHOD(swima_record_t, set_source_id, void,
        !            97:        private_swima_record_t *this, uint8_t source_id)
        !            98: {
        !            99:        this->source_id = source_id;
        !           100: }
        !           101: 
        !           102: METHOD(swima_record_t, get_source_id, uint8_t,
        !           103:        private_swima_record_t *this)
        !           104: {
        !           105:        return this->source_id;
        !           106: }
        !           107: 
        !           108: METHOD(swima_record_t, set_record, void,
        !           109:        private_swima_record_t *this, chunk_t record)
        !           110: {
        !           111:        chunk_free(&this->record);
        !           112:        this->record = chunk_clone(record);
        !           113: }
        !           114: 
        !           115: METHOD(swima_record_t, get_record, chunk_t,
        !           116:        private_swima_record_t *this)
        !           117: {
        !           118:        return this->record;
        !           119: }
        !           120: 
        !           121: METHOD(swima_record_t, get_ref, swima_record_t*,
        !           122:        private_swima_record_t *this)
        !           123: {
        !           124:        ref_get(&this->ref);
        !           125:        return &this->public;
        !           126: }
        !           127: 
        !           128: METHOD(swima_record_t, destroy, void,
        !           129:        private_swima_record_t *this)
        !           130: {
        !           131:        if (ref_put(&this->ref))
        !           132:        {
        !           133:                free(this->sw_id.ptr);
        !           134:                free(this->sw_locator.ptr);
        !           135:                free(this->record.ptr);
        !           136:                free(this);
        !           137:        }
        !           138: }
        !           139: 
        !           140: /**
        !           141:  * See header
        !           142:  */
        !           143: swima_record_t *swima_record_create(uint32_t record_id, chunk_t sw_id,
        !           144:                                                                        chunk_t sw_locator)
        !           145: {
        !           146:        private_swima_record_t *this;
        !           147: 
        !           148:        INIT(this,
        !           149:                .public = {
        !           150:                        .get_record_id = _get_record_id,
        !           151:                        .get_sw_id = _get_sw_id,
        !           152:                        .set_data_model = _set_data_model,
        !           153:                        .get_data_model = _get_data_model,
        !           154:                        .set_source_id = _set_source_id,
        !           155:                        .get_source_id = _get_source_id,
        !           156:                        .set_record = _set_record,
        !           157:                        .get_record = _get_record,
        !           158:                        .get_ref = _get_ref,
        !           159:                        .destroy = _destroy,
        !           160:                },
        !           161:                .record_id = record_id,
        !           162:                .data_model = swima_data_model_iso_2015_swid_xml,
        !           163:                .sw_id = chunk_clone(sw_id),
        !           164:                .ref = 1,
        !           165:        );
        !           166: 
        !           167:        if (sw_locator.len > 0)
        !           168:        {
        !           169:                this->sw_locator = chunk_clone(sw_locator);
        !           170:        }
        !           171: 
        !           172:        return &this->public;
        !           173: }
        !           174: 

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