Added hook to log ID payload type and data
[strongswan.git] / src / conftest / hooks / log_id.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/id_payload.h>
19
20 typedef struct private_log_id_t private_log_id_t;
21
22 /**
23 * Private data of an log_id_t object.
24 */
25 struct private_log_id_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_id_t *this, ike_sa_t *ike_sa, message_t *message,
35 bool incoming)
36 {
37 if (incoming)
38 {
39 enumerator_t *enumerator;
40 payload_t *payload;
41 id_payload_t *id;
42 chunk_t data;
43
44 enumerator = message->create_payload_enumerator(message);
45 while (enumerator->enumerate(enumerator, &payload))
46 {
47 if (payload->get_type(payload) == ID_INITIATOR ||
48 payload->get_type(payload) == ID_RESPONDER)
49 {
50 id = (id_payload_t*)payload;
51 data = id->get_data(id);
52
53 DBG1(DBG_CFG, "%N: %N %B",
54 payload_type_short_names, payload->get_type(payload),
55 id_type_names, id->get_id_type(id), &data);
56 }
57 }
58 enumerator->destroy(enumerator);
59 }
60 return TRUE;
61 }
62
63 METHOD(hook_t, destroy, void,
64 private_log_id_t *this)
65 {
66 free(this);
67 }
68
69 /**
70 * Create the IKE_AUTH fill hook
71 */
72 hook_t *log_id_hook_create(char *name)
73 {
74 private_log_id_t *this;
75
76 INIT(this,
77 .hook = {
78 .listener = {
79 .message = _message,
80 },
81 .destroy = _destroy,
82 },
83 );
84
85 return &this->hook;
86 }