c7758faed1a3bd8afd0a0b096436ee7239d6aefc
[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 * Implements job_t's and incoming_packet_job_t's destroy function.
73 * See #job_t.destroy or #incoming_packet_job_t.destroy for description.
74 */
75 static status_t destroy(job_t *job)
76 {
77 private_incoming_packet_job_t *this = (private_incoming_packet_job_t *) job;
78 allocator_free(this);
79 return SUCCESS;
80 }
81
82
83 /*
84 * Described in header
85 */
86 incoming_packet_job_t *incoming_packet_job_create(packet_t *packet)
87 {
88 private_incoming_packet_job_t *this = allocator_alloc_thing(private_incoming_packet_job_t);
89 if ((this == NULL))
90 {
91 return NULL;
92 }
93
94 /* interface functions */
95 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
96 this->public.job_interface.destroy = destroy;
97
98 /* public functions */
99 this->public.get_packet = (status_t (*)(incoming_packet_job_t *,packet_t **)) get_packet;
100 this->public.destroy = (status_t (*)(incoming_packet_job_t *)) destroy;
101
102 /* private variables */
103 this->packet = packet;
104
105 return &(this->public);
106 }