summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Messenger.c6
-rw-r--r--testing/Messenger_test.c3
-rw-r--r--testing/misc_tools.h2
-rw-r--r--testing/nTox_win32.c6
-rw-r--r--testing/nTox_win32.h4
-rw-r--r--testing/toxic/main.c13
-rw-r--r--testing/toxic/prompt.c62
7 files changed, 79 insertions, 17 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 5532c9cc..4e994a15 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -116,8 +116,8 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
116 return FAERR_ALREADYSENT; 116 return FAERR_ALREADYSENT;
117 117
118 uint32_t i; 118 uint32_t i;
119 for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ 119 for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
120 if(friendlist[i].status == NOFRIEND) { 120 if (friendlist[i].status == NOFRIEND) {
121 DHT_addfriend(client_id); 121 DHT_addfriend(client_id);
122 friendlist[i].status = FRIEND_ADDED; 122 friendlist[i].status = FRIEND_ADDED;
123 friendlist[i].crypt_connection_id = -1; 123 friendlist[i].crypt_connection_id = -1;
@@ -141,7 +141,7 @@ int m_addfriend_norequest(uint8_t * client_id)
141 if (getfriend_id(client_id) != -1) 141 if (getfriend_id(client_id) != -1)
142 return -1; 142 return -1;
143 uint32_t i; 143 uint32_t i;
144 for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ 144 for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
145 if(friendlist[i].status == NOFRIEND) { 145 if(friendlist[i].status == NOFRIEND) {
146 DHT_addfriend(client_id); 146 DHT_addfriend(client_id);
147 friendlist[i].status = FRIEND_REQUESTED; 147 friendlist[i].status = FRIEND_REQUESTED;
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 0518d284..24a78abb 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -138,7 +138,8 @@ int main(int argc, char *argv[])
138 if ( file==NULL ){return 1;} 138 if ( file==NULL ){return 1;}
139 uint8_t * buffer = malloc(Messenger_size()); 139 uint8_t * buffer = malloc(Messenger_size());
140 Messenger_save(buffer); 140 Messenger_save(buffer);
141 fwrite(buffer, 1, Messenger_size(), file); 141 size_t write_result = fwrite(buffer, 1, Messenger_size(), file);
142 if (write_result < Messenger_size()) {return 1;}
142 free(buffer); 143 free(buffer);
143 fclose(file); 144 fclose(file);
144 } 145 }
diff --git a/testing/misc_tools.h b/testing/misc_tools.h
index eb09693e..1abdb809 100644
--- a/testing/misc_tools.h
+++ b/testing/misc_tools.h
@@ -51,6 +51,7 @@ unsigned char * hex_string_to_bin(char hex_string[]);
51 DEBUG_PRINT(__VA_ARGS__, ' '); \ 51 DEBUG_PRINT(__VA_ARGS__, ' '); \
52 } while (0) 52 } while (0)
53 53
54 #undef ERROR
54 #define ERROR(exit_status, ...) do { \ 55 #define ERROR(exit_status, ...) do { \
55 fprintf(stderr, "error in "); \ 56 fprintf(stderr, "error in "); \
56 DEBUG_PRINT(__VA_ARGS__, ' '); \ 57 DEBUG_PRINT(__VA_ARGS__, ' '); \
@@ -58,6 +59,7 @@ unsigned char * hex_string_to_bin(char hex_string[]);
58 } while (0) 59 } while (0)
59#else 60#else
60 #define WARNING(...) 61 #define WARNING(...)
62 #undef ERROR
61 #define ERROR(...) 63 #define ERROR(...)
62#endif // DEBUG 64#endif // DEBUG
63 65
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index dbbd0f6e..e4489f13 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
86 printf(msg); 86 printf(msg);
87} 87}
88 88
89void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length) 89void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length)
90{ 90{
91 char name[MAX_NAME_LENGTH]; 91 char name[MAX_NAME_LENGTH];
92 getname(friendnumber, (uint8_t*)name); 92 getname(friendnumber, (uint8_t*)name);
@@ -275,7 +275,7 @@ void change_status(int savetofile)
275 } 275 }
276 276
277 status[i-3] = 0; 277 status[i-3] = 0;
278 m_set_userstatus(status, strlen((char*)status)); 278 m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status));
279 char numstring[100]; 279 char numstring[100];
280 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); 280 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
281 printf(numstring); 281 printf(numstring);
@@ -407,7 +407,7 @@ int main(int argc, char *argv[])
407 while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { 407 while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
408 sscanf(line, "%s", (char*)status); 408 sscanf(line, "%s", (char*)status);
409 } 409 }
410 m_set_userstatus(status, strlen((char*)status)+1); 410 m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1);
411 statusloaded = 1; 411 statusloaded = 1;
412 printf("%s\n", status); 412 printf("%s\n", status);
413 fclose(status_file); 413 fclose(status_file);
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h
index 271403b8..36d5df1f 100644
--- a/testing/nTox_win32.h
+++ b/testing/nTox_win32.h
@@ -32,7 +32,7 @@
32void do_header(); 32void do_header();
33void print_message(int friendnumber, uint8_t * string, uint16_t length); 33void print_message(int friendnumber, uint8_t * string, uint16_t length);
34void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); 34void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
35void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); 35void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length);
36void load_key(); 36void load_key();
37void add_friend(); 37void add_friend();
38void list_friends(); 38void list_friends();
@@ -44,4 +44,4 @@ void accept_friend_request();
44void line_eval(char* line); 44void line_eval(char* line);
45void get_input(); 45void get_input();
46 46
47#endif \ No newline at end of file 47#endif
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 1ba8b6c9..8de76244 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -249,6 +249,7 @@ static void load_data(char *path)
249static void draw_bar() 249static void draw_bar()
250{ 250{
251 static int odd = 0; 251 static int odd = 0;
252 int blinkrate = 30;
252 253
253 attron(COLOR_PAIR(4)); 254 attron(COLOR_PAIR(4));
254 mvhline(LINES - 2, 0, '_', COLS); 255 mvhline(LINES - 2, 0, '_', COLS);
@@ -266,14 +267,13 @@ static void draw_bar()
266 if (i == active_window) 267 if (i == active_window)
267 attron(A_BOLD); 268 attron(A_BOLD);
268 269
269 odd = (odd+1) % 10; 270 odd = (odd+1) % blinkrate;
270 if (windows[i].blink && (odd < 5)) { 271 if (windows[i].blink && (odd < (blinkrate/2))) {
271 attron(COLOR_PAIR(3)); 272 attron(COLOR_PAIR(3));
272 } 273 }
273
274 printw(" %s", windows[i].title); 274 printw(" %s", windows[i].title);
275 if (windows[i].blink && (odd < 5)) { 275 if (windows[i].blink && (odd < (blinkrate/2))) {
276 attron(COLOR_PAIR(3)); 276 attroff(COLOR_PAIR(3));
277 } 277 }
278 if (i == active_window) { 278 if (i == active_window) {
279 attroff(A_BOLD); 279 attroff(A_BOLD);
@@ -375,9 +375,8 @@ int main(int argc, char *argv[])
375 ch = getch(); 375 ch = getch();
376 if (ch == '\t' || ch == KEY_BTAB) 376 if (ch == '\t' || ch == KEY_BTAB)
377 set_active_window(ch); 377 set_active_window(ch);
378 else if (ch != ERR) { 378 else if (ch != ERR)
379 a->onKey(a, ch); 379 a->onKey(a, ch);
380 }
381 } 380 }
382 return 0; 381 return 0;
383} 382}
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 89c87d8f..d79d061f 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -52,6 +52,17 @@ static void execute(ToxWindow *self, char *u_cmd)
52 cmd[i - newlines] = u_cmd[i]; 52 cmd[i - newlines] = u_cmd[i];
53 } 53 }
54 54
55 int leading_spc = 0;
56 for (i = 0; i < 256 && isspace(cmd[i]); ++i)
57 leading_spc++;
58 memmove(cmd, cmd + leading_spc, 256 - leading_spc);
59
60 int cmd_end = strlen(cmd);
61 while (cmd_end > 0 && cmd_end--)
62 if (!isspace(cmd[cmd_end]))
63 break;
64 cmd[cmd_end + 1] = '\0';
65
55 if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { 66 if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
56 endwin(); 67 endwin();
57 exit(0); 68 exit(0);
@@ -164,6 +175,54 @@ static void execute(ToxWindow *self, char *u_cmd)
164 } 175 }
165 176
166 else if (!strncmp(cmd, "status ", strlen("status "))) { 177 else if (!strncmp(cmd, "status ", strlen("status "))) {
178 char *status = strchr(cmd, ' ');
179 char *msg;
180 char *status_text;
181 if (status == NULL) {
182 wprintw(self->window, "Invalid syntax.\n");
183 return;
184 }
185 status++;
186 USERSTATUS_KIND status_kind;
187 if (!strncmp(status, "online", strlen("online"))) {
188 status_kind = USERSTATUS_KIND_ONLINE;
189 status_text = "ONLINE";
190 }
191
192 else if (!strncmp(status, "away", strlen("away"))) {
193 status_kind = USERSTATUS_KIND_AWAY;
194 status_text = "AWAY";
195 }
196
197 else if (!strncmp(status, "busy", strlen("busy"))) {
198 status_kind = USERSTATUS_KIND_BUSY;
199 status_text = "BUSY";
200 }
201
202 else if (!strncmp(status, "offline", strlen("offline"))) {
203 status_kind = USERSTATUS_KIND_OFFLINE;
204 status_text = "OFFLINE";
205 }
206
207 else
208 {
209 wprintw(self->window, "Invalid status.\n");
210 return;
211 }
212
213 msg = strchr(status, ' ');
214 if (msg == NULL) {
215 m_set_userstatus_kind(status_kind);
216 wprintw(self->window, "Status set to: %s\n", status_text);
217 }
218 else {
219 msg++;
220 m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1);
221 wprintw(self->window, "Status set to: %s, %s\n", status_text, msg);
222 }
223 }
224
225 else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) {
167 char *msg = strchr(cmd, ' '); 226 char *msg = strchr(cmd, ' ');
168 if (msg == NULL) { 227 if (msg == NULL) {
169 wprintw(self->window, "Invalid syntax.\n"); 228 wprintw(self->window, "Invalid syntax.\n");
@@ -306,7 +365,8 @@ static void print_usage(ToxWindow *self)
306 365
307 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); 366 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
308 wprintw(self->window, " add <id> <message> : Add friend\n"); 367 wprintw(self->window, " add <id> <message> : Add friend\n");
309 wprintw(self->window, " status <message> : Set your status\n"); 368 wprintw(self->window, " status <type> <message> : Set your status\n");
369 wprintw(self->window, " statusmsg <message> : Set your status\n");
310 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 370 wprintw(self->window, " nick <nickname> : Set your nickname\n");
311 wprintw(self->window, " accept <number> : Accept friend request\n"); 371 wprintw(self->window, " accept <number> : Accept friend request\n");
312 wprintw(self->window, " myid : Print your ID\n"); 372 wprintw(self->window, " myid : Print your ID\n");