Annotation of embedaddon/strongswan/src/libcharon/plugins/addrblock/addrblock_plugin.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2010 Martin Willi
                      3:  * Copyright (C) 2010 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 "addrblock_plugin.h"
                     17: 
                     18: #include <daemon.h>
                     19: #include <plugins/plugin_feature.h>
                     20: 
                     21: #include "addrblock_validator.h"
                     22: #include "addrblock_narrow.h"
                     23: 
                     24: typedef struct private_addrblock_plugin_t private_addrblock_plugin_t;
                     25: 
                     26: /**
                     27:  * private data of addrblock_plugin
                     28:  */
                     29: struct private_addrblock_plugin_t {
                     30: 
                     31:        /**
                     32:         * public functions
                     33:         */
                     34:        addrblock_plugin_t public;
                     35: 
                     36:        /**
                     37:         * Validator implementation instance.
                     38:         */
                     39:        addrblock_validator_t *validator;
                     40: 
                     41:        /**
                     42:         * Listener to check TS list
                     43:         */
                     44:        addrblock_narrow_t *narrower;
                     45: };
                     46: 
                     47: METHOD(plugin_t, get_name, char*,
                     48:        private_addrblock_plugin_t *this)
                     49: {
                     50:        return "addrblock";
                     51: }
                     52: 
                     53: /**
                     54:  * Register listener
                     55:  */
                     56: static bool plugin_cb(private_addrblock_plugin_t *this,
                     57:                                          plugin_feature_t *feature, bool reg, void *cb_data)
                     58: {
                     59:        if (reg)
                     60:        {
                     61:                lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
                     62:                charon->bus->add_listener(charon->bus, &this->narrower->listener);
                     63:        }
                     64:        else
                     65:        {
                     66:                charon->bus->remove_listener(charon->bus, &this->narrower->listener);
                     67:                lib->credmgr->remove_validator(lib->credmgr,
                     68:                                                                           &this->validator->validator);
                     69:        }
                     70:        return TRUE;
                     71: }
                     72: 
                     73: METHOD(plugin_t, get_features, int,
                     74:        private_addrblock_plugin_t *this, plugin_feature_t *features[])
                     75: {
                     76:        static plugin_feature_t f[] = {
                     77:                PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
                     78:                        PLUGIN_PROVIDE(CUSTOM, "addrblock"),
                     79:                                PLUGIN_SDEPEND(CERT_DECODE, CERT_X509),
                     80:        };
                     81:        *features = f;
                     82:        return countof(f);
                     83: }
                     84: 
                     85: METHOD(plugin_t, destroy, void,
                     86:        private_addrblock_plugin_t *this)
                     87: {
                     88:        this->narrower->destroy(this->narrower);
                     89:        this->validator->destroy(this->validator);
                     90:        free(this);
                     91: }
                     92: 
                     93: /*
                     94:  * see header file
                     95:  */
                     96: plugin_t *addrblock_plugin_create()
                     97: {
                     98:        private_addrblock_plugin_t *this;
                     99: 
                    100:        INIT(this,
                    101:                .public = {
                    102:                        .plugin = {
                    103:                                .get_name = _get_name,
                    104:                                .get_features = _get_features,
                    105:                                .destroy = _destroy,
                    106:                        },
                    107:                },
                    108:                .validator = addrblock_validator_create(),
                    109:                .narrower = addrblock_narrow_create(),
                    110:        );
                    111: 
                    112:        return &this->public.plugin;
                    113: }

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