File: state.c

package info (click to toggle)
alpine 2.11%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,876 kB
  • ctags: 26,747
  • sloc: ansic: 316,152; tcl: 26,277; sh: 11,228; makefile: 1,885; perl: 189; xml: 93; exp: 69; csh: 48; sed: 16
file content (321 lines) | stat: -rw-r--r-- 7,759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#if !defined(lint) && !defined(DOS)
static char rcsid[] = "$Id: state.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
#endif

/*
 * ========================================================================
 * Copyright 2006-2008 University of Washington
 * Copyright 2013 Eduardo Chappa
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * ========================================================================
 */

/*======================================================================
     state.c
     Implements the Pine state management routines
  ====*/


#include "../pith/headers.h"
#include "../pith/state.h"
#include "../pith/conf.h"
#include "../pith/init.h"
#include "../pith/sort.h"
#include "../pith/atttype.h"
#include "../pith/util.h"
#include "../pith/mailindx.h"
#include "../pith/remote.h"
#include "../pith/list.h"
#include "../pith/smime.h"


/*
 * Globals referenced throughout pine...
 */
struct pine *ps_global;				/* THE global variable! */

#ifdef	DEBUG
/*
 * Debug level and output file defined here, referenced globally.
 * The debug file is opened and initialized below...
 */
int          debug        = DEFAULT_DEBUG;
#endif


/*----------------------------------------------------------------------
  General use big buffer. It is used in the following places:
    compose_mail:    while parsing header of postponed message
    append_message2: while writing header into folder
    q_status_messageX: while doing printf formatting
    addr_book: Used to return expanded address in. (Can only use here 
               because mm_log doesn't q_status on PARSE errors !)
    alpine.c: When address specified on command line
    init.c: When expanding variable values
    and many many more...

 ----*/
char         tmp_20k_buf[SIZEOF_20KBUF];


/*
 * new_pine_struct - allocate and fill in with default values a new pine struct
 */
