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 2006-2008 University of Washington
8 * Copyright 2013-2015 Eduardo Chappa
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"
39 * Globals referenced throughout pine...
41 struct pine
*ps_global
; /* THE global variable! */
45 * Debug level and output file defined here, referenced globally.
46 * The debug file is opened and initialized below...
48 int debug
= DEFAULT_DEBUG
;
52 /*----------------------------------------------------------------------
53 General use big buffer. It is used in the following places:
54 compose_mail: while parsing header of postponed message
55 append_message2: while writing header into folder
56 q_status_messageX: while doing printf formatting
57 addr_book: Used to return expanded address in. (Can only use here
58 because mm_log doesn't q_status on PARSE errors !)
59 alpine.c: When address specified on command line
60 init.c: When expanding variable values
64 char tmp_20k_buf
[SIZEOF_20KBUF
];
68 * new_pine_struct - allocate and fill in with default values a new pine struct
75 p
= (struct pine
*)fs_get(sizeof (struct pine
));
76 memset((void *) p
, 0, sizeof(struct pine
));
77 p
->def_sort
= SortArrival
;
78 p
->sort_types
[0] = SortSubject
;
79 p
->sort_types
[1] = SortArrival
;
80 p
->sort_types
[2] = SortFrom
;
81 p
->sort_types
[3] = SortTo
;
82 p
->sort_types
[4] = SortCc
;
83 p
->sort_types
[5] = SortDate
;
84 p
->sort_types
[6] = SortSize
;
85 p
->sort_types
[7] = SortSubject2
;
86 p
->sort_types
[8] = SortScore
;
87 p
->sort_types
[9] = SortThread
;
88 p
->sort_types
[10] = EndofList
;
91 * We need to have access to p->smime even before calling
92 * smime_init() so that we can set do_encrypt and do_sign.
94 p
->smime
= new_smime_struct();
96 p
->atmts
= (ATTACH_S
*) fs_get(sizeof(ATTACH_S
));
97 p
->atmts_allocated
= 1;
98 p
->atmts
->description
= NULL
;
100 p
->init_context
= -1;
101 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
110 * free_pine_struct -- free up allocated data in pine struct and then the
114 free_pine_struct(struct pine
**pps
)
119 if((*pps
)->hostname
!= NULL
)
120 fs_give((void **)&(*pps
)->hostname
);
122 if((*pps
)->localdomain
!= NULL
)
123 fs_give((void **)&(*pps
)->localdomain
);
125 if((*pps
)->ttyo
!= NULL
)
126 fs_give((void **)&(*pps
)->ttyo
);
128 if((*pps
)->home_dir
!= NULL
)
129 fs_give((void **)&(*pps
)->home_dir
);
131 if((*pps
)->folders_dir
!= NULL
)
132 fs_give((void **)&(*pps
)->folders_dir
);
134 if((*pps
)->ui
.homedir
)
135 fs_give((void **)&(*pps
)->ui
.homedir
);
138 fs_give((void **)&(*pps
)->ui
.login
);
140 if((*pps
)->ui
.fullname
)
141 fs_give((void **)&(*pps
)->ui
.fullname
);
143 free_index_format(&(*pps
)->index_disp_format
);
145 if((*pps
)->conv_table
){
146 if((*pps
)->conv_table
->table
)
147 fs_give((void **) &(*pps
)->conv_table
->table
);
149 if((*pps
)->conv_table
->from_charset
)
150 fs_give((void **) &(*pps
)->conv_table
->from_charset
);
152 if((*pps
)->conv_table
->to_charset
)
153 fs_give((void **) &(*pps
)->conv_table
->to_charset
);
155 fs_give((void **)&(*pps
)->conv_table
);
159 fs_give((void **)&(*pps
)->pinerc
);
161 #if defined(DOS) || defined(OS2)
163 fs_give((void **)&(*pps
)->pine_dir
);
165 if((*pps
)->aux_files_dir
)
166 fs_give((void **)&(*pps
)->aux_files_dir
);
169 if((*pps
)->display_charmap
)
170 fs_give((void **)&(*pps
)->display_charmap
);
172 if((*pps
)->keyboard_charmap
)
173 fs_give((void **)&(*pps
)->keyboard_charmap
);
175 if((*pps
)->posting_charmap
)
176 fs_give((void **)&(*pps
)->posting_charmap
);
180 fs_give((void **)&(*pps
)->passfile
);
185 pc
= (PERSONAL_CERT
*) (*pps
)->pwdcert
;
186 free_personal_certs(&pc
);
187 (*pps
)->pwdcert
= NULL
;
189 if((*pps
)->pwdcertdir
)
190 fs_give((void **)&(*pps
)->pwdcertdir
);
191 #endif /* SMIME inside PASSFILE */
192 #endif /* PASSFILE */
194 if((*pps
)->hdr_colors
)
195 free_spec_colors(&(*pps
)->hdr_colors
);
197 if((*pps
)->index_token_colors
)
198 free_spec_colors(&(*pps
)->index_token_colors
);
201 free_keyword_list(&(*pps
)->keywords
);
203 if((*pps
)->kw_colors
)
204 free_spec_colors(&(*pps
)->kw_colors
);
209 for(i
= 0; (*pps
)->atmts
[i
].description
; i
++){
210 fs_give((void **) &(*pps
)->atmts
[i
].description
);
211 fs_give((void **) &(*pps
)->atmts
[i
].number
);
214 fs_give((void **) &(*pps
)->atmts
);
218 msgno_give(&(*pps
)->msgmap
);
222 fs_give((void **) pps
);
227 free_pinerc_strings(struct pine
**pps
)
230 if((*pps
)->prc
->outstanding_pinerc_changes
)
231 write_pinerc((*pps
), Main
, WRP_NONE
);
234 rd_close_remdata(&(*pps
)->prc
->rd
);
236 free_pinerc_s(&(*pps
)->prc
);
240 free_pinerc_s(&(*pps
)->pconf
);
242 if((*pps
)->post_prc
){
243 if((*pps
)->post_prc
->outstanding_pinerc_changes
)
244 write_pinerc((*pps
), Post
, WRP_NONE
);
246 if((*pps
)->post_prc
->rd
)
247 rd_close_remdata(&(*pps
)->post_prc
->rd
);
249 free_pinerc_s(&(*pps
)->post_prc
);
255 * free_vars -- give back resources acquired when we defined the
259 free_vars(struct pine
*ps
)
263 for(i
= 0; ps
&& i
<= V_LAST_VAR
; i
++)
264 free_variable_values(&ps
->vars
[i
]);
269 free_variable_values(struct variable
*var
)
273 free_list_array(&var
->current_val
.l
);
274 free_list_array(&var
->main_user_val
.l
);
275 free_list_array(&var
->post_user_val
.l
);
276 free_list_array(&var
->global_val
.l
);
277 free_list_array(&var
->fixed_val
.l
);
278 free_list_array(&var
->cmdline_val
.l
);
281 if(var
->current_val
.p
)
282 fs_give((void **)&var
->current_val
.p
);
283 if(var
->main_user_val
.p
)
284 fs_give((void **)&var
->main_user_val
.p
);
285 if(var
->post_user_val
.p
)
286 fs_give((void **)&var
->post_user_val
.p
);
287 if(var
->global_val
.p
)
288 fs_give((void **)&var
->global_val
.p
);
290 fs_give((void **)&var
->fixed_val
.p
);
291 if(var
->cmdline_val
.p
)
292 fs_give((void **)&var
->cmdline_val
.p
);
299 new_pinerc_s(char *name
)
301 PINERC_S
*prc
= NULL
;
304 prc
= (PINERC_S
*)fs_get(sizeof(*prc
));
305 memset((void *)prc
, 0, sizeof(*prc
));
306 prc
->name
= cpystr(name
);
318 free_pinerc_s(PINERC_S
**prc
)
322 fs_give((void **)&(*prc
)->name
);
325 rd_free_remdata(&(*prc
)->rd
);
327 if((*prc
)->pinerc_lines
)
328 free_pinerc_lines(&(*prc
)->pinerc_lines
);
330 fs_give((void **)prc
);