Return to updown_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / plugins / updown |
1.1 misho 1: /* 2: * Copyright (C) 2008 Martin Willi 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 "updown_plugin.h" 17: #include "updown_listener.h" 18: #include "updown_handler.h" 19: 20: #include <daemon.h> 21: 22: typedef struct private_updown_plugin_t private_updown_plugin_t; 23: 24: /** 25: * private data of updown plugin 26: */ 27: struct private_updown_plugin_t { 28: 29: /** 30: * implements plugin interface 31: */ 32: updown_plugin_t public; 33: 34: /** 35: * Listener interface, listens to CHILD_SA state changes 36: */ 37: updown_listener_t *listener; 38: 39: /** 40: * Attribute handler, to pass DNS servers to updown 41: */ 42: updown_handler_t *handler; 43: }; 44: 45: METHOD(plugin_t, get_name, char*, 46: private_updown_plugin_t *this) 47: { 48: return "updown"; 49: } 50: 51: /** 52: * Register listener 53: */ 54: static bool plugin_cb(private_updown_plugin_t *this, 55: plugin_feature_t *feature, bool reg, void *cb_data) 56: { 57: if (reg) 58: { 59: if (lib->settings->get_bool(lib->settings, 60: "%s.plugins.updown.dns_handler", FALSE, lib->ns)) 61: { 62: this->handler = updown_handler_create(); 63: charon->attributes->add_handler(charon->attributes, 64: &this->handler->handler); 65: } 66: this->listener = updown_listener_create(this->handler); 67: charon->bus->add_listener(charon->bus, &this->listener->listener); 68: } 69: else 70: { 71: charon->bus->remove_listener(charon->bus, &this->listener->listener); 72: this->listener->destroy(this->listener); 73: if (this->handler) 74: { 75: this->handler->destroy(this->handler); 76: charon->attributes->remove_handler(charon->attributes, 77: &this->handler->handler); 78: } 79: } 80: return TRUE; 81: } 82: 83: METHOD(plugin_t, get_features, int, 84: private_updown_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, "updown"), 89: }; 90: *features = f; 91: return countof(f); 92: } 93: 94: METHOD(plugin_t, destroy, void, 95: private_updown_plugin_t *this) 96: { 97: free(this); 98: } 99: 100: /* 101: * see header file 102: */ 103: plugin_t *updown_plugin_create() 104: { 105: private_updown_plugin_t *this; 106: 107: INIT(this, 108: .public = { 109: .plugin = { 110: .get_name = _get_name, 111: .get_features = _get_features, 112: .destroy = _destroy, 113: }, 114: }, 115: ); 116: 117: return &this->public.plugin; 118: }