- retransmitting of requests implemented
[strongswan.git] / Source / charon / queues / jobs / retransmit_request_job.c
1 /**
2 * @file retransmit_request_job.c
3 *
4 * @brief Implementation of retransmit_request_job_t.
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 #include "retransmit_request_job.h"
24
25
26 #include <utils/allocator.h>
27
28
29 typedef struct private_retransmit_request_job_t private_retransmit_request_job_t;
30
31 /**
32 * Private data of an retransmit_request_job_t Object.
33 */
34 struct private_retransmit_request_job_t {
35 /**
36 * Public retransmit_request_job_t interface.
37 */
38 retransmit_request_job_t public;
39
40 /**
41 * Message ID of the request to resend.
42 */
43 u_int32_t message_id;
44
45 /**
46 * ID of the IKE_SA which the message belongs to.
47 */
48 ike_sa_id_t *ike_sa_id;
49
50 /**
51 * Number of times a request was retransmitted
52 */
53 u_int32_t retransmit_count;
54 };
55
56
57 /**
58 * Implements job_t.get_type.
59 */
60 static job_type_t get_type(private_retransmit_request_job_t *this)
61 {
62 return RETRANSMIT_REQUEST;
63 }
64
65 /**
66 * Implements retransmit_request_job_t.get_ike_sa_id.
67 */
68 static ike_sa_id_t *get_ike_sa_id(private_retransmit_request_job_t *this)
69 {
70 return this->ike_sa_id;
71 }
72
73 /**
74 * Implements retransmit_request_job_t.get_retransmit_count.
75 */
76 static u_int32_t get_retransmit_count(private_retransmit_request_job_t *this)
77 {
78 return this->retransmit_count;
79 }
80
81 /**
82 * Implements retransmit_request_job_t.increase_retransmit_count.
83 */
84 static void increase_retransmit_count(private_retransmit_request_job_t *this)
85 {
86 this->retransmit_count++;
87 }
88
89 /**
90 * Implements retransmit_request_job_t.get_message_id.
91 */
92 static u_int32_t get_message_id(private_retransmit_request_job_t *this)
93 {
94 return this->message_id;
95 }
96
97
98 /**
99 * Implements job_t.destroy.
100 */
101 static void destroy(private_retransmit_request_job_t *this)
102 {
103 this->ike_sa_id->destroy(this->ike_sa_id);
104 allocator_free(this);
105 }
106
107 /*
108 * Described in header.
109 */
110 retransmit_request_job_t *retransmit_request_job_create(u_int32_t message_id,ike_sa_id_t *ike_sa_id)
111 {
112 private_retransmit_request_job_t *this = allocator_alloc_thing(private_retransmit_request_job_t);
113
114 /* interface functions */
115 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
116 /* same as destroy */
117 this->public.job_interface.destroy_all = (void (*) (job_t *)) destroy;
118 this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
119
120 /* public functions */
121 this->public.get_ike_sa_id = (ike_sa_id_t * (*)(retransmit_request_job_t *)) get_ike_sa_id;
122 this->public.get_message_id = (u_int32_t (*)(retransmit_request_job_t *)) get_message_id;
123 this->public.destroy = (void (*)(retransmit_request_job_t *)) destroy;
124 this->public.get_retransmit_count = (u_int32_t (*)(retransmit_request_job_t *)) get_retransmit_count;
125 this->public.increase_retransmit_count = (void (*)(retransmit_request_job_t *)) increase_retransmit_count;
126
127 /* private variables */
128 this->message_id = message_id;
129 this->retransmit_count = 0;
130 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
131
132 return &(this->public);
133 }