From 10feea4474e53c12b74e4334042b13a5d5cfe94f Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 16:44:32 -0700 Subject: [PATCH 01/24] Adds timestamp to toxic, fixes issue #217 --- testing/toxic/chat.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 854d3817..10837aa7 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../../core/Messenger.h" #include "../../core/network.h" @@ -26,11 +27,15 @@ typedef struct { extern void fix_name(uint8_t* name); - static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { ChatContext* ctx = (ChatContext*) self->x; uint8_t nick[MAX_NAME_LENGTH] = {0}; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(ctx->friendnum != num) return; @@ -42,10 +47,21 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(msg); fix_name(nick); + int inthour = timeinfo->tm_hour; + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); + wattron(ctx->history, COLOR_PAIR(4)); + wprintw(ctx->history, "%s: ", now); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s\n", msg); self->blink = true; @@ -74,6 +90,11 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 static void chat_onKey(ToxWindow* self, int key) { ChatContext* ctx = (ChatContext*) self->x; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(isprint(key)) { if(ctx->pos != sizeof(ctx->line)-1) { @@ -82,6 +103,17 @@ static void chat_onKey(ToxWindow* self, int key) { } } else if(key == '\n') { + + int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); From 9267ab2fcaaaedb70c68de6daccea1660138312d Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:14:47 -0700 Subject: [PATCH 02/24] Fixed a bug with the minutes only being 1 character long when less than 10 --- testing/toxic/chat.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 10837aa7..50aa81b0 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -52,7 +52,12 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) char min[2]; char hour[2]; sprintf(hour,"%d",inthour); - sprintf(min,"%d",intmin); + if (intmin < 10) { + sprintf(min,"0%d",intmin); + } else { + sprintf(min,"%d",intmin); + } + wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); @@ -109,7 +114,11 @@ static void chat_onKey(ToxWindow* self, int key) { char min[2]; char hour[2]; sprintf(hour,"%d",inthour); - sprintf(min,"%d",intmin); + if (intmin < 10) { + sprintf(min,"0%d",intmin); + } else { + sprintf(min,"%d",intmin); + } wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); From 8bc8016291aa3f153390e505f614c7b52a6613ae Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:44:30 -0700 Subject: [PATCH 03/24] By popular demand, I made a patch to add seconds to the timestamp --- testing/toxic/seconds.patch | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 testing/toxic/seconds.patch diff --git a/testing/toxic/seconds.patch b/testing/toxic/seconds.patch new file mode 100644 index 00000000..d7ce33a2 --- /dev/null +++ b/testing/toxic/seconds.patch @@ -0,0 +1,61 @@ +--- chat.c 2013-08-02 17:41:08.866583333 -0700 ++++ chat2.c 2013-08-02 17:38:13.672991322 -0700 +@@ -49,8 +49,10 @@ + + int inthour = timeinfo->tm_hour; + int intmin = timeinfo->tm_min; ++ int intsec = timeinfo->tm_sec; + char min[2]; + char hour[2]; ++ char sec[2]; + sprintf(hour,"%d",inthour); + if (intmin < 10) { + sprintf(min,"0%d",intmin); +@@ -58,10 +60,17 @@ + sprintf(min,"%d",intmin); + } + ++ if (intsec < 10) { ++ sprintf(sec,"0%d",intsec); ++ } else { ++ sprintf(sec,"%d",intsec); ++ } ++ + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); +- wprintw(ctx->history,":%s ",min); ++ wprintw(ctx->history,":%s",min); ++ wprintw(ctx->history,":%s",sec); + wattron(ctx->history, COLOR_PAIR(4)); + wprintw(ctx->history, "%s: ", now); + wattron(ctx->history, COLOR_PAIR(4)); +@@ -111,8 +120,10 @@ + + int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done + int intmin = timeinfo->tm_min; ++ int intsec = timeinfo ->tm_sec; + char min[2]; + char hour[2]; ++ char sec[2]; + sprintf(hour,"%d",inthour); + if (intmin < 10) { + sprintf(min,"0%d",intmin); +@@ -120,9 +131,16 @@ + sprintf(min,"%d",intmin); + } + ++ if (intsec < 10) { ++ sprintf(sec,"0%d",intsec); ++ } else { ++ sprintf(sec,"%d",intsec); ++ } ++ + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); +- wprintw(ctx->history,":%s ",min); ++ wprintw(ctx->history,":%s",min); ++ wprintw(ctx->history,":%s ",sec); + wattron(ctx->history, COLOR_PAIR(1)); + wprintw(ctx->history, "you: ", ctx->line); + wattroff(ctx->history, COLOR_PAIR(1)); From adffc77b75bae2e6016f5678ef0dcfd743776abc Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:46:31 -0700 Subject: [PATCH 04/24] Forgot a bit of documentation on using the patch --- PATCH.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 PATCH.md diff --git a/PATCH.md b/PATCH.md new file mode 100644 index 00000000..4af250f3 --- /dev/null +++ b/PATCH.md @@ -0,0 +1,2 @@ +Seconds.patch adds support for seconds to the timestamp in toxic. +To use seconds.patch run patch < seconds.patch while in the directory testing/toxic From d19b4b9db125cb3c75d1fcbe34103bf4bb6b55ff Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:50:35 -0700 Subject: [PATCH 05/24] Moved PATCH.md to the toxic folder --- PATCH.md => testing/toxic/PATCH.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PATCH.md => testing/toxic/PATCH.md (100%) diff --git a/PATCH.md b/testing/toxic/PATCH.md similarity index 100% rename from PATCH.md rename to testing/toxic/PATCH.md From 3678b302dbf2b202afe9e53b46153da69ecbb28e Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Fri, 2 Aug 2013 21:22:02 -0400 Subject: [PATCH 06/24] cleaned up print_friendlist(), it now prints a message if you have _no_ friends --- testing/nTox.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 24d40ead..4989f88a 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -82,18 +82,22 @@ void new_lines(char *line) void print_friendlist() { char name[MAX_NAME_LENGTH]; + int i = 0; new_lines("[i] Friend List:"); - uint32_t i; - for (i = 0; i <= num_requests; i++) { - char fstring[128]; - getname(i, (uint8_t*)name); + while(getname(i++, (uint8_t *)name) != -1) { + /* account for the longest name and the longest "base" string */ + char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")]; + if (strlen(name) <= 0) { - sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); + sprintf(fstring, "[i] Friend: No Friend!\n\tid: %i", i); } else { sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } new_lines(fstring); } + + if(i == 1) + new_lines("\tno friends! D:"); } char *format_message(char *message, int friendnum) From b9e3bf1fa61aac975abe54586e1928f25767ff0a Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Fri, 2 Aug 2013 22:34:45 -0400 Subject: [PATCH 07/24] changed some formatting, fixed the removal of x and y --- testing/nTox.c | 16 ++++++++++------ testing/nTox.h | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 4989f88a..a498e9a1 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -36,11 +36,12 @@ char lines[HISTORY][STRING_LENGTH]; char line[STRING_LENGTH]; -char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n" - "[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"; +char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message " + "(to send message)\n/s status (to change status)\n[i] /l list (l" + "ist friends)\n/h for help\n/i for info\n/n nick (to change nick" + "name)\n/q (to quit)"; int x, y; - uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t num_requests = 0; @@ -126,7 +127,7 @@ char *format_message(char *message, int friendnum) return msg; } -void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) +void line_eval(char *line) { if (line[0] == '/') { char inpt_command = line[1]; @@ -410,13 +411,16 @@ int main(int argc, char *argv[]) char idstring[200]; get_id(idstring); + initscr(); noecho(); raw(); getmaxyx(stdscr, y, x); + + new_lines("/h for list of commands"); new_lines(idstring); - new_lines(help); strcpy(line, ""); + IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); @@ -443,7 +447,7 @@ int main(int argc, char *argv[]) getmaxyx(stdscr, y, x); if (c == '\n') { - line_eval(lines, line); + line_eval(line); strcpy(line, ""); } else if (c == 127) { line[strlen(line)-1] = '\0'; diff --git a/testing/nTox.h b/testing/nTox.h index 9d82556c..47c73513 100644 --- a/testing/nTox.h +++ b/testing/nTox.h @@ -37,12 +37,13 @@ #include #include "../core/Messenger.h" #include "../core/network.h" + #define STRING_LENGTH 256 #define HISTORY 50 #define PUB_KEY_BYTES 32 void new_lines(char *line); -void line_eval(char lines[HISTORY][STRING_LENGTH], char *line); +void line_eval(char *line); void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ; int count_lines(char *string) ; char *appender(char *str, const char c); From 62bf320b6e3cb946cc70a972c35c114b0bcdbad1 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 19:58:00 -0700 Subject: [PATCH 08/24] Removed the seconds patch, it breaks things --- testing/toxic/PATCH.md | 2 -- testing/toxic/seconds.patch | 61 ------------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 testing/toxic/PATCH.md delete mode 100644 testing/toxic/seconds.patch diff --git a/testing/toxic/PATCH.md b/testing/toxic/PATCH.md deleted file mode 100644 index 4af250f3..00000000 --- a/testing/toxic/PATCH.md +++ /dev/null @@ -1,2 +0,0 @@ -Seconds.patch adds support for seconds to the timestamp in toxic. -To use seconds.patch run patch < seconds.patch while in the directory testing/toxic diff --git a/testing/toxic/seconds.patch b/testing/toxic/seconds.patch deleted file mode 100644 index d7ce33a2..00000000 --- a/testing/toxic/seconds.patch +++ /dev/null @@ -1,61 +0,0 @@ ---- chat.c 2013-08-02 17:41:08.866583333 -0700 -+++ chat2.c 2013-08-02 17:38:13.672991322 -0700 -@@ -49,8 +49,10 @@ - - int inthour = timeinfo->tm_hour; - int intmin = timeinfo->tm_min; -+ int intsec = timeinfo->tm_sec; - char min[2]; - char hour[2]; -+ char sec[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); -@@ -58,10 +60,17 @@ - sprintf(min,"%d",intmin); - } - -+ if (intsec < 10) { -+ sprintf(sec,"0%d",intsec); -+ } else { -+ sprintf(sec,"%d",intsec); -+ } -+ - - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); -- wprintw(ctx->history,":%s ",min); -+ wprintw(ctx->history,":%s",min); -+ wprintw(ctx->history,":%s",sec); - wattron(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s: ", now); - wattron(ctx->history, COLOR_PAIR(4)); -@@ -111,8 +120,10 @@ - - int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done - int intmin = timeinfo->tm_min; -+ int intsec = timeinfo ->tm_sec; - char min[2]; - char hour[2]; -+ char sec[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); -@@ -120,9 +131,16 @@ - sprintf(min,"%d",intmin); - } - -+ if (intsec < 10) { -+ sprintf(sec,"0%d",intsec); -+ } else { -+ sprintf(sec,"%d",intsec); -+ } -+ - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); -- wprintw(ctx->history,":%s ",min); -+ wprintw(ctx->history,":%s",min); -+ wprintw(ctx->history,":%s ",sec); - wattron(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "you: ", ctx->line); - wattroff(ctx->history, COLOR_PAIR(1)); From 6b8f12e33cb30380dd0d60943955b2d40118bb11 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 00:45:34 -0400 Subject: [PATCH 09/24] added a getopt system, with -f and -h flags --- testing/nTox.c | 73 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index a498e9a1..319002fd 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -85,7 +85,7 @@ void print_friendlist() char name[MAX_NAME_LENGTH]; int i = 0; new_lines("[i] Friend List:"); - while(getname(i++, (uint8_t *)name) != -1) { + while(getname(i, (uint8_t *)name) != -1) { /* account for the longest name and the longest "base" string */ char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")]; @@ -94,10 +94,11 @@ void print_friendlist() } else { sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } + i++; new_lines(fstring); } - if(i == 1) + if(i == 0) new_lines("\tno friends! D:"); } @@ -241,8 +242,7 @@ void line_eval(char *line) do_refresh(); } else if (inpt_command == 'h') { //help - new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); - new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"); + new_lines(help); } else if (inpt_command == 'i') { //info char idstring[200]; @@ -358,10 +358,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) new_lines(msg); } -void load_key() +void load_key(char *path) { - FILE *data_file = NULL; - data_file = fopen("data","r"); + FILE *data_file = fopen(path, "r"); + if (data_file) { //load keys fseek(data_file, 0, SEEK_END); @@ -373,12 +373,21 @@ void load_key() exit(1); } Messenger_load(data, size); + } else { + fputs("(saving new keys now)\n", stderr); + //else save new keys int size = Messenger_size(); uint8_t data[size]; Messenger_save(data); - data_file = fopen("data","w"); + data_file = fopen(path, "w"); + + if(!data_file) { + perror("[!] load_key"); + exit(1); + } + if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ printf("[i] could not write data file\n[i] exiting\n"); exit(1); @@ -387,38 +396,58 @@ void load_key() fclose(data_file); } +void print_help(void) +{ + printf("nTox %.1f - Command-line tox-core client\n", 0.1); + puts("Options:"); + puts("\t-h\t-\tPrint this help and exit."); + puts("\t-f\t-\tSpecify a keyfile to read from."); +} + int main(int argc, char *argv[]) { + int on = 0; + int c = 0; + int i = 0; + char *filename = "data"; + char idstring[200] = {0}; + if (argc < 4) { - printf("[!] Usage: %s [IP] [port] [public_key] \n", argv[0]); + printf("[!] Usage: %s [IP] [port] [public_key] \n", argv[0]); exit(0); } - int c; - int on = 0; - initMessenger(); - //if keyfiles exist - if(argc > 4){ - if(strncmp(argv[4], "nokey", 6) < 0){ - //load_key(); + + for(i = 0; i < argc; i++) { + if(argv[i][0] == '-') { + if(argv[i][1] == 'h') { + print_help(); + exit(0); + } else if(argv[i][1] == 'f') { + if(argv[i + 1] != NULL) + filename = argv[i + 1]; + else { + fputs("[!] you passed '-f' without giving an argument!\n", stderr); + } + } } - } else { - load_key(); } + + initMessenger(); + load_key(filename); + m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); - char idstring[200]; - get_id(idstring); - initscr(); noecho(); raw(); getmaxyx(stdscr, y, x); new_lines("/h for list of commands"); - new_lines(idstring); + get_id(idstring); + puts(idstring); strcpy(line, ""); IP_Port bootstrap_ip_port; From bb2ea0e5b40012dc722727fe8e5274cd6ec9c563 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 01:14:30 -0400 Subject: [PATCH 10/24] Fixed the printing of a few strings, moved some code around. --- testing/nTox.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 319002fd..dec7a12d 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -90,7 +90,7 @@ void print_friendlist() char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")]; if (strlen(name) <= 0) { - sprintf(fstring, "[i] Friend: No Friend!\n\tid: %i", i); + sprintf(fstring, "[i] Friend: !\n\tid: %i", i); } else { sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } @@ -375,8 +375,6 @@ void load_key(char *path) Messenger_load(data, size); } else { - fputs("(saving new keys now)\n", stderr); - //else save new keys int size = Messenger_size(); uint8_t data[size]; @@ -389,7 +387,7 @@ void load_key(char *path) } if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ - printf("[i] could not write data file\n[i] exiting\n"); + puts("[i] could not write data file! exiting..."); exit(1); } } @@ -401,7 +399,7 @@ void print_help(void) printf("nTox %.1f - Command-line tox-core client\n", 0.1); puts("Options:"); puts("\t-h\t-\tPrint this help and exit."); - puts("\t-f\t-\tSpecify a keyfile to read from."); + puts("\t-f\t-\tSpecify a keyfile to read (or write to) from."); } int main(int argc, char *argv[]) @@ -447,7 +445,7 @@ int main(int argc, char *argv[]) new_lines("/h for list of commands"); get_id(idstring); - puts(idstring); + new_lines(idstring); strcpy(line, ""); IP_Port bootstrap_ip_port; @@ -457,7 +455,7 @@ int main(int argc, char *argv[]) bootstrap_ip_port.ip.i = resolved_address; else exit(1); - + DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); nodelay(stdscr, TRUE); while(true) { From 9b6283c084d1c109be1319d8d325c01322b2cfc5 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 01:27:20 -0400 Subject: [PATCH 11/24] whoops, removed part of a string by accident. --- testing/nTox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/nTox.c b/testing/nTox.c index dec7a12d..312484d6 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -90,7 +90,7 @@ void print_friendlist() char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")]; if (strlen(name) <= 0) { - sprintf(fstring, "[i] Friend: !\n\tid: %i", i); + sprintf(fstring, "[i] Friend: No Friend!\n\tid: %i", i); } else { sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } From e9c330dc60eb54606299abb8cafe0408f7fb76c3 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 01:52:13 -0700 Subject: [PATCH 12/24] Merged a change from a pull request, added a break Merged from https://github.com/greato/ProjectTox-Core --- testing/toxic/prompt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index b0f83811..8536b940 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -141,6 +141,7 @@ static void execute(ToxWindow* self, char* cmd) { case -2: wprintw(self->window, "Please add a message to your request.\n"); case -3: + break; wprintw(self->window, "That appears to be your own ID.\n"); break; case -4: From c444d7a5d4b581e4a205361d146a72cefabcc8b8 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 01:55:07 -0700 Subject: [PATCH 13/24] Added a break from a pull request Merged a change from https://github.com/greato/ProjectTox-Core --- testing/toxic/prompt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 484f5906..e71f5f06 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -141,6 +141,7 @@ static void execute(ToxWindow* self, char* cmd) { case -2: wprintw(self->window, "Please add a message to your request.\n"); case -3: + break; wprintw(self->window, "That appears to be your own ID.\n"); break; case -4: From 52f1dcd9ffc6116d8f45a5451a23cc99becb0d2e Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 03:59:27 -0700 Subject: [PATCH 14/24] Fixed a segfault when recieving text --- testing/toxic/chat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 0e14a295..b835cf2d 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -63,8 +63,6 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); wattron(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s: ", now); - wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s\n", msg); @@ -109,17 +107,19 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { + printf("Get times to int"); int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done int intmin = timeinfo->tm_min; char min[2]; char hour[2]; + printf("Turn to varible"); sprintf(hour,"%d",inthour); if (intmin < 10) { sprintf(min,"0%d",intmin); } else { sprintf(min,"%d",intmin); } - + printf("Display"); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); From 86d7734efea1e7f345a9635f78bbf055116f8d84 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 04:10:47 -0700 Subject: [PATCH 15/24] Removed some useless code --- testing/toxic/chat.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index b835cf2d..19f5c972 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -107,19 +107,16 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { - printf("Get times to int"); int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done int intmin = timeinfo->tm_min; char min[2]; char hour[2]; - printf("Turn to varible"); sprintf(hour,"%d",inthour); if (intmin < 10) { sprintf(min,"0%d",intmin); } else { sprintf(min,"%d",intmin); } - printf("Display"); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); From 28944151c71bae923f8b5cbcdf090cb3190bf098 Mon Sep 17 00:00:00 2001 From: Michael Kress Date: Sat, 3 Aug 2013 16:00:48 +0200 Subject: [PATCH 16/24] fixed printing time stamp in toxic --- testing/toxic/chat.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 19f5c972..ddf59233 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -47,21 +47,8 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(msg); fix_name(nick); - int inthour = timeinfo->tm_hour; - int intmin = timeinfo->tm_min; - char min[2]; - char hour[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); - } else { - sprintf(min,"%d",intmin); - } - - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); - wprintw(ctx->history,":%s ",min); + wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); @@ -106,24 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) { } } else if(key == '\n') { - - int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done - int intmin = timeinfo->tm_min; - char min[2]; - char hour[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); - } else { - sprintf(min,"%d",intmin); - } wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); - wprintw(ctx->history,":%s ",min); + wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "%s\n", ctx->line); if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { @@ -140,7 +114,7 @@ static void chat_onKey(ToxWindow* self, int key) { ctx->line[--ctx->pos] = '\0'; } } - + } static void chat_onDraw(ToxWindow* self) { @@ -188,7 +162,7 @@ ToxWindow new_chat(int friendnum) { uint8_t nick[MAX_NAME_LENGTH] = {0}; getname(friendnum, (uint8_t*) &nick); fix_name(nick); - + snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); ChatContext* x = calloc(1, sizeof(ChatContext)); From 1ae2bfbb7530d3bf856a60587efc3932b4438df6 Mon Sep 17 00:00:00 2001 From: Michael Kress Date: Sat, 3 Aug 2013 16:26:23 +0200 Subject: [PATCH 17/24] added seconds to time stamp in toxic --- testing/toxic/chat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index ddf59233..7cae1c0a 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -48,7 +48,7 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(nick); wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); + wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); @@ -94,7 +94,7 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); + wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); From 54aebfd8071c3e2c7a92c10154dc3644b66ad76b Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 11:51:40 -0700 Subject: [PATCH 18/24] Removed an early break --- testing/toxic/prompt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index e80bdab0..1db60883 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -142,7 +142,6 @@ static void execute(ToxWindow* self, char* cmd) { wprintw(self->window, "Please add a message to your request.\n"); break; case -3: - break; wprintw(self->window, "That appears to be your own ID.\n"); break; case -4: From e77424c40a3f0e71f136d8b0fb179eaef5b970d1 Mon Sep 17 00:00:00 2001 From: Yati Sagade Date: Sun, 4 Aug 2013 00:35:39 +0530 Subject: [PATCH 19/24] Fixed a link --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 55135d03..79b9fd5d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Keep everything really simple. ## The Complex Stuff: + Tox must use UDP simply because [hole punching](http://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable. -+ Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key of the peer [client ID]). ++ Every peer is represented as a [byte string][String] (the public key of the peer [client ID]). + We're using torrent-style DHT so that peers can find the IP of the other peers when they have their ID. + Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)) + When both peers are securely connected, they can exchange messages, initiate a video chat, send files, etc, all using encrypted communications. @@ -50,3 +50,4 @@ configure for the normal user or suffer from being way too centralized. - [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)
- [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)
- [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas) +- [String]: https://en.wikipedia.org/wiki/String_(computer_science) From 7503bfe0aa2f0473225db453a4e5304b4b4ee6f9 Mon Sep 17 00:00:00 2001 From: Yati Sagade Date: Sun, 4 Aug 2013 00:37:14 +0530 Subject: [PATCH 20/24] Fixed a link --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79b9fd5d..a81503a9 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,5 @@ configure for the normal user or suffer from being way too centralized. - [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)
- [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)
- [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas) -- [String]: https://en.wikipedia.org/wiki/String_(computer_science) + +[String]: https://en.wikipedia.org/wiki/String_(computer_science) From d34e4a3408a176525bedfad87cfc996afbe21b66 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 15:12:02 -0400 Subject: [PATCH 21/24] added the -f flag for toxic --- testing/toxic/main.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 391b0b39..001d3382 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -170,12 +170,12 @@ static void do_tox() { doMessenger(); } -static void load_data() { +static void load_data(char *path) { FILE* fd; size_t len; uint8_t* buf; - if((fd = fopen("data", "r")) != NULL) { + if((fd = fopen(path, "r")) != NULL) { fseek(fd, 0, SEEK_END); len = ftell(fd); fseek(fd, 0, SEEK_SET); @@ -213,7 +213,7 @@ static void load_data() { Messenger_save(buf); - fd = fopen("data", "w"); + fd = fopen(path, "w"); if(fd == NULL) { fprintf(stderr, "fopen() failed.\n"); @@ -282,11 +282,25 @@ void prepare_window(WINDOW* w) { int main(int argc, char* argv[]) { int ch; + int i = 0; + char *filename = "data"; ToxWindow* a; + for(i = 0; i < argc; i++) { + if(argv[i][0] == '-') { + if(argv[i][1] == 'f') { + if(argv[i + 1] != NULL) + filename = argv[i + 1]; + else { + fputs("[!] you passed '-f' without giving an argument!\n", stderr); + } + } + } + } + init_term(); init_tox(); - load_data(); + load_data(filename); init_windows(); while(true) { From 9b56e21f81b0956e936a605f2b82d61eecd3d435 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 16:12:02 -0400 Subject: [PATCH 22/24] added a proper error message for messing up the -f flag --- testing/toxic/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 001d3382..3b45a89f 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -283,6 +283,7 @@ void prepare_window(WINDOW* w) { int main(int argc, char* argv[]) { int ch; int i = 0; + int f_flag = 0; char *filename = "data"; ToxWindow* a; @@ -292,7 +293,7 @@ int main(int argc, char* argv[]) { if(argv[i + 1] != NULL) filename = argv[i + 1]; else { - fputs("[!] you passed '-f' without giving an argument!\n", stderr); + f_flag = -1; } } } @@ -303,6 +304,14 @@ int main(int argc, char* argv[]) { load_data(filename); init_windows(); + if(f_flag == -1) { + attron(COLOR_PAIR(3) | A_BOLD); + wprintw(prompt->window, "You passed '-f' without giving an argument!\n" + "defaulting to 'data' for a keyfile...\n"); + attroff(COLOR_PAIR(3) | A_BOLD); + } + + while(true) { // Update tox. do_tox(); From a65715e81134207677354a2e827a38723f3ee6bc Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 17:29:18 -0400 Subject: [PATCH 23/24] fix for issue #306 --- testing/toxic/chat.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 7cae1c0a..a90bb2aa 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -77,6 +77,18 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 } +/* check that the string has one non-space character */ +int string_is_empty(char *string) +{ + int rc = 0; + char *copy = strdup(string); + + rc = ((strtok(copy, " ") == NULL) ? 1:0); + free(copy); + + return rc; +} + static void chat_onKey(ToxWindow* self, int key) { ChatContext* ctx = (ChatContext*) self->x; @@ -92,23 +104,28 @@ static void chat_onKey(ToxWindow* self, int key) { ctx->line[ctx->pos] = '\0'; } } + else if(key == '\n') { - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); - wattron(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "you: ", ctx->line); - wattroff(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "%s\n", ctx->line); + if(!string_is_empty(ctx->line)) { + /* make sure the string has at least non-space character */ + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + wattron(ctx->history, COLOR_PAIR(1)); + wprintw(ctx->history, "you: ", ctx->line); + wattroff(ctx->history, COLOR_PAIR(1)); + wprintw(ctx->history, "%s\n", ctx->line); - if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { - wattron(ctx->history, COLOR_PAIR(3)); - wprintw(ctx->history, " * Failed to send message.\n"); - wattroff(ctx->history, COLOR_PAIR(3)); + if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { + wattron(ctx->history, COLOR_PAIR(3)); + wprintw(ctx->history, " * Failed to send message.\n"); + wattroff(ctx->history, COLOR_PAIR(3)); + } + + ctx->line[0] = '\0'; + ctx->pos = 0; } - - ctx->line[0] = '\0'; - ctx->pos = 0; } + else if(key == 0x107 || key == 0x8 || key == 0x7f) { if(ctx->pos != 0) { ctx->line[--ctx->pos] = '\0'; From 158751cb2db8d2e11e38cbc926d0a979f8a8350a Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sat, 3 Aug 2013 14:46:52 -0700 Subject: [PATCH 24/24] various fixes for first time user * added linking to libsodium * fixed links to docs to point to wiki --- INSTALL.md | 3 ++- core/CMakeLists.txt | 1 + core/DHT.c | 2 +- core/DHT.h | 2 +- core/Lossless_UDP.c | 4 ++-- core/Lossless_UDP.h | 2 +- core/net_crypto.c | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 625a9c6d..483928b0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -101,6 +101,7 @@ Grab the following packages: * http://www.gnu.org/software/automake/ * http://www.cmake.org/ * https://github.com/jedisct1/libsodium + * http://www.hyperrealm.com/libconfig/ Uncompress and install them all. Make sure to follow the README as the instructions change, but they all follow the same pattern below: @@ -118,7 +119,7 @@ make ``` Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory -and make your life more annoying. +(or the wrong version gets installed) and make your life more annoying. Another thing you may want to install is the latest gcc, this caused me a few problems as XCode from 4.3 no longer includes gcc and instead uses LLVM-GCC, a nice install guide can be found at diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 36acb6cf..5bd496cb 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -17,3 +17,4 @@ set(core_sources Messenger.c) add_library(toxcore SHARED ${core_sources}) +target_link_libraries(toxcore ${SODIUM_LIBRARY}) diff --git a/core/DHT.c b/core/DHT.c index 5d5910e0..08b4710e 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -1,6 +1,6 @@ /* DHT.c * - * An implementation of the DHT as seen in docs/DHT.txt + * An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT * * Copyright (C) 2013 Tox project All Rights Reserved. * diff --git a/core/DHT.h b/core/DHT.h index ffa02087..36670ed5 100644 --- a/core/DHT.h +++ b/core/DHT.h @@ -1,6 +1,6 @@ /* DHT.h * - * An implementation of the DHT as seen in docs/DHT.txt + * An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT * * Copyright (C) 2013 Tox project All Rights Reserved. * diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 33b8eb19..a753e5ff 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c @@ -1,6 +1,6 @@ /* Lossless_UDP.c * - * An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt + * An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP * * Copyright (C) 2013 Tox project All Rights Reserved. * @@ -467,7 +467,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested) /* * BEGIN Packet sending functions * One per packet type. - * see docs/Lossless_UDP.txt for more information. + * see http://wiki.tox.im/index.php/Lossless_UDP for more information. */ int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) diff --git a/core/Lossless_UDP.h b/core/Lossless_UDP.h index 573e1ab9..75ef273e 100644 --- a/core/Lossless_UDP.h +++ b/core/Lossless_UDP.h @@ -1,6 +1,6 @@ /* Lossless_UDP.h * - * An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt + * An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP * * Copyright (C) 2013 Tox project All Rights Reserved. * diff --git a/core/net_crypto.c b/core/net_crypto.c index 3b5b67f4..561ba866 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -1,7 +1,7 @@ /* net_crypto.c * * Functions for the core network crypto. - * See also: docs/Crypto.txt + * See also: http://wiki.tox.im/index.php/DHT * * NOTE: This code has to be perfect. We don't mess around with encryption. *