diff options
Diffstat (limited to 'src/vpn/gnunet-daemon-exit.c')
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index da8392ebe..296d92b50 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c | |||
@@ -262,13 +262,24 @@ message_token (void *cls, | |||
262 | msg); | 262 | msg); |
263 | } | 263 | } |
264 | 264 | ||
265 | |||
265 | /** | 266 | /** |
266 | * Reads the configuration servicecfg and populates udp_services | 267 | * Reads the configuration servicecfg and populates udp_services |
268 | * | ||
269 | * @param cls unused | ||
270 | * @param section name of section in config, equal to hostname | ||
271 | * @param option type of redirect | ||
272 | * @param value specification of services, format is | ||
273 | * "OFFERED-PORT:HOSTNAME:HOST-PORT" (SPACE <more of those>)* | ||
267 | */ | 274 | */ |
268 | static void | 275 | static void |
269 | read_service_conf (void *cls, const char *section, const char *option, | 276 | read_service_conf (void *cls, const char *section, const char *option, |
270 | const char *value) | 277 | const char *value) |
271 | { | 278 | { |
279 | char *cpy; | ||
280 | char *redirect; | ||
281 | char *hostname; | ||
282 | char *hostport; | ||
272 | GNUNET_HashCode hash; | 283 | GNUNET_HashCode hash; |
273 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); | 284 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); |
274 | GNUNET_CRYPTO_hash (section, strlen (section) + 1, | 285 | GNUNET_CRYPTO_hash (section, strlen (section) + 1, |
@@ -276,18 +287,26 @@ read_service_conf (void *cls, const char *section, const char *option, | |||
276 | 287 | ||
277 | if (0 == strcmp ("UDP_REDIRECTS", option)) | 288 | if (0 == strcmp ("UDP_REDIRECTS", option)) |
278 | { | 289 | { |
279 | char *saveptr; | 290 | cpy = GNUNET_strdup (value); |
280 | char *value_ = alloca (strlen (value) + 1); | 291 | for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " ")) |
281 | memcpy (value_, value, strlen (value) + 1); | 292 | { |
282 | char *token = strtok_r (value_, " ", &saveptr); | 293 | if (NULL == (hostname = strstr (redirect, ":"))) |
283 | while (NULL != token) | 294 | { |
284 | { | 295 | // FIXME: bitch |
285 | char *isaveptr; | 296 | continue; |
286 | 297 | } | |
287 | char *itoken = strtok_r (token, ":", &isaveptr); | 298 | hostname[0] = '\0'; |
288 | GNUNET_assert (NULL != itoken); | 299 | hostname++; |
289 | int local_port = atoi (itoken); | 300 | if (NULL == (hostport = strstr (hostname, ":"))) |
290 | GNUNET_assert ((local_port > 0) && (local_port < 65536)); | 301 | { |
302 | // FIXME: bitch | ||
303 | continue; | ||
304 | } | ||
305 | hostport[0] = '\0'; | ||
306 | hostport++; | ||
307 | |||
308 | int local_port = atoi (redirect); | ||
309 | GNUNET_assert ((local_port > 0) && (local_port < 65536)); // FIXME: don't crash!!! | ||
291 | *desc = local_port; | 310 | *desc = local_port; |
292 | 311 | ||
293 | GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash); | 312 | GNUNET_CRYPTO_hash (desc, sizeof (GNUNET_HashCode) + 2, &hash); |
@@ -297,9 +316,7 @@ read_service_conf (void *cls, const char *section, const char *option, | |||
297 | memset (serv, 0, sizeof (struct udp_service)); | 316 | memset (serv, 0, sizeof (struct udp_service)); |
298 | serv->my_port = local_port; | 317 | serv->my_port = local_port; |
299 | 318 | ||
300 | itoken = strtok_r (NULL, ":", &isaveptr); | 319 | if (0 == strcmp ("localhost4", hostname)) |
301 | GNUNET_assert (NULL != itoken); | ||
302 | if (0 == strcmp ("localhost4", itoken)) | ||
303 | { | 320 | { |
304 | serv->version = 4; | 321 | serv->version = 4; |
305 | 322 | ||
@@ -314,7 +331,7 @@ read_service_conf (void *cls, const char *section, const char *option, | |||
314 | serv->v4.ip4address)); | 331 | serv->v4.ip4address)); |
315 | GNUNET_free (ip4addr); | 332 | GNUNET_free (ip4addr); |
316 | } | 333 | } |
317 | else if (0 == strcmp ("localhost6", itoken)) | 334 | else if (0 == strcmp ("localhost6", hostname)) |
318 | { | 335 | { |
319 | serv->version = 6; | 336 | serv->version = 6; |
320 | 337 | ||
@@ -334,11 +351,7 @@ read_service_conf (void *cls, const char *section, const char *option, | |||
334 | // Lookup, yadayadayada | 351 | // Lookup, yadayadayada |
335 | GNUNET_assert (0); | 352 | GNUNET_assert (0); |
336 | } | 353 | } |
337 | 354 | serv->remote_port = atoi (hostport); | |
338 | itoken = strtok_r (NULL, ":", &isaveptr); | ||
339 | GNUNET_assert (NULL != itoken); | ||
340 | serv->remote_port = atoi (itoken); | ||
341 | |||
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key1 %x\n", | 355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key1 %x\n", |
343 | *((unsigned long long *) (desc + 1))); | 356 | *((unsigned long long *) (desc + 1))); |
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key2 %x\n", | 357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store with key2 %x\n", |
@@ -347,9 +360,8 @@ read_service_conf (void *cls, const char *section, const char *option, | |||
347 | GNUNET_CONTAINER_multihashmap_put (udp_services, | 360 | GNUNET_CONTAINER_multihashmap_put (udp_services, |
348 | &hash, serv, | 361 | &hash, serv, |
349 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 362 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
350 | |||
351 | token = strtok_r (NULL, " ", &saveptr); | ||
352 | } | 363 | } |
364 | GNUNET_free (cpy); | ||
353 | } | 365 | } |
354 | } | 366 | } |
355 | 367 | ||