summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 097c73af..3a5e9bb3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -1,3 +1,26 @@
1/* nTox.c
2 *
3 * Textual frontend for Tox.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
1#include "nTox.h" 24#include "nTox.h"
2#include <stdio.h> 25#include <stdio.h>
3#include <time.h> 26#include <time.h>
@@ -23,12 +46,14 @@ void new_lines(char *line)
23 do_refresh(); 46 do_refresh();
24} 47}
25 48
49//TODO: rewrite
26unsigned char * hex_string_to_bin(char hex_string[]) 50unsigned char * hex_string_to_bin(char hex_string[])
27{ 51{
28 unsigned char * val = malloc(strlen(hex_string)); 52 size_t len = strlen(hex_string);
53 unsigned char * val = malloc(len);
29 char * pos = hex_string; 54 char * pos = hex_string;
30 int i=0; 55 int i=0;
31 while(i < strlen(hex_string)) 56 while(i < len)
32 { 57 {
33 sscanf(pos,"%2hhx",&val[i]); 58 sscanf(pos,"%2hhx",&val[i]);
34 pos+=2; 59 pos+=2;
@@ -58,7 +83,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
58 doMessenger(); 83 doMessenger();
59 } else if (line[1] == 'm') { //message command: /m friendnumber messsage 84 } else if (line[1] == 'm') { //message command: /m friendnumber messsage
60 int i; 85 int i;
61 int len = strlen(line); 86 size_t len = strlen(line);
62 char numstring[len-3]; 87 char numstring[len-3];
63 char message[len-3]; 88 char message[len-3];
64 for (i=0; i<len; i++) { 89 for (i=0; i<len; i++) {
@@ -77,7 +102,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
77 } else if (line[1] == 'n') { 102 } else if (line[1] == 'n') {
78 uint8_t name[MAX_NAME_LENGTH]; 103 uint8_t name[MAX_NAME_LENGTH];
79 int i = 0; 104 int i = 0;
80 for (i=3; i<strlen(line); i++) { 105 size_t len = strlen(line);
106 for (i=3; i<len; i++) {
81 if (line[i] == 0 || line[i] == '\n') break; 107 if (line[i] == 0 || line[i] == '\n') break;
82 name[i - 3] = line[i]; 108 name[i - 3] = line[i];
83 } 109 }
@@ -89,7 +115,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
89 } else if (line[1] == 's') { 115 } else if (line[1] == 's') {
90 uint8_t status[MAX_USERSTATUS_LENGTH]; 116 uint8_t status[MAX_USERSTATUS_LENGTH];
91 int i = 0; 117 int i = 0;
92 for (i=3; i<strlen(line); i++) { 118 size_t len = strlen(line);
119 for (i=3; i<len; i++) {
93 if (line[i] == 0 || line[i] == '\n') break; 120 if (line[i] == 0 || line[i] == '\n') break;
94 status[i - 3] = line[i]; 121 status[i - 3] = line[i];
95 } 122 }
@@ -111,7 +138,8 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
111{ 138{
112 int i = 0; 139 int i = 0;
113 strcpy(output,input); 140 strcpy(output,input);
114 for (i=line_width; i < strlen(output); i = i + line_width) { 141 size_t len = strlen(output);
142 for (i=line_width; i < len; i = i + line_width) {
115 while (output[i] != ' ' && i != 0) { 143 while (output[i] != ' ' && i != 0) {
116 i--; 144 i--;
117 } 145 }
@@ -123,7 +151,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
123 151
124int count_lines(char *string) 152int count_lines(char *string)
125{ 153{
126 int len = strlen(string); 154 size_t len = strlen(string);
127 int i; 155 int i;
128 int count = 1; 156 int count = 1;
129 for (i=0; i < len; i++) { 157 for (i=0; i < len; i++) {
@@ -136,7 +164,7 @@ int count_lines(char *string)
136 164
137char *appender(char *str, const char c) 165char *appender(char *str, const char c)
138{ 166{
139 int len = strlen(str); 167 size_t len = strlen(str);
140 if (len < STRING_LENGTH) { 168 if (len < STRING_LENGTH) {
141 str[len + 1] = str[len]; 169 str[len + 1] = str[len];
142 str[len] = c; 170 str[len] = c;
@@ -167,6 +195,7 @@ void do_refresh()
167 clrtoeol(); 195 clrtoeol();
168 refresh(); 196 refresh();
169} 197}
198
170void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) 199void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
171{ 200{
172 new_lines("[i] received friend request"); 201 new_lines("[i] received friend request");
@@ -182,6 +211,7 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
182 new_lines(numchar); 211 new_lines(numchar);
183 } 212 }
184} 213}
214
185void print_message(int friendnumber, uint8_t * string, uint16_t length) 215void print_message(int friendnumber, uint8_t * string, uint16_t length)
186{ 216{
187 char name[MAX_NAME_LENGTH]; 217 char name[MAX_NAME_LENGTH];
@@ -192,11 +222,12 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
192 time ( &rawtime ); 222 time ( &rawtime );
193 timeinfo = localtime ( &rawtime ); 223 timeinfo = localtime ( &rawtime );
194 char* temp = asctime(timeinfo); 224 char* temp = asctime(timeinfo);
195 int len = strlen(temp); 225 size_t len = strlen(temp);
196 temp[len-1]='\0'; 226 temp[len-1]='\0';
197 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this 227 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
198 new_lines(msg); 228 new_lines(msg);
199} 229}
230
200void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { 231void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
201 char name[MAX_NAME_LENGTH]; 232 char name[MAX_NAME_LENGTH];
202 getname(friendnumber, (uint8_t*)name); 233 getname(friendnumber, (uint8_t*)name);
@@ -204,6 +235,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
204 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); 235 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
205 new_lines(msg); 236 new_lines(msg);
206} 237}
238
207void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { 239void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
208 char name[MAX_NAME_LENGTH]; 240 char name[MAX_NAME_LENGTH];
209 getname(friendnumber, (uint8_t*)name); 241 getname(friendnumber, (uint8_t*)name);
@@ -211,6 +243,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
211 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); 243 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
212 new_lines(msg); 244 new_lines(msg);
213} 245}
246
214void load_key(){ 247void load_key(){
215 FILE *data_file = NULL; 248 FILE *data_file = NULL;
216 if ((data_file = fopen("data","r"))) { 249 if ((data_file = fopen("data","r"))) {
@@ -237,6 +270,7 @@ void load_key(){
237 } 270 }
238 fclose(data_file); 271 fclose(data_file);
239} 272}
273
240int main(int argc, char *argv[]) 274int main(int argc, char *argv[])
241{ 275{
242 if (argc < 4) { 276 if (argc < 4) {
@@ -294,9 +328,7 @@ int main(int argc, char *argv[])
294 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 328 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
295 nodelay(stdscr, TRUE); 329 nodelay(stdscr, TRUE);
296 while(true) { 330 while(true) {
297 331 if (on == 0 && DHT_isconnected()) {
298 if (on == 0 && DHT_isconnected())
299 {
300 new_lines("[i] connected to DHT\n[i] define username with /n"); 332 new_lines("[i] connected to DHT\n[i] define username with /n");
301 on = 1; 333 on = 1;
302 } 334 }