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

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