menu.c (83444B)
1 /* menu.c 2 * (c) 2002 Mikulas Patocka, Petr 'Brain' Kulhavy 3 * This file is a part of the Links program, released under GPL. 4 */ 5 6 #include <limits.h> 7 8 #include "config.h" 9 #include "links.h" 10 11 static struct history file_history = { 12 0, {&file_history.items, &file_history.items} 13 }; 14 15 static unsigned char *const version_texts[] = { 16 TEXT_(T_LINKS_VERSION), 17 TEXT_(T_OPERATING_SYSTEM_VERSION), 18 TEXT_(T_WORD_SIZE), 19 TEXT_(T_EVENT_HANDLER), 20 TEXT_(T_IPV6), 21 TEXT_(T_COMPRESSION_METHODS), 22 TEXT_(T_ENCRYPTION), 23 TEXT_(T_UTF8_TERMINAL), 24 TEXT_(T_GRAPHICS_MODE), 25 TEXT_(T_CONFIGURATION_DIRECTORY), 26 NULL, 27 }; 28 29 static size_t 30 add_and_pad(unsigned char **s, size_t l, struct terminal *term, 31 unsigned char *str, int maxlen) 32 { 33 unsigned char *x = get_text_translation(str, term); 34 size_t len = strlen((char *)x); 35 l = add_to_str(s, l, x); 36 l = add_to_str(s, l, cast_uchar ": "); 37 while (len++ < maxlen) 38 l = add_chr_to_str(s, l, ' '); 39 return l; 40 } 41 42 static void 43 menu_version(void *term_) 44 { 45 struct terminal *term = (struct terminal *)term_; 46 int i; 47 int maxlen = 0; 48 unsigned char *s; 49 size_t l; 50 unsigned char *const *text_ptr; 51 for (i = 0; version_texts[i]; i++) { 52 unsigned char *t = get_text_translation(version_texts[i], term); 53 int tl = strlen((char *)t); 54 if (tl > maxlen) 55 maxlen = tl; 56 } 57 58 s = NULL; 59 text_ptr = version_texts; 60 61 l = add_and_pad(&s, 0, term, *text_ptr++, maxlen); 62 l = add_to_str(&s, l, cast_uchar VERSION); 63 l = add_chr_to_str(&s, l, '\n'); 64 65 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 66 l = add_to_str(&s, l, system_name); 67 l = add_chr_to_str(&s, l, '\n'); 68 69 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 70 l = add_to_str(&s, l, get_text_translation(TEXT_(T_MEMORY), term)); 71 l = add_chr_to_str(&s, l, ' '); 72 l = add_num_to_str(&s, l, sizeof(void *) * 8); 73 l = add_to_str(&s, l, cast_uchar "-bit, "); 74 l = add_to_str(&s, l, get_text_translation(TEXT_(T_FILE_SIZE), term)); 75 l = add_chr_to_str(&s, l, ' '); 76 l = add_num_to_str(&s, l, sizeof(off_t) * 8 /*- ((off_t)-1 < 0)*/); 77 l = add_to_str(&s, l, cast_uchar "-bit"); 78 l = add_chr_to_str(&s, l, '\n'); 79 80 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 81 l = add_event_string(&s, l, term); 82 l = add_chr_to_str(&s, l, '\n'); 83 84 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 85 if (!support_ipv6) 86 l = add_to_str( 87 &s, l, 88 get_text_translation(TEXT_(T_NOT_ENABLED_IN_SYSTEM), term)); 89 else if (!ipv6_full_access()) 90 l = add_to_str( 91 &s, l, 92 get_text_translation(TEXT_(T_LOCAL_NETWORK_ONLY), term)); 93 else 94 l = add_to_str(&s, l, get_text_translation(TEXT_(T_YES), term)); 95 l = add_chr_to_str(&s, l, '\n'); 96 97 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 98 l = add_compress_methods(&s, l); 99 l = add_chr_to_str(&s, l, '\n'); 100 101 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 102 #ifdef OPENSSL_VERSION 103 l = add_to_str(&s, l, 104 (unsigned char *)OpenSSL_version(OPENSSL_VERSION)); 105 #else 106 l = add_to_str(&s, l, (unsigned char *)SSLeay_version(SSLEAY_VERSION)); 107 #endif 108 l = add_chr_to_str(&s, l, '\n'); 109 110 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 111 l = add_to_str(&s, l, get_text_translation(TEXT_(T_YES), term)); 112 l = add_chr_to_str(&s, l, '\n'); 113 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 114 l = add_to_str(&s, l, get_text_translation(TEXT_(T_NO), term)); 115 l = add_chr_to_str(&s, l, '\n'); 116 117 l = add_and_pad(&s, l, term, *text_ptr++, maxlen); 118 if (links_home) { 119 unsigned char *native_home = 120 os_conv_to_external_path(links_home, NULL); 121 l = add_to_str(&s, l, native_home); 122 free(native_home); 123 } else 124 l = add_to_str(&s, l, 125 get_text_translation(TEXT_(T_NONE), term)); 126 l = add_chr_to_str(&s, l, '\n'); 127 128 if (*text_ptr) 129 internal("menu_version: text mismatched"); 130 131 msg_box(term, getml(s, NULL), TEXT_(T_VERSION_INFORMATION), 132 AL_LEFT | AL_MONO, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK), 133 msg_box_null, B_ENTER | B_ESC); 134 } 135 136 static void 137 menu_about(struct terminal *term, void *d, void *ses_) 138 { 139 msg_box(term, NULL, TEXT_(T_ABOUT), AL_CENTER, 140 TEXT_(T_LINKS__LYNX_LIKE), MSG_BOX_END, (void *)term, 2, 141 TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC, TEXT_(T_VERSION), 142 menu_version, 0); 143 } 144 145 static void 146 menu_keys(struct terminal *term, void *d, void *ses_) 147 { 148 msg_box(term, NULL, TEXT_(T_KEYS), AL_LEFT | AL_MONO, 149 TEXT_(T_KEYS_DESC), MSG_BOX_END, NULL, 1, TEXT_(T_OK), 150 msg_box_null, B_ENTER | B_ESC); 151 } 152 153 void 154 activate_keys(struct session *ses) 155 { 156 menu_keys(ses->term, NULL, ses); 157 } 158 159 static void 160 menu_copying(struct terminal *term, void *d, void *ses_) 161 { 162 msg_box(term, NULL, TEXT_(T_COPYING), AL_CENTER, TEXT_(T_COPYING_DESC), 163 MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, 164 B_ENTER | B_ESC); 165 } 166 167 static void 168 menu_url(struct terminal *term, void *url_, void *ses_) 169 { 170 struct session *ses = (struct session *)ses_; 171 unsigned char *url = get_text_translation((unsigned char *)url_, term); 172 goto_url_utf8(ses, url); 173 } 174 175 static void 176 menu_for_frame(struct terminal *term, void *f_, void *ses_) 177 { 178 struct session *ses = (struct session *)ses_; 179 void (*f)(struct session *, struct f_data_c *, int) = 180 *(void (*const *)(struct session *, struct f_data_c *, int))f_; 181 do_for_frame(ses, f, 0); 182 } 183 184 static void 185 menu_goto_url(struct terminal *term, void *d, void *ses_) 186 { 187 struct session *ses = (struct session *)ses_; 188 dialog_goto_url(ses, cast_uchar ""); 189 } 190 191 static void 192 menu_save_url_as(struct terminal *term, void *d, void *ses_) 193 { 194 struct session *ses = (struct session *)ses_; 195 dialog_save_url(ses); 196 } 197 198 static void 199 menu_go_back(struct terminal *term, void *d, void *ses_) 200 { 201 struct session *ses = (struct session *)ses_; 202 go_back(ses, 1); 203 } 204 205 static void 206 menu_go_forward(struct terminal *term, void *d, void *ses_) 207 { 208 struct session *ses = (struct session *)ses_; 209 go_back(ses, -1); 210 } 211 212 static void 213 menu_reload(struct terminal *term, void *d, void *ses_) 214 { 215 struct session *ses = (struct session *)ses_; 216 reload(ses, -1); 217 } 218 219 void 220 really_exit_prog(void *ses_) 221 { 222 struct session *ses = (struct session *)ses_; 223 register_bottom_half(destroy_terminal, ses->term); 224 } 225 226 static void 227 dont_exit_prog(void *ses_) 228 { 229 struct session *ses = (struct session *)ses_; 230 ses->exit_query = 0; 231 } 232 233 void 234 query_exit(struct session *ses) 235 { 236 int only_one_term = 237 ses->term->list_entry.next == ses->term->list_entry.prev; 238 ses->exit_query = 1; 239 msg_box( 240 ses->term, NULL, TEXT_(T_EXIT_LINKS), AL_CENTER, 241 only_one_term && are_there_downloads() ? TEXT_( 242 T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS_AND_TERMINATE_ALL_DOWNLOADS) 243 : 1 || only_one_term ? TEXT_(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS) 244 : TEXT_(T_DO_YOU_REALLY_WANT_TO_CLOSE_WINDOW), 245 MSG_BOX_END, (void *)ses, 2, TEXT_(T_YES), really_exit_prog, 246 B_ENTER, TEXT_(T_NO), dont_exit_prog, B_ESC); 247 } 248 249 void 250 exit_prog(struct terminal *term, void *d, void *ses_) 251 { 252 struct session *ses = (struct session *)ses_; 253 int only_one_term; 254 if (!ses) { 255 register_bottom_half(destroy_terminal, term); 256 return; 257 } 258 only_one_term = 259 ses->term->list_entry.next == ses->term->list_entry.prev; 260 if (!ses->exit_query 261 && (!d || (only_one_term && are_there_downloads()))) { 262 query_exit(ses); 263 return; 264 } 265 really_exit_prog(ses); 266 } 267 268 struct refresh { 269 struct terminal *term; 270 struct window *win; 271 struct session *ses; 272 int (*fn)(struct terminal *term, struct refresh *r); 273 void *data; 274 struct timer *timer; 275 }; 276 277 static void 278 refresh(void *r_) 279 { 280 struct refresh *r = (struct refresh *)r_; 281 r->timer = NULL; 282 if (r->fn(r->term, r) > 0) 283 return; 284 delete_window(r->win); 285 } 286 287 static void 288 end_refresh(struct refresh *r) 289 { 290 if (r->timer != NULL) 291 kill_timer(r->timer); 292 free(r); 293 } 294 295 static void 296 refresh_abort(struct dialog_data *dlg) 297 { 298 end_refresh(dlg->dlg->udata2); 299 } 300 301 static int 302 resource_info(struct terminal *term, struct refresh *r2) 303 { 304 unsigned char *a; 305 int l; 306 struct refresh *r; 307 308 r = xmalloc(sizeof(struct refresh)); 309 r->term = term; 310 r->win = NULL; 311 r->fn = resource_info; 312 r->timer = NULL; 313 a = NULL; 314 315 l = add_to_str(&a, 0, get_text_translation(TEXT_(T_RESOURCES), term)); 316 l = add_to_str(&a, l, cast_uchar ": "); 317 add_unsigned_long_num_to_str(&a, &l, select_info(CI_FILES)); 318 l = add_chr_to_str(&a, l, ' '); 319 l = add_to_str(&a, l, get_text_translation(TEXT_(T_HANDLES), term)); 320 l = add_to_str(&a, l, cast_uchar ", "); 321 add_unsigned_long_num_to_str(&a, &l, select_info(CI_TIMERS)); 322 l = add_chr_to_str(&a, l, ' '); 323 l = add_to_str(&a, l, get_text_translation(TEXT_(T_TIMERS), term)); 324 l = add_to_str(&a, l, cast_uchar ".\n"); 325 326 l = add_to_str(&a, l, get_text_translation(TEXT_(T_CONNECTIONS), term)); 327 l = add_to_str(&a, l, cast_uchar ": "); 328 add_unsigned_long_num_to_str(&a, &l, 329 connect_info(CI_FILES) 330 - connect_info(CI_CONNECTING) 331 - connect_info(CI_TRANSFER)); 332 l = add_chr_to_str(&a, l, ' '); 333 l = add_to_str(&a, l, get_text_translation(TEXT_(T_WAITING), term)); 334 l = add_to_str(&a, l, cast_uchar ", "); 335 add_unsigned_long_num_to_str(&a, &l, connect_info(CI_CONNECTING)); 336 l = add_chr_to_str(&a, l, ' '); 337 l = add_to_str(&a, l, get_text_translation(TEXT_(T_CONNECTING), term)); 338 l = add_to_str(&a, l, cast_uchar ", "); 339 add_unsigned_long_num_to_str(&a, &l, connect_info(CI_TRANSFER)); 340 l = add_chr_to_str(&a, l, ' '); 341 l = add_to_str(&a, l, 342 get_text_translation(TEXT_(T_tRANSFERRING), term)); 343 l = add_to_str(&a, l, cast_uchar ", "); 344 add_unsigned_long_num_to_str(&a, &l, connect_info(CI_KEEP)); 345 l = add_chr_to_str(&a, l, ' '); 346 l = add_to_str(&a, l, get_text_translation(TEXT_(T_KEEPALIVE), term)); 347 l = add_to_str(&a, l, cast_uchar ".\n"); 348 349 l = add_to_str(&a, l, 350 get_text_translation(TEXT_(T_MEMORY_CACHE), term)); 351 l = add_to_str(&a, l, cast_uchar ": "); 352 add_unsigned_long_num_to_str(&a, &l, cache_info(CI_BYTES)); 353 l = add_chr_to_str(&a, l, ' '); 354 l = add_to_str(&a, l, get_text_translation(TEXT_(T_BYTES), term)); 355 l = add_to_str(&a, l, cast_uchar ", "); 356 add_unsigned_long_num_to_str(&a, &l, cache_info(CI_FILES)); 357 l = add_chr_to_str(&a, l, ' '); 358 l = add_to_str(&a, l, get_text_translation(TEXT_(T_FILES), term)); 359 l = add_to_str(&a, l, cast_uchar ", "); 360 add_unsigned_long_num_to_str(&a, &l, cache_info(CI_LOCKED)); 361 l = add_chr_to_str(&a, l, ' '); 362 l = add_to_str(&a, l, get_text_translation(TEXT_(T_LOCKED), term)); 363 l = add_to_str(&a, l, cast_uchar ", "); 364 add_unsigned_long_num_to_str(&a, &l, cache_info(CI_LOADING)); 365 l = add_chr_to_str(&a, l, ' '); 366 l = add_to_str(&a, l, get_text_translation(TEXT_(T_LOADING), term)); 367 l = add_to_str(&a, l, cast_uchar ".\n"); 368 369 l = add_to_str(&a, l, 370 get_text_translation(TEXT_(T_DECOMPRESSED_CACHE), term)); 371 l = add_to_str(&a, l, cast_uchar ": "); 372 add_unsigned_long_num_to_str(&a, &l, decompress_info(CI_BYTES)); 373 l = add_chr_to_str(&a, l, ' '); 374 l = add_to_str(&a, l, get_text_translation(TEXT_(T_BYTES), term)); 375 l = add_to_str(&a, l, cast_uchar ", "); 376 add_unsigned_long_num_to_str(&a, &l, decompress_info(CI_FILES)); 377 l = add_chr_to_str(&a, l, ' '); 378 l = add_to_str(&a, l, get_text_translation(TEXT_(T_FILES), term)); 379 l = add_to_str(&a, l, cast_uchar ", "); 380 add_unsigned_long_num_to_str(&a, &l, decompress_info(CI_LOCKED)); 381 l = add_chr_to_str(&a, l, ' '); 382 l = add_to_str(&a, l, get_text_translation(TEXT_(T_LOCKED), term)); 383 l = add_to_str(&a, l, cast_uchar ".\n"); 384 385 l = add_to_str( 386 &a, l, 387 get_text_translation(TEXT_(T_FORMATTED_DOCUMENT_CACHE), term)); 388 l = add_to_str(&a, l, cast_uchar ": "); 389 add_unsigned_long_num_to_str(&a, &l, formatted_info(CI_FILES)); 390 l = add_chr_to_str(&a, l, ' '); 391 l = add_to_str(&a, l, get_text_translation(TEXT_(T_DOCUMENTS), term)); 392 l = add_to_str(&a, l, cast_uchar ", "); 393 add_unsigned_long_num_to_str(&a, &l, formatted_info(CI_LOCKED)); 394 l = add_chr_to_str(&a, l, ' '); 395 l = add_to_str(&a, l, get_text_translation(TEXT_(T_LOCKED), term)); 396 l = add_to_str(&a, l, cast_uchar ".\n"); 397 398 l = add_to_str(&a, l, get_text_translation(TEXT_(T_DNS_CACHE), term)); 399 l = add_to_str(&a, l, cast_uchar ": "); 400 add_unsigned_long_num_to_str(&a, &l, dns_info(CI_FILES)); 401 l = add_chr_to_str(&a, l, ' '); 402 l = add_to_str(&a, l, get_text_translation(TEXT_(T_SERVERS), term)); 403 l = add_to_str(&a, l, cast_uchar ", "); 404 l = add_to_str(&a, l, 405 get_text_translation(TEXT_(T_TLS_SESSION_CACHE), term)); 406 l = add_to_str(&a, l, cast_uchar ": "); 407 add_unsigned_long_num_to_str(&a, &l, session_info(CI_FILES)); 408 l = add_chr_to_str(&a, l, ' '); 409 l = add_to_str(&a, l, get_text_translation(TEXT_(T_SERVERS), term)); 410 l = add_chr_to_str(&a, l, '.'); 411 412 if (r2 413 && !strcmp( 414 cast_const_char a, 415 cast_const_char 416 * (unsigned char **)((struct dialog_data *)r2->win->data) 417 ->dlg->udata)) { 418 free(a); 419 free(r); 420 r2->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r2); 421 return 1; 422 } 423 424 msg_box(term, getml(a, NULL), TEXT_(T_RESOURCES), AL_LEFT, a, 425 MSG_BOX_END, (void *)r, 1, TEXT_(T_OK), msg_box_null, 426 B_ENTER | B_ESC); 427 r->win = list_struct(term->windows.next, struct window); 428 ((struct dialog_data *)r->win->data)->dlg->abort = refresh_abort; 429 r->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r); 430 return 0; 431 } 432 433 static void 434 resource_info_menu(struct terminal *term, void *d, void *ses_) 435 { 436 resource_info(term, NULL); 437 } 438 439 static void 440 flush_caches(struct terminal *term, void *d, void *e) 441 { 442 abort_background_connections(); 443 shrink_memory(SH_FREE_ALL); 444 } 445 446 /* jde v historii na polozku id_ptr */ 447 void 448 go_backwards(struct terminal *term, void *id_ptr, void *ses_) 449 { 450 struct session *ses = (struct session *)ses_; 451 unsigned want_id = (unsigned)(long)id_ptr; 452 struct location *l = NULL; 453 struct list_head *ll; 454 int n = 0; 455 foreach (struct location, l, ll, ses->history) { 456 if (l->location_id == want_id) { 457 goto have_it; 458 } 459 n++; 460 } 461 n = -1; 462 foreach (struct location, l, ll, ses->forward_history) { 463 if (l->location_id == want_id) { 464 goto have_it; 465 } 466 n--; 467 } 468 return; 469 470 have_it: 471 go_back(ses, n); 472 } 473 474 static const struct menu_item no_hist_menu[] = { 475 {TEXT_(T_NO_HISTORY), cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 476 { NULL, NULL, 0, NULL, NULL, 0, 0} 477 }; 478 479 static void 480 add_history_menu_entry(struct terminal *term, struct menu_item **mi, int *n, 481 struct location *l) 482 { 483 unsigned char *url; 484 if (!*mi) 485 *mi = new_menu(MENU_FREE_ITEMS | MENU_FREE_TEXT); 486 url = display_url(term, l->url, 1); 487 add_to_menu(mi, url, cast_uchar "", cast_uchar "", go_backwards, 488 (void *)(long)l->location_id, 0, *n); 489 (*n)++; 490 if (*n == INT_MAX) 491 overalloc(); 492 } 493 494 static void 495 history_menu(struct terminal *term, void *ddd, void *ses_) 496 { 497 struct session *ses = (struct session *)ses_; 498 struct location *l = NULL; 499 struct list_head *ll; 500 struct menu_item *mi = NULL; 501 int n = 0; 502 int selected = 0; 503 foreachback (struct location, l, ll, ses->forward_history) { 504 add_history_menu_entry(term, &mi, &n, l); 505 } 506 selected = n; 507 foreach (struct location, l, ll, ses->history) { 508 add_history_menu_entry(term, &mi, &n, l); 509 } 510 if (!mi) 511 do_menu(term, (struct menu_item *)no_hist_menu, ses); 512 else 513 do_menu_selected(term, mi, ses, selected, NULL, NULL); 514 } 515 516 static const struct menu_item no_downloads_menu[] = { 517 {TEXT_(T_NO_DOWNLOADS), cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 518 { NULL, NULL, 0, NULL, NULL, 0, 0} 519 }; 520 521 static void 522 downloads_menu(struct terminal *term, void *ddd, void *ses_) 523 { 524 struct session *ses = (struct session *)ses_; 525 struct download *d = NULL; 526 struct list_head *ld; 527 struct menu_item *mi = NULL; 528 int n = 0; 529 foreachback (struct download, d, ld, downloads) { 530 unsigned char *f, *ff; 531 if (!mi) 532 mi = new_menu(MENU_FREE_ITEMS | MENU_FREE_TEXT 533 | MENU_FREE_RTEXT); 534 f = !d->prog ? d->orig_file : d->url; 535 for (ff = f; *ff; ff++) 536 if ((dir_sep(ff[0])) && ff[1]) 537 f = ff + 1; 538 if (!d->prog) 539 f = stracpy(f); 540 else 541 f = display_url(term, f, 1); 542 add_to_menu(&mi, f, download_percentage(d, 0), cast_uchar "", 543 display_download, d, 0, n); 544 n++; 545 } 546 if (!n) 547 do_menu(term, (struct menu_item *)no_downloads_menu, ses); 548 else 549 do_menu(term, mi, ses); 550 } 551 552 static void 553 menu_doc_info(struct terminal *term, void *ddd, void *ses_) 554 { 555 struct session *ses = (struct session *)ses_; 556 state_msg(ses); 557 } 558 559 static void 560 menu_head_info(struct terminal *term, void *ddd, void *ses_) 561 { 562 struct session *ses = (struct session *)ses_; 563 head_msg(ses); 564 } 565 566 static void 567 menu_toggle(struct terminal *term, void *ddd, void *ses_) 568 { 569 struct session *ses = (struct session *)ses_; 570 toggle(ses, ses->screen, 0); 571 } 572 573 static void 574 set_val(struct terminal *term, void *ip, void *d) 575 { 576 *(int *)d = (int)(long)ip; 577 } 578 579 static void 580 terminal_options_ok(void *p) 581 { 582 cls_redraw_all_terminals(); 583 } 584 585 static unsigned char *const td_labels[] = { TEXT_(T_NO_FRAMES), 586 TEXT_(T_VT_100_FRAMES), 587 TEXT_(T_USE_11M), 588 TEXT_( 589 T_RESTRICT_FRAMES_IN_CP850_852), 590 TEXT_(T_BLOCK_CURSOR), 591 TEXT_(T_COLOR), 592 NULL }; 593 594 static void 595 terminal_options(struct terminal *term, void *xxx, void *ses_) 596 { 597 struct dialog *d; 598 struct term_spec *ts = new_term_spec(term->term); 599 d = mem_calloc(sizeof(struct dialog) + 8 * sizeof(struct dialog_item)); 600 d->title = TEXT_(T_TERMINAL_OPTIONS); 601 d->fn = checkbox_list_fn; 602 d->udata = (void *)td_labels; 603 d->refresh = terminal_options_ok; 604 d->items[0].type = D_CHECKBOX; 605 d->items[0].gid = 1; 606 d->items[0].gnum = TERM_DUMB; 607 d->items[0].dlen = sizeof(int); 608 d->items[0].data = (void *)&ts->mode; 609 d->items[1].type = D_CHECKBOX; 610 d->items[1].gid = 1; 611 d->items[1].gnum = TERM_VT100; 612 d->items[1].dlen = sizeof(int); 613 d->items[1].data = (void *)&ts->mode; 614 d->items[2].type = D_CHECKBOX; 615 d->items[2].gid = 0; 616 d->items[2].dlen = sizeof(int); 617 d->items[2].data = (void *)&ts->m11_hack; 618 d->items[3].type = D_CHECKBOX; 619 d->items[3].gid = 0; 620 d->items[3].dlen = sizeof(int); 621 d->items[3].data = (void *)&ts->restrict_852; 622 d->items[4].type = D_CHECKBOX; 623 d->items[4].gid = 0; 624 d->items[4].dlen = sizeof(int); 625 d->items[4].data = (void *)&ts->block_cursor; 626 d->items[5].type = D_CHECKBOX; 627 d->items[5].gid = 0; 628 d->items[5].dlen = sizeof(int); 629 d->items[5].data = (void *)&ts->col; 630 d->items[6].type = D_BUTTON; 631 d->items[6].gid = B_ENTER; 632 d->items[6].fn = ok_dialog; 633 d->items[6].text = TEXT_(T_OK); 634 d->items[7].type = D_BUTTON; 635 d->items[7].gid = B_ESC; 636 d->items[7].fn = cancel_dialog; 637 d->items[7].text = TEXT_(T_CANCEL); 638 d->items[8].type = D_END; 639 do_dialog(term, d, getml(d, NULL)); 640 } 641 642 static void 643 refresh_network(void *xxx) 644 { 645 abort_background_connections(); 646 register_bottom_half(check_queue, NULL); 647 } 648 649 static unsigned char max_c_str[3]; 650 static unsigned char max_cth_str[3]; 651 static unsigned char max_t_str[3]; 652 static unsigned char time_str[5]; 653 static unsigned char unrtime_str[5]; 654 static unsigned char addrtime_str[4]; 655 656 static void 657 refresh_connections(void *xxx) 658 { 659 netcfg_stamp++; 660 max_connections = atoi(cast_const_char max_c_str); 661 max_connections_to_host = atoi(cast_const_char max_cth_str); 662 max_tries = atoi(cast_const_char max_t_str); 663 receive_timeout = atoi(cast_const_char time_str); 664 unrestartable_receive_timeout = atoi(cast_const_char unrtime_str); 665 timeout_multiple_addresses = atoi(cast_const_char addrtime_str); 666 refresh_network(xxx); 667 } 668 669 static unsigned char *net_msg[10]; 670 671 static void 672 dlg_net_options(struct terminal *term, void *xxx, void *yyy) 673 { 674 struct dialog *d; 675 int a; 676 snprint(max_c_str, 3, max_connections); 677 snprint(max_cth_str, 3, max_connections_to_host); 678 snprint(max_t_str, 3, max_tries); 679 snprint(time_str, 5, receive_timeout); 680 snprint(unrtime_str, 5, unrestartable_receive_timeout); 681 snprint(addrtime_str, 4, timeout_multiple_addresses); 682 d = mem_calloc(sizeof(struct dialog) + 12 * sizeof(struct dialog_item)); 683 d->title = TEXT_(T_NETWORK_OPTIONS); 684 d->fn = group_fn; 685 d->udata = (void *)net_msg; 686 d->refresh = refresh_connections; 687 a = 0; 688 net_msg[a] = TEXT_(T_MAX_CONNECTIONS); 689 d->items[a].type = D_FIELD; 690 d->items[a].data = max_c_str; 691 d->items[a].dlen = 3; 692 d->items[a].fn = check_number; 693 d->items[a].gid = 1; 694 d->items[a++].gnum = 99; 695 net_msg[a] = TEXT_(T_MAX_CONNECTIONS_TO_ONE_HOST); 696 d->items[a].type = D_FIELD; 697 d->items[a].data = max_cth_str; 698 d->items[a].dlen = 3; 699 d->items[a].fn = check_number; 700 d->items[a].gid = 1; 701 d->items[a++].gnum = 99; 702 net_msg[a] = TEXT_(T_RETRIES); 703 d->items[a].type = D_FIELD; 704 d->items[a].data = max_t_str; 705 d->items[a].dlen = 3; 706 d->items[a].fn = check_number; 707 d->items[a].gid = 0; 708 d->items[a++].gnum = 16; 709 net_msg[a] = TEXT_(T_RECEIVE_TIMEOUT_SEC); 710 d->items[a].type = D_FIELD; 711 d->items[a].data = time_str; 712 d->items[a].dlen = 5; 713 d->items[a].fn = check_number; 714 d->items[a].gid = 1; 715 d->items[a++].gnum = 9999; 716 net_msg[a] = TEXT_(T_TIMEOUT_WHEN_UNRESTARTABLE); 717 d->items[a].type = D_FIELD; 718 d->items[a].data = unrtime_str; 719 d->items[a].dlen = 5; 720 d->items[a].fn = check_number; 721 d->items[a].gid = 1; 722 d->items[a++].gnum = 9999; 723 net_msg[a] = TEXT_(T_TIMEOUT_WHEN_TRYING_MULTIPLE_ADDRESSES); 724 d->items[a].type = D_FIELD; 725 d->items[a].data = addrtime_str; 726 d->items[a].dlen = 4; 727 d->items[a].fn = check_number; 728 d->items[a].gid = 1; 729 d->items[a++].gnum = 999; 730 net_msg[a] = TEXT_(T_BIND_TO_LOCAL_IP_ADDRESS); 731 d->items[a].type = D_FIELD; 732 d->items[a].data = bind_ip_address; 733 d->items[a].dlen = sizeof(bind_ip_address); 734 d->items[a++].fn = check_local_ip_address; 735 if (support_ipv6) { 736 net_msg[a] = TEXT_(T_BIND_TO_LOCAL_IPV6_ADDRESS); 737 d->items[a].type = D_FIELD; 738 d->items[a].data = bind_ipv6_address; 739 d->items[a].dlen = sizeof(bind_ipv6_address); 740 d->items[a++].fn = check_local_ipv6_address; 741 } 742 net_msg[a] = TEXT_(T_SET_TIME_OF_DOWNLOADED_FILES); 743 d->items[a].type = D_CHECKBOX; 744 d->items[a].data = (unsigned char *)&download_utime; 745 d->items[a++].dlen = sizeof(int); 746 d->items[a].type = D_BUTTON; 747 d->items[a].gid = B_ENTER; 748 d->items[a].fn = ok_dialog; 749 d->items[a++].text = TEXT_(T_OK); 750 d->items[a].type = D_BUTTON; 751 d->items[a].gid = B_ESC; 752 d->items[a].fn = cancel_dialog; 753 d->items[a++].text = TEXT_(T_CANCEL); 754 d->items[a].type = D_END; 755 do_dialog(term, d, getml(d, NULL)); 756 } 757 758 static unsigned char *const ipv6_labels[] = { 759 TEXT_(T_IPV6_DEFAULT), TEXT_(T_IPV6_PREFER_IPV4), 760 TEXT_(T_IPV6_PREFER_IPV6), TEXT_(T_IPV6_USE_ONLY_IPV4), 761 TEXT_(T_IPV6_USE_ONLY_IPV6), NULL 762 }; 763 764 static void 765 dlg_ipv6_options(struct terminal *term, void *xxx, void *yyy) 766 { 767 struct dialog *d; 768 d = mem_calloc(sizeof(struct dialog) + 7 * sizeof(struct dialog_item)); 769 d->title = TEXT_(T_IPV6_OPTIONS); 770 d->fn = checkbox_list_fn; 771 d->udata = (void *)ipv6_labels; 772 d->refresh = refresh_network; 773 d->items[0].type = D_CHECKBOX; 774 d->items[0].gid = 1; 775 d->items[0].gnum = ADDR_PREFERENCE_DEFAULT; 776 d->items[0].dlen = sizeof(int); 777 d->items[0].data = (void *)&ipv6_options.addr_preference; 778 d->items[1].type = D_CHECKBOX; 779 d->items[1].gid = 1; 780 d->items[1].gnum = ADDR_PREFERENCE_IPV4; 781 d->items[1].dlen = sizeof(int); 782 d->items[1].data = (void *)&ipv6_options.addr_preference; 783 d->items[2].type = D_CHECKBOX; 784 d->items[2].gid = 1; 785 d->items[2].gnum = ADDR_PREFERENCE_IPV6; 786 d->items[2].dlen = sizeof(int); 787 d->items[2].data = (void *)&ipv6_options.addr_preference; 788 d->items[3].type = D_CHECKBOX; 789 d->items[3].gid = 1; 790 d->items[3].gnum = ADDR_PREFERENCE_IPV4_ONLY; 791 d->items[3].dlen = sizeof(int); 792 d->items[3].data = (void *)&ipv6_options.addr_preference; 793 d->items[4].type = D_CHECKBOX; 794 d->items[4].gid = 1; 795 d->items[4].gnum = ADDR_PREFERENCE_IPV6_ONLY; 796 d->items[4].dlen = sizeof(int); 797 d->items[4].data = (void *)&ipv6_options.addr_preference; 798 d->items[5].type = D_BUTTON; 799 d->items[5].gid = B_ENTER; 800 d->items[5].fn = ok_dialog; 801 d->items[5].text = TEXT_(T_OK); 802 d->items[6].type = D_BUTTON; 803 d->items[6].gid = B_ESC; 804 d->items[6].fn = cancel_dialog; 805 d->items[6].text = TEXT_(T_CANCEL); 806 d->items[7].type = D_END; 807 do_dialog(term, d, getml(d, NULL)); 808 } 809 810 #define N_N 6 811 812 static unsigned char *const proxy_msg[] = { 813 TEXT_(T_HTTP_PROXY__HOST_PORT), 814 TEXT_(T_HTTPS_PROXY__HOST_PORT), 815 TEXT_(T_SOCKS_4A_PROXY__USER_HOST_PORT), 816 TEXT_(T_APPEND_TEXT_TO_SOCKS_LOOKUPS), 817 TEXT_(T_NOPROXY_LIST), 818 TEXT_(T_ONLY_PROXIES), 819 }; 820 821 static void 822 proxy_fn(struct dialog_data *dlg) 823 { 824 struct terminal *term = dlg->win->term; 825 int max = 0, min = 0; 826 int w, rw; 827 int i; 828 int y = -1; 829 for (i = 0; i < N_N; i++) { 830 max_text_width(term, proxy_msg[i], &max, AL_LEFT); 831 min_text_width(term, proxy_msg[i], &min, AL_LEFT); 832 } 833 max_group_width(term, proxy_msg + N_N, dlg->items + N_N, 834 dlg->n - 2 - N_N, &max); 835 min_group_width(term, proxy_msg + N_N, dlg->items + N_N, 836 dlg->n - 2 - N_N, &min); 837 max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max); 838 min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min); 839 w = dlg->win->term->x * 9 / 10 - 2 * DIALOG_LB; 840 if (w > max) 841 w = max; 842 if (w < min) 843 w = min; 844 if (w > dlg->win->term->x - 2 * DIALOG_LB) 845 w = dlg->win->term->x - 2 * DIALOG_LB; 846 if (w < 1) 847 w = 1; 848 rw = 0; 849 for (i = 0; i < N_N; i++) { 850 dlg_format_text_and_field(dlg, NULL, proxy_msg[i], 851 &dlg->items[i], 0, &y, w, &rw, 852 COLOR_DIALOG_TEXT, AL_LEFT); 853 y++; 854 } 855 dlg_format_group(dlg, NULL, proxy_msg + N_N, dlg->items + N_N, 856 dlg->n - 2 - N_N, 0, &y, w, &rw); 857 y++; 858 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, 859 AL_CENTER); 860 w = rw; 861 dlg->xw = w + 2 * DIALOG_LB; 862 dlg->yw = y + 2 * DIALOG_TB; 863 center_dlg(dlg); 864 draw_dlg(dlg); 865 y = dlg->y + DIALOG_TB; 866 for (i = 0; i < N_N; i++) { 867 dlg_format_text_and_field( 868 dlg, term, proxy_msg[i], &dlg->items[i], dlg->x + DIALOG_LB, 869 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 870 y++; 871 } 872 dlg_format_group(dlg, term, proxy_msg + N_N, &dlg->items[N_N], 873 dlg->n - 2 - N_N, dlg->x + DIALOG_LB, &y, w, NULL); 874 y++; 875 dlg_format_buttons(dlg, term, &dlg->items[dlg->n - 2], 2, 876 dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER); 877 } 878 879 void 880 reset_settings_for_tor(void) 881 { 882 max_connections = 10; 883 max_connections_to_host = 8; 884 max_tries = 3; 885 receive_timeout = 120; 886 unrestartable_receive_timeout = 600; 887 888 max_format_cache_entries = 5; 889 memory_cache_size = 4194304; 890 image_cache_size = 1048576; 891 font_cache_size = 2097152; 892 aggressive_cache = 1; 893 894 http_options.http10 = 0; 895 http_options.allow_blacklist = 1; 896 http_options.no_accept_charset = 0; 897 http_options.no_compression = 0; 898 http_options.retry_internal_errors = 0; 899 http_options.header.extra_header[0] = 0; 900 901 dither_letters = 1; 902 dither_images = 1; 903 904 dds.tables = 1; 905 dds.frames = 1; 906 dds.auto_refresh = 0; 907 dds.display_images = 1; 908 } 909 910 static void 911 data_cleanup(void) 912 { 913 struct session *ses = NULL; 914 struct list_head *lses; 915 reset_settings_for_tor(); 916 foreach (struct session, ses, lses, sessions) { 917 ses->ds.tables = dds.tables; 918 ses->ds.frames = dds.frames; 919 ses->ds.auto_refresh = dds.auto_refresh; 920 ses->ds.display_images = dds.display_images; 921 cleanup_session(ses); 922 draw_formatted(ses); 923 } 924 free_blacklist(); 925 free_cookies(); 926 free_auth(); 927 abort_all_connections(); 928 shrink_memory(SH_FREE_ALL); 929 } 930 931 static unsigned char http_proxy[MAX_STR_LEN]; 932 static unsigned char https_proxy[MAX_STR_LEN]; 933 static unsigned char socks_proxy[MAX_STR_LEN]; 934 static unsigned char no_proxy[MAX_STR_LEN]; 935 936 static void 937 display_proxy(struct terminal *term, unsigned char *result, 938 unsigned char *proxy) 939 { 940 unsigned char *url, *res; 941 int sl; 942 943 if (!proxy[0]) { 944 result[0] = 0; 945 return; 946 } 947 948 url = stracpy(cast_uchar "proxy://"); 949 add_to_strn(&url, proxy); 950 add_to_strn(&url, cast_uchar "/"); 951 952 res = display_url(term, url, 0); 953 954 sl = (int)strlen(cast_const_char res); 955 if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8) 956 || res[sl - 1] != '/') { 957 result[0] = 0; 958 } else { 959 res[sl - 1] = 0; 960 safe_strncpy(result, res + 8, MAX_STR_LEN); 961 } 962 963 free(url); 964 free(res); 965 } 966 967 static void 968 display_noproxy_list(struct terminal *term, unsigned char *result, 969 unsigned char *noproxy_list) 970 { 971 unsigned char *res; 972 res = display_host_list(term, noproxy_list); 973 if (!res) { 974 result[0] = 0; 975 } else 976 safe_strncpy(result, res, MAX_STR_LEN); 977 free(res); 978 } 979 980 int 981 save_proxy(int charset, unsigned char *result, unsigned char *proxy) 982 { 983 unsigned char *url, *res; 984 int sl; 985 int retval; 986 987 if (!proxy[0]) { 988 result[0] = 0; 989 return 0; 990 } 991 992 proxy = stracpy(proxy); 993 994 url = stracpy(cast_uchar "proxy://"); 995 add_to_strn(&url, proxy); 996 add_to_strn(&url, cast_uchar "/"); 997 998 free(proxy); 999 1000 if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1001 NULL, NULL, NULL)) { 1002 free(url); 1003 result[0] = 0; 1004 return -1; 1005 } 1006 1007 res = idn_encode_url(url, 0); 1008 1009 free(url); 1010 1011 if (!res) { 1012 result[0] = 0; 1013 return -1; 1014 } 1015 sl = (int)strlen(cast_const_char res); 1016 if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8) 1017 || res[sl - 1] != '/') { 1018 result[0] = 0; 1019 retval = -1; 1020 } else { 1021 res[sl - 1] = 0; 1022 safe_strncpy(result, res + 8, MAX_STR_LEN); 1023 retval = 1024 strlen(cast_const_char(res + 8)) >= MAX_STR_LEN ? -1 : 0; 1025 } 1026 1027 free(res); 1028 1029 return retval; 1030 } 1031 1032 int 1033 save_noproxy_list(int charset, unsigned char *result, 1034 unsigned char *noproxy_list) 1035 { 1036 unsigned char *res; 1037 1038 noproxy_list = stracpy(noproxy_list); 1039 res = idn_encode_host(noproxy_list, 1040 (int)strlen(cast_const_char noproxy_list), 1041 cast_uchar ".,", 0); 1042 free(noproxy_list); 1043 if (!res) { 1044 result[0] = 0; 1045 return -1; 1046 } else { 1047 safe_strncpy(result, res, MAX_STR_LEN); 1048 retval = strlen(cast_const_char res) >= MAX_STR_LEN ? -1 : 0; 1049 } 1050 free(res); 1051 return retval; 1052 } 1053 1054 static int 1055 check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data *di, 1056 int (*save)(int, unsigned char *, unsigned char *)) 1057 { 1058 unsigned char *result = xmalloc(MAX_STR_LEN); 1059 if (save(0, result, di->cdata)) { 1060 free(result); 1061 msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER, 1062 TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1, 1063 TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC); 1064 return 1; 1065 } 1066 free(result); 1067 return 0; 1068 } 1069 1070 static int 1071 check_proxy(struct dialog_data *dlg, struct dialog_item_data *di) 1072 { 1073 return check_proxy_noproxy(dlg, di, save_proxy); 1074 } 1075 1076 static int 1077 check_noproxy_list(struct dialog_data *dlg, struct dialog_item_data *di) 1078 { 1079 return check_proxy_noproxy(dlg, di, save_noproxy_list); 1080 } 1081 1082 static int 1083 proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di) 1084 { 1085 struct terminal *term = dlg->win->term; 1086 int op = proxies.only_proxies; 1087 int r = ok_dialog(dlg, di); 1088 if (r) 1089 return r; 1090 save_proxy(0, proxies.http_proxy, http_proxy); 1091 save_proxy(0, proxies.https_proxy, https_proxy); 1092 save_proxy(0, proxies.socks_proxy, socks_proxy); 1093 save_noproxy_list(0, proxies.no_proxy, no_proxy); 1094 1095 if (!proxies.only_proxies) { 1096 /* parsing duplicated in make_connection */ 1097 long lp; 1098 char *end; 1099 unsigned char *p = 1100 cast_uchar strchr(cast_const_char proxies.socks_proxy, '@'); 1101 if (!p) 1102 p = proxies.socks_proxy; 1103 else 1104 p++; 1105 p = cast_uchar strchr(cast_const_char p, ':'); 1106 if (p) { 1107 p++; 1108 lp = strtol(cast_const_char p, &end, 10); 1109 if (!*end && lp == 9050) { 1110 proxies.only_proxies = 1; 1111 msg_box(term, NULL, TEXT_(T_PROXIES), AL_LEFT, 1112 TEXT_(T_TOR_MODE_ENABLED), MSG_BOX_END, 1113 NULL, 1, TEXT_(T_OK), msg_box_null, 1114 B_ENTER | B_ESC); 1115 } 1116 } 1117 } 1118 1119 if (op != proxies.only_proxies) { 1120 data_cleanup(); 1121 } 1122 refresh_network(NULL); 1123 return 0; 1124 } 1125 1126 static void 1127 dlg_proxy_options(struct terminal *term, void *xxx, void *yyy) 1128 { 1129 struct dialog *d; 1130 int a = 0; 1131 display_proxy(term, http_proxy, proxies.http_proxy); 1132 display_proxy(term, https_proxy, proxies.https_proxy); 1133 display_proxy(term, socks_proxy, proxies.socks_proxy); 1134 display_noproxy_list(term, no_proxy, proxies.no_proxy); 1135 d = mem_calloc(sizeof(struct dialog) 1136 + (N_N + 2) * sizeof(struct dialog_item)); 1137 d->title = TEXT_(T_PROXIES); 1138 d->fn = proxy_fn; 1139 d->items[a].type = D_FIELD; 1140 d->items[a].dlen = MAX_STR_LEN; 1141 d->items[a].data = http_proxy; 1142 d->items[a].fn = check_proxy; 1143 a++; 1144 d->items[a].type = D_FIELD; 1145 d->items[a].dlen = MAX_STR_LEN; 1146 d->items[a].data = https_proxy; 1147 d->items[a].fn = check_proxy; 1148 a++; 1149 d->items[a].type = D_FIELD; 1150 d->items[a].dlen = MAX_STR_LEN; 1151 d->items[a].data = socks_proxy; 1152 d->items[a].fn = check_proxy; 1153 a++; 1154 d->items[a].type = D_FIELD; 1155 d->items[a].dlen = MAX_STR_LEN; 1156 d->items[a].data = proxies.dns_append; 1157 a++; 1158 d->items[a].type = D_FIELD; 1159 d->items[a].dlen = MAX_STR_LEN; 1160 d->items[a].data = no_proxy; 1161 d->items[a].fn = check_noproxy_list; 1162 a++; 1163 d->items[a].type = D_CHECKBOX; 1164 d->items[a].data = (unsigned char *)&proxies.only_proxies; 1165 d->items[a].dlen = sizeof(int); 1166 a++; 1167 d->items[a].type = D_BUTTON; 1168 d->items[a].gid = B_ENTER; 1169 d->items[a].fn = proxy_ok_dialog; 1170 d->items[a].text = TEXT_(T_OK); 1171 a++; 1172 d->items[a].type = D_BUTTON; 1173 d->items[a].gid = B_ESC; 1174 d->items[a].fn = cancel_dialog; 1175 d->items[a].text = TEXT_(T_CANCEL); 1176 a++; 1177 d->items[a].type = D_END; 1178 do_dialog(term, d, getml(d, NULL)); 1179 } 1180 1181 #undef N_N 1182 1183 static int 1184 check_file(struct dialog_data *dlg, struct dialog_item_data *di, int type) 1185 { 1186 unsigned char *p = di->cdata; 1187 int r; 1188 struct stat st; 1189 links_ssl *ssl; 1190 if (!p[0]) 1191 return 0; 1192 EINTRLOOP(r, stat(cast_const_char p, &st)); 1193 if (r || !S_ISREG(st.st_mode)) { 1194 msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER, 1195 TEXT_(T_THE_FILE_DOES_NOT_EXIST), MSG_BOX_END, NULL, 1, 1196 TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC); 1197 return 1; 1198 } 1199 ssl = getSSL(); 1200 if (!ssl) 1201 return 0; 1202 #if !defined(OPENSSL_NO_STDIO) 1203 if (!type) { 1204 r = SSL_use_PrivateKey_file(ssl->ssl, cast_const_char p, 1205 SSL_FILETYPE_PEM); 1206 r = r != 1; 1207 } else { 1208 r = SSL_use_certificate_file(ssl->ssl, cast_const_char p, 1209 SSL_FILETYPE_PEM); 1210 r = r != 1; 1211 } 1212 #else 1213 r = 0; 1214 #endif 1215 if (r) 1216 msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER, 1217 TEXT_(T_THE_FILE_HAS_INVALID_FORMAT), MSG_BOX_END, NULL, 1218 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC); 1219 freeSSL(ssl); 1220 return r; 1221 } 1222 1223 static int 1224 check_file_key(struct dialog_data *dlg, struct dialog_item_data *di) 1225 { 1226 return check_file(dlg, di, 0); 1227 } 1228 1229 static int 1230 check_file_crt(struct dialog_data *dlg, struct dialog_item_data *di) 1231 { 1232 return check_file(dlg, di, 1); 1233 } 1234 1235 static unsigned char *const ssl_labels[] = { 1236 TEXT_(T_ACCEPT_INVALID_CERTIFICATES), 1237 TEXT_(T_WARN_ON_INVALID_CERTIFICATES), 1238 TEXT_(T_REJECT_INVALID_CERTIFICATES), 1239 TEXT_(T_CLIENT_CERTIFICATE_KEY_FILE), 1240 TEXT_(T_CLIENT_CERTIFICATE_FILE), 1241 TEXT_(T_CLIENT_CERTIFICATE_KEY_PASSWORD), 1242 NULL 1243 }; 1244 1245 static void 1246 ssl_options_fn(struct dialog_data *dlg) 1247 { 1248 struct terminal *term = dlg->win->term; 1249 int max = 0, min = 0; 1250 int w, rw; 1251 int y = 0; 1252 checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &max, 1253 max_text_width); 1254 checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &min, 1255 min_text_width); 1256 max_text_width(term, ssl_labels[dlg->n - 4], &max, AL_LEFT); 1257 min_text_width(term, ssl_labels[dlg->n - 4], &min, AL_LEFT); 1258 max_text_width(term, ssl_labels[dlg->n - 3], &max, AL_LEFT); 1259 min_text_width(term, ssl_labels[dlg->n - 3], &min, AL_LEFT); 1260 max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max); 1261 min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min); 1262 w = term->x * 9 / 10 - 2 * DIALOG_LB; 1263 if (w > max) 1264 w = max; 1265 if (w < min) 1266 w = min; 1267 if (w > term->x - 2 * DIALOG_LB) 1268 w = term->x - 2 * DIALOG_LB; 1269 if (w < 5) 1270 w = 5; 1271 rw = 0; 1272 dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw, 1273 dlg->dlg->udata); 1274 y++; 1275 dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 5], 1276 dlg->items + dlg->n - 5, 0, &y, w, &rw, 1277 COLOR_DIALOG_TEXT, AL_LEFT); 1278 y++; 1279 dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 4], 1280 dlg->items + dlg->n - 4, 0, &y, w, &rw, 1281 COLOR_DIALOG_TEXT, AL_LEFT); 1282 y++; 1283 dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 3], 1284 dlg->items + dlg->n - 3, 0, &y, w, &rw, 1285 COLOR_DIALOG_TEXT, AL_LEFT); 1286 y++; 1287 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, 1288 AL_CENTER); 1289 w = rw; 1290 dlg->xw = rw + 2 * DIALOG_LB; 1291 dlg->yw = y + 2 * DIALOG_TB; 1292 center_dlg(dlg); 1293 draw_dlg(dlg); 1294 y = dlg->y + DIALOG_TB + 1; 1295 dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5, 1296 dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata); 1297 y++; 1298 dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 5], 1299 dlg->items + dlg->n - 5, dlg->x + DIALOG_LB, 1300 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1301 y++; 1302 dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 4], 1303 dlg->items + dlg->n - 4, dlg->x + DIALOG_LB, 1304 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1305 y++; 1306 dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 3], 1307 dlg->items + dlg->n - 3, dlg->x + DIALOG_LB, 1308 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1309 y++; 1310 dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, 1311 dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER); 1312 } 1313 1314 static void 1315 dlg_ssl_options(struct terminal *term, void *xxx, void *yyy) 1316 { 1317 struct dialog *d; 1318 int a = 0; 1319 const int items = 8; 1320 d = mem_calloc(sizeof(struct dialog) 1321 + items * sizeof(struct dialog_item)); 1322 d->title = TEXT_(T_SSL_OPTIONS); 1323 d->fn = ssl_options_fn; 1324 d->udata = (void *)ssl_labels; 1325 d->refresh = refresh_network; 1326 d->items[a].type = D_CHECKBOX; 1327 d->items[a].gid = 1; 1328 d->items[a].gnum = SSL_ACCEPT_INVALID_CERTIFICATE; 1329 d->items[a].dlen = sizeof(int); 1330 d->items[a].data = (void *)&ssl_options.certificates; 1331 a++; 1332 d->items[a].type = D_CHECKBOX; 1333 d->items[a].gid = 1; 1334 d->items[a].gnum = SSL_WARN_ON_INVALID_CERTIFICATE; 1335 d->items[a].dlen = sizeof(int); 1336 d->items[a].data = (void *)&ssl_options.certificates; 1337 a++; 1338 d->items[a].type = D_CHECKBOX; 1339 d->items[a].gid = 1; 1340 d->items[a].gnum = SSL_REJECT_INVALID_CERTIFICATE; 1341 d->items[a].dlen = sizeof(int); 1342 d->items[a].data = (void *)&ssl_options.certificates; 1343 a++; 1344 d->items[a].type = D_FIELD; 1345 d->items[a].dlen = MAX_STR_LEN; 1346 d->items[a].data = ssl_options.client_cert_key; 1347 d->items[a].fn = check_file_key; 1348 a++; 1349 d->items[a].type = D_FIELD; 1350 d->items[a].dlen = MAX_STR_LEN; 1351 d->items[a].data = ssl_options.client_cert_crt; 1352 d->items[a].fn = check_file_crt; 1353 a++; 1354 d->items[a].type = D_FIELD_PASS; 1355 d->items[a].dlen = MAX_STR_LEN; 1356 d->items[a].data = ssl_options.client_cert_password; 1357 a++; 1358 d->items[a].type = D_BUTTON; 1359 d->items[a].gid = B_ENTER; 1360 d->items[a].fn = ok_dialog; 1361 d->items[a].text = TEXT_(T_OK); 1362 a++; 1363 d->items[a].type = D_BUTTON; 1364 d->items[a].gid = B_ESC; 1365 d->items[a].fn = cancel_dialog; 1366 d->items[a].text = TEXT_(T_CANCEL); 1367 a++; 1368 d->items[a].type = D_END; 1369 do_dialog(term, d, getml(d, NULL)); 1370 } 1371 1372 static unsigned char *const http_labels[] = { 1373 TEXT_(T_USE_HTTP_10), 1374 TEXT_(T_ALLOW_SERVER_BLACKLIST), 1375 TEXT_(T_DO_NOT_SEND_ACCEPT_CHARSET), 1376 TEXT_(T_DO_NOT_ADVERTISE_COMPRESSION_SUPPORT), 1377 TEXT_(T_RETRY_ON_INTERNAL_ERRORS), 1378 NULL 1379 }; 1380 1381 static unsigned char *const http_header_labels[] = { TEXT_(T_FAKE_FIREFOX), 1382 TEXT_(T_FAKE_USERAGENT), 1383 TEXT_(T_EXTRA_HEADER), 1384 NULL }; 1385 1386 static void 1387 httpheadopt_fn(struct dialog_data *dlg) 1388 { 1389 struct terminal *term = dlg->win->term; 1390 int max = 0, min = 0; 1391 int w, rw; 1392 int y = 0; 1393 checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &max, 1394 max_text_width); 1395 checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &min, 1396 min_text_width); 1397 max_text_width(term, http_header_labels[dlg->n - 5], &max, AL_LEFT); 1398 min_text_width(term, http_header_labels[dlg->n - 5], &min, AL_LEFT); 1399 max_text_width(term, http_header_labels[dlg->n - 4], &max, AL_LEFT); 1400 min_text_width(term, http_header_labels[dlg->n - 4], &min, AL_LEFT); 1401 max_text_width(term, http_header_labels[dlg->n - 3], &max, AL_LEFT); 1402 min_text_width(term, http_header_labels[dlg->n - 3], &min, AL_LEFT); 1403 max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max); 1404 min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min); 1405 w = term->x * 9 / 10 - 2 * DIALOG_LB; 1406 if (w > max) 1407 w = max; 1408 if (w < min) 1409 w = min; 1410 if (w > term->x - 2 * DIALOG_LB) 1411 w = term->x - 2 * DIALOG_LB; 1412 if (w < 5) 1413 w = 5; 1414 rw = 0; 1415 dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw, 1416 dlg->dlg->udata); 1417 y++; 1418 dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 5], 1419 dlg->items + dlg->n - 5, 0, &y, w, &rw, 1420 COLOR_DIALOG_TEXT, AL_LEFT); 1421 y++; 1422 dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 4], 1423 dlg->items + dlg->n - 4, 0, &y, w, &rw, 1424 COLOR_DIALOG_TEXT, AL_LEFT); 1425 y++; 1426 dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 3], 1427 dlg->items + dlg->n - 3, 0, &y, w, &rw, 1428 COLOR_DIALOG_TEXT, AL_LEFT); 1429 y++; 1430 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, 1431 AL_CENTER); 1432 w = rw; 1433 dlg->xw = rw + 2 * DIALOG_LB; 1434 dlg->yw = y + 2 * DIALOG_TB; 1435 center_dlg(dlg); 1436 draw_dlg(dlg); 1437 y = dlg->y + DIALOG_TB + 1; 1438 dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5, 1439 dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata); 1440 y++; 1441 dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 5], 1442 dlg->items + dlg->n - 5, dlg->x + DIALOG_LB, 1443 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1444 y++; 1445 dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 4], 1446 dlg->items + dlg->n - 4, dlg->x + DIALOG_LB, 1447 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1448 y++; 1449 dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 3], 1450 dlg->items + dlg->n - 3, dlg->x + DIALOG_LB, 1451 &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); 1452 y++; 1453 dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, 1454 dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER); 1455 } 1456 1457 static int 1458 dlg_http_header_options(struct dialog_data *dlg, struct dialog_item_data *di) 1459 { 1460 struct http_header_options *header = 1461 (struct http_header_options *)di->cdata; 1462 struct dialog *d; 1463 d = mem_calloc(sizeof(struct dialog) + 12 * sizeof(struct dialog_item)); 1464 d->title = TEXT_(T_HTTP_HEADER_OPTIONS); 1465 d->fn = httpheadopt_fn; 1466 d->udata = (void *)http_header_labels; 1467 d->items[0].type = D_CHECKBOX; 1468 d->items[0].gid = 0; 1469 d->items[0].dlen = sizeof(int); 1470 d->items[0].data = (void *)&header->fake_firefox; 1471 d->items[1].type = D_FIELD; 1472 d->items[1].dlen = MAX_STR_LEN; 1473 d->items[1].data = header->fake_useragent; 1474 d->items[2].type = D_FIELD; 1475 d->items[2].dlen = MAX_STR_LEN; 1476 d->items[2].data = header->extra_header; 1477 d->items[3].type = D_BUTTON; 1478 d->items[3].gid = B_ENTER; 1479 d->items[3].fn = ok_dialog; 1480 d->items[3].text = TEXT_(T_OK); 1481 d->items[4].type = D_BUTTON; 1482 d->items[4].gid = B_ESC; 1483 d->items[4].fn = cancel_dialog; 1484 d->items[4].text = TEXT_(T_CANCEL); 1485 d->items[5].type = D_END; 1486 do_dialog(dlg->win->term, d, getml(d, NULL)); 1487 return 0; 1488 } 1489 1490 static void 1491 dlg_http_options(struct terminal *term, void *xxx, void *yyy) 1492 { 1493 struct dialog *d; 1494 int a = 0; 1495 d = mem_calloc(sizeof(struct dialog) + 8 * sizeof(struct dialog_item)); 1496 d->title = TEXT_(T_HTTP_BUG_WORKAROUNDS); 1497 d->fn = checkbox_list_fn; 1498 d->udata = (void *)http_labels; 1499 d->refresh = refresh_network; 1500 d->items[a].type = D_CHECKBOX; 1501 d->items[a].gid = 0; 1502 d->items[a].dlen = sizeof(int); 1503 d->items[a].data = (void *)&http_options.http10; 1504 a++; 1505 d->items[a].type = D_CHECKBOX; 1506 d->items[a].gid = 0; 1507 d->items[a].dlen = sizeof(int); 1508 d->items[a].data = (void *)&http_options.allow_blacklist; 1509 a++; 1510 d->items[a].type = D_CHECKBOX; 1511 d->items[a].gid = 0; 1512 d->items[a].dlen = sizeof(int); 1513 d->items[a].data = (void *)&http_options.no_accept_charset; 1514 a++; 1515 d->items[a].type = D_CHECKBOX; 1516 d->items[a].gid = 0; 1517 d->items[a].dlen = sizeof(int); 1518 d->items[a].data = (void *)&http_options.no_compression; 1519 a++; 1520 d->items[a].type = D_CHECKBOX; 1521 d->items[a].gid = 0; 1522 d->items[a].dlen = sizeof(int); 1523 d->items[a].data = (void *)&http_options.retry_internal_errors; 1524 a++; 1525 d->items[a].type = D_BUTTON; 1526 d->items[a].gid = 0; 1527 d->items[a].fn = dlg_http_header_options; 1528 d->items[a].text = TEXT_(T_HEADER_OPTIONS); 1529 d->items[a].data = (void *)&http_options.header; 1530 d->items[a].dlen = sizeof(struct http_header_options); 1531 a++; 1532 d->items[a].type = D_BUTTON; 1533 d->items[a].gid = B_ENTER; 1534 d->items[a].fn = ok_dialog; 1535 d->items[a].text = TEXT_(T_OK); 1536 a++; 1537 d->items[a].type = D_BUTTON; 1538 d->items[a].gid = B_ESC; 1539 d->items[a].fn = cancel_dialog; 1540 d->items[a].text = TEXT_(T_CANCEL); 1541 a++; 1542 d->items[a].type = D_END; 1543 a++; 1544 do_dialog(term, d, getml(d, NULL)); 1545 } 1546 1547 static unsigned char mc_str[8]; 1548 static unsigned char doc_str[4]; 1549 1550 static void 1551 cache_refresh(void *xxx) 1552 { 1553 memory_cache_size = atoi(cast_const_char mc_str) * 1024; 1554 max_format_cache_entries = atoi(cast_const_char doc_str); 1555 shrink_memory(SH_CHECK_QUOTA); 1556 } 1557 1558 static unsigned char *const cache_texts[] = { 1559 TEXT_(T_MEMORY_CACHE_SIZE__KB), TEXT_(T_NUMBER_OF_FORMATTED_DOCUMENTS), 1560 TEXT_(T_AGGRESSIVE_CACHE) 1561 }; 1562 1563 static void 1564 cache_opt(struct terminal *term, void *xxx, void *yyy) 1565 { 1566 struct dialog *d; 1567 int a; 1568 snprint(mc_str, 8, memory_cache_size / 1024); 1569 snprint(doc_str, 4, max_format_cache_entries); 1570 d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item)); 1571 a = 0; 1572 d->title = TEXT_(T_CACHE_OPTIONS); 1573 d->fn = group_fn; 1574 d->udata = (void *)cache_texts; 1575 d->refresh = cache_refresh; 1576 d->items[a].type = D_FIELD; 1577 d->items[a].dlen = 8; 1578 d->items[a].data = mc_str; 1579 d->items[a].fn = check_number; 1580 d->items[a].gid = 0; 1581 d->items[a].gnum = INT_MAX / 1024; 1582 a++; 1583 d->items[a].type = D_FIELD; 1584 d->items[a].dlen = 4; 1585 d->items[a].data = doc_str; 1586 d->items[a].fn = check_number; 1587 d->items[a].gid = 0; 1588 d->items[a].gnum = 999; 1589 a++; 1590 d->items[a].type = D_CHECKBOX; 1591 d->items[a].gid = 0; 1592 d->items[a].dlen = sizeof(int); 1593 d->items[a].data = (void *)&aggressive_cache; 1594 a++; 1595 d->items[a].type = D_BUTTON; 1596 d->items[a].gid = B_ENTER; 1597 d->items[a].fn = ok_dialog; 1598 d->items[a].text = TEXT_(T_OK); 1599 a++; 1600 d->items[a].type = D_BUTTON; 1601 d->items[a].gid = B_ESC; 1602 d->items[a].fn = cancel_dialog; 1603 d->items[a].text = TEXT_(T_CANCEL); 1604 a++; 1605 d->items[a].type = D_END; 1606 do_dialog(term, d, getml(d, NULL)); 1607 } 1608 1609 static void 1610 menu_kill_background_connections(struct terminal *term, void *xxx, void *yyy) 1611 { 1612 abort_background_connections(); 1613 } 1614 1615 static void 1616 menu_kill_all_connections(struct terminal *term, void *xxx, void *yyy) 1617 { 1618 abort_all_connections(); 1619 } 1620 1621 static void 1622 menu_save_html_options(struct terminal *term, void *xxx, void *ses_) 1623 { 1624 struct session *ses = (struct session *)ses_; 1625 memcpy(&dds, &ses->ds, sizeof(struct document_setup)); 1626 write_html_config(term); 1627 } 1628 1629 static unsigned char marg_str[2]; 1630 1631 static void 1632 session_refresh(struct session *ses) 1633 { 1634 html_interpret_recursive(ses->screen); 1635 draw_formatted(ses); 1636 } 1637 1638 static void 1639 html_refresh(void *ses_) 1640 { 1641 struct session *ses = (struct session *)ses_; 1642 ses->ds.margin = atoi(cast_const_char marg_str); 1643 session_refresh(ses); 1644 } 1645 1646 static unsigned char *const html_texts[] = { 1647 TEXT_(T_DISPLAY_TABLES), 1648 TEXT_(T_DISPLAY_FRAMES), 1649 TEXT_(T_BREAK_LONG_LINES), 1650 TEXT_(T_DISPLAY_LINKS_TO_IMAGES), 1651 TEXT_(T_DISPLAY_IMAGE_FILENAMES), 1652 TEXT_(T_LINK_ORDER_BY_COLUMNS), 1653 TEXT_(T_NUMBERED_LINKS), 1654 TEXT_(T_AUTO_REFRESH), 1655 TEXT_(T_TARGET_IN_NEW_WINDOW), 1656 TEXT_(T_TEXT_MARGIN), 1657 cast_uchar "", 1658 TEXT_(T_IGNORE_CHARSET_INFO_SENT_BY_SERVER) 1659 }; 1660 1661 static int 1662 dlg_assume_cp(struct dialog_data *dlg, struct dialog_item_data *di) 1663 { 1664 return 0; 1665 } 1666 1667 void 1668 dialog_html_options(struct session *ses) 1669 { 1670 struct dialog *d; 1671 int a; 1672 1673 snprint(marg_str, 2, ses->ds.margin); 1674 d = mem_calloc(sizeof(struct dialog) + 14 * sizeof(struct dialog_item)); 1675 d->title = TEXT_(T_HTML_OPTIONS); 1676 d->fn = group_fn; 1677 d->udata = (void *)html_texts; 1678 d->udata2 = ses; 1679 d->refresh = html_refresh; 1680 d->refresh_data = ses; 1681 a = 0; 1682 d->items[a].type = D_CHECKBOX; 1683 d->items[a].data = (unsigned char *)&ses->ds.tables; 1684 d->items[a].dlen = sizeof(int); 1685 a++; 1686 d->items[a].type = D_CHECKBOX; 1687 d->items[a].data = (unsigned char *)&ses->ds.frames; 1688 d->items[a].dlen = sizeof(int); 1689 a++; 1690 d->items[a].type = D_CHECKBOX; 1691 d->items[a].data = (unsigned char *)&ses->ds.break_long_lines; 1692 d->items[a].dlen = sizeof(int); 1693 a++; 1694 d->items[a].type = D_CHECKBOX; 1695 d->items[a].data = (unsigned char *)&ses->ds.images; 1696 d->items[a].dlen = sizeof(int); 1697 a++; 1698 d->items[a].type = D_CHECKBOX; 1699 d->items[a].data = (unsigned char *)&ses->ds.image_names; 1700 d->items[a].dlen = sizeof(int); 1701 a++; 1702 d->items[a].type = D_CHECKBOX; 1703 d->items[a].data = (unsigned char *)&ses->ds.table_order; 1704 d->items[a].dlen = sizeof(int); 1705 a++; 1706 d->items[a].type = D_CHECKBOX; 1707 d->items[a].data = (unsigned char *)&ses->ds.num_links; 1708 d->items[a].dlen = sizeof(int); 1709 a++; 1710 d->items[a].type = D_CHECKBOX; 1711 d->items[a].data = (unsigned char *)&ses->ds.auto_refresh; 1712 d->items[a].dlen = sizeof(int); 1713 a++; 1714 d->items[a].type = D_CHECKBOX; 1715 d->items[a].data = (unsigned char *)&ses->ds.target_in_new_window; 1716 d->items[a].dlen = sizeof(int); 1717 a++; 1718 d->items[a].type = D_FIELD; 1719 d->items[a].dlen = 2; 1720 d->items[a].data = marg_str; 1721 d->items[a].fn = check_number; 1722 d->items[a].gid = 0; 1723 d->items[a].gnum = 9; 1724 a++; 1725 d->items[a].type = D_BUTTON; 1726 d->items[a].gid = 0; 1727 d->items[a].fn = dlg_assume_cp; 1728 d->items[a].text = TEXT_(T_DEFAULT_CODEPAGE); 1729 d->items[a].data = (unsigned char *)&ses->ds.assume_cp; 1730 d->items[a].dlen = sizeof(int); 1731 a++; 1732 d->items[a].type = D_CHECKBOX; 1733 d->items[a].data = (unsigned char *)&ses->ds.hard_assume; 1734 d->items[a].dlen = sizeof(int); 1735 a++; 1736 d->items[a].type = D_BUTTON; 1737 d->items[a].gid = B_ENTER; 1738 d->items[a].fn = ok_dialog; 1739 d->items[a].text = TEXT_(T_OK); 1740 a++; 1741 d->items[a].type = D_BUTTON; 1742 d->items[a].gid = B_ESC; 1743 d->items[a].fn = cancel_dialog; 1744 d->items[a].text = TEXT_(T_CANCEL); 1745 a++; 1746 d->items[a].type = D_END; 1747 do_dialog(ses->term, d, getml(d, NULL)); 1748 } 1749 1750 static void 1751 menu_html_options(struct terminal *term, void *xxx, void *ses_) 1752 { 1753 struct session *ses = (struct session *)ses_; 1754 dialog_html_options(ses); 1755 } 1756 1757 static unsigned char *const color_texts[] = { cast_uchar "", cast_uchar "", 1758 cast_uchar "", 1759 TEXT_(T_IGNORE_DOCUMENT_COLOR) }; 1760 1761 static void 1762 html_color_refresh(void *ses_) 1763 { 1764 struct session *ses = (struct session *)ses_; 1765 html_interpret_recursive(ses->screen); 1766 draw_formatted(ses); 1767 } 1768 1769 static void 1770 select_color(struct terminal *term, int n, int *ptr) 1771 { 1772 int i; 1773 struct menu_item *mi; 1774 mi = new_menu(MENU_FREE_ITEMS); 1775 for (i = 0; i < n; i++) { 1776 add_to_menu(&mi, TEXT_(T_COLOR_0 + i), cast_uchar "", 1777 cast_uchar "", set_val, (void *)(unsigned long)i, 0, 1778 i); 1779 } 1780 do_menu_selected(term, mi, ptr, *ptr, NULL, NULL); 1781 } 1782 1783 static int 1784 select_color_8(struct dialog_data *dlg, struct dialog_item_data *di) 1785 { 1786 select_color(dlg->win->term, 8, (int *)di->cdata); 1787 return 0; 1788 } 1789 1790 static int 1791 select_color_16(struct dialog_data *dlg, struct dialog_item_data *di) 1792 { 1793 select_color(dlg->win->term, 16, (int *)di->cdata); 1794 return 0; 1795 } 1796 1797 static void 1798 menu_color(struct terminal *term, void *xxx, void *ses_) 1799 { 1800 struct session *ses = (struct session *)ses_; 1801 struct dialog *d; 1802 1803 d = mem_calloc(sizeof(struct dialog) + 6 * sizeof(struct dialog_item)); 1804 d->title = TEXT_(T_COLOR); 1805 d->fn = group_fn; 1806 d->udata = (void *)color_texts; 1807 d->udata2 = ses; 1808 d->refresh = html_color_refresh; 1809 d->refresh_data = ses; 1810 1811 d->items[0].type = D_BUTTON; 1812 d->items[0].gid = 0; 1813 d->items[0].text = TEXT_(T_TEXT_COLOR); 1814 d->items[0].fn = select_color_16; 1815 d->items[0].data = (unsigned char *)&ses->ds.t_text_color; 1816 d->items[0].dlen = sizeof(int); 1817 1818 d->items[1].type = D_BUTTON; 1819 d->items[1].gid = 0; 1820 d->items[1].text = TEXT_(T_LINK_COLOR); 1821 d->items[1].fn = select_color_16; 1822 d->items[1].data = (unsigned char *)&ses->ds.t_link_color; 1823 d->items[1].dlen = sizeof(int); 1824 1825 d->items[2].type = D_BUTTON; 1826 d->items[2].gid = 0; 1827 d->items[2].text = TEXT_(T_BACKGROUND_COLOR); 1828 d->items[2].fn = select_color_8; 1829 d->items[2].data = (unsigned char *)&ses->ds.t_background_color; 1830 d->items[2].dlen = sizeof(int); 1831 1832 d->items[3].type = D_CHECKBOX; 1833 d->items[3].data = (unsigned char *)(&ses->ds.t_ignore_document_color); 1834 d->items[3].dlen = sizeof(int); 1835 1836 d->items[4].type = D_BUTTON; 1837 d->items[4].gid = B_ENTER; 1838 d->items[4].fn = ok_dialog; 1839 d->items[4].text = TEXT_(T_OK); 1840 1841 d->items[5].type = D_BUTTON; 1842 d->items[5].gid = B_ESC; 1843 d->items[5].fn = cancel_dialog; 1844 d->items[5].text = TEXT_(T_CANCEL); 1845 1846 d->items[6].type = D_END; 1847 1848 do_dialog(term, d, getml(d, NULL)); 1849 } 1850 1851 static unsigned char new_bookmarks_file[MAX_STR_LEN]; 1852 static int new_bookmarks_codepage = 0; 1853 1854 static void 1855 refresh_misc(void *ses_) 1856 { 1857 struct session *ses = (struct session *)ses_; 1858 if (strcmp((char *)new_bookmarks_file, (char *)bookmarks_file)) 1859 reinit_bookmarks(ses, new_bookmarks_file); 1860 } 1861 1862 static unsigned char *const miscopt_labels[] = { TEXT_(T_BOOKMARKS_FILE), 1863 NULL }; 1864 static unsigned char *const miscopt_checkbox_labels[] = { 1865 TEXT_(T_SAVE_URL_HISTORY_ON_EXIT), NULL 1866 }; 1867 1868 static void 1869 miscopt_fn(struct dialog_data *dlg) 1870 { 1871 struct terminal *term = dlg->win->term; 1872 unsigned char **labels = dlg->dlg->udata; 1873 int max = 0, min = 0; 1874 int w, rw; 1875 int y = 0; 1876 int a = 0; 1877 int bmk = !anonymous; 1878 1879 max_text_width(term, labels[0], &max, AL_LEFT); 1880 min_text_width(term, labels[0], &min, AL_LEFT); 1881 if (bmk) { 1882 max_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1, 1883 &max); 1884 min_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1, 1885 &min); 1886 } 1887 if (a) { 1888 max_buttons_width(term, dlg->items + dlg->n - 3 - bmk, 1, &max); 1889 min_buttons_width(term, dlg->items + dlg->n - 3 - bmk, 1, &min); 1890 } 1891 if (bmk) { 1892 checkboxes_width(term, miscopt_checkbox_labels, 1, &max, 1893 max_text_width); 1894 checkboxes_width(term, miscopt_checkbox_labels, 1, &min, 1895 min_text_width); 1896 } 1897 max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max); 1898 min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min); 1899 w = term->x * 9 / 10 - 2 * DIALOG_LB; 1900 if (w > max) 1901 w = max; 1902 if (w < min) 1903 w = min; 1904 if (w > term->x - 2 * DIALOG_LB) 1905 w = term->x - 2 * DIALOG_LB; 1906 if (w < 5) 1907 w = 5; 1908 rw = 0; 1909 1910 if (bmk) { 1911 dlg_format_text_and_field( 1912 dlg, NULL, labels[0], dlg->items + dlg->n - 4 - a - bmk, 0, 1913 &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT); 1914 y++; 1915 } 1916 if (bmk) { 1917 y++; 1918 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - a - bmk, 1919 1, 0, &y, w, &rw, AL_LEFT); 1920 } 1921 if (a) 1922 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - bmk, 1, 1923 0, &y, w, &rw, AL_LEFT); 1924 if (bmk) 1925 dlg_format_checkboxes(dlg, NULL, dlg->items + dlg->n - 3, 1, 0, 1926 &y, w, &rw, miscopt_checkbox_labels); 1927 dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, 1928 AL_CENTER); 1929 w = rw; 1930 dlg->xw = w + 2 * DIALOG_LB; 1931 dlg->yw = y + 2 * DIALOG_TB; 1932 center_dlg(dlg); 1933 draw_dlg(dlg); 1934 y = dlg->y + DIALOG_TB; 1935 y++; 1936 if (bmk) { 1937 dlg_format_text_and_field(dlg, term, labels[0], 1938 dlg->items + dlg->n - 4 - a - bmk, 1939 dlg->x + DIALOG_LB, &y, w, NULL, 1940 COLOR_DIALOG_TEXT, AL_LEFT); 1941 y++; 1942 dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - a - bmk, 1943 1, dlg->x + DIALOG_LB, &y, w, NULL, 1944 AL_CENTER); 1945 } 1946 if (a) 1947 dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - bmk, 1, 1948 dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER); 1949 if (bmk) { 1950 dlg_format_checkboxes(dlg, term, dlg->items + dlg->n - 3, 1, 1951 dlg->x + DIALOG_LB, &y, w, NULL, 1952 miscopt_checkbox_labels); 1953 y++; 1954 } 1955 dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, 1956 dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER); 1957 } 1958 1959 static void 1960 miscelaneous_options(struct terminal *term, void *xxx, void *ses_) 1961 { 1962 struct session *ses = (struct session *)ses_; 1963 struct dialog *d; 1964 int a = 0; 1965 1966 /* if you add something into text mode (or both text and graphics), 1967 * remove this (and enable also miscelaneous_options in do_setup_menu) 1968 */ 1969 if (anonymous) 1970 return; 1971 1972 safe_strncpy(new_bookmarks_file, bookmarks_file, MAX_STR_LEN); 1973 d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item)); 1974 d->title = TEXT_(T_MISCELANEOUS_OPTIONS); 1975 d->refresh = refresh_misc; 1976 d->refresh_data = ses; 1977 d->fn = miscopt_fn; 1978 d->udata = (void *)miscopt_labels; 1979 d->udata2 = ses; 1980 if (!anonymous) { 1981 d->items[a].type = D_FIELD; 1982 d->items[a].dlen = MAX_STR_LEN; 1983 d->items[a].data = new_bookmarks_file; 1984 a++; 1985 d->items[a].type = D_BUTTON; 1986 d->items[a].gid = 0; 1987 d->items[a].fn = dlg_assume_cp; 1988 d->items[a].text = TEXT_(T_BOOKMARKS_ENCODING); 1989 d->items[a].data = (unsigned char *)&new_bookmarks_codepage; 1990 d->items[a].dlen = sizeof(int); 1991 a++; 1992 } 1993 if (!anonymous) { 1994 d->items[a].type = D_CHECKBOX; 1995 d->items[a].gid = 0; 1996 d->items[a].dlen = sizeof(int); 1997 d->items[a].data = (void *)&save_history; 1998 a++; 1999 } 2000 d->items[a].type = D_BUTTON; 2001 d->items[a].gid = B_ENTER; 2002 d->items[a].fn = ok_dialog; 2003 d->items[a].text = TEXT_(T_OK); 2004 a++; 2005 d->items[a].type = D_BUTTON; 2006 d->items[a].gid = B_ESC; 2007 d->items[a].fn = cancel_dialog; 2008 d->items[a].text = TEXT_(T_CANCEL); 2009 a++; 2010 d->items[a].type = D_END; 2011 do_dialog(term, d, getml(d, NULL)); 2012 } 2013 2014 static const struct menu_item file_menu11[] = { 2015 {TEXT_(T_GOTO_URL), cast_uchar "g", TEXT_(T_HK_GOTO_URL), 2016 menu_goto_url, NULL, 0, 1}, 2017 { TEXT_(T_GO_BACK), cast_uchar "z", TEXT_(T_HK_GO_BACK), menu_go_back, 2018 NULL, 0, 1}, 2019 { TEXT_(T_GO_FORWARD), cast_uchar "x", TEXT_(T_HK_GO_FORWARD), 2020 menu_go_forward, NULL, 0, 1}, 2021 { TEXT_(T_HISTORY), cast_uchar ">", TEXT_(T_HK_HISTORY), history_menu, 2022 NULL, 1, 1}, 2023 { TEXT_(T_RELOAD), cast_uchar "Ctrl-R", TEXT_(T_HK_RELOAD), menu_reload, 2024 NULL, 0, 1}, 2025 }; 2026 2027 static const struct menu_item file_menu12[] = { 2028 {TEXT_(T_BOOKMARKS), cast_uchar "s", TEXT_(T_HK_BOOKMARKS), 2029 menu_bookmark_manager, NULL, 0, 1}, 2030 }; 2031 2032 static const struct menu_item file_menu21[] = { 2033 {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1}, 2034 { TEXT_(T_SAVE_AS), cast_uchar "", TEXT_(T_HK_SAVE_AS), save_as, NULL, 2035 0, 1}, 2036 { TEXT_(T_SAVE_URL_AS), cast_uchar "", TEXT_(T_HK_SAVE_URL_AS), 2037 menu_save_url_as, NULL, 0, 1}, 2038 { TEXT_(T_SAVE_FORMATTED_DOCUMENT), cast_uchar "", 2039 TEXT_(T_HK_SAVE_FORMATTED_DOCUMENT), menu_save_formatted, NULL, 0, 2040 1 }, 2041 }; 2042 2043 static const struct menu_item file_menu22[] = { 2044 {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1}, 2045 { TEXT_(T_KILL_BACKGROUND_CONNECTIONS), cast_uchar "", 2046 TEXT_(T_HK_KILL_BACKGROUND_CONNECTIONS), 2047 menu_kill_background_connections, NULL, 0, 1}, 2048 { TEXT_(T_KILL_ALL_CONNECTIONS), cast_uchar "", 2049 TEXT_(T_HK_KILL_ALL_CONNECTIONS), menu_kill_all_connections, NULL, 0, 2050 1 }, 2051 { TEXT_(T_FLUSH_ALL_CACHES), cast_uchar "", 2052 TEXT_(T_HK_FLUSH_ALL_CACHES), flush_caches, NULL, 0, 1}, 2053 { TEXT_(T_RESOURCE_INFO), cast_uchar "", TEXT_(T_HK_RESOURCE_INFO), 2054 resource_info_menu, NULL, 0, 1}, 2055 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1}, 2056 }; 2057 2058 static const struct menu_item file_menu3[] = { 2059 {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1}, 2060 { TEXT_(T_EXIT), cast_uchar "q", TEXT_(T_HK_EXIT), exit_prog, NULL, 0, 2061 1 }, 2062 { NULL, NULL, 0, NULL, NULL, 0, 0} 2063 }; 2064 2065 static void 2066 do_file_menu(struct terminal *term, void *xxx, void *ses_) 2067 { 2068 struct session *ses = (struct session *)ses_; 2069 int x; 2070 int o; 2071 struct menu_item *file_menu, *e; 2072 file_menu = 2073 xmalloc(sizeof(file_menu11) + sizeof(file_menu12) 2074 + sizeof(file_menu21) + sizeof(file_menu22) 2075 + sizeof(file_menu3) + 3 * sizeof(struct menu_item)); 2076 e = file_menu; 2077 memcpy(e, file_menu11, sizeof(file_menu11)); 2078 e += sizeof(file_menu11) / sizeof(struct menu_item); 2079 if (!anonymous) { 2080 memcpy(e, file_menu12, sizeof(file_menu12)); 2081 e += sizeof(file_menu12) / sizeof(struct menu_item); 2082 } 2083 if ((o = can_open_in_new(term))) { 2084 e->text = TEXT_(T_NEW_WINDOW); 2085 e->rtext = o - 1 ? cast_uchar ">" : cast_uchar ""; 2086 e->hotkey = TEXT_(T_HK_NEW_WINDOW); 2087 e->func = open_in_new_window; 2088 e->data = (void *)&send_open_new_xterm_ptr; 2089 e->in_m = o - 1; 2090 e->free_i = 0; 2091 e++; 2092 } 2093 if (!anonymous) { 2094 memcpy(e, file_menu21, sizeof(file_menu21)); 2095 e += sizeof(file_menu21) / sizeof(struct menu_item); 2096 } 2097 memcpy(e, file_menu22, sizeof(file_menu22)); 2098 e += sizeof(file_menu22) / sizeof(struct menu_item); 2099 x = 1; 2100 memcpy(e, file_menu3 + x, 2101 sizeof(file_menu3) - x * sizeof(struct menu_item)); 2102 do_menu(term, file_menu, ses); 2103 } 2104 2105 static void (*const search_dlg_ptr)(struct session *ses, struct f_data_c *f, 2106 int a) = search_dlg; 2107 static void (*const search_back_dlg_ptr)(struct session *ses, 2108 struct f_data_c *f, 2109 int a) = search_back_dlg; 2110 static void (*const find_next_ptr)(struct session *ses, struct f_data_c *f, 2111 int a) = find_next; 2112 static void (*const find_next_back_ptr)(struct session *ses, struct f_data_c *f, 2113 int a) = find_next_back; 2114 static void (*const set_frame_ptr)(struct session *ses, struct f_data_c *f, 2115 int a) = set_frame; 2116 2117 static const struct menu_item view_menu[] = { 2118 {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, 2119 (void *)&search_dlg_ptr, 0, 0}, 2120 { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), 2121 menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0}, 2122 { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), 2123 menu_for_frame, (void *)&find_next_ptr, 0, 0}, 2124 { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), 2125 menu_for_frame, (void *)&find_next_back_ptr, 0, 0}, 2126 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2127 { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", 2128 TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0}, 2129 { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), 2130 menu_doc_info, NULL, 0, 0}, 2131 { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO), 2132 menu_head_info, NULL, 0, 0}, 2133 { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", 2134 TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, 2135 (void *)&set_frame_ptr, 0, 0}, 2136 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2137 { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), 2138 menu_html_options, NULL, 0, 0}, 2139 { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "", 2140 TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0}, 2141 { NULL, NULL, 0, NULL, NULL, 0, 0} 2142 }; 2143 2144 static const struct menu_item view_menu_anon[] = { 2145 {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, 2146 (void *)&search_dlg_ptr, 0, 0}, 2147 { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), 2148 menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0}, 2149 { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), 2150 menu_for_frame, (void *)&find_next_ptr, 0, 0}, 2151 { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), 2152 menu_for_frame, (void *)&find_next_back_ptr, 0, 0}, 2153 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2154 { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", 2155 TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0}, 2156 { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), 2157 menu_doc_info, NULL, 0, 0}, 2158 { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", 2159 TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, 2160 (void *)&set_frame_ptr, 0, 0}, 2161 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2162 { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), 2163 menu_html_options, NULL, 0, 0}, 2164 { NULL, NULL, 0, NULL, NULL, 0, 0} 2165 }; 2166 2167 static const struct menu_item view_menu_color[] = { 2168 {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, 2169 (void *)&search_dlg_ptr, 0, 0}, 2170 { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), 2171 menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0}, 2172 { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), 2173 menu_for_frame, (void *)&find_next_ptr, 0, 0}, 2174 { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), 2175 menu_for_frame, (void *)&find_next_back_ptr, 0, 0}, 2176 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2177 { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", 2178 TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0}, 2179 { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), 2180 menu_doc_info, NULL, 0, 0}, 2181 { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO), 2182 menu_head_info, NULL, 0, 0}, 2183 { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", 2184 TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, 2185 (void *)&set_frame_ptr, 0, 0}, 2186 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2187 { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), 2188 menu_html_options, NULL, 0, 0}, 2189 { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0, 2190 0 }, 2191 { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "", 2192 TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0}, 2193 { NULL, NULL, 0, NULL, NULL, 0, 0} 2194 }; 2195 2196 static const struct menu_item view_menu_anon_color[] = { 2197 {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, 2198 (void *)&search_dlg_ptr, 0, 0}, 2199 { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), 2200 menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0}, 2201 { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), 2202 menu_for_frame, (void *)&find_next_ptr, 0, 0}, 2203 { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), 2204 menu_for_frame, (void *)&find_next_back_ptr, 0, 0}, 2205 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2206 { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", 2207 TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0}, 2208 { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), 2209 menu_doc_info, NULL, 0, 0}, 2210 { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", 2211 TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, 2212 (void *)&set_frame_ptr, 0, 0}, 2213 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0}, 2214 { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), 2215 menu_html_options, NULL, 0, 0}, 2216 { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0, 2217 0 }, 2218 { NULL, NULL, 0, NULL, NULL, 0, 0} 2219 }; 2220 2221 static void 2222 do_view_menu(struct terminal *term, void *xxx, void *ses_) 2223 { 2224 struct session *ses = (struct session *)ses_; 2225 if (term->spec->col) { 2226 if (!anonymous) 2227 do_menu(term, (struct menu_item *)view_menu_color, ses); 2228 else 2229 do_menu(term, (struct menu_item *)view_menu_anon_color, 2230 ses); 2231 } else { 2232 if (!anonymous) 2233 do_menu(term, (struct menu_item *)view_menu, ses); 2234 else 2235 do_menu(term, (struct menu_item *)view_menu_anon, ses); 2236 } 2237 } 2238 2239 static const struct menu_item help_menu[] = { 2240 {TEXT_(T_ABOUT), cast_uchar "", TEXT_(T_HK_ABOUT), menu_about, NULL, 0, 2241 0 }, 2242 { TEXT_(T_KEYS), cast_uchar "F1", TEXT_(T_HK_KEYS), menu_keys, NULL, 0, 2243 0 }, 2244 { TEXT_(T_MANUAL), cast_uchar "", TEXT_(T_HK_MANUAL), menu_url, 2245 TEXT_(T_URL_MANUAL), 0, 0}, 2246 { TEXT_(T_HOMEPAGE), cast_uchar "", TEXT_(T_HK_HOMEPAGE), menu_url, 2247 TEXT_(T_URL_HOMEPAGE), 0, 0}, 2248 { TEXT_(T_COPYING), cast_uchar "", TEXT_(T_HK_COPYING), menu_copying, 2249 NULL, 0, 0}, 2250 { NULL, NULL, 0, NULL, NULL, 0, 0} 2251 }; 2252 2253 static const struct menu_item net_options_menu[] = { 2254 {TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS), 2255 dlg_net_options, NULL, 0, 0}, 2256 { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES), 2257 dlg_proxy_options, NULL, 0, 0}, 2258 { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS), 2259 dlg_ssl_options, NULL, 0, 0}, 2260 { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), 2261 dlg_http_options, NULL, 0, 0}, 2262 { NULL, NULL, 0, NULL, NULL, 0, 0} 2263 }; 2264 2265 static const struct menu_item net_options_ipv6_menu[] = { 2266 {TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS), 2267 dlg_net_options, NULL, 0, 0}, 2268 { TEXT_(T_IPV6_OPTIONS), cast_uchar "", TEXT_(T_HK_IPV6_OPTIONS), 2269 dlg_ipv6_options, NULL, 0, 0}, 2270 { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES), 2271 dlg_proxy_options, NULL, 0, 0}, 2272 { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS), 2273 dlg_ssl_options, NULL, 0, 0}, 2274 { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), 2275 dlg_http_options, NULL, 0, 0}, 2276 { NULL, NULL, 0, NULL, NULL, 0, 0} 2277 }; 2278 2279 static void 2280 network_menu(struct terminal *term, void *xxx, void *yyy) 2281 { 2282 if (support_ipv6) 2283 do_menu(term, (struct menu_item *)net_options_ipv6_menu, NULL); 2284 else 2285 do_menu(term, (struct menu_item *)net_options_menu, NULL); 2286 } 2287 2288 static void 2289 menu_write_config(struct terminal *term, void *xxx, void *yyy) 2290 { 2291 write_config(term); 2292 } 2293 2294 static const struct menu_item setup_menu_2[] = { 2295 {TEXT_(T_TERMINAL_OPTIONS), cast_uchar "", 2296 TEXT_(T_HK_TERMINAL_OPTIONS), terminal_options, NULL, 0, 1}, 2297 }; 2298 2299 static const struct menu_item setup_menu_5[] = { 2300 {TEXT_(T_NETWORK_OPTIONS), cast_uchar ">", TEXT_(T_HK_NETWORK_OPTIONS), 2301 network_menu, NULL, 1, 1}, 2302 }; 2303 2304 static const struct menu_item setup_menu_6[] = { 2305 {TEXT_(T_MISCELANEOUS_OPTIONS), cast_uchar "", 2306 TEXT_(T_HK_MISCELANEOUS_OPTIONS), miscelaneous_options, NULL, 0, 1}, 2307 }; 2308 2309 static const struct menu_item setup_menu_7[] = { 2310 {TEXT_(T_CACHE), cast_uchar "", TEXT_(T_HK_CACHE), cache_opt, NULL, 0, 2311 1 }, 2312 { TEXT_(T_ASSOCIATIONS), cast_uchar "", TEXT_(T_HK_ASSOCIATIONS), 2313 menu_assoc_manager, NULL, 0, 1}, 2314 { TEXT_(T_FILE_EXTENSIONS), cast_uchar "", TEXT_(T_HK_FILE_EXTENSIONS), 2315 menu_ext_manager, NULL, 0, 1}, 2316 { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1}, 2317 { TEXT_(T_SAVE_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_OPTIONS), 2318 menu_write_config, NULL, 0, 1}, 2319 }; 2320 2321 static const struct menu_item setup_menu_8[] = { 2322 {NULL, NULL, 0, NULL, NULL, 0, 0} 2323 }; 2324 2325 static void 2326 do_setup_menu(struct terminal *term, void *xxx, void *ses_) 2327 { 2328 struct session *ses = (struct session *)ses_; 2329 struct menu_item *setup_menu, *e; 2330 int size = sizeof(setup_menu_2) + sizeof(setup_menu_5) 2331 + sizeof(setup_menu_6) + sizeof(setup_menu_7) 2332 + sizeof(setup_menu_8); 2333 setup_menu = xmalloc(size); 2334 e = setup_menu; 2335 memcpy(e, setup_menu_2, sizeof(setup_menu_2)); 2336 e += sizeof(setup_menu_2) / sizeof(struct menu_item); 2337 if (!anonymous) { 2338 memcpy(e, setup_menu_5, sizeof(setup_menu_5)); 2339 e += sizeof(setup_menu_5) / sizeof(struct menu_item); 2340 } 2341 if (!anonymous) { 2342 memcpy(e, setup_menu_6, sizeof(setup_menu_6)); 2343 e += sizeof(setup_menu_6) / sizeof(struct menu_item); 2344 } 2345 if (!anonymous) { 2346 memcpy(e, setup_menu_7, sizeof(setup_menu_7)); 2347 e += sizeof(setup_menu_7) / sizeof(struct menu_item); 2348 } 2349 memcpy(e, setup_menu_8, sizeof(setup_menu_8)); 2350 do_menu(term, setup_menu, ses); 2351 } 2352 2353 static void 2354 do_help_menu(struct terminal *term, void *xxx, void *ses_) 2355 { 2356 struct session *ses = (struct session *)ses_; 2357 do_menu(term, (struct menu_item *)help_menu, ses); 2358 } 2359 2360 static const struct menu_item main_menu[] = { 2361 {TEXT_(T_FILE), cast_uchar "", TEXT_(T_HK_FILE), do_file_menu, NULL, 1, 2362 1 }, 2363 { TEXT_(T_VIEW), cast_uchar "", TEXT_(T_HK_VIEW), do_view_menu, NULL, 1, 2364 1 }, 2365 { TEXT_(T_LINK), cast_uchar "", TEXT_(T_HK_LINK), link_menu, NULL, 1, 2366 1 }, 2367 { TEXT_(T_DOWNLOADS), cast_uchar "", TEXT_(T_HK_DOWNLOADS), 2368 downloads_menu, NULL, 1, 1}, 2369 { TEXT_(T_SETUP), cast_uchar "", TEXT_(T_HK_SETUP), do_setup_menu, NULL, 2370 1, 1}, 2371 { TEXT_(T_HELP), cast_uchar "", TEXT_(T_HK_HELP), do_help_menu, NULL, 1, 2372 1 }, 2373 { NULL, NULL, 0, NULL, NULL, 0, 0} 2374 }; 2375 2376 /* lame technology rulez ! */ 2377 2378 void 2379 activate_bfu_technology(struct session *ses, int item) 2380 { 2381 struct terminal *term = ses->term; 2382 struct menu_item *m = (struct menu_item *)main_menu; 2383 do_mainmenu(term, m, ses, item); 2384 } 2385 2386 struct history goto_url_history = { 2387 0, {&goto_url_history.items, &goto_url_history.items} 2388 }; 2389 2390 void 2391 dialog_goto_url(struct session *ses, unsigned char *url) 2392 { 2393 input_field(ses->term, NULL, TEXT_(T_GOTO_URL), TEXT_(T_ENTER_URL), ses, 2394 &goto_url_history, MAX_INPUT_URL_LEN, url, 0, 0, NULL, 2, 2395 TEXT_(T_OK), goto_url, TEXT_(T_CANCEL), input_field_null); 2396 } 2397 2398 void 2399 dialog_save_url(struct session *ses) 2400 { 2401 input_field(ses->term, NULL, TEXT_(T_SAVE_URL), TEXT_(T_ENTER_URL), ses, 2402 &goto_url_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, 2403 NULL, 2, TEXT_(T_OK), save_url, TEXT_(T_CANCEL), 2404 input_field_null); 2405 } 2406 2407 struct does_file_exist_s { 2408 void (*fn)(struct session *, unsigned char *, int); 2409 void (*cancel)(void *); 2410 int flags; 2411 struct session *ses; 2412 unsigned char *file; 2413 unsigned char *url; 2414 unsigned char *head; 2415 }; 2416 2417 static void 2418 does_file_exist_ok(struct does_file_exist_s *h, int mode) 2419 { 2420 if (h->fn) { 2421 unsigned char *d = h->file; 2422 unsigned char *dd; 2423 for (dd = h->file; *dd; dd++) 2424 if (dir_sep(*dd)) 2425 d = dd + 1; 2426 if (d - h->file < MAX_STR_LEN) { 2427 memcpy(download_dir, h->file, d - h->file); 2428 download_dir[d - h->file] = 0; 2429 } 2430 h->fn(h->ses, h->file, mode); 2431 } 2432 } 2433 2434 static void 2435 does_file_exist_continue(void *data) 2436 { 2437 does_file_exist_ok(data, DOWNLOAD_CONTINUE); 2438 } 2439 2440 static void 2441 does_file_exist_overwrite(void *data) 2442 { 2443 does_file_exist_ok(data, DOWNLOAD_OVERWRITE); 2444 } 2445 2446 static void 2447 does_file_exist_cancel(void *data) 2448 { 2449 struct does_file_exist_s *h = (struct does_file_exist_s *)data; 2450 if (h->cancel) 2451 h->cancel(h->ses); 2452 } 2453 2454 static void 2455 does_file_exist_rename(void *data) 2456 { 2457 struct does_file_exist_s *h = (struct does_file_exist_s *)data; 2458 query_file(h->ses, h->url, h->head, h->fn, h->cancel, h->flags); 2459 } 2460 2461 static void 2462 does_file_exist(void *d_, unsigned char *file) 2463 { 2464 struct does_file_exist_s *d = (struct does_file_exist_s *)d_; 2465 unsigned char *f; 2466 unsigned char *wd; 2467 struct session *ses = d->ses; 2468 struct stat st; 2469 int r; 2470 struct does_file_exist_s *h; 2471 unsigned char *msg; 2472 int file_type = 0; 2473 2474 h = xmalloc(sizeof(struct does_file_exist_s)); 2475 h->fn = d->fn; 2476 h->cancel = d->cancel; 2477 h->flags = d->flags; 2478 h->ses = ses; 2479 h->file = stracpy(file); 2480 h->url = stracpy(d->url); 2481 h->head = stracpy(d->head); 2482 2483 if (!*file) { 2484 does_file_exist_rename(h); 2485 goto free_h_ret; 2486 } 2487 2488 if (test_abort_downloads_to_file(file, ses->term->cwd, 0)) { 2489 msg = TEXT_(T_ALREADY_EXISTS_AS_DOWNLOAD); 2490 goto display_msgbox; 2491 } 2492 2493 wd = get_cwd(); 2494 set_cwd(ses->term->cwd); 2495 f = translate_download_file(file); 2496 EINTRLOOP(r, stat(cast_const_char f, &st)); 2497 free(f); 2498 if (wd) { 2499 set_cwd(wd); 2500 free(wd); 2501 } 2502 if (r) { 2503 does_file_exist_ok(h, DOWNLOAD_DEFAULT); 2504 free_h_ret: 2505 free(h->head); 2506 free(h->file); 2507 free(h->url); 2508 free(h); 2509 return; 2510 } 2511 2512 if (!S_ISREG(st.st_mode)) { 2513 if (S_ISDIR(st.st_mode)) 2514 file_type = 2; 2515 else 2516 file_type = 1; 2517 } 2518 2519 msg = TEXT_(T_ALREADY_EXISTS); 2520 display_msgbox: 2521 if (file_type == 2) { 2522 msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL), 2523 TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER, 2524 TEXT_(T_DIRECTORY), cast_uchar " ", h->file, 2525 cast_uchar " ", TEXT_(T_ALREADY_EXISTS), MSG_BOX_END, 2526 (void *)h, 2, TEXT_(T_RENAME), does_file_exist_rename, 2527 B_ENTER, TEXT_(T_CANCEL), does_file_exist_cancel, 2528 B_ESC); 2529 } else if (file_type || h->flags != DOWNLOAD_CONTINUE) { 2530 msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL), 2531 TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER, TEXT_(T_FILE), 2532 cast_uchar " ", h->file, cast_uchar " ", msg, 2533 cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_OVERWRITE), 2534 MSG_BOX_END, (void *)h, 3, TEXT_(T_OVERWRITE), 2535 does_file_exist_overwrite, B_ENTER, TEXT_(T_RENAME), 2536 does_file_exist_rename, 0, TEXT_(T_CANCEL), 2537 does_file_exist_cancel, B_ESC); 2538 } else { 2539 msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL), 2540 TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER, TEXT_(T_FILE), 2541 cast_uchar " ", h->file, cast_uchar " ", msg, 2542 cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_CONTINUE), 2543 MSG_BOX_END, (void *)h, 4, TEXT_(T_CONTINUE), 2544 does_file_exist_continue, B_ENTER, TEXT_(T_OVERWRITE), 2545 does_file_exist_overwrite, 0, TEXT_(T_RENAME), 2546 does_file_exist_rename, 0, TEXT_(T_CANCEL), 2547 does_file_exist_cancel, B_ESC); 2548 } 2549 } 2550 2551 static void 2552 query_file_cancel(void *d_, unsigned char *s_) 2553 { 2554 struct does_file_exist_s *d = (struct does_file_exist_s *)d_; 2555 if (d->cancel) 2556 d->cancel(d->ses); 2557 } 2558 2559 void 2560 query_file(struct session *ses, unsigned char *url, unsigned char *head, 2561 void (*fn)(struct session *, unsigned char *, int), 2562 void (*cancel)(void *), int flags) 2563 { 2564 unsigned char *fc, *file, *def; 2565 size_t dfl; 2566 struct does_file_exist_s *h; 2567 2568 h = xmalloc(sizeof(struct does_file_exist_s)); 2569 2570 fc = get_filename_from_url(url, head, 0); 2571 file = stracpy(fc); 2572 free(fc); 2573 check_filename(&file); 2574 2575 def = NULL; 2576 dfl = add_to_str(&def, 0, download_dir); 2577 if (*def && !dir_sep(def[strlen(cast_const_char def) - 1])) 2578 dfl = add_chr_to_str(&def, dfl, '/'); 2579 dfl = add_to_str(&def, dfl, file); 2580 free(file); 2581 2582 h->fn = fn; 2583 h->cancel = cancel; 2584 h->flags = flags; 2585 h->ses = ses; 2586 h->file = NULL; 2587 h->url = stracpy(url); 2588 h->head = stracpy(head); 2589 2590 input_field(ses->term, getml(h, h->url, h->head, NULL), 2591 TEXT_(T_DOWNLOAD), TEXT_(T_SAVE_TO_FILE), h, &file_history, 2592 MAX_INPUT_URL_LEN, def, 0, 0, NULL, 2, TEXT_(T_OK), 2593 does_file_exist, TEXT_(T_CANCEL), query_file_cancel); 2594 free(def); 2595 } 2596 2597 static struct history search_history = { 2598 0, {&search_history.items, &search_history.items} 2599 }; 2600 2601 void 2602 search_back_dlg(struct session *ses, struct f_data_c *f, int a) 2603 { 2604 if (list_empty(ses->history) || !f->f_data || !f->vs) { 2605 msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_LEFT, 2606 TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, 2607 TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC); 2608 return; 2609 } 2610 input_field( 2611 ses->term, NULL, TEXT_(T_SEARCH_BACK), TEXT_(T_SEARCH_FOR_TEXT), 2612 ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2613 2, TEXT_(T_OK), search_for_back, TEXT_(T_CANCEL), input_field_null); 2614 } 2615 2616 void 2617 search_dlg(struct session *ses, struct f_data_c *f, int a) 2618 { 2619 if (list_empty(ses->history) || !f->f_data || !f->vs) { 2620 msg_box(ses->term, NULL, TEXT_(T_SEARCH_FOR_TEXT), AL_LEFT, 2621 TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, 2622 TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC); 2623 return; 2624 } 2625 input_field(ses->term, NULL, TEXT_(T_SEARCH), TEXT_(T_SEARCH_FOR_TEXT), 2626 ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 2627 0, NULL, 2, TEXT_(T_OK), search_for, TEXT_(T_CANCEL), 2628 input_field_null); 2629 } 2630 2631 void 2632 free_history_lists(void) 2633 { 2634 free_history(goto_url_history); 2635 free_history(file_history); 2636 free_history(search_history); 2637 }