diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-25 15:18:14 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-25 19:56:11 +0000 |
commit | 56d249e5ad798f65a6cf97ecc9ae22b4c86ddf5b (patch) | |
tree | 737483763195e9993fbb739b2118a591f5e439a5 | |
parent | d22332dd505b5a269d379863a091d74522fce27b (diff) |
Add a MAX_HOSTNAME_LENGTH constant.
Fixes #946.
-rw-r--r-- | toxcore/tox.api.h | 17 | ||||
-rw-r--r-- | toxcore/tox.h | 19 | ||||
-rw-r--r-- | toxcore/tox_api.c | 1 |
3 files changed, 31 insertions, 6 deletions
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 241441b8..4e20429e 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -307,6 +307,16 @@ const FILE_ID_LENGTH = 32; | |||
307 | */ | 307 | */ |
308 | const MAX_FILENAME_LENGTH = 255; | 308 | const MAX_FILENAME_LENGTH = 255; |
309 | 309 | ||
310 | /** | ||
311 | * Maximum length of a hostname, e.g. proxy or bootstrap node names. | ||
312 | * | ||
313 | * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so | ||
314 | * they are 255 characters plus one NUL byte. | ||
315 | * | ||
316 | * @deprecated The macro will be removed in 0.3.0. Use the function instead. | ||
317 | */ | ||
318 | const MAX_HOSTNAME_LENGTH = 256; | ||
319 | |||
310 | 320 | ||
311 | /******************************************************************************* | 321 | /******************************************************************************* |
312 | * | 322 | * |
@@ -496,8 +506,8 @@ static class options { | |||
496 | * The IP address or DNS name of the proxy to be used. | 506 | * The IP address or DNS name of the proxy to be used. |
497 | * | 507 | * |
498 | * If used, this must be non-NULL and be a valid DNS name. The name must not | 508 | * If used, this must be non-NULL and be a valid DNS name. The name must not |
499 | * exceed 255 characters, and be in a NUL-terminated C string format | 509 | * exceed $MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C string |
500 | * (255 chars + 1 NUL byte). | 510 | * format ($MAX_HOSTNAME_LENGTH includes the NUL byte). |
501 | * | 511 | * |
502 | * This member is ignored (it can be NULL) if proxy_type is ${PROXY_TYPE.NONE}. | 512 | * This member is ignored (it can be NULL) if proxy_type is ${PROXY_TYPE.NONE}. |
503 | * | 513 | * |
@@ -746,7 +756,8 @@ uint8_t[size] savedata { | |||
746 | * This function will attempt to connect to the node using UDP. You must use | 756 | * This function will attempt to connect to the node using UDP. You must use |
747 | * this function even if ${options.this.udp_enabled} was set to false. | 757 | * this function even if ${options.this.udp_enabled} was set to false. |
748 | * | 758 | * |
749 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. | 759 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. Must be |
760 | * at most $MAX_HOSTNAME_LENGTH chars, including the NUL byte. | ||
750 | * @param port The port on the host on which the bootstrap Tox instance is | 761 | * @param port The port on the host on which the bootstrap Tox instance is |
751 | * listening. | 762 | * listening. |
752 | * @param public_key The long term public key of the bootstrap node | 763 | * @param public_key The long term public key of the bootstrap node |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 1b4ce7be..b71e1a02 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -332,6 +332,18 @@ uint32_t tox_file_id_length(void); | |||
332 | 332 | ||
333 | uint32_t tox_max_filename_length(void); | 333 | uint32_t tox_max_filename_length(void); |
334 | 334 | ||
335 | /** | ||
336 | * Maximum length of a hostname, e.g. proxy or bootstrap node names. | ||
337 | * | ||
338 | * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so | ||
339 | * they are 255 characters plus one NUL byte. | ||
340 | * | ||
341 | * @deprecated The macro will be removed in 0.3.0. Use the function instead. | ||
342 | */ | ||
343 | #define TOX_MAX_HOSTNAME_LENGTH 256 | ||
344 | |||
345 | uint32_t tox_max_hostname_length(void); | ||
346 | |||
335 | 347 | ||
336 | /******************************************************************************* | 348 | /******************************************************************************* |
337 | * | 349 | * |
@@ -551,8 +563,8 @@ struct Tox_Options { | |||
551 | * The IP address or DNS name of the proxy to be used. | 563 | * The IP address or DNS name of the proxy to be used. |
552 | * | 564 | * |
553 | * If used, this must be non-NULL and be a valid DNS name. The name must not | 565 | * If used, this must be non-NULL and be a valid DNS name. The name must not |
554 | * exceed 255 characters, and be in a NUL-terminated C string format | 566 | * exceed TOX_MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C string |
555 | * (255 chars + 1 NUL byte). | 567 | * format (TOX_MAX_HOSTNAME_LENGTH includes the NUL byte). |
556 | * | 568 | * |
557 | * This member is ignored (it can be NULL) if proxy_type is TOX_PROXY_TYPE_NONE. | 569 | * This member is ignored (it can be NULL) if proxy_type is TOX_PROXY_TYPE_NONE. |
558 | * | 570 | * |
@@ -913,7 +925,8 @@ typedef enum TOX_ERR_BOOTSTRAP { | |||
913 | * This function will attempt to connect to the node using UDP. You must use | 925 | * This function will attempt to connect to the node using UDP. You must use |
914 | * this function even if Tox_Options.udp_enabled was set to false. | 926 | * this function even if Tox_Options.udp_enabled was set to false. |
915 | * | 927 | * |
916 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. | 928 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. Must be |
929 | * at most TOX_MAX_HOSTNAME_LENGTH chars, including the NUL byte. | ||
917 | * @param port The port on the host on which the bootstrap Tox instance is | 930 | * @param port The port on the host on which the bootstrap Tox instance is |
918 | * listening. | 931 | * listening. |
919 | * @param public_key The long term public key of the bootstrap node | 932 | * @param public_key The long term public key of the bootstrap node |
diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 8fee8c80..31f21158 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c | |||
@@ -29,6 +29,7 @@ CONST_FUNCTION(max_custom_packet_size, MAX_CUSTOM_PACKET_SIZE) | |||
29 | CONST_FUNCTION(hash_length, HASH_LENGTH) | 29 | CONST_FUNCTION(hash_length, HASH_LENGTH) |
30 | CONST_FUNCTION(file_id_length, FILE_ID_LENGTH) | 30 | CONST_FUNCTION(file_id_length, FILE_ID_LENGTH) |
31 | CONST_FUNCTION(max_filename_length, MAX_FILENAME_LENGTH) | 31 | CONST_FUNCTION(max_filename_length, MAX_FILENAME_LENGTH) |
32 | CONST_FUNCTION(max_hostname_length, MAX_HOSTNAME_LENGTH) | ||
32 | 33 | ||
33 | 34 | ||
34 | #define ACCESSORS(type, ns, name) \ | 35 | #define ACCESSORS(type, ns, name) \ |