Annotation of embedaddon/strongswan/src/libimcv/pts/components/pts_comp_func_name.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2011-2014 Andreas Steffen
                      3:  *
                      4:  * HSR Hochschule fuer Technik Rapperswil
                      5:  *
                      6:  * This program is free software; you can redistribute it and/or modify it
                      7:  * under the terms of the GNU General Public License as published by the
                      8:  * Free Software Foundation; either version 2 of the License, or (at your
                      9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     10:  *
                     11:  * This program is distributed in the hope that it will be useful, but
                     12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     14:  * for more details.
                     15:  */
                     16: 
                     17: #include "imcv.h"
                     18: #include "pts/components/pts_comp_func_name.h"
                     19: 
                     20: #include <utils/debug.h>
                     21: 
                     22: typedef struct private_pts_comp_func_name_t private_pts_comp_func_name_t;
                     23: 
                     24: /**
                     25:  * Private data of a pts_comp_func_name_t object.
                     26:  *
                     27:  */
                     28: struct private_pts_comp_func_name_t {
                     29: 
                     30:        /**
                     31:         * Public pts_comp_func_name_t interface.
                     32:         */
                     33:        pts_comp_func_name_t public;
                     34: 
                     35:        /**
                     36:         * PTS Component Functional Name Vendor ID
                     37:         */
                     38:        uint32_t vid;
                     39: 
                     40:        /**
                     41:         * PTS Component Functional Name
                     42:         */
                     43:        uint32_t name;
                     44: 
                     45:        /**
                     46:         * PTS Component Functional Name Qualifier
                     47:         */
                     48:        uint8_t qualifier;
                     49: 
                     50: };
                     51: 
                     52: METHOD(pts_comp_func_name_t, get_vendor_id, uint32_t,
                     53:        private_pts_comp_func_name_t *this)
                     54: {
                     55:        return this->vid;
                     56: }
                     57: 
                     58: METHOD(pts_comp_func_name_t, get_name, uint32_t,
                     59:        private_pts_comp_func_name_t *this)
                     60: {
                     61:        return this->name;
                     62: }
                     63: 
                     64: METHOD(pts_comp_func_name_t, get_qualifier, uint8_t,
                     65:        private_pts_comp_func_name_t *this)
                     66: {
                     67:        return this->qualifier;
                     68: }
                     69: 
                     70: METHOD(pts_comp_func_name_t, set_qualifier, void,
                     71:        private_pts_comp_func_name_t *this, uint8_t qualifier)
                     72: {
                     73:        this->qualifier = qualifier;
                     74: }
                     75: 
                     76: static bool equals(private_pts_comp_func_name_t *this,
                     77:                                   private_pts_comp_func_name_t *other)
                     78: {
                     79:        if (this->vid != other->vid || this->name != other->name)
                     80:        {
                     81:                return FALSE;
                     82:        }
                     83:        if (this->qualifier == PTS_QUALIFIER_UNKNOWN ||
                     84:                other->qualifier == PTS_QUALIFIER_UNKNOWN)
                     85:        {
                     86:                return TRUE;
                     87:        }
                     88:        /* TODO handle qualifier wildcards */
                     89: 
                     90:        return this->qualifier == other->qualifier;
                     91: }
                     92: 
                     93: METHOD(pts_comp_func_name_t, clone_, pts_comp_func_name_t*,
                     94:        private_pts_comp_func_name_t *this)
                     95: {
                     96:        private_pts_comp_func_name_t *clone;
                     97: 
                     98:        clone = malloc_thing(private_pts_comp_func_name_t);
                     99:        memcpy(clone, this, sizeof(private_pts_comp_func_name_t));
                    100: 
                    101:        return &clone->public;
                    102: }
                    103: 
                    104: METHOD(pts_comp_func_name_t, log_, void,
                    105:        private_pts_comp_func_name_t *this, char *label)
                    106: {
                    107:        enum_name_t *names, *types;
                    108:        char flags[8];
                    109:        int type;
                    110: 
                    111:        names = imcv_pts_components->get_comp_func_names(imcv_pts_components,
                    112:                                                                                        this->vid);
                    113:        types = imcv_pts_components->get_qualifier_type_names(imcv_pts_components,
                    114:                                                                                        this->vid);
                    115:        type =  imcv_pts_components->get_qualifier(imcv_pts_components,
                    116:                                                                                        &this->public, flags);
                    117: 
                    118:        if (names && types)
                    119:        {
                    120:                DBG3(DBG_PTS, "%s%N functional component '%N' [%s] '%N'",
                    121:                         label, pen_names, this->vid, names, this->name, flags, types, type);
                    122:        }
                    123:        else
                    124:        {
                    125:                DBG3(DBG_PTS, "%s0x%06x functional component 0x%08x 0x%02x",
                    126:                         label, this->vid, this->name, this->qualifier);
                    127:        }
                    128: }
                    129: 
                    130: METHOD(pts_comp_func_name_t, destroy, void,
                    131:        private_pts_comp_func_name_t *this)
                    132: {
                    133:        free(this);
                    134: }
                    135: 
                    136: /**
                    137:  * See header
                    138:  */
                    139: pts_comp_func_name_t* pts_comp_func_name_create(uint32_t vid, uint32_t name,
                    140:                                                                                                uint8_t qualifier)
                    141: {
                    142:        private_pts_comp_func_name_t *this;
                    143: 
                    144:        INIT(this,
                    145:                .public = {
                    146:                        .get_vendor_id = _get_vendor_id,
                    147:                        .get_name = _get_name,
                    148:                        .get_qualifier = _get_qualifier,
                    149:                        .set_qualifier = _set_qualifier,
                    150:                        .equals = (bool(*)(pts_comp_func_name_t*,pts_comp_func_name_t*))equals,
                    151:                        .clone = _clone_,
                    152:                        .log = _log_,
                    153:                        .destroy = _destroy,
                    154:                },
                    155:                .vid = vid,
                    156:                .name = name,
                    157:                .qualifier = qualifier,
                    158:        );
                    159: 
                    160:        return &this->public;
                    161: }
                    162: 

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