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

Contents of /trunk/Mix/Src/menunym.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: 11486 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 - nym management
9 $Id: menunym.c,v 1.2 2002/09/18 23:26:16 rabbi Exp $ */
10
11
12 #include "menu.h"
13 #include "mix3.h"
14 #include <string.h>
15 #include <stdlib.h>
16 #ifdef POSIX
17 #include <unistd.h>
18 #endif /* POSIX */
19
20 #ifdef USE_NCURSES
21 void menu_nym(char *nnym)
22 {
23 char nym[maxnym][LINELEN];
24 char pending[maxnym][LINELEN];
25 int c, i, num = 0, numpending = 0, select = -1;
26 int edit = 0;
27 BUFFER *nymlist;
28 int s;
29 int pass = 0;
30 char reliability[9]; /* When printing information about a chain,
31 this variable stores the reliability. */
32
33 nymlist = buf_new();
34
35 strcpy(nym[0], NONANON);
36 strcatn(nym[0], " (", sizeof(nym[0]));
37 strcatn(nym[0], NAME, sizeof(nym[0]));
38 strcatn(nym[0], ")", sizeof(nym[0]));
39
40 strcpy(nym[1], ANON);
41 num = 2;
42 if (nymlist_read(nymlist) == -1) {
43 user_delpass();
44 mix_status("");
45 } else
46 pass = 1;
47 while (nymlist_get(nymlist, nym[num], NULL, NULL, NULL, NULL, NULL, &s) >= 0) {
48 if (s == NYM_OK) {
49 if (num < maxnym)
50 num++;
51 } else if (s == NYM_WAITING) {
52 if (numpending < maxnym)
53 strncpy(pending[numpending++], nym[num], LINELEN);
54 }
55 }
56 buf_free(nymlist);
57
58 nymselect:
59 clear();
60 standout();
61 printw("Select nym:\n\n");
62 standend();
63 #ifdef USE_PGP
64 if (pass)
65 printw("c)reate new nym\ne)dit nym\nd)elete nym\n\n");
66 else
67 printw("[nym passphrase is invalid]\n\n");
68 #endif /* USE_PGP */
69 for (i = 0; i < num; i++)
70 printw("%d) %s\n", i, nym[i]);
71 if (numpending > 0) {
72 printw("\n\nWaiting for confirmation: ");
73 for (i = 0; i < numpending; i++)
74 printw("%s ", pending[i]);
75 printw("\n");
76 }
77 select:
78 if (select != -1)
79 printw("\r%d", select);
80 else
81 printw("\r \r");
82 refresh();
83 c = getch();
84 if (c == erasechar())
85 c = KEY_BACKSPACE;
86 if (c >= '0' && c <= '9') {
87 if (select == -1)
88 select = c - '0';
89 else
90 select = 10 * select + c - '0';
91 if (edit ? select == 0 || select >= num + numpending - 1 : select >= num) {
92 beep();
93 select = -1;
94 }
95 refresh();
96 goto select;
97 } else
98 switch (c) {
99 case KEY_BACKSPACE:
100 select /= 10;
101 if (select < 1)
102 select = -1;
103 goto select;
104 case 'q':
105 if (edit) {
106 edit = 0;
107 select = -1;
108 goto nymselect;
109 }
110 break;
111 #ifdef USE_PGP
112 case 'e':
113 if (pass) {
114 if (edit || num + numpending < 3) {
115 edit = 0;
116 select = -1;
117 goto nymselect;
118 } else {
119 clear();
120 standout();
121 printw("Edit nym:\n\n");
122 standend();
123 for (i = 2; i < num + numpending; i++)
124 printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
125 printw("\n");
126 select = -1;
127 edit = NYM_MODIFY;
128 goto select;
129 }
130 }
131 break;
132 case 'd':
133 if (pass) {
134 if (edit || num + numpending < 3) {
135 edit = 0;
136 select = -1;
137 goto nymselect;
138 } else {
139 clear();
140 standout();
141 printw("Delete nym:\n\n");
142 standend();
143 for (i = 2; i < num + numpending; i++)
144 printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
145 printw("\n");
146 select = -1;
147 edit = NYM_DELETE;
148 goto select;
149 }
150 }
151 break;
152 case '\r':
153 case '\n':
154 if (select == -1 || (edit && select == 0)) {
155 beep();
156 edit = 0;
157 select = -1;
158 goto nymselect;
159 }
160 if (!edit) {
161 strncpy(nnym, nym[select], LINELEN);
162 return;
163 }
164 /* fallthru */
165 case 'c':
166 if (pass) {
167 char nymserv[LINELEN] = "*";
168 char replyblock[5][CHAINMAX], dest[10][LINELEN];
169 int latent[5], desttype[5];
170 char mdest[LINELEN], pdest[LINELEN] = "alt.anonymous.messages",
171 psub[LINELEN] = "";
172 int deflatent = 0, defdesttype = MSG_MAIL;
173 char alias[LINELEN] = "";
174 BUFFER *name, *opt;
175 char sendchain[CHAINMAX];
176 int sendnumcopies = 1, rnum = 1;
177 int i;
178 char line[LINELEN];
179 int acksend = 0, signsend = 0, fixedsize = 0, disable = 0,
180 fingerkey = 1;
181
182 name = buf_new();
183 opt = buf_new();
184 strncpy(sendchain, CHAIN, CHAINMAX);
185 strncpy(mdest, ADDRESS, LINELEN);
186 if (edit)
187 strncpy(alias, select + 1 < num ? nym[select + 1] :
188 pending[select + 1 - num], LINELEN);
189 if (edit == NYM_MODIFY) {
190 nymlist_getnym(alias, NULL, NULL, opt, name, NULL);
191 acksend = bufifind(opt, "+acksend");
192 signsend = bufifind(opt, "+signsend");
193 fixedsize = bufifind(opt, "+fixedsize");
194 disable = bufifind(opt, "+disable");
195 fingerkey = bufifind(opt, "+fingerkey");
196 rnum = -1;
197 }
198 newnym:
199 if (!edit) {
200 clear();
201 standout();
202 printw("Create a nym:");
203 standend();
204
205 mvprintw(3, 0, "Alias address: ");
206 echo();
207 wgetnstr(stdscr, alias, LINELEN);
208 noecho();
209 if (alias[0] == '\0')
210 goto end;
211 for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
212 alias[i] = '\0';
213 if (i == 0)
214 goto newnym;
215 mvprintw(4, 0, "Pseudonym: ");
216 echo();
217 wgetnstr(stdscr, line, LINELEN);
218 noecho();
219 buf_sets(name, line);
220 menu_chain(nymserv, 2, 0);
221 }
222 if (edit != NYM_DELETE) {
223 for (i = 0; i < 5; i++) {
224 desttype[i] = defdesttype;
225 latent[i] = deflatent;
226 dest[i][0] = '\0';
227 strcpy(replyblock[i], "*,*,*,*");
228 }
229 if (rnum != -1) {
230 menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
231 replyblock[0]);
232 desttype[0] = defdesttype;
233 latent[0] = deflatent;
234 strncpy(dest[0], desttype[0] == MSG_POST ? pdest : mdest,
235 LINELEN);
236 }
237 }
238 redraw:
239 clear();
240 standout();
241 switch (edit) {
242 case NYM_DELETE:
243 printw("Delete nym:");
244 break;
245 case NYM_MODIFY:
246 printw("Edit nym:");
247 break;
248 default:
249 printw("Create a nym:");
250 break;
251 }
252 standend();
253 loop:
254 {
255 if (!edit) {
256 cl(2, 0);
257 printw("Nym: a)lias address: %s", alias);
258 cl(3, 0);
259 printw(" nym s)erver: %s", nymserv);
260 }
261 if (edit != NYM_DELETE) {
262 cl(4, 0);
263 printw(" p)seudonym: %s", name->data);
264 if (edit)
265 mvprintw(6, 0, "Nym modification:");
266 else
267 mvprintw(6, 0, "Nym creation:");
268 }
269 cl(7, 0);
270 chain_reliability(sendchain, 0, reliability); /* chaintype 0=mix */
271 printw(" c)hain to nym server: %-30s (reliability: %s)", sendchain, reliability);
272 cl(8, 0);
273 printw(" n)umber of redundant copies: %d", sendnumcopies);
274 if (edit != NYM_DELETE) {
275 mvprintw(10, 0, "Configuration:\n");
276 printw(" A)cknowledge sending: %s\n", acksend ? "yes" : "no");
277 printw(" S)erver signatures: %s\n", signsend ? "yes" : "no");
278 printw(" F)ixed size replies: %s\n", fixedsize ? "yes" :
279 "no");
280 printw(" D)isable: %s\n", disable ? "yes" : "no");
281 printw(" Finger K)ey: %s\n", fingerkey ? "yes" : "no");
282 mvprintw(17, 0, "Reply chains:");
283 cl(18, 0);
284 if (rnum == -1)
285 printw(" create new r)eply block");
286 else {
287 printw(" number of r)eply chains: %2d reliability", rnum);
288 for (i = 0; i < rnum; i++) {
289 cl(i + 19, 0);
290 chain_reliability(replyblock[i], 1, reliability); /* 1=ek */
291 printw(" %d) %30s %-31s [%s]", i + 1,
292 desttype[i] == MSG_NULL ?
293 "(cover traffic)" : dest[i], replyblock[i],
294 reliability);
295 }
296 }
297 }
298 move(LINES - 1, COLS - 1);
299 refresh();
300 c = getch();
301 if (edit != NYM_DELETE && c >= '1' && c <= '9' && c - '1' < rnum) {
302 menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
303 replyblock[c - '1']);
304 desttype[c - '1'] = defdesttype;
305 latent[c - '1'] = deflatent;
306 strncpy(dest[c - '1'],
307 desttype[c - '1'] == MSG_POST ? pdest : mdest, LINELEN);
308 goto redraw;
309 }
310 switch (c) {
311 case 'A':
312 acksend = !acksend;
313 goto redraw;
314 case 'S':
315 signsend = !signsend;
316 goto redraw;
317 case 'F':
318 fixedsize = !fixedsize;
319 goto redraw;
320 case 'D':
321 disable = !disable;
322 goto redraw;
323 case 'K':
324 fingerkey = !fingerkey;
325 goto redraw;
326 case 'q':
327 edit = 0;
328 select = -1;
329 goto nymselect;
330 case '\014':
331 goto redraw;
332 case 'a':
333 cl(2, 0);
334 printw("Nym: a)lias address: ");
335 echo();
336 wgetnstr(stdscr, alias, LINELEN);
337 noecho();
338 for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
339 alias[i] = '\0';
340 if (i == 0)
341 goto nymselect;
342 goto redraw;
343 case 'p':
344 cl(4, 0);
345 printw(" p)seudonym: ");
346 echo();
347 wgetnstr(stdscr, line, LINELEN);
348 noecho();
349 if (line[0] != '\0')
350 buf_sets(name, line);
351 goto redraw;
352 case 'c':
353 menu_chain(sendchain, 0, 0);
354 goto redraw;
355 case 'n':
356 cl(8, 0);
357 printw(" n)umber of redundant copies: ");
358 echo();
359 wgetnstr(stdscr, line, LINELEN);
360 noecho();
361 sendnumcopies = strtol(line, NULL, 10);
362 if (sendnumcopies < 1 || sendnumcopies > 10)
363 sendnumcopies = 1;
364 goto redraw;
365 case 'r':
366 cl(18, 0);
367 printw(" number of r)eply chains: ");
368 echo();
369 wgetnstr(stdscr, line, LINELEN);
370 noecho();
371 i = rnum;
372 rnum = strtol(line, NULL, 10);
373 if (rnum < 1)
374 rnum = 1;
375 if (rnum > 5)
376 rnum = 5;
377 for (; i < rnum; i++)
378 if (dest[i][0] == '\0') {
379 desttype[i] = defdesttype;
380 latent[i] = deflatent;
381 strncpy(dest[i], defdesttype == MSG_POST ? pdest :
382 mdest, LINELEN);
383 }
384 goto redraw;
385 case 's':
386 menu_chain(nymserv, 2, 0);
387 goto redraw;
388 case '\n':
389 case '\r':
390 {
391 BUFFER *chains;
392 int err;
393
394 if (rnum == -1)
395 chains = NULL;
396 else {
397 chains = buf_new();
398 for (i = 0; i < rnum; i++)
399 if (replyblock[i][0] != '\0') {
400 if (desttype[i] == MSG_POST)
401 buf_appendf(chains, "Subject: %s\n", psub);
402 if (desttype[i] == MSG_MAIL)
403 buf_appends(chains, "To: ");
404 else if (desttype[i] == MSG_POST)
405 buf_appends(chains, "Newsgroups: ");
406 else
407 buf_appends(chains, "Null:");
408 buf_appendf(chains, "%s\n", dest[i]);
409 buf_appendf(chains, "Chain: %s\n", replyblock[i]);
410 buf_appendf(chains, "Latency: %d\n\n", latent[i]);
411 }
412 }
413 create:
414 clear();
415 buf_setf(opt,
416 " %cacksend %csignsend +cryptrecv %cfixedsize %cdisable %cfingerkey",
417 acksend ? '+' : '-',
418 signsend ? '+' : '-',
419 fixedsize ? '+' : '-',
420 disable ? '+' : '-',
421 fingerkey ? '+' : '-');
422 if (edit) {
423 mix_status("Preparing nymserver configuration message...");
424 err = nym_config(edit, alias, NULL,
425 name, sendchain, sendnumcopies,
426 chains, opt);
427 } else {
428 mix_status("Preparing nym creation request...");
429 err = nym_config(edit, alias, nymserv, name,
430 sendchain, sendnumcopies, chains,
431 opt);
432 }
433 if (err == -3) {
434 beep();
435 mix_status("Bad passphrase!");
436 getch();
437 goto create;
438 }
439 if (err != 0) {
440 mix_genericerror();
441 beep();
442 refresh();
443 } else {
444 if (edit)
445 mix_status("Nymserver configuration message completed.");
446 else
447 mix_status("Nym creation request completed.");
448 }
449 if (chains)
450 buf_free(chains);
451 goto end;
452 }
453 default:
454 beep();
455 goto loop;
456 }
457 }
458 end:
459 buf_free(name);
460 buf_free(opt);
461 return;
462 }
463 #endif /* USE_PGP */
464 default:
465 beep();
466 goto select;
467 }
468 }
469
470 #endif /* USE_NCURSES */

  ViewVC Help
Powered by ViewVC 1.1.5