Annotation of embedaddon/strongswan/src/libcharon/plugins/uci/uci_plugin.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2008 Thomas Kallenberg
        !             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 "uci_plugin.h"
        !            17: #include "uci_config.h"
        !            18: #include "uci_creds.h"
        !            19: #include "uci_control.h"
        !            20: 
        !            21: #include <daemon.h>
        !            22: 
        !            23: /**
        !            24:  * UCI package name to use for lookups
        !            25:  */
        !            26: #define UCI_PACKAGE "strongswan"
        !            27: 
        !            28: typedef struct private_uci_plugin_t private_uci_plugin_t;
        !            29: 
        !            30: /**
        !            31:  * private data of uci plugin
        !            32:  */
        !            33: struct private_uci_plugin_t {
        !            34: 
        !            35:        /**
        !            36:         * implements plugin interface
        !            37:         */
        !            38:        uci_plugin_t public;
        !            39: 
        !            40:        /**
        !            41:         * UCI configuration backend
        !            42:         */
        !            43:        uci_config_t *config;
        !            44: 
        !            45:        /**
        !            46:         * UCI credential set implementation
        !            47:         */
        !            48:        uci_creds_t *creds;
        !            49: 
        !            50:        /**
        !            51:         * UCI parser wrapper
        !            52:         */
        !            53:        uci_parser_t *parser;
        !            54: 
        !            55:        /**
        !            56:         * UCI control interface
        !            57:         */
        !            58:        uci_control_t *control;
        !            59: };
        !            60: 
        !            61: METHOD(plugin_t, get_name, char*,
        !            62:        private_uci_plugin_t *this)
        !            63: {
        !            64:        return "uci";
        !            65: }
        !            66: 
        !            67: /**
        !            68:  * Register backend
        !            69:  */
        !            70: static bool plugin_cb(private_uci_plugin_t *this,
        !            71:                                          plugin_feature_t *feature, bool reg, void *cb_data)
        !            72: {
        !            73:        if (reg)
        !            74:        {
        !            75:                charon->backends->add_backend(charon->backends, &this->config->backend);
        !            76:                lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
        !            77:        }
        !            78:        else
        !            79:        {
        !            80:                charon->backends->remove_backend(charon->backends,
        !            81:                                                                                 &this->config->backend);
        !            82:                lib->credmgr->remove_set(lib->credmgr, &this->creds->credential_set);
        !            83:        }
        !            84:        return TRUE;
        !            85: }
        !            86: 
        !            87: METHOD(plugin_t, get_features, int,
        !            88:        private_uci_plugin_t *this, plugin_feature_t *features[])
        !            89: {
        !            90:        static plugin_feature_t f[] = {
        !            91:                PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
        !            92:                        PLUGIN_PROVIDE(CUSTOM, "uci"),
        !            93:        };
        !            94:        *features = f;
        !            95:        return countof(f);
        !            96: }
        !            97: 
        !            98: METHOD(plugin_t, destroy, void,
        !            99:        private_uci_plugin_t *this)
        !           100: {
        !           101:        this->config->destroy(this->config);
        !           102:        this->creds->destroy(this->creds);
        !           103:        this->parser->destroy(this->parser);
        !           104:        this->control->destroy(this->control);
        !           105:        free(this);
        !           106: }
        !           107: 
        !           108: /*
        !           109:  * see header file
        !           110:  */
        !           111: plugin_t *uci_plugin_create()
        !           112: {
        !           113:        private_uci_plugin_t *this;
        !           114: 
        !           115:        INIT(this,
        !           116:                .public = {
        !           117:                        .plugin = {
        !           118:                                .get_name = _get_name,
        !           119:                                .get_features = _get_features,
        !           120:                                .destroy = _destroy,
        !           121:                        },
        !           122:                },
        !           123:                .parser = uci_parser_create(UCI_PACKAGE),
        !           124:                .control = uci_control_create(),
        !           125:        );
        !           126:        this->config = uci_config_create(this->parser);
        !           127:        this->creds = uci_creds_create(this->parser);
        !           128: 
        !           129:        return &this->public.plugin;
        !           130: }

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