diff options
author | irungentoo <irungentoo@gmail.com> | 2015-02-01 20:16:49 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-02-01 20:16:49 -0500 |
commit | fbe9fd0610a8e935dac39c679e25fabfbe487fe6 (patch) | |
tree | 477d0e237b1982c63489a49f8cfa9a897f326990 /testing/test_avatars.c | |
parent | 33f65929e3f430e9542192d0adf98f1252a911f4 (diff) | |
parent | c2421e6f21482b82257c4926c40dc830397973ea (diff) |
Merge branch 'ittner-update-avatar-docs-2'
Diffstat (limited to 'testing/test_avatars.c')
-rw-r--r-- | testing/test_avatars.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/testing/test_avatars.c b/testing/test_avatars.c index 71a0330e..b4adc48f 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: |
@@ -163,14 +163,14 @@ static void byte_to_hex_str(const uint8_t *buf, const size_t buflen, char *dst) | |||
163 | dst[j++] = '\0'; | 163 | dst[j++] = '\0'; |
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 an avatar of the given format for the given |
167 | * client id. | 167 | * public key. |
168 | */ | 168 | */ |
169 | static int make_avatar_file_name(char *dst, size_t dst_len, const char *base_dir, | 169 | static 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 | |||
196 | static int load_user_avatar(Tox *tox, char *base_dir, int friendnum, | 196 | static 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 | */ |
231 | static int save_user_avatar(Tox *tox, char *base_dir, int friendnum, | 231 | static 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 */ |
253 | static int delete_user_avatar(Tox *tox, char *base_dir, int friendnum) | 253 | static 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 | ||
289 | static void friend_status_cb(Tox *tox, int n, uint8_t status, void *ud) | 289 | static 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) | |||
300 | static void friend_avatar_info_cb(Tox *tox, int32_t n, uint8_t format, uint8_t *hash, void *ud) | 300 | static 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 | |||
428 | static void friend_request_cb(Tox *tox, const uint8_t *public_key, | 428 | static 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 | } |