struct pine *
new_pine_struct(void)
{
    struct pine *p;

    p		       = (struct pine *)fs_get(sizeof (struct pine));
    memset((void *) p, 0, sizeof(struct pine));
    p->def_sort        = SortArrival;
    p->sort_types[0]   = SortSubject;
    p->sort_types[1]   = SortArrival;
    p->sort_types[2]   = SortFrom;
    p->sort_types[3]   = SortTo;
    p->sort_types[4]   = SortCc;
    p->sort_types[5]   = SortDate;
    p->sort_types[6]   = SortSize;
    p->sort_types[7]   = SortSubject2;
    p->sort_types[8]   = SortScore;
    p->sort_types[9]   = SortThread;
    p->sort_types[10]  = EndofList;
#ifdef SMIME
    /*
     * We need to have access to p->smime even before calling
     * smime_init() so that we can set do_encrypt and do_sign.
     */
    p->smime           = new_smime_struct();
#endif /* SMIME */
    p->atmts           = (ATTACH_S *) fs_get(sizeof(ATTACH_S));
    p->atmts_allocated = 1;
    p->atmts->description = NULL;
    p->low_speed       = 1;
    p->init_context    = -1;
/*    msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
    init_init_vars(p);

    return(p);
}



/*
 * free_pine_struct -- free up allocated data in pine struct and then the
 *		       struct itself
 */
void
free_pine_struct(struct pine **pps)
{ 
    if(!(pps && (*pps)))
      return;

    if((*pps)->hostname != NULL)
      fs_give((void **)&(*pps)->hostname);

    if((*pps)->localdomain != NULL)
      fs_give((void **)&(*pps)->localdomain);

    if((*pps)->ttyo != NULL)
      fs_give((void **)&(*pps)->ttyo);

    if((*pps)->home_dir != NULL)
      fs_give((void **)&(*pps)->home_dir);

    if((*pps)->folders_dir != NULL)
      fs_give((void **)&(*pps)->folders_dir);

    if((*pps)->ui.homedir)
      fs_give((void **)&(*pps)->ui.homedir);

    if((*pps)->ui.login)
      fs_give((void **)&(*pps)->ui.login);

    if((*pps)->ui.fullname)
      fs_give((void **)&(*pps)->ui.fullname);

    free_index_format(&(*pps)->index_disp_format);

    if((*pps)->conv_table){
	if((*pps)->conv_table->table)
	  fs_give((void **) &(*pps)->conv_table->table);
	
	if((*pps)->conv_table->from_charset)
	  fs_give((void **) &(*pps)->conv_table->from_charset);
	
	if((*pps)->conv_table->to_charset)
	  fs_give((void **) &(*pps)->conv_table->to_charset);

	fs_give((void **)&(*pps)->conv_table);
    }

    if((*pps)->pinerc)
      fs_give((void **)&(*pps)->pinerc);

#if defined(DOS) || defined(OS2)
    if((*pps)->pine_dir)
      fs_give((void **)&(*pps)->pine_dir);

    if((*pps)->aux_files_dir)
      fs_give((void **)&(*pps)->aux_files_dir);
#endif

    if((*pps)->display_charmap)
      fs_give((void **)&(*pps)->display_charmap);

    if((*pps)->keyboard_charmap)
      fs_give((void **)&(*pps)->keyboard_charmap);

    if((*pps)->posting_charmap)
      fs_give((void **)&(*pps)->posting_charmap);

#ifdef PASSFILE
    if((*pps)->passfile)
      fs_give((void **)&(*pps)->passfile);
#endif /* PASSFILE */

    if((*pps)->hdr_colors)
      free_spec_colors(&(*pps)->hdr_colors);

    if((*pps)->index_token_colors)
      free_spec_colors(&(*pps)->index_token_colors);

    if((*pps)->keywords)
      free_keyword_list(&(*pps)->keywords);

    if((*pps)->kw_colors)
      free_spec_colors(&(*pps)->kw_colors);

    if((*pps)->atmts){
	int i;

	for(i = 0; (*pps)->atmts[i].description; i++){
	    fs_give((void **) &(*pps)->atmts[i].description);
	    fs_give((void **) &(*pps)->atmts[i].number);
	}

	fs_give((void **) &(*pps)->atmts);
    }

    if((*pps)->msgmap)
      msgno_give(&(*pps)->msgmap);
    
    free_vars(*pps);

    fs_give((void **) pps);
}


void
free_pinerc_strings(struct pine **pps)
{
    if((*pps)->prc){
	if((*pps)->prc->outstanding_pinerc_changes)
	  write_pinerc((*pps), Main, WRP_NONE);

	if((*pps)->prc->rd)
	  rd_close_remdata(&(*pps)->prc->rd);
	
	free_pinerc_s(&(*pps)->prc);
    }

    if((*pps)->pconf)
      free_pinerc_s(&(*pps)->pconf);

    if((*pps)->post_prc){
	if((*pps)->post_prc->outstanding_pinerc_changes)
	  write_pinerc((*pps), Post, WRP_NONE);

	if((*pps)->post_prc->rd)
	  rd_close_remdata(&(*pps)->post_prc->rd);
	
	free_pinerc_s(&(*pps)->post_prc);
    }
}


/*
 * free_vars -- give back resources acquired when we defined the
 *		variables list
 */
void
free_vars(struct pine *ps)
{
    register int i;

    for(i = 0; ps && i <= V_LAST_VAR; i++)
      free_variable_values(&ps->vars[i]);
}


void
free_variable_values(struct variable *var)
{
    if(var){
	if(var->is_list){
	    free_list_array(&var->current_val.l);
	    free_list_array(&var->main_user_val.l);
	    free_list_array(&var->post_user_val.l);
	    free_list_array(&var->global_val.l);
	    free_list_array(&var->fixed_val.l);
	    free_list_array(&var->cmdline_val.l);
	}
	else{
	    if(var->current_val.p)
	      fs_give((void **)&var->current_val.p);
	    if(var->main_user_val.p)
	      fs_give((void **)&var->main_user_val.p);
	    if(var->post_user_val.p)
	      fs_give((void **)&var->post_user_val.p);
	    if(var->global_val.p)
	      fs_give((void **)&var->global_val.p);
	    if(var->fixed_val.p)
	      fs_give((void **)&var->fixed_val.p);
	    if(var->cmdline_val.p)
	      fs_give((void **)&var->cmdline_val.p);
	}
    }
}


PINERC_S *
new_pinerc_s(char *name)
{
    PINERC_S *prc = NULL;

    if(name){
	prc = (PINERC_S *)fs_get(sizeof(*prc));
	memset((void *)prc, 0, sizeof(*prc));
	prc->name = cpystr(name);
	if(IS_REMOTE(name))
	  prc->type = RemImap;
	else
	  prc->type = Loc;
    }

    return(prc);
}


void
free_pinerc_s(PINERC_S **prc)
{
    if(prc && *prc){
	if((*prc)->name)
	  fs_give((void **)&(*prc)->name);

	if((*prc)->rd)
	  rd_free_remdata(&(*prc)->rd);

	if((*prc)->pinerc_lines)
	  free_pinerc_lines(&(*prc)->pinerc_lines);

	fs_give((void **)prc);
    }
}