From baadd95b458e9cba041446282c67ede73199de5e Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 23 Aug 2013 23:03:44 +0200 Subject: [PATCH 1/5] Use new public api --- src/chat.c | 41 ++++++++-------- src/chat.h | 2 +- src/dhtstatus.c | 19 ++++---- src/friendlist.c | 21 ++++---- src/friendlist.h | 2 +- src/main.c | 92 +++++++++++++++++++++++++++--------- src/prompt.c | 113 +++++++++++++++++++++----------------------- src/toxic_windows.h | 28 ++++++----- src/windows.c | 23 +++++---- 9 files changed, 195 insertions(+), 146 deletions(-) diff --git a/src/chat.c b/src/chat.c index 30b8d95..9490233 100644 --- a/src/chat.c +++ b/src/chat.c @@ -13,7 +13,6 @@ #include #include -#include "Messenger.h" #include "network.h" #include "toxic_windows.h" @@ -31,7 +30,7 @@ typedef struct { } ChatContext; void print_help(ChatContext *self); -void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd); +void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd); struct tm *get_time(void) { @@ -42,10 +41,10 @@ struct tm *get_time(void) return timeinfo; } -static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, uint16_t len) +static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len) { ChatContext *ctx = (ChatContext *) self->x; - uint8_t nick[MAX_NAME_LENGTH] = {0}; + uint8_t nick[TOX_MAX_NAME_LENGTH] = {0}; struct tm *timeinfo = get_time(); if (ctx->friendnum != num) @@ -53,7 +52,7 @@ static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, getname(m, num, (uint8_t *) &nick); msg[len - 1] = '\0'; - nick[MAX_NAME_LENGTH - 1] = '\0'; + nick[TOX_MAX_NAME_LENGTH - 1] = '\0'; wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); @@ -67,7 +66,7 @@ static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, beep(); } -static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len) +static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uint16_t len) { ChatContext *ctx = (ChatContext *) self->x; struct tm *timeinfo = get_time(); @@ -176,7 +175,7 @@ static char *wc_to_char(wchar_t ch) return ret; } -static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key) +static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) { ChatContext *ctx = (ChatContext *) self->x; struct tm *timeinfo = get_time(); @@ -222,7 +221,7 @@ static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key) else { /* make sure the string has at least non-space character */ if (!string_is_empty(line)) { - uint8_t selfname[MAX_NAME_LENGTH]; + uint8_t selfname[TOX_MAX_NAME_LENGTH]; getself_name(m, selfname, sizeof(selfname)); wattron(ctx->history, COLOR_PAIR(2)); @@ -247,7 +246,7 @@ static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key) } } -void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) +void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) { if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { wclear(self->window); @@ -281,7 +280,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattroff(ctx->history, COLOR_PAIR(2)); - uint8_t selfname[MAX_NAME_LENGTH]; + uint8_t selfname[TOX_MAX_NAME_LENGTH]; int len = getself_name(m, selfname, sizeof(selfname)); char msg[MAX_STR_SIZE - len - 4]; snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t *) selfname, action); @@ -308,20 +307,20 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) } status++; - USERSTATUS status_kind; + TOX_USERSTATUS status_kind; if (!strncmp(status, "online", strlen("online"))) { - status_kind = USERSTATUS_NONE; + status_kind = TOX_USERSTATUS_NONE; status_text = "ONLINE"; } else if (!strncmp(status, "away", strlen("away"))) { - status_kind = USERSTATUS_AWAY; + status_kind = TOX_USERSTATUS_AWAY; status_text = "AWAY"; } else if (!strncmp(status, "busy", strlen("busy"))) { - status_kind = USERSTATUS_BUSY; + status_kind = TOX_USERSTATUS_BUSY; status_text = "BUSY"; } @@ -358,12 +357,12 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) } else if (!strcmp(cmd, "/myid")) { - char id[FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; + char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; int i; - uint8_t address[FRIEND_ADDRESS_SIZE]; + uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; getaddress(m, address); - for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) { char xx[3]; snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); @@ -383,7 +382,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) wprintw(ctx->history, "Invalid command.\n"); } -static void chat_onDraw(ToxWindow *self, Messenger *m) +static void chat_onDraw(ToxWindow *self, Tox *m) { curs_set(1); int x, y; @@ -394,7 +393,7 @@ static void chat_onDraw(ToxWindow *self, Messenger *m) wrefresh(self->window); } -static void chat_onInit(ToxWindow *self, Messenger *m) +static void chat_onInit(ToxWindow *self, Tox *m) { int x, y; ChatContext *ctx = (ChatContext *) self->x; @@ -424,7 +423,7 @@ void print_help(ChatContext *self) wattroff(self->history, COLOR_PAIR(2)); } -ToxWindow new_chat(Messenger *m, int friendnum) +ToxWindow new_chat(Tox *m, int friendnum) { ToxWindow ret; memset(&ret, 0, sizeof(ret)); @@ -437,7 +436,7 @@ ToxWindow new_chat(Messenger *m, int friendnum) ret.onStatusChange = &chat_onStatusChange; ret.onAction = &chat_onAction; - uint8_t nick[MAX_NAME_LENGTH] = {0}; + uint8_t nick[TOX_MAX_NAME_LENGTH] = {0}; getname(m, friendnum, (uint8_t *) &nick); snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); diff --git a/src/chat.h b/src/chat.h index 7599d46..d222b0d 100644 --- a/src/chat.h +++ b/src/chat.h @@ -1,6 +1,6 @@ #ifndef CHAT_H_6489PZ13 #define CHAT_H_6489PZ13 -ToxWindow new_chat(Messenger *m, int friendnum); +ToxWindow new_chat(Tox *m, int friendnum); #endif /* end of include guard: CHAT_H_6489PZ13 */ diff --git a/src/dhtstatus.c b/src/dhtstatus.c index 8bd98b7..5df5666 100644 --- a/src/dhtstatus.c +++ b/src/dhtstatus.c @@ -4,30 +4,28 @@ #include "dhtstatus.h" #include "string.h" -#include "network.h" -#include "DHT.h" typedef uint8_t ipbuf[3 * 4 + 3 + 1]; static int num_selected = 0; -static void printip(ipbuf buf, IP ip) +static void printip(ipbuf buf, tox_IP ip) { sprintf((char *)buf, "%u.%u.%u.%u", ip.c[0], ip.c[1], ip.c[2], ip.c[3]); } -static void dhtstatus_onKey(ToxWindow *self, Messenger *m, wint_t key) +static void dhtstatus_onKey(ToxWindow *self, Tox *m, wint_t key) { switch (key) { case KEY_UP: case 'k': if (--num_selected < 0) - num_selected = CLIENT_ID_SIZE - 1; + num_selected = TOX_CLIENT_ID_SIZE - 1; break; case KEY_DOWN: case 'j': - num_selected = (num_selected + 1) % CLIENT_ID_SIZE; + num_selected = (num_selected + 1) % TOX_CLIENT_ID_SIZE; break; case '\n': @@ -38,9 +36,10 @@ static void dhtstatus_onKey(ToxWindow *self, Messenger *m, wint_t key) } } -static void dhtstatus_onDraw(ToxWindow *self, Messenger *m) +static void dhtstatus_onDraw(ToxWindow *self, Tox *m) { - Client_data *close_clientlist = DHT_get_close_list(m->dht); + /* + Client_data *close_clientlist = DHT_get_close_list(m->dht); curs_set(0); werase(self->window); @@ -52,6 +51,7 @@ static void dhtstatus_onDraw(ToxWindow *self, Messenger *m) now); for (i = 0; i < 32; i++) { /*Number of nodes in closelist*/ + /* Client_data *client = close_clientlist + i; if (i == num_selected) wattron(self->window, COLOR_PAIR(3)); @@ -82,9 +82,10 @@ static void dhtstatus_onDraw(ToxWindow *self, Messenger *m) } wrefresh(self->window); + */ } -static void dhtstatus_onInit(ToxWindow *self, Messenger *m) +static void dhtstatus_onInit(ToxWindow *self, Tox *m) { } diff --git a/src/friendlist.c b/src/friendlist.c index 548c222..ec6d970 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -10,15 +10,14 @@ #include #include -#include "Messenger.h" -#include "network.h" +#include "tox.h" #include "friendlist.h" typedef struct { - uint8_t name[MAX_NAME_LENGTH]; - uint8_t status[MAX_STATUSMESSAGE_LENGTH]; + uint8_t name[TOX_MAX_NAME_LENGTH]; + uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; int num; int chatwin; } friend_t; @@ -28,7 +27,7 @@ static int num_friends = 0; static int num_selected = 0; -void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, uint16_t len) +void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len) { if (num >= num_friends) return; @@ -40,7 +39,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t len) { - if (len >= MAX_NAME_LENGTH || num >= num_friends) + if (len >= TOX_MAX_NAME_LENGTH || num >= num_friends) return; memcpy((char *) &friends[num].name, (char *) str, len); @@ -49,14 +48,14 @@ void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t le void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t len) { - if (len >= MAX_STATUSMESSAGE_LENGTH || num >= num_friends) + if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num >= num_friends) return; memcpy((char *) &friends[num].status, (char *) str, len); friends[num].status[len] = 0; } -int friendlist_onFriendAdded(Messenger *m, int num) +int friendlist_onFriendAdded(Tox *m, int num) { if (num_friends == MAX_FRIENDS_NUM) return -1; @@ -69,7 +68,7 @@ int friendlist_onFriendAdded(Messenger *m, int num) return 0; } -static void friendlist_onKey(ToxWindow *self, Messenger *m, wint_t key) +static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) { if (key == KEY_UP) { if (--num_selected < 0) @@ -87,7 +86,7 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, wint_t key) } } -static void friendlist_onDraw(ToxWindow *self, Messenger *m) +static void friendlist_onDraw(ToxWindow *self, Tox *m) { curs_set(0); werase(self->window); @@ -125,7 +124,7 @@ void disable_chatwin(int f_num) friends[f_num].chatwin = -1; } -static void friendlist_onInit(ToxWindow *self, Messenger *m) +static void friendlist_onInit(ToxWindow *self, Tox *m) { } diff --git a/src/friendlist.h b/src/friendlist.h index 3a5d393..26c9106 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -5,7 +5,7 @@ #include "chat.h" ToxWindow new_friendlist(); -int friendlist_onFriendAdded(Messenger *m, int num); +int friendlist_onFriendAdded(Tox *m, int num); void disable_chatwin(int f_num); #endif /* end of include guard: FRIENDLIST_H_53I41IM */ diff --git a/src/main.c b/src/main.c index 688cf5c..b3005cb 100644 --- a/src/main.c +++ b/src/main.c @@ -14,16 +14,18 @@ #include #include #include +#include +#include #ifdef _win32 #include #else #include #include +#include #endif -#include "Messenger.h" -#include "network.h" +#include "tox.h" #include "configdir.h" #include "toxic_windows.h" @@ -34,6 +36,50 @@ char *DATA_FILE = NULL; char *SRVLIST_FILE = NULL; +static Tox *tox; + + +/* +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. + + rc = getaddrinfo(address, "echo", &hints, &server); + + // Lookup failed. + if (rc != 0) { + return 0; + } + + // IPv4 records only.. + if (server->ai_family != AF_INET) { + freeaddrinfo(server); + return 0; + } + + + addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr; + + freeaddrinfo(server); + return addr; +} + void on_window_resize(int sig) { endwin(); @@ -68,10 +114,10 @@ static void init_term() refresh(); } -static Messenger *init_tox() +static Tox *init_tox() { /* Init core */ - Messenger *m = initMessenger(); + Tox *m = tox_new(); /* Callbacks */ m_callback_friendrequest(m, on_request, NULL); @@ -136,11 +182,11 @@ uint32_t resolve_addr(const char *address) #define MAXSERVERS 50 /* Connects to a random DHT server listed in the DHTservers file */ -int init_connection(Messenger *m) +int init_connection(Tox *m) { FILE *fp = NULL; - if (DHT_isconnected(m->dht)) + if (tox_isconnected(m)) return 0; fp = fopen(SRVLIST_FILE, "r"); @@ -172,7 +218,7 @@ int init_connection(Messenger *m) if (!ip || !port || !key) return 3; - IP_Port dht; + tox_IP_Port dht; dht.port = htons(atoi(port)); uint32_t resolved_address = resolve_addr(ip); @@ -180,19 +226,19 @@ int init_connection(Messenger *m) return 0; dht.ip.i = resolved_address; - unsigned char *binary_string = hex_string_to_bin(key); - DHT_bootstrap(m->dht, dht, binary_string); + uint8_t *binary_string = hex_string_to_bin(key); + tox_bootstrap(m, dht, binary_string); free(binary_string); return 0; } -static void do_tox(Messenger *m, ToxWindow *prompt) +static void do_tox(Tox *m, ToxWindow *prompt) { static int conn_try = 0; static int conn_err = 0; static bool dht_on = false; - if (!dht_on && !DHT_isconnected(m->dht) && !(conn_try++ % 100)) { + if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) { if (!conn_err) { conn_err = init_connection(m); wprintw(prompt->window, "\nEstablishing connection...\n"); @@ -200,15 +246,15 @@ static void do_tox(Messenger *m, ToxWindow *prompt) if (conn_err) wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err); } - } else if (!dht_on && DHT_isconnected(m->dht)) { + } else if (!dht_on && tox_isconnected(m)) { dht_on = true; wprintw(prompt->window, "\nDHT connected.\n"); - } else if (dht_on && !DHT_isconnected(m->dht)) { + } else if (dht_on && !tox_isconnected(m)) { dht_on = false; wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); } - doMessenger(m); + tox_do(m); } int f_loadfromfile; @@ -220,7 +266,7 @@ int f_loadfromfile; * Return 2 opening path failed * Return 3 fwrite failed */ -int store_data(Messenger *m, char *path) +int store_data(Tox *m, char *path) { if (f_loadfromfile == 0) /*If file loading/saving is disabled*/ return 0; @@ -229,14 +275,14 @@ int store_data(Messenger *m, char *path) size_t len; uint8_t *buf; - len = Messenger_size(m); + len = tox_size(m); buf = malloc(len); if (buf == NULL) { return 1; } - Messenger_save(m, buf); + tox_save(m, buf); fd = fopen(path, "w"); @@ -256,7 +302,7 @@ int store_data(Messenger *m, char *path) return 0; } -static void load_data(Messenger *m, char *path) +static void load_data(Tox *m, char *path) { if (f_loadfromfile == 0) /*If file loading/saving is disabled*/ return; @@ -287,12 +333,14 @@ static void load_data(Messenger *m, char *path) exit(1); } - Messenger_load(m, buf, len); + tox_load(m, buf, len); uint32_t i; - for (i = 0; i < m->numfriends; i++) { + char name[TOX_MAX_NAME_LENGTH]; + while (tox_getname(m, i, (uint8_t *)name) != -1) { on_friendadded(m, i); + i++; } free(buf); @@ -354,7 +402,7 @@ int main(int argc, char *argv[]) free(user_config_dir); init_term(); - Messenger *m = init_tox(); + Tox *m = init_tox(); ToxWindow *prompt = init_windows(m); if (f_loadfromfile) @@ -382,7 +430,7 @@ int main(int argc, char *argv[]) draw_active_window(m); } - cleanupMessenger(m); + tox_kill(m); free(DATA_FILE); free(SRVLIST_FILE); return 0; diff --git a/src/prompt.c b/src/prompt.c index 887c486..50e0d4c 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -10,40 +10,37 @@ #include #include -#include "Messenger.h" -#include "network.h" - #include "prompt.h" extern char *DATA_FILE; -extern int store_data(Messenger *m, char *path); +extern int store_data(Tox *m, char *path); -uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX +uint8_t pending_requests[MAX_STR_SIZE][TOX_CLIENT_ID_SIZE]; // XXX uint8_t num_requests = 0; // XXX static char prompt_buf[MAX_STR_SIZE] = {0}; static int prompt_buf_pos = 0; /* commands */ -void cmd_accept(ToxWindow *, Messenger *m, char **); -void cmd_add(ToxWindow *, Messenger *m, char **); -void cmd_clear(ToxWindow *, Messenger *m, char **); -void cmd_connect(ToxWindow *, Messenger *m, char **); -void cmd_help(ToxWindow *, Messenger *m, char **); -void cmd_msg(ToxWindow *, Messenger *m, char **); -void cmd_myid(ToxWindow *, Messenger *m, char **); -void cmd_nick(ToxWindow *, Messenger *m, char **); -void cmd_mynick(ToxWindow *, Messenger *m, char **); -void cmd_quit(ToxWindow *, Messenger *m, char **); -void cmd_status(ToxWindow *, Messenger *m, char **); -void cmd_statusmsg(ToxWindow *, Messenger *m, char **); +void cmd_accept(ToxWindow *, Tox *m, char **); +void cmd_add(ToxWindow *, Tox *m, char **); +void cmd_clear(ToxWindow *, Tox *m, char **); +void cmd_connect(ToxWindow *, Tox *m, char **); +void cmd_help(ToxWindow *, Tox *m, char **); +void cmd_msg(ToxWindow *, Tox *m, char **); +void cmd_myid(ToxWindow *, Tox *m, char **); +void cmd_nick(ToxWindow *, Tox *m, char **); +void cmd_mynick(ToxWindow *, Tox *m, char **); +void cmd_quit(ToxWindow *, Tox *m, char **); +void cmd_status(ToxWindow *, Tox *m, char **); +void cmd_statusmsg(ToxWindow *, Tox *m, char **); #define NUM_COMMANDS 14 static struct { char *name; int numargs; - void (*func)(ToxWindow *, Messenger *m, char **); + void (*func)(ToxWindow *, Tox *m, char **); } commands[] = { { "accept", 1, cmd_accept }, { "add", 1, cmd_add }, @@ -64,7 +61,7 @@ static struct { // XXX: int add_req(uint8_t *public_key) { - memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); + memcpy(pending_requests[num_requests], public_key, TOX_CLIENT_ID_SIZE); ++num_requests; return num_requests - 1; } @@ -83,7 +80,7 @@ unsigned char *hex_string_to_bin(char hex_string[]) return val; } -void cmd_accept(ToxWindow *self, Messenger *m, char **args) +void cmd_accept(ToxWindow *self, Tox *m, char **args) { int num = atoi(args[1]); @@ -102,9 +99,9 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args) } } -void cmd_add(ToxWindow *self, Messenger *m, char **args) +void cmd_add(ToxWindow *self, Tox *m, char **args) { - uint8_t id_bin[FRIEND_ADDRESS_SIZE]; + uint8_t id_bin[TOX_FRIEND_ADDRESS_SIZE]; char xx[3]; uint32_t x; char *id = args[1]; @@ -118,14 +115,14 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) if (!msg) msg = ""; - if (strlen(id) != 2 * FRIEND_ADDRESS_SIZE) { + if (strlen(id) != 2 * TOX_FRIEND_ADDRESS_SIZE) { wprintw(self->window, "Invalid ID length.\n"); return; } int i; - for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) { + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) { xx[0] = id[2 * i]; xx[1] = id[2 * i + 1]; xx[2] = '\0'; @@ -138,38 +135,38 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) id_bin[i] = x; } - for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) { id[i] = toupper(id[i]); } int num = m_addfriend(m, id_bin, (uint8_t *) msg, strlen(msg) + 1); switch (num) { - case FAERR_TOOLONG: + case TOX_FAERR_TOOLONG: wprintw(self->window, "Message is too long.\n"); break; - case FAERR_NOMESSAGE: + case TOX_FAERR_NOMESSAGE: wprintw(self->window, "Please add a message to your request.\n"); break; - case FAERR_OWNKEY: + case TOX_FAERR_OWNKEY: wprintw(self->window, "That appears to be your own ID.\n"); break; - case FAERR_ALREADYSENT: + case TOX_FAERR_ALREADYSENT: wprintw(self->window, "Friend request already sent.\n"); break; - case FAERR_UNKNOWN: + case TOX_FAERR_UNKNOWN: wprintw(self->window, "Undefined error when adding friend.\n"); break; - case FAERR_BADCHECKSUM: + case TOX_FAERR_BADCHECKSUM: wprintw(self->window, "Bad checksum in address.\n"); break; - case FAERR_SETNEWNOSPAM: + case TOX_FAERR_SETNEWNOSPAM: wprintw(self->window, "Nospam was different.\n"); break; @@ -180,14 +177,14 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) } } -void cmd_clear(ToxWindow *self, Messenger *m, char **args) +void cmd_clear(ToxWindow *self, Tox *m, char **args) { wclear(self->window); } -void cmd_connect(ToxWindow *self, Messenger *m, char **args) +void cmd_connect(ToxWindow *self, Tox *m, char **args) { - IP_Port dht; + tox_IP_Port dht; char *ip = args[1]; char *port = args[2]; char *key = args[3]; @@ -205,18 +202,18 @@ void cmd_connect(ToxWindow *self, Messenger *m, char **args) } dht.ip.i = resolved_address; - unsigned char *binary_string = hex_string_to_bin(key); - DHT_bootstrap(m->dht, dht, binary_string); + uint8_t *binary_string = hex_string_to_bin(key); + tox_bootstrap(m, dht, binary_string); free(binary_string); } -void cmd_quit(ToxWindow *self, Messenger *m, char **args) +void cmd_quit(ToxWindow *self, Tox *m, char **args) { endwin(); exit(0); } -void cmd_help(ToxWindow *self, Messenger *m, char **args) +void cmd_help(ToxWindow *self, Tox *m, char **args) { wclear(self->window); wattron(self->window, COLOR_PAIR(2) | A_BOLD); @@ -242,7 +239,7 @@ void cmd_help(ToxWindow *self, Messenger *m, char **args) wattroff(self->window, COLOR_PAIR(2)); } -void cmd_msg(ToxWindow *self, Messenger *m, char **args) +void cmd_msg(ToxWindow *self, Tox *m, char **args) { char *id = args[1]; char *msg = args[2]; @@ -253,14 +250,14 @@ void cmd_msg(ToxWindow *self, Messenger *m, char **args) wprintw(self->window, "Message successfully sent.\n"); } -void cmd_myid(ToxWindow *self, Messenger *m, char **args) +void cmd_myid(ToxWindow *self, Tox *m, char **args) { - char id[FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; + char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0}; size_t i; - uint8_t address[FRIEND_ADDRESS_SIZE]; + uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; getaddress(m, address); - for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) { + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) { char xx[3]; snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); @@ -269,7 +266,7 @@ void cmd_myid(ToxWindow *self, Messenger *m, char **args) wprintw(self->window, "%s\n", id); } -void cmd_nick(ToxWindow *self, Messenger *m, char **args) +void cmd_nick(ToxWindow *self, Tox *m, char **args) { char *nick = args[1]; setname(m, (uint8_t *) nick, strlen(nick) + 1); @@ -280,29 +277,29 @@ void cmd_nick(ToxWindow *self, Messenger *m, char **args) } } -void cmd_mynick(ToxWindow *self, Messenger *m, char **args) +void cmd_mynick(ToxWindow *self, Tox *m, char **args) { - uint8_t *nick = malloc(m->name_length); - getself_name(m, nick, m->name_length); + uint8_t *nick = malloc(TOX_MAX_NAME_LENGTH); + tox_getselfname(m, nick, TOX_MAX_NAME_LENGTH); wprintw(self->window, "Current nickname: %s\n", nick); free(nick); } -void cmd_status(ToxWindow *self, Messenger *m, char **args) +void cmd_status(ToxWindow *self, Tox *m, char **args) { char *status = args[1]; char *status_text; - USERSTATUS status_kind; + TOX_USERSTATUS status_kind; if (!strncmp(status, "online", strlen("online"))) { - status_kind = USERSTATUS_NONE; + status_kind = TOX_USERSTATUS_NONE; status_text = "ONLINE"; } else if (!strncmp(status, "away", strlen("away"))) { - status_kind = USERSTATUS_AWAY; + status_kind = TOX_USERSTATUS_AWAY; status_text = "AWAY"; } else if (!strncmp(status, "busy", strlen("busy"))) { - status_kind = USERSTATUS_BUSY; + status_kind = TOX_USERSTATUS_BUSY; status_text = "BUSY"; } else { wprintw(self->window, "Invalid status.\n"); @@ -321,14 +318,14 @@ void cmd_status(ToxWindow *self, Messenger *m, char **args) } } -void cmd_statusmsg(ToxWindow *self, Messenger *m, char **args) +void cmd_statusmsg(ToxWindow *self, Tox *m, char **args) { char *msg = args[1]; m_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); wprintw(self->window, "Status set to: %s\n", msg); } -static void execute(ToxWindow *self, Messenger *m, char *u_cmd) +static void execute(ToxWindow *self, Tox *m, char *u_cmd) { int newlines = 0; char cmd[MAX_STR_SIZE] = {0}; @@ -436,7 +433,7 @@ static void execute(ToxWindow *self, Messenger *m, char *u_cmd) wprintw(self->window, "Invalid command.\n"); } -static void prompt_onKey(ToxWindow *self, Messenger *m, wint_t key) +static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key) { /* Add printable characters to line */ if (isprint(key)) { @@ -472,7 +469,7 @@ static void prompt_onKey(ToxWindow *self, Messenger *m, wint_t key) } } -static void prompt_onDraw(ToxWindow *self, Messenger *m) +static void prompt_onDraw(ToxWindow *self, Tox *m) { curs_set(1); int x, y; @@ -493,7 +490,7 @@ static void prompt_onDraw(ToxWindow *self, Messenger *m) wrefresh(self->window); } -static void prompt_onInit(ToxWindow *self, Messenger *m) +static void prompt_onInit(ToxWindow *self, Tox *m) { scrollok(self->window, 1); cmd_help(self, m, NULL); diff --git a/src/toxic_windows.h b/src/toxic_windows.h index 4b1abf1..34edf6f 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -9,7 +9,9 @@ #include #include #include -#include "Messenger.h" + +#include "tox.h" + #define MAX_WINDOWS_NUM 32 #define MAX_FRIENDS_NUM 100 #define MAX_STR_SIZE 256 @@ -25,14 +27,14 @@ typedef struct ToxWindow_ ToxWindow; struct ToxWindow_ { - void(*onKey)(ToxWindow *, Messenger *, wint_t); - void(*onDraw)(ToxWindow *, Messenger *); - void(*onInit)(ToxWindow *, Messenger *); + void(*onKey)(ToxWindow *, Tox *, wint_t); + void(*onDraw)(ToxWindow *, Tox *); + void(*onInit)(ToxWindow *, Tox *); void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t); - void(*onMessage)(ToxWindow *, Messenger *, int, uint8_t *, uint16_t); + void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t); void(*onNickChange)(ToxWindow *, int, uint8_t *, uint16_t); void(*onStatusChange)(ToxWindow *, int, uint8_t *, uint16_t); - void(*onAction)(ToxWindow *, Messenger *, int, uint8_t *, uint16_t); + void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t); char title[256]; void *x; @@ -42,14 +44,14 @@ struct ToxWindow_ { }; void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata); -void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); -void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); -void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); -void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); -void on_friendadded(Messenger *m, int friendnumber); +void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); +void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); +void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); +void on_statuschange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); +void on_friendadded(Tox *m, int friendnumber); ToxWindow *init_windows(); -void draw_active_window(Messenger *m); -int add_window(Messenger *m, ToxWindow w); +void draw_active_window(Tox *m); +int add_window(Tox *m, ToxWindow w); void del_window(ToxWindow *w); void set_active_window(int ch); #endif diff --git a/src/windows.c b/src/windows.c index 6ce234e..d0852e3 100644 --- a/src/windows.c +++ b/src/windows.c @@ -2,18 +2,21 @@ #include "config.h" #endif +#include +#include + #include "friendlist.h" #include "prompt.h" #include "dhtstatus.h" #include "toxic_windows.h" extern char *DATA_FILE; -extern int store_data(Messenger *m, char *path); +extern int store_data(Tox *m, char *path); static ToxWindow windows[MAX_WINDOWS_NUM]; static ToxWindow *active_window; static ToxWindow *prompt; -static Messenger *m; +static Tox *m; /* CALLBACKS START */ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) @@ -36,7 +39,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userd } } -void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) +void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { int i; @@ -46,7 +49,7 @@ void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length } } -void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) +void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { int i; @@ -56,7 +59,7 @@ void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, } } -void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) +void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); int i; @@ -67,7 +70,7 @@ void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t len } } -void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) +void on_statuschange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); int i; @@ -78,17 +81,17 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l } } -void on_friendadded(Messenger *m, int friendnumber) +void on_friendadded(Tox *m, int friendnumber) { friendlist_onFriendAdded(m, friendnumber); if (store_data(m, DATA_FILE)) { - wprintw(prompt->window, "\nCould not store Messenger data\n"); + wprintw(prompt->window, "\nCould not store Tox data\n"); } } /* CALLBACKS END */ -int add_window(Messenger *m, ToxWindow w) +int add_window(Tox *m, ToxWindow w) { if (LINES < 2) return -1; @@ -226,7 +229,7 @@ void prepare_window(WINDOW *w) wresize(w, LINES - 2, COLS); } -void draw_active_window(Messenger *m) +void draw_active_window(Tox *m) { ToxWindow *a = active_window; From 59c628e4b1a1d1979d60e8b612e0fea996177f5b Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 23 Aug 2013 23:52:07 +0200 Subject: [PATCH 2/5] Remove duplicated function resolve_addr --- src/main.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/main.c b/src/main.c index b3005cb..d02b86a 100644 --- a/src/main.c +++ b/src/main.c @@ -38,48 +38,6 @@ char *SRVLIST_FILE = NULL; static Tox *tox; - -/* -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. - - rc = getaddrinfo(address, "echo", &hints, &server); - - // Lookup failed. - if (rc != 0) { - return 0; - } - - // IPv4 records only.. - if (server->ai_family != AF_INET) { - freeaddrinfo(server); - return 0; - } - - - addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr; - - freeaddrinfo(server); - return addr; -} - void on_window_resize(int sig) { endwin(); From 0f97e37fa30271bd0371c68a5ea5dd6f02636fe0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 23 Aug 2013 23:52:35 +0200 Subject: [PATCH 3/5] Remove unused global variable --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index d02b86a..a63411e 100644 --- a/src/main.c +++ b/src/main.c @@ -36,8 +36,6 @@ char *DATA_FILE = NULL; char *SRVLIST_FILE = NULL; -static Tox *tox; - void on_window_resize(int sig) { endwin(); From 2db69f0fd60ae476df7bebaaebc604c10c48d8a2 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 24 Aug 2013 00:21:01 +0200 Subject: [PATCH 4/5] Use tox_ instead of m_ functions --- src/chat.c | 18 ++++++++---------- src/friendlist.c | 2 +- src/main.c | 18 +++++++++--------- src/prompt.c | 12 ++++++------ 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/chat.c b/src/chat.c index 9490233..8e4ae66 100644 --- a/src/chat.c +++ b/src/chat.c @@ -13,8 +13,6 @@ #include #include -#include "network.h" - #include "toxic_windows.h" #include "friendlist.h" #include "chat.h" @@ -50,7 +48,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1 if (ctx->friendnum != num) return; - getname(m, num, (uint8_t *) &nick); + tox_getname(m, num, (uint8_t *) &nick); msg[len - 1] = '\0'; nick[TOX_MAX_NAME_LENGTH - 1] = '\0'; @@ -232,7 +230,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) wattroff(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "%s\n", line); - if (m_sendmessage(m, ctx->friendnum, (uint8_t *) line, strlen(line) + 1) == 0) { + if (tox_sendmessage(m, ctx->friendnum, (uint8_t *) line, strlen(line) + 1) == 0) { wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, " * Failed to send message.\n"); wattroff(ctx->history, COLOR_PAIR(3)); @@ -289,7 +287,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) wprintw(ctx->history, msg); wattroff(ctx->history, COLOR_PAIR(5)); - if (m_sendaction(m, ctx->friendnum, (uint8_t *) msg, strlen(msg) + 1) < 0) { + if (tox_sendaction(m, ctx->friendnum, (uint8_t *) msg, strlen(msg) + 1) < 0) { wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, " * Failed to send action\n"); wattroff(ctx->history, COLOR_PAIR(3)); @@ -332,12 +330,12 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) msg = strchr(status, ' '); if (msg == NULL) { - m_set_userstatus(m, status_kind); + tox_set_userstatus(m, status_kind); wprintw(ctx->history, "Status set to: %s\n", status_text); } else { msg++; - m_set_userstatus(m, status_kind); - m_set_statusmessage(m, ( uint8_t *) msg, strlen(msg) + 1); + tox_set_userstatus(m, status_kind); + tox_set_statusmessage(m, ( uint8_t *) msg, strlen(msg) + 1); wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); } } @@ -352,7 +350,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) } nick++; - setname(m, (uint8_t *) nick, strlen(nick) + 1); + tox_setname(m, (uint8_t *) nick, strlen(nick) + 1); wprintw(ctx->history, "Nickname set to: %s\n", nick); } @@ -437,7 +435,7 @@ ToxWindow new_chat(Tox *m, int friendnum) ret.onAction = &chat_onAction; uint8_t nick[TOX_MAX_NAME_LENGTH] = {0}; - getname(m, friendnum, (uint8_t *) &nick); + tox_getname(m, friendnum, (uint8_t *) &nick); snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); diff --git a/src/friendlist.c b/src/friendlist.c index ec6d970..b198656 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -61,7 +61,7 @@ int friendlist_onFriendAdded(Tox *m, int num) return -1; friends[num_friends].num = num; - getname(m, num, friends[num_friends].name); + tox_getname(m, num, friends[num_friends].name); strcpy((char *) friends[num_friends].name, "unknown"); strcpy((char *) friends[num_friends].status, "unknown"); friends[num_friends++].chatwin = -1; diff --git a/src/main.c b/src/main.c index a63411e..390099a 100644 --- a/src/main.c +++ b/src/main.c @@ -76,19 +76,19 @@ static Tox *init_tox() Tox *m = tox_new(); /* Callbacks */ - m_callback_friendrequest(m, on_request, NULL); - m_callback_friendmessage(m, on_message, NULL); - m_callback_namechange(m, on_nickchange, NULL); - m_callback_statusmessage(m, on_statuschange, NULL); - m_callback_action(m, on_action, NULL); + tox_callback_friendrequest(m, on_request, NULL); + tox_callback_friendmessage(m, on_message, NULL); + tox_callback_namechange(m, on_nickchange, NULL); + tox_callback_statusmessage(m, on_statuschange, NULL); + tox_callback_action(m, on_action, NULL); #ifdef __linux__ - setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy")); + tox_setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy")); #elif defined(WIN32) - setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux")); + tox_setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux")); #elif defined(__APPLE__) - setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); //This used to users of other Unixes are hipsters + tox_setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); //This used to users of other Unixes are hipsters #else - setname(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4")); + tox_setname(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4")); #endif return m; } diff --git a/src/prompt.c b/src/prompt.c index 50e0d4c..94dbe52 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -244,7 +244,7 @@ void cmd_msg(ToxWindow *self, Tox *m, char **args) char *id = args[1]; char *msg = args[2]; - if (m_sendmessage(m, atoi(id), (uint8_t *) msg, strlen(msg) + 1) == 0) + if (tox_sendmessage(m, atoi(id), (uint8_t *) msg, strlen(msg) + 1) == 0) wprintw(self->window, "Error occurred while sending message.\n"); else wprintw(self->window, "Message successfully sent.\n"); @@ -269,7 +269,7 @@ void cmd_myid(ToxWindow *self, Tox *m, char **args) void cmd_nick(ToxWindow *self, Tox *m, char **args) { char *nick = args[1]; - setname(m, (uint8_t *) nick, strlen(nick) + 1); + tox_setname(m, (uint8_t *) nick, strlen(nick) + 1); wprintw(self->window, "Nickname set to: %s\n", nick); if (store_data(m, DATA_FILE)) { @@ -309,11 +309,11 @@ void cmd_status(ToxWindow *self, Tox *m, char **args) char *msg = args[2]; if (msg == NULL) { - m_set_userstatus(m, status_kind); + tox_set_userstatus(m, status_kind); wprintw(self->window, "Status set to: %s\n", status_text); } else { - m_set_userstatus(m, status_kind); - m_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); + tox_set_userstatus(m, status_kind); + tox_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); } } @@ -321,7 +321,7 @@ void cmd_status(ToxWindow *self, Tox *m, char **args) void cmd_statusmsg(ToxWindow *self, Tox *m, char **args) { char *msg = args[1]; - m_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); + tox_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); wprintw(self->window, "Status set to: %s\n", msg); } From 6f9813ceeeeed64ca896676ce29cec7e92a901f4 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 24 Aug 2013 00:21:39 +0200 Subject: [PATCH 5/5] Use tox.h and tox_new for toxcore discovery --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 35b17cd..2226f9f 100644 --- a/configure.ac +++ b/configure.ac @@ -252,7 +252,7 @@ CPPFLAGS_SAVE="$CPPFLAGS" if test -n "$LIBTOXCORE_SEARCH_HEADERS"; then CFLAGS="$CFLAGS -I$LIBTOXCORE_SEARCH_HEADERS $LIBSODIUM_CFLAGS" CPPFLAGS="$CPPFLAGS -I$LIBTOXCORE_SEARCH_HEADERS $LIBSODIUM_CFLAGS" - AC_CHECK_HEADER([Messenger.h], + AC_CHECK_HEADER([tox.h], [ LIBTOXCORE_CFLAGS="-I$LIBTOXCORE_SEARCH_HEADERS" ], @@ -263,7 +263,7 @@ if test -n "$LIBTOXCORE_SEARCH_HEADERS"; then else CFLAGS="$CFLAGS $LIBSODIUM_CFLAGS" CPPFLAGS="$CPPFLAGS $LIBSODIUM_CFLAGS" - AC_CHECK_HEADER([Messenger.h], + AC_CHECK_HEADER([tox.h], [], [ AC_MSG_ERROR([headers for the toxcore library were not found on your system]) @@ -279,7 +279,7 @@ LIBTOXCORE_LDFLAGS= LDFLAGS_SAVE="$LDFLAGS" if test -n "$LIBTOXCORE_SEARCH_LIBS"; then LDFLAGS="$LDFLAGS $LIBSODIUM_LDFLAGS -L$LIBTOXCORE_SEARCH_LIBS $LIBSODIUM_LIBS" - AC_CHECK_LIB([toxcore], [initMessenger], + AC_CHECK_LIB([toxcore], [tox_new], [ LIBTOXCORE_LDFLAGS="-L$LIBTOXCORE_SEARCH_LIBS" LIBTOXCORE_LIBS="-ltoxcore" @@ -290,7 +290,7 @@ if test -n "$LIBTOXCORE_SEARCH_LIBS"; then ) else LDFLAGS="$LDFLAGS $LIBSODIUM_LDFLAGS $LIBSODIUM_LIBS" - AC_CHECK_LIB([toxcore], [initMessenger], + AC_CHECK_LIB([toxcore], [tox_new], [], [ AC_MSG_ERROR([required library toxcore was not found on your system])