Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / debug_peer.c
blob25d641a40f9d6efde2dc93dba2d4937394f1a11d
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* debug_peer 3
6 /* SUMMARY
7 /* increase verbose logging for specific peers
8 /* SYNOPSIS
9 /* #include <debug_peer.h>
11 /* void debug_peer_init(void)
13 /* int peer_debug_check(peer_name, peer_addr)
14 /* const char *peer_name;
15 /* const char *peer_addr;
17 /* void debug_peer_restore()
18 /* DESCRIPTION
19 /* This module implements increased verbose logging for specific
20 /* network peers.
22 /* The \fIdebug_peer_list\fR configuration parameter
23 /* specifies what peers receive this special treatment; see
24 /* namadr_list(3) for a description of the matching process.
26 /* The \fIdebug_peer_level\fR configuration parameter specifies
27 /* by what amount the verbose logging level should increase when
28 /* a peer is listed in \fIdebug_peer_list\fR.
30 /* debug_peer_init() performs initializations that must be
31 /* performed once at the start of the program.
33 /* debug_peer_check() increases the verbose logging level when the
34 /* client name or address matches the debug_peer_list pattern.
35 /* The result is non-zero when the noise leven was increased.
37 /* debug_peer_restore() restores the verbose logging level.
38 /* This routine has no effect when debug_peer_check() had no
39 /* effect; this routine can safely be called multiple times.
40 /* DIAGNOSTICS
41 /* Panic: interface violations.
42 /* Fatal errors: unable to access a peer_list file; invalid
43 /* peer_list pattern; invalid verbosity level increment.
44 /* SEE ALSO
45 /* msg(3) the msg_verbose variable
46 /* namadr_list(3) match host by name or by address
47 /* CONFIG PARAMETERS
48 /* debug_peer_list, patterns as described in namadr_list(3)
49 /* debug_peer_level, verbose logging level
50 /* LICENSE
51 /* .ad
52 /* .fi
53 /* The Secure Mailer license must be distributed with this software.
54 /* AUTHOR(S)
55 /* Wietse Venema
56 /* IBM T.J. Watson Research
57 /* P.O. Box 704
58 /* Yorktown Heights, NY 10598, USA
59 /*--*/
61 /* System library. */
63 #include <sys_defs.h>
65 /* Utility library. */
67 #include <msg.h>
69 /* Global library. */
71 #include <mail_params.h>
72 #include <namadr_list.h>
73 #include <debug_peer.h>
74 #include <match_parent_style.h>
76 /* Application-specific. */
78 #define UNUSED_SAVED_LEVEL (-1)
80 static NAMADR_LIST *debug_peer_list;
81 static int saved_level = UNUSED_SAVED_LEVEL;
83 /* debug_peer_init - initialize */
85 void debug_peer_init(void)
87 const char *myname = "debug_peer_init";
90 * Sanity check.
92 if (debug_peer_list)
93 msg_panic("%s: repeated call", myname);
94 if (var_debug_peer_list == 0)
95 msg_panic("%s: uninitialized %s", myname, VAR_DEBUG_PEER_LIST);
96 if (var_debug_peer_level <= 0)
97 msg_fatal("%s: %s <= 0", myname, VAR_DEBUG_PEER_LEVEL);
100 * Finally.
102 if (*var_debug_peer_list)
103 debug_peer_list =
104 namadr_list_init(match_parent_style(VAR_DEBUG_PEER_LIST),
105 var_debug_peer_list);
108 /* debug_peer_check - see if this peer needs verbose logging */
110 int debug_peer_check(const char *name, const char *addr)
114 * Crank up the noise when this peer is listed.
116 if (debug_peer_list != 0
117 && saved_level == UNUSED_SAVED_LEVEL
118 && namadr_list_match(debug_peer_list, name, addr) != 0) {
119 saved_level = msg_verbose;
120 msg_verbose += var_debug_peer_level;
121 return (1);
123 return (0);
126 /* debug_peer_restore - restore logging level */
128 void debug_peer_restore(void)
130 if (saved_level != UNUSED_SAVED_LEVEL) {
131 msg_verbose = saved_level;
132 saved_level = UNUSED_SAVED_LEVEL;