Annotation of embedaddon/strongswan/src/libcharon/plugins/radattr/radattr_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 "radattr_plugin.h"
                     17: 
                     18: #include "radattr_listener.h"
                     19: 
                     20: #include <daemon.h>
                     21: 
                     22: typedef struct private_radattr_plugin_t private_radattr_plugin_t;
                     23: 
                     24: /**
                     25:  * private data of radattr plugin
                     26:  */
                     27: struct private_radattr_plugin_t {
                     28: 
                     29:        /**
                     30:         * implements plugin interface
                     31:         */
                     32:        radattr_plugin_t public;
                     33: 
                     34:        /**
                     35:         * Listener acting on messages
                     36:         */
                     37:        radattr_listener_t *listener;
                     38: };
                     39: 
                     40: METHOD(plugin_t, get_name, char*,
                     41:        private_radattr_plugin_t *this)
                     42: {
                     43:        return "radattr";
                     44: }
                     45: 
                     46: /**
                     47:  * Register listener
                     48:  */
                     49: static bool plugin_cb(private_radattr_plugin_t *this,
                     50:                                          plugin_feature_t *feature, bool reg, void *cb_data)
                     51: {
                     52:        if (reg)
                     53:        {
                     54:                charon->bus->add_listener(charon->bus, &this->listener->listener);
                     55:        }
                     56:        else
                     57:        {
                     58:                charon->bus->remove_listener(charon->bus, &this->listener->listener);
                     59:        }
                     60:        return TRUE;
                     61: }
                     62: 
                     63: METHOD(plugin_t, get_features, int,
                     64:        private_radattr_plugin_t *this, plugin_feature_t *features[])
                     65: {
                     66:        static plugin_feature_t f[] = {
                     67:                PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
                     68:                        PLUGIN_PROVIDE(CUSTOM, "radattr"),
                     69:        };
                     70:        *features = f;
                     71:        return countof(f);
                     72: }
                     73: 
                     74: METHOD(plugin_t, destroy, void,
                     75:        private_radattr_plugin_t *this)
                     76: {
                     77:        this->listener->destroy(this->listener);
                     78:        free(this);
                     79: }
                     80: 
                     81: /**
                     82:  * Plugin constructor
                     83:  */
                     84: plugin_t *radattr_plugin_create()
                     85: {
                     86:        private_radattr_plugin_t *this;
                     87: 
                     88:        INIT(this,
                     89:                .public = {
                     90:                        .plugin = {
                     91:                                .get_name = _get_name,
                     92:                                .get_features = _get_features,
                     93:                                .destroy = _destroy,
                     94:                        },
                     95:                },
                     96:                .listener = radattr_listener_create(),
                     97:        );
                     98: 
                     99:        return &this->public.plugin;
                    100: }

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