diff --git a/build/Makefile.am b/build/Makefile.am index a670d9b..83437e6 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -41,3 +41,12 @@ toxic_LDADD = $(LIBTOXCORE_LDFLAGS) \ $(LIBSODIUM_LIBS) \ $(WINSOCK2_LIBS) + +# For audio support +if BUILD_AV +toxic_SOURCES += $(top_srcdir)/src/audio_call.c \ + $(top_srcdir)/src/audio_call.h + +toxic_CFLAGS += $(LIBTOXAV_CFLAGS) +toxic_LDADD += $(LIBTOXAV_LIBS) +endif \ No newline at end of file diff --git a/configure.ac b/configure.ac index 4fcd5d1..28430e3 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.65]) -AC_INIT([toxic], [0.2.4], [http://tox.im/]) +AC_INIT([toxic], [0.2.5], [https://tox.im/]) AC_CONFIG_AUX_DIR(configure_aux) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([config.h]) @@ -381,6 +381,69 @@ if test "x$LIBTOXCORE_FOUND" = "xno"; then AC_SUBST(LIBTOXCORE_LDFLAGS) fi + +#### +#### A/V Stuff + +AV_SEARCH_DIR= +BUILD_AV="yes" + +AC_ARG_WITH(libtoxav-prefix, + AC_HELP_STRING([--with-libtoxav-prefix=DIR], + [search for libtoxav in DIR, i.e. look for libraries in + DIR/lib and for headers in DIR/include]), + [ + AV_SEARCH_DIR="$withval" + ] +) + +if test -n "$AV_SEARCH_DIR"; then + CFLAGS="$CFLAGS -I$AV_SEARCH_DIR/include" + CPPFLAGS="$CPPFLAGS -I$AV_SEARCH_DIR/include" + LDFLAGS="$LDFLAGS -L$AV_SEARCH_DIR/lib" + export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$AV_SEARCH_DIR/lib/pkgconfig +fi + +# Check if specified enable +AC_ARG_ENABLE([av], + [AC_HELP_STRING([--disable-av], [build AV support libraries (default: auto)]) ], + [ + if test "x$enableval" = "xno"; then + BUILD_AV="no" + elif test "x$enableval" = "xyes"; then + BUILD_AV="yes" + fi + ] +) + +# Check for A/V library + +if test "x$BUILD_AV" = "xyes"; then + export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig + + PKG_CHECK_EXISTS([libtoxav], + [ + AC_CHECK_HEADER([tox/toxav.h], + [ + # Place define for audio support + AC_DEFINE([_SUPPORT_AUDIO], [], [If audio supported]) + AC_MSG_NOTICE([Building with audio support]) + ], + [ + AC_MSG_NOTICE([No A/V headers; disabling A/V support]) + BUILD_AV="no" + ],) + ], + [ + AC_MSG_NOTICE([No A/V library; disabling A/V support]) + ]) +fi + +AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes") + + + + TOXIC_VERSION="$PACKAGE_VERSION" AC_PATH_PROG([GIT], [git], [no]) if test "x$GIT" != "xno"; then diff --git a/src/chat.c b/src/chat.c index efec9fa..d89bfdd 100644 --- a/src/chat.c +++ b/src/chat.c @@ -547,7 +547,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m) self->x = x2; /* Truncate note if it doesn't fit in statusbar */ - uint16_t maxlen = x2 - getcurx(statusbar->topline) - 4; + uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 7; if (statusbar->statusmsg_len > maxlen) { statusbar->statusmsg[maxlen] = '\0'; statusbar->statusmsg_len = maxlen; @@ -559,7 +559,16 @@ static void chat_onDraw(ToxWindow *self, Tox *m) wattroff(statusbar->topline, A_BOLD); } - wprintw(statusbar->topline, "\n"); + wclrtoeol(statusbar->topline); + wmove(statusbar->topline, 0, x2 - (KEY_IDENT_DIGITS * 2) - 3); + wprintw(statusbar->topline, "{"); + + int i; + + for (i = 0; i < KEY_IDENT_DIGITS; ++i) + wprintw(statusbar->topline, "%02X", friends[self->num].pub_key[i] & 0xff); + + wprintw(statusbar->topline, "}\n"); mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2); } diff --git a/src/friendlist.c b/src/friendlist.c index f569405..7e22091 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -130,6 +130,7 @@ static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort friends[i].online = false; friends[i].status = TOX_USERSTATUS_NONE; friends[i].namelength = tox_get_name(m, num, friends[i].name); + tox_get_client_id(m, num, friends[i].pub_key); if (friends[i].namelength == -1 || friends[i].name[0] == '\0') { strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME); @@ -363,7 +364,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) wprintw(self->window, " (%s)\n", friends[f].statusmsg); } else { - wprintw(self->window, "[O]"); + wprintw(self->window, "["); + wattron(self->window, A_BOLD); + wprintw(self->window, "O"); + wattroff(self->window, A_BOLD); + wprintw(self->window, "]"); if (f_selected) wattron(self->window, A_BOLD); diff --git a/src/friendlist.h b/src/friendlist.h index 3abc781..029c9a6 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -9,6 +9,7 @@ typedef struct { uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; uint16_t statusmsg_len; uint8_t pending_groupchat[TOX_CLIENT_ID_SIZE]; + uint8_t pub_key[TOX_CLIENT_ID_SIZE]; int num; int chatwin; bool active; diff --git a/src/main.c b/src/main.c index 3a68fbf..3b9bcc1 100644 --- a/src/main.c +++ b/src/main.c @@ -232,34 +232,34 @@ int init_connection(Tox *m) return 5; } -static void do_tox(Tox *m, ToxWindow *prompt) +static void do_connection(Tox *m, ToxWindow *prompt) { static int conn_try = 0; static int conn_err = 0; static bool dht_on = false; - if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) { + bool is_connected = tox_isconnected(m); + + if (!dht_on && !is_connected && !(conn_try++ % 100)) { prep_prompt_win(); if (!conn_err) { wprintw(prompt->window, "Establishing connection...\n"); if ((conn_err = init_connection(m))) wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err); } - } else if (!dht_on && tox_isconnected(m)) { + } else if (!dht_on && is_connected) { dht_on = true; prompt_update_connectionstatus(prompt, dht_on); prep_prompt_win(); wprintw(prompt->window, "\nDHT connected.\n"); - } else if (dht_on && !tox_isconnected(m)) { + } else if (dht_on && !is_connected) { dht_on = false; prompt_update_connectionstatus(prompt, dht_on); prep_prompt_win(); wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); } - - tox_do(m); } int f_loadfromfile; @@ -405,9 +405,7 @@ static void do_file_senders(Tox *m) continue; } - int pieces = 0; - - while (pieces++ < MAX_PIECES_SEND) { + while (true) { if (tox_file_send_data(m, friendnum, filenum, file_senders[i].nextpiece, file_senders[i].piecelen) == -1) break; @@ -432,21 +430,17 @@ static void do_file_senders(Tox *m) } } -/* This should only be called on exit */ -static void close_file_transfers(Tox *m) +void exit_toxic(Tox *m) { + store_data(m, DATA_FILE); + int i; for (i = 0; i < max_file_senders_index; ++i) { if (file_senders[i].active) fclose(file_senders[i].file); } -} -void exit_toxic(Tox *m) -{ - store_data(m, DATA_FILE); - close_file_transfers(m); free(DATA_FILE); free(SRVLIST_FILE); free(prompt->stb); @@ -456,6 +450,16 @@ void exit_toxic(Tox *m) exit(EXIT_SUCCESS); } +static void do_toxic(Tox *m, ToxWindow *prompt) +{ + do_connection(m, prompt); + draw_active_window(m); + do_file_senders(m); + + /* main tox-core loop */ + tox_do(m); +} + int main(int argc, char *argv[]) { char *user_config_dir = get_user_config_dir(); @@ -466,6 +470,9 @@ int main(int argc, char *argv[]) int i = 0; int f_use_ipv4 = 0; + // Make sure all written files are read/writeable only by the current user. + umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + for (i = 0; i < argc; ++i) { if (argv[i] == NULL) break; @@ -549,12 +556,8 @@ int main(int argc, char *argv[]) prompt_init_statusbar(prompt, m); sort_friendlist_index(m); - while (true) { - do_tox(m, prompt); - do_file_senders(m); - draw_active_window(m); - } + while (true) + do_toxic(m, prompt); - exit_toxic(m); return 0; } diff --git a/src/prompt.c b/src/prompt.c index 741b9e0..6d0a238 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -162,7 +162,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key) else if (key == KEY_END) { /* END key: move cursor to end of line */ if (prt->pos != prt->len) prt->pos = prt->len; - } + } else if (key == KEY_LEFT) { if (prt->pos > 0) @@ -418,7 +418,16 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m) snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick); /* temporary until statusmessage saving works */ - uint8_t *statusmsg = "Toxing on Toxic v.0.2.4"; + uint8_t ver[strlen(TOXICVER) + 1]; + uint8_t statusmsg[MAX_STR_SIZE]; + strcpy(ver, TOXICVER); + uint8_t *toxic_ver = strtok(ver, "_"); + + if (toxic_ver != NULL) + snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver); + else + snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic hacker edition"); + m_set_statusmessage(m, statusmsg, strlen(statusmsg) + 1); snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg); diff --git a/src/toxic_windows.h b/src/toxic_windows.h index 3a3d62e..774b790 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -26,6 +26,7 @@ #define N_DEFAULT_WINS 2 /* number of permanent default windows */ #define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */ #define CHATBOX_HEIGHT 4 +#define KEY_IDENT_DIGITS 2 /* number of hex digits to display for the pub-key based identifier */ #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 @@ -149,7 +150,6 @@ struct PromptBuf { #define MAX_FILES 256 #define FILE_PIECE_SIZE 1024 #define TIMEOUT_FILESENDER 300 -#define MAX_PIECES_SEND 100 /* Max number of pieces to send per file per call to do_file_senders() */ typedef struct { FILE *file;