Postfix3.3.1
dict_fail.c
[詳解]
1 /*++
2 /* NAME
3 /* dict_fail 3
4 /* SUMMARY
5 /* dictionary manager interface to 'always fail' table
6 /* SYNOPSIS
7 /* #include <dict_fail.h>
8 /*
9 /* DICT *dict_fail_open(name, open_flags, dict_flags)
10 /* const char *name;
11 /* int open_flags;
12 /* int dict_flags;
13 /* DESCRIPTION
14 /* dict_fail_open() implements a dummy dictionary that fails
15 /* all operations. The name can be used for logging.
16 /* SEE ALSO
17 /* dict(3) generic dictionary manager
18 /* LICENSE
19 /* .ad
20 /* .fi
21 /* The Secure Mailer license must be distributed with this software.
22 /* AUTHOR(S)
23 /* Wietse Venema
24 /* IBM T.J. Watson Research
25 /* P.O. Box 704
26 /* Yorktown Heights, NY 10598, USA
27 /*--*/
28 
29 /* System library. */
30 
31 #include <sys_defs.h>
32 
33 /* Utility library. */
34 
35 #include <mymalloc.h>
36 #include <msg.h>
37 #include <dict.h>
38 #include <dict_fail.h>
39 
40 /* Application-specific. */
41 
42 typedef struct {
43  DICT dict; /* generic members */
44  int dict_errno; /* fixed error result */
45 } DICT_FAIL;
46 
47 /* dict_fail_sequence - fail lookup */
48 
49 static int dict_fail_sequence(DICT *dict, int unused_func,
50  const char **key, const char **value)
51 {
52  DICT_FAIL *dp = (DICT_FAIL *) dict;
53 
55 }
56 
57 /* dict_fail_update - fail lookup */
58 
59 static int dict_fail_update(DICT *dict, const char *unused_name,
60  const char *unused_value)
61 {
62  DICT_FAIL *dp = (DICT_FAIL *) dict;
63 
65 }
66 
67 /* dict_fail_lookup - fail lookup */
68 
69 static const char *dict_fail_lookup(DICT *dict, const char *unused_name)
70 {
71  DICT_FAIL *dp = (DICT_FAIL *) dict;
72 
73  DICT_ERR_VAL_RETURN(dict, dp->dict_errno, (char *) 0);
74 }
75 
76 /* dict_fail_delete - fail delete */
77 
78 static int dict_fail_delete(DICT *dict, const char *unused_name)
79 {
80  DICT_FAIL *dp = (DICT_FAIL *) dict;
81 
83 }
84 
85 /* dict_fail_close - close fail dictionary */
86 
87 static void dict_fail_close(DICT *dict)
88 {
89  dict_free(dict);
90 }
91 
92 /* dict_fail_open - make association with fail variable */
93 
94 DICT *dict_fail_open(const char *name, int open_flags, int dict_flags)
95 {
96  DICT_FAIL *dp;
97 
98  dp = (DICT_FAIL *) dict_alloc(DICT_TYPE_FAIL, name, sizeof(*dp));
99  dp->dict.lookup = dict_fail_lookup;
100  if (open_flags & O_RDWR) {
101  dp->dict.update = dict_fail_update;
102  dp->dict.delete = dict_fail_delete;
103  }
104  dp->dict.sequence = dict_fail_sequence;
105  dp->dict.close = dict_fail_close;
106  dp->dict.flags = dict_flags | DICT_FLAG_PATTERN;
109  return (DICT_DEBUG (&dp->dict));
110 }
void(* close)(struct DICT *)
Definition: dict.h:87
int(* delete)(struct DICT *, const char *)
Definition: dict.h:84
int flags
Definition: dict.h:81
#define DICT_ERR_RETRY
Definition: dict.h:178
#define DICT_TYPE_FAIL
Definition: dict_fail.h:22
DICT dict
Definition: dict_fail.c:43
Definition: dict.h:78
int(* update)(struct DICT *, const char *, const char *)
Definition: dict.h:83
#define DICT_OWNER_TRUSTED
Definition: dict.h:46
DICT * dict_fail_open(const char *name, int open_flags, int dict_flags)
Definition: dict_fail.c:94
const char *(* lookup)(struct DICT *, const char *)
Definition: dict.h:82
#define DICT_ERR_VAL_RETURN(dict, err, val)
Definition: dict.h:192
int status
Definition: dict.h:38
#define DICT_FLAG_PATTERN
Definition: dict.h:115
void dict_free(DICT *)
Definition: dict_alloc.c:163
#define DICT_STAT_ERROR
Definition: dict.h:187
int(* sequence)(struct DICT *, int, const char **, const char **)
Definition: dict.h:85
DICT * dict_alloc(const char *, const char *, ssize_t)
Definition: dict_alloc.c:135
DICT_OWNER owner
Definition: dict.h:93
int dict_errno
Definition: dict_fail.c:44