* new version 2.19.9999
[alpine.git] / pith / state.c
blobd3a7cbe66107ff02b8c6e02618bd872ac81e9ff9
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: state.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
3 #endif
5 /*
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 /*======================================================================
20 state.c
21 Implements the Pine state management routines
22 ====*/
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! */
43 #ifdef DEBUG
45 * Debug level and output file defined here, referenced globally.
46 * The debug file is opened and initialized below...
48 int debug = DEFAULT_DEBUG;
49 #endif
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
61 and many many more...
63 ----*/
64 char tmp_20k_buf[SIZEOF_20KBUF];
68 * new_pine_struct - allocate and fill in with default values a new pine struct
70 struct pine *
71 new_pine_struct(void)
73 struct pine *p;
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;
89 #ifdef SMIME
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();
95 #endif /* SMIME */
96 p->atmts = (ATTACH_S *) fs_get(sizeof(ATTACH_S));
97 p->atmts_allocated = 1;
98 p->atmts->description = NULL;
99 p->low_speed = 1;
100 p->init_context = -1;
101 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
102 init_init_vars(p);
104 return(p);
110 * free_pine_struct -- free up allocated data in pine struct and then the
111 * struct itself
113 void
114 free_pine_struct(struct pine **pps)
116 if(!(pps && (*pps)))
117 return;
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);
137 if((*pps)->ui.login)
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);
158 if((*pps)->pinerc)
159 fs_give((void **)&(*pps)->pinerc);
161 #if defined(DOS) || defined(OS2)
162 if((*pps)->pine_dir)
163 fs_give((void **)&(*pps)->pine_dir);
165 if((*pps)->aux_files_dir)
166 fs_give((void **)&(*pps)->aux_files_dir);
167 #endif
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);
178 #ifdef PASSFILE
179 if((*pps)->passfile)
180 fs_give((void **)&(*pps)->passfile);
181 #ifdef SMIME
182 if((*pps)->pwdcert){
183 PERSONAL_CERT *pc;
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);
200 if((*pps)->keywords)
201 free_keyword_list(&(*pps)->keywords);
203 if((*pps)->kw_colors)
204 free_spec_colors(&(*pps)->kw_colors);
206 if((*pps)->atmts){
207 int i;
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);
217 if((*pps)->msgmap)
218 msgno_give(&(*pps)->msgmap);
220 free_vars(*pps);
222 fs_give((void **) pps);
226 void
227 free_pinerc_strings(struct pine **pps)
229 if((*pps)->prc){
230 if((*pps)->prc->outstanding_pinerc_changes)
231 write_pinerc((*pps), Main, WRP_NONE);
233 if((*pps)->prc->rd)
234 rd_close_remdata(&(*pps)->prc->rd);
236 free_pinerc_s(&(*pps)->prc);
239 if((*pps)->pconf)
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
256 * variables list
258 void
259 free_vars(struct pine *ps)
261 register int i;
263 for(i = 0; ps && i <= V_LAST_VAR; i++)
264 free_variable_values(&ps->vars[i]);
268 void
269 free_variable_values(struct variable *var)
271 if(var){
272 if(var->is_list){
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);
280 else{
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);
289 if(var->fixed_val.p)
290 fs_give((void **)&var->fixed_val.p);
291 if(var->cmdline_val.p)
292 fs_give((void **)&var->cmdline_val.p);
298 PINERC_S *
299 new_pinerc_s(char *name)
301 PINERC_S *prc = NULL;
303 if(name){
304 prc = (PINERC_S *)fs_get(sizeof(*prc));
305 memset((void *)prc, 0, sizeof(*prc));
306 prc->name = cpystr(name);
307 if(IS_REMOTE(name))
308 prc->type = RemImap;
309 else
310 prc->type = Loc;
313 return(prc);
317 void
318 free_pinerc_s(PINERC_S **prc)
320 if(prc && *prc){
321 if((*prc)->name)
322 fs_give((void **)&(*prc)->name);
324 if((*prc)->rd)
325 rd_free_remdata(&(*prc)->rd);
327 if((*prc)->pinerc_lines)
328 free_pinerc_lines(&(*prc)->pinerc_lines);
330 fs_give((void **)prc);