summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-10-27 20:25:31 -0400
committerirungentoo <irungentoo@gmail.com>2013-10-27 20:25:31 -0400
commitd2ab13c61121fd14bbb2edc4406eaf807bbab3ec (patch)
tree7be227c6fe84da12de99bf00fd71866eadff01aa
parent937dbd3a7ab00755096b69c106d5f7655e9752d9 (diff)
Cleaned up some code/fixed some warnings.
I'm sure nobody has any of the old save files anymore so I removed the functions.
-rw-r--r--toxcore/Messenger.c140
-rw-r--r--toxcore/net_crypto.c2
-rw-r--r--toxcore/tox.h2
3 files changed, 3 insertions, 141 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 7da77541..be3d82e0 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1890,144 +1890,6 @@ void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len)
1890 networking_wait_cleanup(m->net, data, len); 1890 networking_wait_cleanup(m->net, data, len);
1891} 1891}
1892 1892
1893/* return size of the messenger data (for saving) */
1894uint32_t Messenger_size_old(Messenger *m)
1895{
1896 return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
1897 + sizeof(uint32_t) // nospam.
1898 + sizeof(uint32_t) // DHT size.
1899 + DHT_size(m->dht) // DHT itself.
1900 + sizeof(uint32_t) // Friendlist size.
1901 + sizeof(Friend) * m->numfriends // Friendlist itself.
1902 + sizeof(uint16_t) // Own nickname length.
1903 + m->name_length // Own nickname.
1904 ;
1905}
1906
1907/* Save the messenger in data of size Messenger_size(). Old version without cookies. */
1908static void Messenger_save_old(Messenger *m, uint8_t *data)
1909{
1910 save_keys(m->net_crypto, data);
1911 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
1912
1913 uint32_t nospam = get_nospam(&(m->fr));
1914 memcpy(data, &nospam, sizeof(nospam));
1915 data += sizeof(nospam);
1916
1917 uint32_t size = DHT_size(m->dht);
1918 memcpy(data, &size, sizeof(size));
1919 data += sizeof(size);
1920 DHT_save(m->dht, data);
1921 data += size;
1922
1923 size = sizeof(Friend) * m->numfriends;
1924 memcpy(data, &size, sizeof(size));
1925 data += sizeof(size);
1926 memcpy(data, m->friendlist, sizeof(Friend) * m->numfriends);
1927 data += size;
1928
1929 uint16_t small_size = m->name_length;
1930 memcpy(data, &small_size, sizeof(small_size));
1931 data += sizeof(small_size);
1932 memcpy(data, m->name, small_size);
1933}
1934
1935/* Load the messenger from data of size length. Old version without cookies. */
1936static int Messenger_load_old(Messenger *m, uint8_t *data, uint32_t length)
1937{
1938 if (length == ~((uint32_t)0))
1939 return -1;
1940
1941 /* BLOCK1: PUBKEY, SECKEY, NOSPAM, SIZE */
1942 if (length < crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 2)
1943 return -1;
1944
1945 load_keys(m->net_crypto, data);
1946 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
1947 length -= crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
1948
1949 uint32_t nospam;
1950 memcpy(&nospam, data, sizeof(nospam));
1951 set_nospam(&(m->fr), nospam);
1952 data += sizeof(nospam);
1953 length -= sizeof(nospam);
1954
1955 uint32_t size;
1956
1957 if (length < sizeof(size))
1958 return -1;
1959
1960 memcpy(&size, data, sizeof(size));
1961 data += sizeof(size);
1962 length -= sizeof(size);
1963
1964 if (length < size)
1965 return -1;
1966
1967 if (DHT_load_old(m->dht, data, size) == -1) {
1968#ifdef DEBUG
1969 fprintf(stderr, "Data file: Something wicked happened to the stored connections...\n");
1970 /* DO go on, friends/name still might be intact */
1971#endif
1972 }
1973
1974 data += size;
1975 length -= size;
1976
1977 if (length < sizeof(size))
1978 return -1;
1979
1980 memcpy(&size, data, sizeof(size));
1981 data += sizeof(size);
1982 length -= sizeof(size);
1983
1984 if (length < size)
1985 return -1;
1986
1987 if (!(size % sizeof(Friend))) {
1988 uint16_t num = size / sizeof(Friend);
1989 Friend *friend_list = (Friend *)data;
1990
1991 uint32_t i;
1992
1993 for (i = 0; i < num; ++i) {
1994 if (friend_list[i].status >= 3) {
1995 int fnum = m_addfriend_norequest(m, friend_list[i].client_id);
1996 setfriendname(m, fnum, friend_list[i].name, friend_list[i].name_length);
1997 /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */
1998 } else if (friend_list[i].status != 0) {
1999 /* TODO: This is not a good way to do this. */
2000 uint8_t address[FRIEND_ADDRESS_SIZE];
2001 id_copy(address, friend_list[i].client_id);
2002 memcpy(address + crypto_box_PUBLICKEYBYTES, &(friend_list[i].friendrequest_nospam), sizeof(uint32_t));
2003 uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum));
2004 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum));
2005 m_addfriend(m, address, friend_list[i].info, friend_list[i].info_size);
2006 }
2007 }
2008 }
2009
2010 data += size;
2011 length -= size;
2012
2013 uint16_t small_size;
2014
2015 if (length < sizeof(small_size))
2016 return -1;
2017
2018 memcpy(&small_size, data, sizeof(small_size));
2019 data += sizeof(small_size);
2020 length -= sizeof(small_size);
2021
2022 if (length < small_size)
2023 return -1;
2024
2025 setname(m, data, small_size);
2026
2027 return 0;
2028}
2029
2030
2031/* new messenger format for load/save, more robust and forward compatible */ 1893/* new messenger format for load/save, more robust and forward compatible */
2032 1894
2033#define MESSENGER_STATE_COOKIE_GLOBAL 0x15ed1b1e 1895#define MESSENGER_STATE_COOKIE_GLOBAL 0x15ed1b1e
@@ -2176,7 +2038,7 @@ int messenger_load(Messenger *m, uint8_t *data, uint32_t length)
2176 return load_state(messenger_load_state_callback, m, data + cookie_len, 2038 return load_state(messenger_load_state_callback, m, data + cookie_len,
2177 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); 2039 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE);
2178 else /* old state file */ 2040 else /* old state file */
2179 return Messenger_load_old(m, data, length); 2041 return -1;
2180} 2042}
2181 2043
2182/* Return the number of friends in the instance m. 2044/* Return the number of friends in the instance m.
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 9b8eff96..3c7c114e 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -29,7 +29,7 @@
29#endif 29#endif
30 30
31#include "net_crypto.h" 31#include "net_crypto.h"
32 32#include "util.h"
33static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id) 33static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id)
34{ 34{
35 return (uint32_t)crypt_connection_id >= c->crypto_connections_length; 35 return (uint32_t)crypt_connection_id >= c->crypto_connections_length;
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 0c7aa13c..5d3916b4 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -62,7 +62,7 @@ extern "C" {
62#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) 62#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
63 63
64#define TOX_PORTRANGE_FROM 33445 64#define TOX_PORTRANGE_FROM 33445
65#define TOX_PORTRANGE_TO 33455 65#define TOX_PORTRANGE_TO 33545
66#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM 66#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
67 67
68typedef union { 68typedef union {