mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 02:03:03 +01:00
Merge branch 'master' of github.com:/Tox/toxic
This commit is contained in:
commit
8b6d50cd68
47
.travis.yml
Normal file
47
.travis.yml
Normal file
@ -0,0 +1,47 @@
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_script:
|
||||
# installing libsodium, needed for Core
|
||||
- git clone git://github.com/jedisct1/libsodium.git
|
||||
- cd libsodium
|
||||
- git checkout tags/0.4.2
|
||||
- ./autogen.sh
|
||||
- ./configure && make check -j3
|
||||
- sudo make install
|
||||
- cd ..
|
||||
# installing libconfig, needed for DHT_bootstrap_daemon
|
||||
- wget http://www.hyperrealm.com/libconfig/libconfig-1.4.9.tar.gz
|
||||
- tar -xvzf libconfig-1.4.9.tar.gz
|
||||
- cd libconfig-1.4.9
|
||||
- ./configure && make -j3
|
||||
- sudo make install
|
||||
- cd ..
|
||||
# creating librarys' links and updating cache
|
||||
- sudo ldconfig
|
||||
# installing sphinx, needed for documentation
|
||||
- sudo apt-get install python-sphinx
|
||||
# installing check, needed for unit tests
|
||||
- sudo apt-get install check
|
||||
|
||||
- git clone https://github.com/irungentoo/ProjectTox-Core.git toxcore
|
||||
- cd toxcore
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake ..
|
||||
- make toxcore -j2
|
||||
- cd ../..
|
||||
script:
|
||||
- autoreconf -i
|
||||
- ./configure --with-libtoxcore-headers=$TRAVIS_BUILD_DIR/toxcore/core --with-libtoxcore-libs=$TRAVIS_BUILD_DIR/toxcore/build/core
|
||||
- make -j2
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
irc:
|
||||
channels:
|
||||
- "chat.freenode.net#tox-dev"
|
||||
on_success: always
|
||||
on_failure: always
|
@ -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])
|
||||
|
59
src/chat.c
59
src/chat.c
@ -13,9 +13,6 @@
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "Messenger.h"
|
||||
#include "network.h"
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "friendlist.h"
|
||||
#include "chat.h"
|
||||
@ -31,7 +28,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,18 +39,18 @@ 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)
|
||||
return;
|
||||
|
||||
getname(m, num, (uint8_t *) &nick);
|
||||
tox_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 +64,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 +173,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 +219,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));
|
||||
@ -233,7 +230,7 @@ static void chat_onKey(ToxWindow *self, Messenger *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));
|
||||
@ -247,7 +244,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 +278,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);
|
||||
@ -290,7 +287,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *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));
|
||||
@ -308,20 +305,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";
|
||||
}
|
||||
|
||||
@ -333,12 +330,12 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *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);
|
||||
}
|
||||
}
|
||||
@ -353,17 +350,17 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *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);
|
||||
}
|
||||
|
||||
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 +380,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 +391,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 +421,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,8 +434,8 @@ ToxWindow new_chat(Messenger *m, int friendnum)
|
||||
ret.onStatusChange = &chat_onStatusChange;
|
||||
ret.onAction = &chat_onAction;
|
||||
|
||||
uint8_t nick[MAX_NAME_LENGTH] = {0};
|
||||
getname(m, friendnum, (uint8_t *) &nick);
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
|
||||
tox_getname(m, friendnum, (uint8_t *) &nick);
|
||||
|
||||
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -10,15 +10,14 @@
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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,27 +48,27 @@ 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;
|
||||
|
||||
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;
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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 */
|
||||
|
106
src/main.c
106
src/main.c
@ -14,16 +14,18 @@
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifdef _win32
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "Messenger.h"
|
||||
#include "network.h"
|
||||
#include "tox.h"
|
||||
|
||||
#include "configdir.h"
|
||||
#include "toxic_windows.h"
|
||||
@ -68,39 +70,79 @@ 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);
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */
|
||||
#define MINLINE 70
|
||||
#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");
|
||||
@ -132,7 +174,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);
|
||||
|
||||
@ -140,19 +182,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");
|
||||
@ -160,15 +202,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;
|
||||
@ -180,7 +222,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;
|
||||
@ -189,14 +231,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");
|
||||
|
||||
@ -216,7 +258,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;
|
||||
@ -247,12 +289,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);
|
||||
@ -314,7 +358,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)
|
||||
@ -342,7 +386,7 @@ int main(int argc, char *argv[])
|
||||
draw_active_window(m);
|
||||
}
|
||||
|
||||
cleanupMessenger(m);
|
||||
tox_kill(m);
|
||||
free(DATA_FILE);
|
||||
free(SRVLIST_FILE);
|
||||
return 0;
|
||||
|
125
src/prompt.c
125
src/prompt.c
@ -10,40 +10,37 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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,25 +239,25 @@ 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];
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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,10 +266,10 @@ 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);
|
||||
tox_setname(m, (uint8_t *) nick, strlen(nick) + 1);
|
||||
wprintw(self->window, "Nickname set to: %s\n", nick);
|
||||
|
||||
if (store_data(m, DATA_FILE)) {
|
||||
@ -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");
|
||||
@ -312,23 +309,23 @@ void cmd_status(ToxWindow *self, Messenger *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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
tox_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);
|
||||
|
@ -9,7 +9,9 @@
|
||||
#include <stdbool.h>
|
||||
#include <wctype.h>
|
||||
#include <wchar.h>
|
||||
#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
|
||||
|
@ -2,18 +2,21 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user