Fixed loading and a small problem with the length of crypto requests.

This commit is contained in:
irungentoo 2013-08-15 20:56:22 -04:00
parent 36cb9b003d
commit b15230583c
4 changed files with 19 additions and 5 deletions

View File

@ -810,10 +810,18 @@ int Messenger_load(Messenger *m, uint8_t * data, uint32_t length)
uint32_t i;
for (i = 0; i < num; ++i) {
if(temp[i].status != 0) {
if(temp[i].status >= 3) {
int fnum = m_addfriend_norequest(m, temp[i].client_id);
setfriendname(m, fnum, temp[i].name);
/* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */
} else if (temp[i].status != 0) {
/* TODO: this is not a good way to do this. */
uint8_t address[FRIEND_ADDRESS_SIZE];
memcpy(address, temp[i].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(address + crypto_box_PUBLICKEYBYTES, &(temp[i].friendrequest_nospam), sizeof(uint32_t));
uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum));
memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum));
m_addfriend(m, address, temp[i].info, temp[i].info_size);
}
}
free(temp);

View File

@ -35,7 +35,7 @@ int send_friendrequest(uint8_t * public_key, uint32_t nospam_num, uint8_t * data
{
if(length - sizeof(nospam_num) > MAX_DATA_SIZE)
return -1;
uint8_t temp[MAX_DATA_SIZE];
memcpy(temp, &nospam_num, sizeof(nospam_num));
memcpy(temp + sizeof(nospam_num), data, length);

View File

@ -228,7 +228,7 @@ int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t
memcpy(temp + 1, data, length);
temp[0] = request_id;
random_nonce(nonce);
int len = encrypt_data(public_key, self_secret_key, nonce, temp, length,
int len = encrypt_data(public_key, self_secret_key, nonce, temp, length + 1,
1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet);
if (len == -1)
return -1;
@ -287,7 +287,7 @@ static int cryptopacket_handle(IP_Port source, uint8_t * packet, uint32_t length
if (len == -1 || len == 0)
return 1;
if (!cryptopackethandlers[number]) return 1;
cryptopackethandlers[number](source, public_key, data, len - 1);
cryptopackethandlers[number](source, public_key, data, len);
} else { /* if request is not for us, try routing it. */
if(route_packet(packet + 1, packet, length) == length)

View File

@ -147,6 +147,8 @@ static void do_tox(Messenger *m, ToxWindow * prompt)
doMessenger(m);
}
int f_loadfromfile;
/*
* Store Messenger to given location
* Return 0 stored successfully
@ -156,6 +158,8 @@ static void do_tox(Messenger *m, ToxWindow * prompt)
*/
int store_data(Messenger *m, char *path)
{
if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
return 0;
FILE *fd;
size_t len;
uint8_t *buf;
@ -186,6 +190,8 @@ int store_data(Messenger *m, char *path)
static void load_data(Messenger *m, char *path)
{
if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
return;
FILE *fd;
size_t len;
uint8_t *buf;
@ -233,7 +239,7 @@ int main(int argc, char *argv[])
char *user_config_dir = get_user_config_dir();
int config_err = 0;
int f_loadfromfile = 1;
f_loadfromfile = 1;
int f_flag = 0;
int i = 0;
for (i = 0; i < argc; ++i) {