From 8e80ced6cea5c50e628c1931f6b3b764b97efb41 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 22 May 2015 18:23:56 -0400 Subject: Move savedata to options struct. Add a way to select the type of savedata (normal savedata, load a secret key, potentially others?) to load. --- other/apidsl/tox.in.h | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'other/apidsl') diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index dd47df23..b769135a 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -340,6 +340,24 @@ enum class PROXY_TYPE { SOCKS5, } +/** + * Type of savedata to create the Tox instance from. + */ +enum class SAVEDATA_TYPE { + /** + * No savedata. + */ + NONE, + /** + * Savedata is one that was obtained from ${savedata.get} + */ + TOX_SAVE, + /** + * Savedata is a secret key of length ${SECRET_KEY_SIZE} + */ + SECRET_KEY, +} + static class options { /** @@ -416,6 +434,23 @@ static class options { * The port to use for the TCP server. If 0, the tcp server is disabled. */ uint16_t tcp_port; + + namespace savedata { + /** + * The type of savedata to load from. + */ + SAVEDATA_TYPE type; + + /** + * The savedata. + */ + const uint8_t[length] data; + + /** + * The length of the savedata. + */ + size_t length; + } } @@ -474,21 +509,15 @@ static class options { * This function will bring the instance into a valid state. Running the event * loop with a new instance will operate correctly. * - * If the data parameter is not NULL, this function will load the Tox instance - * from a byte array previously filled by ${savedata.get}. - * * If loading failed or succeeded only partially, the new or partially loaded * instance is returned and an error code is set. * * @param options An options object as described above. If this parameter is * NULL, the default options are used. - * @param data A byte array containing data previously stored by ${savedata.get}. - * @param length The length of the byte array data. If this parameter is 0, the - * data parameter is ignored. * * @see $iterate for the event loop. */ -static this new(const options_t *options, const uint8_t[length] data) { +static this new(const options_t *options) { NULL, /** * The function was unable to allocate enough memory to store the internal -- cgit v1.2.3 From 441e0073625b7ae9c69e977f510a8295e388a198 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 25 May 2015 15:20:38 -0400 Subject: tox_new returns NULL on failure. --- other/apidsl/tox.in.h | 2 ++ toxcore/tox.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'other/apidsl') diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index b769135a..5b371c17 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -516,6 +516,8 @@ static class options { * NULL, the default options are used. * * @see $iterate for the event loop. + * + * @return A new Tox instance pointer on success or NULL on failure. */ static this new(const options_t *options) { NULL, diff --git a/toxcore/tox.h b/toxcore/tox.h index b556d138..038a366f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -609,6 +609,8 @@ typedef enum TOX_ERR_NEW { * NULL, the default options are used. * * @see tox_iterate for the event loop. + * + * @return A new Tox instance pointer on success or NULL on failure. */ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error); -- cgit v1.2.3 From 29c37bf2f4f7870e932ea5bf2f9f23a23f3b7cc1 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 28 May 2015 11:37:24 -0400 Subject: Fixed comment. --- other/apidsl/tox.in.h | 2 +- toxcore/tox.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'other/apidsl') diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index 5b371c17..87d0ab87 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -1512,7 +1512,7 @@ namespace file { */ DATA, /** - * Avatar filename. This consists of $hash(image). + * Avatar file_id. This consists of $hash(image). * Avatar data. This consists of the image data. * * Avatars can be sent at any time the client wishes. Generally, a client will diff --git a/toxcore/tox.h b/toxcore/tox.h index 038a366f..cf5491af 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1596,7 +1596,7 @@ enum TOX_FILE_KIND { TOX_FILE_KIND_DATA, /** - * Avatar filename. This consists of tox_hash(image). + * Avatar file_id. This consists of tox_hash(image). * Avatar data. This consists of the image data. * * Avatars can be sent at any time the client wishes. Generally, a client will -- cgit v1.2.3 From 5ea703c844b12e86702c35b53b0b798fe5f86634 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 29 May 2015 19:01:14 -0400 Subject: Comment fix. --- other/apidsl/tox.in.h | 9 ++------- toxcore/tox.h | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'other/apidsl') diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index 87d0ab87..fc66dfac 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -611,13 +611,8 @@ uint8_t[size] savedata { * Sends a "get nodes" request to the given bootstrap node with IP, port, and * public key to setup connections. * - * This function will attempt to connect to the node using UDP and TCP at the - * same time. - * - * Tox will use the node as a TCP relay in case ${options.this.udp_enabled} was - * false, and also to connect to friends that are in TCP-only mode. Tox will - * also use the TCP connection when NAT hole punching is slow, and later switch - * to UDP if hole punching succeeds. + * This function will attempt to connect to the node using UDP. You must use + * this function even if ${options.this.udp_enabled} was set to false. * * @param address The hostname or IP address (IPv4 or IPv6) of the node. * @param port The port on the host on which the bootstrap Tox instance is diff --git a/toxcore/tox.h b/toxcore/tox.h index cf5491af..e5158915 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -679,13 +679,8 @@ typedef enum TOX_ERR_BOOTSTRAP { * Sends a "get nodes" request to the given bootstrap node with IP, port, and * public key to setup connections. * - * This function will attempt to connect to the node using UDP and TCP at the - * same time. - * - * Tox will use the node as a TCP relay in case Tox_Options.udp_enabled was - * false, and also to connect to friends that are in TCP-only mode. Tox will - * also use the TCP connection when NAT hole punching is slow, and later switch - * to UDP if hole punching succeeds. + * This function will attempt to connect to the node using UDP. You must use + * this function even if Tox_Options.udp_enabled was set to false. * * @param address The hostname or IP address (IPv4 or IPv6) of the node. * @param port The port on the host on which the bootstrap Tox instance is -- cgit v1.2.3 From 6d883f488ff59b2394982b62895d50b1d1d55bf4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 3 Jun 2015 19:56:12 -0400 Subject: Return error if file_id parameter is NULL. --- other/apidsl/tox.in.h | 1 + toxcore/tox.c | 5 +++++ toxcore/tox.h | 5 +++++ 3 files changed, 11 insertions(+) (limited to 'other/apidsl') diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index fc66dfac..30c78e44 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -1651,6 +1651,7 @@ namespace file { error for get { + NULL, /** * The friend_number passed did not designate a valid friend. */ diff --git a/toxcore/tox.c b/toxcore/tox.c index d3b021aa..3e9db766 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -1011,6 +1011,11 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, TOX_ERR_FILE_GET *error) { + if (!file_id) { + SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); + return 0; + } + const Messenger *m = tox; int ret = file_get_id(m, friend_number, file_number, file_id); diff --git a/toxcore/tox.h b/toxcore/tox.h index e5158915..14c9f616 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1780,6 +1780,11 @@ typedef enum TOX_ERR_FILE_GET { */ TOX_ERR_FILE_GET_OK, + /** + * One of the arguments to the function was NULL when it was not expected. + */ + TOX_ERR_FILE_GET_NULL, + /** * The friend_number passed did not designate a valid friend. */ -- cgit v1.2.3