summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/messenger_test.c12
-rw-r--r--core/Messenger.c6
-rw-r--r--core/net_crypto.c2
-rw-r--r--other/CMakeLists.txt15
-rw-r--r--other/DHTservers2
-rw-r--r--testing/toxic/main.c47
-rw-r--r--testing/toxic/prompt.c1
7 files changed, 67 insertions, 18 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index 3ca89152..9de69409 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -88,12 +88,12 @@ START_TEST(test_m_set_userstatus)
88 uint16_t bad_length = REALLY_BIG_NUMBER; 88 uint16_t bad_length = REALLY_BIG_NUMBER;
89 89
90 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1), 90 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1),
91 "m_set_userstatus did NOT catch the following length: %d\n", 91 "m_set_userstatus did NOT catch the following length: %d\n",
92 REALLY_BIG_NUMBER); 92 REALLY_BIG_NUMBER);
93 93
94 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0), 94 ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0),
95 "m_set_userstatus did NOT return 0 on the following length: %d\n" 95 "m_set_userstatus did NOT return 0 on the following length: %d\n"
96 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); 96 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
97} 97}
98END_TEST 98END_TEST
99 99
@@ -157,10 +157,10 @@ START_TEST(test_setname)
157 int bad_length = REALLY_BIG_NUMBER; 157 int bad_length = REALLY_BIG_NUMBER;
158 158
159 ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1), 159 ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1),
160 "setname() did NOT error on %d as a length argument!\n", bad_length); 160 "setname() did NOT error on %d as a length argument!\n", bad_length);
161 161
162 ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0), 162 ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0),
163 "setname() did NOT return 0 on good arguments!\n"); 163 "setname() did NOT return 0 on good arguments!\n");
164} 164}
165END_TEST 165END_TEST
166 166
diff --git a/core/Messenger.c b/core/Messenger.c
index 2b5c8241..8a5d9ed4 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -37,6 +37,8 @@ static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_i
37 return -1 if realloc fails */ 37 return -1 if realloc fails */
38int realloc_friendlist(Messenger *m, uint32_t num) 38int realloc_friendlist(Messenger *m, uint32_t num)
39{ 39{
40 if (num * sizeof(Friend) == 0) return -1;
41
40 Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend)); 42 Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend));
41 43
42 if (newfriendlist == NULL && num != 0) 44 if (newfriendlist == NULL && num != 0)
@@ -597,7 +599,6 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
597 599
598/*Interval in seconds between LAN discovery packet sending*/ 600/*Interval in seconds between LAN discovery packet sending*/
599#define LAN_DISCOVERY_INTERVAL 60 601#define LAN_DISCOVERY_INTERVAL 60
600
601#define PORT 33445 602#define PORT 33445
602 603
603/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ 604/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/
@@ -951,6 +952,7 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
951 } 952 }
952 } 953 }
953 954
955 free(temp);
954 data += size; 956 data += size;
955 length -= size; 957 length -= size;
956 958
@@ -968,7 +970,5 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
968 970
969 setname(m, data, small_size); 971 setname(m, data, small_size);
970 972
971 free(temp);
972 return 0; 973 return 0;
973} 974}
974
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 7fdd035f..6ced942b 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -406,6 +406,8 @@ static int getcryptconnection_id(uint8_t *public_key)
406 return -1 if realloc fails */ 406 return -1 if realloc fails */
407int realloc_cryptoconnection(uint32_t num) 407int realloc_cryptoconnection(uint32_t num)
408{ 408{
409 if (num * sizeof(Crypto_Connection) == 0) return -1;
410
409 Crypto_Connection *newcrypto_connections = realloc(crypto_connections, num * sizeof(Crypto_Connection)); 411 Crypto_Connection *newcrypto_connections = realloc(crypto_connections, num * sizeof(Crypto_Connection));
410 412
411 if (newcrypto_connections == NULL && num != 0) 413 if (newcrypto_connections == NULL && num != 0)
diff --git a/other/CMakeLists.txt b/other/CMakeLists.txt
index db742e3e..10e5b051 100644
--- a/other/CMakeLists.txt
+++ b/other/CMakeLists.txt
@@ -1,9 +1,24 @@
1cmake_minimum_required(VERSION 2.6.0) 1cmake_minimum_required(VERSION 2.6.0)
2 2
3cmake_policy(SET CMP0011 NEW) 3cmake_policy(SET CMP0011 NEW)
4SET(USER_NAME $ENV{USERNAME} CACHE STRING UserName)
4 5
5include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake) 6include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake)
6 7
8if(WIN32)
9 file(MAKE_DIRECTORY "C:/Users/${USER_NAME}/AppData/Roaming/.tox")
10 file(INSTALL DHTservers DESTINATION "C:/Users/${USER_NAME}/AppData/Roaming/.tox")
11else()
12 set(HOME "$ENV{HOME}")
13 if(APPLE)
14 file(MAKE_DIRECTORY ${HOME}Library/Application Support/.tox)
15 file(INSTALL DHTservers DESTINATION ${HOME}Library/Application Support/.tox)
16 else()
17 file(MAKE_DIRECTORY ${HOME}/.tox)
18 file(INSTALL DHTservers DESTINATION ${HOME}/.tox)
19 endif()
20endif()
21
7if(LINUX) 22if(LINUX)
8 add_subdirectory(bootstrap_serverdaemon) 23 add_subdirectory(bootstrap_serverdaemon)
9endif() 24endif()
diff --git a/other/DHTservers b/other/DHTservers
index 6efba882..bf2d2728 100644
--- a/other/DHTservers
+++ b/other/DHTservers
@@ -5,3 +5,5 @@
581.224.34.47 443 48F0D94C0D54EB1995A2ECEDE7DB6BDD5E05D81704B2F3D1BB9FE43AC97B7269 581.224.34.47 443 48F0D94C0D54EB1995A2ECEDE7DB6BDD5E05D81704B2F3D1BB9FE43AC97B7269
6198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854 6198.46.136.167 33445 728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854
795.47.140.214 33445 F4BF7C5A9D0EF4CB684090C38DE937FAE1612021F21FEA4DCBFAC6AAFEF58E68 795.47.140.214 33445 F4BF7C5A9D0EF4CB684090C38DE937FAE1612021F21FEA4DCBFAC6AAFEF58E68
854.215.145.71 33445 6EDDEE2188EF579303C0766B4796DCBA89C93058B6032FEA51593DCD42FB746C
966.74.30.125 33445 7155386A691E7BD3C4C0589D70ACDA191D488634772885CCED5DD7B3F7E6310D
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 4562f394..05fabe4c 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -27,6 +27,7 @@
27 27
28/* Export for use in Callbacks */ 28/* Export for use in Callbacks */
29char *DATA_FILE = NULL; 29char *DATA_FILE = NULL;
30char dir[31];
30 31
31void on_window_resize(int sig) 32void on_window_resize(int sig)
32{ 33{
@@ -35,6 +36,17 @@ void on_window_resize(int sig)
35 clear(); 36 clear();
36} 37}
37 38
39void setdir()
40{
41 #ifdef WIN32
42 strcpy(dir, "%appdata%/.tox/");
43 #elif defined(MAC_OSX)
44 strcpy(dir, "~/Library/Application Support/.tox/");
45 #elif defined(linux)
46 strcpy(dir, "~/.tox/");
47 #endif
48}
49
38static void init_term() 50static void init_term()
39{ 51{
40 /* Setup terminal */ 52 /* Setup terminal */
@@ -52,6 +64,10 @@ static void init_term()
52 init_pair(3, COLOR_RED, COLOR_BLACK); 64 init_pair(3, COLOR_RED, COLOR_BLACK);
53 init_pair(4, COLOR_BLUE, COLOR_BLACK); 65 init_pair(4, COLOR_BLUE, COLOR_BLACK);
54 init_pair(5, COLOR_YELLOW, COLOR_BLACK); 66 init_pair(5, COLOR_YELLOW, COLOR_BLACK);
67 init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
68 init_pair(7, COLOR_BLACK, COLOR_BLACK);
69 init_pair(8, COLOR_BLACK, COLOR_WHITE);
70
55 } 71 }
56 72
57 refresh(); 73 refresh();
@@ -68,13 +84,15 @@ static Messenger *init_tox()
68 m_callback_namechange(m, on_nickchange, NULL); 84 m_callback_namechange(m, on_nickchange, NULL);
69 m_callback_statusmessage(m, on_statuschange, NULL); 85 m_callback_statusmessage(m, on_statuschange, NULL);
70 m_callback_action(m, on_action, NULL); 86 m_callback_action(m, on_action, NULL);
71#ifdef __linux__ 87 #ifdef __linux__
72 setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy")); 88 setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy"));
73#elif WIN32 89 #elif defined(WIN32)
74 setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux")); 90 setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux"));
75#else 91 #elif defined(MAC_OSX)
76 setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); 92 setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); //This used to users of other Unixes are hipsters
77#endif 93 #else
94 setname(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4"));
95 #endif
78 return m; 96 return m;
79} 97}
80 98
@@ -88,7 +106,13 @@ int init_connection(void)
88 if (DHT_isconnected()) 106 if (DHT_isconnected())
89 return 0; 107 return 0;
90 108
91 FILE *fp = fopen("../../../other/DHTservers", "r"); 109 #if WIN32
110 FILE *fp = fopen("%appdata%/.tox/DHTservers", "r");
111 #elif MAC_OSX
112 FILE *fp = fopen("~/Library/Application Support/.tox/DHTservers", "r");
113 #else
114 FILE *fp = fopen("~/.tox/DHTservers", "r");
115 #endif
92 116
93 if (!fp) 117 if (!fp)
94 return 1; 118 return 1;
@@ -255,6 +279,7 @@ static void load_data(Messenger *m, char *path)
255 279
256int main(int argc, char *argv[]) 280int main(int argc, char *argv[])
257{ 281{
282 setdir();
258 char *user_config_dir = get_user_config_dir(); 283 char *user_config_dir = get_user_config_dir();
259 int config_err = 0; 284 int config_err = 0;
260 285
@@ -281,12 +306,16 @@ int main(int argc, char *argv[])
281 config_err = create_user_config_dir(user_config_dir); 306 config_err = create_user_config_dir(user_config_dir);
282 307
283 if (config_err) { 308 if (config_err) {
309 strcat(DATA_FILE, dir);
284 DATA_FILE = strdup("data"); 310 DATA_FILE = strdup("data");
311
312
285 } else { 313 } else {
286 DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); 314 DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
287 strcpy(DATA_FILE, user_config_dir); 315 strcpy(DATA_FILE, user_config_dir);
288 strcat(DATA_FILE, CONFIGDIR); 316 strcat(DATA_FILE, CONFIGDIR);
289 strcat(DATA_FILE, "data"); 317 strcat(DATA_FILE, dir);
318 DATA_FILE = strdup("data");
290 } 319 }
291 } 320 }
292 321
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 0c1cf4b0..473633d4 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -272,6 +272,7 @@ void cmd_nick(ToxWindow *self, Messenger *m, char **args)
272 char *nick = args[1]; 272 char *nick = args[1];
273 setname(m, (uint8_t *) nick, strlen(nick) + 1); 273 setname(m, (uint8_t *) nick, strlen(nick) + 1);
274 wprintw(self->window, "Nickname set to: %s\n", nick); 274 wprintw(self->window, "Nickname set to: %s\n", nick);
275
275 if (store_data(m, DATA_FILE)) { 276 if (store_data(m, DATA_FILE)) {
276 wprintw(self->window, "\nCould not store Messenger data\n"); 277 wprintw(self->window, "\nCould not store Messenger data\n");
277 } 278 }