Annotation of embedaddon/strongswan/src/libcharon/plugins/unity/unity_plugin.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2012 Martin Willi
                      3:  * Copyright (C) 2012 revosec AG
                      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 "unity_plugin.h"
                     17: #include "unity_handler.h"
                     18: #include "unity_narrow.h"
                     19: #include "unity_provider.h"
                     20: 
                     21: #include <daemon.h>
                     22: 
                     23: typedef struct private_unity_plugin_t private_unity_plugin_t;
                     24: 
                     25: /**
                     26:  * private data of unity_plugin
                     27:  */
                     28: struct private_unity_plugin_t {
                     29: 
                     30:        /**
                     31:         * public functions
                     32:         */
                     33:        unity_plugin_t public;
                     34: 
                     35:        /**
                     36:         * Handler for UNITY configuration attributes
                     37:         */
                     38:        unity_handler_t *handler;
                     39: 
                     40:        /**
                     41:         * Responder Unity configuration attribute provider
                     42:         */
                     43:        unity_provider_t *provider;
                     44: 
                     45:        /**
                     46:         * Traffic selector narrower, for Unity Split-Includes
                     47:         */
                     48:        unity_narrow_t *narrower;
                     49: };
                     50: 
                     51: METHOD(plugin_t, get_name, char*,
                     52:        private_unity_plugin_t *this)
                     53: {
                     54:        return "unity";
                     55: }
                     56: 
                     57: /**
                     58:  * Register listener
                     59:  */
                     60: static bool plugin_cb(private_unity_plugin_t *this,
                     61:                                          plugin_feature_t *feature, bool reg, void *cb_data)
                     62: {
                     63:        if (reg)
                     64:        {
                     65:                charon->attributes->add_handler(charon->attributes,
                     66:                                                                                &this->handler->handler);
                     67:                charon->attributes->add_provider(charon->attributes,
                     68:                                                                                 &this->provider->provider);
                     69:                charon->bus->add_listener(charon->bus, &this->narrower->listener);
                     70:        }
                     71:        else
                     72:        {
                     73:                charon->bus->remove_listener(charon->bus, &this->narrower->listener);
                     74:                charon->attributes->remove_handler(charon->attributes,
                     75:                                                                                   &this->handler->handler);
                     76:                charon->attributes->remove_provider(charon->attributes,
                     77:                                                                                        &this->provider->provider);
                     78: 
                     79:        }
                     80:        return TRUE;
                     81: }
                     82: 
                     83: METHOD(plugin_t, get_features, int,
                     84:        private_unity_plugin_t *this, plugin_feature_t *features[])
                     85: {
                     86:        static plugin_feature_t f[] = {
                     87:                PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
                     88:                        PLUGIN_PROVIDE(CUSTOM, "unity"),
                     89:        };
                     90:        *features = f;
                     91:        return countof(f);
                     92: }
                     93: 
                     94: METHOD(plugin_t, destroy, void,
                     95:        private_unity_plugin_t *this)
                     96: {
                     97:        this->narrower->destroy(this->narrower);
                     98:        this->handler->destroy(this->handler);
                     99:        this->provider->destroy(this->provider);
                    100:        free(this);
                    101: }
                    102: 
                    103: /*
                    104:  * see header file
                    105:  */
                    106: plugin_t *unity_plugin_create()
                    107: {
                    108:        private_unity_plugin_t *this;
                    109: 
                    110:        INIT(this,
                    111:                .public = {
                    112:                        .plugin = {
                    113:                                .get_name = _get_name,
                    114:                                .get_features = _get_features,
                    115:                                .destroy = _destroy,
                    116:                        },
                    117:                },
                    118:                .handler = unity_handler_create(),
                    119:                .provider = unity_provider_create(),
                    120:        );
                    121:        this->narrower = unity_narrow_create(this->handler);
                    122: 
                    123:        return &this->public.plugin;
                    124: }

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