Annotation of embedaddon/strongswan/src/conftest/hooks/ignore_message.c, revision 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 "hook.h"
        !            17: 
        !            18: typedef struct private_ignore_message_t private_ignore_message_t;
        !            19: 
        !            20: /**
        !            21:  * Private data of an ignore_message_t object.
        !            22:  */
        !            23: struct private_ignore_message_t {
        !            24: 
        !            25:        /**
        !            26:         * Implements the hook_t interface.
        !            27:         */
        !            28:        hook_t hook;
        !            29: 
        !            30:        /**
        !            31:         * Drop incoming or outgoing?
        !            32:         */
        !            33:        bool in;
        !            34: 
        !            35:        /**
        !            36:         * Drop requests or responses?
        !            37:         */
        !            38:        bool req;
        !            39: 
        !            40:        /**
        !            41:         * ID of message to drop.
        !            42:         */
        !            43:        int id;
        !            44: };
        !            45: 
        !            46: METHOD(listener_t, message, bool,
        !            47:        private_ignore_message_t *this, ike_sa_t *ike_sa, message_t *message,
        !            48:        bool incoming, bool plain)
        !            49: {
        !            50:        if (incoming == this->in && plain &&
        !            51:                message->get_request(message) == this->req &&
        !            52:                message->get_message_id(message) == this->id)
        !            53:        {
        !            54:                DBG1(DBG_CFG, "ignoring message");
        !            55:                message->set_exchange_type(message, EXCHANGE_TYPE_UNDEFINED);
        !            56:        }
        !            57:        return TRUE;
        !            58: }
        !            59: 
        !            60: METHOD(hook_t, destroy, void,
        !            61:        private_ignore_message_t *this)
        !            62: {
        !            63:        free(this);
        !            64: }
        !            65: 
        !            66: /**
        !            67:  * Create the ignore_message hook
        !            68:  */
        !            69: hook_t *ignore_message_hook_create(char *name)
        !            70: {
        !            71:        private_ignore_message_t *this;
        !            72: 
        !            73:        INIT(this,
        !            74:                .hook = {
        !            75:                        .listener = {
        !            76:                                .message = _message,
        !            77:                        },
        !            78:                        .destroy = _destroy,
        !            79:                },
        !            80:                .in = conftest->test->get_bool(conftest->test,
        !            81:                                                                                "hooks.%s.inbound", TRUE, name),
        !            82:                .req = conftest->test->get_bool(conftest->test,
        !            83:                                                                                "hooks.%s.request", TRUE, name),
        !            84:                .id = conftest->test->get_int(conftest->test,
        !            85:                                                                                "hooks.%s.id", 0, name),
        !            86:        );
        !            87: 
        !            88:        return &this->hook;
        !            89: }

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