- added destroy_all to job_t
[strongswan.git] / Source / charon / jobs / incoming_packet_job.c
1 /**
2 * @file incoming_packet_job.h
3 *
4 * @brief Job of type INCOMING_PACKET
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23
24 #include "incoming_packet_job.h"
25
26 #include "../utils/allocator.h"
27
28 /**
29 * Private data of an incoming_packet_job_t Object
30 *
31 */
32 typedef struct private_incoming_packet_job_s private_incoming_packet_job_t;
33
34 struct private_incoming_packet_job_s {
35 /**
36 * public incoming_packet_job_t interface
37 */
38 incoming_packet_job_t public;
39
40 /**
41 * Assigned packet
42 */
43 packet_t *packet;
44 };
45
46
47 /**
48 * Implements incoming_packet_job_t's get_type function.
49 * See #incoming_packet_job_t.get_type for description.
50 */
51 static job_type_t get_type(private_incoming_packet_job_t *this)
52 {
53 return INCOMING_PACKET;
54 }
55
56 /**
57 * Implements incoming_packet_job_t's get_configuration_name function.
58 * See #incoming_packet_job_t.get_configuration_name for description.
59 */
60 static status_t get_packet(private_incoming_packet_job_t *this,packet_t **packet)
61 {
62 if (this->packet == NULL)
63 {
64 return FAILED;
65 }
66 *packet = this->packet;
67 return SUCCESS;
68 }
69
70
71
72 /**
73 * Implements job_t's and destroy_all function.
74 * See #job_t.destroy_all description.
75 */
76 static status_t destroy_all(private_incoming_packet_job_t *this)
77 {
78 if (this->packet != NULL)
79 {
80 this->packet->destroy(this->packet);
81 }
82 allocator_free(this);
83 return SUCCESS;
84 }
85
86 /**
87 * Implements job_t's and incoming_packet_job_t's destroy function.
88 * See #job_t.destroy or #incoming_packet_job_t.destroy for description.
89 */
90 static status_t destroy(job_t *job)
91 {
92 private_incoming_packet_job_t *this = (private_incoming_packet_job_t *) job;
93 allocator_free(this);
94 return SUCCESS;
95 }
96
97
98 /*
99 * Described in header
100 */
101 incoming_packet_job_t *incoming_packet_job_create(packet_t *packet)
102 {
103 private_incoming_packet_job_t *this = allocator_alloc_thing(private_incoming_packet_job_t);
104 if ((this == NULL))
105 {
106 return NULL;
107 }
108
109 /* interface functions */
110 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
111 this->public.job_interface.destroy_all = (status_t (*) (job_t *)) destroy_all;
112 this->public.job_interface.destroy = destroy;
113
114 /* public functions */
115 this->public.get_packet = (status_t (*)(incoming_packet_job_t *,packet_t **)) get_packet;
116 this->public.destroy = (status_t (*)(incoming_packet_job_t *)) destroy;
117
118 /* private variables */
119 this->packet = packet;
120
121 return &(this->public);
122 }