d14de48ad26cb80378fd9f6f2c696de94fd02c8e
[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 /**
69 * Implements job_t's and initiate_ike_sa_job_t's destroy function.
70 * See #job_t.destroy or #initiate_ike_sa_job_t.destroy for description.
71 */
72 static status_t destroy(job_t *job)
73 {
74 private_initiate_ike_sa_job_t *this = (private_initiate_ike_sa_job_t *) job;
75 allocator_free(this->configuration_name);
76 allocator_free(this);
77 return SUCCESS;
78 }
79
80
81 /*
82 * Described in header
83 */
84 initiate_ike_sa_job_t *initiate_ike_sa_job_create(char *configuration_name)
85 {
86 private_initiate_ike_sa_job_t *this = allocator_alloc_thing(private_initiate_ike_sa_job_t);
87 if ((this == NULL) || (configuration_name == NULL))
88 {
89 return NULL;
90 }
91
92 /* interface functions */
93 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
94 this->public.job_interface.destroy = destroy;
95
96 /* public functions */
97 this->public.get_configuration_name = (char * (*)(initiate_ike_sa_job_t *)) get_configuration_name;
98 this->public.destroy = (status_t (*)(initiate_ike_sa_job_t *)) destroy;
99
100 /* private variables */
101 this->configuration_name = allocator_alloc(strlen(configuration_name) + 1);
102 if (this->configuration_name == NULL)
103 {
104 allocator_free(this);
105 return NULL;
106 }
107 strcpy(this->configuration_name,configuration_name);
108
109 return &(this->public);
110 }