aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-21 11:05:44 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-21 11:05:44 +0000
commitb7fe65e8a48aeb0f9ff51fa01ed2dd5ef5158f23 (patch)
treedc5581ce3c0614bbe617bdb5bf2bce4167dd350e
parentc19bed204759289016e66a14efad0b731f6e4fa5 (diff)
downloadgnunet-b7fe65e8a48aeb0f9ff51fa01ed2dd5ef5158f23.tar.gz
gnunet-b7fe65e8a48aeb0f9ff51fa01ed2dd5ef5158f23.zip
improved url parsing
-rw-r--r--src/transport/plugin_transport_http_server.c96
1 files changed, 76 insertions, 20 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 2cc59662c..f81f5cf6e 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -375,31 +375,92 @@ server_lookup_serverconnection (struct Plugin *plugin,
375 void *a; 375 void *a;
376 size_t a_len; 376 size_t a_len;
377 struct GNUNET_PeerIdentity target; 377 struct GNUNET_PeerIdentity target;
378 int check = GNUNET_NO;
379 uint32_t tag = 0; 378 uint32_t tag = 0;
380 int direction = GNUNET_SYSERR; 379 int direction = GNUNET_SYSERR;
381 380
381 /* url parsing variables */
382 size_t url_len;
383 char *url_end;
384 char *hash_start;
385 char *hash_end;
386 char *tag_start;
387 char *tag_end;
388
382 conn_info = MHD_get_connection_info (mhd_connection, 389 conn_info = MHD_get_connection_info (mhd_connection,
383 MHD_CONNECTION_INFO_CLIENT_ADDRESS); 390 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
384 if ((conn_info->client_addr->sa_family != AF_INET) && 391 if ((conn_info->client_addr->sa_family != AF_INET) &&
385 (conn_info->client_addr->sa_family != AF_INET6)) 392 (conn_info->client_addr->sa_family != AF_INET6))
386 return NULL; 393 return NULL;
387 394
388 if ((strlen (&url[1]) >= 105) && (url[104] == ';')) 395 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
396 "New %s connection from %s\n",
397 method, url);
398 /* URL parsing
399 * URL is valid if it is in the form [peerid[103];tag]*/
400 url_len = strlen (url);
401 url_end = (char *) &url[url_len];
402
403 if (url_len < 105)
389 { 404 {
390 char hash[104]; 405 goto error; /* too short */
391 char *tagc = (char *) &url[105]; 406 }
392 407 hash_start = strrchr (url, '/');
393 memcpy (&hash, &url[1], 103); 408 if (NULL == hash_start)
394 hash[103] = '\0'; 409 {
395 if (GNUNET_OK == 410 goto error; /* '/' delimiter not found */
396 GNUNET_CRYPTO_hash_from_string ((const char *) &hash, 411 }
397 &(target.hashPubKey))) 412 if (hash_start >= url_end)
398 { 413 {
399 tag = strtoul (tagc, NULL, 10); 414 goto error; /* mal formed */
400 if (tagc > 0) 415 }
401 check = GNUNET_YES; 416 hash_start++;
402 } 417
418 hash_end = strrchr (hash_start, ';');
419 if (NULL == hash_end)
420 goto error; /* ';' delimiter not found */
421 if (hash_end >= url_end)
422 {
423 goto error; /* mal formed */
424 }
425
426 if (hash_start >= hash_end)
427 {
428 goto error; /* mal formed */
429 }
430
431 if ((strlen(hash_start) - strlen(hash_end)) != 103)
432 {
433 goto error; /* invalid hash length */
434 }
435
436 char hash[104];
437 memcpy (hash, hash_start, 103);
438 hash[103] = '\0';
439 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((const char *) hash, &(target.hashPubKey)))
440 {
441 goto error; /* mal formed */
442 }
443
444 if (hash_end >= url_end)
445 {
446 goto error; /* mal formed */
447 }
448
449 tag_start = &hash_end[1];
450 /* Converting tag */
451 tag_end = NULL;
452 tag = strtoul (tag_start, &tag_end, 10);
453 if (tag == 0)
454 {
455 goto error; /* mal formed */
456 }
457 if (tag_end == NULL)
458 {
459 goto error; /* mal formed */
460 }
461 if (tag_end != url_end)
462 {
463 goto error; /* mal formed */
403 } 464 }
404 465
405 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 466 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
@@ -408,14 +469,9 @@ server_lookup_serverconnection (struct Plugin *plugin,
408 direction = _SEND; 469 direction = _SEND;
409 else 470 else
410 { 471 {
411 GNUNET_break_op (0);
412 goto error; 472 goto error;
413 } 473 }
414 474
415
416 if (check == GNUNET_NO)
417 goto error;
418
419 plugin->cur_connections++; 475 plugin->cur_connections++;
420 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 476 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
421 "Server: New %s connection from %s with tag %u\n", 477 "Server: New %s connection from %s with tag %u\n",