payload: Use common prefixes for all payload type identifiers
[strongswan.git] / src / conftest / hooks / log_ke.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/ke_payload.h>
19
20 typedef struct private_log_ke_t private_log_ke_t;
21
22 /**
23 * Private data of an log_ke_t object.
24 */
25 struct private_log_ke_t {
26
27 /**
28 * Implements the hook_t interface.
29 */
30 hook_t hook;
31 };
32
33 METHOD(listener_t, message, bool,
34 private_log_ke_t *this, ike_sa_t *ike_sa, message_t *message,
35 bool incoming, bool plain)
36 {
37 if (incoming && plain)
38 {
39 enumerator_t *enumerator;
40 payload_t *payload;
41 ke_payload_t *ke;
42
43 enumerator = message->create_payload_enumerator(message);
44 while (enumerator->enumerate(enumerator, &payload))
45 {
46 if (payload->get_type(payload) == PLV2_KEY_EXCHANGE)
47 {
48 ke = (ke_payload_t*)payload;
49 DBG1(DBG_CFG, "received DH group %N",
50 diffie_hellman_group_names, ke->get_dh_group_number(ke));
51 }
52 }
53 enumerator->destroy(enumerator);
54 }
55 return TRUE;
56 }
57
58 METHOD(hook_t, destroy, void,
59 private_log_ke_t *this)
60 {
61 free(this);
62 }
63
64 /**
65 * Create the IKE_AUTH fill hook
66 */
67 hook_t *log_ke_hook_create(char *name)
68 {
69 private_log_ke_t *this;
70
71 INIT(this,
72 .hook = {
73 .listener = {
74 .message = _message,
75 },
76 .destroy = _destroy,
77 },
78 );
79
80 return &this->hook;
81 }