Use standard ID getter in log_id hook
[strongswan.git] / src / conftest / hooks / set_ike_version.c
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_version_t private_set_ike_version_t;
21
22 /**
23 * Private data of an set_ike_version_t object.
24 */
25 struct private_set_ike_version_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 * Major version to set
44 */
45 int major;
46
47 /**
48 * Minor version to set
49 */
50 int minor;
51 };
52
53 METHOD(listener_t, message, bool,
54 private_set_ike_version_t *this, ike_sa_t *ike_sa, message_t *message,
55 bool incoming)
56 {
57 if (!incoming &&
58 message->get_request(message) == this->req &&
59 message->get_message_id(message) == this->id)
60 {
61 DBG1(DBG_CFG, "setting IKE version of message ID %d to %d.%d",
62 this->id, this->major, this->minor);
63 message->set_major_version(message, this->major);
64 message->set_minor_version(message, this->minor);
65 }
66 return TRUE;
67 }
68
69 METHOD(hook_t, destroy, void,
70 private_set_ike_version_t *this)
71 {
72 free(this);
73 }
74
75 /**
76 * Create the IKE_AUTH fill hook
77 */
78 hook_t *set_ike_version_hook_create(char *name)
79 {
80 private_set_ike_version_t *this;
81
82 INIT(this,
83 .hook = {
84 .listener = {
85 .message = _message,
86 },
87 .destroy = _destroy,
88 },
89 .req = conftest->test->get_bool(conftest->test,
90 "hooks.%s.request", TRUE, name),
91 .id = conftest->test->get_int(conftest->test,
92 "hooks.%s.id", 0, name),
93 .major = conftest->test->get_int(conftest->test,
94 "hooks.%s.major", 2, name),
95 .minor = conftest->test->get_int(conftest->test,
96 "hooks.%s.minor", 0, name),
97 );
98
99 return &this->hook;
100 }