29
29
// for later cleanup.
30
30
static struct tr_tcp_config * tcp_config = 0 ;
31
31
32
- /**
33
- * Creates and returns an `rtr_mgr_config` structure from the specified
34
- * `rtr_mgr_group` structure.
35
- * @param groups
36
- * @return
37
- */
38
- static struct rtr_mgr_config * rtr_create_mgr_config (
39
- rtr_mgr_group * groups , unsigned int count
40
- ) {
41
- // Initialize result.
42
- struct rtr_mgr_config * result = malloc (sizeof (struct rtr_mgr_config ));
43
- memset (result , 0 , sizeof (struct rtr_mgr_config ));
44
-
45
- // Populate result.
46
- result -> groups = groups ;
47
- result -> len = count ;
48
-
49
- // Return result.
50
- return result ;
51
- }
52
-
53
32
/**
54
33
* Creates and returns a `rtr_mgr_group` structure from the specified
55
34
* `rtr_socket` structure array containing the specified number of elements.
56
35
* @param rtr_socket
57
36
* @param count
58
37
* @return
59
38
*/
60
- static rtr_mgr_group * rtr_create_mgr_group (
39
+ static struct rtr_mgr_group * rtr_create_mgr_group (
61
40
struct rtr_socket * sockets , unsigned int count
62
41
) {
63
- // Create a prototype rtr_mgr_group to be able to retrieve its size.
64
- // TODO: Remove when rtr_mgr_group is not an anonymous struct anymore.
65
- rtr_mgr_group prototype ;
66
-
67
42
// Iterator.
68
43
unsigned int i ;
69
44
70
45
// Initialize result.
71
- rtr_mgr_group * result = malloc (sizeof prototype ); // TODO: see above
72
- memset (result , 0 , sizeof prototype ); // TODO: see above.
46
+ struct rtr_mgr_group * result = malloc (sizeof ( struct rtr_mgr_group ));
47
+ memset (result , 0 , sizeof ( struct rtr_mgr_group ));
73
48
74
49
// Populate result.
75
50
result -> sockets = malloc (count * sizeof (struct rtr_socket * ));
@@ -109,7 +84,6 @@ static struct rtr_socket *rtr_create_rtr_socket(struct tr_socket *socket) {
109
84
* @param server_hostkey_path
110
85
* @param username
111
86
* @param client_privkey_path
112
- * @param client_pubkey_path
113
87
* @return
114
88
*/
115
89
static struct tr_ssh_config * rtr_create_ssh_config (
@@ -118,8 +92,7 @@ static struct tr_ssh_config *rtr_create_ssh_config(
118
92
const char * bindaddr ,
119
93
const char * server_hostkey_path ,
120
94
const char * username ,
121
- const char * client_privkey_path ,
122
- const char * client_pubkey_path
95
+ const char * client_privkey_path
123
96
) {
124
97
// Initialize result.
125
98
struct tr_ssh_config * result = malloc (sizeof (struct tr_ssh_config ));
@@ -139,8 +112,6 @@ static struct tr_ssh_config *rtr_create_ssh_config(
139
112
result -> server_hostkey_path = strdup (server_hostkey_path );
140
113
if (client_privkey_path )
141
114
result -> client_privkey_path = strdup (client_privkey_path );
142
- if (client_pubkey_path )
143
- result -> client_pubkey_path = strdup (client_pubkey_path );
144
115
145
116
// Return result.
146
117
return result ;
@@ -256,29 +227,29 @@ void rtr_close(struct rtr_mgr_config *rtr_mgr_config) {
256
227
struct rtr_mgr_config * rtr_ssh_connect (
257
228
const char * host , const char * port , const char * bindaddr ,
258
229
const char * hostkey_file , const char * username , const char * privkey_file ,
259
- const char * pubkey_file , const pfx_update_fp callback
230
+ const pfx_update_fp callback
260
231
) {
261
- // Create RTR manager config with the single server group.
262
- struct rtr_mgr_config * result = rtr_create_mgr_config (
263
- rtr_create_mgr_group (
264
- rtr_create_rtr_socket (
265
- rtr_create_ssh_socket (rtr_create_ssh_config (
266
- host ,
267
- strtoul (port , 0 , 10 ),
268
- bindaddr ,
269
- hostkey_file ,
270
- username ,
271
- privkey_file ,
272
- pubkey_file
273
- ))
274
- ),
275
- 1
232
+ // Prepare pointer to result config.
233
+ struct rtr_mgr_config * result ;
234
+
235
+ // Create the single server group.
236
+ struct rtr_mgr_group * group = rtr_create_mgr_group (
237
+ rtr_create_rtr_socket (
238
+ rtr_create_ssh_socket (rtr_create_ssh_config (
239
+ host ,
240
+ strtoul (port , 0 , 10 ),
241
+ bindaddr ,
242
+ hostkey_file ,
243
+ username ,
244
+ privkey_file
245
+ ))
276
246
),
277
247
1
278
248
);
279
249
280
250
// Initialize RTR manager and bail out on error.
281
- if (rtr_mgr_init (result , 240 , 520 , callback ) == RTR_ERROR ) {
251
+ result = rtr_mgr_init (group , 1 , 240 , 520 , callback , 0 , 0 );
252
+ if (!result ) {
282
253
fprintf (stderr , "Error initializing RTR manager." );
283
254
return 0 ;
284
255
}
@@ -297,21 +268,20 @@ struct rtr_mgr_config *rtr_tcp_connect(
297
268
const char * host , const char * port , const char * bindaddr ,
298
269
const pfx_update_fp callback
299
270
) {
300
- // Create RTR manager config with the single server group.
301
- struct rtr_mgr_config * result = rtr_create_mgr_config (
302
- rtr_create_mgr_group (
303
- rtr_create_rtr_socket (
304
- rtr_create_tcp_socket (
305
- rtr_create_tcp_config (host , port , bindaddr )
306
- )
307
- ),
308
- 1
271
+ // Prepare pointer to result config.
272
+ struct rtr_mgr_config * result ;
273
+
274
+ // Create the single server group.
275
+ struct rtr_mgr_group * group = rtr_create_mgr_group (
276
+ rtr_create_rtr_socket (
277
+ rtr_create_tcp_socket (rtr_create_tcp_config (host , port , bindaddr ))
309
278
),
310
279
1
311
280
);
312
281
313
282
// Initialize RTR manager and bail out on error.
314
- if (rtr_mgr_init (result , 240 , 520 , callback ) == RTR_ERROR ) {
283
+ result = rtr_mgr_init (group , 1 , 240 , 520 , callback , 0 , 0 );
284
+ if (!result ) {
315
285
fprintf (stderr , "Error initializing RTR manager." );
316
286
return 0 ;
317
287
}
0 commit comments