Annotation of embedaddon/strongswan/src/libimcv/imv/imv_workitem.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2013 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 "imv_workitem.h"
                     17: 
                     18: #include <utils/debug.h>
                     19: #include <tncif_names.h>
                     20: 
                     21: typedef struct private_imv_workitem_t private_imv_workitem_t;
                     22: 
                     23: ENUM(imv_workitem_type_names, IMV_WORKITEM_PACKAGES, IMV_WORKITEM_TPM_ATTEST,
                     24:        "PCKGS",
                     25:        "UNSRC",
                     26:        "FWDEN",
                     27:        "PWDEN",
                     28:        "FREFM",
                     29:        "FMEAS",
                     30:        "FMETA",
                     31:        "DREFM",
                     32:        "DMEAS",
                     33:        "DMETA",
                     34:        "TCPOP",
                     35:        "TCPBL",
                     36:        "UDPOP",
                     37:        "UDPBL",
                     38:        "SWIDT",
                     39:        "TPMRA"
                     40: );
                     41: 
                     42: /**
                     43:  * Private data of a imv_workitem_t object.
                     44:  *
                     45:  */
                     46: struct private_imv_workitem_t {
                     47: 
                     48:        /**
                     49:         * Public imv_workitem_t interface.
                     50:         */
                     51:        imv_workitem_t public;
                     52: 
                     53:        /**
                     54:         * Primary workitem key
                     55:         */
                     56:        int id;
                     57: 
                     58:        /**
                     59:         * IMV ID
                     60:         */
                     61:        TNC_IMVID imv_id;
                     62: 
                     63:        /**
                     64:         * Workitem type
                     65:         */
                     66:        imv_workitem_type_t type;
                     67: 
                     68:        /**
                     69:         * Argument string
                     70:         */
                     71:        char *arg_str;
                     72: 
                     73:        /**
                     74:         * Argument integer
                     75:         */
                     76:        int arg_int;
                     77: 
                     78:        /**
                     79:         * Result string
                     80:         */
                     81:        char *result;
                     82: 
                     83:        /**
                     84:         * IMV action recommendation
                     85:         */
                     86:        TNC_IMV_Action_Recommendation rec_fail;
                     87: 
                     88:        /**
                     89:         * IMV action recommendation
                     90:         */
                     91:        TNC_IMV_Action_Recommendation rec_noresult;
                     92: 
                     93:        /**
                     94:         * IMV action recommendation
                     95:         */
                     96:        TNC_IMV_Action_Recommendation rec_final;
                     97: 
                     98: };
                     99: 
                    100: METHOD(imv_workitem_t, get_id, int,
                    101:        private_imv_workitem_t *this)
                    102: {
                    103:        return this->id;
                    104: }
                    105: 
                    106: METHOD(imv_workitem_t, set_imv_id, void,
                    107:        private_imv_workitem_t *this, TNC_IMVID imv_id)
                    108: {
                    109:        this->imv_id = imv_id;
                    110: 
                    111:        DBG2(DBG_IMV, "IMV %d handles %N workitem %d", imv_id,
                    112:                 imv_workitem_type_names, this->type, this->id);
                    113: }
                    114: 
                    115: METHOD(imv_workitem_t, get_imv_id, TNC_IMVID,
                    116:        private_imv_workitem_t *this)
                    117: {
                    118:        return this->imv_id;
                    119: }
                    120: 
                    121: METHOD(imv_workitem_t, get_type, imv_workitem_type_t,
                    122:        private_imv_workitem_t *this)
                    123: {
                    124:        return this->type;
                    125: }
                    126: 
                    127: METHOD(imv_workitem_t, get_arg_str, char*,
                    128:        private_imv_workitem_t *this)
                    129: {
                    130:        return this->arg_str;
                    131: }
                    132: 
                    133: METHOD(imv_workitem_t, get_arg_int, int,
                    134:        private_imv_workitem_t *this)
                    135: {
                    136:        return this->arg_int;
                    137: }
                    138: 
                    139: METHOD(imv_workitem_t, set_result, TNC_IMV_Action_Recommendation,
                    140:        private_imv_workitem_t *this, char *result, TNC_IMV_Evaluation_Result eval)
                    141: {
                    142:        this->result = strdup(result);
                    143:        switch (eval)
                    144:        {
                    145:                case TNC_IMV_EVALUATION_RESULT_COMPLIANT:
                    146:                        this->rec_final = TNC_IMV_ACTION_RECOMMENDATION_ALLOW;
                    147:                        break;
                    148:                case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR:
                    149:                case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR:
                    150:                        this->rec_final = this->rec_fail;
                    151:                        break;
                    152:                case TNC_IMV_EVALUATION_RESULT_ERROR:
                    153:                case TNC_IMV_EVALUATION_RESULT_DONT_KNOW:
                    154:                default:
                    155:                        this->rec_final = this->rec_noresult;
                    156:                        break;
                    157:        }
                    158:        DBG2(DBG_IMV, "IMV %d handled %N workitem %d: %N%s%s", this->imv_id,
                    159:                 imv_workitem_type_names, this->type, this->id,
                    160:                 TNC_IMV_Action_Recommendation_names, this->rec_final,
                    161:                 strlen(result) ? " - " : "", result);
                    162: 
                    163:        return this->rec_final;
                    164: }
                    165: 
                    166: METHOD(imv_workitem_t, get_result, TNC_IMV_Action_Recommendation,
                    167:        private_imv_workitem_t *this, char **result)
                    168: {
                    169:        if (result)
                    170:        {
                    171:                *result = this->result;
                    172:        }
                    173:        return this->rec_final;
                    174: }
                    175: 
                    176: METHOD(imv_workitem_t, destroy, void,
                    177:        private_imv_workitem_t *this)
                    178: {
                    179:        free(this->arg_str);
                    180:        free(this->result);
                    181:        free(this);
                    182: }
                    183: 
                    184: /**
                    185:  * See header
                    186:  */
                    187: imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
                    188:                                                                        char *arg_str, int arg_int,
                    189:                                                                        TNC_IMV_Action_Recommendation rec_fail,
                    190:                                                                        TNC_IMV_Action_Recommendation rec_noresult)
                    191: {
                    192:        private_imv_workitem_t *this;
                    193: 
                    194:        INIT(this,
                    195:                .public = {
                    196:                        .get_id = _get_id,
                    197:                        .set_imv_id = _set_imv_id,
                    198:                        .get_imv_id = _get_imv_id,
                    199:                        .get_type = _get_type,
                    200:                        .get_arg_str = _get_arg_str,
                    201:                        .get_arg_int = _get_arg_int,
                    202:                        .set_result = _set_result,
                    203:                        .get_result = _get_result,
                    204:                        .destroy = _destroy,
                    205:                },
                    206:                .id = id,
                    207:                .imv_id = TNC_IMVID_ANY,
                    208:                .type = type,
                    209:                .arg_str = arg_str ? strdup(arg_str) : NULL,
                    210:                .arg_int = arg_int,
                    211:                .rec_fail = rec_fail,
                    212:                .rec_noresult = rec_noresult,
                    213:                .rec_final = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                    214:        );
                    215: 
                    216:        return &this->public;
                    217: }
                    218: 

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