1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: state.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2020 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 /*======================================================================
21 Implements the Pine state management routines
25 #include "../pith/headers.h"
26 #include "../pith/state.h"
27 #include "../pith/conf.h"
28 #include "../pith/init.h"
29 #include "../pith/sort.h"
30 #include "../pith/atttype.h"
31 #include "../pith/util.h"
32 #include "../pith/mailindx.h"
33 #include "../pith/remote.h"
34 #include "../pith/list.h"
35 #include "../pith/smime.h"
36 #include "../pith/ical.h"
37 #include "../pith/bldaddr.h"
40 * Globals referenced throughout pine...
42 struct pine
*ps_global
; /* THE global variable! */
46 * Debug level and output file defined here, referenced globally.
47 * The debug file is opened and initialized below...
49 int debug
= DEFAULT_DEBUG
;
53 /*----------------------------------------------------------------------
54 General use big buffer. It is used in the following places:
55 compose_mail: while parsing header of postponed message
56 append_message2: while writing header into folder
57 q_status_messageX: while doing printf formatting
58 addr_book: Used to return expanded address in. (Can only use here
59 because mm_log doesn't q_status on PARSE errors !)
60 alpine.c: When address specified on command line
61 init.c: When expanding variable values
65 char tmp_20k_buf
[SIZEOF_20KBUF
];
69 * new_pine_struct - allocate and fill in with default values a new pine struct
76 p
= (struct pine
*)fs_get(sizeof (struct pine
));
77 memset((void *) p
, 0, sizeof(struct pine
));
78 p
->def_sort
= SortArrival
;
79 p
->sort_types
[0] = SortSubject
;
80 p
->sort_types
[1] = SortArrival
;
81 p
->sort_types
[2] = SortFrom
;
82 p
->sort_types
[3] = SortTo
;
83 p
->sort_types
[4] = SortCc
;
84 p
->sort_types
[5] = SortDate
;
85 p
->sort_types
[6] = SortSize
;
86 p
->sort_types
[7] = SortSubject2
;
87 p
->sort_types
[8] = SortScore
;
88 p
->sort_types
[9] = SortThread
;
89 p
->sort_types
[10] = EndofList
;
92 * We need to have access to p->smime even before calling
93 * smime_init() so that we can set do_encrypt and do_sign.
95 p
->smime
= new_smime_struct();
97 p
->atmts
= (ATTACH_S
*) fs_get(sizeof(ATTACH_S
));
98 p
->atmts_allocated
= 1;
99 p
->atmts
->description
= NULL
;
101 p
->init_context
= -1;
102 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
111 * free_pine_struct -- free up allocated data in pine struct and then the
115 free_pine_struct(struct pine
**pps
)
120 if((*pps
)->free_initial_cmds
!= NULL
)
121 fs_give((void **) &(*pps
)->free_initial_cmds
);
123 if((*pps
)->id
!= NULL
)
124 mail_free_idlist(&(*pps
)->id
);
126 if((*pps
)->hostname
!= NULL
)
127 fs_give((void **)&(*pps
)->hostname
);
129 if((*pps
)->localdomain
!= NULL
)
130 fs_give((void **)&(*pps
)->localdomain
);
132 if((*pps
)->ttyo
!= NULL
)
133 fs_give((void **)&(*pps
)->ttyo
);
135 if((*pps
)->home_dir
!= NULL
)
136 fs_give((void **)&(*pps
)->home_dir
);
138 if((*pps
)->folders_dir
!= NULL
)
139 fs_give((void **)&(*pps
)->folders_dir
);
141 if((*pps
)->html_dir
!= NULL
)
142 fs_give((void **)&(*pps
)->html_dir
);
144 if((*pps
)->html_dir_list
!= NULL
)
145 free_html_log(&(*pps
)->html_dir_list
);
147 if((*pps
)->ui
.homedir
)
148 fs_give((void **)&(*pps
)->ui
.homedir
);
151 fs_give((void **)&(*pps
)->ui
.login
);
153 if((*pps
)->ui
.fullname
)
154 fs_give((void **)&(*pps
)->ui
.fullname
);
156 free_index_format(&(*pps
)->index_disp_format
);
158 if((*pps
)->conv_table
){
159 if((*pps
)->conv_table
->table
)
160 fs_give((void **) &(*pps
)->conv_table
->table
);
162 if((*pps
)->conv_table
->from_charset
)
163 fs_give((void **) &(*pps
)->conv_table
->from_charset
);
165 if((*pps
)->conv_table
->to_charset
)
166 fs_give((void **) &(*pps
)->conv_table
->to_charset
);
168 fs_give((void **)&(*pps
)->conv_table
);
172 fs_give((void **)&(*pps
)->pinerc
);
174 #if defined(DOS) || defined(OS2)
176 fs_give((void **)&(*pps
)->pine_dir
);
178 if((*pps
)->aux_files_dir
)
179 fs_give((void **)&(*pps
)->aux_files_dir
);
182 if((*pps
)->display_charmap
)
183 fs_give((void **)&(*pps
)->display_charmap
);
185 if((*pps
)->keyboard_charmap
)
186 fs_give((void **)&(*pps
)->keyboard_charmap
);
188 if((*pps
)->posting_charmap
)
189 fs_give((void **)&(*pps
)->posting_charmap
);
192 if((*pps
)->pwdcertdir
)
193 fs_give((void **)&(*pps
)->pwdcertdir
);
198 pc
= (PERSONAL_CERT
*) (*pps
)->pwdcert
;
199 free_personal_certs(&pc
);
200 (*pps
)->pwdcert
= NULL
;
203 if((*pps
)->pwdcertlist
){
206 cert
= (CertList
*) (*pps
)->pwdcertlist
;
207 free_certlist(&cert
);
208 (*pps
)->pwdcertlist
= NULL
;
211 if((*pps
)->backuppassword
){
214 cert
= (CertList
*) (*pps
)->backuppassword
;
215 free_certlist(&cert
);
216 (*pps
)->backuppassword
= NULL
;
223 fs_give((void **)&(*pps
)->passfile
);
224 #endif /* PASSFILE */
226 if((*pps
)->hdr_colors
)
227 free_spec_colors(&(*pps
)->hdr_colors
);
229 if((*pps
)->index_token_colors
)
230 free_spec_colors(&(*pps
)->index_token_colors
);
233 free_keyword_list(&(*pps
)->keywords
);
235 if((*pps
)->kw_colors
)
236 free_spec_colors(&(*pps
)->kw_colors
);
241 for(i
= 0; (*pps
)->atmts
[i
].description
; i
++){
242 fs_give((void **) &(*pps
)->atmts
[i
].description
);
243 fs_give((void **) &(*pps
)->atmts
[i
].number
);
246 fs_give((void **) &(*pps
)->atmts
);
250 msgno_give(&(*pps
)->msgmap
);
254 fs_give((void **) pps
);
259 free_pinerc_strings(struct pine
**pps
)
262 if((*pps
)->prc
->outstanding_pinerc_changes
)
263 write_pinerc((*pps
), Main
, WRP_NONE
);
266 rd_close_remdata(&(*pps
)->prc
->rd
);
268 free_pinerc_s(&(*pps
)->prc
);
272 free_pinerc_s(&(*pps
)->pconf
);
274 if((*pps
)->post_prc
){
275 if((*pps
)->post_prc
->outstanding_pinerc_changes
)
276 write_pinerc((*pps
), Post
, WRP_NONE
);
278 if((*pps
)->post_prc
->rd
)
279 rd_close_remdata(&(*pps
)->post_prc
->rd
);
281 free_pinerc_s(&(*pps
)->post_prc
);
287 * free_vars -- give back resources acquired when we defined the
291 free_vars(struct pine
*ps
)
295 for(i
= 0; ps
&& i
<= V_LAST_VAR
; i
++)
296 free_variable_values(&ps
->vars
[i
]);
301 free_variable_values(struct variable
*var
)
305 free_list_array(&var
->current_val
.l
);
306 free_list_array(&var
->main_user_val
.l
);
307 free_list_array(&var
->post_user_val
.l
);
308 free_list_array(&var
->global_val
.l
);
309 free_list_array(&var
->fixed_val
.l
);
310 free_list_array(&var
->cmdline_val
.l
);
313 if(var
->current_val
.p
)
314 fs_give((void **)&var
->current_val
.p
);
315 if(var
->main_user_val
.p
)
316 fs_give((void **)&var
->main_user_val
.p
);
317 if(var
->post_user_val
.p
)
318 fs_give((void **)&var
->post_user_val
.p
);
319 if(var
->global_val
.p
)
320 fs_give((void **)&var
->global_val
.p
);
322 fs_give((void **)&var
->fixed_val
.p
);
323 if(var
->cmdline_val
.p
)
324 fs_give((void **)&var
->cmdline_val
.p
);
331 new_pinerc_s(char *name
)
333 PINERC_S
*prc
= NULL
;
336 prc
= (PINERC_S
*)fs_get(sizeof(*prc
));
337 memset((void *)prc
, 0, sizeof(*prc
));
338 prc
->name
= cpystr(name
);
350 free_pinerc_s(PINERC_S
**prc
)
354 fs_give((void **)&(*prc
)->name
);
357 rd_free_remdata(&(*prc
)->rd
);
359 if((*prc
)->pinerc_lines
)
360 free_pinerc_lines(&(*prc
)->pinerc_lines
);
362 fs_give((void **)prc
);
367 free_pith_module_globals(void)
369 free_filter_module_globals();
371 free_bldaddr_module_globals();
372 fname_to_locale(NULL
);