summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/Avatars.md4
-rw-r--r--testing/test_avatars.c48
2 files changed, 26 insertions, 26 deletions
diff --git a/docs/Avatars.md b/docs/Avatars.md
index 1dcbba96..a24c1f7c 100644
--- a/docs/Avatars.md
+++ b/docs/Avatars.md
@@ -244,7 +244,7 @@ already downloaded by other clients can be reused.
244Given the Tox data directory described in STS Draft v0.1.0: 244Given the Tox data directory described in STS Draft v0.1.0:
245 245
246 - Avatars are stored in a directory called "avatars" and named 246 - Avatars are stored in a directory called "avatars" and named
247 as "xxxxx.png", where "xxxxx" is the complete client id (but not friend 247 as "xxxxx.png", where "xxxxx" is the complete public key (but not friend
248 address!) encoded as an uppercase hexadecimal string and "png" is the 248 address!) encoded as an uppercase hexadecimal string and "png" is the
249 extension for the PNG avatar. As new image formats may be used in the 249 extension for the PNG avatar. As new image formats may be used in the
250 future, clients should ensure no other file "xxxxx.*" exists. No file 250 future, clients should ensure no other file "xxxxx.*" exists. No file
@@ -408,7 +408,7 @@ calls:
408 408
409In the previous examples, implementation of the functions to check, store 409In the previous examples, implementation of the functions to check, store
410and retrieve data from the cache were omitted for brevity. These functions 410and retrieve data from the cache were omitted for brevity. These functions
411will also need to get the friend client ID (public key) from they friend 411will also need to get the friend public key (client id) from they friend
412number and, usually, convert it from a byte string to a hexadecimal 412number and, usually, convert it from a byte string to a hexadecimal
413string. A complete, yet more complex, example is available in the file 413string. A complete, yet more complex, example is available in the file
414`testing/test_avatars.c`. 414`testing/test_avatars.c`.
diff --git a/testing/test_avatars.c b/testing/test_avatars.c
index 71a0330e..fabef2c3 100644
--- a/testing/test_avatars.c
+++ b/testing/test_avatars.c
@@ -18,7 +18,7 @@
18 * Data dir MAY have: 18 * Data dir MAY have:
19 * 19 *
20 * - A directory named "avatars" with the user's avatar and cached avatars. 20 * - A directory named "avatars" with the user's avatar and cached avatars.
21 * The user avatar must be named in the format: "<uppercase user id>.png" 21 * The user avatar must be named in the format: "<uppercase pub key>.png"
22 * 22 *
23 * 23 *
24 * The bot will answer to these commands: 24 * The bot will answer to these commands:
@@ -164,13 +164,13 @@ static void byte_to_hex_str(const uint8_t *buf, const size_t buflen, char *dst)
164} 164}
165 165
166/* Make the cache file name for a avatar of the given format for the given 166/* Make the cache file name for a avatar of the given format for the given
167 * client id. 167 * public key.
168 */ 168 */
169static int make_avatar_file_name(char *dst, size_t dst_len, const char *base_dir, 169static int make_avatar_file_name(char *dst, size_t dst_len, const char *base_dir,
170 const uint8_t format, uint8_t *client_id) 170 const uint8_t format, uint8_t *public_key)
171{ 171{
172 char client_id_str[2 * TOX_CLIENT_ID_SIZE + 1]; 172 char public_key_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
173 byte_to_hex_str(client_id, TOX_CLIENT_ID_SIZE, client_id_str); 173 byte_to_hex_str(public_key, TOX_PUBLIC_KEY_SIZE, public_key_str);
174 174
175 const char *suffix = get_avatar_suffix_from_format(format); 175 const char *suffix = get_avatar_suffix_from_format(format);
176 176
@@ -178,7 +178,7 @@ static int make_avatar_file_name(char *dst, size_t dst_len, const char *base_dir
178 return -1; /* Error */ 178 return -1; /* Error */
179 179
180 int n = snprintf(dst, dst_len, "%s/%s/%s.%s", base_dir, AVATAR_DIR_NAME, 180 int n = snprintf(dst, dst_len, "%s/%s/%s.%s", base_dir, AVATAR_DIR_NAME,
181 client_id_str, suffix); 181 public_key_str, suffix);
182 dst[dst_len - 1] = '\0'; 182 dst[dst_len - 1] = '\0';
183 183
184 if (n >= dst_len) 184 if (n >= dst_len)
@@ -196,7 +196,7 @@ static int make_avatar_file_name(char *dst, size_t dst_len, const char *base_dir
196static int load_user_avatar(Tox *tox, char *base_dir, int friendnum, 196static int load_user_avatar(Tox *tox, char *base_dir, int friendnum,
197 uint8_t format, uint8_t *hash, uint8_t *data, uint32_t *datalen) 197 uint8_t format, uint8_t *hash, uint8_t *data, uint32_t *datalen)
198{ 198{
199 uint8_t addr[TOX_CLIENT_ID_SIZE]; 199 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
200 200
201 if (tox_get_client_id(tox, friendnum, addr) != 0) { 201 if (tox_get_client_id(tox, friendnum, addr) != 0) {
202 DEBUG("Bad client id, friendnumber=%d", friendnum); 202 DEBUG("Bad client id, friendnumber=%d", friendnum);
@@ -224,14 +224,14 @@ static int load_user_avatar(Tox *tox, char *base_dir, int friendnum,
224 return 0; 224 return 0;
225} 225}
226 226
227/* Save a user avatar into the cache. Gets the file name from client id and 227/* Save a user avatar into the cache. Gets the file name from the public key
228 * the given data format. 228 * and the given data format.
229 * Returns 0 on success, or -1 on error. 229 * Returns 0 on success, or -1 on error.
230 */ 230 */
231static int save_user_avatar(Tox *tox, char *base_dir, int friendnum, 231static int save_user_avatar(Tox *tox, char *base_dir, int friendnum,
232 uint8_t format, uint8_t *data, uint32_t datalen) 232 uint8_t format, uint8_t *data, uint32_t datalen)
233{ 233{
234 uint8_t addr[TOX_CLIENT_ID_SIZE]; 234 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
235 235
236 if (tox_get_client_id(tox, friendnum, addr) != 0) { 236 if (tox_get_client_id(tox, friendnum, addr) != 0) {
237 DEBUG("Bad client id, friendnumber=%d", friendnum); 237 DEBUG("Bad client id, friendnumber=%d", friendnum);
@@ -252,7 +252,7 @@ static int save_user_avatar(Tox *tox, char *base_dir, int friendnum,
252/* Delete all cached avatars for a given user */ 252/* Delete all cached avatars for a given user */
253static int delete_user_avatar(Tox *tox, char *base_dir, int friendnum) 253static int delete_user_avatar(Tox *tox, char *base_dir, int friendnum)
254{ 254{
255 uint8_t addr[TOX_CLIENT_ID_SIZE]; 255 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
256 256
257 if (tox_get_client_id(tox, friendnum, addr) != 0) { 257 if (tox_get_client_id(tox, friendnum, addr) != 0) {
258 DEBUG("Bad client id, friendnumber=%d", friendnum); 258 DEBUG("Bad client id, friendnumber=%d", friendnum);
@@ -288,11 +288,11 @@ static int delete_user_avatar(Tox *tox, char *base_dir, int friendnum)
288 288
289static void friend_status_cb(Tox *tox, int n, uint8_t status, void *ud) 289static void friend_status_cb(Tox *tox, int n, uint8_t status, void *ud)
290{ 290{
291 uint8_t addr[TOX_CLIENT_ID_SIZE]; 291 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
292 char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; 292 char addr_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
293 293
294 if (tox_get_client_id(tox, n, addr) == 0) { 294 if (tox_get_client_id(tox, n, addr) == 0) {
295 byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); 295 byte_to_hex_str(addr, TOX_PUBLIC_KEY_SIZE, addr_str);
296 printf("Receiving status from %s: %u\n", addr_str, status); 296 printf("Receiving status from %s: %u\n", addr_str, status);
297 } 297 }
298} 298}
@@ -300,12 +300,12 @@ static void friend_status_cb(Tox *tox, int n, uint8_t status, void *ud)
300static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t *hash, void *ud) 300static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t *hash, void *ud)
301{ 301{
302 char *base_dir = (char *) ud; 302 char *base_dir = (char *) ud;
303 uint8_t addr[TOX_CLIENT_ID_SIZE]; 303 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
304 char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; 304 char addr_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
305 char hash_str[2 * TOX_HASH_LENGTH + 1]; 305 char hash_str[2 * TOX_HASH_LENGTH + 1];
306 306
307 if (tox_get_client_id(tox, n, addr) == 0) { 307 if (tox_get_client_id(tox, n, addr) == 0) {
308 byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); 308 byte_to_hex_str(addr, TOX_PUBLIC_KEY_SIZE, addr_str);
309 printf("Receiving avatar information from %s.\n", addr_str); 309 printf("Receiving avatar information from %s.\n", addr_str);
310 } else { 310 } else {
311 DEBUG("tox_get_client_id failed"); 311 DEBUG("tox_get_client_id failed");
@@ -350,12 +350,12 @@ static void friend_avatar_data_cb(Tox *tox, int32_t n, uint8_t format,
350 uint8_t *hash, uint8_t *data, uint32_t datalen, void *ud) 350 uint8_t *hash, uint8_t *data, uint32_t datalen, void *ud)
351{ 351{
352 char *base_dir = (char *) ud; 352 char *base_dir = (char *) ud;
353 uint8_t addr[TOX_CLIENT_ID_SIZE]; 353 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
354 char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; 354 char addr_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
355 char hash_str[2 * TOX_HASH_LENGTH + 1]; 355 char hash_str[2 * TOX_HASH_LENGTH + 1];
356 356
357 if (tox_get_client_id(tox, n, addr) == 0) { 357 if (tox_get_client_id(tox, n, addr) == 0) {
358 byte_to_hex_str(addr, TOX_CLIENT_ID_SIZE, addr_str); 358 byte_to_hex_str(addr, TOX_PUBLIC_KEY_SIZE, addr_str);
359 printf("Receiving avatar data from %s.\n", addr_str); 359 printf("Receiving avatar data from %s.\n", addr_str);
360 } else { 360 } else {
361 DEBUG("tox_get_client_id failed"); 361 DEBUG("tox_get_client_id failed");
@@ -382,8 +382,8 @@ static void friend_msg_cb(Tox *tox, int n, const uint8_t *msg, uint16_t len, voi
382{ 382{
383 const char *base_dir = (char *) ud; 383 const char *base_dir = (char *) ud;
384 const char *msg_str = (char *) msg; 384 const char *msg_str = (char *) msg;
385 uint8_t addr[TOX_CLIENT_ID_SIZE]; 385 uint8_t addr[TOX_PUBLIC_KEY_SIZE];
386 char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; 386 char addr_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
387 387
388 if (tox_get_client_id(tox, n, addr) == 0) { 388 if (tox_get_client_id(tox, n, addr) == 0) {
389 byte_to_hex_str(addr, TOX_FRIEND_ADDRESS_SIZE, addr_str); 389 byte_to_hex_str(addr, TOX_FRIEND_ADDRESS_SIZE, addr_str);
@@ -428,8 +428,8 @@ static void friend_msg_cb(Tox *tox, int n, const uint8_t *msg, uint16_t len, voi
428static void friend_request_cb(Tox *tox, const uint8_t *public_key, 428static void friend_request_cb(Tox *tox, const uint8_t *public_key,
429 const uint8_t *data, uint16_t length, void *ud) 429 const uint8_t *data, uint16_t length, void *ud)
430{ 430{
431 char addr_str[2 * TOX_CLIENT_ID_SIZE + 1]; 431 char addr_str[2 * TOX_PUBLIC_KEY_SIZE + 1];
432 byte_to_hex_str(public_key, TOX_CLIENT_ID_SIZE, addr_str); 432 byte_to_hex_str(public_key, TOX_PUBLIC_KEY_SIZE, addr_str);
433 printf("Accepting friend request from %s.\n %s\n", addr_str, data); 433 printf("Accepting friend request from %s.\n %s\n", addr_str, data);
434 tox_add_friend_norequest(tox, public_key); 434 tox_add_friend_norequest(tox, public_key);
435} 435}