improved log output for checkout_by_message()
[strongswan.git] / src / charon / queues / jobs / process_message_job.c
1 /**
2 * @file process_message_job.h
3 *
4 * @brief Implementation of process_message_job_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2007 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25 #include "process_message_job.h"
26
27 #include <daemon.h>
28
29 typedef struct private_process_message_job_t private_process_message_job_t;
30
31 /**
32 * Private data of an process_message_job_t Object
33 */
34 struct private_process_message_job_t {
35 /**
36 * public process_message_job_t interface
37 */
38 process_message_job_t public;
39
40 /**
41 * Message associated with this job
42 */
43 message_t *message;
44 };
45
46 /**
47 * Implements job_t.get_type.
48 */
49 static job_type_t get_type(private_process_message_job_t *this)
50 {
51 return PROCESS_MESSAGE;
52 }
53
54 /**
55 * Implementation of job_t.execute.
56 */
57 static status_t execute(private_process_message_job_t *this)
58 {
59 ike_sa_t *ike_sa;
60
61 ike_sa = charon->ike_sa_manager->checkout_by_message(charon->ike_sa_manager,
62 this->message);
63 if (ike_sa)
64 {
65 DBG1(DBG_NET, "received packet: from %#H to %#H",
66 this->message->get_source(this->message),
67 this->message->get_destination(this->message));
68 if (ike_sa->process_message(ike_sa, this->message) == DESTROY_ME)
69 {
70 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
71 ike_sa);
72 }
73 else
74 {
75 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
76 }
77 }
78 return DESTROY_ME;
79 }
80
81 /**
82 * Implements job_t.destroy.
83 */
84 static void destroy(private_process_message_job_t *this)
85 {
86 this->message->destroy(this->message);
87 free(this);
88 }
89
90 /*
91 * Described in header
92 */
93 process_message_job_t *process_message_job_create(message_t *message)
94 {
95 private_process_message_job_t *this = malloc_thing(private_process_message_job_t);
96
97 /* interface functions */
98 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
99 this->public.job_interface.execute = (status_t (*) (job_t *)) execute;
100 this->public.job_interface.destroy = (void(*)(job_t*))destroy;
101
102 /* private variables */
103 this->message = message;
104
105 return &(this->public);
106 }