diff options
Diffstat (limited to 'testing/toxic')
-rw-r--r-- | testing/toxic/chat.c | 36 | ||||
-rw-r--r-- | testing/toxic/friendlist.c | 16 | ||||
-rw-r--r-- | testing/toxic/main.c | 47 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 78 | ||||
-rw-r--r-- | testing/toxic/windows.h | 10 |
5 files changed, 95 insertions, 92 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index e1897230..112b20b7 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -29,9 +29,9 @@ extern int active_window; | |||
29 | extern void del_window(ToxWindow *w, int f_num); | 29 | extern void del_window(ToxWindow *w, int f_num); |
30 | extern void fix_name(uint8_t *name); | 30 | extern void fix_name(uint8_t *name); |
31 | void print_help(ChatContext *self); | 31 | void print_help(ChatContext *self); |
32 | void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo); | 32 | void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo); |
33 | 33 | ||
34 | static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | 34 | static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, uint16_t len) |
35 | { | 35 | { |
36 | ChatContext *ctx = (ChatContext*) self->x; | 36 | ChatContext *ctx = (ChatContext*) self->x; |
37 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 37 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
@@ -43,7 +43,7 @@ static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | |||
43 | if (ctx->friendnum != num) | 43 | if (ctx->friendnum != num) |
44 | return; | 44 | return; |
45 | 45 | ||
46 | getname(num, (uint8_t*) &nick); | 46 | getname(m, num, (uint8_t*) &nick); |
47 | msg[len-1] = '\0'; | 47 | msg[len-1] = '\0'; |
48 | nick[MAX_NAME_LENGTH-1] = '\0'; | 48 | nick[MAX_NAME_LENGTH-1] = '\0'; |
49 | fix_name(msg); | 49 | fix_name(msg); |
@@ -61,7 +61,7 @@ static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | |||
61 | beep(); | 61 | beep(); |
62 | } | 62 | } |
63 | 63 | ||
64 | static void chat_onAction(ToxWindow *self, int num, uint8_t *action, uint16_t len) | 64 | static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len) |
65 | { | 65 | { |
66 | ChatContext *ctx = (ChatContext*) self->x; | 66 | ChatContext *ctx = (ChatContext*) self->x; |
67 | time_t now; | 67 | time_t now; |
@@ -117,7 +117,7 @@ int string_is_empty(char *string) | |||
117 | return rc; | 117 | return rc; |
118 | } | 118 | } |
119 | 119 | ||
120 | static void chat_onKey(ToxWindow *self, int key) | 120 | static void chat_onKey(ToxWindow *self, Messenger *m, int key) |
121 | { | 121 | { |
122 | ChatContext *ctx = (ChatContext*) self->x; | 122 | ChatContext *ctx = (ChatContext*) self->x; |
123 | time_t now; | 123 | time_t now; |
@@ -155,7 +155,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
155 | wmove(self->window, y2-CURS_Y_OFFSET, 0); | 155 | wmove(self->window, y2-CURS_Y_OFFSET, 0); |
156 | wclrtobot(self->window); | 156 | wclrtobot(self->window); |
157 | if (ctx->line[0] == '/') | 157 | if (ctx->line[0] == '/') |
158 | execute(self, ctx, ctx->line, timeinfo); | 158 | execute(self, ctx, m, ctx->line, timeinfo); |
159 | else { | 159 | else { |
160 | if (!string_is_empty(ctx->line)) { | 160 | if (!string_is_empty(ctx->line)) { |
161 | /* make sure the string has at least non-space character */ | 161 | /* make sure the string has at least non-space character */ |
@@ -167,7 +167,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
167 | wattroff(ctx->history, COLOR_PAIR(1)); | 167 | wattroff(ctx->history, COLOR_PAIR(1)); |
168 | wprintw(ctx->history, "%s\n", ctx->line); | 168 | wprintw(ctx->history, "%s\n", ctx->line); |
169 | } | 169 | } |
170 | if (m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { | 170 | if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { |
171 | wattron(ctx->history, COLOR_PAIR(3)); | 171 | wattron(ctx->history, COLOR_PAIR(3)); |
172 | wprintw(ctx->history, " * Failed to send message.\n"); | 172 | wprintw(ctx->history, " * Failed to send message.\n"); |
173 | wattroff(ctx->history, COLOR_PAIR(3)); | 173 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -178,7 +178,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | 181 | void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo) |
182 | { | 182 | { |
183 | if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { | 183 | if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { |
184 | wclear(self->window); | 184 | wclear(self->window); |
@@ -210,14 +210,14 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
210 | wattroff(ctx->history, COLOR_PAIR(2)); | 210 | wattroff(ctx->history, COLOR_PAIR(2)); |
211 | 211 | ||
212 | uint8_t selfname[MAX_NAME_LENGTH]; | 212 | uint8_t selfname[MAX_NAME_LENGTH]; |
213 | int len = getself_name(selfname); | 213 | int len = getself_name(m, selfname); |
214 | char msg[MAX_STR_SIZE-len-4]; | 214 | char msg[MAX_STR_SIZE-len-4]; |
215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); | 215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); |
216 | 216 | ||
217 | wattron(ctx->history, COLOR_PAIR(1)); | 217 | wattron(ctx->history, COLOR_PAIR(1)); |
218 | wprintw(ctx->history, msg); | 218 | wprintw(ctx->history, msg); |
219 | wattroff(ctx->history, COLOR_PAIR(1)); | 219 | wattroff(ctx->history, COLOR_PAIR(1)); |
220 | if (m_sendaction(ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { | 220 | if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { |
221 | wattron(ctx->history, COLOR_PAIR(3)); | 221 | wattron(ctx->history, COLOR_PAIR(3)); |
222 | wprintw(ctx->history, " * Failed to send action\n"); | 222 | wprintw(ctx->history, " * Failed to send action\n"); |
223 | wattroff(ctx->history, COLOR_PAIR(3)); | 223 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -256,13 +256,13 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
256 | 256 | ||
257 | msg = strchr(status, ' '); | 257 | msg = strchr(status, ' '); |
258 | if (msg == NULL) { | 258 | if (msg == NULL) { |
259 | m_set_userstatus(status_kind); | 259 | m_set_userstatus(m, status_kind); |
260 | wprintw(ctx->history, "Status set to: %s\n", status_text); | 260 | wprintw(ctx->history, "Status set to: %s\n", status_text); |
261 | } | 261 | } |
262 | else { | 262 | else { |
263 | msg++; | 263 | msg++; |
264 | m_set_userstatus(status_kind); | 264 | m_set_userstatus(m, status_kind); |
265 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); | 265 | m_set_statusmessage(m, ( uint8_t*) msg, strlen(msg)+1); |
266 | wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); | 266 | wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); |
267 | } | 267 | } |
268 | } | 268 | } |
@@ -275,7 +275,7 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
275 | return; | 275 | return; |
276 | } | 276 | } |
277 | nick++; | 277 | nick++; |
278 | setname((uint8_t*) nick, strlen(nick)+1); | 278 | setname(m, (uint8_t*) nick, strlen(nick)+1); |
279 | wprintw(ctx->history, "Nickname set to: %s\n", nick); | 279 | wprintw(ctx->history, "Nickname set to: %s\n", nick); |
280 | } | 280 | } |
281 | 281 | ||
@@ -312,7 +312,7 @@ static void chat_onDraw(ToxWindow *self) | |||
312 | wrefresh(self->window); | 312 | wrefresh(self->window); |
313 | } | 313 | } |
314 | 314 | ||
315 | static void chat_onInit(ToxWindow *self) | 315 | static void chat_onInit(ToxWindow *self, Messenger *m) |
316 | { | 316 | { |
317 | int x, y; | 317 | int x, y; |
318 | ChatContext *ctx = (ChatContext*) self->x; | 318 | ChatContext *ctx = (ChatContext*) self->x; |
@@ -329,7 +329,7 @@ void print_help(ChatContext *self) | |||
329 | wattron(self->history, COLOR_PAIR(2) | A_BOLD); | 329 | wattron(self->history, COLOR_PAIR(2) | A_BOLD); |
330 | wprintw(self->history, "Commands:\n"); | 330 | wprintw(self->history, "Commands:\n"); |
331 | wattroff(self->history, A_BOLD); | 331 | wattroff(self->history, A_BOLD); |
332 | 332 | ||
333 | wprintw(self->history, " /status <type> <message> : Set your status\n"); | 333 | wprintw(self->history, " /status <type> <message> : Set your status\n"); |
334 | wprintw(self->history, " /nick <nickname> : Set your nickname\n"); | 334 | wprintw(self->history, " /nick <nickname> : Set your nickname\n"); |
335 | wprintw(self->history, " /me <action> : Do an action\n"); | 335 | wprintw(self->history, " /me <action> : Do an action\n"); |
@@ -342,7 +342,7 @@ void print_help(ChatContext *self) | |||
342 | wattroff(self->history, COLOR_PAIR(2)); | 342 | wattroff(self->history, COLOR_PAIR(2)); |
343 | } | 343 | } |
344 | 344 | ||
345 | ToxWindow new_chat(int friendnum) | 345 | ToxWindow new_chat(Messenger *m, int friendnum) |
346 | { | 346 | { |
347 | ToxWindow ret; | 347 | ToxWindow ret; |
348 | memset(&ret, 0, sizeof(ret)); | 348 | memset(&ret, 0, sizeof(ret)); |
@@ -356,7 +356,7 @@ ToxWindow new_chat(int friendnum) | |||
356 | ret.onAction = &chat_onAction; | 356 | ret.onAction = &chat_onAction; |
357 | 357 | ||
358 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 358 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
359 | getname(friendnum, (uint8_t*) &nick); | 359 | getname(m, friendnum, (uint8_t*) &nick); |
360 | fix_name(nick); | 360 | fix_name(nick); |
361 | 361 | ||
362 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); | 362 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); |
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index f2aa1cf4..56061cf9 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c | |||
@@ -14,7 +14,7 @@ | |||
14 | 14 | ||
15 | extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; | 15 | extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM]; |
16 | extern int add_window(ToxWindow w, int n); | 16 | extern int add_window(ToxWindow w, int n); |
17 | extern ToxWindow new_chat(int friendnum); | 17 | extern ToxWindow new_chat(Messenger *m, int friendnum); |
18 | 18 | ||
19 | extern int active_window; | 19 | extern int active_window; |
20 | 20 | ||
@@ -42,7 +42,7 @@ void fix_name(uint8_t *name) | |||
42 | *q = 0; | 42 | *q = 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | void friendlist_onMessage(ToxWindow *self, int num, uint8_t *str, uint16_t len) | 45 | void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, uint16_t len) |
46 | { | 46 | { |
47 | if (num >= num_friends) | 47 | if (num >= num_friends) |
48 | return; | 48 | return; |
@@ -54,7 +54,7 @@ void friendlist_onMessage(ToxWindow *self, int num, uint8_t *str, uint16_t len) | |||
54 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | 54 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { |
55 | if (WINDOW_STATUS[i] == -1) { | 55 | if (WINDOW_STATUS[i] == -1) { |
56 | WINDOW_STATUS[i] = num; | 56 | WINDOW_STATUS[i] = num; |
57 | add_window(new_chat(num), i); | 57 | add_window(new_chat(m, num), i); |
58 | active_window = i; | 58 | active_window = i; |
59 | break; | 59 | break; |
60 | } | 60 | } |
@@ -82,20 +82,20 @@ void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t | |||
82 | fix_name(friends[num].status); | 82 | fix_name(friends[num].status); |
83 | } | 83 | } |
84 | 84 | ||
85 | int friendlist_onFriendAdded(int num) | 85 | int friendlist_onFriendAdded(Messenger *m, int num) |
86 | { | 86 | { |
87 | if (num_friends == MAX_FRIENDS_NUM) | 87 | if (num_friends == MAX_FRIENDS_NUM) |
88 | return -1; | 88 | return -1; |
89 | 89 | ||
90 | friends[num_friends].num = num; | 90 | friends[num_friends].num = num; |
91 | getname(num, friends[num_friends].name); | 91 | getname(m, num, friends[num_friends].name); |
92 | strcpy((char*) friends[num_friends].name, "unknown"); | 92 | strcpy((char*) friends[num_friends].name, "unknown"); |
93 | strcpy((char*) friends[num_friends].status, "unknown"); | 93 | strcpy((char*) friends[num_friends].status, "unknown"); |
94 | friends[num_friends++].chatwin = -1; | 94 | friends[num_friends++].chatwin = -1; |
95 | return 0; | 95 | return 0; |
96 | } | 96 | } |
97 | 97 | ||
98 | static void friendlist_onKey(ToxWindow *self, int key) | 98 | static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) |
99 | { | 99 | { |
100 | if (key == KEY_UP) { | 100 | if (key == KEY_UP) { |
101 | if (--num_selected < 0) | 101 | if (--num_selected < 0) |
@@ -121,7 +121,7 @@ static void friendlist_onKey(ToxWindow *self, int key) | |||
121 | if (WINDOW_STATUS[i] == -1) { | 121 | if (WINDOW_STATUS[i] == -1) { |
122 | WINDOW_STATUS[i] = num_selected; | 122 | WINDOW_STATUS[i] = num_selected; |
123 | friends[num_selected].chatwin = num_selected; | 123 | friends[num_selected].chatwin = num_selected; |
124 | add_window(new_chat(num_selected), i); | 124 | add_window(new_chat(m, num_selected), i); |
125 | active_window = i; | 125 | active_window = i; |
126 | break; | 126 | break; |
127 | } | 127 | } |
@@ -164,7 +164,7 @@ void disable_chatwin(int f_num) | |||
164 | friends[f_num].chatwin = -1; | 164 | friends[f_num].chatwin = -1; |
165 | } | 165 | } |
166 | 166 | ||
167 | static void friendlist_onInit(ToxWindow *self) | 167 | static void friendlist_onInit(ToxWindow *self, Messenger *m) |
168 | { | 168 | { |
169 | 169 | ||
170 | } | 170 | } |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 752453f2..c14dee1f 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -25,7 +25,7 @@ | |||
25 | extern ToxWindow new_prompt(); | 25 | extern ToxWindow new_prompt(); |
26 | extern ToxWindow new_friendlist(); | 26 | extern ToxWindow new_friendlist(); |
27 | 27 | ||
28 | extern int friendlist_onFriendAdded(int num); | 28 | extern int friendlist_onFriendAdded(Messenger *m, int num); |
29 | extern void disable_chatwin(int f_num); | 29 | extern void disable_chatwin(int f_num); |
30 | extern int add_req(uint8_t *public_key); // XXX | 30 | extern int add_req(uint8_t *public_key); // XXX |
31 | extern unsigned char *hex_string_to_bin(char hex_string[]); | 31 | extern unsigned char *hex_string_to_bin(char hex_string[]); |
@@ -40,6 +40,8 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS]; | |||
40 | static ToxWindow windows[MAX_WINDOW_SLOTS]; | 40 | static ToxWindow windows[MAX_WINDOW_SLOTS]; |
41 | static ToxWindow* prompt; | 41 | static ToxWindow* prompt; |
42 | 42 | ||
43 | static Messenger *m; | ||
44 | |||
43 | int w_num; | 45 | int w_num; |
44 | int active_window; | 46 | int active_window; |
45 | 47 | ||
@@ -63,25 +65,25 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
63 | } | 65 | } |
64 | } | 66 | } |
65 | 67 | ||
66 | void on_message(int friendnumber, uint8_t *string, uint16_t length) | 68 | void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) |
67 | { | 69 | { |
68 | int i; | 70 | int i; |
69 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 71 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { |
70 | if (windows[i].onMessage != NULL) | 72 | if (windows[i].onMessage != NULL) |
71 | windows[i].onMessage(&windows[i], friendnumber, string, length); | 73 | windows[i].onMessage(&windows[i], m, friendnumber, string, length); |
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | void on_action(int friendnumber, uint8_t *string, uint16_t length) | 77 | void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) |
76 | { | 78 | { |
77 | int i; | 79 | int i; |
78 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 80 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { |
79 | if (windows[i].onAction != NULL) | 81 | if (windows[i].onAction != NULL) |
80 | windows[i].onAction(&windows[i], friendnumber, string, length); | 82 | windows[i].onAction(&windows[i], m, friendnumber, string, length); |
81 | } | 83 | } |
82 | } | 84 | } |
83 | 85 | ||
84 | void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) | 86 | void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) |
85 | { | 87 | { |
86 | wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); | 88 | wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); |
87 | int i; | 89 | int i; |
@@ -91,7 +93,7 @@ void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
91 | } | 93 | } |
92 | } | 94 | } |
93 | 95 | ||
94 | void on_statuschange(int friendnumber, uint8_t *string, uint16_t length) | 96 | void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length) |
95 | { | 97 | { |
96 | wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); | 98 | wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); |
97 | int i; | 99 | int i; |
@@ -103,7 +105,7 @@ void on_statuschange(int friendnumber, uint8_t *string, uint16_t length) | |||
103 | 105 | ||
104 | void on_friendadded(int friendnumber) | 106 | void on_friendadded(int friendnumber) |
105 | { | 107 | { |
106 | friendlist_onFriendAdded(friendnumber); | 108 | friendlist_onFriendAdded(m, friendnumber); |
107 | } | 109 | } |
108 | /* CALLBACKS END */ | 110 | /* CALLBACKS END */ |
109 | 111 | ||
@@ -129,14 +131,14 @@ static void init_term() | |||
129 | static void init_tox() | 131 | static void init_tox() |
130 | { | 132 | { |
131 | /* Init core */ | 133 | /* Init core */ |
132 | initMessenger(); | 134 | m = initMessenger(); |
133 | 135 | ||
134 | /* Callbacks */ | 136 | /* Callbacks */ |
135 | m_callback_friendrequest(on_request); | 137 | m_callback_friendrequest(m, on_request); |
136 | m_callback_friendmessage(on_message); | 138 | m_callback_friendmessage(m, on_message); |
137 | m_callback_namechange(on_nickchange); | 139 | m_callback_namechange(m, on_nickchange); |
138 | m_callback_statusmessage(on_statuschange); | 140 | m_callback_statusmessage(m, on_statuschange); |
139 | m_callback_action(on_action); | 141 | m_callback_action(m, on_action); |
140 | } | 142 | } |
141 | 143 | ||
142 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ | 144 | #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ |
@@ -211,7 +213,7 @@ int add_window(ToxWindow w, int n) | |||
211 | return -1; | 213 | return -1; |
212 | 214 | ||
213 | windows[n] = w; | 215 | windows[n] = w; |
214 | w.onInit(&w); | 216 | w.onInit(&w, m); |
215 | w_num++; | 217 | w_num++; |
216 | return n; | 218 | return n; |
217 | } | 219 | } |
@@ -237,7 +239,7 @@ static void init_windows() | |||
237 | w_num = 0; | 239 | w_num = 0; |
238 | int n_prompt = 0; | 240 | int n_prompt = 0; |
239 | int n_friendslist = 1; | 241 | int n_friendslist = 1; |
240 | if (add_window(new_prompt(), n_prompt) == -1 | 242 | if (add_window(new_prompt(), n_prompt) == -1 |
241 | || add_window(new_friendlist(), n_friendslist) == -1) { | 243 | || add_window(new_friendlist(), n_friendslist) == -1) { |
242 | fprintf(stderr, "add_window() failed.\n"); | 244 | fprintf(stderr, "add_window() failed.\n"); |
243 | endwin(); | 245 | endwin(); |
@@ -257,7 +259,7 @@ static void do_tox() | |||
257 | dht_on = false; | 259 | dht_on = false; |
258 | wprintw(prompt->window, "\nDHT disconnected.\n"); | 260 | wprintw(prompt->window, "\nDHT disconnected.\n"); |
259 | } | 261 | } |
260 | doMessenger(); | 262 | doMessenger(m); |
261 | } | 263 | } |
262 | 264 | ||
263 | static void load_data(char *path) | 265 | static void load_data(char *path) |
@@ -285,17 +287,17 @@ static void load_data(char *path) | |||
285 | endwin(); | 287 | endwin(); |
286 | exit(1); | 288 | exit(1); |
287 | } | 289 | } |
288 | Messenger_load(buf, len); | 290 | Messenger_load(m, buf, len); |
289 | } | 291 | } |
290 | else { | 292 | else { |
291 | len = Messenger_size(); | 293 | len = Messenger_size(m); |
292 | buf = malloc(len); | 294 | buf = malloc(len); |
293 | if (buf == NULL) { | 295 | if (buf == NULL) { |
294 | fprintf(stderr, "malloc() failed.\n"); | 296 | fprintf(stderr, "malloc() failed.\n"); |
295 | endwin(); | 297 | endwin(); |
296 | exit(1); | 298 | exit(1); |
297 | } | 299 | } |
298 | Messenger_save(buf); | 300 | Messenger_save(m, buf); |
299 | 301 | ||
300 | fd = fopen(path, "w"); | 302 | fd = fopen(path, "w"); |
301 | if (fd == NULL) { | 303 | if (fd == NULL) { |
@@ -329,7 +331,7 @@ static void draw_bar() | |||
329 | move(LINES - 1, 0); | 331 | move(LINES - 1, 0); |
330 | 332 | ||
331 | attron(COLOR_PAIR(4) | A_BOLD); | 333 | attron(COLOR_PAIR(4) | A_BOLD); |
332 | printw(" TOXIC " TOXICVER "|"); | 334 | printw(" TOXIC " TOXICVER "|"); |
333 | attroff(COLOR_PAIR(4) | A_BOLD); | 335 | attroff(COLOR_PAIR(4) | A_BOLD); |
334 | 336 | ||
335 | int i; | 337 | int i; |
@@ -473,7 +475,8 @@ int main(int argc, char *argv[]) | |||
473 | if (ch == '\t' || ch == KEY_BTAB) | 475 | if (ch == '\t' || ch == KEY_BTAB) |
474 | set_active_window(ch); | 476 | set_active_window(ch); |
475 | else if (ch != ERR) | 477 | else if (ch != ERR) |
476 | a->onKey(a, ch); | 478 | a->onKey(a, m, ch); |
477 | } | 479 | } |
480 | cleanupMessenger(m); | ||
478 | return 0; | 481 | return 0; |
479 | } | 482 | } |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index ab44e960..67f80fef 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -20,24 +20,24 @@ static char prompt_buf[MAX_STR_SIZE] = {0}; | |||
20 | static int prompt_buf_pos = 0; | 20 | static int prompt_buf_pos = 0; |
21 | 21 | ||
22 | /* commands */ | 22 | /* commands */ |
23 | void cmd_accept(ToxWindow *, char **); | 23 | void cmd_accept(ToxWindow *, Messenger *m, char **); |
24 | void cmd_add(ToxWindow *, char **); | 24 | void cmd_add(ToxWindow *, Messenger *m, char **); |
25 | void cmd_clear(ToxWindow *, char **); | 25 | void cmd_clear(ToxWindow *, Messenger *m, char **); |
26 | void cmd_connect(ToxWindow *, char **); | 26 | void cmd_connect(ToxWindow *, Messenger *m, char **); |
27 | void cmd_help(ToxWindow *, char **); | 27 | void cmd_help(ToxWindow *, Messenger *m, char **); |
28 | void cmd_msg(ToxWindow *, char **); | 28 | void cmd_msg(ToxWindow *, Messenger *m, char **); |
29 | void cmd_myid(ToxWindow *, char **); | 29 | void cmd_myid(ToxWindow *, Messenger *m, char **); |
30 | void cmd_nick(ToxWindow *, char **); | 30 | void cmd_nick(ToxWindow *, Messenger *m, char **); |
31 | void cmd_quit(ToxWindow *, char **); | 31 | void cmd_quit(ToxWindow *, Messenger *m, char **); |
32 | void cmd_status(ToxWindow *, char **); | 32 | void cmd_status(ToxWindow *, Messenger *m, char **); |
33 | void cmd_statusmsg(ToxWindow *, char **); | 33 | void cmd_statusmsg(ToxWindow *, Messenger *m, char **); |
34 | 34 | ||
35 | #define NUM_COMMANDS 13 | 35 | #define NUM_COMMANDS 13 |
36 | 36 | ||
37 | static struct { | 37 | static struct { |
38 | char *name; | 38 | char *name; |
39 | int numargs; | 39 | int numargs; |
40 | void (*func)(ToxWindow *, char **); | 40 | void (*func)(ToxWindow *, Messenger *m, char **); |
41 | } commands[] = { | 41 | } commands[] = { |
42 | { "accept", 1, cmd_accept }, | 42 | { "accept", 1, cmd_accept }, |
43 | { "add", 1, cmd_add }, | 43 | { "add", 1, cmd_add }, |
@@ -74,7 +74,7 @@ unsigned char *hex_string_to_bin(char hex_string[]) | |||
74 | return val; | 74 | return val; |
75 | } | 75 | } |
76 | 76 | ||
77 | void cmd_accept(ToxWindow *self, char **args) | 77 | void cmd_accept(ToxWindow *self, Messenger *m, char **args) |
78 | { | 78 | { |
79 | int num = atoi(args[1]); | 79 | int num = atoi(args[1]); |
80 | if (num >= num_requests) { | 80 | if (num >= num_requests) { |
@@ -82,7 +82,7 @@ void cmd_accept(ToxWindow *self, char **args) | |||
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | 84 | ||
85 | num = m_addfriend_norequest(pending_requests[num]); | 85 | num = m_addfriend_norequest(m, pending_requests[num]); |
86 | if (num == -1) | 86 | if (num == -1) |
87 | wprintw(self->window, "Failed to add friend.\n"); | 87 | wprintw(self->window, "Failed to add friend.\n"); |
88 | else { | 88 | else { |
@@ -91,7 +91,7 @@ void cmd_accept(ToxWindow *self, char **args) | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | void cmd_add(ToxWindow *self, char **args) | 94 | void cmd_add(ToxWindow *self, Messenger *m, char **args) |
95 | { | 95 | { |
96 | uint8_t id_bin[KEY_SIZE_BYTES]; | 96 | uint8_t id_bin[KEY_SIZE_BYTES]; |
97 | char xx[3]; | 97 | char xx[3]; |
@@ -121,7 +121,7 @@ void cmd_add(ToxWindow *self, char **args) | |||
121 | } | 121 | } |
122 | id_bin[i] = x; | 122 | id_bin[i] = x; |
123 | } | 123 | } |
124 | int num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1); | 124 | int num = m_addfriend(m, id_bin, (uint8_t*) msg, strlen(msg)+1); |
125 | switch (num) { | 125 | switch (num) { |
126 | case FAERR_TOOLONG: | 126 | case FAERR_TOOLONG: |
127 | wprintw(self->window, "Message is too long.\n"); | 127 | wprintw(self->window, "Message is too long.\n"); |
@@ -145,12 +145,12 @@ void cmd_add(ToxWindow *self, char **args) | |||
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | void cmd_clear(ToxWindow *self, char **args) | 148 | void cmd_clear(ToxWindow *self, Messenger *m, char **args) |
149 | { | 149 | { |
150 | wclear(self->window); | 150 | wclear(self->window); |
151 | } | 151 | } |
152 | 152 | ||
153 | void cmd_connect(ToxWindow *self, char **args) | 153 | void cmd_connect(ToxWindow *self, Messenger *m, char **args) |
154 | { | 154 | { |
155 | IP_Port dht; | 155 | IP_Port dht; |
156 | char *ip = args[1]; | 156 | char *ip = args[1]; |
@@ -174,13 +174,13 @@ void cmd_connect(ToxWindow *self, char **args) | |||
174 | free(binary_string); | 174 | free(binary_string); |
175 | } | 175 | } |
176 | 176 | ||
177 | void cmd_quit(ToxWindow *self, char **args) | 177 | void cmd_quit(ToxWindow *self, Messenger *m, char **args) |
178 | { | 178 | { |
179 | endwin(); | 179 | endwin(); |
180 | exit(0); | 180 | exit(0); |
181 | } | 181 | } |
182 | 182 | ||
183 | void cmd_help(ToxWindow *self, char **args) | 183 | void cmd_help(ToxWindow *self, Messenger *m, char **args) |
184 | { | 184 | { |
185 | wclear(self->window); | 185 | wclear(self->window); |
186 | wattron(self->window, COLOR_PAIR(2) | A_BOLD); | 186 | wattron(self->window, COLOR_PAIR(2) | A_BOLD); |
@@ -197,7 +197,7 @@ void cmd_help(ToxWindow *self, char **args) | |||
197 | wprintw(self->window, " quit/exit : Exit program\n"); | 197 | wprintw(self->window, " quit/exit : Exit program\n"); |
198 | wprintw(self->window, " help : Print this message again\n"); | 198 | wprintw(self->window, " help : Print this message again\n"); |
199 | wprintw(self->window, " clear : Clear this window\n"); | 199 | wprintw(self->window, " clear : Clear this window\n"); |
200 | 200 | ||
201 | wattron(self->window, A_BOLD); | 201 | wattron(self->window, A_BOLD); |
202 | wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); | 202 | wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); |
203 | wattroff(self->window, A_BOLD); | 203 | wattroff(self->window, A_BOLD); |
@@ -205,17 +205,17 @@ void cmd_help(ToxWindow *self, char **args) | |||
205 | wattroff(self->window, COLOR_PAIR(2)); | 205 | wattroff(self->window, COLOR_PAIR(2)); |
206 | } | 206 | } |
207 | 207 | ||
208 | void cmd_msg(ToxWindow *self, char **args) | 208 | void cmd_msg(ToxWindow *self, Messenger *m, char **args) |
209 | { | 209 | { |
210 | char *id = args[1]; | 210 | char *id = args[1]; |
211 | char *msg = args[2]; | 211 | char *msg = args[2]; |
212 | if (m_sendmessage(atoi(id), (uint8_t*) msg, strlen(msg)+1) == 0) | 212 | if (m_sendmessage(m, atoi(id), (uint8_t*) msg, strlen(msg)+1) == 0) |
213 | wprintw(self->window, "Error occurred while sending message.\n"); | 213 | wprintw(self->window, "Error occurred while sending message.\n"); |
214 | else | 214 | else |
215 | wprintw(self->window, "Message successfully sent.\n"); | 215 | wprintw(self->window, "Message successfully sent.\n"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cmd_myid(ToxWindow *self, char **args) | 218 | void cmd_myid(ToxWindow *self, Messenger *m, char **args) |
219 | { | 219 | { |
220 | char id[KEY_SIZE_BYTES*2 + 1] = {0}; | 220 | char id[KEY_SIZE_BYTES*2 + 1] = {0}; |
221 | size_t i; | 221 | size_t i; |
@@ -227,14 +227,14 @@ void cmd_myid(ToxWindow *self, char **args) | |||
227 | wprintw(self->window, "Your ID: %s\n", id); | 227 | wprintw(self->window, "Your ID: %s\n", id); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cmd_nick(ToxWindow *self, char **args) | 230 | void cmd_nick(ToxWindow *self, Messenger *m, char **args) |
231 | { | 231 | { |
232 | char *nick = args[1]; | 232 | char *nick = args[1]; |
233 | setname((uint8_t*) nick, strlen(nick)+1); | 233 | setname(m, (uint8_t*) nick, strlen(nick)+1); |
234 | wprintw(self->window, "Nickname set to: %s\n", nick); | 234 | wprintw(self->window, "Nickname set to: %s\n", nick); |
235 | } | 235 | } |
236 | 236 | ||
237 | void cmd_status(ToxWindow *self, char **args) | 237 | void cmd_status(ToxWindow *self, Messenger *m, char **args) |
238 | { | 238 | { |
239 | char *status = args[1]; | 239 | char *status = args[1]; |
240 | char *status_text; | 240 | char *status_text; |
@@ -260,24 +260,24 @@ void cmd_status(ToxWindow *self, char **args) | |||
260 | 260 | ||
261 | char *msg = args[2]; | 261 | char *msg = args[2]; |
262 | if (msg == NULL) { | 262 | if (msg == NULL) { |
263 | m_set_userstatus(status_kind); | 263 | m_set_userstatus(m, status_kind); |
264 | wprintw(self->window, "Status set to: %s\n", status_text); | 264 | wprintw(self->window, "Status set to: %s\n", status_text); |
265 | } | 265 | } |
266 | else { | 266 | else { |
267 | m_set_userstatus(status_kind); | 267 | m_set_userstatus(m, status_kind); |
268 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); | 268 | m_set_statusmessage(m, (uint8_t*) msg, strlen(msg)+1); |
269 | wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); | 269 | wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | void cmd_statusmsg(ToxWindow *self, char **args) | 273 | void cmd_statusmsg(ToxWindow *self, Messenger *m, char **args) |
274 | { | 274 | { |
275 | char *msg = args[1]; | 275 | char *msg = args[1]; |
276 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); | 276 | m_set_statusmessage(m, (uint8_t*) msg, strlen(msg)+1); |
277 | wprintw(self->window, "Status set to: %s\n", msg); | 277 | wprintw(self->window, "Status set to: %s\n", msg); |
278 | } | 278 | } |
279 | 279 | ||
280 | static void execute(ToxWindow *self, char *u_cmd) | 280 | static void execute(ToxWindow *self, Messenger *m, char *u_cmd) |
281 | { | 281 | { |
282 | int newlines = 0; | 282 | int newlines = 0; |
283 | char cmd[MAX_STR_SIZE] = {0}; | 283 | char cmd[MAX_STR_SIZE] = {0}; |
@@ -341,13 +341,13 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | } | 343 | } |
344 | /* check for excess arguments */ | 344 | /* check for excess arguments */ |
345 | if (strcmp(cmdargs[0], "add") && strlen(cmdargs[j]) != 0) { | 345 | if (strcmp(cmdargs[0], "add") && strlen(cmdargs[j]) != 0) { |
346 | wprintw(self->window, "Invalid command: too many arguments to %s.\n", commands[i].name); | 346 | wprintw(self->window, "Invalid command: too many arguments to %s.\n", commands[i].name); |
347 | return; | 347 | return; |
348 | } | 348 | } |
349 | /* pass arguments to command function */ | 349 | /* pass arguments to command function */ |
350 | (commands[i].func)(self, cmdargs); | 350 | (commands[i].func)(self, m, cmdargs); |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | } | 353 | } |
@@ -356,7 +356,7 @@ static void execute(ToxWindow *self, char *u_cmd) | |||
356 | wprintw(self->window, "Invalid command.\n"); | 356 | wprintw(self->window, "Invalid command.\n"); |
357 | } | 357 | } |
358 | 358 | ||
359 | static void prompt_onKey(ToxWindow *self, int key) | 359 | static void prompt_onKey(ToxWindow *self, Messenger *m, int key) |
360 | { | 360 | { |
361 | /* Add printable characters to line */ | 361 | /* Add printable characters to line */ |
362 | if (isprint(key)) { | 362 | if (isprint(key)) { |
@@ -380,7 +380,7 @@ static void prompt_onKey(ToxWindow *self, int key) | |||
380 | /* RETURN key: execute command */ | 380 | /* RETURN key: execute command */ |
381 | else if (key == '\n') { | 381 | else if (key == '\n') { |
382 | wprintw(self->window, "\n"); | 382 | wprintw(self->window, "\n"); |
383 | execute(self, prompt_buf); | 383 | execute(self, m, prompt_buf); |
384 | prompt_buf_pos = 0; | 384 | prompt_buf_pos = 0; |
385 | prompt_buf[0] = 0; | 385 | prompt_buf[0] = 0; |
386 | } | 386 | } |
@@ -413,10 +413,10 @@ static void prompt_onDraw(ToxWindow *self) | |||
413 | wrefresh(self->window); | 413 | wrefresh(self->window); |
414 | } | 414 | } |
415 | 415 | ||
416 | static void prompt_onInit(ToxWindow *self) | 416 | static void prompt_onInit(ToxWindow *self, Messenger *m) |
417 | { | 417 | { |
418 | scrollok(self->window, 1); | 418 | scrollok(self->window, 1); |
419 | cmd_help(self, NULL); | 419 | cmd_help(self, m, NULL); |
420 | wclrtoeol(self->window); | 420 | wclrtoeol(self->window); |
421 | } | 421 | } |
422 | 422 | ||
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index c6925ce1..648243d0 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h | |||
@@ -9,7 +9,7 @@ | |||
9 | #define KEY_SIZE_BYTES 32 | 9 | #define KEY_SIZE_BYTES 32 |
10 | 10 | ||
11 | /* number of permanent default windows */ | 11 | /* number of permanent default windows */ |
12 | #define N_DEFAULT_WINS 2 | 12 | #define N_DEFAULT_WINS 2 |
13 | 13 | ||
14 | /* maximum window slots for WINDOW_STATUS array */ | 14 | /* maximum window slots for WINDOW_STATUS array */ |
15 | #define MAX_WINDOW_SLOTS N_DEFAULT_WINS+MAX_FRIENDS_NUM | 15 | #define MAX_WINDOW_SLOTS N_DEFAULT_WINS+MAX_FRIENDS_NUM |
@@ -17,14 +17,14 @@ | |||
17 | typedef struct ToxWindow_ ToxWindow; | 17 | typedef struct ToxWindow_ ToxWindow; |
18 | 18 | ||
19 | struct ToxWindow_ { | 19 | struct ToxWindow_ { |
20 | void(*onKey)(ToxWindow*, int); | 20 | void(*onKey)(ToxWindow*, Messenger*, int); |
21 | void(*onDraw)(ToxWindow*); | 21 | void(*onDraw)(ToxWindow*); |
22 | void(*onInit)(ToxWindow*); | 22 | void(*onInit)(ToxWindow*, Messenger*); |
23 | void(*onFriendRequest)(ToxWindow*, uint8_t*, uint8_t*, uint16_t); | 23 | void(*onFriendRequest)(ToxWindow*, uint8_t*, uint8_t*, uint16_t); |
24 | void(*onMessage)(ToxWindow*, int, uint8_t*, uint16_t); | 24 | void(*onMessage)(ToxWindow*, Messenger*, int, uint8_t*, uint16_t); |
25 | void(*onNickChange)(ToxWindow*, int, uint8_t*, uint16_t); | 25 | void(*onNickChange)(ToxWindow*, int, uint8_t*, uint16_t); |
26 | void(*onStatusChange)(ToxWindow*, int, uint8_t*, uint16_t); | 26 | void(*onStatusChange)(ToxWindow*, int, uint8_t*, uint16_t); |
27 | void(*onAction)(ToxWindow*, int, uint8_t*, uint16_t); | 27 | void(*onAction)(ToxWindow*, Messenger*, int, uint8_t*, uint16_t); |
28 | char title[256]; | 28 | char title[256]; |
29 | 29 | ||
30 | void* x; | 30 | void* x; |