mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:23:01 +01:00
Use new public api
This commit is contained in:
parent
9ab34ca5dd
commit
baadd95b45
41
src/chat.c
41
src/chat.c
@ -13,7 +13,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "Messenger.h"
|
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#include "toxic_windows.h"
|
#include "toxic_windows.h"
|
||||||
@ -31,7 +30,7 @@ typedef struct {
|
|||||||
} ChatContext;
|
} ChatContext;
|
||||||
|
|
||||||
void print_help(ChatContext *self);
|
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)
|
struct tm *get_time(void)
|
||||||
{
|
{
|
||||||
@ -42,10 +41,10 @@ struct tm *get_time(void)
|
|||||||
return timeinfo;
|
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;
|
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();
|
struct tm *timeinfo = get_time();
|
||||||
|
|
||||||
if (ctx->friendnum != num)
|
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);
|
getname(m, num, (uint8_t *) &nick);
|
||||||
msg[len - 1] = '\0';
|
msg[len - 1] = '\0';
|
||||||
nick[MAX_NAME_LENGTH - 1] = '\0';
|
nick[TOX_MAX_NAME_LENGTH - 1] = '\0';
|
||||||
|
|
||||||
wattron(ctx->history, COLOR_PAIR(2));
|
wattron(ctx->history, COLOR_PAIR(2));
|
||||||
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
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();
|
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;
|
ChatContext *ctx = (ChatContext *) self->x;
|
||||||
struct tm *timeinfo = get_time();
|
struct tm *timeinfo = get_time();
|
||||||
@ -176,7 +175,7 @@ static char *wc_to_char(wchar_t ch)
|
|||||||
return ret;
|
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;
|
ChatContext *ctx = (ChatContext *) self->x;
|
||||||
struct tm *timeinfo = get_time();
|
struct tm *timeinfo = get_time();
|
||||||
@ -222,7 +221,7 @@ static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key)
|
|||||||
else {
|
else {
|
||||||
/* make sure the string has at least non-space character */
|
/* make sure the string has at least non-space character */
|
||||||
if (!string_is_empty(line)) {
|
if (!string_is_empty(line)) {
|
||||||
uint8_t selfname[MAX_NAME_LENGTH];
|
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||||
getself_name(m, selfname, sizeof(selfname));
|
getself_name(m, selfname, sizeof(selfname));
|
||||||
|
|
||||||
wattron(ctx->history, COLOR_PAIR(2));
|
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")) {
|
if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
|
||||||
wclear(self->window);
|
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);
|
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||||
wattroff(ctx->history, COLOR_PAIR(2));
|
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));
|
int len = getself_name(m, selfname, sizeof(selfname));
|
||||||
char msg[MAX_STR_SIZE - len - 4];
|
char msg[MAX_STR_SIZE - len - 4];
|
||||||
snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t *) selfname, action);
|
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++;
|
status++;
|
||||||
USERSTATUS status_kind;
|
TOX_USERSTATUS status_kind;
|
||||||
|
|
||||||
if (!strncmp(status, "online", strlen("online"))) {
|
if (!strncmp(status, "online", strlen("online"))) {
|
||||||
status_kind = USERSTATUS_NONE;
|
status_kind = TOX_USERSTATUS_NONE;
|
||||||
status_text = "ONLINE";
|
status_text = "ONLINE";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!strncmp(status, "away", strlen("away"))) {
|
else if (!strncmp(status, "away", strlen("away"))) {
|
||||||
status_kind = USERSTATUS_AWAY;
|
status_kind = TOX_USERSTATUS_AWAY;
|
||||||
status_text = "AWAY";
|
status_text = "AWAY";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!strncmp(status, "busy", strlen("busy"))) {
|
else if (!strncmp(status, "busy", strlen("busy"))) {
|
||||||
status_kind = USERSTATUS_BUSY;
|
status_kind = TOX_USERSTATUS_BUSY;
|
||||||
status_text = "BUSY";
|
status_text = "BUSY";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,12 +357,12 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (!strcmp(cmd, "/myid")) {
|
else if (!strcmp(cmd, "/myid")) {
|
||||||
char id[FRIEND_ADDRESS_SIZE * 2 + 1] = {0};
|
char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0};
|
||||||
int i;
|
int i;
|
||||||
uint8_t address[FRIEND_ADDRESS_SIZE];
|
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||||
getaddress(m, address);
|
getaddress(m, address);
|
||||||
|
|
||||||
for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) {
|
for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
|
||||||
char xx[3];
|
char xx[3];
|
||||||
snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff);
|
snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff);
|
||||||
strcat(id, xx);
|
strcat(id, xx);
|
||||||
@ -383,7 +382,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd)
|
|||||||
wprintw(ctx->history, "Invalid command.\n");
|
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);
|
curs_set(1);
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -394,7 +393,7 @@ static void chat_onDraw(ToxWindow *self, Messenger *m)
|
|||||||
wrefresh(self->window);
|
wrefresh(self->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chat_onInit(ToxWindow *self, Messenger *m)
|
static void chat_onInit(ToxWindow *self, Tox *m)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
ChatContext *ctx = (ChatContext *) self->x;
|
ChatContext *ctx = (ChatContext *) self->x;
|
||||||
@ -424,7 +423,7 @@ void print_help(ChatContext *self)
|
|||||||
wattroff(self->history, COLOR_PAIR(2));
|
wattroff(self->history, COLOR_PAIR(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxWindow new_chat(Messenger *m, int friendnum)
|
ToxWindow new_chat(Tox *m, int friendnum)
|
||||||
{
|
{
|
||||||
ToxWindow ret;
|
ToxWindow ret;
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
@ -437,7 +436,7 @@ ToxWindow new_chat(Messenger *m, int friendnum)
|
|||||||
ret.onStatusChange = &chat_onStatusChange;
|
ret.onStatusChange = &chat_onStatusChange;
|
||||||
ret.onAction = &chat_onAction;
|
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);
|
getname(m, friendnum, (uint8_t *) &nick);
|
||||||
|
|
||||||
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef CHAT_H_6489PZ13
|
#ifndef CHAT_H_6489PZ13
|
||||||
#define 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 */
|
#endif /* end of include guard: CHAT_H_6489PZ13 */
|
||||||
|
@ -4,30 +4,28 @@
|
|||||||
|
|
||||||
#include "dhtstatus.h"
|
#include "dhtstatus.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "network.h"
|
|
||||||
#include "DHT.h"
|
|
||||||
|
|
||||||
typedef uint8_t ipbuf[3 * 4 + 3 + 1];
|
typedef uint8_t ipbuf[3 * 4 + 3 + 1];
|
||||||
static int num_selected = 0;
|
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]);
|
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) {
|
switch (key) {
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
case 'k':
|
case 'k':
|
||||||
if (--num_selected < 0)
|
if (--num_selected < 0)
|
||||||
num_selected = CLIENT_ID_SIZE - 1;
|
num_selected = TOX_CLIENT_ID_SIZE - 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
case 'j':
|
case 'j':
|
||||||
num_selected = (num_selected + 1) % CLIENT_ID_SIZE;
|
num_selected = (num_selected + 1) % TOX_CLIENT_ID_SIZE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\n':
|
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);
|
curs_set(0);
|
||||||
werase(self->window);
|
werase(self->window);
|
||||||
|
|
||||||
@ -52,6 +51,7 @@ static void dhtstatus_onDraw(ToxWindow *self, Messenger *m)
|
|||||||
now);
|
now);
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) { /*Number of nodes in closelist*/
|
for (i = 0; i < 32; i++) { /*Number of nodes in closelist*/
|
||||||
|
/*
|
||||||
Client_data *client = close_clientlist + i;
|
Client_data *client = close_clientlist + i;
|
||||||
|
|
||||||
if (i == num_selected) wattron(self->window, COLOR_PAIR(3));
|
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);
|
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 <stdint.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "Messenger.h"
|
#include "tox.h"
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t name[MAX_NAME_LENGTH];
|
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||||
uint8_t status[MAX_STATUSMESSAGE_LENGTH];
|
uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||||
int num;
|
int num;
|
||||||
int chatwin;
|
int chatwin;
|
||||||
} friend_t;
|
} friend_t;
|
||||||
@ -28,7 +27,7 @@ static int num_friends = 0;
|
|||||||
static int num_selected = 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)
|
if (num >= num_friends)
|
||||||
return;
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
memcpy((char *) &friends[num].name, (char *) str, len);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
memcpy((char *) &friends[num].status, (char *) str, len);
|
memcpy((char *) &friends[num].status, (char *) str, len);
|
||||||
friends[num].status[len] = 0;
|
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)
|
if (num_friends == MAX_FRIENDS_NUM)
|
||||||
return -1;
|
return -1;
|
||||||
@ -69,7 +68,7 @@ int friendlist_onFriendAdded(Messenger *m, int num)
|
|||||||
return 0;
|
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 (key == KEY_UP) {
|
||||||
if (--num_selected < 0)
|
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);
|
curs_set(0);
|
||||||
werase(self->window);
|
werase(self->window);
|
||||||
@ -125,7 +124,7 @@ void disable_chatwin(int f_num)
|
|||||||
friends[f_num].chatwin = -1;
|
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"
|
#include "chat.h"
|
||||||
|
|
||||||
ToxWindow new_friendlist();
|
ToxWindow new_friendlist();
|
||||||
int friendlist_onFriendAdded(Messenger *m, int num);
|
int friendlist_onFriendAdded(Tox *m, int num);
|
||||||
void disable_chatwin(int f_num);
|
void disable_chatwin(int f_num);
|
||||||
|
|
||||||
#endif /* end of include guard: FRIENDLIST_H_53I41IM */
|
#endif /* end of include guard: FRIENDLIST_H_53I41IM */
|
||||||
|
92
src/main.c
92
src/main.c
@ -14,16 +14,18 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#ifdef _win32
|
#ifdef _win32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Messenger.h"
|
#include "tox.h"
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
#include "configdir.h"
|
#include "configdir.h"
|
||||||
#include "toxic_windows.h"
|
#include "toxic_windows.h"
|
||||||
@ -34,6 +36,50 @@
|
|||||||
char *DATA_FILE = NULL;
|
char *DATA_FILE = NULL;
|
||||||
char *SRVLIST_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)
|
void on_window_resize(int sig)
|
||||||
{
|
{
|
||||||
endwin();
|
endwin();
|
||||||
@ -68,10 +114,10 @@ static void init_term()
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Messenger *init_tox()
|
static Tox *init_tox()
|
||||||
{
|
{
|
||||||
/* Init core */
|
/* Init core */
|
||||||
Messenger *m = initMessenger();
|
Tox *m = tox_new();
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
m_callback_friendrequest(m, on_request, NULL);
|
m_callback_friendrequest(m, on_request, NULL);
|
||||||
@ -136,11 +182,11 @@ uint32_t resolve_addr(const char *address)
|
|||||||
#define MAXSERVERS 50
|
#define MAXSERVERS 50
|
||||||
|
|
||||||
/* Connects to a random DHT server listed in the DHTservers file */
|
/* Connects to a random DHT server listed in the DHTservers file */
|
||||||
int init_connection(Messenger *m)
|
int init_connection(Tox *m)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
if (DHT_isconnected(m->dht))
|
if (tox_isconnected(m))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fp = fopen(SRVLIST_FILE, "r");
|
fp = fopen(SRVLIST_FILE, "r");
|
||||||
@ -172,7 +218,7 @@ int init_connection(Messenger *m)
|
|||||||
if (!ip || !port || !key)
|
if (!ip || !port || !key)
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
IP_Port dht;
|
tox_IP_Port dht;
|
||||||
dht.port = htons(atoi(port));
|
dht.port = htons(atoi(port));
|
||||||
uint32_t resolved_address = resolve_addr(ip);
|
uint32_t resolved_address = resolve_addr(ip);
|
||||||
|
|
||||||
@ -180,19 +226,19 @@ int init_connection(Messenger *m)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
dht.ip.i = resolved_address;
|
dht.ip.i = resolved_address;
|
||||||
unsigned char *binary_string = hex_string_to_bin(key);
|
uint8_t *binary_string = hex_string_to_bin(key);
|
||||||
DHT_bootstrap(m->dht, dht, binary_string);
|
tox_bootstrap(m, dht, binary_string);
|
||||||
free(binary_string);
|
free(binary_string);
|
||||||
return 0;
|
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_try = 0;
|
||||||
static int conn_err = 0;
|
static int conn_err = 0;
|
||||||
static bool dht_on = false;
|
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) {
|
if (!conn_err) {
|
||||||
conn_err = init_connection(m);
|
conn_err = init_connection(m);
|
||||||
wprintw(prompt->window, "\nEstablishing connection...\n");
|
wprintw(prompt->window, "\nEstablishing connection...\n");
|
||||||
@ -200,15 +246,15 @@ static void do_tox(Messenger *m, ToxWindow *prompt)
|
|||||||
if (conn_err)
|
if (conn_err)
|
||||||
wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", 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;
|
dht_on = true;
|
||||||
wprintw(prompt->window, "\nDHT connected.\n");
|
wprintw(prompt->window, "\nDHT connected.\n");
|
||||||
} else if (dht_on && !DHT_isconnected(m->dht)) {
|
} else if (dht_on && !tox_isconnected(m)) {
|
||||||
dht_on = false;
|
dht_on = false;
|
||||||
wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
|
wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
doMessenger(m);
|
tox_do(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
int f_loadfromfile;
|
int f_loadfromfile;
|
||||||
@ -220,7 +266,7 @@ int f_loadfromfile;
|
|||||||
* Return 2 opening path failed
|
* Return 2 opening path failed
|
||||||
* Return 3 fwrite 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*/
|
if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
|
||||||
return 0;
|
return 0;
|
||||||
@ -229,14 +275,14 @@ int store_data(Messenger *m, char *path)
|
|||||||
size_t len;
|
size_t len;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
len = Messenger_size(m);
|
len = tox_size(m);
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Messenger_save(m, buf);
|
tox_save(m, buf);
|
||||||
|
|
||||||
fd = fopen(path, "w");
|
fd = fopen(path, "w");
|
||||||
|
|
||||||
@ -256,7 +302,7 @@ int store_data(Messenger *m, char *path)
|
|||||||
return 0;
|
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*/
|
if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
|
||||||
return;
|
return;
|
||||||
@ -287,12 +333,14 @@ static void load_data(Messenger *m, char *path)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Messenger_load(m, buf, len);
|
tox_load(m, buf, len);
|
||||||
|
|
||||||
uint32_t i;
|
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);
|
on_friendadded(m, i);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -354,7 +402,7 @@ int main(int argc, char *argv[])
|
|||||||
free(user_config_dir);
|
free(user_config_dir);
|
||||||
|
|
||||||
init_term();
|
init_term();
|
||||||
Messenger *m = init_tox();
|
Tox *m = init_tox();
|
||||||
ToxWindow *prompt = init_windows(m);
|
ToxWindow *prompt = init_windows(m);
|
||||||
|
|
||||||
if (f_loadfromfile)
|
if (f_loadfromfile)
|
||||||
@ -382,7 +430,7 @@ int main(int argc, char *argv[])
|
|||||||
draw_active_window(m);
|
draw_active_window(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanupMessenger(m);
|
tox_kill(m);
|
||||||
free(DATA_FILE);
|
free(DATA_FILE);
|
||||||
free(SRVLIST_FILE);
|
free(SRVLIST_FILE);
|
||||||
return 0;
|
return 0;
|
||||||
|
113
src/prompt.c
113
src/prompt.c
@ -10,40 +10,37 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "Messenger.h"
|
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
|
|
||||||
extern char *DATA_FILE;
|
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
|
uint8_t num_requests = 0; // XXX
|
||||||
|
|
||||||
static char prompt_buf[MAX_STR_SIZE] = {0};
|
static char prompt_buf[MAX_STR_SIZE] = {0};
|
||||||
static int prompt_buf_pos = 0;
|
static int prompt_buf_pos = 0;
|
||||||
|
|
||||||
/* commands */
|
/* commands */
|
||||||
void cmd_accept(ToxWindow *, Messenger *m, char **);
|
void cmd_accept(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_add(ToxWindow *, Messenger *m, char **);
|
void cmd_add(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_clear(ToxWindow *, Messenger *m, char **);
|
void cmd_clear(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_connect(ToxWindow *, Messenger *m, char **);
|
void cmd_connect(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_help(ToxWindow *, Messenger *m, char **);
|
void cmd_help(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_msg(ToxWindow *, Messenger *m, char **);
|
void cmd_msg(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_myid(ToxWindow *, Messenger *m, char **);
|
void cmd_myid(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_nick(ToxWindow *, Messenger *m, char **);
|
void cmd_nick(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_mynick(ToxWindow *, Messenger *m, char **);
|
void cmd_mynick(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_quit(ToxWindow *, Messenger *m, char **);
|
void cmd_quit(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_status(ToxWindow *, Messenger *m, char **);
|
void cmd_status(ToxWindow *, Tox *m, char **);
|
||||||
void cmd_statusmsg(ToxWindow *, Messenger *m, char **);
|
void cmd_statusmsg(ToxWindow *, Tox *m, char **);
|
||||||
|
|
||||||
#define NUM_COMMANDS 14
|
#define NUM_COMMANDS 14
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
char *name;
|
char *name;
|
||||||
int numargs;
|
int numargs;
|
||||||
void (*func)(ToxWindow *, Messenger *m, char **);
|
void (*func)(ToxWindow *, Tox *m, char **);
|
||||||
} commands[] = {
|
} commands[] = {
|
||||||
{ "accept", 1, cmd_accept },
|
{ "accept", 1, cmd_accept },
|
||||||
{ "add", 1, cmd_add },
|
{ "add", 1, cmd_add },
|
||||||
@ -64,7 +61,7 @@ static struct {
|
|||||||
// XXX:
|
// XXX:
|
||||||
int add_req(uint8_t *public_key)
|
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;
|
++num_requests;
|
||||||
return num_requests - 1;
|
return num_requests - 1;
|
||||||
}
|
}
|
||||||
@ -83,7 +80,7 @@ unsigned char *hex_string_to_bin(char hex_string[])
|
|||||||
return val;
|
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]);
|
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];
|
char xx[3];
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
char *id = args[1];
|
char *id = args[1];
|
||||||
@ -118,14 +115,14 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args)
|
|||||||
if (!msg)
|
if (!msg)
|
||||||
msg = "";
|
msg = "";
|
||||||
|
|
||||||
if (strlen(id) != 2 * FRIEND_ADDRESS_SIZE) {
|
if (strlen(id) != 2 * TOX_FRIEND_ADDRESS_SIZE) {
|
||||||
wprintw(self->window, "Invalid ID length.\n");
|
wprintw(self->window, "Invalid ID length.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
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[0] = id[2 * i];
|
||||||
xx[1] = id[2 * i + 1];
|
xx[1] = id[2 * i + 1];
|
||||||
xx[2] = '\0';
|
xx[2] = '\0';
|
||||||
@ -138,38 +135,38 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args)
|
|||||||
id_bin[i] = x;
|
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]);
|
id[i] = toupper(id[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int num = m_addfriend(m, id_bin, (uint8_t *) msg, strlen(msg) + 1);
|
int num = m_addfriend(m, id_bin, (uint8_t *) msg, strlen(msg) + 1);
|
||||||
|
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case FAERR_TOOLONG:
|
case TOX_FAERR_TOOLONG:
|
||||||
wprintw(self->window, "Message is too long.\n");
|
wprintw(self->window, "Message is too long.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_NOMESSAGE:
|
case TOX_FAERR_NOMESSAGE:
|
||||||
wprintw(self->window, "Please add a message to your request.\n");
|
wprintw(self->window, "Please add a message to your request.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_OWNKEY:
|
case TOX_FAERR_OWNKEY:
|
||||||
wprintw(self->window, "That appears to be your own ID.\n");
|
wprintw(self->window, "That appears to be your own ID.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_ALREADYSENT:
|
case TOX_FAERR_ALREADYSENT:
|
||||||
wprintw(self->window, "Friend request already sent.\n");
|
wprintw(self->window, "Friend request already sent.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_UNKNOWN:
|
case TOX_FAERR_UNKNOWN:
|
||||||
wprintw(self->window, "Undefined error when adding friend.\n");
|
wprintw(self->window, "Undefined error when adding friend.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_BADCHECKSUM:
|
case TOX_FAERR_BADCHECKSUM:
|
||||||
wprintw(self->window, "Bad checksum in address.\n");
|
wprintw(self->window, "Bad checksum in address.\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FAERR_SETNEWNOSPAM:
|
case TOX_FAERR_SETNEWNOSPAM:
|
||||||
wprintw(self->window, "Nospam was different.\n");
|
wprintw(self->window, "Nospam was different.\n");
|
||||||
break;
|
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);
|
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 *ip = args[1];
|
||||||
char *port = args[2];
|
char *port = args[2];
|
||||||
char *key = args[3];
|
char *key = args[3];
|
||||||
@ -205,18 +202,18 @@ void cmd_connect(ToxWindow *self, Messenger *m, char **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dht.ip.i = resolved_address;
|
dht.ip.i = resolved_address;
|
||||||
unsigned char *binary_string = hex_string_to_bin(key);
|
uint8_t *binary_string = hex_string_to_bin(key);
|
||||||
DHT_bootstrap(m->dht, dht, binary_string);
|
tox_bootstrap(m, dht, binary_string);
|
||||||
free(binary_string);
|
free(binary_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_quit(ToxWindow *self, Messenger *m, char **args)
|
void cmd_quit(ToxWindow *self, Tox *m, char **args)
|
||||||
{
|
{
|
||||||
endwin();
|
endwin();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_help(ToxWindow *self, Messenger *m, char **args)
|
void cmd_help(ToxWindow *self, Tox *m, char **args)
|
||||||
{
|
{
|
||||||
wclear(self->window);
|
wclear(self->window);
|
||||||
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
|
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));
|
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 *id = args[1];
|
||||||
char *msg = args[2];
|
char *msg = args[2];
|
||||||
@ -253,14 +250,14 @@ void cmd_msg(ToxWindow *self, Messenger *m, char **args)
|
|||||||
wprintw(self->window, "Message successfully sent.\n");
|
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;
|
size_t i;
|
||||||
uint8_t address[FRIEND_ADDRESS_SIZE];
|
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||||
getaddress(m, address);
|
getaddress(m, address);
|
||||||
|
|
||||||
for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) {
|
for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
|
||||||
char xx[3];
|
char xx[3];
|
||||||
snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff);
|
snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff);
|
||||||
strcat(id, xx);
|
strcat(id, xx);
|
||||||
@ -269,7 +266,7 @@ void cmd_myid(ToxWindow *self, Messenger *m, char **args)
|
|||||||
wprintw(self->window, "%s\n", id);
|
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];
|
char *nick = args[1];
|
||||||
setname(m, (uint8_t *) nick, strlen(nick) + 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);
|
uint8_t *nick = malloc(TOX_MAX_NAME_LENGTH);
|
||||||
getself_name(m, nick, m->name_length);
|
tox_getselfname(m, nick, TOX_MAX_NAME_LENGTH);
|
||||||
wprintw(self->window, "Current nickname: %s\n", nick);
|
wprintw(self->window, "Current nickname: %s\n", nick);
|
||||||
free(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 = args[1];
|
||||||
char *status_text;
|
char *status_text;
|
||||||
|
|
||||||
USERSTATUS status_kind;
|
TOX_USERSTATUS status_kind;
|
||||||
|
|
||||||
if (!strncmp(status, "online", strlen("online"))) {
|
if (!strncmp(status, "online", strlen("online"))) {
|
||||||
status_kind = USERSTATUS_NONE;
|
status_kind = TOX_USERSTATUS_NONE;
|
||||||
status_text = "ONLINE";
|
status_text = "ONLINE";
|
||||||
} else if (!strncmp(status, "away", strlen("away"))) {
|
} else if (!strncmp(status, "away", strlen("away"))) {
|
||||||
status_kind = USERSTATUS_AWAY;
|
status_kind = TOX_USERSTATUS_AWAY;
|
||||||
status_text = "AWAY";
|
status_text = "AWAY";
|
||||||
} else if (!strncmp(status, "busy", strlen("busy"))) {
|
} else if (!strncmp(status, "busy", strlen("busy"))) {
|
||||||
status_kind = USERSTATUS_BUSY;
|
status_kind = TOX_USERSTATUS_BUSY;
|
||||||
status_text = "BUSY";
|
status_text = "BUSY";
|
||||||
} else {
|
} else {
|
||||||
wprintw(self->window, "Invalid status.\n");
|
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];
|
char *msg = args[1];
|
||||||
m_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1);
|
m_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1);
|
||||||
wprintw(self->window, "Status set to: %s\n", msg);
|
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;
|
int newlines = 0;
|
||||||
char cmd[MAX_STR_SIZE] = {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");
|
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 */
|
/* Add printable characters to line */
|
||||||
if (isprint(key)) {
|
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);
|
curs_set(1);
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -493,7 +490,7 @@ static void prompt_onDraw(ToxWindow *self, Messenger *m)
|
|||||||
wrefresh(self->window);
|
wrefresh(self->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prompt_onInit(ToxWindow *self, Messenger *m)
|
static void prompt_onInit(ToxWindow *self, Tox *m)
|
||||||
{
|
{
|
||||||
scrollok(self->window, 1);
|
scrollok(self->window, 1);
|
||||||
cmd_help(self, m, NULL);
|
cmd_help(self, m, NULL);
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include "Messenger.h"
|
|
||||||
|
#include "tox.h"
|
||||||
|
|
||||||
#define MAX_WINDOWS_NUM 32
|
#define MAX_WINDOWS_NUM 32
|
||||||
#define MAX_FRIENDS_NUM 100
|
#define MAX_FRIENDS_NUM 100
|
||||||
#define MAX_STR_SIZE 256
|
#define MAX_STR_SIZE 256
|
||||||
@ -25,14 +27,14 @@
|
|||||||
typedef struct ToxWindow_ ToxWindow;
|
typedef struct ToxWindow_ ToxWindow;
|
||||||
|
|
||||||
struct ToxWindow_ {
|
struct ToxWindow_ {
|
||||||
void(*onKey)(ToxWindow *, Messenger *, wint_t);
|
void(*onKey)(ToxWindow *, Tox *, wint_t);
|
||||||
void(*onDraw)(ToxWindow *, Messenger *);
|
void(*onDraw)(ToxWindow *, Tox *);
|
||||||
void(*onInit)(ToxWindow *, Messenger *);
|
void(*onInit)(ToxWindow *, Tox *);
|
||||||
void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t);
|
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(*onNickChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
||||||
void(*onStatusChange)(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];
|
char title[256];
|
||||||
|
|
||||||
void *x;
|
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_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_message(Tox *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_action(Tox *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_nickchange(Tox *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_statuschange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
||||||
void on_friendadded(Messenger *m, int friendnumber);
|
void on_friendadded(Tox *m, int friendnumber);
|
||||||
ToxWindow *init_windows();
|
ToxWindow *init_windows();
|
||||||
void draw_active_window(Messenger *m);
|
void draw_active_window(Tox *m);
|
||||||
int add_window(Messenger *m, ToxWindow w);
|
int add_window(Tox *m, ToxWindow w);
|
||||||
void del_window(ToxWindow *w);
|
void del_window(ToxWindow *w);
|
||||||
void set_active_window(int ch);
|
void set_active_window(int ch);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,18 +2,21 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
#include "dhtstatus.h"
|
#include "dhtstatus.h"
|
||||||
#include "toxic_windows.h"
|
#include "toxic_windows.h"
|
||||||
|
|
||||||
extern char *DATA_FILE;
|
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 windows[MAX_WINDOWS_NUM];
|
||||||
static ToxWindow *active_window;
|
static ToxWindow *active_window;
|
||||||
static ToxWindow *prompt;
|
static ToxWindow *prompt;
|
||||||
static Messenger *m;
|
static Tox *m;
|
||||||
|
|
||||||
/* CALLBACKS START */
|
/* CALLBACKS START */
|
||||||
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
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;
|
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;
|
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);
|
wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string);
|
||||||
int i;
|
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);
|
wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string);
|
||||||
int i;
|
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);
|
friendlist_onFriendAdded(m, friendnumber);
|
||||||
|
|
||||||
if (store_data(m, DATA_FILE)) {
|
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 */
|
/* CALLBACKS END */
|
||||||
|
|
||||||
int add_window(Messenger *m, ToxWindow w)
|
int add_window(Tox *m, ToxWindow w)
|
||||||
{
|
{
|
||||||
if (LINES < 2)
|
if (LINES < 2)
|
||||||
return -1;
|
return -1;
|
||||||
@ -226,7 +229,7 @@ void prepare_window(WINDOW *w)
|
|||||||
wresize(w, LINES - 2, COLS);
|
wresize(w, LINES - 2, COLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_active_window(Messenger *m)
|
void draw_active_window(Tox *m)
|
||||||
{
|
{
|
||||||
|
|
||||||
ToxWindow *a = active_window;
|
ToxWindow *a = active_window;
|
||||||
|
Loading…
Reference in New Issue
Block a user