/[pkg-mixmaster]/trunk/Mix/Src/menu.c
ViewVC logotype

Contents of /trunk/Mix/Src/menu.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 262 - (show annotations) (download)
Wed Sep 18 23:26:17 2002 UTC (10 years, 8 months ago) by rabbi
File MIME type: text/plain
File size: 21473 byte(s)
Added closing comments for all #ifdef statements. All #endif's, as well as
nested braces, should be commented to reference their start.

We need to provide comments before every function as well.
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
2
3 Mixmaster may be redistributed and modified under certain conditions.
4 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5 ANY KIND, either express or implied. See the file COPYRIGHT for
6 details.
7
8 Menu-based user interface
9 $Id: menu.c,v 1.7 2002/09/18 23:26:16 rabbi Exp $ */
10
11
12 #include "menu.h"
13 #include "mix3.h"
14 #include <string.h>
15 #include <ctype.h>
16 #include <stdlib.h>
17 #include <fcntl.h>
18 #ifdef POSIX
19 #include <unistd.h>
20 #else /* end of POSIX */
21 #include <io.h>
22 #endif /* else if not POSIX */
23 #include <assert.h>
24
25 void menu_folder(char command, char *foldername)
26 {
27 mix_init(NULL);
28 if (foldername)
29 menu_init();
30 read_folder(command, foldername, ANON);
31 menu_exit();
32 }
33
34 void read_folder(char command, char *foldername, char *nym)
35 {
36 #ifdef USE_NCURSES
37 char path[PATHMAX] = "stdin", path_with_tilde[PATHMAX], l[LINELEN];
38 #else /* end of USE_NCURSES */
39 char path[PATHMAX] = "stdin", l[LINELEN];
40 #endif /* else if not USE_NCURSES */
41 char *h;
42 FILE *f;
43 BUFFER *folder;
44 BUFFER *line, *field, *content, *name;
45 BUFFER *index;
46 BUFFER *mail, *log;
47 int mailfolder = -1; /* -1 = unknown, 0 = no mailfolder, 1 = mailfolder */
48 int num = 0;
49 long from = -1, subject = -1;
50 int folder_has_changed;
51 #ifdef USE_NCURSES
52 BUFFER *deleted_message;
53 BUFFER *new_folder;
54 BUFFER *new_index;
55 long length;
56 char sub[LINELEN], str[LINELEN], search[LINELEN] = "";
57 long p;
58 int display, range, selected, i, redraw, c, q;
59
60 #endif /* USE_NCURSES */
61 int ispgp = 0, eof = 0;
62 folder_has_changed = 0;
63
64 line = buf_new();
65 field = buf_new();
66 content = buf_new();
67 index = buf_new();
68 mail = buf_new();
69 name = buf_new();
70 folder = buf_new();
71 log = buf_new();
72
73 if (foldername == NULL)
74 f = stdin;
75 else {
76 if (foldername[0] == '~' && (h = getenv("HOME")) != NULL) {
77 strncpy(path, h, PATHMAX);
78 strcatn(path, foldername + 1, PATHMAX);
79 } else
80 strncpy(path, foldername, PATHMAX);
81 f = fopen(path, "r");
82 }
83 if (f == NULL) {
84 #ifdef USE_NCURSES
85 if (foldername)
86 beep();
87 #endif /* USE_NCURSES */
88 mix_status("Can't read %s.\n", path);
89 goto end;
90 }
91 for (;;) {
92 if (fgets(l, sizeof(l), f) == NULL)
93 eof = 1;
94 else if (mailfolder == -1) {
95 if (strleft(l, "From "))
96 mailfolder = 1;
97 if (strileft(l, "from:") || strileft(l, "path:")
98 || strileft(l, "xref:"))
99 mailfolder = 0;
100 }
101 if (eof || (mailfolder && strleft(l, "From ")) ||
102 (mailfolder == 0 && from != -1 &&
103 (strileft(l, "path:") ||
104 strileft(l, "xref:")))) {
105 if (num > 1)
106 mix_status("Reading message %d", num);
107 #ifdef USE_PGP
108 if (ispgp)
109 switch (nym_decrypt(mail, NULL, log)) {
110 case 2:
111 from = -1, subject = -1;
112 while (buf_getline(mail, line) == 0) {
113 if (bufileft(line, "from:"))
114 from = folder->length + mail->ptr - line->length - 1;
115 if (bufileft(line, "subject:"))
116 subject = folder->length + mail->ptr - line->length - 1;
117 }
118 folder_has_changed = 1;
119 break;
120 case -1:
121 buf_clear(mail);
122 from = -1, subject = -1;
123 continue;
124 default:
125 ;
126 }
127 #endif /* USE_PGP */
128 buf_cat(folder, mail);
129 buf_clear(mail);
130 ispgp = 0;
131 if (num > 0) {
132 buf_appendl(index, from);
133 buf_appendl(index, subject);
134 }
135 if (eof)
136 break;
137
138 buf_appendl(index, folder->length);
139 from = subject = -1;
140 num++;
141 }
142 if (from == -1 && strileft(l, "from:"))
143 from = folder->length + mail->length;
144
145 if (subject == -1 && strileft(l, "subject:"))
146 subject = folder->length + mail->length;
147
148 buf_appends(mail, l);
149 if (strleft(l, begin_pgp))
150 ispgp = 1;
151 }
152
153 if (foldername)
154 fclose(f);
155 else {
156 dup2(open("/dev/tty", O_RDWR), fileno(stdin));
157 menu_init();
158 }
159
160 mix_status("");
161 if (folder->length == 0) {
162 #ifdef USE_NCURSES
163 clear();
164 beep();
165 #endif /* USE_NCURSES */
166 mix_status("%s is empty.\n", path);
167 goto end;
168 }
169 if (mailfolder != 1) {
170 #ifdef USE_NCURSES
171 clear();
172 beep();
173 #endif /* USE_NCURSES */
174 mix_status("%s is not a mail folder.\n", path);
175 goto end;
176 }
177 #ifndef USE_NCURSES
178 if (command == 0) {
179 buf_write(folder, stdout);
180 goto end;
181 }
182 if (num > 1) {
183 mix_status("Folder contains several messages.");
184 goto end;
185 }
186 #endif /* not USE_NCURSES */
187
188 if (num < 2) {
189 folder->ptr = 0;
190 mimedecode(folder);
191
192 if (command != 0)
193 send_message(command, nym, folder);
194 #ifdef USE_NCURSES
195 else
196 read_message(folder, nym);
197
198 clear();
199 #endif /* USE_NCURSES */
200 goto end;
201 }
202 #ifdef USE_NCURSES
203 display = selected = 0;
204 range = LINES - 3;
205 redraw = 2;
206
207 for (;;) {
208 if (selected < 0)
209 selected = 0;
210 if (selected >= num)
211 selected = num - 1;
212
213 if (selected < display) {
214 display = selected - range / 2;
215 redraw = 2;
216 }
217 if (selected >= display + range) {
218 display = selected - range / 2;
219 redraw = 2;
220 }
221 if (display >= num - 5)
222 display = num - 5;
223 if (display < 0)
224 display = 0;
225
226 if (redraw) {
227 if (redraw == 2) {
228 clear();
229 standout();
230 mvprintw(0, 0, "Mixmaster %s", VERSION);
231 printw(" %.20s reading %.50s", nym, path);
232 standend();
233 }
234 for (i = display; i < display + range; i++) {
235 if (i < num) {
236 index->ptr = 12 * i;
237 p = buf_getl(index);
238 buf_clear(name);
239 folder->ptr = buf_getl(index);
240 if (folder->ptr < 0)
241 folder->ptr = 0;
242 else {
243 buf_getheader(folder, field, line);
244 if (line->length) {
245 decode_header(line);
246 rfc822_name(line, name);
247 }
248 }
249 if (i == selected)
250 standout();
251
252 mvaddnstr(i - display + 2, 0, name->data, 18);
253
254 sub[0] = '\0';
255 folder->ptr = buf_getl(index);
256 if (folder->ptr < 0)
257 folder->ptr = 0;
258 else {
259 buf_getheader(folder, field, content);
260 if (content->length) {
261 decode_header(content);
262 strncpy(sub, content->data, sizeof(sub));
263 }
264 }
265 if (sub[0] == '\0')
266 strcpy(sub, "(no subject)");
267 mvaddnstr(i - display + 2, 20, sub, COLS - 21);
268
269 if (i == selected)
270 standend();
271 }
272 }
273 }
274 move(LINES - 1, COLS - 1);
275 refresh();
276 redraw = 0;
277
278 c = getch();
279 switch (c) {
280 case '\014':
281 display = selected - range / 2;
282 redraw = 2;
283 break;
284 case 'q':
285 clear();
286 goto end;
287 case '/':
288 echo();
289 cl(LINES - 1, 0);
290 printw("Search: ");
291 refresh();
292 wgetnstr(stdscr, str, LINELEN);
293 if (str[0] != '\0')
294 strncpy(search, str, LINELEN);
295 noecho();
296 for (i = (selected < num ? selected + 1 : 0); i < num; i++) {
297 index->ptr = 12 * i + 4;
298 folder->ptr = buf_getl(index);
299 if (folder->ptr < 0)
300 folder->ptr = 0;
301 else {
302 buf_getheader(folder, field, line);
303 if (line->length) {
304 decode_header(line);
305 if (bufifind(line, search))
306 break;
307 }
308 }
309 folder->ptr = buf_getl(index);
310 if (folder->ptr < 0)
311 folder->ptr = 0;
312 else {
313 buf_getheader(folder, field, line);
314 if (line->length) {
315 decode_header(line);
316 if (bufifind(line, search))
317 break;
318 }
319 }
320 }
321 if (i < num)
322 selected = i;
323 else
324 beep();
325 redraw = 1;
326 break;
327 case '\r': /* read message */
328 case '\n':
329 case 'r': /* reply to message */
330 case 'g':
331 case 'f':
332 case 'm':
333 case 'p':
334 case 's':
335 index->ptr = 12 * selected;
336 p = buf_getl(index);
337 if (selected < num - 1) {
338 index->ptr = 12 * (selected + 1);
339 q = buf_getl(index) - p;
340 } else
341 q = folder->length - p;
342 buf_clear(mail);
343 buf_append(mail, folder->data + p, q);
344 mimedecode(mail);
345 if(c == 's')
346 savemsg(mail);
347 else{
348 if (c == '\r' || c == '\n')
349 read_message(mail, nym);
350 else
351 send_message(c, nym, mail);
352 }
353 redraw = 2;
354 break;
355 case 'd': /* delete message */
356 /* Remove message from folder */
357 if(num > 0){
358 index->ptr = 12 * selected;
359 p = buf_getl(index);
360 if (selected < num - 1) {
361 index->ptr = 12 * (selected + 1);
362 q = buf_getl(index) - p;
363 } else
364 q = folder->length - p;
365 deleted_message = buf_new();
366 new_folder = buf_new();
367 buf_cut_out(folder, deleted_message, new_folder, p, q);
368 buf_free(deleted_message);
369 buf_free(folder);
370 folder = new_folder;
371 /* Update index file */
372 new_index = buf_new();
373 index->ptr = 0;
374 if(selected > 0)
375 buf_get(index, new_index, 12 * selected);
376 index->ptr = 12 * (selected + 1);
377 while((from = buf_getl(index)) != -1){
378 subject = buf_getl(index);
379 length = buf_getl(index);
380 buf_appendl(new_index, from - q);
381 buf_appendl(new_index, subject - q);
382 buf_appendl(new_index, length - q);
383 }
384 buf_free(index);
385 index = new_index;
386 /* Done */
387 num--;
388 folder_has_changed = 1;
389 }
390 redraw = 2;
391 break;
392 case KEY_UP:
393 selected--;
394 redraw = 1;
395 break;
396 case KEY_DOWN:
397 case 'n': /* nym ???? */
398 selected++;
399 redraw = 1;
400 break;
401 case KEY_PPAGE:
402 selected -= range;
403 redraw = 1;
404 break;
405 case KEY_NPAGE:
406 selected += range;
407 redraw = 1;
408 break;
409 default:
410 beep();
411 }
412 }
413 #endif /* USE_NCURSES */
414
415 end:
416 #ifdef USE_NCURSES
417 /* If folder has changed, ask user about saving new folder. */
418 if (folder_has_changed && !streq(path, "stdin")) {
419 mvprintw(LINES - 2, 0, "Buffer has changed. Save [y/n]? ");
420 c = getch();
421 cl(LINES - 2, 0);
422 if ((c == 'y') || (c == 'Y')){
423 strncpy(path_with_tilde, path, PATHMAX-1);
424 strcat(path_with_tilde, "~");
425 rename(path, path_with_tilde); /* Rename folder to folder~ */
426 f = fopen(path, "w"); /* Write new folder */
427 if (f == NULL)
428 mix_status("Can't write to %s.", path);
429 else{
430 buf_write(folder, f);
431 mix_status("Wrote %s.", path);
432 fclose(f);
433 }
434 }
435 else{
436 mix_status("%s was not saved.", path);
437 }
438 }
439 #endif /* USE_NCURSES */
440 buf_free(folder);
441 buf_free(line);
442 buf_free(field);
443 buf_free(content);
444 buf_free(index);
445 buf_free(mail);
446 buf_free(name);
447 buf_free(log);
448 }
449
450 #ifdef USE_NCURSES
451 static int sortrel(const void *a, const void *b)
452 {
453 int na, ra, nb, rb;
454
455 na = *(int *) a;
456 nb = *(int *) b;
457
458 ra = *((int *) a + 1);
459 rb = *((int *) b + 1);
460 return rb - ra;
461 }
462
463 void menu_main(void)
464 {
465 int y, x;
466 int pool, n;
467 int c;
468 BUFFER *chainlist, *line;
469 char nym[LINELEN] = ANON;
470
471 chainlist = buf_new();
472 line = buf_new();
473
474 mix_init(NULL);
475 menu_init();
476
477 menu_redraw:
478 clear();
479 for (;;) {
480 standout();
481 mvprintw(0, 0, "Mixmaster %s", VERSION);
482 mvprintw(0, COLS - sizeof(COPYRIGHT), COPYRIGHT);
483 standend();
484 mix_status(NULL);
485
486 mvprintw(8, 4, "n)ym: %s", nym);
487 y = 12, x = 25;
488 mvprintw(y++, x, "m)ail");
489 mvprintw(y++, x, "p)ost to Usenet");
490 mvprintw(y++, x, "r)ead mail");
491 mvprintw(y++, x, "d)ummy message");
492 mvprintw(y++, x, "s)end messages from pool");
493 mvprintw(y++, x, "q)uit");
494
495 pool = pool_read(NULL);
496 if (pool == 1)
497 mvprintw(4, 2, "%3d outgoing message in the pool. \n", pool);
498 else
499 mvprintw(4, 2, "%3d outgoing messages in the pool.\n", pool);
500
501 move(LINES - 1, COLS - 1);
502 refresh();
503 c = getch();
504 if (c != ERR) {
505 mix_status("");
506 switch (c) {
507 case '\014':
508 mix_status("");
509 goto menu_redraw;
510 case 'n':
511 menu_nym(nym);
512 goto menu_redraw;
513 case 'm':
514 case 'p':
515 send_message(c, nym, NULL);
516 break;
517 case 'd':
518 mix_status("Creating message...");
519 if (mix_encrypt(MSG_NULL, NULL, NULL, 1, chainlist) != 0) {
520 if (chainlist->length > 0)
521 mix_status("%s", chainlist->data);
522 else
523 mix_genericerror();
524 beep();
525 } else {
526 for (n = 0; buf_getline(chainlist, line) == 0; n++) ;
527 if (n > 1)
528 mix_status("Done (%d packets).", n);
529 else
530 mix_status("Chain: %s", chainlist->data);
531 }
532 break;
533 case 's':
534 mix_status("Mailing messages...");
535 mix_send();
536 mix_status("Done.");
537 break;
538 case 'r':
539 {
540 char name[LINELEN];
541
542 cl(LINES - 3, 0);
543 if (getenv("MAIL"))
544 printw("File name [%s]: ", getenv("MAIL"));
545 else
546 printw("File name: ");
547 echo();
548 wgetnstr(stdscr, name, LINELEN);
549 noecho();
550 cl(LINES - 3, 0);
551 if (name[0] == '\0') {
552 if (getenv("MAIL"))
553 read_folder(0, getenv("MAIL"), nym);
554 } else
555 read_folder(0, name, nym);
556 }
557 break;
558 case 'q':
559 case 'Q':
560 goto quit;
561 default:
562 beep();
563 }
564 }
565 }
566
567 quit:
568 menu_exit();
569 buf_free(chainlist);
570 buf_free(line);
571 }
572
573 void read_message(BUFFER *message, char *nym)
574 {
575 int l = 0;
576 int c;
577 int inhdr = 1, txtbegin;
578 BUFFER *field, *content, *line, *hdr;
579 char sub[LINELEN] = "mail";
580 char thisnym[LINELEN] = "";
581
582 field = buf_new();
583 content = buf_new();
584 line = buf_new();
585 hdr = buf_new();
586
587 if (thisnym[0] == '\0')
588 strncpy(thisnym, nym, LINELEN);
589
590 if (bufleft(message, "From nymserver ")) {
591 /* select nym if Nym: pseudo header is in the first line */
592 buf_getline(message, line);
593 buf_getheader(message, field, content);
594 if (bufieq(field, "Nym"))
595 strncpy(thisnym, content->data, sizeof(thisnym));
596 buf_rewind(message);
597 }
598 while (buf_getheader(message, field, content) == 0) {
599 if (bufieq(field, "received") || bufleft(field, "From "))
600 continue;
601 if (bufieq(field, "subject"))
602 strncpy(sub, content->data, sizeof(sub));
603 buf_appendheader(hdr, field, content);
604 }
605 if (strlen(sub) > COLS - strlen(VERSION) - strlen(thisnym) - 23)
606 sub[COLS - strlen(VERSION) - strlen(thisnym) - 24] = '\0';
607 txtbegin = message->ptr;
608
609 loop:
610 clear();
611 standout();
612 mvprintw(0, 0, "Mixmaster %s", VERSION);
613 printw(" %.20s reading %.50s\n", thisnym, sub);
614 standend();
615 mix_status(NULL);
616
617 while (l < LINES - 2) {
618 if (inhdr) {
619 if (buf_getline(hdr, line) == -1)
620 buf_clear(line), inhdr = 0;
621 } else {
622 if (buf_getline(message, line) == -1) {
623 standout();
624 mvprintw(LINES - 1, 0, "Command");
625 standend();
626 refresh();
627 for (;;) {
628 c = getch();
629 switch (c) {
630 case 'm':
631 case 'p':
632 case 'r':
633 case 'g':
634 case 'f':
635 send_message(c, thisnym, message);
636 goto end;
637 case 'u':
638 inhdr = 0;
639 message->ptr = txtbegin;
640 l = 0;
641 goto loop;
642 case 'h':
643 inhdr = 1;
644 hdr->ptr = 0;
645 message->ptr = txtbegin;
646 l = 0;
647 goto loop;
648 case 's':
649 savemsg(message);
650 /* fallthru */
651 case 'q':
652 case 'i':
653 case '\n':
654 case '\r':
655 goto end;
656 case '\014':
657 refresh();
658 continue;
659 default:
660 beep();
661 refresh();
662 }
663 }
664 }
665 }
666 mvprintw(l + 1, 0, "%s\n", line->data);
667 l += (line->length - 1) / COLS + 1;
668 }
669 standout();
670 mvprintw(LINES - 1, 0, "MORE");
671 standend();
672 refresh();
673 for (;;) {
674 c = getch();
675 switch (c) {
676 case 'm':
677 case 'p':
678 case 'r':
679 case 'g':
680 case 'f':
681 send_message(c, thisnym, message);
682 goto end;
683 case 'u':
684 inhdr = 0;
685 message->ptr = txtbegin;
686 l = 0;
687 goto loop;
688 case 'h':
689 inhdr = 1; /* show full header */
690 hdr->ptr = 0;
691 message->ptr = txtbegin;
692 l = 0;
693 goto loop;
694 case 's':
695 savemsg(message);
696 /* fallthru */
697 case 'q':
698 case 'i':
699 goto end;
700 case ' ':
701 case '\n':
702 case '\r':
703 l = 0;
704 goto loop;
705 case '\014':
706 refresh();
707 continue;
708 default:
709 beep();
710 refresh();
711 }
712 }
713 end:
714 buf_free(field);
715 buf_free(content);
716 buf_free(line);
717 buf_free(hdr);
718 }
719
720 int menu_replychain(int *d, int *l, char *mdest, char *pdest, char *psub,
721 char *r)
722 {
723 int c;
724 char line[LINELEN];
725 char reliability[9];
726
727 redraw:
728 clear();
729 standout();
730 printw("Create a nym reply block:");
731 standend();
732 mix_status(NULL);
733
734 mvprintw(3, 0, "Type of reply block:\n");
735 if (*d == MSG_MAIL)
736 standout();
737 printw(" m)ail ");
738 if (*d == MSG_MAIL)
739 standend();
740
741 if (*d == MSG_POST)
742 standout();
743 printw(" Usenet message p)ool ");
744 if (*d == MSG_POST)
745 standend();
746
747 if (*d == MSG_NULL)
748 standout();
749 printw(" cover t)raffic ");
750 if (*d == MSG_NULL)
751 standend();
752
753 if (*d != MSG_NULL)
754 mvprintw(6, 0, "d)estination: %s", *d == MSG_MAIL ? mdest : pdest);
755 if (psub && *d == MSG_POST)
756 mvprintw(7, 0, "s)ubject: %s", psub);
757 chain_reliability(r, 1, reliability); /* chaintype 1=ek */
758 mvprintw(8, 0, "c)hain: %-39s (reliability: %s)", r, reliability);
759 mvprintw(10, 0, "l)atency: %d hours", *l);
760 move(LINES - 1, COLS - 1);
761
762 for (;;) {
763 refresh();
764 c = getch();
765 switch (c) {
766 case 'm':
767 *d = MSG_MAIL;
768 goto redraw;
769 case 'p':
770 *d = MSG_POST;
771 goto redraw;
772 case 't':
773 *d = MSG_NULL;
774 goto redraw;
775 case 'q':
776 return (-1);
777 case 'd':
778 cl(6, 0);
779 printw("d)estination: ");
780 echo();
781 wgetnstr(stdscr, *d == MSG_MAIL ? mdest : pdest, LINELEN);
782 noecho();
783 goto redraw;
784 case 'l':
785 cl(10, 0);
786 printw("l)atency: ");
787 echo();
788 wgetnstr(stdscr, line, LINELEN);
789 *l = strtol(line, NULL, 10);
790 if (*l < 0)
791 *l = 0;
792 noecho();
793 goto redraw;
794 case 'c':
795 menu_chain(r, 1, *d == MSG_POST);
796 goto redraw;
797 case '\014':
798 goto redraw;
799 case '\n':
800 case '\r':
801 return (0);
802 case 's':
803 if (*d == MSG_POST) {
804 cl(7, 0);
805 printw("s)ubject: ");
806 echo();
807 wgetnstr(stdscr, psub, LINELEN);
808 noecho();
809 goto redraw;
810 }
811 default:
812 beep();
813 }
814 }
815 }
816
817 void menu_chain(char *chainstr, int chaintype, int post)
818 /* chaintype 0=mix 1=ek 2=newnym */
819 {
820 REMAILER remailer[MAXREM];
821 int rlist[2 * MAXREM];
822 char newchain[CHAINMAX];
823 char info[LINELEN];
824 int num = 0, i, middlemanlast=0, ok = 1;
825 int c, x, y;
826 int nymserv = 0;
827 int chain[20], chainlen = 0;
828 char reliability[9];
829
830 if (chaintype == 2)
831 nymserv = 1, chaintype = 1;
832 assert(chaintype == 0 || chaintype == 1);
833
834 clear();
835 standout();
836 if (nymserv)
837 printw("Select nym server:\n\n");
838 else
839 printw("Select remailer chain:\n\n");
840 standend();
841
842 if (chaintype == 1)
843 num = t1_rlist(remailer);
844 else
845 num = mix2_rlist(remailer);
846
847 if (num < 1) {
848 mix_status("Can't read remailer list.");
849 beep();
850 return;
851 }
852 for (i = 0; i < num; i++) {
853 rlist[2 * i] = i + 1;
854 rlist[2 * i + 1] = remailer[i + 1].info[chaintype].reliability -
855 remailer[i + 1].info[chaintype].latency / 3600;
856 if (remailer[i + 1].info[chaintype].history[0] == '\0')
857 rlist[2 * i + 1] = -1;
858 if ((nymserv && !remailer[i + 1].flags.newnym) ||
859 ((chaintype == 0 && !remailer[i + 1].flags.mix) ||
860 (chaintype == 1 && !nymserv && (!remailer[i + 1].flags.ek
861 || !remailer[i + 1].flags.pgp))))
862 rlist[2 * i] = 0, rlist[2 * i + 1] = -2;
863 }
864 qsort(rlist, num - 1, 2 * sizeof(int), sortrel);
865
866 for (i = 0; i < num; i++)
867 if (rlist[2 * i + 1] == -2) {
868 num = i;
869 break;
870 }
871 if (num < 1) {
872 mix_status("No remailers found!");
873 return;
874 }
875 if (num > 2 * (LINES - 6))
876 num = 2 * (LINES - 6);
877 if (num > 2 * 26)
878 num = 2 * 26;
879
880 for (i = 0; i < num && rlist[2 * i + 1] > -2; i++) {
881 y = i, x = 0;
882 if (y >= LINES - 6)
883 y -= LINES - 6, x += 40;
884 mvprintw(y + 2, x, "%c", i < 26 ? i + 'a' : i - 26 + 'A');
885 mvprintw(y + 2, x + 2, "%s", remailer[rlist[2 * i]].name);
886 mvprintw(y + 2, x + 16, "%s",
887 remailer[rlist[2 * i]].info[chaintype].history);
888 sprintf(info, "%3.2f",
889 remailer[rlist[2 * i]].info[chaintype].reliability / 100.0);
890 mvprintw(y + 2, x + 29 + 6 - strlen(info), "%s%%", info);
891 }
892 y = num + 3;
893 if (y > LINES - 4)
894 y = LINES - 4;
895 mvprintw(y, 0, "* select at random");
896
897 for (;;) {
898 newchain[0] = '\0';
899 for (i = 0; i < chainlen; i++) {
900 if (i)
901 strcatn(newchain, ",", CHAINMAX);
902 if (chain[i])
903 strcatn(newchain, remailer[chain[i]].name, CHAINMAX);
904 else
905 strcatn(newchain, "*", CHAINMAX);
906 }
907 if (chainlen > 0) {
908 ok = 1;
909 middlemanlast = remailer[chain[chainlen - 1]].flags.middle;
910 if (post && !remailer[chain[chainlen - 1]].flags.post)
911 ok = 0;
912 } else
913 ok = 1;
914
915 mvprintw(LINES - 4, 40,
916 middlemanlast ?
917 "MIDDLEMAN " :
918 (ok ?
919 " " :
920 "NO POSTING "));
921 cl(LINES - 3, 0);
922 cl(LINES - 2, 0);
923 cl(LINES - 1, 0);
924 if(!nymserv){
925 chain_reliability(newchain, chaintype, reliability);
926 mvprintw(LINES - 4, 58, "(reliability: %s)", reliability);
927 }
928 mvprintw(LINES - 3, 0, nymserv ? "Nym server: %s" : "Chain: %s",
929 newchain);
930 refresh();
931 c = getch();
932 if (c == '\n' || c == '\r') {
933 /* beep and sleep in case the user made a mistake */
934 if (middlemanlast) {
935 beep();
936 sleep(2);
937 }
938 if (ok || middlemanlast)
939 break;
940 else
941 beep();
942 } else if (c == '*') {
943 if (chainlen > 19 || (nymserv && chainlen > 0))
944 beep();
945 else
946 chain[chainlen++] = 0;
947 } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
948 if (c >= 'a')
949 c -= 'a';
950 else
951 c = c - 'A' + 26;
952
953 if (chainlen > 19 || (nymserv && chainlen > 0) || c >= num)
954 beep();
955 else
956 chain[chainlen++] = rlist[2 * c];
957 } else if (c == killchar())
958 chainlen = 0;
959 else if ((c == KEY_BACKSPACE || c == KEY_LEFT || c == erasechar())
960 && chainlen > 0)
961 --chainlen;
962 else
963 beep();
964 }
965 if (chainlen)
966 strncpy(chainstr, newchain, CHAINMAX);
967 }
968
969 #endif /* USE_NCURSES */

  ViewVC Help
Powered by ViewVC 1.1.5