From 91a2ef1d84cdb94923251a18a80cd8946e70c790 Mon Sep 17 00:00:00 2001 From: Jude <0b1100110@gmail.com> Date: Fri, 23 Aug 2013 11:41:54 -0500 Subject: [PATCH 1/4] warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] --- src/chat.c | 3 +-- src/prompt.c | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/chat.c b/src/chat.c index 30b8d95..d3d46c2 100644 --- a/src/chat.c +++ b/src/chat.c @@ -359,11 +359,10 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) else if (!strcmp(cmd, "/myid")) { char id[FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; - int i; uint8_t address[FRIEND_ADDRESS_SIZE]; getaddress(m, address); - for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { + for (size_t i = 0; i < FRIEND_ADDRESS_SIZE; i++) { char xx[3]; snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); diff --git a/src/prompt.c b/src/prompt.c index 887c486..0bae4d1 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -75,9 +75,8 @@ unsigned char *hex_string_to_bin(char hex_string[]) size_t len = strlen(hex_string); unsigned char *val = malloc(len); char *pos = hex_string; - int i; - for (i = 0; i < len; ++i, pos += 2) + for (size_t i = 0; i < len; ++i, pos += 2) sscanf(pos, "%2hhx", &val[i]); return val; @@ -123,7 +122,7 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) return; } - int i; + size_t i; for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) { xx[0] = id[2 * i]; @@ -332,7 +331,7 @@ static void execute(ToxWindow *self, Messenger *m, char *u_cmd) { int newlines = 0; char cmd[MAX_STR_SIZE] = {0}; - int i; + size_t i; for (i = 0; i < strlen(prompt_buf); ++i) { if (u_cmd[i] == '\n') @@ -478,7 +477,7 @@ static void prompt_onDraw(ToxWindow *self, Messenger *m) int x, y; getyx(self->window, y, x); (void) x; - int i; + size_t i; for (i = 0; i < (strlen(prompt_buf)); ++i) { if ((prompt_buf[i] == '\n') && (y != 0)) From 34fb7ba885ed9e9b91ad76004cdfc1d9a4709bbe Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Thu, 12 Sep 2013 17:31:10 +0000 Subject: [PATCH 2/4] Manually merged changes by 1100110 --- src/chat.c | 2 +- src/prompt.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/chat.c b/src/chat.c index fd1b885..2efc314 100644 --- a/src/chat.c +++ b/src/chat.c @@ -324,7 +324,7 @@ static void execute(ToxWindow *self, ChatContext *ctx, StatusBar *statusbar, Tox else if (!strcmp(cmd, "/myid")) { char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {'\0'}; - int i; + size_t i; uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; tox_getaddress(m, address); diff --git a/src/prompt.c b/src/prompt.c index 420bfef..dd09d8f 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -87,7 +87,7 @@ void prompt_onFriendRequest(ToxWindow *prompt, uint8_t *key, uint8_t *data, uint int n = add_req(key); wprintw(prompt->window, "\nFriend request from:\n"); - int i; + size_t i; for (i = 0; i < KEY_SIZE_BYTES; ++i) { wprintw(prompt->window, "%02x", key[i] & 0xff); @@ -121,7 +121,7 @@ unsigned char *hex_string_to_bin(char hex_string[]) } char *pos = hex_string; - int i; + size_t i; for (i = 0; i < len; ++i, pos += 2) sscanf(pos, "%2hhx", &val[i]); @@ -168,7 +168,8 @@ void cmd_add(ToxWindow *self, Tox *m, int argc, char **argv) char xx[3]; uint32_t x; uint8_t *msg; - int i, num; + size_t i; + int num; char *id = argv[1]; @@ -477,7 +478,7 @@ static void execute(ToxWindow *self, Tox *m, char *u_cmd) { int newlines = 0; char cmd[MAX_STR_SIZE] = {'\0'}; - int i; + size_t i; for (i = 0; i < strlen(prompt_buf); ++i) { if (u_cmd[i] == '\n') @@ -595,7 +596,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m) { curs_set(1); int x, y; - int i; + size_t i; getyx(self->window, y, x); for (i = 0; i < (strlen(prompt_buf)); ++i) { From 960bed12a89b59dd55ffd72a97212a2849c9c319 Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Sat, 14 Sep 2013 11:21:38 +0200 Subject: [PATCH 3/4] If the user gave a filename for the datafile, don't imply that they want to ignore the serverlist file. --- src/main.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index 262b154..3f79bcb 100644 --- a/src/main.c +++ b/src/main.c @@ -389,24 +389,16 @@ int main(int argc, char *argv[]) } } + config_err = create_user_config_dir(user_config_dir); if (DATA_FILE == NULL ) { - config_err = create_user_config_dir(user_config_dir); - if (config_err) { DATA_FILE = strdup("data"); - SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers"); } else { DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); - SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); - - if (DATA_FILE != NULL && SRVLIST_FILE != NULL) { + if (DATA_FILE != NULL) { strcpy(DATA_FILE, user_config_dir); strcat(DATA_FILE, CONFIGDIR); strcat(DATA_FILE, "data"); - - strcpy(SRVLIST_FILE, user_config_dir); - strcat(SRVLIST_FILE, CONFIGDIR); - strcat(SRVLIST_FILE, "DHTservers"); } else { endwin(); fprintf(stderr, "malloc() failed. Aborting...\n"); @@ -415,6 +407,21 @@ int main(int argc, char *argv[]) } } + if (config_err) { + SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers"); + } else { + SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); + if (SRVLIST_FILE != NULL) { + strcpy(SRVLIST_FILE, user_config_dir); + strcat(SRVLIST_FILE, CONFIGDIR); + strcat(SRVLIST_FILE, "DHTservers"); + } else { + endwin(); + fprintf(stderr, "malloc() failed. Aborting...\n"); + exit(EXIT_FAILURE); + } + } + free(user_config_dir); init_term(); From f78bca7269cb3fa4123261f3aed9aa3b5c8aab53 Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Sun, 15 Sep 2013 09:22:23 +0200 Subject: [PATCH 4/4] Adapted to ipv6-enabled tox main.c: - init_tox(): tox_new() => tox_new(TOX_ENABLE_IPV6_DEFAULT) (enables dual-stack per default) - resolv_addr(): killed - init_connection(): use tox_bootstrap_from_address(), which does the resolving prompt.c: - cmd_connect(): use tox_bootstrap_from_address(), which does the resolving --- src/main.c | 72 +++------------------------------------------------- src/prompt.c | 11 ++------ 2 files changed, 5 insertions(+), 78 deletions(-) diff --git a/src/main.c b/src/main.c index 3f79bcb..8a2db7f 100644 --- a/src/main.c +++ b/src/main.c @@ -90,7 +90,7 @@ static void init_term() static Tox *init_tox() { /* Init core */ - Tox *m = tox_new(); + Tox *m = tox_new(TOX_ENABLE_IPV6_DEFAULT); if (m == NULL) return NULL; @@ -114,65 +114,6 @@ static Tox *init_tox() return m; } -/* - resolve_addr(): - address should represent IPv4 or a hostname with A record - - returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i - returns 0 on failure - - TODO: Fix ipv6 support -*/ -uint32_t resolve_addr(const char *address) -{ - struct addrinfo *server = NULL; - struct addrinfo hints; - int rc; - uint32_t addr; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; // IPv4 only right now. - hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses. - -#ifdef _WIN32 - int res; - WSADATA wsa_data; - - res = WSAStartup(MAKEWORD(2, 2), &wsa_data); - if (res != 0) - { - return 0; - } -#endif - rc = getaddrinfo(address, "echo", &hints, &server); - - // Lookup failed. - if (rc != 0) { -#ifdef _WIN32 - WSACleanup(); -#endif - return 0; - } - - // IPv4 records only.. - if (server->ai_family != AF_INET) { - freeaddrinfo(server); -#ifdef _WIN32 - WSACleanup(); -#endif - return 0; - } - - - addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr; - - freeaddrinfo(server); -#ifdef _WIN32 - WSACleanup(); -#endif - return addr; -} - #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ #define MINLINE 70 #define MAXSERVERS 50 @@ -211,16 +152,9 @@ int init_connection(Tox *m) if (ip == NULL || port == NULL || key == NULL) return 3; - tox_IP_Port dht; - dht.port = htons(atoi(port)); - uint32_t resolved_address = resolve_addr(ip); - - if (resolved_address == 0) - return 0; - - dht.ip.i = resolved_address; uint8_t *binary_string = hex_string_to_bin(key); - tox_bootstrap(m, dht, binary_string); + tox_bootstrap_from_address(m, ip, TOX_ENABLE_IPV6_DEFAULT, + htons(atoi(port)), binary_string); free(binary_string); return 0; } diff --git a/src/prompt.c b/src/prompt.c index 6bf48e9..fb6fda8 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -285,16 +285,9 @@ void cmd_connect(ToxWindow *self, Tox *m, int argc, char **argv) return; } - dht.port = htons(atoi(port)); - uint32_t resolved_address = resolve_addr(ip); - - if (resolved_address == 0) { - return; - } - - dht.ip.i = resolved_address; uint8_t *binary_string = hex_string_to_bin(key); - tox_bootstrap(m, dht, binary_string); + tox_bootstrap_from_address(m, ip, TOX_ENABLE_IPV6_DEFAULT, + htons(atoi(port)), binary_string); free(binary_string); }