Save function renamed to tox_get_savedata()

This commit is contained in:
irungentoo 2015-03-17 16:20:38 -04:00
parent 67f6d0857a
commit 8286c2c22f
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
5 changed files with 18 additions and 17 deletions

View File

@ -305,9 +305,9 @@ START_TEST(test_one)
tox_self_set_name(tox1, name, sizeof(name), 0); tox_self_set_name(tox1, name, sizeof(name), 0);
ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
size_t save_size = tox_save_size(tox1); size_t save_size = tox_get_savedata_size(tox1);
uint8_t data[save_size]; uint8_t data[save_size];
tox_save(tox1, data); tox_get_savedata(tox1, data);
tox_kill(tox2); tox_kill(tox2);
TOX_ERR_NEW err_n; TOX_ERR_NEW err_n;

View File

@ -965,9 +965,9 @@ static int save_data(Tox *m)
} }
int res = 1; int res = 1;
size_t size = tox_save_size(m); size_t size = tox_get_savedata_size(m);
uint8_t data[size]; uint8_t data[size];
tox_save(m, data); tox_get_savedata(m, data);
if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
fputs("[!] could not write data file (1)!", stderr); fputs("[!] could not write data file (1)!", stderr);

View File

@ -224,13 +224,13 @@ void tox_kill(Tox *tox)
logger_kill_global(); logger_kill_global();
} }
size_t tox_save_size(const Tox *tox) size_t tox_get_savedata_size(const Tox *tox)
{ {
const Messenger *m = tox; const Messenger *m = tox;
return messenger_size(m); return messenger_size(m);
} }
void tox_save(const Tox *tox, uint8_t *data) void tox_get_savedata(const Tox *tox, uint8_t *data)
{ {
if (data) { if (data) {
const Messenger *m = tox; const Messenger *m = tox;

View File

@ -497,14 +497,14 @@ typedef enum TOX_ERR_NEW {
* loop with a new instance will operate correctly. * loop with a new instance will operate correctly.
* *
* If the data parameter is not NULL, this function will load the Tox instance * If the data parameter is not NULL, this function will load the Tox instance
* from a byte array previously filled by tox_save. * from a byte array previously filled by tox_get_savedata.
* *
* If loading failed or succeeded only partially, the new or partially loaded * If loading failed or succeeded only partially, the new or partially loaded
* instance is returned and an error code is set. * instance is returned and an error code is set.
* *
* @param options An options object as described above. If this parameter is * @param options An options object as described above. If this parameter is
* NULL, the default options are used. * NULL, the default options are used.
* @param data A byte array containing data previously stored by tox_save. * @param data A byte array containing data previously stored by tox_get_savedata.
* @param length The length of the byte array data. If this parameter is 0, the * @param length The length of the byte array data. If this parameter is 0, the
* data parameter is ignored. * data parameter is ignored.
* *
@ -525,20 +525,21 @@ void tox_kill(Tox *tox);
/** /**
* Calculates the number of bytes required to store the tox instance with * Calculates the number of bytes required to store the tox instance with
* tox_save. This function cannot fail. The result is always greater than 0. * tox_get_savedata. This function cannot fail. The result is always greater
* than 0.
* *
* @see threading for concurrency implications. * @see threading for concurrency implications.
*/ */
size_t tox_save_size(const Tox *tox); size_t tox_get_savedata_size(const Tox *tox);
/** /**
* Store all information associated with the tox instance to a byte array. * Store all information associated with the tox instance to a byte array.
* *
* @param data A memory region large enough to store the tox instance data. * @param data A memory region large enough to store the tox instance data.
* Call tox_save_size to find the number of bytes required. If this parameter * Call tox_get_savedata_size to find the number of bytes required. If this parameter
* is NULL, this function has no effect. * is NULL, this function has no effect.
*/ */
void tox_save(const Tox *tox, uint8_t *data); void tox_get_savedata(const Tox *tox, uint8_t *data);
/******************************************************************************* /*******************************************************************************

View File

@ -66,7 +66,7 @@ int tox_pass_salt_length()
/* return size of the messenger data (for encrypted saving). */ /* return size of the messenger data (for encrypted saving). */
uint32_t tox_encrypted_size(const Tox *tox) uint32_t tox_encrypted_size(const Tox *tox)
{ {
return tox_save_size(tox) + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; return tox_get_savedata_size(tox) + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
} }
/* This retrieves the salt used to encrypt the given data, which can then be passed to /* This retrieves the salt used to encrypt the given data, which can then be passed to
@ -205,9 +205,9 @@ int tox_pass_encrypt(const uint8_t *data, uint32_t data_len, uint8_t *passphrase
int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength) int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength)
{ {
/* first get plain save data */ /* first get plain save data */
uint32_t temp_size = tox_save_size(tox); uint32_t temp_size = tox_get_savedata_size(tox);
uint8_t temp_data[temp_size]; uint8_t temp_data[temp_size];
tox_save(tox, temp_data); tox_get_savedata(tox, temp_data);
/* now encrypt */ /* now encrypt */
return tox_pass_encrypt(temp_data, temp_size, passphrase, pplength, data); return tox_pass_encrypt(temp_data, temp_size, passphrase, pplength, data);
@ -222,9 +222,9 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3
int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key) int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key)
{ {
/* first get plain save data */ /* first get plain save data */
uint32_t temp_size = tox_save_size(tox); uint32_t temp_size = tox_get_savedata_size(tox);
uint8_t temp_data[temp_size]; uint8_t temp_data[temp_size];
tox_save(tox, temp_data); tox_get_savedata(tox, temp_data);
/* encrypt */ /* encrypt */
return tox_pass_key_encrypt(temp_data, temp_size, key, data); return tox_pass_key_encrypt(temp_data, temp_size, key, data);