diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-16 09:26:05 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-16 09:26:05 -0400 |
commit | 2757b254fef9354feff7527d9209232654d58126 (patch) | |
tree | cc6705bbfd49e043dbe5bb6a377a1bf705f45c61 /toxcore | |
parent | 08585e5b60aeaf304701245ea7a1b7e3ce843e57 (diff) | |
parent | fa7c21f95c78eabf3c0f0d247cd7f28ec47eff3d (diff) |
Merge branch 'iphydf-new_api' into new_api
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/tox.c | 22 | ||||
-rw-r--r-- | toxcore/tox.h | 43 |
2 files changed, 35 insertions, 30 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index 54daafc8..da109502 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -135,7 +135,7 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng | |||
135 | break; | 135 | break; |
136 | 136 | ||
137 | default: | 137 | default: |
138 | SET_ERROR_PARAMETER(error, TOX_ERR_PROXY_TYPE); | 138 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE); |
139 | return NULL; | 139 | return NULL; |
140 | } | 140 | } |
141 | 141 | ||
@@ -150,7 +150,7 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng | |||
150 | if (m_options.ipv6enabled) | 150 | if (m_options.ipv6enabled) |
151 | m_options.proxy_info.ip_port.ip.family = AF_UNSPEC; | 151 | m_options.proxy_info.ip_port.ip.family = AF_UNSPEC; |
152 | 152 | ||
153 | if (!addr_resolve_or_parse_ip(options->proxy_address, &m_options.proxy_info.ip_port.ip, NULL)) { | 153 | if (!addr_resolve_or_parse_ip(options->proxy_host, &m_options.proxy_info.ip_port.ip, NULL)) { |
154 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); | 154 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); |
155 | //TODO: TOX_ERR_NEW_PROXY_NOT_FOUND if domain. | 155 | //TODO: TOX_ERR_NEW_PROXY_NOT_FOUND if domain. |
156 | return NULL; | 156 | return NULL; |
@@ -249,7 +249,7 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t * | |||
249 | return ret; | 249 | return ret; |
250 | } else { /* DHT only works on UDP. */ | 250 | } else { /* DHT only works on UDP. */ |
251 | if (DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key) == 0) { | 251 | if (DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key) == 0) { |
252 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_ADDRESS); | 252 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST); |
253 | return 0; | 253 | return 0; |
254 | } | 254 | } |
255 | 255 | ||
@@ -275,7 +275,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8 | |||
275 | } | 275 | } |
276 | 276 | ||
277 | if (address_to_ip(m, address, &ip_port, &ip_port_v4) == -1) { | 277 | if (address_to_ip(m, address, &ip_port, &ip_port_v4) == -1) { |
278 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_ADDRESS); | 278 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST); |
279 | return 0; | 279 | return 0; |
280 | } | 280 | } |
281 | 281 | ||
@@ -350,12 +350,12 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) | |||
350 | memcpy(public_key, m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES); | 350 | memcpy(public_key, m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES); |
351 | } | 351 | } |
352 | 352 | ||
353 | void tox_self_get_private_key(const Tox *tox, uint8_t *private_key) | 353 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) |
354 | { | 354 | { |
355 | const Messenger *m = tox; | 355 | const Messenger *m = tox; |
356 | 356 | ||
357 | if (private_key) | 357 | if (secret_key) |
358 | memcpy(private_key, m->net_crypto->self_secret_key, crypto_box_SECRETKEYBYTES); | 358 | memcpy(secret_key, m->net_crypto->self_secret_key, crypto_box_SECRETKEYBYTES); |
359 | } | 359 | } |
360 | 360 | ||
361 | bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET_INFO *error) | 361 | bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET_INFO *error) |
@@ -567,18 +567,18 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number) | |||
567 | return m_friend_exists(m, friend_number); | 567 | return m_friend_exists(m, friend_number); |
568 | } | 568 | } |
569 | 569 | ||
570 | size_t tox_friend_list_size(const Tox *tox) | 570 | size_t tox_self_get_friend_list_size(const Tox *tox) |
571 | { | 571 | { |
572 | const Messenger *m = tox; | 572 | const Messenger *m = tox; |
573 | return count_friendlist(m); | 573 | return count_friendlist(m); |
574 | } | 574 | } |
575 | 575 | ||
576 | void tox_friend_get_list(const Tox *tox, uint32_t *list) | 576 | void tox_self_get_friend_list(const Tox *tox, uint32_t *list) |
577 | { | 577 | { |
578 | if (list) { | 578 | if (list) { |
579 | const Messenger *m = tox; | 579 | const Messenger *m = tox; |
580 | //TODO: size parameter? | 580 | //TODO: size parameter? |
581 | copy_friendlist(m, list, tox_friend_list_size(tox)); | 581 | copy_friendlist(m, list, tox_self_get_friend_list_size(tox)); |
582 | } | 582 | } |
583 | } | 583 | } |
584 | 584 | ||
@@ -965,7 +965,7 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
965 | return 0; | 965 | return 0; |
966 | 966 | ||
967 | case -6: | 967 | case -6: |
968 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_CHUNK_QUEUE_FULL); | 968 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_CHUNK_SENDQ); |
969 | return 0; | 969 | return 0; |
970 | 970 | ||
971 | case -7: | 971 | case -7: |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 1457a70b..f1b8b893 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -211,6 +211,11 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); | |||
211 | #define TOX_PUBLIC_KEY_SIZE 32 | 211 | #define TOX_PUBLIC_KEY_SIZE 32 |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * The size of a Tox Secret Key in bytes. | ||
215 | */ | ||
216 | #define TOX_SECRET_KEY_SIZE 32 | ||
217 | |||
218 | /** | ||
214 | * The size of a Tox address in bytes. Tox addresses are in the format | 219 | * The size of a Tox address in bytes. Tox addresses are in the format |
215 | * [Public Key (TOX_PUBLIC_KEY_SIZE bytes)][nospam (4 bytes)][checksum (2 bytes)]. | 220 | * [Public Key (TOX_PUBLIC_KEY_SIZE bytes)][nospam (4 bytes)][checksum (2 bytes)]. |
216 | * | 221 | * |
@@ -344,7 +349,7 @@ struct Tox_Options { | |||
344 | * | 349 | * |
345 | * This member is ignored (it can be NULL) if proxy_enabled is false. | 350 | * This member is ignored (it can be NULL) if proxy_enabled is false. |
346 | */ | 351 | */ |
347 | char *proxy_address; | 352 | const char *proxy_host; |
348 | 353 | ||
349 | /** | 354 | /** |
350 | * The port to use to connect to the proxy server. | 355 | * The port to use to connect to the proxy server. |
@@ -443,9 +448,9 @@ typedef enum TOX_ERR_NEW { | |||
443 | /** | 448 | /** |
444 | * proxy_type was invalid. | 449 | * proxy_type was invalid. |
445 | */ | 450 | */ |
446 | TOX_ERR_PROXY_TYPE, | 451 | TOX_ERR_NEW_PROXY_BAD_TYPE, |
447 | /** | 452 | /** |
448 | * proxy_type was valid but the proxy_address passed had an invalid format | 453 | * proxy_type was valid but the proxy_host passed had an invalid format |
449 | * or was NULL. | 454 | * or was NULL. |
450 | */ | 455 | */ |
451 | TOX_ERR_NEW_PROXY_BAD_HOST, | 456 | TOX_ERR_NEW_PROXY_BAD_HOST, |
@@ -454,7 +459,7 @@ typedef enum TOX_ERR_NEW { | |||
454 | */ | 459 | */ |
455 | TOX_ERR_NEW_PROXY_BAD_PORT, | 460 | TOX_ERR_NEW_PROXY_BAD_PORT, |
456 | /** | 461 | /** |
457 | * The proxy address passed could not be resolved. | 462 | * The proxy host passed could not be resolved. |
458 | */ | 463 | */ |
459 | TOX_ERR_NEW_PROXY_NOT_FOUND, | 464 | TOX_ERR_NEW_PROXY_NOT_FOUND, |
460 | /** | 465 | /** |
@@ -542,10 +547,10 @@ typedef enum TOX_ERR_BOOTSTRAP { | |||
542 | TOX_ERR_BOOTSTRAP_OK, | 547 | TOX_ERR_BOOTSTRAP_OK, |
543 | TOX_ERR_BOOTSTRAP_NULL, | 548 | TOX_ERR_BOOTSTRAP_NULL, |
544 | /** | 549 | /** |
545 | * The address could not be resolved to an IP address, or the IP address | 550 | * The host could not be resolved to an IP address, or the IP address |
546 | * passed was invalid. | 551 | * passed was invalid. |
547 | */ | 552 | */ |
548 | TOX_ERR_BOOTSTRAP_BAD_ADDRESS, | 553 | TOX_ERR_BOOTSTRAP_BAD_HOST, |
549 | /** | 554 | /** |
550 | * The port passed was invalid. The valid port range is (1, 65535). | 555 | * The port passed was invalid. The valid port range is (1, 65535). |
551 | */ | 556 | */ |
@@ -564,14 +569,14 @@ typedef enum TOX_ERR_BOOTSTRAP { | |||
564 | * also use the TCP connection when NAT hole punching is slow, and later switch | 569 | * also use the TCP connection when NAT hole punching is slow, and later switch |
565 | * to UDP if hole punching succeeds. | 570 | * to UDP if hole punching succeeds. |
566 | * | 571 | * |
567 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. | 572 | * @param host The hostname or IP address (IPv4 or IPv6) of the node. |
568 | * @param port The port on the host on which the bootstrap Tox instance is | 573 | * @param port The port on the host on which the bootstrap Tox instance is |
569 | * listening. | 574 | * listening. |
570 | * @param public_key The long term public key of the bootstrap node | 575 | * @param public_key The long term public key of the bootstrap node |
571 | * (TOX_PUBLIC_KEY_SIZE bytes). | 576 | * (TOX_PUBLIC_KEY_SIZE bytes). |
572 | * @return true on success. | 577 | * @return true on success. |
573 | */ | 578 | */ |
574 | bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key, TOX_ERR_BOOTSTRAP *error); | 579 | bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, TOX_ERR_BOOTSTRAP *error); |
575 | 580 | ||
576 | 581 | ||
577 | /** | 582 | /** |
@@ -581,13 +586,13 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t * | |||
581 | * the same bootstrap node, or to add TCP relays without using them as | 586 | * the same bootstrap node, or to add TCP relays without using them as |
582 | * bootstrap nodes. | 587 | * bootstrap nodes. |
583 | * | 588 | * |
584 | * @param address The hostname or IP address (IPv4 or IPv6) of the TCP relay. | 589 | * @param host The hostname or IP address (IPv4 or IPv6) of the TCP relay. |
585 | * @param port The port on the host on which the TCP relay is listening. | 590 | * @param port The port on the host on which the TCP relay is listening. |
586 | * @param public_key The long term public key of the TCP relay | 591 | * @param public_key The long term public key of the TCP relay |
587 | * (TOX_PUBLIC_KEY_SIZE bytes). | 592 | * (TOX_PUBLIC_KEY_SIZE bytes). |
588 | * @return true on success. | 593 | * @return true on success. |
589 | */ | 594 | */ |
590 | bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key, | 595 | bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, |
591 | TOX_ERR_BOOTSTRAP *error); | 596 | TOX_ERR_BOOTSTRAP *error); |
592 | 597 | ||
593 | 598 | ||
@@ -697,7 +702,7 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key); | |||
697 | /** | 702 | /** |
698 | * Copy the secret key from the Tox object. | 703 | * Copy the secret key from the Tox object. |
699 | * | 704 | * |
700 | * @param secret_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If | 705 | * @param secret_key A memory region of at least TOX_SECRET_KEY_SIZE bytes. If |
701 | * this parameter is NULL, this function has no effect. | 706 | * this parameter is NULL, this function has no effect. |
702 | */ | 707 | */ |
703 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key); | 708 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key); |
@@ -978,20 +983,20 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number); | |||
978 | * Return the number of friends on the friend list. | 983 | * Return the number of friends on the friend list. |
979 | * | 984 | * |
980 | * This function can be used to determine how much memory to allocate for | 985 | * This function can be used to determine how much memory to allocate for |
981 | * tox_friend_list. | 986 | * tox_self_get_friend_list. |
982 | */ | 987 | */ |
983 | size_t tox_friend_list_size(const Tox *tox); | 988 | size_t tox_self_get_friend_list_size(const Tox *tox); |
984 | 989 | ||
985 | 990 | ||
986 | /** | 991 | /** |
987 | * Copy a list of valid friend numbers into an array. | 992 | * Copy a list of valid friend numbers into an array. |
988 | * | 993 | * |
989 | * Call tox_friend_list_size to determine the number of elements to allocate. | 994 | * Call tox_self_get_friend_list_size to determine the number of elements to allocate. |
990 | * | 995 | * |
991 | * @param list A memory region with enough space to hold the friend list. If | 996 | * @param list A memory region with enough space to hold the friend list. If |
992 | * this parameter is NULL, this function has no effect. | 997 | * this parameter is NULL, this function has no effect. |
993 | */ | 998 | */ |
994 | void tox_friend_get_list(const Tox *tox, uint32_t *list); | 999 | void tox_self_get_friend_list(const Tox *tox, uint32_t *list); |
995 | 1000 | ||
996 | 1001 | ||
997 | 1002 | ||
@@ -1096,7 +1101,7 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 | |||
1096 | * tox_friend_get_status_message_size. | 1101 | * tox_friend_get_status_message_size. |
1097 | */ | 1102 | */ |
1098 | typedef void tox_friend_status_message_cb(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, | 1103 | typedef void tox_friend_status_message_cb(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, |
1099 | void *user_data); | 1104 | void *user_data); |
1100 | 1105 | ||
1101 | /** | 1106 | /** |
1102 | * Set the callback for the `friend_status_message` event. Pass NULL to unset. | 1107 | * Set the callback for the `friend_status_message` event. Pass NULL to unset. |
@@ -1155,7 +1160,7 @@ TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_ | |||
1155 | * tox_friend_get_connection_status on the passed friend_number. | 1160 | * tox_friend_get_connection_status on the passed friend_number. |
1156 | */ | 1161 | */ |
1157 | typedef void tox_friend_connection_status_cb(Tox *tox, uint32_t friend_number, TOX_CONNECTION connection_status, | 1162 | typedef void tox_friend_connection_status_cb(Tox *tox, uint32_t friend_number, TOX_CONNECTION connection_status, |
1158 | void *user_data); | 1163 | void *user_data); |
1159 | 1164 | ||
1160 | /** | 1165 | /** |
1161 | * Set the callback for the `friend_connection_status` event. Pass NULL to | 1166 | * Set the callback for the `friend_connection_status` event. Pass NULL to |
@@ -1655,7 +1660,7 @@ typedef enum TOX_ERR_FILE_SEND_CHUNK { | |||
1655 | /** | 1660 | /** |
1656 | * Packet queue is full. | 1661 | * Packet queue is full. |
1657 | */ | 1662 | */ |
1658 | TOX_ERR_FILE_SEND_CHUNK_QUEUE_FULL, | 1663 | TOX_ERR_FILE_SEND_CHUNK_SENDQ, |
1659 | /** | 1664 | /** |
1660 | * Position parameter was wrong. | 1665 | * Position parameter was wrong. |
1661 | */ | 1666 | */ |
@@ -1893,7 +1898,7 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin | |||
1893 | * @param length The length of the packet data byte array. | 1898 | * @param length The length of the packet data byte array. |
1894 | */ | 1899 | */ |
1895 | typedef void tox_friend_lossless_packet_cb(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, | 1900 | typedef void tox_friend_lossless_packet_cb(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, |
1896 | void *user_data); | 1901 | void *user_data); |
1897 | 1902 | ||
1898 | /** | 1903 | /** |
1899 | * Set the callback for the `friend_lossless_packet` event. Pass NULL to unset. | 1904 | * Set the callback for the `friend_lossless_packet` event. Pass NULL to unset. |