home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  66.9 KB  |  1,885 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /**********************************************************************
  20.  prefs.c
  21.  By Daniel Malmer
  22.  11/8/96
  23.  
  24.  Unix implementation of cross-platform preferences.
  25.  The preferences file is now written in Javascript.
  26.  Users will be able to download new preferences over the net.
  27.  
  28.  If you want to add a new preference, add an entry to the pref_map
  29.  array, defined below.  If you want to specify a default value, you
  30.  will have to edit one of the Javascript files in ns/modules/libpref:
  31.  
  32.  ns/modules/libpref/src/init/all.js:  preferences for all platforms
  33.  ns/modules/libpref/src/unix.js: preferences only on Unix
  34.  
  35.  The eventual goal is to eliminate most of this file.  Rather than
  36.  other parts of the XFE accessing the fe_globalPrefs structure, they
  37.  will make calls to PREF_GetCharPref(), PREF_GetIntPref(), etc.
  38.  
  39. **********************************************************************/
  40.  
  41.  
  42. #include <stdio.h>
  43. #include <stddef.h>
  44. #include <pwd.h>
  45.  
  46. #include "mozilla.h"
  47. #include "xfe.h"
  48. #include "fonts.h"
  49. #include "libi18n.h"
  50. #include "xpgetstr.h"
  51. #include "prefapi.h"
  52. #include "prefs.h"
  53. #include "net.h"
  54.  
  55. /* 
  56.  * prefs version
  57.  */
  58.  
  59. #define PREFS_INIT_VERSION    "1.0"
  60.  
  61. /*
  62.  * external declarations
  63.  */
  64. extern int XFE_TILDE_USER_SYNTAX_DISALLOWED;
  65. extern int XFE_UNKNOWN_EMAIL_ADDR;
  66. extern int XFE_PREFS_UPGRADE;
  67.  
  68. /*
  69.  * global definitions
  70.  */
  71. /* This should probably be defined someplace else... */
  72. MSG_Prefs* fe_mailNewsPrefs = NULL;
  73.  
  74. /*
  75.  * typedefs
  76.  */
  77. typedef void (*io_routine_type)(char*, void*);
  78.  
  79. /*
  80.  * Maps a Javascript name to an offset in the preferences
  81.  * structure.  We also need to keep track of the type of the
  82.  * field, and a post-processing routine to fix the field.
  83.  */
  84. struct pref_map {
  85.     char* name;
  86.     size_t offset;
  87.     io_routine_type read_routine;
  88.     io_routine_type write_routine;
  89.     Bool upgrade_only;        /* saved only when upgrading from 3.0 to 4.0 */
  90. };
  91.  
  92. /* 
  93.  * Declarations for static functions.
  94.  */
  95. static void fix_path(void*);
  96. static Bool XFE_OldReadPrefs(char * filename, XFE_GlobalPrefs *prefs);
  97. static Bool evaluate_preferences_file(char* filename);
  98. static Bool read_old_prefs_file(XFE_GlobalPrefs* prefs);
  99. static void split_all_proxies(XFE_GlobalPrefs* prefs);
  100. static void split_proxy(char** proxy, int* port, int default_port);
  101. static void xfe_prefs_from_environment(XFE_GlobalPrefs* prefs);
  102. static char* xfe_organization(void);
  103. static void read_str(char* name, void* ptr);
  104. static void write_str(char* name, void* ptr);
  105. static void read_int(char* name, void* ptr);
  106. static void write_int(char* name, void* ptr);
  107. static void read_bool(char* name, void* ptr);
  108. static void write_bool(char* name, void* ptr);
  109. static void read_path(char* name, void* ptr);
  110. static void write_path(char* name, void* ptr);
  111. static void read_char_set(char* name, void* ptr);
  112. static void write_char_set(char* name, void* ptr);
  113. static void read_font_spec(char* name, void* ptr);
  114. static void write_font_spec(char* name, void* ptr);
  115. static void read_color(char* name, void* ptr);
  116. static void write_color(char* name, void* ptr);
  117. static void tweaks(XFE_GlobalPrefs* prefs);
  118.  
  119. static int def = 0;
  120.  
  121. /*
  122.  * macros
  123.  */
  124. #define FIELD_OFFSET(field) offsetof(struct _XFE_GlobalPrefs, field)
  125. #define GET_FIELD(map, prefs) ( ((char*) prefs) + map.offset )
  126. #define REPLACE_STRING(slot, string) if ( slot ) free(slot); \
  127.                                      slot = strdup(string);
  128.  
  129. /*
  130.  * static definitions
  131.  */
  132. static struct pref_map pref_map[] = {
  133.  
  134. {"browser.xfe.prefs_version", FIELD_OFFSET(version_number), read_str, write_str},
  135.  
  136. {"applications.tn3270", FIELD_OFFSET(tn3270_command), read_str, write_str},
  137. {"applications.telnet", FIELD_OFFSET(telnet_command), read_str, write_str},
  138. {"applications.rlogin", FIELD_OFFSET(rlogin_command), read_str, write_str},
  139. {"applications.rlogin_with_user", FIELD_OFFSET(rlogin_user_command), read_str, write_str},
  140.  
  141. {"autoupdate.enabled", FIELD_OFFSET(auto_install), read_bool, write_bool},
  142.  
  143. {"browser.download_directory", FIELD_OFFSET(tmp_dir), read_path, write_path, },
  144. {"browser.chrome.show_toolbar", FIELD_OFFSET(show_toolbar_p), read_bool, write_bool},
  145. {"browser.chrome.show_url_bar", FIELD_OFFSET(show_url_p), read_bool, write_bool},
  146. {"browser.chrome.show_directory_buttons", FIELD_OFFSET(show_directory_buttons_p), read_bool, write_bool},
  147. {"browser.chrome.show_menubar", FIELD_OFFSET(show_menubar_p), read_bool, write_bool},
  148. {"browser.chrome.show_status_bar", FIELD_OFFSET(show_bottom_status_bar_p), read_bool, write_bool},
  149. {"browser.fancy_ftp", FIELD_OFFSET(fancy_ftp_p), read_bool, write_bool},
  150. #ifndef NO_SECURITY
  151. {"browser.chrome.show_security_bar", FIELD_OFFSET(show_security_bar_p), read_bool, write_bool},
  152. #endif
  153. {"browser.cache.memory_cache_size", FIELD_OFFSET(memory_cache_size), read_int, write_int},
  154. {"browser.cache.disk_cache_size", FIELD_OFFSET(disk_cache_size), read_int, write_int},
  155. {"browser.cache.directory", FIELD_OFFSET(cache_dir), read_path, write_path, },
  156. {"browser.cache.check_doc_frequency", FIELD_OFFSET(verify_documents), read_int, write_int},
  157. /* spider begin */
  158. {"browser.sarcache.directory", FIELD_OFFSET(sar_cache_dir), read_path, write_path, },
  159. /* spider end */
  160. {"browser.cache.disk_cache_ssl", FIELD_OFFSET(cache_ssl_p), read_bool, write_bool},
  161. {"browser.bookmark_file", FIELD_OFFSET(bookmark_file), read_path, write_path, },
  162. {"browser.history_file", FIELD_OFFSET(history_file), read_path, write_path, },
  163. {"browser.chrome.toolbar_style", FIELD_OFFSET(toolbar_style), read_int, write_int},
  164. {"browser.chrome.toolbar_tips", FIELD_OFFSET(toolbar_tips_p), read_bool, write_bool},
  165. {"browser.startup.page", FIELD_OFFSET(browser_startup_page), read_int, write_int},
  166. {"browser.startup.homepage", FIELD_OFFSET(home_document), read_str, write_str},
  167. {"browser.underline_anchors", FIELD_OFFSET(underline_links_p), read_bool, write_bool},
  168. {"browser.link_expiration", FIELD_OFFSET(global_history_expiration), read_int, write_int},
  169. {"browser.startup.license_accepted", FIELD_OFFSET(license_accepted), read_str, write_str},
  170. {"browser.user_history_file", FIELD_OFFSET(user_history_file), read_path, write_path, },
  171. {"browser.use_document_fonts", FIELD_OFFSET(use_doc_fonts), read_int, write_int},
  172. {"browser.enable_webfonts", FIELD_OFFSET(enable_webfonts), read_bool, write_bool},
  173. {"browser.foreground_color", FIELD_OFFSET(text_color), read_color, write_color},
  174. {"browser.background_color", FIELD_OFFSET(background_color), read_color, write_color},
  175. {"browser.anchor_color", FIELD_OFFSET(links_color), read_color, write_color},
  176. {"browser.visited_color", FIELD_OFFSET(vlinks_color), read_color, write_color},
  177. {"browser.use_document_colors", FIELD_OFFSET(use_doc_colors), read_bool, write_bool},
  178. {"browser.enable_style_sheets", FIELD_OFFSET(enable_style_sheet), read_bool, write_bool},
  179.  
  180. #ifdef EDITOR
  181. /* The editor preferences haven't all been defined yet */
  182. {"editor.show_character_toolbar", FIELD_OFFSET(editor_character_toolbar), read_bool, write_bool},
  183. {"editor.show_paragraph_toolbar", FIELD_OFFSET(editor_paragraph_toolbar), read_bool, write_bool},
  184. {"editor.author", FIELD_OFFSET(editor_author_name), read_str, write_str},
  185. {"editor.html_editor", FIELD_OFFSET(editor_html_editor), read_path, write_path, },
  186. {"editor.image_editor", FIELD_OFFSET(editor_image_editor), read_path, write_path, },
  187. {"editor.template_location", FIELD_OFFSET(editor_document_template), read_str, write_str},
  188. #ifdef HELLFREEZE
  189. {"editor.auto_save_delay", FIELD_OFFSET(editor_autosave_period), int32},
  190. #endif
  191. {"editor.use_custom_colors", FIELD_OFFSET(editor_custom_colors), read_bool, write_bool},
  192. {"editor.background_color", FIELD_OFFSET(editor_background_color), read_color, write_color},
  193. {"editor.text_color", FIELD_OFFSET(editor_normal_color), read_color, write_color},
  194. {"editor.link_color", FIELD_OFFSET(editor_link_color), read_color, write_color},
  195. {"editor.active_link_color", FIELD_OFFSET(editor_active_color), read_color, write_color},
  196. {"editor.followed_link_color", FIELD_OFFSET(editor_followed_color), read_color, write_color},
  197. {"editor.background_image", FIELD_OFFSET(editor_background_image), read_path, write_path, },
  198. {"editor.publish_keep_links", FIELD_OFFSET(editor_maintain_links), read_bool, write_bool},
  199. {"editor.publish_keep_images", FIELD_OFFSET(editor_keep_images), read_bool, write_bool},
  200. {"editor.publish_location", FIELD_OFFSET(editor_publish_location), read_str, write_str},
  201. {"editor.publish_username", FIELD_OFFSET(editor_publish_username), read_str, write_str},
  202. {"editor.publish_password", FIELD_OFFSET(editor_publish_password), read_str, write_str},
  203. {"editor.publish_save_password", FIELD_OFFSET(editor_save_publish_password), read_bool, write_bool},
  204. {"editor.publish_browse_location", FIELD_OFFSET(editor_browse_location), read_str, write_str},
  205. {"editor.show_copyright", FIELD_OFFSET(editor_copyright_hint), read_bool, write_bool},
  206. #endif
  207.  
  208. #ifdef FORTEZZA
  209. {"fortezza.toggle", FIELD_OFFSET(fortezza_toggle), read_int, write_int},
  210. {"fortezza.timeout", FIELD_OFFSET(fortezza_timeout), read_int, write_int},
  211. #endif
  212.  
  213. {"general.startup.browser", FIELD_OFFSET(startup_browser_p), read_bool, write_bool},
  214. {"general.startup.mail", FIELD_OFFSET(startup_mail_p), read_bool, write_bool},
  215. {"general.startup.news", FIELD_OFFSET(startup_news_p), read_bool, write_bool},
  216. {"general.startup.editor", FIELD_OFFSET(startup_editor_p), read_bool, write_bool},
  217. {"general.startup.conference", FIELD_OFFSET(startup_conference_p), read_bool, write_bool},
  218. {"general.startup.netcaster", FIELD_OFFSET(startup_netcaster_p), read_bool, write_bool},
  219. {"general.startup.calendar", FIELD_OFFSET(startup_calendar_p), read_bool, write_bool},
  220. {"general.always_load_images", FIELD_OFFSET(autoload_images_p), read_bool, write_bool},
  221. {"general.help_source.site", FIELD_OFFSET(help_source_site), read_int, write_int},
  222. {"general.help_source.url", FIELD_OFFSET(help_source_url), read_str, write_str},
  223.  
  224. {"helpers.global_mime_types_file", FIELD_OFFSET(global_mime_types_file), read_path, write_path, },
  225. {"helpers.private_mime_types_file", FIELD_OFFSET(private_mime_types_file), read_path, write_path, },
  226. {"helpers.global_mailcap_file", FIELD_OFFSET(global_mailcap_file), read_path, write_path, },
  227. {"helpers.private_mailcap_file", FIELD_OFFSET(private_mailcap_file), read_path, write_path, },
  228.  
  229. {"images.dither", FIELD_OFFSET(dither_images), read_str, write_str},
  230. {"images.incremental_display", FIELD_OFFSET(streaming_images), read_bool, write_bool},
  231.  
  232. {"intl.character_set", FIELD_OFFSET(doc_csid), read_int, write_int},
  233. {"intl.font_charset", FIELD_OFFSET(font_charset), read_char_set, write_char_set},
  234. {"intl.font_spec_list", FIELD_OFFSET(font_spec_list), read_font_spec, write_font_spec},
  235. {"intl.accept_languages", FIELD_OFFSET(lang_regions), read_str, write_str},
  236.  
  237. {"mail.play_sound", FIELD_OFFSET(enable_biff), read_bool, write_bool},
  238. {"mail.strictly_mime", FIELD_OFFSET(qp_p), read_bool, write_bool},
  239. {"mail.file_attach_binary", FIELD_OFFSET(file_attach_binary), read_bool, write_bool},
  240. {"mail.deliver_immediately", FIELD_OFFSET(queue_for_later_p), read_bool, write_bool},
  241. {"mail.default_cc", FIELD_OFFSET(mail_bcc), read_str, write_str},
  242. {"mail.default_fcc", FIELD_OFFSET(mail_fcc), read_path, write_path, },
  243. {"mail.cc_self", FIELD_OFFSET(mailbccself_p), read_bool, write_bool},
  244. {"mail.use_fcc", FIELD_OFFSET(mailfcc_p), read_bool, write_bool},
  245. {"mail.auto_quote", FIELD_OFFSET(autoquote_reply), read_bool, write_bool},
  246. {"mail.html_compose", FIELD_OFFSET(send_html_msg), read_bool, write_bool},
  247. /* K&R says that enum types are int's... */
  248. {"mail.quoted_style", FIELD_OFFSET(citation_font), read_int, write_int},
  249. {"mail.quoted_size", FIELD_OFFSET(citation_size), read_int, write_int},
  250. {"mail.citation_color", FIELD_OFFSET(citation_color), read_str, write_str},
  251. {"mail.identity.username", FIELD_OFFSET(real_name), read_str, write_str},
  252. {"mail.identity.useremail", FIELD_OFFSET(email_address), read_str, write_str},
  253. {"mail.identity.organization", FIELD_OFFSET(organization), read_str, write_str},
  254. {"mail.identity.reply_to", FIELD_OFFSET(reply_to_address), read_str, write_str, },
  255. {"mail.signature_file", FIELD_OFFSET(signature_file), read_path, write_path, },
  256. {"mail.attach_vcard", FIELD_OFFSET(attach_address_card), read_bool, write_bool},
  257. {"mail.addr_book.lastnamefirst", FIELD_OFFSET(addr_book_lastname_first), read_bool, write_bool},
  258. /*
  259.  * This is no good on machines where ints are less than four bytes.
  260.  * In those cases, signature_date will have to be a time_t.
  261.  */
  262. {"mail.signature_date", FIELD_OFFSET(signature_date), read_int, write_int},
  263. {"mail.use_movemail", FIELD_OFFSET(use_movemail_p), read_bool, write_bool},
  264. {"mail.use_builtin_movemail", FIELD_OFFSET(builtin_movemail_p), read_bool, write_bool},
  265. {"mail.movemail_program", FIELD_OFFSET(movemail_program), read_path, write_path, },
  266. {"mail.pop_name", FIELD_OFFSET(pop3_user_id), read_str, write_str},
  267. {"mail.directory", FIELD_OFFSET(mail_directory), read_path, write_path, },
  268. {"mail.imap.server_sub_directory", FIELD_OFFSET(imap_mail_directory), read_path, write_path, },
  269. {"mail.imap.root_dir", FIELD_OFFSET(imap_mail_local_directory), read_path, write_path, },
  270. {"mail.check_time", FIELD_OFFSET(biff_interval), read_int, write_int},
  271. {"mail.check_new_mail", FIELD_OFFSET(auto_check_mail), read_bool, write_bool},
  272. {"mail.leave_on_server", FIELD_OFFSET(pop3_leave_mail_on_server), read_bool, write_bool},
  273. {"mail.imap.local_copies", FIELD_OFFSET(imap_local_copies), read_bool, write_bool},
  274. {"mail.imap.server_ssl", FIELD_OFFSET(imap_server_ssl), read_bool, write_bool},
  275. {"mail.limit_message_size", FIELD_OFFSET(pop3_msg_size_limit_p), read_bool, write_bool},
  276. {"mail.max_size", FIELD_OFFSET(pop3_msg_size_limit), read_int, write_int},
  277. {"mail.prompt_purge_threshhold", FIELD_OFFSET(msg_prompt_purge_threshold), read_bool, write_bool},
  278. {"mail.purge_threshhold", FIELD_OFFSET(msg_purge_threshold), read_int, write_int},
  279. {"mail.use_mapi_server", FIELD_OFFSET(use_ns_mapi_server), read_bool, write_bool},
  280. {"mail.movemail_warn", FIELD_OFFSET(movemail_warn), read_bool, write_bool},
  281. {"mail.server_type", FIELD_OFFSET(mail_server_type), read_int, write_int},
  282. {"mail.fixed_width_messages", FIELD_OFFSET(fixed_message_font_p), read_bool, write_bool},
  283. {"mail.empty_trash", FIELD_OFFSET(emptyTrash), read_bool, write_bool},
  284. {"mail.remember_password", FIELD_OFFSET(rememberPswd), read_bool, write_bool},
  285. {"mail.support_skey", FIELD_OFFSET(support_skey), read_bool, write_bool},
  286. {"mail.pop_password", FIELD_OFFSET(pop3_password), read_str, write_str},
  287. {"mail.thread_mail", FIELD_OFFSET(mail_thread_p), read_bool, write_bool},
  288. {"mail.pane_config", FIELD_OFFSET(mail_pane_style), read_int, write_int},
  289. {"mail.sort_by", FIELD_OFFSET(mail_sort_style), read_int, write_int},
  290. {"mail.default_html_action", FIELD_OFFSET(html_def_action), read_int, write_int},
  291. {"mail.imap.delete_is_move_to_trash", FIELD_OFFSET(imap_delete_is_move_to_trash), read_bool, write_bool},
  292.  
  293. {"mailnews.reuse_message_window", FIELD_OFFSET(reuse_msg_window), read_bool, write_bool},
  294. {"mailnews.reuse_thread_window", FIELD_OFFSET(reuse_thread_window), read_bool, write_bool},
  295. {"mailnews.message_in_thread_window", FIELD_OFFSET(msg_in_thread_window), read_bool, write_bool},
  296. {"mailnews.wraplength", FIELD_OFFSET(msg_wrap_length), read_int, write_int},
  297. {"mailnews.nicknames_only", FIELD_OFFSET(expand_addr_nicknames_only), read_bool, write_bool},
  298. {"mailnews.reply_on_top", FIELD_OFFSET(reply_on_top), read_int, write_int},
  299. {"mailnews.reply_with_extra_lines", FIELD_OFFSET(reply_with_extra_lines), read_int, write_int},
  300.  
  301. {"network.cookie.warnAboutCookies", FIELD_OFFSET(warn_accept_cookie), read_bool, write_bool},
  302. {"network.cookie.cookieBehavior", FIELD_OFFSET(accept_cookie), read_int, write_int},
  303. {"network.hosts.smtp_server", FIELD_OFFSET(mailhost), read_str, write_str},
  304. {"network.hosts.pop_server", FIELD_OFFSET(pop3_host), read_str, write_str},
  305. {"network.max_connections", FIELD_OFFSET(max_connections), read_int, write_int},
  306. {"network.tcpbufsize", FIELD_OFFSET(network_buffer_size), read_int, write_int},
  307. {"network.hosts.nntp_server", FIELD_OFFSET(newshost), read_str, write_str},
  308. {"network.hosts.socks_server", FIELD_OFFSET(socks_host), read_str, write_str},
  309. {"network.hosts.socks_serverport", FIELD_OFFSET(socks_host_port), read_int, write_int},
  310. {"network.proxy.ftp", FIELD_OFFSET(ftp_proxy), read_str, write_str},
  311. {"network.proxy.ftp_port", FIELD_OFFSET(ftp_proxy_port), read_int, write_int},
  312. {"network.proxy.http", FIELD_OFFSET(http_proxy), read_str, write_str},
  313. {"network.proxy.http_port", FIELD_OFFSET(http_proxy_port), read_int, write_int},
  314. {"network.proxy.gopher", FIELD_OFFSET(gopher_proxy), read_str, write_str},
  315. {"network.proxy.gopher_port", FIELD_OFFSET(gopher_proxy_port), read_int, write_int},
  316. {"network.proxy.wais", FIELD_OFFSET(wais_proxy), read_str, write_str},
  317. {"network.proxy.wais_port", FIELD_OFFSET(wais_proxy_port), read_int, write_int},
  318. #ifndef NO_SECURITY
  319. {"network.proxy.ssl", FIELD_OFFSET(https_proxy), read_str, write_str},
  320. {"network.proxy.ssl_port", FIELD_OFFSET(https_proxy_port), read_int, write_int},
  321. #endif
  322. {"network.proxy.no_proxies_on", FIELD_OFFSET(no_proxy), read_str, write_str},
  323. {"network.proxy.type", FIELD_OFFSET(proxy_mode), read_int, write_int},
  324. {"network.proxy.autoconfig_url", FIELD_OFFSET(proxy_url), read_str, write_str},
  325.  
  326. {"news.default_cc", FIELD_OFFSET(news_bcc), read_str, write_str},
  327. {"news.default_fcc", FIELD_OFFSET(news_fcc), read_path, write_path, },
  328. {"news.cc_self", FIELD_OFFSET(newsbccself_p), read_bool, write_bool},
  329. {"news.use_fcc", FIELD_OFFSET(newsfcc_p), read_bool, write_bool},
  330. {"news.directory", FIELD_OFFSET(newsrc_directory), read_path, write_path, },
  331. {"news.notify.on", FIELD_OFFSET(news_notify_on), read_bool, write_bool},
  332. {"news.max_articles", FIELD_OFFSET(news_max_articles), read_int, write_int},
  333. {"news.cache_xover", FIELD_OFFSET(news_cache_xover), read_bool, write_bool},
  334. {"news.show_first_unread", FIELD_OFFSET(show_first_unread_p), read_bool, write_bool},
  335. {"news.sash_geometry", FIELD_OFFSET(news_sash_geometry), read_str, write_str},
  336. {"news.thread_news", FIELD_OFFSET(news_thread_p), read_bool, write_bool},
  337. {"news.pane_config", FIELD_OFFSET(news_pane_style), read_int, write_int},
  338. {"news.sort_by", FIELD_OFFSET(news_sort_style), read_int, write_int},
  339. {"news.keep.method", FIELD_OFFSET(news_keep_method), read_int, write_int},
  340. {"news.keep.days", FIELD_OFFSET(news_keep_days), read_int, write_int},
  341. {"news.keep.count", FIELD_OFFSET(news_keep_count), read_int, write_int},
  342. {"news.keep.only_unread", FIELD_OFFSET(news_keep_only_unread), read_bool, write_bool},
  343. {"news.remove_bodies.by_age", FIELD_OFFSET(news_remove_bodies_by_age), read_bool, write_bool},
  344. {"news.remove_bodies.days", FIELD_OFFSET(news_remove_bodies_days), read_int, write_int},
  345. {"news.server_port", FIELD_OFFSET(news_server_port), read_int, write_int},
  346. {"news.server_is_secure", FIELD_OFFSET(news_server_secure), read_bool, write_bool},
  347.  
  348. {"offline.startup_mode", FIELD_OFFSET(offline_startup_mode), read_int, write_int},
  349. {"offline.news.download.unread_only", FIELD_OFFSET(offline_news_download_unread), read_bool, write_bool},
  350. {"offline.news.download.by_date", FIELD_OFFSET(offline_news_download_by_date), read_bool, write_bool},
  351. {"offline.news.download.use_days", FIELD_OFFSET(offline_news_download_use_days), read_bool, write_bool},
  352. {"offline.news.download.days", FIELD_OFFSET(offline_news_download_days), read_int, write_int},
  353. {"offline.news.download.increments", FIELD_OFFSET(offline_news_download_inc), read_int, write_int},
  354.  
  355. {"security.email_as_ftp_password", FIELD_OFFSET(email_anonftp), read_bool, write_bool},
  356. {"security.submit_email_forms", FIELD_OFFSET(email_submit), read_bool, write_bool},
  357. {"security.warn_entering_secure", FIELD_OFFSET(enter_warn), read_bool, write_bool, True},
  358. {"security.warn_leaving_secure", FIELD_OFFSET(leave_warn), read_bool, write_bool, True},
  359. {"security.warn_viewing_mixed", FIELD_OFFSET(mixed_warn), read_bool, write_bool, True},
  360. {"security.warn_submit_insecure", FIELD_OFFSET(submit_warn), read_bool, write_bool, True},
  361. #ifdef JAVA
  362. {"security.enable_java", FIELD_OFFSET(enable_java), read_bool, write_bool},
  363. #endif
  364. {"javascript.enabled", FIELD_OFFSET(enable_javascript), read_bool, write_bool},
  365. {"security.enable_ssl2", FIELD_OFFSET(ssl2_enable), read_bool, write_bool, True},
  366. {"security.enable_ssl3", FIELD_OFFSET(ssl3_enable), read_bool, write_bool, True},
  367. {"security.ciphers", FIELD_OFFSET(cipher), read_str, write_str, True},
  368. {"security.default_personal_cert", FIELD_OFFSET(def_user_cert), read_str, write_str, True},
  369. {"security.use_password", FIELD_OFFSET(use_password), read_bool, write_bool, True},
  370. {"security.ask_for_password", FIELD_OFFSET(ask_password), read_int, write_int, True},
  371. {"security.password_lifetime", FIELD_OFFSET(password_timeout), read_int, write_int, True},
  372. {"custtoolbar.has_toolbar_folder", FIELD_OFFSET(has_toolbar_folder), read_bool, write_bool},
  373. {"custtoolbar.personal_toolbar_folder", FIELD_OFFSET(personal_toolbar_folder), read_str, write_str},
  374. {"print.print_command", FIELD_OFFSET(print_command), read_str, write_str},
  375. {"print.print_reversed", FIELD_OFFSET(print_reversed), read_bool, write_bool},
  376. {"print.print_color", FIELD_OFFSET(print_color), read_bool, write_bool},
  377. {"print.print_landscape", FIELD_OFFSET(print_landscape), read_bool, write_bool},
  378. {"print.print_paper_size", FIELD_OFFSET(print_paper_size), read_int, write_int},
  379.  
  380.  
  381. {"taskbar.floating", FIELD_OFFSET(task_bar_floating), read_bool, write_bool},
  382. {"taskbar.horizontal", FIELD_OFFSET(task_bar_horizontal), read_bool, write_bool},
  383. {"taskbar.ontop", FIELD_OFFSET(task_bar_ontop), read_bool, write_bool},
  384. {"taskbar.x", FIELD_OFFSET(task_bar_x), read_int, write_int},
  385. {"taskbar.y", FIELD_OFFSET(task_bar_y), read_int, write_int},
  386.  
  387. {"custtoolbar.Browser.Navigation_Toolbar.position", FIELD_OFFSET(browser_navigation_toolbar_position), read_int, write_int},
  388. {"custtoolbar.Browser.Navigation_Toolbar.showing", FIELD_OFFSET(browser_navigation_toolbar_showing), read_bool, write_bool},
  389. {"custtoolbar.Browser.Navigation_Toolbar.open", FIELD_OFFSET(browser_navigation_toolbar_open), read_bool, write_bool},
  390.  
  391. {"custtoolbar.Browser.Location_Toolbar.position", FIELD_OFFSET(browser_location_toolbar_position), read_int, write_int},
  392. {"custtoolbar.Browser.Location_Toolbar.showing", FIELD_OFFSET(browser_location_toolbar_showing), read_bool, write_bool},
  393. {"custtoolbar.Browser.Location_Toolbar.open", FIELD_OFFSET(browser_location_toolbar_open), read_bool, write_bool},
  394.  
  395. {"custtoolbar.Browser.Personal_Toolbar.position", FIELD_OFFSET(browser_personal_toolbar_position), read_int, write_int},
  396. {"custtoolbar.Browser.Personal_Toolbar.showing", FIELD_OFFSET(browser_personal_toolbar_showing), read_bool, write_bool},
  397. {"custtoolbar.Browser.Personal_Toolbar.open", FIELD_OFFSET(browser_personal_toolbar_open), read_bool, write_bool},
  398.  
  399. {"custtoolbar.Messenger.Navigation_Toolbar.position", FIELD_OFFSET(messenger_navigation_toolbar_position), read_int, write_int},
  400. {"custtoolbar.Messenger.Navigation_Toolbar.showing", FIELD_OFFSET(messenger_navigation_toolbar_showing), read_bool, write_bool},
  401. {"custtoolbar.Messenger.Navigation_Toolbar.open", FIELD_OFFSET(messenger_navigation_toolbar_open), read_bool, write_bool},
  402.  
  403. {"custtoolbar.Messenger.Location_Toolbar.position", FIELD_OFFSET(messenger_location_toolbar_position), read_int, write_int},
  404. {"custtoolbar.Messenger.Location_Toolbar.showing", FIELD_OFFSET(messenger_location_toolbar_showing), read_bool, write_bool},
  405. {"custtoolbar.Messenger.Location_Toolbar.open", FIELD_OFFSET(messenger_location_toolbar_open), read_bool, write_bool},
  406.  
  407. {"custtoolbar.Messages.Navigation_Toolbar.position", FIELD_OFFSET(messages_navigation_toolbar_position), read_int, write_int},
  408. {"custtoolbar.Messages.Navigation_Toolbar.showing", FIELD_OFFSET(messages_navigation_toolbar_showing), read_bool, write_bool},
  409. {"custtoolbar.Messages.Navigation_Toolbar.open", FIELD_OFFSET(messages_navigation_toolbar_open), read_bool, write_bool},
  410.  
  411. {"custtoolbar.Messages.Location_Toolbar.position", FIELD_OFFSET(messages_location_toolbar_position), read_int, write_int},
  412. {"custtoolbar.Messages.Location_Toolbar.showing", FIELD_OFFSET(messages_location_toolbar_showing), read_bool, write_bool},
  413. {"custtoolbar.Messages.Location_Toolbar.open", FIELD_OFFSET(messages_location_toolbar_open), read_bool, write_bool},
  414.  
  415. {"custtoolbar.Folders.Navigation_Toolbar.position", FIELD_OFFSET(folders_navigation_toolbar_position), read_int, write_int},
  416. {"custtoolbar.Folders.Navigation_Toolbar.showing", FIELD_OFFSET(folders_navigation_toolbar_showing), read_bool, write_bool},
  417. {"custtoolbar.Folders.Navigation_Toolbar.open", FIELD_OFFSET(folders_navigation_toolbar_open), read_bool, write_bool},
  418.  
  419. {"custtoolbar.Folders.Location_Toolbar.position", FIELD_OFFSET(folders_location_toolbar_position), read_int, write_int},
  420. {"custtoolbar.Folders.Location_Toolbar.showing", FIELD_OFFSET(folders_location_toolbar_showing), read_bool, write_bool},
  421. {"custtoolbar.Folders.Location_Toolbar.open", FIELD_OFFSET(folders_location_toolbar_open), read_bool, write_bool},
  422.  
  423. {"custtoolbar.Address_Book.Address_Book_Toolbar.position", FIELD_OFFSET(address_book_address_book_toolbar_position), read_int, write_int},
  424. {"custtoolbar.Address_Book.Address_Book_Toolbar.showing", FIELD_OFFSET(address_book_address_book_toolbar_showing), read_bool, write_bool},
  425. {"custtoolbar.Address_Book.Address_Book_Toolbar.open", FIELD_OFFSET(address_book_address_book_toolbar_open), read_bool, write_bool},
  426.  
  427. {"custtoolbar.Compose_Message.Message_Toolbar.position", FIELD_OFFSET(compose_message_message_toolbar_position), read_int, write_int},
  428. {"custtoolbar.Compose_Message.Message_Toolbar.showing", FIELD_OFFSET(compose_message_message_toolbar_showing), read_bool, write_bool},
  429. {"custtoolbar.Compose_Message.Message_Toolbar.open", FIELD_OFFSET(compose_message_message_toolbar_open), read_bool, write_bool},
  430.  
  431. {"custtoolbar.Composer.Composition_Toolbar.position", FIELD_OFFSET(composer_composition_toolbar_position), read_int, write_int},
  432. {"custtoolbar.Composer.Composition_Toolbar.showing", FIELD_OFFSET(composer_composition_toolbar_showing), read_bool, write_bool},
  433. {"custtoolbar.Composer.Composition_Toolbar.open", FIELD_OFFSET(composer_composition_toolbar_open), read_bool, write_bool},
  434.  
  435. {"custtoolbar.Composer.Formatting_Toolbar.position", FIELD_OFFSET(composer_formatting_toolbar_position), read_int, write_int},
  436. {"custtoolbar.Composer.Formatting_Toolbar.showing", FIELD_OFFSET(composer_formatting_toolbar_showing), read_bool, write_bool},
  437. {"custtoolbar.Composer.Formatting_Toolbar.open", FIELD_OFFSET(composer_formatting_toolbar_open), read_bool, write_bool},
  438.  
  439. {"browser.win_width", FIELD_OFFSET(browser_win_width), read_int, write_int},
  440. {"browser.win_height",FIELD_OFFSET(browser_win_height), read_int, write_int},
  441.  
  442. {"mail.compose.win_width", FIELD_OFFSET(mail_compose_win_width), read_int, write_int},
  443. {"mail.compose.win_height",FIELD_OFFSET(mail_compose_win_height), read_int, write_int},
  444.  
  445. {"editor.win_width", FIELD_OFFSET(editor_win_width), read_int, write_int},
  446. {"editor.win_height",FIELD_OFFSET(editor_win_height), read_int, write_int},
  447.  
  448. {"mail.folder.win_width", FIELD_OFFSET(mail_folder_win_width), read_int, write_int},
  449. {"mail.folder.win_height",FIELD_OFFSET(mail_folder_win_height), read_int, write_int},
  450.  
  451. {"mail.msg.win_width", FIELD_OFFSET(mail_msg_win_width), read_int, write_int},
  452. {"mail.msg.win_height",FIELD_OFFSET(mail_msg_win_height), read_int, write_int},
  453.  
  454. {"mail.thread.win_width", FIELD_OFFSET(mail_thread_win_width), read_int, write_int},
  455. {"mail.thread.win_height",FIELD_OFFSET(mail_thread_win_height), read_int, write_int},
  456.  
  457. };
  458.  
  459. static int num_prefs = sizeof(pref_map) / sizeof(pref_map[0]);
  460.  
  461. /*
  462.  * XFE_UpgradePrefs
  463.  * Upgrades the preferences to the Javascript file.
  464.  */
  465. Bool
  466. XFE_UpgradePrefs(char* filename, XFE_GlobalPrefs* prefs)
  467. {
  468.     int i;
  469.     char* tmp = NULL;
  470.     void* field;
  471.     Bool status;
  472.  
  473.     /*
  474.      * If we're not supposed to remember the password, replace
  475.      * the password with blank, and then restore it after saving.
  476.      */
  477.     if ( !prefs->rememberPswd ) {
  478.         tmp = prefs->pop3_password;
  479.         prefs->pop3_password = "";
  480.     }
  481.  
  482.     split_all_proxies(prefs);
  483.  
  484.     for ( i = 0; i < num_prefs; i++ ) {
  485.         field = GET_FIELD(pref_map[i], prefs);
  486.         pref_map[i].write_routine(pref_map[i].name, field);
  487.     }
  488.  
  489.     status = ( PREF_SavePrefFileAs(filename) == PREF_NOERROR ) ? TRUE : FALSE;
  490.  
  491.     if ( !prefs->rememberPswd ) {
  492.         prefs->pop3_password = tmp;
  493.     }
  494.  
  495.     return status;
  496. }
  497.  
  498.  
  499. /*
  500.  * XFE_SavePrefs
  501.  * Save the preferences to the Javascript file.
  502.  */
  503. Bool
  504. XFE_SavePrefs(char* filename, XFE_GlobalPrefs* prefs)
  505. {
  506.     int i;
  507.     char* tmp = NULL;
  508.     void* field;
  509.     Bool status;
  510.  
  511.     /*
  512.      * If we're not supposed to remember the password, replace
  513.      * the password with blank, and then restore it after saving.
  514.      */
  515.     if ( !prefs->rememberPswd ) {
  516.         tmp = prefs->pop3_password;
  517.         prefs->pop3_password = "";
  518.     }
  519.  
  520.     /* split_all_proxies(prefs); */
  521.  
  522.     for ( i = 0; i < num_prefs; i++ ) {
  523.         if (! pref_map[i].upgrade_only) {
  524.             field = GET_FIELD(pref_map[i], prefs);
  525.             pref_map[i].write_routine(pref_map[i].name, field);
  526.         }
  527.     }
  528.  
  529.     status = ( PREF_SavePrefFileAs(filename) == PREF_NOERROR ) ? TRUE : FALSE;
  530.  
  531.     if ( !prefs->rememberPswd ) {
  532.         prefs->pop3_password = tmp;
  533.     }
  534.  
  535.     return status;
  536. }
  537.  
  538.  
  539. /*
  540.  * read_old_prefs_file
  541.  * Tries to read all of the old preferences files that might be on
  542.  * disk.  Starts at most recent naming convention, and works its
  543.  * way back.
  544.  */
  545. static Bool
  546. read_old_prefs_file(XFE_GlobalPrefs* prefs)
  547. {
  548.     int i;
  549.     struct stat st;
  550.     char buf[1024];
  551.     char* home_dir;
  552.     char* filenames[] = {"%s/.netscape/preferences",
  553.                          "%s/.netscape-preferences",
  554.                          "%s/.MCOM-preferences",};
  555.  
  556.     /* Code stolen from mozilla.c */
  557.     home_dir = getenv ("HOME");
  558.     if (!home_dir || !*home_dir) {
  559.         /* Default to "/" in case a root shell is running in dire straits. */
  560.         struct passwd *pw = getpwuid(getuid());
  561.         home_dir = pw ? pw->pw_dir : "/";
  562.     } else {
  563.         char *slash;
  564.         /* Trim trailing slashes just to be fussy. */
  565.         while ((slash = strrchr(home_dir, '/')) && slash[1] == '\0')
  566.         *slash = '\0';
  567.     }
  568.  
  569.     for ( i = 0; i < sizeof(filenames)/sizeof(filenames[0]); i++ ) {
  570.         PR_snprintf(buf, sizeof(buf), filenames[i], home_dir);
  571.         if ( stat(buf, &st) == 0 ) {
  572.             return XFE_OldReadPrefs(buf, prefs);
  573.         }
  574.     }
  575.  
  576.     return FALSE;
  577. }
  578.  
  579.  
  580. /*
  581.  * XFE_ReadPrefs
  582.  * Read preferences from the Javascript file.
  583.  */
  584. Bool
  585. XFE_ReadPrefs(char* filename, XFE_GlobalPrefs* prefs)
  586. {
  587.     int i;
  588.     void* field;
  589.     struct stat st;
  590.  
  591.     XFE_DefaultPrefs(prefs);
  592.     xfe_prefs_from_environment(prefs);
  593.  
  594.     if ( stat(filename, &st) == -1 ) {
  595.         if ( read_old_prefs_file(prefs) == FALSE ) {
  596.             return FALSE;
  597.         }
  598.     }
  599.  
  600.     if ( evaluate_preferences_file(filename) == FALSE ) {
  601.         return FALSE;
  602.     }
  603.  
  604.     def = 0; /* Indicate that we want to read real prefs, not defaults */
  605.     for ( i = 0; i < num_prefs; i++ ) {
  606.         field = GET_FIELD(pref_map[i], prefs);
  607.         pref_map[i].read_routine(pref_map[i].name, field);
  608.     }
  609.  
  610.     tweaks(prefs);
  611.  
  612.     return TRUE;
  613. }
  614.  
  615.  
  616. /*
  617.  * XFE_DefaultPrefs
  618.  */
  619. void
  620. XFE_DefaultPrefs(XFE_GlobalPrefs* prefs)
  621. {
  622.     int i;
  623.     void* field;
  624.     char* email_addr;
  625.     char* real_name;
  626.     char* organization;
  627.  
  628.     for ( i = 0; i < num_prefs; i++ ) {
  629.         field = GET_FIELD(pref_map[i], prefs);
  630.         pref_map[i].read_routine(pref_map[i].name, field);
  631.     }
  632.  
  633.     prefs->doc_csid = XFE_GetDefaultCSID();
  634.     fe_DefaultUserInfo(&email_addr, &real_name, False);
  635.     organization = xfe_organization();
  636.  
  637.     REPLACE_STRING(prefs->email_address, email_addr ? 
  638.                                          email_addr : 
  639.                                          XP_GetString(XFE_UNKNOWN_EMAIL_ADDR));
  640.     REPLACE_STRING(prefs->email_address, email_addr);
  641.     REPLACE_STRING(prefs->real_name, real_name);
  642.     REPLACE_STRING(prefs->organization, organization);
  643.  
  644.     if ( organization ) free(organization);
  645.  
  646.     tweaks(prefs);
  647. }
  648.  
  649.  
  650. /*
  651.  * evaluate_preferences_file
  652.  */
  653. static Bool
  654. evaluate_preferences_file(char* filename)
  655. {
  656.     FILE* file;
  657.     char* pref_buf;
  658.     struct stat stat_buf;
  659.     size_t size;
  660.     Bool ret;
  661.  
  662.     if ( stat(filename, &stat_buf) == -1 ) {
  663.         return FALSE;
  664.     }
  665.  
  666.     size = stat_buf.st_size;
  667.  
  668.     if ( (file = fopen(filename, "r")) == NULL ) {
  669.         return FALSE;
  670.     }
  671.  
  672.     if ( (pref_buf = malloc(size)) == NULL ) {
  673.         return FALSE;
  674.     }
  675.  
  676.     if ( fread(pref_buf, sizeof(char), size, file) != size ) {
  677.         return FALSE;
  678.     }
  679.  
  680.     ret = (Bool) PREF_EvaluateJSBuffer(pref_buf, size);
  681.     free(pref_buf);
  682.     return ret;
  683. }
  684.  
  685.  
  686. /*
  687.  * fix_path
  688.  */
  689. static void
  690. fix_path(void* arg)
  691. {
  692.     char** path = (char**) arg;
  693.     char* home = getenv ("HOME");
  694.  
  695.     if ( !home ) home = "";
  696.  
  697.     if ( *path && **path == '~') {
  698.         if ( (*path)[1] != '/' && (*path)[1] != 0) {
  699.             fprintf (stderr, XP_GetString(XFE_TILDE_USER_SYNTAX_DISALLOWED),
  700.                      XP_AppName);
  701.         } else {
  702.             char* new = (char*) malloc ( strlen(*path) + strlen(home) + 3 );
  703.             if ( new == NULL ) return;
  704.             strcpy(new, home);
  705.             if ( home[strlen(home)-1] != '/' ) strcat (new, "/");
  706.             if ( (*path)[1] && (*path)[2] ) strcat (new, (*path) + 2);
  707.             free ( *path );
  708.             *path = new;
  709.         }
  710.     }
  711. }
  712.  
  713.  
  714. /*
  715.  * split_all_proxies
  716.  * Trims the :port off the end of all of the proxies.
  717.  */
  718. static void
  719. split_all_proxies(XFE_GlobalPrefs* prefs)
  720. {
  721.     split_proxy(&prefs->socks_host, &prefs->socks_host_port, 0);
  722.     split_proxy(&prefs->ftp_proxy, &prefs->ftp_proxy_port, 0);
  723.     split_proxy(&prefs->http_proxy, &prefs->http_proxy_port, 0);
  724.     split_proxy(&prefs->gopher_proxy, &prefs->gopher_proxy_port, 0);
  725.     split_proxy(&prefs->wais_proxy, &prefs->wais_proxy_port, 0);
  726. #ifndef NO_SECURITY
  727.     split_proxy(&prefs->https_proxy, &prefs->https_proxy_port, 0);
  728. #endif
  729. }
  730.  
  731.  
  732. /*
  733.  * split_proxy
  734.  * Takes a proxy of the form "host:port".
  735.  * Trims the port off the end.
  736.  */
  737. static void
  738. split_proxy(char** proxy, int* port, int default_port)
  739. {
  740.     char* tmp;
  741.  
  742.     assert(port != NULL);
  743.  
  744.     if (tmp = strchr(*proxy, ':') ) {
  745.         *tmp = '\0';
  746.         *port = atoi(tmp+1);
  747.     } else {
  748.         /* If *port is set, we're upgrading from
  749.            a beta so don't overwrite with default_port */
  750.         if(!*port) {
  751.             *port = default_port;
  752.         }
  753.     }
  754. }
  755.  
  756.  
  757. /*
  758.  * xfe_prefs_from_environment
  759.  */
  760. static void
  761. xfe_prefs_from_environment (XFE_GlobalPrefs *prefs)
  762. {
  763.   /* Set some slots in the prefs structure based on the environment.
  764.    */
  765.   char *env;
  766.   if ((env = getenv ("WWW_HOME")))     StrAllocCopy (prefs->home_document,env);
  767.   if ((env = getenv ("NNTPSERVER")))   StrAllocCopy (prefs->newshost, env);
  768.   if ((env = getenv ("TMPDIR")))       StrAllocCopy (prefs->tmp_dir, env);
  769.  
  770.   if ((env = getenv ("NEWSRC")))
  771.     {
  772.       char *s;
  773.       StrAllocCopy (prefs->newsrc_directory, env);
  774.       s = strrchr (prefs->newsrc_directory, '/');
  775.       if (s) *s = 0;
  776.     }
  777.  
  778.   /* These damn proxy env vars *should* be set to "host:port" but apparently
  779.      for historical reasons they tend to be set to "http://host:port/proxy/"
  780.      so if there are any slashes in the name, extract the host and port as
  781.      if it were a URL.
  782.  
  783.      And, as extra BS, we need to map "http://host/" to "host:80".  FMH.
  784.    */
  785. #define PARSE_PROXY_ENV(NAME,VAR)                \
  786.     if ((env = getenv (NAME)))                    \
  787.       {                                \
  788.     char *new = (strchr (env, '/')                \
  789.              ? NET_ParseURL (env, GET_HOST_PART)    \
  790.              : strdup (env));                \
  791.         if (! strchr (new, ':'))                \
  792.       {                            \
  793.         char *new2 = (char *) malloc (strlen (new) + 10);    \
  794.         strcpy (new2, new);                    \
  795.         strcat (new2, ":80");                \
  796.         free (new);                        \
  797.         new = new2;                        \
  798.       }                            \
  799.     if (VAR) free (VAR);                    \
  800.     VAR = new;                        \
  801.       }
  802.   PARSE_PROXY_ENV ("ftp_proxy", prefs->ftp_proxy)
  803.   PARSE_PROXY_ENV ("http_proxy", prefs->http_proxy)
  804. #ifndef NO_SECURITY
  805.   PARSE_PROXY_ENV ("https_proxy", prefs->https_proxy)
  806. #endif
  807.   PARSE_PROXY_ENV ("gopher_proxy", prefs->gopher_proxy)
  808.   PARSE_PROXY_ENV ("wais_proxy", prefs->wais_proxy)
  809.   /* #### hack commas in some way? */
  810.   PARSE_PROXY_ENV ("no_proxy", prefs->no_proxy)
  811. #undef PARSE_PROXY_ENV
  812.  
  813.   if (prefs->organization) free (prefs->organization);
  814.   prefs->organization = xfe_organization ();
  815. }
  816.  
  817.  
  818. /* Hack yet another damned environment variable.
  819.    Returns a string for the organization, or "" if none.
  820.    Consults the ORGANIZATION environment variable, which
  821.    may be a string (the organization) or 
  822.  */
  823. static char *
  824. xfe_organization (void)
  825. {
  826.   char *e;
  827.  
  828.   e = getenv ("NEWSORG");    /* trn gives this priority. */
  829.   if (!e || !*e)
  830.     e = getenv ("ORGANIZATION");
  831.  
  832.   if (!e || !*e)
  833.     {
  834.       /* GNUS does this so it must be right... */
  835.       char *home = getenv ("HOME");
  836.       if (!home) home = "";
  837.       e = (char *) malloc (strlen (home) + 20);
  838.       strcpy (e, home);
  839.       strcat (e, "/.organization");
  840.     }
  841.   else
  842.     {
  843.       e = strdup (e);
  844.     }
  845.  
  846.   if (*e == '/')
  847.     {
  848.       FILE *f = fopen (e, "r");
  849.       if (f)
  850.     {
  851.       char buf [1024];
  852.       char *s = buf;
  853.       int left = sizeof (buf) - 5;
  854.       int read;
  855.       *s = 0;
  856.       while (1)
  857.         {
  858.           if (fgets (s, left, f))
  859.         read = strlen (s);
  860.           else
  861.         break;
  862.           left -= read;
  863.           s += read;
  864.           *s++ = '\t';
  865.         }
  866.       *s = 0;
  867.       fclose (f);
  868.       free (e);
  869.       e = strdup (fe_StringTrim (buf));
  870.     }
  871.       else
  872.     {
  873.       /* File unreadable - set e to "" */
  874.       *e = 0;
  875.     }
  876.     }
  877.  
  878.   if (! e) abort ();
  879.   return e;
  880. }
  881.  
  882.  
  883. /*
  884.  * XFE_GetDefaultCSID
  885.  */
  886. int16
  887. XFE_GetDefaultCSID(void)
  888. {
  889.   int16 csid;
  890.  
  891.   csid = 0;
  892.  
  893.   if ((fe_globalData.default_url_charset != NULL)
  894.       && (fe_globalData.default_url_charset[0] != 0))
  895.     csid = (INTL_CharSetNameToID((char *)fe_globalData.default_url_charset));
  896.  
  897.   if (csid)
  898.   {
  899.     if (csid == CS_JIS)
  900.     {
  901.         csid = CS_JIS_AUTO;
  902.     }
  903.     return csid;
  904.   }
  905.  
  906.   return (CS_LATIN1);
  907. }
  908.  
  909.  
  910. /*
  911.  * read_str
  912.  */
  913. static void
  914. read_str(char* name, void* field)
  915. {
  916.     char buf[4096];
  917.     int len = sizeof(buf);
  918.  
  919.     memset(buf, 0, len);
  920.  
  921.     if ( def ) {
  922.         PREF_GetDefaultCharPref(name, buf, &len);
  923.     } else {
  924.         PREF_GetCharPref(name, buf, &len);
  925.     }
  926.  
  927.     *(char**) field = strdup(buf);
  928. }
  929.  
  930.  
  931. /*
  932.  * write_str
  933.  */
  934. static void
  935. write_str(char* name, void* field)
  936. {
  937.     PREF_SetCharPref(name, *(char**) field ? *(char**) field : "");
  938. }
  939.  
  940.  
  941. /*
  942.  * read_bool
  943.  */
  944. static void
  945. read_bool(char* name, void* field)
  946. {
  947.     if ( def ) {
  948.         PREF_GetDefaultBoolPref(name, (Bool*) field);
  949.     } else {
  950.         PREF_GetBoolPref(name, (Bool*) field);
  951.     }
  952. }
  953.  
  954.  
  955. /*
  956.  * write_bool
  957.  */
  958. static void
  959. write_bool(char* name, void* field)
  960. {
  961.     PREF_SetBoolPref(name, *(Bool*) field);
  962. }
  963.  
  964.  
  965. /*
  966.  * read_int
  967.  */
  968. static void
  969. read_int(char* name, void* field)
  970. {
  971.     if ( def ) {
  972.         PREF_GetDefaultIntPref(name, (int32*) field);
  973.     } else {
  974.         PREF_GetIntPref(name, (int32*) field);
  975.     }
  976. }
  977.  
  978.  
  979. /*
  980.  * write_int
  981.  */
  982. static void
  983. write_int(char* name, void* field)
  984. {
  985.     PREF_SetIntPref(name, *(int32*) field);
  986. }
  987.  
  988.  
  989. /*
  990.  * Paths
  991.  * If there's a tilde in the path, we expand it to the user's
  992.  * home directory.
  993.  */
  994.  
  995. /*
  996.  * read_path
  997.  */
  998. static void
  999. read_path(char* name, void* field)
  1000. {
  1001.     read_str(name, field);
  1002.     fix_path(field);
  1003. }
  1004.  
  1005.  
  1006. /*
  1007.  * write_path
  1008.  */
  1009. static void
  1010. write_path(char* name, void* field)
  1011. {
  1012.     fix_path(field);
  1013.     write_str(name, field);
  1014. }
  1015.  
  1016.  
  1017. /*
  1018.  * Editor colors
  1019.  * LO_Color is a structure that has red, blue and green values.  This
  1020.  * value is stored in the prefs file as #rrggbb.
  1021.  */
  1022.  
  1023. /*
  1024.  * read_color
  1025.  */
  1026. static void
  1027. read_color(char* name, void* field)
  1028. {
  1029.     LO_Color* color = (LO_Color*) field;
  1030.  
  1031.     if ( def ) {
  1032.         PREF_GetDefaultColorPref(name, &color->red, &color->green, &color->blue);
  1033.     } else {
  1034.         PREF_GetColorPref(name, &color->red, &color->green, &color->blue);
  1035.     }
  1036. }
  1037.  
  1038.  
  1039. /*
  1040.  * write_color
  1041.  */
  1042. static void
  1043. write_color(char* name, void* field)
  1044. {
  1045.     LO_Color* color = (LO_Color*) field;
  1046.  
  1047.     PREF_SetColorPref(name, color->red, color->green, color->blue);
  1048. }
  1049.  
  1050.  
  1051. /*
  1052.  * Character sets
  1053.  * It's not clear that this belongs in 4.0, but it was there
  1054.  * for 2.0, 3.0, so we'll carry it forward for the time being.
  1055.  */
  1056.  
  1057. /*
  1058.  * read_char_set
  1059.  */
  1060. static void
  1061. read_char_set(char* name, void* field)
  1062. {
  1063.     char* char_set = *(char**) field;
  1064.  
  1065.     if ( def ) return;
  1066.  
  1067.     read_str(name, &char_set);
  1068.  
  1069.     if ( char_set && *char_set ) {
  1070.         fe_ReadFontCharSet(char_set);
  1071.     }
  1072. }
  1073.  
  1074.  
  1075. /*
  1076.  * write_char_set
  1077.  */
  1078. static void
  1079. write_char_set(char* name, void* field)
  1080. {
  1081.     char* char_set = *(char**) field;
  1082.  
  1083.     REPLACE_STRING(char_set, fe_GetFontCharSetSetting());
  1084.     write_str(name, &char_set);
  1085. }
  1086.  
  1087.  
  1088. /*
  1089.  * Font specs
  1090.  * In the 2.0/3.0 Navigator, each FONT_SPEC was written out a line
  1091.  * at a time.  It's not clear that it belongs in the preferences file
  1092.  * anymore, but we write it out as a comma-separated list for the time
  1093.  * being.
  1094.  */
  1095.  
  1096. /*
  1097.  * read_font_spec
  1098.  */
  1099. static void
  1100. read_font_spec(char* name, void* field)
  1101. {
  1102.     char* font_spec = *(char**) field;
  1103.  
  1104.     if ( def ) return;
  1105.  
  1106.     read_str(name, &font_spec);
  1107.  
  1108.     if ( font_spec && *font_spec ) {
  1109.         char* copy = strdup(font_spec);
  1110.         char* tmp = strtok(copy, ",");
  1111.  
  1112.         do {
  1113.             fe_ReadFontSpec(tmp);
  1114.         } while ( (tmp = strtok(NULL, ",")) != NULL );
  1115.         free(copy);
  1116.     }
  1117. }
  1118.  
  1119.  
  1120. /*
  1121.  * write_font_spec
  1122.  */
  1123. static void
  1124. write_font_spec(char* name, void* field)
  1125. {
  1126.     char* font_spec = *(char**) field;
  1127.     fe_FontSettings* next;
  1128.     fe_FontSettings* set;
  1129.     char buf[4096];
  1130.  
  1131.     set = fe_GetFontSettings();
  1132.     next = set;
  1133.     buf[0] = '\0';
  1134.     while ( next ) {
  1135.         if ( strchr(next->spec, '\n') ) {
  1136.             *strchr(next->spec, '\n') = '\0';
  1137.         }
  1138.         strcat(buf, next->spec);
  1139.         strcat(buf, ",");
  1140.         next = next->next;
  1141.     } 
  1142.     REPLACE_STRING(font_spec, buf);
  1143.     fe_FreeFontSettings(set);
  1144.  
  1145.     write_str(name, &font_spec);
  1146. }
  1147.  
  1148.  
  1149. /*
  1150.  * prefs_parse_color
  1151.  */
  1152. static Boolean
  1153. prefs_parse_color(LO_Color* color, char* string)
  1154. {
  1155.     if (!LO_ParseRGB(string, &color->red, &color->green, &color->blue)) {
  1156.     color->red = color->blue = color->green = 0; /* black */
  1157.     return FALSE;
  1158.     }
  1159.     return TRUE;
  1160. }
  1161.  
  1162.  
  1163. /*
  1164.  * xfe_prefs_get_line
  1165.  * Read a line of preferences
  1166.  * handling multiline values
  1167.  */
  1168. static char *
  1169. xfe_prefs_get_line(char *s, int n, FILE *fp)
  1170. {
  1171.   char *p, *q;
  1172.   int len;
  1173.  
  1174.   /*
  1175.    * get a line
  1176.    */
  1177.   p = fgets(s, n, fp);
  1178.   if (p == NULL)
  1179.     return p;
  1180.  
  1181.   /*
  1182.    * Check for multiline
  1183.    */
  1184.   q = p;
  1185.   while (q) {
  1186.     len = strlen(q);
  1187.     /* must have at least two chars: backslash and new-line */
  1188.     if (len < 2)
  1189.       break;
  1190.     /* check if the line ends with a '\\' and a '\n' */
  1191.     if ((*(q+len-1) != '\n') || (*(q+len-2) != '\\'))
  1192.       break;
  1193.     /* drop the slash and retain the new-line */
  1194.     *(q+len-2) = '\n';
  1195.     *(q+len-1) = '\0';
  1196.     n -= len - 1; /* less space left in buffer */
  1197.     /* stop if no space left */
  1198.     if (n <= 0)
  1199.       break;
  1200.     /* get the next part */
  1201.     q = fgets(q+len-1, n, fp);
  1202.   }
  1203.   return p;
  1204. }
  1205.  
  1206.  
  1207. /* reads in the global preferences.
  1208.  * 
  1209.  * returns True on success and FALSE
  1210.  * on failure (unable to open prefs file)
  1211.  *
  1212.  * the prefs structure must be zero'd at creation since
  1213.  * this function will free any existing char pointers 
  1214.  * passed in and will malloc new ones.
  1215.  */
  1216. static Bool
  1217. XFE_OldReadPrefs(char * filename, XFE_GlobalPrefs *prefs)
  1218. {
  1219.     FILE * fp;
  1220.     char buffer [4096];
  1221.     char *name, *value, *colon;
  1222.  
  1223.   /* First set all slots to the builtin defaults.
  1224.      Then, let the environment override that.
  1225.      Then, let the file override the environment.
  1226.  
  1227.      This means that, generally, the environment variables are only
  1228.      consulted when there is no preferences file on disk - once the
  1229.      preferences get saved, the prevailing env. var values will have
  1230.      been captured in it.
  1231.    */
  1232.  
  1233.     XFE_DefaultPrefs(prefs);
  1234.     xfe_prefs_from_environment (prefs);
  1235.  
  1236.     fp = fopen (filename, "r");
  1237.  
  1238.     if (!fp)
  1239.         return(FALSE);
  1240.  
  1241.     if (! xfe_prefs_get_line(buffer, 4096, fp))
  1242.         *buffer = 0;
  1243.  
  1244.     while (xfe_prefs_get_line (buffer, 4096, fp)) {
  1245.         name = XP_StripLine (buffer);
  1246.  
  1247.         if (*name == '#')
  1248.             continue;  /* comment */
  1249.  
  1250.         colon = strchr (name, ':');
  1251.         
  1252.         if (!colon)
  1253.             continue;  /* not a name/value pair */
  1254.  
  1255.         *colon= '\0';  /* terminate */
  1256.  
  1257.         value = XP_StripLine (colon+1);
  1258.  
  1259. # define BOOLP(x) (XP_STRCASECMP((x),"TRUE") ? FALSE : TRUE)
  1260.  
  1261.         /* OPTIONS MENU
  1262.          */
  1263.         if (!XP_STRCASECMP("SHOW_TOOLBAR", name))
  1264.             prefs->show_toolbar_p = BOOLP (value);
  1265.         else if (!XP_STRCASECMP("SHOW_URL", name))
  1266.             prefs->show_url_p = BOOLP (value);
  1267.         else if (!XP_STRCASECMP("SHOW_DIRECTORY_BUTTONS", name))
  1268.             prefs->show_directory_buttons_p = BOOLP (value);
  1269.         else if (!XP_STRCASECMP("SHOW_MENUBAR", name))
  1270.             prefs->show_menubar_p = BOOLP (value);
  1271.         else if (!XP_STRCASECMP("SHOW_BOTTOM_STATUS_BAR", name))
  1272.             prefs->show_bottom_status_bar_p = BOOLP (value);
  1273.         else if (!XP_STRCASECMP("AUTOLOAD_IMAGES", name))
  1274.             prefs->autoload_images_p = BOOLP (value);
  1275.         else if (!XP_STRCASECMP("FTP_FILE_INFO", name))
  1276.             prefs->fancy_ftp_p = BOOLP (value);
  1277. #ifndef NO_SECURITY
  1278.         else if (!XP_STRCASECMP("SHOW_SECURITY_BAR", name))
  1279.             prefs->show_security_bar_p = BOOLP (value);
  1280. #endif
  1281.  
  1282.  
  1283.         /* APPLICATIONS
  1284.          */
  1285.         else if (!XP_STRCASECMP("TN3270", name))
  1286.             StrAllocCopy (prefs->tn3270_command, value);
  1287.         else if (!XP_STRCASECMP("TELNET", name))
  1288.             StrAllocCopy (prefs->telnet_command, value);
  1289.         else if (!XP_STRCASECMP("RLOGIN", name))
  1290.             StrAllocCopy (prefs->rlogin_command, value);
  1291.         else if (!XP_STRCASECMP("RLOGIN_USER", name))
  1292.             StrAllocCopy (prefs->rlogin_user_command, value);
  1293.  
  1294.         /* CACHE
  1295.          */
  1296.         else if (!XP_STRCASECMP("MEMORY_CACHE_SIZE", name))
  1297.             prefs->memory_cache_size = atoi (value);
  1298.         else if (!XP_STRCASECMP("DISK_CACHE_SIZE", name))
  1299.             prefs->disk_cache_size = atoi (value);
  1300.         else if (!XP_STRCASECMP("CACHE_DIR", name))
  1301.             StrAllocCopy (prefs->cache_dir, value);
  1302.         else if (!XP_STRCASECMP("VERIFY_DOCUMENTS", name))
  1303.             prefs->verify_documents = atoi (value);
  1304.         else if (!XP_STRCASECMP("CACHE_SSL_PAGES", name))
  1305.             prefs->cache_ssl_p = BOOLP (value);
  1306.  
  1307.         /* COLORS
  1308.          */
  1309.     
  1310.         /* COMPOSITION
  1311.          */
  1312.         else if (!XP_STRCASECMP("8BIT_MAIL_AND_NEWS", name))
  1313.             prefs->qp_p = !BOOLP (value);
  1314.         else if (!XP_STRCASECMP("QUEUE_FOR_LATER", name))
  1315.             prefs->queue_for_later_p = BOOLP (value);
  1316.         else if (!XP_STRCASECMP("MAIL_BCC_SELF", name))
  1317.             prefs->mailbccself_p = BOOLP (value);
  1318.         else if (!XP_STRCASECMP("NEWS_BCC_SELF", name))
  1319.             prefs->newsbccself_p = BOOLP (value);
  1320.         else if (!XP_STRCASECMP("MAIL_BCC", name))
  1321.             StrAllocCopy (prefs->mail_bcc, value);
  1322.         else if (!XP_STRCASECMP("NEWS_BCC", name))
  1323.             StrAllocCopy (prefs->news_bcc, value);
  1324.         else if (!XP_STRCASECMP("MAIL_FCC", name)) {
  1325.             StrAllocCopy (prefs->mail_fcc, value);
  1326.             /* 4.0 prefs */
  1327.             prefs->mailfcc_p = TRUE;
  1328.         }
  1329.         else if (!XP_STRCASECMP("NEWS_FCC", name)) {
  1330.             StrAllocCopy (prefs->news_fcc, value);
  1331.             /* 4.0 prefs */
  1332.             prefs->newsfcc_p = TRUE;
  1333.         }
  1334.         else if (!XP_STRCASECMP("MAIL_AUTOQUOTE_REPLY", name))
  1335.             prefs->autoquote_reply = BOOLP (value);
  1336.  
  1337.         /* DIRECTORIES
  1338.          */
  1339.         else if (!XP_STRCASECMP("TMPDIR", name))
  1340.             StrAllocCopy (prefs->tmp_dir, value);
  1341.         else if (!XP_STRCASECMP("BOOKMARKS_FILE", name))
  1342.             StrAllocCopy (prefs->bookmark_file, value);
  1343.         else if (!XP_STRCASECMP("HISTORY_FILE", name))
  1344.             StrAllocCopy (prefs->history_file, value);
  1345.         else if (!XP_STRCASECMP("USER_HISTORY_FILE", name)) /* add to save user typing*/
  1346.             StrAllocCopy (prefs->user_history_file, value);
  1347.  
  1348.         /* FONTS
  1349.          */
  1350.         else if (!XP_STRCASECMP("DOC_CSID", name))
  1351.             prefs->doc_csid = atoi (value);
  1352.         else if (!XP_STRCASECMP("FONT_CHARSET", name))
  1353.             fe_ReadFontCharSet(value);
  1354.         else if (!XP_STRCASECMP("FONT_SPEC", name))
  1355.             fe_ReadFontSpec(value);
  1356.         else if (!XP_STRCASECMP("CITATION_FONT", name))
  1357.             prefs->citation_font = (MSG_FONT) atoi (value);
  1358.         else if (!XP_STRCASECMP("CITATION_SIZE", name))
  1359.             prefs->citation_size = (MSG_CITATION_SIZE) atoi (value);
  1360.         else if (!XP_STRCASECMP("CITATION_COLOR", name))
  1361.             StrAllocCopy (prefs->citation_color, value);
  1362.  
  1363.         /* PREFERED LANGUAGE/REGION
  1364.          */
  1365.         else if (!XP_STRCASECMP("PREFERED_LANG_REGIONS", name))
  1366.             StrAllocCopy (prefs->lang_regions, value);
  1367.  
  1368.         /* HELPERS
  1369.          */
  1370.         else if (!XP_STRCASECMP("MIME_TYPES", name))
  1371.             StrAllocCopy (prefs->global_mime_types_file, value);
  1372.         else if (!XP_STRCASECMP("PERSONAL_MIME_TYPES", name))
  1373.             StrAllocCopy (prefs->private_mime_types_file, value);
  1374.         else if (!XP_STRCASECMP("MAILCAP", name))
  1375.             StrAllocCopy (prefs->global_mailcap_file, value);
  1376.         else if (!XP_STRCASECMP("PERSONAL_MAILCAP", name))
  1377.             StrAllocCopy (prefs->private_mailcap_file, value);
  1378.  
  1379.         /* IDENTITY
  1380.          */
  1381.         else if (!XP_STRCASECMP("REAL_NAME", name))
  1382.             StrAllocCopy (prefs->real_name, value);
  1383.         else if (!XP_STRCASECMP("EMAIL_ADDRESS", name))
  1384.             StrAllocCopy (prefs->email_address, value);
  1385.         else if (!XP_STRCASECMP("ORGANIZATION", name))
  1386.             StrAllocCopy (prefs->organization, value);
  1387.         else if (!XP_STRCASECMP("SIGNATURE_FILE", name))
  1388.             StrAllocCopy (prefs->signature_file, value);
  1389.         else if (!XP_STRCASECMP("SIGNATURE_DATE", name))
  1390.             prefs->signature_date = (time_t) atol (value);
  1391.  
  1392.         /* IMAGES
  1393.        */
  1394.         else if (!XP_STRCASECMP("DITHER_IMAGES", name))
  1395.             StrAllocCopy (prefs->dither_images, value);
  1396.         else if (!XP_STRCASECMP("STREAMING_IMAGES", name))
  1397.             prefs->streaming_images = BOOLP (value);
  1398.  
  1399.       /* MAIL
  1400.        */
  1401.         else if (!XP_STRCASECMP("MAILHOST", name))
  1402.             StrAllocCopy (prefs->mailhost, value);
  1403.         else if (!XP_STRCASECMP("MAIL_DIR", name))
  1404.             /*####*/    StrAllocCopy (prefs->mail_directory, value);
  1405.         else if (!XP_STRCASECMP("BIFF_INTERVAL", name))
  1406.             prefs->biff_interval = atol(value);
  1407.         else if (!XP_STRCASECMP("AUTO_CHECK_MAIL", name))
  1408.             prefs->auto_check_mail = BOOLP (value);
  1409.         else if (!XP_STRCASECMP("USE_MOVEMAIL", name)) {
  1410.             /* 3.0 prefs */
  1411.             prefs->use_movemail_p = BOOLP (value);
  1412.         }
  1413.         else if (!XP_STRCASECMP("BUILTIN_MOVEMAIL", name))
  1414.             prefs->builtin_movemail_p = BOOLP (value);
  1415.         else if (!XP_STRCASECMP("MOVEMAIL_PROGRAM", name))
  1416.             StrAllocCopy (prefs->movemail_program, value);
  1417.         else if (!XP_STRCASECMP("POP3_HOST", name))
  1418.             StrAllocCopy (prefs->pop3_host, value);
  1419.         else if (!XP_STRCASECMP("POP3_USER_ID", name))
  1420.             StrAllocCopy (prefs->pop3_user_id, value);
  1421.         else if (!XP_STRCASECMP("POP3_LEAVE_ON_SERVER", name))
  1422.             prefs->pop3_leave_mail_on_server = BOOLP (value);
  1423.         else if (!XP_STRCASECMP("POP3_MSG_SIZE_LIMIT", name))
  1424.             prefs->pop3_msg_size_limit = atol (value);
  1425.  
  1426.         else if (!XP_STRCASECMP("MAIL_SASH_GEOMETRY", name))
  1427.             StrAllocCopy(prefs->mail_sash_geometry, value);
  1428.         else if (!XP_STRCASECMP("AUTO_EMPTY_TRASH", name))
  1429.             prefs->emptyTrash = BOOLP (value);
  1430.         else if (!XP_STRCASECMP("REMEMBER_MAIL_PASSWORD", name))
  1431.             prefs->rememberPswd = BOOLP (value);
  1432.         else if (!XP_STRCASECMP("MAIL_PASSWORD", name))
  1433.             StrAllocCopy (prefs->pop3_password, value);
  1434.         else if (!XP_STRCASECMP("THREAD_MAIL", name))
  1435.             prefs->mail_thread_p = BOOLP (value);
  1436.         else if (!XP_STRCASECMP("MAIL_PANE_STYLE", name))
  1437.             prefs->mail_pane_style = atoi (value);
  1438.         else if (!XP_STRCASECMP("MAIL_SORT_STYLE", name))
  1439.             prefs->mail_sort_style = atol (value);
  1440.         else if (!XP_STRCASECMP("MOVEMAIL_WARN", name))
  1441.             prefs->movemail_warn = BOOLP (value);
  1442.  
  1443.         /* NETWORK
  1444.        */
  1445.         else if (!XP_STRCASECMP("MAX_CONNECTIONS", name))
  1446.             prefs->max_connections = atoi (value);
  1447.         else if (!XP_STRCASECMP("SOCKET_BUFFER_SIZE", name))
  1448.             /* The unit for tcp buffer size in 3.0 prefs is kbypes
  1449.              * The unit for tcp buffer size in 4.0 prefs is bytes
  1450.              */
  1451.             prefs->network_buffer_size = atoi (value) * 1024;
  1452.  
  1453.       /* PROTOCOLS
  1454.        */
  1455.         else if (!XP_STRCASECMP("USE_EMAIL_FOR_ANON_FTP", name))
  1456.             prefs->email_anonftp = BOOLP(value);
  1457.         else if (!XP_STRCASECMP("ALERT_EMAIL_FORM_SUBMIT", name))
  1458.             prefs->email_submit = BOOLP(value);
  1459.         else if (!XP_STRCASECMP("ACCEPT_COOKIE", name)) {
  1460.             if (atoi(value) == 0) {
  1461.                 /* do not show an alert before accepting a cookie */
  1462.                 prefs->accept_cookie = NET_Accept;
  1463.                 prefs->warn_accept_cookie = FALSE;
  1464.             }
  1465.             else {
  1466.                 /* show an alert before accepting a cookie */
  1467.                 prefs->accept_cookie = NET_Accept;
  1468.                 prefs->warn_accept_cookie = TRUE;
  1469.             }
  1470.         }
  1471.  
  1472.       /* NEWS
  1473.        */
  1474.         else if (!XP_STRCASECMP("NNTPSERVER", name))
  1475.             StrAllocCopy (prefs->newshost, value);
  1476.         else if (!XP_STRCASECMP("NEWSRC_DIR", name))
  1477.             StrAllocCopy (prefs->newsrc_directory, value);
  1478.         else if (!XP_STRCASECMP("NEWS_MAX_ARTICLES", name))
  1479.             prefs->news_max_articles = atol (value);
  1480.         else if (!XP_STRCASECMP("NEWS_CACHE_HEADERS", name))
  1481.             prefs->news_cache_xover = BOOLP (value);
  1482.         else if (!XP_STRCASECMP("SHOW_FIRST_UNREAD", name))
  1483.             prefs->show_first_unread_p = BOOLP (value);
  1484.         else if (!XP_STRCASECMP("NEWS_SASH_GEOMETRY", name))
  1485.             StrAllocCopy(prefs->news_sash_geometry, value);
  1486.         else if (!XP_STRCASECMP("THREAD_NEWS", name))
  1487.             prefs->news_thread_p = BOOLP (value);
  1488.         else if (!XP_STRCASECMP("NEWS_PANE_STYLE", name))
  1489.             prefs->news_pane_style = atoi (value);
  1490.         else if (!XP_STRCASECMP("NEWS_SORT_STYLE", name))
  1491.             prefs->news_sort_style = atol (value);
  1492.  
  1493.       /* PROXIES
  1494.        */
  1495.         else if (!XP_STRCASECMP("PROXY_URL", name))
  1496.             StrAllocCopy (prefs->proxy_url, value);
  1497.         else if (!XP_STRCASECMP("PROXY_MODE", name))
  1498.             prefs->proxy_mode = atol (value);
  1499.         else if (!XP_STRCASECMP("SOCKS_HOST", name))
  1500.             StrAllocCopy (prefs->socks_host, value);
  1501.         else if (!XP_STRCASECMP("FTP_PROXY", name))
  1502.             StrAllocCopy (prefs->ftp_proxy, value);
  1503.         else if (!XP_STRCASECMP("HTTP_PROXY", name))
  1504.             StrAllocCopy (prefs->http_proxy, value);
  1505. #ifndef NO_SECURITY
  1506.         else if (!XP_STRCASECMP("HTTPS_PROXY", name))
  1507.             StrAllocCopy (prefs->https_proxy, value);
  1508. #endif
  1509.         else if (!XP_STRCASECMP("GOPHER_PROXY", name))
  1510.             StrAllocCopy (prefs->gopher_proxy, value);
  1511.         else if (!XP_STRCASECMP("WAIS_PROXY", name))
  1512.             StrAllocCopy (prefs->wais_proxy, value);
  1513.         else if (!XP_STRCASECMP("NO_PROXY", name))
  1514.             StrAllocCopy (prefs->no_proxy, value);
  1515.  
  1516.       /* SECURITY
  1517.        */
  1518. #ifndef NO_SECURITY
  1519.         else if (!XP_STRCASECMP("ASK_PASSWORD", name))
  1520.             prefs->ask_password = atoi (value);
  1521.         else if (!XP_STRCASECMP("PASSWORD_TIMEOUT", name))
  1522.             prefs->password_timeout = atoi (value);
  1523. #ifdef FORTEZZA
  1524.         else if (!XP_STRCASECMP("FORTEZZA_TIMEOUT_ON", name))
  1525.             prefs->fortezza_toggle = atoi (value);
  1526.         else if (!XP_STRCASECMP("FORTEZZA_TIMEOUT", name))
  1527.             prefs->fortezza_timeout = atoi (value);
  1528. #endif
  1529.  
  1530.         else if (!XP_STRCASECMP("WARN_ENTER_SECURE", name))
  1531.             prefs->enter_warn = BOOLP (value);
  1532.         else if (!XP_STRCASECMP("WARN_LEAVE_SECURE", name))
  1533.             prefs->leave_warn = BOOLP (value);
  1534.         else if (!XP_STRCASECMP("WARN_MIXED_SECURE", name))
  1535.             prefs->mixed_warn = BOOLP (value);
  1536.         else if (!XP_STRCASECMP("WARN_SUBMIT_INSECURE", name))
  1537.             prefs->submit_warn = BOOLP (value);
  1538. #ifdef JAVA
  1539.         else if (!XP_STRCASECMP("DISABLE_JAVA", name))
  1540.             prefs->enable_java = !BOOLP (value);
  1541. #endif
  1542.         else if (!XP_STRCASECMP("DISABLE_JAVASCRIPT", name))
  1543.             prefs->enable_javascript = !BOOLP (value);
  1544.  
  1545.         else if (!XP_STRCASECMP("DEFAULT_USER_CERT", name))
  1546.             StrAllocCopy (prefs->def_user_cert, value);
  1547. #endif /* ! NO_SECURITY */
  1548.         else if (!XP_STRCASECMP("ENABLE_SSL2", name))
  1549.             prefs->ssl2_enable = BOOLP (value);
  1550.         else if (!XP_STRCASECMP("ENABLE_SSL3", name))
  1551.             prefs->ssl3_enable = BOOLP (value);
  1552.         else if (!XP_STRCASECMP("CIPHER", name))
  1553.             StrAllocCopy (prefs->cipher, value);
  1554.         else if (!XP_STRCASECMP("LICENSE_ACCEPTED", name))
  1555.             StrAllocCopy (prefs->license_accepted, value);
  1556.  
  1557.       /* STYLES (GENERAL APPEARANCE)
  1558.        */
  1559.         else if (!XP_STRCASECMP("TOOLBAR_ICONS", name))
  1560.             prefs->toolbar_icons_p = BOOLP (value);
  1561.         else if (!XP_STRCASECMP("TOOLBAR_TEXT", name))
  1562.             prefs->toolbar_text_p = BOOLP (value);
  1563.         else if (!XP_STRCASECMP("TOOLBAR_TIPS", name))
  1564.             prefs->toolbar_tips_p = BOOLP (value);
  1565.         else if (!XP_STRCASECMP("STARTUP_MODE", name)) 
  1566.             prefs->startup_mode = atoi (value); 
  1567.         else if (!XP_STRCASECMP("HOME_DOCUMENT", name))
  1568.             StrAllocCopy (prefs->home_document, value);
  1569.         else if (!XP_STRCASECMP("UNDERLINE_LINKS", name))
  1570.             prefs->underline_links_p = BOOLP (value);
  1571.         else if (!XP_STRCASECMP("HISTORY_EXPIRATION", name))
  1572.             prefs->global_history_expiration = atoi (value);
  1573.         else if (!XP_STRCASECMP("FIXED_MESSAGE_FONT", name))
  1574.             prefs->fixed_message_font_p = BOOLP (value);
  1575.         /*** no longer valid. we need one each for mail and news - dp
  1576.           else if (!XP_STRCASECMP("SORT_MESSAGES", name))
  1577.           prefs->msg_sort_style = atol (value);
  1578.           else if (!XP_STRCASECMP("THREAD_MESSAGES", name))
  1579.           prefs->msg_thread_p = BOOLP (value);
  1580. ***/
  1581.  
  1582.       /* BOOKMARK
  1583.        */
  1584.  
  1585.         /* PRINT
  1586.        */
  1587.         else if (!XP_STRCASECMP("PRINT_COMMAND", name))
  1588.             StrAllocCopy (prefs->print_command, value);
  1589.         else if (!XP_STRCASECMP("PRINT_REVERSED", name))
  1590.             prefs->print_reversed = BOOLP (value);
  1591.         else if (!XP_STRCASECMP("PRINT_COLOR", name))
  1592.             prefs->print_color = BOOLP (value);
  1593.         else if (!XP_STRCASECMP("PRINT_LANDSCAPE", name))
  1594.             prefs->print_landscape = BOOLP (value);
  1595.         else if (!XP_STRCASECMP("PRINT_PAPER", name))
  1596.             prefs->print_paper_size = atoi (value);
  1597.  
  1598. #ifdef EDITOR
  1599.         /* EDITOR */
  1600.         else if (!XP_STRCASECMP("EDITOR_CHARACTER_TOOLBAR", name))
  1601.             prefs->editor_character_toolbar = BOOLP(value);
  1602.         else if (!XP_STRCASECMP("EDITOR_PARAGRAPH_TOOLBAR", name))
  1603.             prefs->editor_paragraph_toolbar = BOOLP(value);
  1604.         else if (!XP_STRCASECMP("EDITOR_AUTHOR_NAME", name))
  1605.             StrAllocCopy (prefs->editor_author_name, value);
  1606.         else if (!XP_STRCASECMP("EDITOR_HTML_EDITOR", name))
  1607.             StrAllocCopy (prefs->editor_html_editor, value);
  1608.         else if (!XP_STRCASECMP("EDITOR_IMAGE_EDITOR", name))
  1609.             StrAllocCopy (prefs->editor_image_editor, value);
  1610.         else if (!XP_STRCASECMP("EDITOR_NEW_DOCUMENT_TEMPLATE", name))
  1611.             StrAllocCopy (prefs->editor_document_template, value);
  1612.         else if (!XP_STRCASECMP("EDITOR_AUTOSAVE_PERIOD", name))
  1613.             prefs->editor_autosave_period = atoi(value);
  1614.         else if (!XP_STRCASECMP("EDITOR_CUSTOM_COLORS", name))
  1615.             prefs->editor_custom_colors = BOOLP(value);
  1616.         else if (!XP_STRCASECMP("EDITOR_BACKGROUND_COLOR", name))
  1617.             prefs_parse_color(&prefs->editor_background_color, value);
  1618.         else if (!XP_STRCASECMP("EDITOR_NORMAL_COLOR", name))
  1619.             prefs_parse_color(&prefs->editor_normal_color, value);
  1620.         else if (!XP_STRCASECMP("EDITOR_LINK_COLOR", name))
  1621.             prefs_parse_color(&prefs->editor_link_color, value);
  1622.         else if (!XP_STRCASECMP("EDITOR_ACTIVE_COLOR", name))
  1623.             prefs_parse_color(&prefs->editor_active_color, value);
  1624.         else if (!XP_STRCASECMP("EDITOR_FOLLOWED_COLOR", name))
  1625.             prefs_parse_color(&prefs->editor_followed_color, value);
  1626.         else if (!XP_STRCASECMP("EDITOR_BACKGROUND_IMAGE", name))
  1627.             StrAllocCopy (prefs->editor_background_image, value);
  1628.         else if (!XP_STRCASECMP("EDITOR_MAINTAIN_LINKS", name))
  1629.             prefs->editor_maintain_links = BOOLP(value);
  1630.         else if (!XP_STRCASECMP("EDITOR_KEEP_IMAGES", name))
  1631.             prefs->editor_keep_images = BOOLP(value);
  1632.         else if (!XP_STRCASECMP("EDITOR_PUBLISH_LOCATION", name))
  1633.             StrAllocCopy (prefs->editor_publish_location, value);
  1634.         else if (!XP_STRCASECMP("EDITOR_BROWSE_LOCATION", name))
  1635.             StrAllocCopy (prefs->editor_browse_location, value);
  1636.         else if (!XP_STRCASECMP("EDITOR_PUBLISH_USERNAME", name))
  1637.             StrAllocCopy (prefs->editor_publish_username, value);
  1638.         else if (!XP_STRCASECMP("EDITOR_PUBLISH_PASSWORD", name))
  1639.             StrAllocCopy (prefs->editor_publish_password, value);
  1640.         else if (!XP_STRCASECMP("EDITOR_COPYRIGHT_HINT", name))
  1641.             prefs->editor_copyright_hint = BOOLP(value);
  1642.         /* to to add publish stuff */
  1643. #endif /*EDITOR*/
  1644.     }
  1645.  
  1646.     fclose (fp);
  1647.  
  1648.     prefs->pop3_msg_size_limit_p = (prefs->pop3_msg_size_limit > 0) ? True : False;
  1649.     prefs->pop3_msg_size_limit = abs (prefs->pop3_msg_size_limit);
  1650.  
  1651.     /* change default proxy mode to 3 */
  1652.     if (prefs->proxy_mode == 0) prefs->proxy_mode = PROXY_STYLE_NONE;
  1653.  
  1654.     /* Include the current version number in global prefs when upgrading from 3.0 to 4.0 */
  1655.     StrAllocCopy(prefs->version_number, PREFS_CURRENT_VERSION);
  1656.  
  1657.     /* toolbar icons/text */
  1658.  
  1659.     if (prefs->toolbar_icons_p && prefs->toolbar_text_p) {
  1660.         prefs->toolbar_style = BROWSER_TOOLBAR_ICONS_AND_TEXT;
  1661.     }
  1662.     else if (prefs->toolbar_icons_p) { 
  1663.         prefs->toolbar_style = BROWSER_TOOLBAR_ICONS_ONLY;
  1664.     }        
  1665.     else {
  1666.         prefs->toolbar_style = BROWSER_TOOLBAR_TEXT_ONLY;
  1667.     }
  1668.  
  1669.     /* movemail -> mail server type */
  1670.  
  1671.     if (prefs->use_movemail_p)
  1672.         prefs->mail_server_type = MAIL_SERVER_MOVEMAIL;
  1673.     else
  1674.         prefs->mail_server_type = MAIL_SERVER_POP3;
  1675.  
  1676.     /* start up mode */
  1677.  
  1678.     prefs->startup_browser_p = 
  1679.         prefs->startup_mail_p = 
  1680.         prefs->startup_news_p = 
  1681.         prefs->startup_editor_p = 
  1682.         prefs->startup_conference_p = 
  1683.         prefs->startup_netcaster_p = 
  1684.         prefs->startup_calendar_p = False;
  1685.     if (prefs->startup_mode == 0)
  1686.         prefs->startup_browser_p = True;
  1687.     else if (prefs->startup_mode == 1)
  1688.         prefs->startup_mail_p = True;
  1689.     else if (prefs->startup_mode == 2)
  1690.         prefs->startup_news_p = True;
  1691.  
  1692.     /* home document */
  1693.  
  1694.     if (prefs->home_document &&  *prefs->home_document)
  1695.         prefs->browser_startup_page = BROWSER_STARTUP_HOME;
  1696.     else
  1697.         prefs->browser_startup_page = BROWSER_STARTUP_BLANK;
  1698.  
  1699.     /* link expiration
  1700.      * In 3.0 you can make link never expire, i.e. global_history_expiration < 0
  1701.      * For 4.0, need to convert it to some large number because there is
  1702.      * no option for never expire
  1703.      */
  1704.  
  1705.     if (prefs->global_history_expiration < 0) 
  1706.         prefs->global_history_expiration = LINK_NEVER_EXPIRE_DAYS;
  1707.  
  1708.     if (!prefs->dither_images ||
  1709.         !XP_STRCASECMP(prefs->dither_images, "TRUE") ||
  1710.         !XP_STRCASECMP(prefs->dither_images, "FALSE"))
  1711.         StrAllocCopy (prefs->dither_images, "Auto");  {
  1712.         char *home = getenv ("HOME");
  1713.         if (!home) home = "";
  1714.  
  1715. #define FROB(SLOT)                            \
  1716.     if (prefs->SLOT && *prefs->SLOT == '~')                \
  1717.     {                                    \
  1718.     if (prefs->SLOT[1] != '/' && prefs->SLOT[1] != 0)        \
  1719.       {                                \
  1720.         fprintf (stderr,    XP_GetString( XFE_TILDE_USER_SYNTAX_DISALLOWED ), \
  1721.              XP_AppName);                    \
  1722.       }                                \
  1723.     else                                \
  1724.       {                                \
  1725.         char *new = (char *)                    \
  1726.           malloc (strlen (prefs->SLOT) + strlen (home) + 3);    \
  1727.         strcpy (new, home);                        \
  1728.         if (home[strlen(home)-1] != '/')                \
  1729.           strcat (new, "/");                    \
  1730.         if (prefs->SLOT[1] && prefs->SLOT[2])            \
  1731.           strcat (new, prefs->SLOT + 2);                \
  1732.         free (prefs->SLOT);                        \
  1733.         prefs->SLOT = new;                        \
  1734.       }                                \
  1735.     }
  1736.  
  1737.     FROB(cache_dir)
  1738.     FROB(mail_fcc)
  1739.     FROB(news_fcc)
  1740.     FROB(tmp_dir)
  1741.     FROB(bookmark_file)
  1742.     FROB(history_file)
  1743.     FROB(user_history_file)
  1744.     FROB(global_mime_types_file)
  1745.     FROB(private_mime_types_file)
  1746.     /* spider begin */
  1747.     FROB(sar_cache_dir)
  1748.     /* spider end */
  1749.     FROB(global_mailcap_file)
  1750.     FROB(private_mailcap_file)
  1751.     FROB(signature_file)
  1752.     FROB(mail_directory)
  1753.     FROB(movemail_program)
  1754.     FROB(newsrc_directory)
  1755.  
  1756. #ifdef EDITOR
  1757.     FROB(editor_html_editor);
  1758.     FROB(editor_image_editor);
  1759.     FROB(editor_background_image);
  1760. #endif
  1761.     }
  1762.  
  1763.     return (TRUE);
  1764. }
  1765.  
  1766. /*
  1767.  * tweaks
  1768.  * Some tweaking...
  1769.  */
  1770. static void
  1771. tweaks(XFE_GlobalPrefs* prefs)
  1772. {
  1773.     /* movemail */
  1774.     if ((prefs->mail_server_type == MAIL_SERVER_IMAP) ||
  1775.         (prefs->mail_server_type == MAIL_SERVER_INBOX) ||
  1776.         (prefs->mail_server_type == MAIL_SERVER_POP3))
  1777.         prefs->use_movemail_p = FALSE;
  1778.  
  1779.     /* toolbar style */
  1780.     if (prefs->toolbar_style == BROWSER_TOOLBAR_ICONS_ONLY) {
  1781.         prefs->toolbar_icons_p = True;
  1782.         prefs->toolbar_text_p = False;
  1783.     }
  1784.     else if (prefs->toolbar_style == BROWSER_TOOLBAR_TEXT_ONLY) {
  1785.         prefs->toolbar_icons_p = False;
  1786.         prefs->toolbar_text_p = True;
  1787.     }
  1788.     else if (prefs->toolbar_style == BROWSER_TOOLBAR_ICONS_AND_TEXT) {
  1789.         prefs->toolbar_icons_p = True;
  1790.         prefs->toolbar_text_p = True;
  1791.     }
  1792. }
  1793.  
  1794.  
  1795. /*
  1796.  * pref_callback
  1797.  */
  1798. static int
  1799. pref_callback(const char* name, void* data)
  1800. {
  1801.     int i = (int) data;
  1802.     void* field = GET_FIELD(pref_map[i], (&fe_globalPrefs));
  1803.  
  1804.     def = 0; /* Indicate that we want to read real prefs, not defaults */
  1805.     pref_map[i].read_routine(pref_map[i].name, field);
  1806.  
  1807.     return 0;
  1808. }
  1809.  
  1810.  
  1811. /*
  1812.  * FE_register_pref_callbacks
  1813.  */
  1814. void
  1815. FE_register_pref_callbacks(void)
  1816. {
  1817.     int i;
  1818.  
  1819.     for ( i = 0; i < num_prefs; i++ ) {
  1820.         PREF_RegisterCallback(pref_map[i].name, pref_callback, (void*) i);
  1821.     }
  1822. }
  1823.  
  1824. /* compares two version numbers.
  1825.  * returns > 0  if version1 > version2
  1826.  *         = 0 if version1 == version2
  1827.  *         < 0 if version1 < version2
  1828.  */
  1829. static Bool compare_version(char *version_str_1, 
  1830.                             char *version_str_2) 
  1831. {
  1832.     /* The prefs version number is something like 4.0, 4.1...
  1833.      * For now, we can get away with using strcmp...
  1834.      */
  1835.  
  1836.     char *version_1 = (XP_STRLEN(version_str_1)) == 0 ? PREFS_INIT_VERSION : version_str_1;
  1837.     char *version_2 = (XP_STRLEN(version_str_2)) == 0 ? PREFS_INIT_VERSION : version_str_2;
  1838.  
  1839.     return XP_STRCMP(version_1, version_2);
  1840. }
  1841.  
  1842. /* Returns true if we have upgraded the prefs */
  1843. void fe_upgrade_prefs(XFE_GlobalPrefs* prefs) 
  1844. {
  1845.     /* See if we need to upgrade the user */
  1846.     if (compare_version(fe_globalPrefs.version_number, PREFS_CURRENT_VERSION) < 0) {
  1847.         /* Here's the place to do upgrades... */
  1848.  
  1849.         /* Change version number */
  1850.         XP_FREEIF(prefs->version_number);
  1851.         StrAllocCopy(prefs->version_number, PREFS_CURRENT_VERSION);
  1852.     }
  1853. }
  1854.  
  1855. /* Checks if we need to upgrade prefs. prefs->prefs_need_upgrade will be updated by
  1856.  * this routine.
  1857.  */
  1858. void fe_check_prefs_version(XFE_GlobalPrefs* prefs) 
  1859. {
  1860.     /* See if we need to upgrade the user */
  1861.  
  1862.     prefs->prefs_need_upgrade = compare_version(PREFS_CURRENT_VERSION, prefs->version_number);
  1863. }
  1864.  
  1865. Bool fe_CheckVersionAndSavePrefs(char            *filename,
  1866.                                  XFE_GlobalPrefs *prefs) 
  1867. {
  1868.     if (prefs->prefs_need_upgrade > 0) {
  1869.         Bool result;
  1870.         Bool confirm;
  1871.         char *msg = PR_smprintf(XP_GetString(XFE_PREFS_UPGRADE),
  1872.                                 prefs->version_number,
  1873.                                 PREFS_CURRENT_VERSION);
  1874.         confirm = fe_Confirm_2(FE_GetToplevelWidget(), msg);
  1875.         if (confirm) fe_upgrade_prefs(prefs);
  1876.         result = XFE_SavePrefs ((char *) fe_globalData.user_prefs_file,    prefs);
  1877.         if (result && confirm) prefs->prefs_need_upgrade = 0;
  1878.         XP_FREE(msg);
  1879.         return result;
  1880.     }
  1881.     else {
  1882.         return (XFE_SavePrefs ((char *) fe_globalData.user_prefs_file, prefs));
  1883.     }
  1884. }
  1885.