Annotation of embedaddon/strongswan/src/conftest/hooks/set_ike_request.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_request_t private_set_ike_request_t;
                     21: 
                     22: /**
                     23:  * Private data of an set_ike_request_t object.
                     24:  */
                     25: struct private_set_ike_request_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_request_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:                DBG1(DBG_CFG, "toggling IKE message request flag");
                     52:                message->set_request(message, !this->req);
                     53:        }
                     54:        return TRUE;
                     55: }
                     56: 
                     57: METHOD(hook_t, destroy, void,
                     58:        private_set_ike_request_t *this)
                     59: {
                     60:        free(this);
                     61: }
                     62: 
                     63: /**
                     64:  * Create the IKE_AUTH fill hook
                     65:  */
                     66: hook_t *set_ike_request_hook_create(char *name)
                     67: {
                     68:        private_set_ike_request_t *this;
                     69: 
                     70:        INIT(this,
                     71:                .hook = {
                     72:                        .listener = {
                     73:                                .message = _message,
                     74:                        },
                     75:                        .destroy = _destroy,
                     76:                },
                     77:                .req = conftest->test->get_bool(conftest->test,
                     78:                                                                                "hooks.%s.request", TRUE, name),
                     79:                .id = conftest->test->get_int(conftest->test,
                     80:                                                                                "hooks.%s.id", 0, name),
                     81:        );
                     82: 
                     83:        return &this->hook;
                     84: }

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