mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:23:02 +01:00
merge
This commit is contained in:
commit
03f807f1cd
@ -320,7 +320,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);
|
||||
|
||||
|
93
src/main.c
93
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;
|
||||
|
||||
@ -116,65 +116,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
|
||||
@ -213,16 +154,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;
|
||||
}
|
||||
@ -391,21 +325,29 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (DATA_FILE == NULL ) {
|
||||
config_err = create_user_config_dir(user_config_dir);
|
||||
|
||||
if (DATA_FILE == NULL ) {
|
||||
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");
|
||||
} else {
|
||||
endwin();
|
||||
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
@ -415,7 +357,6 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(user_config_dir);
|
||||
|
||||
|
20
src/prompt.c
20
src/prompt.c
@ -119,7 +119,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]);
|
||||
@ -164,7 +164,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];
|
||||
|
||||
@ -280,16 +281,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);
|
||||
}
|
||||
|
||||
@ -555,7 +549,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')
|
||||
@ -673,7 +667,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user