]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/conftest/hooks/set_ike_request.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / conftest / hooks / set_ike_request.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "hook.h"
18
19 #include <encoding/payloads/unknown_payload.h>
20
21 typedef struct private_set_ike_request_t private_set_ike_request_t;
22
23 /**
24 * Private data of an set_ike_request_t object.
25 */
26 struct private_set_ike_request_t {
27
28 /**
29 * Implements the hook_t interface.
30 */
31 hook_t hook;
32
33 /**
34 * Alter requests or responses?
35 */
36 bool req;
37
38 /**
39 * ID of message to alter.
40 */
41 int id;
42 };
43
44 METHOD(listener_t, message, bool,
45 private_set_ike_request_t *this, ike_sa_t *ike_sa, message_t *message,
46 bool incoming, bool plain)
47 {
48 if (!incoming && plain &&
49 message->get_request(message) == this->req &&
50 message->get_message_id(message) == this->id)
51 {
52 DBG1(DBG_CFG, "toggling IKE message request flag");
53 message->set_request(message, !this->req);
54 }
55 return TRUE;
56 }
57
58 METHOD(hook_t, destroy, void,
59 private_set_ike_request_t *this)
60 {
61 free(this);
62 }
63
64 /**
65 * Create the IKE_AUTH fill hook
66 */
67 hook_t *set_ike_request_hook_create(char *name)
68 {
69 private_set_ike_request_t *this;
70
71 INIT(this,
72 .hook = {
73 .listener = {
74 .message = _message,
75 },
76 .destroy = _destroy,
77 },
78 .req = conftest->test->get_bool(conftest->test,
79 "hooks.%s.request", TRUE, name),
80 .id = conftest->test->get_int(conftest->test,
81 "hooks.%s.id", 0, name),
82 );
83
84 return &this->hook;
85 }