- added destroy_all to job_t
[strongswan.git] / Source / charon / jobs / initiate_ike_sa_job.c
1 /**
2 * @file initiate_ike_sa_job.c
3 *
4 * @brief Job of type INITIATE_IKE_SA
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 <stdlib.h>
25
26 #include "initiate_ike_sa_job.h"
27
28 #include "../utils/allocator.h"
29
30 /**
31 * Private data of an initiate_ike_sa_job_t Object
32 *
33 */
34 typedef struct private_initiate_ike_sa_job_s private_initiate_ike_sa_job_t;
35
36 struct private_initiate_ike_sa_job_s {
37 /**
38 * public initiate_ike_sa_job_t interface
39 */
40 initiate_ike_sa_job_t public;
41
42 /**
43 * Name of the assigned configuration
44 */
45 char *configuration_name;
46 };
47
48
49 /**
50 * Implements initiate_ike_sa_job_t's get_type function.
51 * See #initiate_ike_sa_job_t.get_type for description.
52 */
53 static job_type_t get_type(private_initiate_ike_sa_job_t *this)
54 {
55 return INITIATE_IKE_SA;
56 }
57
58 /**
59 * Implements initiate_ike_sa_job_t's get_configuration_name function.
60 * See #initiate_ike_sa_job_t.get_configuration_name for description.
61 */
62 static char * get_configuration_name(private_initiate_ike_sa_job_t *this)
63 {
64 return this->configuration_name;
65 }
66
67 /**
68 * Implements job_t's and initiate_ike_sa_job_t's destroy function.
69 * See #job_t.destroy or #initiate_ike_sa_job_t.destroy for description.
70 */
71 static status_t destroy(job_t *job)
72 {
73 private_initiate_ike_sa_job_t *this = (private_initiate_ike_sa_job_t *) job;
74 allocator_free(this->configuration_name);
75 allocator_free(this);
76 return SUCCESS;
77 }
78
79
80 /*
81 * Described in header
82 */
83 initiate_ike_sa_job_t *initiate_ike_sa_job_create(char *configuration_name)
84 {
85 private_initiate_ike_sa_job_t *this = allocator_alloc_thing(private_initiate_ike_sa_job_t);
86 if ((this == NULL) || (configuration_name == NULL))
87 {
88 return NULL;
89 }
90
91 /* interface functions */
92 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
93 /* same as destroy */
94 this->public.job_interface.destroy_all = (status_t (*) (job_t *)) destroy;
95 this->public.job_interface.destroy = destroy;
96
97 /* public functions */
98 this->public.get_configuration_name = (char * (*)(initiate_ike_sa_job_t *)) get_configuration_name;
99 this->public.destroy = (status_t (*)(initiate_ike_sa_job_t *)) destroy;
100
101 /* private variables */
102 this->configuration_name = allocator_alloc(strlen(configuration_name) + 1);
103 if (this->configuration_name == NULL)
104 {
105 allocator_free(this);
106 return NULL;
107 }
108 strcpy(this->configuration_name,configuration_name);
109
110 return &(this->public);
111 }