summaryrefslogtreecommitdiff
path: root/testing/toxic/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/main.c')
-rw-r--r--testing/toxic/main.c47
1 files changed, 25 insertions, 22 deletions
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 @@
25extern ToxWindow new_prompt(); 25extern ToxWindow new_prompt();
26extern ToxWindow new_friendlist(); 26extern ToxWindow new_friendlist();
27 27
28extern int friendlist_onFriendAdded(int num); 28extern int friendlist_onFriendAdded(Messenger *m, int num);
29extern void disable_chatwin(int f_num); 29extern void disable_chatwin(int f_num);
30extern int add_req(uint8_t *public_key); // XXX 30extern int add_req(uint8_t *public_key); // XXX
31extern unsigned char *hex_string_to_bin(char hex_string[]); 31extern unsigned char *hex_string_to_bin(char hex_string[]);
@@ -40,6 +40,8 @@ char WINDOW_STATUS[MAX_WINDOW_SLOTS];
40static ToxWindow windows[MAX_WINDOW_SLOTS]; 40static ToxWindow windows[MAX_WINDOW_SLOTS];
41static ToxWindow* prompt; 41static ToxWindow* prompt;
42 42
43static Messenger *m;
44
43int w_num; 45int w_num;
44int active_window; 46int 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
66void on_message(int friendnumber, uint8_t *string, uint16_t length) 68void 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
75void on_action(int friendnumber, uint8_t *string, uint16_t length) 77void 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
84void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) 86void 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
94void on_statuschange(int friendnumber, uint8_t *string, uint16_t length) 96void 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
104void on_friendadded(int friendnumber) 106void 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()
129static void init_tox() 131static 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
263static void load_data(char *path) 265static 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}