File: cleanup_state.c

package info (click to toggle)
postfix 0.0.19991231pl11-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,044 kB
  • ctags: 4,401
  • sloc: ansic: 33,767; makefile: 5,099; sh: 1,790; awk: 19
file content (138 lines) | stat: -rw-r--r-- 4,313 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
/*++
/* NAME
/*	cleanup_state 3
/* SUMMARY
/*	per-message state variables
/* SYNOPSIS
/*	#include "cleanup.h"
/*
/*	void	cleanup_state_alloc(void)
/*
/*	void	cleanup_state_free(void)
/* DESCRIPTION
/*	This module maintains about two dozen global (ugh) state variables
/*	that are used by many routines in the course of processing one
/*	message. Using globals seems to make more sense than passing around
/*	large parameter lists, or passing around a structure with a large
/*	number of components. We can get away with this because we need only
/*	one instance at a time.
/*
/*	cleanup_state_alloc() initializes the per-message state variables.
/*
/*	cleanup_state_free() cleans up.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*--*/

/* System library. */

#include <sys_defs.h>

/* Utility library. */

#include <mymalloc.h>
#include <vstring.h>
#include <vstream.h>

/* Global library. */

#include <been_here.h>
#include <mail_params.h>

/* Application-specific. */

#include "cleanup.h"

 /*
  * These variables are accessed by many functions, and there is only one
  * instance of each. Rather than passing around lots and lots of parameters,
  * or passing them around in a structure, we just make the variables global,
  * because that is what they are.
  */
VSTRING *cleanup_inbuf;			/* read buffer */
VSTRING *cleanup_temp1;			/* scratch buffer, local use only */
VSTRING *cleanup_temp2;			/* scratch buffer, local use only */
VSTREAM *cleanup_src;			/* current input stream */
VSTREAM *cleanup_dst;			/* current output stream */
MAIL_STREAM *cleanup_handle;		/* mail stream handle */
char   *cleanup_queue_id;		/* queue file basename */
time_t  cleanup_time;			/* posting time */
char   *cleanup_fullname;		/* envelope sender full name */
char   *cleanup_sender;			/* envelope sender address */
char   *cleanup_from;			/* From: address */
char   *cleanup_resent_from;		/* Resent-From: address */
char   *cleanup_recip;			/* envelope recipient address */
char   *cleanup_return_receipt;		/* return-receipt address */
char   *cleanup_errors_to;		/* errors-to address */
int     cleanup_flags;			/* processing options */
int     cleanup_errs;			/* any badness experienced */
int     cleanup_err_mask;		/* allowed badness */
VSTRING *cleanup_header_buf;		/* multi-record header */
int     cleanup_headers_seen;		/* which headers were seen */
int     cleanup_hop_count;		/* count of received: headers */
ARGV   *cleanup_recipients;		/* recipients from regular headers */
ARGV   *cleanup_resent_recip;		/* recipients from resent headers */
char   *cleanup_resent;			/* any resent- header seen */
BH_TABLE *cleanup_dups;			/* recipient dup filter */

/* cleanup_state_alloc - initialize global state */

void    cleanup_state_alloc(void)
{
    cleanup_hop_count = 0;
    cleanup_headers_seen = 0;
    cleanup_time = 0;
    cleanup_errs = 0;
    cleanup_from = 0;
    cleanup_fullname = 0;
    cleanup_header_buf = vstring_alloc(100);
    cleanup_queue_id = 0;
    cleanup_recip = 0;
    cleanup_return_receipt = 0;
    cleanup_errors_to = 0;
    cleanup_recipients = argv_alloc(2);
    cleanup_resent = "";
    cleanup_resent_from = 0;
    cleanup_resent_recip = argv_alloc(2);
    cleanup_sender = 0;
    cleanup_temp1 = vstring_alloc(10);
    cleanup_temp2 = vstring_alloc(10);
    cleanup_inbuf = vstring_alloc(100);
    cleanup_dups = been_here_init(var_dup_filter_limit, BH_FLAG_FOLD);
}

/* cleanup_state_free - destroy global state */

void    cleanup_state_free(void)
{
    if (cleanup_fullname)
	myfree(cleanup_fullname);
    if (cleanup_sender)
	myfree(cleanup_sender);
    if (cleanup_from)
	myfree(cleanup_from);
    if (cleanup_resent_from)
	myfree(cleanup_resent_from);
    if (cleanup_recip)
	myfree(cleanup_recip);
    if (cleanup_return_receipt)
	myfree(cleanup_return_receipt);
    if (cleanup_errors_to)
	myfree(cleanup_errors_to);
    vstring_free(cleanup_header_buf);
    argv_free(cleanup_recipients);
    argv_free(cleanup_resent_recip);
    vstring_free(cleanup_temp1);
    vstring_free(cleanup_temp2);
    vstring_free(cleanup_inbuf);
    if (cleanup_queue_id)
	myfree(cleanup_queue_id);
    been_here_free(cleanup_dups);
}