diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/tox.api.h | 36 | ||||
-rw-r--r-- | toxcore/tox.c | 45 | ||||
-rw-r--r-- | toxcore/tox.h | 52 |
3 files changed, 125 insertions, 8 deletions
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 97a85312..6cb3145b 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -245,10 +245,17 @@ const SECRET_KEY_SIZE = 32; | |||
245 | 245 | ||
246 | /** | 246 | /** |
247 | * The size of a Tox Conference unique id in bytes. | 247 | * The size of a Tox Conference unique id in bytes. |
248 | * | ||
249 | * @deprecated Use $CONFERENCE_ID_SIZE instead. | ||
248 | */ | 250 | */ |
249 | const CONFERENCE_UID_SIZE = 32; | 251 | const CONFERENCE_UID_SIZE = 32; |
250 | 252 | ||
251 | /** | 253 | /** |
254 | * The size of a Tox Conference unique id in bytes. | ||
255 | */ | ||
256 | const CONFERENCE_ID_SIZE = 32; | ||
257 | |||
258 | /** | ||
252 | * The size of the nospam in bytes when written in a Tox address. | 259 | * The size of the nospam in bytes when written in a Tox address. |
253 | */ | 260 | */ |
254 | const NOSPAM_SIZE = sizeof(uint32_t); | 261 | const NOSPAM_SIZE = sizeof(uint32_t); |
@@ -2464,11 +2471,38 @@ namespace conference { | |||
2464 | /** | 2471 | /** |
2465 | * Get the conference unique ID. | 2472 | * Get the conference unique ID. |
2466 | * | 2473 | * |
2474 | * If id is NULL, this function has no effect. | ||
2475 | * | ||
2476 | * @param id A memory region large enough to store $CONFERENCE_ID_SIZE bytes. | ||
2477 | * | ||
2478 | * @return true on success. | ||
2479 | */ | ||
2480 | const bool get_id(uint32_t conference_number, uint8_t[CONFERENCE_ID_SIZE] id); | ||
2481 | |||
2482 | /** | ||
2483 | * Return the conference number associated with the specified id. | ||
2484 | * | ||
2485 | * @param id A byte array containing the conference id ($CONFERENCE_ID_SIZE). | ||
2486 | * | ||
2487 | * @return the conference number on success, an unspecified value on failure. | ||
2488 | */ | ||
2489 | const uint32_t by_id(const uint8_t[CONFERENCE_ID_SIZE] id) { | ||
2490 | NULL, | ||
2491 | /** | ||
2492 | * No conference with the given id exists on the conference list. | ||
2493 | */ | ||
2494 | NOT_FOUND, | ||
2495 | } | ||
2496 | |||
2497 | /** | ||
2498 | * Get the conference unique ID. | ||
2499 | * | ||
2467 | * If uid is NULL, this function has no effect. | 2500 | * If uid is NULL, this function has no effect. |
2468 | * | 2501 | * |
2469 | * @param uid A memory region large enough to store $CONFERENCE_UID_SIZE bytes. | 2502 | * @param uid A memory region large enough to store $CONFERENCE_UID_SIZE bytes. |
2470 | * | 2503 | * |
2471 | * @return true on success. | 2504 | * @return true on success. |
2505 | * @deprecated use $get_id instead (exactly the same function, just renamed). | ||
2472 | */ | 2506 | */ |
2473 | const bool get_uid(uint32_t conference_number, uint8_t[CONFERENCE_UID_SIZE] uid); | 2507 | const bool get_uid(uint32_t conference_number, uint8_t[CONFERENCE_UID_SIZE] uid); |
2474 | 2508 | ||
@@ -2478,6 +2512,7 @@ namespace conference { | |||
2478 | * @param uid A byte array containing the conference id ($CONFERENCE_UID_SIZE). | 2512 | * @param uid A byte array containing the conference id ($CONFERENCE_UID_SIZE). |
2479 | * | 2513 | * |
2480 | * @return the conference number on success, an unspecified value on failure. | 2514 | * @return the conference number on success, an unspecified value on failure. |
2515 | * @deprecated use $by_id instead (exactly the same function, just renamed). | ||
2481 | */ | 2516 | */ |
2482 | const uint32_t by_uid(const uint8_t[CONFERENCE_UID_SIZE] uid) { | 2517 | const uint32_t by_uid(const uint8_t[CONFERENCE_UID_SIZE] uid) { |
2483 | NULL, | 2518 | NULL, |
@@ -2678,6 +2713,7 @@ typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk; | |||
2678 | typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New; | 2713 | typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New; |
2679 | typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete; | 2714 | typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete; |
2680 | typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query; | 2715 | typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query; |
2716 | typedef TOX_ERR_CONFERENCE_BY_ID Tox_Err_Conference_By_Id; | ||
2681 | typedef TOX_ERR_CONFERENCE_BY_UID Tox_Err_Conference_By_Uid; | 2717 | typedef TOX_ERR_CONFERENCE_BY_UID Tox_Err_Conference_By_Uid; |
2682 | typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite; | 2718 | typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite; |
2683 | typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join; | 2719 | typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index cdccbe45..101494cc 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -1457,31 +1457,60 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_ | |||
1457 | return (Tox_Conference_Type)ret; | 1457 | return (Tox_Conference_Type)ret; |
1458 | } | 1458 | } |
1459 | 1459 | ||
1460 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid /* TOX_CONFERENCE_ID_SIZE bytes */) | 1460 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id /* TOX_CONFERENCE_ID_SIZE bytes */) |
1461 | { | 1461 | { |
1462 | const Messenger *m = tox; | 1462 | const Messenger *m = tox; |
1463 | return conference_get_uid((Group_Chats *)m->conferences_object, conference_number, uid); | 1463 | return conference_get_uid((Group_Chats *)m->conferences_object, conference_number, id); |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) | 1466 | // TODO(iphydf): Delete in 0.3.0. |
1467 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid /* TOX_CONFERENCE_ID_SIZE bytes */) | ||
1467 | { | 1468 | { |
1468 | if (!uid) { | 1469 | return tox_conference_get_id(tox, conference_number, uid); |
1469 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_NULL); | 1470 | } |
1471 | |||
1472 | uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error) | ||
1473 | { | ||
1474 | if (!id) { | ||
1475 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL); | ||
1470 | return UINT32_MAX; | 1476 | return UINT32_MAX; |
1471 | } | 1477 | } |
1472 | 1478 | ||
1473 | const Messenger *m = tox; | 1479 | const Messenger *m = tox; |
1474 | int32_t ret = conference_by_uid((Group_Chats *)m->conferences_object, uid); | 1480 | int32_t ret = conference_by_uid((Group_Chats *)m->conferences_object, id); |
1475 | 1481 | ||
1476 | if (ret == -1) { | 1482 | if (ret == -1) { |
1477 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_NOT_FOUND); | 1483 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND); |
1478 | return UINT32_MAX; | 1484 | return UINT32_MAX; |
1479 | } | 1485 | } |
1480 | 1486 | ||
1481 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_OK); | 1487 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_OK); |
1482 | return ret; | 1488 | return ret; |
1483 | } | 1489 | } |
1484 | 1490 | ||
1491 | // TODO(iphydf): Delete in 0.3.0. | ||
1492 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) | ||
1493 | { | ||
1494 | Tox_Err_Conference_By_Id id_error; | ||
1495 | const uint32_t res = tox_conference_by_id(tox, uid, &id_error); | ||
1496 | |||
1497 | switch (id_error) { | ||
1498 | case TOX_ERR_CONFERENCE_BY_ID_OK: | ||
1499 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_OK); | ||
1500 | break; | ||
1501 | |||
1502 | case TOX_ERR_CONFERENCE_BY_ID_NULL: | ||
1503 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_NULL); | ||
1504 | break; | ||
1505 | |||
1506 | case TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND: | ||
1507 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_UID_NOT_FOUND); | ||
1508 | break; | ||
1509 | } | ||
1510 | |||
1511 | return res; | ||
1512 | } | ||
1513 | |||
1485 | static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error) | 1514 | static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error) |
1486 | { | 1515 | { |
1487 | switch (ret) { | 1516 | switch (ret) { |
diff --git a/toxcore/tox.h b/toxcore/tox.h index f8279afe..4c83ca23 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -250,12 +250,21 @@ uint32_t tox_secret_key_size(void); | |||
250 | 250 | ||
251 | /** | 251 | /** |
252 | * The size of a Tox Conference unique id in bytes. | 252 | * The size of a Tox Conference unique id in bytes. |
253 | * | ||
254 | * @deprecated Use TOX_CONFERENCE_ID_SIZE instead. | ||
253 | */ | 255 | */ |
254 | #define TOX_CONFERENCE_UID_SIZE 32 | 256 | #define TOX_CONFERENCE_UID_SIZE 32 |
255 | 257 | ||
256 | uint32_t tox_conference_uid_size(void); | 258 | uint32_t tox_conference_uid_size(void); |
257 | 259 | ||
258 | /** | 260 | /** |
261 | * The size of a Tox Conference unique id in bytes. | ||
262 | */ | ||
263 | #define TOX_CONFERENCE_ID_SIZE 32 | ||
264 | |||
265 | uint32_t tox_conference_id_size(void); | ||
266 | |||
267 | /** | ||
259 | * The size of the nospam in bytes when written in a Tox address. | 268 | * The size of the nospam in bytes when written in a Tox address. |
260 | */ | 269 | */ |
261 | #define TOX_NOSPAM_SIZE (sizeof(uint32_t)) | 270 | #define TOX_NOSPAM_SIZE (sizeof(uint32_t)) |
@@ -2817,11 +2826,52 @@ TOX_CONFERENCE_TYPE tox_conference_get_type(const Tox *tox, uint32_t conference_ | |||
2817 | /** | 2826 | /** |
2818 | * Get the conference unique ID. | 2827 | * Get the conference unique ID. |
2819 | * | 2828 | * |
2829 | * If id is NULL, this function has no effect. | ||
2830 | * | ||
2831 | * @param id A memory region large enough to store TOX_CONFERENCE_ID_SIZE bytes. | ||
2832 | * | ||
2833 | * @return true on success. | ||
2834 | */ | ||
2835 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id); | ||
2836 | |||
2837 | typedef enum TOX_ERR_CONFERENCE_BY_ID { | ||
2838 | |||
2839 | /** | ||
2840 | * The function returned successfully. | ||
2841 | */ | ||
2842 | TOX_ERR_CONFERENCE_BY_ID_OK, | ||
2843 | |||
2844 | /** | ||
2845 | * One of the arguments to the function was NULL when it was not expected. | ||
2846 | */ | ||
2847 | TOX_ERR_CONFERENCE_BY_ID_NULL, | ||
2848 | |||
2849 | /** | ||
2850 | * No conference with the given id exists on the conference list. | ||
2851 | */ | ||
2852 | TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND, | ||
2853 | |||
2854 | } TOX_ERR_CONFERENCE_BY_ID; | ||
2855 | |||
2856 | |||
2857 | /** | ||
2858 | * Return the conference number associated with the specified id. | ||
2859 | * | ||
2860 | * @param id A byte array containing the conference id (TOX_CONFERENCE_ID_SIZE). | ||
2861 | * | ||
2862 | * @return the conference number on success, an unspecified value on failure. | ||
2863 | */ | ||
2864 | uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, TOX_ERR_CONFERENCE_BY_ID *error); | ||
2865 | |||
2866 | /** | ||
2867 | * Get the conference unique ID. | ||
2868 | * | ||
2820 | * If uid is NULL, this function has no effect. | 2869 | * If uid is NULL, this function has no effect. |
2821 | * | 2870 | * |
2822 | * @param uid A memory region large enough to store TOX_CONFERENCE_UID_SIZE bytes. | 2871 | * @param uid A memory region large enough to store TOX_CONFERENCE_UID_SIZE bytes. |
2823 | * | 2872 | * |
2824 | * @return true on success. | 2873 | * @return true on success. |
2874 | * @deprecated use tox_conference_get_id instead (exactly the same function, just renamed). | ||
2825 | */ | 2875 | */ |
2826 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid); | 2876 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid); |
2827 | 2877 | ||
@@ -2851,6 +2901,7 @@ typedef enum TOX_ERR_CONFERENCE_BY_UID { | |||
2851 | * @param uid A byte array containing the conference id (TOX_CONFERENCE_UID_SIZE). | 2901 | * @param uid A byte array containing the conference id (TOX_CONFERENCE_UID_SIZE). |
2852 | * | 2902 | * |
2853 | * @return the conference number on success, an unspecified value on failure. | 2903 | * @return the conference number on success, an unspecified value on failure. |
2904 | * @deprecated use tox_conference_by_id instead (exactly the same function, just renamed). | ||
2854 | */ | 2905 | */ |
2855 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, TOX_ERR_CONFERENCE_BY_UID *error); | 2906 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, TOX_ERR_CONFERENCE_BY_UID *error); |
2856 | 2907 | ||
@@ -3054,6 +3105,7 @@ typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk; | |||
3054 | typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New; | 3105 | typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New; |
3055 | typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete; | 3106 | typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete; |
3056 | typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query; | 3107 | typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query; |
3108 | typedef TOX_ERR_CONFERENCE_BY_ID Tox_Err_Conference_By_Id; | ||
3057 | typedef TOX_ERR_CONFERENCE_BY_UID Tox_Err_Conference_By_Uid; | 3109 | typedef TOX_ERR_CONFERENCE_BY_UID Tox_Err_Conference_By_Uid; |
3058 | typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite; | 3110 | typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite; |
3059 | typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join; | 3111 | typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join; |