Postfix3.3.1
scache.h
[詳解]
1 #ifndef _SCACHE_H_INCLUDED_
2 #define _SCACHE_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* scache 3h
7 /* SUMMARY
8 /* generic session cache API
9 /* SYNOPSIS
10 /* #include <scache.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * Utility library.
16  */
17 #include <vstring.h>
18 
19 typedef struct SCACHE SCACHE;
20 typedef struct SCACHE_SIZE SCACHE_SIZE;
21 
22  /*
23  * In order to cache a session, we specify:
24  *
25  * - TTL for this session.
26  *
27  * - File descriptor.
28  *
29  * - Transport name and physical endpoint. The transport name must be included,
30  * because fall-back destinations can be transport-dependent, and routing
31  * for a given destination may be context dependent.
32  *
33  * In the case of SMTP, the physical endpoint is the numerical IP address and
34  * TCP port.
35  *
36  * - Application-specific endpoint properties.
37  *
38  * In the case of SMTP, the properties specify the ESMTP features advertised by
39  * the server.
40  *
41  * Note: with message delivery transports that have only one endpoint per
42  * logical destination, the above is the only information that needs to be
43  * maintained in a connection cache.
44  */
45 typedef void (*SCACHE_SAVE_ENDP_FN) (SCACHE *, int, const char *, const char *, int);
46 typedef int (*SCACHE_FIND_ENDP_FN) (SCACHE *, const char *, VSTRING *);
47 
48  /*
49  * The following information is stored in order to make a binding from
50  * logical destination to physical destination. One logical destination can
51  * have multiple physical destinations (and one physical destination can
52  * have multiple sessions).
53  *
54  * - TTL for this binding.
55  *
56  * - Transport name and logical destination.
57  *
58  * In the case of SMTP: the next-hop (NOT: fall-back) destination domain and
59  * destination network port. It is not useful to create a link for an
60  * address literal (but it is not harmful either: it just wastes a few
61  * bits). This information specifies the destination domain in [] if no MX
62  * lookup is done.
63  *
64  * - Application-specific properties.
65  *
66  * In case the of SMTP, the properties specify a) whether a physical endpoint
67  * is best mx host with respect to a logical or fall-back destination (this
68  * information is needed by the loop detection code in smtp_proto.c).
69  *
70  * - Transport name and physical endpoint (see above).
71  *
72  * Note 1: there is no need to store the binding's MX preference or equivalent
73  * with respect to the logical destination; a client should store only the
74  * first successful session for a given delivery request (otherwise the
75  * client would keep talking to a less preferred server after the cached
76  * connection for a more preferred server expires). After a failed delivery,
77  * the client should not attempt to cache follow-up sessions with less
78  * preferred endpoints under the same logical destination.
79  *
80  * Note 2: logical to physical bindings exist independently from cached
81  * sessions. The two types of information have independent TTLs; creation
82  * and destruction proceed independently. Thus, a logical to physical
83  * binding can refer to an endpoint for which all cached connections are
84  * occupied or expired.
85  */
86 typedef void (*SCACHE_SAVE_DEST_FN) (SCACHE *, int, const char *, const char *, const char *);
87 typedef int (*SCACHE_FIND_DEST_FN) (SCACHE *, const char *, VSTRING *, VSTRING *);
88 
89  /*
90  * Session cache statistics. These are the actual numbers at a specific
91  * point in time.
92  */
93 struct SCACHE_SIZE {
94  int dest_count; /* Nr of destination names */
95  int endp_count; /* Nr of endpoint addresses */
96  int sess_count; /* Nr of cached sessions */
97 };
98 
99  /*
100  * Generic session cache object. Actual session cache objects are derived
101  * types with some additional, cache dependent, private information.
102  */
103 struct SCACHE {
108  void (*size) (struct SCACHE *, SCACHE_SIZE *);
109  void (*free) (struct SCACHE *);
110 };
111 
112 extern SCACHE *scache_single_create(void);
113 extern SCACHE *scache_clnt_create(const char *, int, int, int);
114 extern SCACHE *scache_multi_create(void);
115 
116 #define scache_save_endp(scache, ttl, endp_label, endp_prop, fd) \
117  (scache)->save_endp((scache), (ttl), (endp_label), (endp_prop), (fd))
118 #define scache_find_endp(scache, endp_label, endp_prop) \
119  (scache)->find_endp((scache), (endp_label), (endp_prop))
120 #define scache_save_dest(scache, ttl, dest_label, dest_prop, endp_label) \
121  (scache)->save_dest((scache), (ttl), (dest_label), (dest_prop), (endp_label))
122 #define scache_find_dest(scache, dest_label, dest_prop, endp_prop) \
123  (scache)->find_dest((scache), (dest_label), (dest_prop), (endp_prop))
124 #define scache_size(scache, stats) (scache)->size((scache), (stats))
125 #define scache_free(scache) (scache)->free(scache)
126 
127  /*
128  * Cache types.
129  */
130 #define SCACHE_TYPE_SINGLE 1 /* single-instance cache */
131 #define SCACHE_TYPE_CLIENT 2 /* session cache client */
132 #define SCACHE_TYPE_MULTI 3 /* multi-instance cache */
133 
134  /*
135  * Client-server protocol.
136  */
137 #define SCACHE_REQ_FIND_ENDP "find_endp"
138 #define SCACHE_REQ_SAVE_ENDP "save_endp"
139 #define SCACHE_REQ_FIND_DEST "find_dest"
140 #define SCACHE_REQ_SAVE_DEST "save_dest"
141 
142  /*
143  * Session cache server status codes.
144  */
145 #define SCACHE_STAT_OK 0 /* request completed successfully */
146 #define SCACHE_STAT_BAD 1 /* malformed request */
147 #define SCACHE_STAT_FAIL 2 /* request completed unsuccessfully */
148 
149 /* LICENSE
150 /* .ad
151 /* .fi
152 /* The Secure Mailer license must be distributed with this software.
153 /* AUTHOR(S)
154 /* Wietse Venema
155 /* IBM T.J. Watson Research
156 /* P.O. Box 704
157 /* Yorktown Heights, NY 10598, USA
158 /*
159 /* Wietse Venema
160 /* Google, Inc.
161 /* 111 8th Avenue
162 /* New York, NY 10011, USA
163 /*--*/
164 
165 #endif
int dest_count
Definition: scache.h:94
int(* SCACHE_FIND_DEST_FN)(SCACHE *, const char *, VSTRING *, VSTRING *)
Definition: scache.h:87
void(* size)(struct SCACHE *, SCACHE_SIZE *)
Definition: scache.h:108
void(* SCACHE_SAVE_DEST_FN)(SCACHE *, int, const char *, const char *, const char *)
Definition: scache.h:86
SCACHE_FIND_DEST_FN find_dest
Definition: scache.h:107
SCACHE * scache_multi_create(void)
Definition: scache_multi.c:477
int sess_count
Definition: scache.h:96
SCACHE * scache_single_create(void)
SCACHE_SAVE_ENDP_FN save_endp
Definition: scache.h:104
SCACHE_SAVE_DEST_FN save_dest
Definition: scache.h:106
int endp_count
Definition: scache.h:95
int int
Definition: smtpd_proxy.h:21
SCACHE_FIND_ENDP_FN find_endp
Definition: scache.h:105
int(* SCACHE_FIND_ENDP_FN)(SCACHE *, const char *, VSTRING *)
Definition: scache.h:46
Definition: scache.h:103
SCACHE * scache_clnt_create(const char *, int, int, int)
Definition: scache_clnt.c:404
void(* free)(struct SCACHE *)
Definition: scache.h:109
void(* SCACHE_SAVE_ENDP_FN)(SCACHE *, int, const char *, const char *, int)
Definition: scache.h:45