mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #606 from FullName/Permit.Wshadow
Permit -Wshadow as useful warning.
This commit is contained in:
commit
c7c72b0756
|
@ -310,48 +310,30 @@ START_TEST(test_messenger_state_saveloadsave)
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
#define DEFTESTCASE(NAME) \
|
||||||
|
TCase *tc_##NAME = tcase_create(#NAME); \
|
||||||
|
tcase_add_test(tc_##NAME, test_##NAME); \
|
||||||
|
suite_add_tcase(s, tc_##NAME);
|
||||||
|
|
||||||
Suite *messenger_suite(void)
|
Suite *messenger_suite(void)
|
||||||
{
|
{
|
||||||
Suite *s = suite_create("Messenger");
|
Suite *s = suite_create("Messenger");
|
||||||
|
|
||||||
TCase *userstatus_size = tcase_create("userstatus_size");
|
DEFTESTCASE(dht_state_saveloadsave);
|
||||||
TCase *set_userstatus = tcase_create("set_userstatus");
|
DEFTESTCASE(messenger_state_saveloadsave);
|
||||||
TCase *send_message = tcase_create("send_message");
|
|
||||||
TCase *friend_exists = tcase_create("friend_exists");
|
|
||||||
TCase *get_friend_connectionstatus = tcase_create("get_friend_connectionstatus");
|
|
||||||
TCase *getself_name = tcase_create("getself_name");
|
|
||||||
TCase *delfriend = tcase_create("delfriend");
|
|
||||||
//TCase *addfriend = tcase_create("addfriend");
|
|
||||||
TCase *setname = tcase_create("setname");
|
|
||||||
TCase *getname = tcase_create("getname");
|
|
||||||
TCase *dht_state_saveloadsave = tcase_create("dht_state_saveloadsave");
|
|
||||||
TCase *messenger_state_saveloadsave = tcase_create("messenger_state_saveloadsave");
|
|
||||||
|
|
||||||
tcase_add_test(userstatus_size, test_m_get_userstatus_size);
|
DEFTESTCASE(getself_name);
|
||||||
tcase_add_test(set_userstatus, test_m_set_userstatus);
|
DEFTESTCASE(m_get_userstatus_size);
|
||||||
tcase_add_test(get_friend_connectionstatus, test_m_get_friend_connectionstatus);
|
DEFTESTCASE(m_set_userstatus);
|
||||||
tcase_add_test(friend_exists, test_m_friend_exists);
|
|
||||||
tcase_add_test(getself_name, test_getself_name);
|
|
||||||
tcase_add_test(send_message, test_m_sendmesage);
|
|
||||||
tcase_add_test(delfriend, test_m_delfriend);
|
|
||||||
//tcase_add_test(addfriend, test_m_addfriend);
|
|
||||||
tcase_add_test(setname, test_getname);
|
|
||||||
tcase_add_test(setname, test_setname);
|
|
||||||
tcase_add_test(dht_state_saveloadsave, test_dht_state_saveloadsave);
|
|
||||||
tcase_add_test(messenger_state_saveloadsave, test_messenger_state_saveloadsave);
|
|
||||||
|
|
||||||
suite_add_tcase(s, userstatus_size);
|
/* DEFTESTCASE(m_addfriend); */
|
||||||
suite_add_tcase(s, set_userstatus);
|
DEFTESTCASE(m_friend_exists);
|
||||||
suite_add_tcase(s, get_friend_connectionstatus);
|
DEFTESTCASE(m_get_friend_connectionstatus);
|
||||||
suite_add_tcase(s, friend_exists);
|
DEFTESTCASE(m_delfriend);
|
||||||
suite_add_tcase(s, send_message);
|
|
||||||
suite_add_tcase(s, getself_name);
|
DEFTESTCASE(setname);
|
||||||
suite_add_tcase(s, delfriend);
|
DEFTESTCASE(getname);
|
||||||
//suite_add_tcase(s, addfriend);
|
DEFTESTCASE(m_sendmesage);
|
||||||
suite_add_tcase(s, getname);
|
|
||||||
suite_add_tcase(s, setname);
|
|
||||||
suite_add_tcase(s, messenger_state_saveloadsave);
|
|
||||||
suite_add_tcase(s, dht_state_saveloadsave);
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,9 +123,9 @@ START_TEST(test_ip_equal)
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
#define DEFTESTCASE(NAME) \
|
#define DEFTESTCASE(NAME) \
|
||||||
TCase *NAME = tcase_create(#NAME); \
|
TCase *tc_##NAME = tcase_create(#NAME); \
|
||||||
tcase_add_test(NAME, test_##NAME); \
|
tcase_add_test(tc_##NAME, test_##NAME); \
|
||||||
suite_add_tcase(s, NAME);
|
suite_add_tcase(s, tc_##NAME);
|
||||||
|
|
||||||
Suite *network_suite(void)
|
Suite *network_suite(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,6 +56,12 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
|
||||||
|
{
|
||||||
|
printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
|
||||||
|
m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6);
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME needed as print_request has to match the interface expected by
|
/* FIXME needed as print_request has to match the interface expected by
|
||||||
* networking_requesthandler and so cannot take a Messenger * */
|
* networking_requesthandler and so cannot take a Messenger * */
|
||||||
static Messenger *m;
|
static Messenger *m;
|
||||||
|
@ -87,12 +93,6 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *us
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
|
|
||||||
{
|
|
||||||
printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
|
|
||||||
m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char lines[HISTORY][STRING_LENGTH];
|
char lines[HISTORY][STRING_LENGTH];
|
||||||
char line[STRING_LENGTH];
|
char input_line[STRING_LENGTH];
|
||||||
|
|
||||||
char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message "
|
char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message "
|
||||||
"(to send message)\n/s status (to change status)\n[i] /l list (l"
|
"(to send message)\n/s status (to change status)\n[i] /l list (l"
|
||||||
|
@ -442,7 +442,7 @@ void do_refresh()
|
||||||
move(y - 1, 0);
|
move(y - 1, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
printw(">> ");
|
printw(">> ");
|
||||||
printw(line);
|
printw(input_line);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
@ -642,7 +642,7 @@ int main(int argc, char *argv[])
|
||||||
new_lines("/h for list of commands");
|
new_lines("/h for list of commands");
|
||||||
get_id(m, idstring);
|
get_id(m, idstring);
|
||||||
new_lines(idstring);
|
new_lines(idstring);
|
||||||
strcpy(line, "");
|
strcpy(input_line, "");
|
||||||
|
|
||||||
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
||||||
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
||||||
|
@ -694,12 +694,12 @@ int main(int argc, char *argv[])
|
||||||
getmaxyx(stdscr, y, x);
|
getmaxyx(stdscr, y, x);
|
||||||
|
|
||||||
if ((c == 0x0d) || (c == 0x0a)) {
|
if ((c == 0x0d) || (c == 0x0a)) {
|
||||||
line_eval(m, line);
|
line_eval(m, input_line);
|
||||||
strcpy(line, "");
|
strcpy(input_line, "");
|
||||||
} else if (c == 8 || c == 127) {
|
} else if (c == 8 || c == 127) {
|
||||||
line[strlen(line) - 1] = '\0';
|
input_line[strlen(input_line) - 1] = '\0';
|
||||||
} else if (isalnum(c) || ispunct(c) || c == ' ') {
|
} else if (isalnum(c) || ispunct(c) || c == ' ') {
|
||||||
strcpy(line, appender(line, (char) c));
|
strcpy(input_line, appender(input_line, (char) c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -613,11 +613,11 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
|
||||||
if (status == NOFRIEND)
|
if (status == NOFRIEND)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const uint8_t was_connected = m->friendlist[friendnumber].status == FRIEND_ONLINE;
|
const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE;
|
||||||
const uint8_t is_connected = status == FRIEND_ONLINE;
|
const uint8_t is_online = status == FRIEND_ONLINE;
|
||||||
|
|
||||||
if (is_connected != was_connected)
|
if (is_online != was_online)
|
||||||
m->friend_connectionstatuschange(m, friendnumber, is_connected, m->friend_connectionstatuschange_userdata);
|
m->friend_connectionstatuschange(m, friendnumber, is_online, m->friend_connectionstatuschange_userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_friend_status(Messenger *m, int friendnumber, uint8_t status)
|
void set_friend_status(Messenger *m, int friendnumber, uint8_t status)
|
||||||
|
|
|
@ -446,10 +446,10 @@ int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
|
||||||
int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
|
int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
int id = getcryptconnection_id(c, public_key);
|
int id_existing = getcryptconnection_id(c, public_key);
|
||||||
|
|
||||||
if (id != -1) {
|
if (id_existing != -1) {
|
||||||
IP_Port c_ip = connection_ip(c->lossless_udp, c->crypto_connections[id].number);
|
IP_Port c_ip = connection_ip(c->lossless_udp, c->crypto_connections[id_existing].number);
|
||||||
|
|
||||||
if (ipport_equal(&c_ip, &ip_port))
|
if (ipport_equal(&c_ip, &ip_port))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -464,12 +464,12 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
|
||||||
|
|
||||||
for (i = 0; i <= c->crypto_connections_length; ++i) {
|
for (i = 0; i <= c->crypto_connections_length; ++i) {
|
||||||
if (c->crypto_connections[i].status == CONN_NO_CONNECTION) {
|
if (c->crypto_connections[i].status == CONN_NO_CONNECTION) {
|
||||||
int id = new_connection(c->lossless_udp, ip_port);
|
int id_new = new_connection(c->lossless_udp, ip_port);
|
||||||
|
|
||||||
if (id == -1)
|
if (id_new == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
c->crypto_connections[i].number = id;
|
c->crypto_connections[i].number = id_new;
|
||||||
c->crypto_connections[i].status = CONN_HANDSHAKE_SENT;
|
c->crypto_connections[i].status = CONN_HANDSHAKE_SENT;
|
||||||
random_nonce(c->crypto_connections[i].recv_nonce);
|
random_nonce(c->crypto_connections[i].recv_nonce);
|
||||||
memcpy(c->crypto_connections[i].public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
memcpy(c->crypto_connections[i].public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
||||||
|
@ -478,7 +478,7 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
|
||||||
if (c->crypto_connections_length == i)
|
if (c->crypto_connections_length == i)
|
||||||
++c->crypto_connections_length;
|
++c->crypto_connections_length;
|
||||||
|
|
||||||
if (send_cryptohandshake(c, id, public_key, c->crypto_connections[i].recv_nonce,
|
if (send_cryptohandshake(c, id_new, public_key, c->crypto_connections[i].recv_nonce,
|
||||||
c->crypto_connections[i].sessionpublic_key) == 1) {
|
c->crypto_connections[i].sessionpublic_key) == 1) {
|
||||||
increment_nonce(c->crypto_connections[i].recv_nonce);
|
increment_nonce(c->crypto_connections[i].recv_nonce);
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user